KiCad PCB EDA Suite
Loading...
Searching...
No Matches
schematic_undo_redo.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) 2004 Jean-Pierre Charras, [email protected]
5 * Copyright The KiCad Developers, see AUTHORS.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
25#include <sch_actions.h>
26#include <sch_edit_frame.h>
27#include <tool/tool_manager.h>
28#include <schematic.h>
29#include <sch_bus_entry.h>
30#include <sch_commit.h>
31#include <sch_group.h>
32#include <sch_junction.h>
33#include <sch_line.h>
34#include <sch_bitmap.h>
35#include <sch_sheet_pin.h>
36#include <sch_table.h>
39#include <tool/actions.h>
40#include <wx/log.h>
41
42
43/* Functions to undo and redo edit commands.
44 *
45 * m_UndoList and m_RedoList handle a std::vector of PICKED_ITEMS_LIST
46 * Each PICKED_ITEMS_LIST handle a std::vector of pickers (class ITEM_PICKER),
47 * that store the list of schematic items that are concerned by the command to
48 * undo or redo and is created for each command to undo (handle also a command
49 * to redo). each picker has a pointer pointing to an item to undo or redo (in
50 * fact: deleted, added or modified), and has a pointer to a copy of this item,
51 * when this item has been modified (the old values of parameters are
52 * therefore saved)
53 *
54 * there are 3 cases:
55 * - delete item(s) command
56 * - change item(s) command
57 * - add item(s) command
58 * and 2 cases for block:
59 * - move list of items
60 * - mirror (Y) list of items
61 *
62 * Undo command
63 * - delete item(s) command:
64 * => deleted items are moved in undo list
65 *
66 * - change item(s) command
67 * => A copy of item(s) is made (a DrawPickedStruct list of wrappers)
68 * the .m_Link member of each wrapper points the modified item.
69 * the .m_Item member of each wrapper points the old copy of this item.
70 *
71 * - add item(s) command
72 * =>A list of item(s) is made. The .m_Item member of each wrapper points
73 * the new item.
74 *
75 * Redo command
76 * - delete item(s) old command:
77 * => deleted items are moved into m_tree
78 *
79 * - change item(s) command
80 * => the copy of item(s) is moved in Undo list
81 *
82 * - add item(s) command
83 * => The list of item(s) is used to create a deleted list in undo
84 * list(same as a delete command)
85 *
86 * Some block operations that change items can be undone without memorized
87 * items, just the coordinates of the transform: move list of items (undo/
88 * redo is made by moving with the opposite move vector) mirror (Y) and flip
89 * list of items (undo/redo is made by mirror or flip items) so they are
90 * handled specifically.
91 *
92 * A problem is the hierarchical sheet handling.
93 * the data associated (sub-hierarchy, undo/redo list) is deleted only
94 * when the sheet is really deleted (i.e. when deleted from undo or redo list)
95 * This is handled by its destructor.
96 */
97
98
99/* Used if undo / redo command:
100 * swap data between Item and its copy, pointed by its picked item link member
101 * swapped data is data modified by editing, so not all values are swapped
102 */
103
105 UNDO_REDO aCommandType, bool aAppend,
106 bool aDirtyConnectivity )
107{
108 PICKED_ITEMS_LIST* commandToUndo = nullptr;
109
110 wxCHECK( aItem, /* void */ );
111
112 if( aDirtyConnectivity )
113 {
114 if( !aItem->IsConnectivityDirty() && aItem->Connection()
115 && ( aItem->Connection()->Name() == m_highlightedConn
116 || aItem->Connection()->HasDriverChanged() ) )
117 {
119 }
120
121 aItem->SetConnectivityDirty();
122 }
123
125
126 // If the last stack was empty, use that one instead of creating a new stack
127 if( lastUndo )
128 {
129 if( aAppend || !lastUndo->GetCount() )
130 commandToUndo = lastUndo;
131 else
132 PushCommandToUndoList( lastUndo );
133 }
134
135 if( !commandToUndo )
136 {
137 commandToUndo = new PICKED_ITEMS_LIST();
138 }
139
140 ITEM_PICKER itemWrapper( aScreen, aItem, aCommandType );
141 itemWrapper.SetFlags( aItem->GetFlags() );
142
143 switch( aCommandType )
144 {
145 case UNDO_REDO::CHANGED: /* Create a copy of item */
146 itemWrapper.SetLink( aItem->Duplicate( IGNORE_PARENT_GROUP, nullptr, true ) );
147 commandToUndo->PushItem( itemWrapper );
148 break;
149
150 case UNDO_REDO::NEWITEM:
151 case UNDO_REDO::DELETED:
152 commandToUndo->PushItem( itemWrapper );
153 break;
154
155 default:
156 wxFAIL_MSG( wxString::Format( wxT( "SaveCopyInUndoList() error (unknown code %X)" ),
157 aCommandType ) );
158 break;
159 }
160
161 if( commandToUndo->GetCount() )
162 {
163 /* Save the copy in undo list */
164 PushCommandToUndoList( commandToUndo );
165
166 /* Clear redo list, because after new save there is no redo to do */
168 }
169 else
170 {
171 delete commandToUndo;
172 }
173}
174
175
177 UNDO_REDO aTypeCommand, bool aAppend,
178 bool aDirtyConnectivity )
179{
180 PICKED_ITEMS_LIST* commandToUndo = nullptr;
181
182 if( !aItemsList.GetCount() )
183 return;
184
186
187 // If the last stack was empty, use that one instead of creating a new stack
188 if( lastUndo )
189 {
190 if( aAppend || !lastUndo->GetCount() )
191 commandToUndo = lastUndo;
192 else
193 PushCommandToUndoList( lastUndo );
194 }
195
196 if( !commandToUndo )
197 {
198 commandToUndo = new PICKED_ITEMS_LIST();
199 commandToUndo->SetDescription( aItemsList.GetDescription() );
200 }
201
202 // Copy picker list:
203 if( !commandToUndo->GetCount() )
204 {
205 commandToUndo->CopyList( aItemsList );
206
207 for( const std::unique_ptr<SCH_ITEM>& item : GetRepeatItems() )
208 {
209 EDA_ITEM* repeatItemClone = item->Clone();
210 repeatItemClone->SetFlags( UR_TRANSIENT );
211
212 ITEM_PICKER repeatItemPicker( nullptr, repeatItemClone, UNDO_REDO::REPEAT_ITEM );
213 commandToUndo->PushItem( repeatItemPicker );
214 }
215 }
216 else
217 {
218 // Unless we are appending, in which case, get the picker items
219 for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
220 commandToUndo->PushItem( aItemsList.GetItemWrapper( ii) );
221 }
222
223 // Verify list, and creates data if needed
224 for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ )
225 {
226 SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( commandToUndo->GetPickedItem( ii ) );
227
228 // Common items implemented in EDA_DRAW_FRAME will not be SCH_ITEMs.
229 if( !sch_item )
230 continue;
231
232 UNDO_REDO command = commandToUndo->GetPickedItemStatus( ii );
233
234 if( command == UNDO_REDO::UNSPECIFIED )
235 {
236 command = aTypeCommand;
237 commandToUndo->SetPickedItemStatus( command, ii );
238 }
239
240 switch( command )
241 {
242 case UNDO_REDO::CHANGED:
243
244 /* If needed, create a copy of item, and put in undo list
245 * in the picker, as link
246 * If this link is not null, the copy is already done
247 */
248 if( commandToUndo->GetPickedItemLink( ii ) == nullptr )
249 commandToUndo->SetPickedItemLink( sch_item->Duplicate( IGNORE_PARENT_GROUP, nullptr, true ), ii );
250
251 wxASSERT( commandToUndo->GetPickedItemLink( ii ) );
252 break;
253
254 case UNDO_REDO::NEWITEM:
255 case UNDO_REDO::DELETED:
256 case UNDO_REDO::PAGESETTINGS:
257 case UNDO_REDO::REPEAT_ITEM:
258 break;
259
260 default:
261 wxFAIL_MSG( wxString::Format( wxT( "Unknown undo/redo command %d" ), command ) );
262 break;
263 }
264 }
265
266 if( commandToUndo->GetCount() )
267 {
268 /* Save the copy in undo list */
269 PushCommandToUndoList( commandToUndo );
270
271 /* Clear redo list, because after new save there is no redo to do */
273 }
274 else // Should not occur
275 {
276 delete commandToUndo;
277 }
278}
279
280
282{
283 std::vector<SCH_ITEM*> bulkAddedItems;
284 std::vector<SCH_ITEM*> bulkRemovedItems;
285 std::vector<SCH_ITEM*> bulkChangedItems;
286 std::set<SCH_TABLE*> changedTables;
287 bool dirtyConnectivity = false;
288 bool rebuildHierarchyNavigator = false;
289 bool refreshHierarchy = false;
290 SCH_CLEANUP_FLAGS connectivityCleanUp = NO_CLEANUP;
292 bool clearedRepeatItems = false;
293
294 // Undo in the reverse order of list creation: (this can allow stacked changes like the
295 // same item can be changed and deleted in the same complex command).
296 // After hitting 0, subtracting 1 will roll the value over to its max representation
297 for( unsigned ii = aList->GetCount() - 1; ii < std::numeric_limits<unsigned>::max(); ii-- )
298 {
299 UNDO_REDO status = aList->GetPickedItemStatus( ii );
300 EDA_ITEM* eda_item = aList->GetPickedItem( ii );
301 SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( aList->GetScreenForItem( ii ) );
302 SCH_SHEET_PATH undoSheet = sheets.FindSheetForScreen( screen );
303
304 eda_item->SetFlags( aList->GetPickerFlags( ii ) );
305 eda_item->ClearEditFlags();
306 eda_item->ClearTempFlags();
307
308 // Set connectable object connectivity status.
309 auto propagateConnectivityDamage =
310 [&]( SCH_ITEM* schItem )
311 {
312 if( schItem->IsConnectable() )
313 {
314 schItem->SetConnectivityDirty();
315
316 if( schItem->Type() == SCH_SYMBOL_T )
317 {
318 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( schItem );
319
320 wxCHECK( symbol, /* void */ );
321
322 for( SCH_PIN* pin : symbol->GetPins( &undoSheet ) )
323 pin->SetConnectivityDirty();
324 }
325 else if( schItem->Type() == SCH_SHEET_T )
326 {
327 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( schItem );
328
329 wxCHECK( sheet, /* void */ );
330
331 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
332 pin->SetConnectivityDirty();
333 }
334
336 dirtyConnectivity = true;
337
338 // Do a local clean up if there are any connectable objects in the commit
339 if( connectivityCleanUp == NO_CLEANUP )
340 connectivityCleanUp = LOCAL_CLEANUP;
341
342 // Do a full rebauild of the connectivity if there is a sheet in the commit
343 if( schItem->Type() == SCH_SHEET_T )
344 connectivityCleanUp = GLOBAL_CLEANUP;
345 }
346 else if( schItem->Type() == SCH_RULE_AREA_T )
347 {
348 dirtyConnectivity = true;
349 }
350 };
351
352 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( eda_item );
353
354 if( status == UNDO_REDO::NEWITEM )
355 {
356 if( schItem )
357 propagateConnectivityDamage( schItem );
358
359 // If we are removing the current sheet, get out first
360 if( eda_item->Type() == SCH_SHEET_T )
361 {
362 rebuildHierarchyNavigator = true;
363 refreshHierarchy = true;
364
365 if( static_cast<SCH_SHEET*>( eda_item )->GetScreen() == GetScreen() )
367 }
368
369 RemoveFromScreen( eda_item, screen );
370 aList->SetPickedItemStatus( UNDO_REDO::DELETED, ii );
371
372 bulkRemovedItems.emplace_back( schItem );
373 }
374 else if( status == UNDO_REDO::DELETED )
375 {
376 if( eda_item->Type() == SCH_SHEET_T )
377 {
378 rebuildHierarchyNavigator = true;
379 refreshHierarchy = true;
380 }
381
382 if( schItem )
383 propagateConnectivityDamage( schItem );
384
385 // deleted items are re-inserted on undo
386 AddToScreen( eda_item, screen );
387 aList->SetPickedItemStatus( UNDO_REDO::NEWITEM, ii );
388
389 bulkAddedItems.emplace_back( schItem );
390 }
391 else if( status == UNDO_REDO::PAGESETTINGS )
392 {
393 if( GetCurrentSheet() != undoSheet )
394 {
395 SetCurrentSheet( undoSheet );
397 }
398
399 // swap current settings with stored settings
400 DS_PROXY_UNDO_ITEM alt_item( this );
401 DS_PROXY_UNDO_ITEM* item = static_cast<DS_PROXY_UNDO_ITEM*>( eda_item );
402 item->Restore( this );
403 *item = std::move( alt_item );
404 }
405 else if( status == UNDO_REDO::REPEAT_ITEM )
406 {
407 if( !clearedRepeatItems )
408 {
410 clearedRepeatItems = true;
411 }
412
413 if( schItem )
414 {
415 propagateConnectivityDamage( schItem );
416 AddCopyForRepeatItem( schItem );
417
418 if( schItem->Type() == SCH_SHEET_T )
419 {
420 rebuildHierarchyNavigator = true;
421 refreshHierarchy = true;
422 }
423 }
424 }
425 else if( schItem )
426 {
427 SCH_ITEM* itemCopy = dynamic_cast<SCH_ITEM*>( aList->GetPickedItemLink( ii ) );
428
429 wxCHECK2( itemCopy, continue );
430
431 if( schItem->HasConnectivityChanges( itemCopy, &GetCurrentSheet() ) )
432 propagateConnectivityDamage( schItem );
433
434 // The root sheet is a pseudo object that owns the root screen object but is not on
435 // the root screen so do not attempt to remove it from the screen it owns.
436 if( schItem != &Schematic().Root() )
437 RemoveFromScreen( schItem, screen );
438
439 switch( status )
440 {
441 case UNDO_REDO::CHANGED:
442 if( schItem->Type() == SCH_SHEET_T )
443 {
444 const SCH_SHEET* origSheet = static_cast<const SCH_SHEET*>( schItem );
445 const SCH_SHEET* copySheet = static_cast<const SCH_SHEET*>( itemCopy );
446
447 wxCHECK2( origSheet && copySheet, continue );
448
449 if( ( origSheet->GetName() != copySheet->GetName() )
450 || ( origSheet->GetFileName() != copySheet->GetFileName() )
451 || origSheet->HasPageNumberChanges( *copySheet ) )
452 {
453 rebuildHierarchyNavigator = true;
454 }
455
456 // Sheet name changes do not require rebuilding the hiearchy.
457 if( ( origSheet->GetFileName() != copySheet->GetFileName() )
458 || origSheet->HasPageNumberChanges( *copySheet ) )
459 {
460 refreshHierarchy = true;
461 }
462 }
463
464 schItem->SwapItemData( itemCopy );
465
466 bulkChangedItems.emplace_back( schItem );
467
468 // Special cases for items which have instance data
469 if( schItem->GetParent() && schItem->GetParent()->Type() == SCH_SYMBOL_T
470 && schItem->Type() == SCH_FIELD_T )
471 {
472 SCH_FIELD* field = static_cast<SCH_FIELD*>( schItem );
473 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( schItem->GetParent() );
474
475 if( field->GetId() == FIELD_T::REFERENCE )
476 {
477 // Lazy eval of sheet list; this is expensive even when unsorted
478 if( sheets.empty() )
479 sheets = m_schematic->Hierarchy();
480
481 SCH_SHEET_PATH sheet = sheets.FindSheetForScreen( screen );
482 symbol->SetRef( &sheet, field->GetText() );
483 }
484
485 bulkChangedItems.emplace_back( symbol );
486 }
487
488 break;
489
490 default:
491 wxFAIL_MSG( wxString::Format( wxT( "Unknown undo/redo command %d" ),
492 aList->GetPickedItemStatus( ii ) ) );
493 break;
494 }
495
496 if( schItem->Type() == SCH_SYMBOL_T )
497 {
498 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( schItem );
499 sym->UpdatePins();
500 }
501
502 if( schItem != &Schematic().Root() )
503 AddToScreen( schItem, screen );
504 }
505 }
506
507 // We have now swapped all the group parent and group member pointers. But it is a
508 // risky proposition to bet on the pointers being invariant, so validate them all.
509 for( int ii = 0; ii < (int) aList->GetCount(); ++ii )
510 {
511 ITEM_PICKER& wrapper = aList->GetItemWrapper( ii );
512
513 SCH_ITEM* parentGroup = Schematic().ResolveItem( wrapper.GetGroupId(), nullptr, true );
514 wrapper.GetItem()->SetParentGroup( dynamic_cast<SCH_GROUP*>( parentGroup ) );
515
516 if( EDA_GROUP* group = dynamic_cast<SCH_GROUP*>( wrapper.GetItem() ) )
517 {
518 // Items list may contain dodgy pointers, so don't use RemoveAll()
519 group->GetItems().clear();
520
521 for( const KIID& member : wrapper.GetGroupMembers() )
522 {
523 if( SCH_ITEM* memberItem = Schematic().ResolveItem( member, nullptr, true ) )
524 group->AddItem( memberItem );
525 }
526 }
527
528 // And prepare for a redo by updating group info based on current image
529 if( EDA_ITEM* item = wrapper.GetLink() )
530 wrapper.SetLink( item );
531 }
532
534
535 // Notify our listeners
536 if( bulkAddedItems.size() > 0 )
537 Schematic().OnItemsAdded( bulkAddedItems );
538
539 if( bulkRemovedItems.size() > 0 )
540 Schematic().OnItemsRemoved( bulkRemovedItems );
541
542 if( bulkChangedItems.size() > 0 )
543 Schematic().OnItemsChanged( bulkChangedItems );
544
545 if( refreshHierarchy )
547
548 if( dirtyConnectivity )
549 {
550 wxLogTrace( wxS( "CONN_PROFILE" ),
551 wxS( "Undo/redo %s clean up connectivity rebuild." ),
552 ( connectivityCleanUp == LOCAL_CLEANUP ) ? wxS( "local" ) : wxS( "global" ) );
553
554 SCH_COMMIT localCommit( m_toolManager );
555
556 RecalculateConnections( &localCommit, connectivityCleanUp );
557
558 if( connectivityCleanUp == GLOBAL_CLEANUP )
560
561 // Restore hop over shapes of wires, if any
562 if( eeconfig()->m_Appearance.show_hop_over )
563 {
564 for( SCH_ITEM* item : GetScreen()->Items() )
565 {
566 if( item->Type() != SCH_LINE_T )
567 continue;
568
569 SCH_LINE* line = static_cast<SCH_LINE*>( item );
570
571 if( line->IsWire() )
572 UpdateHopOveredWires( line );
573 }
574 }
575 }
576
577 // Update the hierarchy navigator when there are sheet changes.
578 if( rebuildHierarchyNavigator )
580}
581
582
584{
586
587 // Skip empty frames
588 while( undo && !undo->GetCount() )
589 {
590 delete undo;
592 }
593
594 if( undo )
595 {
597 undo->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
598 {
599 delete aItem;
600 } );
601
602 delete undo;
603
604 m_toolManager->GetTool<SCH_SELECTION_TOOL>()->RebuildSelection();
605 }
606
607 GetCanvas()->Refresh();
608}
609
610
612{
613 if( aItemCount == 0 )
614 return;
615
616 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
617
618 if( aItemCount < 0 )
619 {
620 list.ClearCommandList();
621 }
622 else
623 {
624 for( int ii = 0; ii < aItemCount; ii++ )
625 {
626 if( list.m_CommandsList.size() == 0 )
627 break;
628
629 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
630 list.m_CommandsList.erase( list.m_CommandsList.begin() );
631
632 curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
633 {
634 delete aItem;
635 } );
636 delete curr_cmd; // Delete command
637 }
638 }
639}
640
641
void Restore(EDA_DRAW_FRAME *aFrame, KIGFX::VIEW *aView=nullptr)
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
UNDO_REDO_CONTAINER m_undoList
UNDO_REDO_LIST
Specify whether we are interacting with the undo or redo stacks.
UNDO_REDO_CONTAINER m_redoList
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A set of EDA_ITEMs (i.e., without duplicates).
Definition: eda_group.h:46
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:97
virtual void ClearEditFlags()
Definition: eda_item.h:155
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:141
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:109
EDA_ITEM * GetParent() const
Definition: eda_item.h:111
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:118
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:144
virtual void ClearTempFlags()
Definition: eda_item.h:168
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
void SetLink(EDA_ITEM *aItem)
void SetFlags(EDA_ITEM_FLAGS aFlags)
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:194
Definition: kiid.h:49
A holder to handle information on schematic or board items.
bool SetPickedItemStatus(UNDO_REDO aStatus, unsigned aIdx)
Set the type of undo/redo operation for a given picked item.
EDA_ITEM_FLAGS GetPickerFlags(unsigned aIdx) const
Return the value of the picker flag.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void SetDescription(const wxString &aDescription)
UNDO_REDO GetPickedItemStatus(unsigned int aIdx) const
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
wxString GetDescription() const
const ITEM_PICKER & GetItemWrapper(unsigned int aIdx) const
unsigned GetCount() const
void CopyList(const PICKED_ITEMS_LIST &aSource)
Copy all data from aSource to the list.
bool SetPickedItemLink(EDA_ITEM *aLink, unsigned aIdx)
Set the link associated to a given picked item.
void ClearListAndDeleteItems(std::function< void(EDA_ITEM *)> aItemDeleter)
Delete the list of pickers AND the data pointed by #m_PickedItem or #m_PickedItemLink according to th...
BASE_SCREEN * GetScreenForItem(unsigned int aIdx) const
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
void OnItemsAdded(std::vector< SCH_ITEM * > &aNewItems)
Must be used if Add() is used using a BULK_x ADD_MODE to generate a change event for listeners.
Definition: schematic.cpp:796
void OnItemsRemoved(std::vector< SCH_ITEM * > &aRemovedItems)
Must be used if Remove() is used using a BULK_x REMOVE_MODE to generate a change event for listeners.
Definition: schematic.cpp:802
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition: schematic.h:130
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:219
SCH_SHEET & Root() const
Definition: schematic.h:136
void RefreshHierarchy()
Definition: schematic.cpp:227
void OnItemsChanged(std::vector< SCH_ITEM * > &aItems)
Notify the schematic and its listeners that an item on the schematic has been modified in some way.
Definition: schematic.cpp:808
static TOOL_ACTION leaveSheet
Definition: sch_actions.h:220
void RemoveFromScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen) override
Remove an item from the screen (and view) aScreen is the screen the item is located on,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EESCHEMA_SETTINGS * eeconfig() const
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr) override
Add an item to the screen (and view) aScreen is the screen the item is located on,...
bool HasDriverChanged() const
wxString Name(bool aIgnoreSheet=false) const
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void RollbackSchematicFromUndo()
Perform an undo of the last edit without logging a corresponding redo.
bool m_highlightedConnChanged
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Free the undo or redo list from aList element.
SCHEMATIC * m_schematic
The currently loaded schematic.
SCH_SHEET_PATH & GetCurrentSheet() const
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr)
Generate the connection data for the entire schematic hierarchy.
SCHEMATIC & Schematic() const
const std::vector< std::unique_ptr< SCH_ITEM > > & GetRepeatItems() const
Return the items which are to be repeated with the insert key.
void UpdateHierarchyNavigator(bool aRefreshNetNavigator=true, bool aClear=false)
Update the hierarchy navigation tree and history.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void ClearRepeatItemsList()
Clear the list of items which are to be repeated with the insert key.
EDA_ITEM * ResolveItem(const KIID &aId, bool aAllowNullptrReturn=false) const override
Fetch an item by KIID.
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
void DisplayCurrentSheet()
Draw the current sheet on the display.
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList)
Restore an undo or redo command to put data pointed by aList in the previous state.
void AddCopyForRepeatItem(const SCH_ITEM *aItem)
wxString m_highlightedConn
The highlighted net or bus or empty string.
void UpdateHopOveredWires(SCH_ITEM *aItem)
FIELD_T GetId() const
Definition: sch_field.h:115
A set of SCH_ITEMs (i.e., without duplicates).
Definition: sch_group.h:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:159
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:557
bool IsConnectivityDirty() const
Definition: sch_item.h:555
virtual bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const
Check if aItem has connectivity changes against this object.
Definition: sch_item.h:574
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:318
void SwapItemData(SCH_ITEM *aImage)
Swap data between aItem and aImage.
Definition: sch_item.cpp:452
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:42
bool IsWire() const
Return true if the line is a wire.
Definition: sch_line.cpp:937
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_SHEET_PATH FindSheetForScreen(const SCH_SCREEN *aScreen)
Return the first SCH_SHEET_PATH object (not necessarily the only one) using a particular screen.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:47
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:321
wxString GetName() const
Definition: sch_sheet.h:113
bool HasPageNumberChanges(const SCH_SHEET &aOther) const
Check if the instance data of this sheet has any changes compared to aOther.
Definition: sch_sheet.cpp:1475
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:187
Schematic symbol object.
Definition: sch_symbol.h:75
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:288
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:592
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:171
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
A holder to handle a list of undo (or redo) commands.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
#define IGNORE_PARENT_GROUP
Definition: eda_item.h:54
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack
Class to handle a set of SCH_ITEMs.
SCH_CLEANUP_FLAGS
Definition: schematic.h:73
@ LOCAL_CLEANUP
Definition: schematic.h:75
@ NO_CLEANUP
Definition: schematic.h:74
@ GLOBAL_CLEANUP
Definition: schematic.h:76
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_SHEET_T
Definition: typeinfo.h:175
@ SCH_RULE_AREA_T
Definition: typeinfo.h:170
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...