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 <list_operations.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, const wxPoint &rotationPoint)
 
void MirrorY (PICKED_ITEMS_LIST &aItemsList, const wxPoint &aMirrorPoint)
 
void MirrorX (PICKED_ITEMS_LIST &aItemsList, const 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 DuplicateItemsInList (SCH_SCREEN *screen, PICKED_ITEMS_LIST &aItemsList, const wxPoint &aMoveVector)
 Routine to copy a new entity of an object for each object in list and reposition it. More...
 
SCH_ITEMDuplicateStruct (SCH_ITEM *aDrawStruct, bool aClone)
 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 DuplicateItemsInList ( SCH_SCREEN screen,
PICKED_ITEMS_LIST aItemsList,
const wxPoint aMoveVector 
)

Routine to copy a new entity of an object for each object in list and reposition it.

Return the new created object list in aItemsList

Definition at line 226 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().

228 {
229  SCH_ITEM* newitem;
230 
231  if( aItemsList.GetCount() == 0 )
232  return;
233 
234  for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
235  {
236  newitem = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
237  aItemsList.SetPickedItem( newitem, ii );
238  aItemsList.SetPickedItemStatus( UR_NEW, ii );
239  {
240  switch( newitem->Type() )
241  {
242  case SCH_JUNCTION_T:
243  case SCH_LINE_T:
244  case SCH_BUS_BUS_ENTRY_T:
246  case SCH_TEXT_T:
247  case SCH_LABEL_T:
248  case SCH_GLOBAL_LABEL_T:
250  case SCH_SHEET_PIN_T:
251  case SCH_MARKER_T:
252  case SCH_NO_CONNECT_T:
253  default:
254  break;
255 
256  case SCH_SHEET_T:
257  {
258  SCH_SHEET* sheet = (SCH_SHEET*) newitem;
259  sheet->SetTimeStamp( GetNewTimeStamp() );
260  break;
261  }
262 
263  case SCH_COMPONENT_T:
264  ( (SCH_COMPONENT*) newitem )->SetTimeStamp( GetNewTimeStamp() );
265  ( (SCH_COMPONENT*) newitem )->ClearAnnotation( NULL );
266  break;
267  }
268 
269  SetSchItemParent( newitem, screen );
270  screen->Append( newitem );
271  }
272  }
273 
274  MoveItemsInList( aItemsList, aMoveVector );
275 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
void MoveItemsInList(PICKED_ITEMS_LIST &aItemsList, const wxPoint &aMoveVector)
Function MoveItemsInList Move a list of items to a given move vector.
void SetSchItemParent(SCH_ITEM *Struct, SCH_SCREEN *Screen)
timestamp_t GetNewTimeStamp()
Definition: common.cpp:166
bool SetPickedItem(EDA_ITEM *aItem, unsigned aIdx)
Function SetPickedItem.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
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)
Routine to create a new copy of given struct.
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:230
SCH_ITEM* DuplicateStruct ( SCH_ITEM aDrawStruct,
bool  aClone = false 
)

Routine to create 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 278 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().

279 {
280  wxCHECK_MSG( aDrawStruct != NULL, NULL,
281  wxT( "Cannot duplicate NULL schematic item! Bad programmer." ) );
282 
283  SCH_ITEM* NewDrawStruct = (SCH_ITEM*) aDrawStruct->Clone();
284 
285  if( aClone )
286  NewDrawStruct->SetTimeStamp( aDrawStruct->GetTimeStamp() );
287 
288  return NewDrawStruct;
289 }
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
timestamp_t GetTimeStamp() const
Definition: base_struct.h:231
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:230
void MirrorX ( PICKED_ITEMS_LIST aItemsList,
const 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:281
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,
const 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:281
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 108 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().

109 {
110  for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
111  {
112  SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
113  item->Move( aMoveVector );
114  }
115 }
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,
const 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:281
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:225
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:240