KiCad PCB EDA Suite
operations_on_items_lists.cpp File Reference

Functions used in block commands, or undo/redo, to move, mirror, delete, copy ... More...

#include <fctsys.h>
#include <pgm_base.h>
#include <class_drawpanel.h>
#include <schframe.h>
#include <general.h>
#include <protos.h>
#include <sch_bus_entry.h>
#include <sch_marker.h>
#include <sch_line.h>
#include <sch_no_connect.h>
#include <sch_sheet.h>
#include <sch_component.h>
#include <sch_junction.h>

Go to the source code of this file.

Functions

void SetSchItemParent (SCH_ITEM *Struct, SCH_SCREEN *Screen)
 
void RotateListOfItems (PICKED_ITEMS_LIST &aItemsList, wxPoint &rotationPoint)
 
void MirrorY (PICKED_ITEMS_LIST &aItemsList, wxPoint &aMirrorPoint)
 
void MirrorX (PICKED_ITEMS_LIST &aItemsList, wxPoint &aMirrorPoint)
 
void MoveItemsInList (PICKED_ITEMS_LIST &aItemsList, const wxPoint aMoveVector)
 Function MoveItemsInList Move a list of items to a given move vector. More...
 
void DeleteItemsInList (EDA_DRAW_PANEL *panel, PICKED_ITEMS_LIST &aItemsList)
 Function DeleteItemsInList delete schematic items in aItemsList deleted items are put in undo list. More...
 
void DuplicateItemsInList (SCH_SCREEN *screen, PICKED_ITEMS_LIST &aItemsList, const wxPoint aMoveVector)
 
SCH_ITEMDuplicateStruct (SCH_ITEM *aDrawStruct, bool aClone)
 Function DuplicateStruct Routine to create a new copy of given struct. More...
 

Detailed Description

Functions used in block commands, or undo/redo, to move, mirror, delete, copy ...

lists of schematic items.

Definition in file operations_on_items_lists.cpp.

Function Documentation

void DeleteItemsInList ( EDA_DRAW_PANEL panel,
PICKED_ITEMS_LIST aItemsList 
)

Function DeleteItemsInList delete schematic items in aItemsList deleted items are put in undo list.

Definition at line 129 of file operations_on_items_lists.cpp.

References PICKED_ITEMS_LIST::GetCount(), EDA_DRAW_PANEL::GetParent(), PICKED_ITEMS_LIST::GetPickedItem(), EDA_DRAW_PANEL::GetScreen(), PICKED_ITEMS_LIST::PushItem(), SCH_SCREEN::Remove(), SCH_EDIT_FRAME::SaveCopyInUndoList(), SCH_SHEET_PIN_T, EDA_ITEM::Type(), and UR_DELETED.

Referenced by SCH_EDIT_FRAME::DeleteConnection(), and SCH_EDIT_FRAME::HandleBlockEnd().

130 {
131  SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen();
132  SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent();
133  PICKED_ITEMS_LIST itemsList;
134 
135  for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
136  {
137  SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
138  ITEM_PICKER itemWrapper( item, UR_DELETED );
139 
140  if( item->Type() == SCH_SHEET_PIN_T )
141  {
142  /* this item is depending on a sheet, and is not in global list */
143  wxMessageBox( wxT( "DeleteItemsInList() err: unexpected SCH_SHEET_PIN_T" ) );
144  }
145  else
146  {
147  screen->Remove( item );
148 
149  /* Unlink the structure */
150  itemsList.PushItem( itemWrapper );
151  }
152  }
153 
154  frame->SaveCopyInUndoList( itemsList, UR_DELETED );
155 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))
Function SaveCopyInUndoList.
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
void Remove(SCH_ITEM *aItem)
Function Remove removes aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:158
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
unsigned GetCount() const
Function GetCount.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void DuplicateItemsInList ( SCH_SCREEN screen,
PICKED_ITEMS_LIST aItemsList,
const wxPoint  aMoveVector 
)

Definition at line 189 of file operations_on_items_lists.cpp.

References SCH_SCREEN::Append(), DuplicateStruct(), PICKED_ITEMS_LIST::GetCount(), GetNewTimeStamp(), PICKED_ITEMS_LIST::GetPickedItem(), MoveItemsInList(), SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_COMPONENT_T, SCH_GLOBAL_LABEL_T, SCH_HIERARCHICAL_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LINE_T, SCH_MARKER_T, SCH_NO_CONNECT_T, SCH_SHEET_PIN_T, SCH_SHEET_T, SCH_TEXT_T, PICKED_ITEMS_LIST::SetPickedItem(), PICKED_ITEMS_LIST::SetPickedItemStatus(), SetSchItemParent(), EDA_ITEM::SetTimeStamp(), EDA_ITEM::Type(), and UR_NEW.

Referenced by SCH_EDIT_FRAME::HandleBlockPlace().

191 {
192  SCH_ITEM* newitem;
193 
194  if( aItemsList.GetCount() == 0 )
195  return;
196 
197  for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
198  {
199  newitem = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
200  aItemsList.SetPickedItem( newitem, ii );
201  aItemsList.SetPickedItemStatus( UR_NEW, ii );
202  {
203  switch( newitem->Type() )
204  {
205  case SCH_JUNCTION_T:
206  case SCH_LINE_T:
207  case SCH_BUS_BUS_ENTRY_T:
209  case SCH_TEXT_T:
210  case SCH_LABEL_T:
211  case SCH_GLOBAL_LABEL_T:
213  case SCH_SHEET_PIN_T:
214  case SCH_MARKER_T:
215  case SCH_NO_CONNECT_T:
216  default:
217  break;
218 
219  case SCH_SHEET_T:
220  {
221  SCH_SHEET* sheet = (SCH_SHEET*) newitem;
222  sheet->SetTimeStamp( GetNewTimeStamp() );
223  break;
224  }
225 
226  case SCH_COMPONENT_T:
227  ( (SCH_COMPONENT*) newitem )->SetTimeStamp( GetNewTimeStamp() );
228  ( (SCH_COMPONENT*) newitem )->ClearAnnotation( NULL );
229  break;
230  }
231 
232  SetSchItemParent( newitem, screen );
233  screen->Append( newitem );
234  }
235  }
236 
237  MoveItemsInList( aItemsList, aMoveVector );
238 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
time_t GetNewTimeStamp()
Definition: common.cpp:166
void MoveItemsInList(PICKED_ITEMS_LIST &aItemsList, const wxPoint aMoveVector)
Function MoveItemsInList Move a list of items to a given move vector.
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:217
void SetSchItemParent(SCH_ITEM *Struct, SCH_SCREEN *Screen)
bool SetPickedItem(EDA_ITEM *aItem, unsigned aIdx)
Function SetPickedItem.
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
unsigned GetCount() const
Function GetCount.
bool SetPickedItemStatus(UNDO_REDO_T aStatus, unsigned aIdx)
Function SetPickedItemStatus sets the type of undo/redo operation for a given picked item...
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
void Append(SCH_ITEM *aItem)
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
SCH_ITEM * DuplicateStruct(SCH_ITEM *aDrawStruct, bool aClone)
Function DuplicateStruct Routine to create a new copy of given struct.
SCH_ITEM* DuplicateStruct ( SCH_ITEM aDrawStruct,
bool  aClone 
)

Function DuplicateStruct Routine to create a new copy of given struct.

Function DuplicateStruct creates a new copy of given struct.

The new object is not put in draw list (not linked)

Parameters
aDrawStruct= the SCH_ITEM to duplicate
aClone(default = false) if true duplicate also some parameters that must be unique (timestamp and sheet name) aClone must be false. use true only is undo/redo duplications

Definition at line 251 of file operations_on_items_lists.cpp.

References EDA_ITEM::Clone(), EDA_ITEM::GetTimeStamp(), and EDA_ITEM::SetTimeStamp().

Referenced by SCH_EDIT_FRAME::copyBlockItems(), DuplicateItemsInList(), SCH_EDIT_FRAME::PasteListOfItems(), and SCH_EDIT_FRAME::SaveCopyInUndoList().

252 {
253  wxCHECK_MSG( aDrawStruct != NULL, NULL,
254  wxT( "Cannot duplicate NULL schematic item! Bad programmer." ) );
255 
256  SCH_ITEM* NewDrawStruct = (SCH_ITEM*) aDrawStruct->Clone();
257 
258  if( aClone )
259  NewDrawStruct->SetTimeStamp( aDrawStruct->GetTimeStamp() );
260 
261  return NewDrawStruct;
262 }
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:217
time_t GetTimeStamp() const
Definition: base_struct.h:218
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void MirrorX ( PICKED_ITEMS_LIST aItemsList,
wxPoint aMirrorPoint 
)

Definition at line 97 of file operations_on_items_lists.cpp.

References EDA_ITEM::ClearFlags(), PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetPickedItem(), SCH_ITEM::MirrorX(), and wxPoint::y.

Referenced by SCH_EDIT_FRAME::HandleBlockEnd().

98 {
99  for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
100  {
101  SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
102  item->MirrorX( aMirrorPoint.y ); // Place it in its new position.
103  item->ClearFlags();
104  }
105 }
virtual void MirrorX(int aXaxis_position)=0
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
unsigned GetCount() const
Function GetCount.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void MirrorY ( PICKED_ITEMS_LIST aItemsList,
wxPoint aMirrorPoint 
)

Definition at line 86 of file operations_on_items_lists.cpp.

References EDA_ITEM::ClearFlags(), PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetPickedItem(), SCH_ITEM::MirrorY(), and wxPoint::x.

Referenced by SCH_EDIT_FRAME::HandleBlockEnd().

87 {
88  for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
89  {
90  SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
91  item->MirrorY( aMirrorPoint.x ); // Place it in its new position.
92  item->ClearFlags();
93  }
94 }
virtual void MirrorY(int aYaxis_position)=0
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
unsigned GetCount() const
Function GetCount.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void MoveItemsInList ( PICKED_ITEMS_LIST aItemsList,
const wxPoint  aMoveVector 
)

Function MoveItemsInList Move a list of items to a given move vector.

Parameters
aItemsList= list of picked items
aMoveVector= the move vector value

Definition at line 114 of file operations_on_items_lists.cpp.

References PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetPickedItem(), and SCH_ITEM::Move().

Referenced by DuplicateItemsInList(), SCH_EDIT_FRAME::HandleBlockEnd(), SCH_EDIT_FRAME::HandleBlockPlace(), and SCH_EDIT_FRAME::PasteListOfItems().

115 {
116  for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
117  {
118  SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
119  item->Move( aMoveVector );
120  }
121 }
unsigned GetCount() const
Function GetCount.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
virtual void Move(const wxPoint &aMoveVector)=0
Function Move moves the item by aMoveVector to a new position.
void RotateListOfItems ( PICKED_ITEMS_LIST aItemsList,
wxPoint rotationPoint 
)

Definition at line 75 of file operations_on_items_lists.cpp.

References EDA_ITEM::ClearFlags(), PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetPickedItem(), and SCH_ITEM::Rotate().

Referenced by SCH_EDIT_FRAME::HandleBlockEnd().

76 {
77  for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
78  {
79  SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
80  item->Rotate( rotationPoint ); // Place it in its new position.
81  item->ClearFlags();
82  }
83 }
virtual void Rotate(wxPoint aPosition)=0
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
unsigned GetCount() const
Function GetCount.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void SetSchItemParent ( SCH_ITEM Struct,
SCH_SCREEN Screen 
)

Definition at line 47 of file operations_on_items_lists.cpp.

References SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_COMPONENT_T, SCH_GLOBAL_LABEL_T, SCH_HIERARCHICAL_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LINE_T, SCH_MARKER_T, SCH_NO_CONNECT_T, SCH_SHEET_PIN_T, SCH_SHEET_T, SCH_TEXT_T, EDA_ITEM::SetParent(), and EDA_ITEM::Type().

Referenced by DuplicateItemsInList(), and SCH_EDIT_FRAME::PasteListOfItems().

48 {
49  switch( Struct->Type() )
50  {
51  case SCH_JUNCTION_T:
52  case SCH_TEXT_T:
53  case SCH_LABEL_T:
54  case SCH_GLOBAL_LABEL_T:
56  case SCH_COMPONENT_T:
57  case SCH_LINE_T:
60  case SCH_SHEET_T:
61  case SCH_MARKER_T:
62  case SCH_NO_CONNECT_T:
63  Struct->SetParent( Screen );
64  break;
65 
66  case SCH_SHEET_PIN_T:
67  break;
68 
69  default:
70  break;
71  }
72 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:227