KiCad PCB EDA Suite
operations_on_items_lists.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
31 #include <fctsys.h>
32 #include <pgm_base.h>
33 #include <class_drawpanel.h>
34 #include <schframe.h>
35 
36 #include <general.h>
37 #include <protos.h>
38 #include <sch_bus_entry.h>
39 #include <sch_marker.h>
40 #include <sch_line.h>
41 #include <sch_no_connect.h>
42 #include <sch_sheet.h>
43 #include <sch_component.h>
44 #include <sch_junction.h>
45 
46 
47 void SetSchItemParent( SCH_ITEM* Struct, SCH_SCREEN* Screen )
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 }
73 
74 
75 void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& rotationPoint )
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 }
84 
85 
86 void MirrorY( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint )
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 }
95 
96 
97 void MirrorX( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint )
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 }
106 
107 
114 void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector )
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 }
122 
123 
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 }
156 
157 
159 {
160  wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) );
161 
162  // Here, aItem is not null.
163 
164  SCH_SCREEN* screen = GetScreen();
165 
166  if( aItem->Type() == SCH_SHEET_PIN_T )
167  {
168  // This iten is attached to a node, and is not accessible by the global list directly.
169  SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent();
170  wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
171  wxT( "Sheet label has invalid parent item." ) );
173  sheet->RemovePin( (SCH_SHEET_PIN*) aItem );
175  }
176  else
177  {
178  screen->Remove( aItem );
179  SaveCopyInUndoList( aItem, UR_DELETED );
181  }
182 }
183 
184 
185 /* Routine to copy a new entity of an object for each object in list and
186  * reposition it.
187  * Return the new created object list in aItemsList
188  */
190  const wxPoint aMoveVector )
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 }
239 
240 
251 SCH_ITEM* DuplicateStruct( SCH_ITEM* aDrawStruct, bool aClone )
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 }
Definition of the SCH_SHEET class for Eeschema.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
void DuplicateItemsInList(SCH_SCREEN *screen, PICKED_ITEMS_LIST &aItemsList, const wxPoint aMoveVector)
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
void DeleteItem(SCH_ITEM *aItem)
Function DeleteItem removes aItem from the current screen and saves it in the undo list...
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))
Function SaveCopyInUndoList.
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
time_t GetNewTimeStamp()
Definition: common.cpp:166
EDA_ITEM * GetParent() const
Definition: base_struct.h:222
void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
Definition: draw_panel.cpp:305
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
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)
virtual void Rotate(wxPoint aPosition)=0
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:530
void RemovePin(SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:368
EDA_RECT const GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_sheet.cpp:680
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:227
bool SetPickedItem(EDA_ITEM *aItem, unsigned aIdx)
Function SetPickedItem.
void RotateListOfItems(PICKED_ITEMS_LIST &aItemsList, wxPoint &rotationPoint)
Class SCH_SHEET_PIN defines a sheet pin (label) used in sheets to create hierarchical schematics...
Definition: sch_sheet.h:62
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
virtual void MirrorX(int aXaxis_position)=0
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
virtual void MirrorY(int aYaxis_position)=0
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
time_t GetTimeStamp() const
Definition: base_struct.h:218
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.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
Definition the SCH_COMPONENT class for Eeschema.
see class PGM_BASE
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)
void DeleteItemsInList(EDA_DRAW_PANEL *panel, PICKED_ITEMS_LIST &aItemsList)
Function DeleteItemsInList delete schematic items in aItemsList deleted items are put in undo list...
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
void MirrorY(PICKED_ITEMS_LIST &aItemsList, wxPoint &aMirrorPoint)
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
void MirrorX(PICKED_ITEMS_LIST &aItemsList, wxPoint &aMirrorPoint)
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.
virtual void Move(const wxPoint &aMoveVector)=0
Function Move moves the item by aMoveVector to a new position.