KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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) 2012 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2016 CERN
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 * @author Maciej Suminski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#include <functional>
29using namespace std::placeholders;
31#include <macros.h>
32#include <pcb_edit_frame.h>
33#include <pcb_track.h>
34#include <pcb_group.h>
35#include <pcb_shape.h>
36#include <pcb_generator.h>
37#include <footprint.h>
38#include <lset.h>
39#include <pad.h>
40#include <origin_viewitem.h>
42#include <tool/tool_manager.h>
43#include <tool/actions.h>
44#include <tools/pcb_actions.h>
46#include <tools/pcb_control.h>
48#include <board_commit.h>
50#include <wx/msgdlg.h>
51#include <pcb_board_outline.h>
52
53/* Functions to undo and redo edit commands.
54 * commands to undo are stored in CurrentScreen->m_UndoList
55 * commands to redo are stored in CurrentScreen->m_RedoList
56 *
57 * m_UndoList and m_RedoList handle a std::vector of PICKED_ITEMS_LIST
58 * Each PICKED_ITEMS_LIST handle a std::vector of pickers (class ITEM_PICKER),
59 * that store the list of schematic items that are concerned by the command to undo or redo
60 * and is created for each command to undo (handle also a command to redo).
61 * each picker has a pointer pointing to an item to undo or redo (in fact: deleted, added or
62 * modified),
63 * and has a pointer to a copy of this item, when this item has been modified
64 * (the old values of parameters are therefore saved)
65 *
66 * there are 3 cases:
67 * - delete item(s) command
68 * - change item(s) command
69 * - add item(s) command
70 *
71 * Undo command
72 * - delete item(s) command:
73 * => deleted items are moved in undo list
74 *
75 * - change item(s) command
76 * => A copy of item(s) is made (a DrawPickedStruct list of wrappers)
77 * the .m_Link member of each wrapper points the modified item.
78 * the .m_Item member of each wrapper points the old copy of this item.
79 *
80 * - add item(s) command
81 * =>A list of item(s) is made. The .m_Item member of each wrapper points the new item.
82 *
83 * Redo command
84 * - delete item(s) old command:
85 * => deleted items are moved in EEDrawList list, and in
86 *
87 * - change item(s) command
88 * => the copy of item(s) is moved in Undo list
89 *
90 * - add item(s) command
91 * => The list of item(s) is used to create a deleted list in undo list(same as a delete
92 * command)
93 *
94 * Some block operations that change items can be undone without memorize items, just the
95 * coordinates of the transform:
96 * move list of items (undo/redo is made by moving with the opposite move vector)
97 * mirror (Y) and flip list of items (undo/redo is made by mirror or flip items)
98 * so they are handled specifically.
99 *
100 */
101
102
104 const PICKED_ITEMS_LIST& aItemsList,
105 UNDO_REDO aCommandType )
106{
107 int preExisting = (int) commandToUndo->GetCount();
108
109 for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
110 commandToUndo->PushItem( aItemsList.GetItemWrapper(ii) );
111
112 for( unsigned ii = preExisting; ii < commandToUndo->GetCount(); ii++ )
113 {
114 EDA_ITEM* item = commandToUndo->GetPickedItem( ii );
115 UNDO_REDO command = commandToUndo->GetPickedItemStatus( ii );
116
117 if( command == UNDO_REDO::UNSPECIFIED )
118 {
119 command = aCommandType;
120 commandToUndo->SetPickedItemStatus( command, ii );
121 }
122
123 wxASSERT( item );
124
125 switch( command )
126 {
130 // If we don't yet have a copy in the link, set one up
131 if( !commandToUndo->GetPickedItemLink( ii ) )
132 commandToUndo->SetPickedItemLink( BOARD_COMMIT::MakeImage( item ), ii );
133
134 break;
135
139 break;
140
141 default:
142 wxFAIL_MSG( wxString::Format( wxT( "Unrecognized undo command: %X" ), command ) );
143 break;
144 }
145 }
146
147 if( commandToUndo->GetCount() )
148 {
149 /* Save the copy in undo list */
150 PushCommandToUndoList( commandToUndo );
151
152 /* Clear redo list, because after a new command one cannot redo a command */
154 }
155 else
156 {
157 // Should not occur
158 wxASSERT( false );
159 delete commandToUndo;
160 }
161}
162
163
165{
166 PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
167 PICKED_ITEMS_LIST itemsList;
168
169 itemsList.PushItem( ITEM_PICKER( nullptr, aItem, aCommandType ) );
170 saveCopyInUndoList( commandToUndo, itemsList, aCommandType );
171}
172
173
175 UNDO_REDO aCommandType )
176{
177 PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
178 commandToUndo->SetDescription( aItemsList.GetDescription() );
179
180 saveCopyInUndoList( commandToUndo, aItemsList, aCommandType );
181}
182
183
185 UNDO_REDO aCommandType )
186{
187 PICKED_ITEMS_LIST* commandToUndo = PopCommandFromUndoList();
188
189 if( !commandToUndo )
190 {
191 commandToUndo = new PICKED_ITEMS_LIST();
192 commandToUndo->SetDescription( aItemsList.GetDescription() );
193 }
194
195 saveCopyInUndoList( commandToUndo, aItemsList, aCommandType );
196}
197
198
204{
205 for( unsigned ii = 0; ii < aList->GetCount(); ++ii )
206 {
207 switch( aList->GetPickedItem( ii )->Type() )
208 {
209 case PCB_SHAPE_T:
210 case PCB_FOOTPRINT_T:
211 case PCB_TEXT_T:
212 case PCB_TEXTBOX_T:
213 case PCB_FIELD_T:
214 return true;
215
216 default:
217 break;
218 }
219 }
220
221 return false;
222}
223
224
226{
227 if( UndoRedoBlocked() )
228 return;
229
230 if( GetUndoCommandCount() <= 0 )
231 return;
232
233 // Inform tools that undo command was issued
234 m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
235
236 // Get the old list
238
239 bool shapesChanged = undoListContainsShapesOrFootprints( list );
240
241 // Undo the command
242 PutDataInPreviousState( list, shapesChanged );
243
244 // Put the old list in RedoList
245 list->ReversePickersListOrder();
246 PushCommandToRedoList( list );
247
248 OnModify();
249
252
253 if( shapesChanged )
254 {
255 m_pcb->UpdateBoardOutline();
256 GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
257 }
258
259 GetCanvas()->Refresh();
260}
261
262
264{
265 if( UndoRedoBlocked() )
266 return;
267
268 if( GetRedoCommandCount() == 0 )
269 return;
270
271 // Inform tools that redo command was issued
273
274 // Get the old list
276
277 bool shapesChanged = undoListContainsShapesOrFootprints( list );
278
279 // Redo the command
280 PutDataInPreviousState( list, shapesChanged );
281
282 // Put the old list in UndoList
283 list->ReversePickersListOrder();
284 PushCommandToUndoList( list );
285
286 OnModify();
287
290
291 if( shapesChanged )
292 {
293 m_pcb->UpdateBoardOutline();
294 GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
295 }
296
297 GetCanvas()->Refresh();
298}
299
300
302{
303 bool not_found = false;
304 bool reBuild_ratsnest = false;
305 bool deep_reBuild_ratsnest = false; // true later if pointers must be rebuilt
306 bool solder_mask_dirty = false;
307 bool current_show_ratsnest = GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest;
308 std::vector<BOX2I> dirty_rule_areas;
309
310 KIGFX::PCB_VIEW* view = GetCanvas()->GetView();
311 std::shared_ptr<CONNECTIVITY_DATA> connectivity = GetBoard()->GetConnectivity();
312
313 GetBoard()->IncrementTimeStamp(); // clear caches
314
315 // Enum to track the modification type of items. Used to enable bulk BOARD_LISTENER
316 // callbacks at the end of the undo / redo operation
317 enum ITEM_CHANGE_TYPE
318 {
319 ADDED,
320 DELETED,
321 CHANGED
322 };
323
324 std::unordered_map<EDA_ITEM*, ITEM_CHANGE_TYPE> item_changes;
325
326 auto clear_local_ratsnest_flags =
327 [&]( EDA_ITEM* item )
328 {
329 switch( item->Type() )
330 {
331 case PCB_TRACE_T:
332 case PCB_ARC_T:
333 case PCB_VIA_T:
334 static_cast<PCB_TRACK*>( item )->SetLocalRatsnestVisible( current_show_ratsnest );
335 break;
336
337 case PCB_ZONE_T:
338 static_cast<ZONE*>( item )->SetLocalRatsnestVisible( current_show_ratsnest );
339 break;
340
341 case PCB_FOOTPRINT_T:
342 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
343 pad->SetLocalRatsnestVisible( current_show_ratsnest );
344
345 break;
346
347 default:
348 break;
349 }
350 };
351
352 auto update_item_change_state =
353 [&]( EDA_ITEM* item, ITEM_CHANGE_TYPE change_type )
354 {
355 auto item_itr = item_changes.find( item );
356
357 if( item_itr == item_changes.end() )
358 {
359 // First time we've seen this item - tag the current change type
360 item_changes.insert( { item, change_type } );
361 return;
362 }
363
364 // Update the item state based on the current and next change type
365 switch( item_itr->second )
366 {
367 case ITEM_CHANGE_TYPE::ADDED:
368 if( change_type == ITEM_CHANGE_TYPE::DELETED )
369 {
370 // The item was previously added, now deleted - as far as bulk callbacks
371 // are concerned, the item has never existed
372 item_changes.erase( item_itr );
373 }
374 else if( change_type == ITEM_CHANGE_TYPE::ADDED )
375 {
376 // Error condition - added an already added item
377 wxASSERT_MSG( false, wxT( "UndoRedo: should not add already added item" ) );
378 }
379
380 // For all other cases, the item remains as ADDED as seen by the bulk callbacks
381 break;
382
383 case ITEM_CHANGE_TYPE::DELETED:
384 // This is an error condition - item has already been deleted so should not
385 // be operated on further
386 wxASSERT_MSG( false, wxT( "UndoRedo: should not alter already deleted item" ) );
387 break;
388
389 case ITEM_CHANGE_TYPE::CHANGED:
390 if( change_type == ITEM_CHANGE_TYPE::DELETED )
391 {
392 item_itr->second = ITEM_CHANGE_TYPE::DELETED;
393 }
394 else if( change_type == ITEM_CHANGE_TYPE::ADDED )
395 {
396 // This is an error condition - item has already been changed so should not
397 // be added
398 wxASSERT_MSG( false, wxT( "UndoRedo: should not add already changed item" ) );
399 }
400
401 // Otherwise, item remains CHANGED
402 break;
403 }
404 };
405
406 // Undo in the reverse order of list creation: (this can allow stacked changes
407 // like the same item can be changes and deleted in the same complex command
408
409 // Restore changes in reverse order
410 for( int ii = (int) aList->GetCount() - 1; ii >= 0 ; ii-- )
411 {
412 EDA_ITEM* eda_item = aList->GetPickedItem( (unsigned) ii );
413
414 /* Test for existence of item on board.
415 * It could be deleted, and no more on board:
416 * - if a call to SaveCopyInUndoList was forgotten in Pcbnew
417 * - in zones outlines, when a change in one zone merges this zone with an other
418 * This test avoids a Pcbnew crash
419 * Obviously, this test is not made for deleted items
420 */
421 UNDO_REDO status = aList->GetPickedItemStatus( ii );
422
423 if( status != UNDO_REDO::DELETED
424 && status != UNDO_REDO::DRILLORIGIN // origin markers never on board
425 && status != UNDO_REDO::GRIDORIGIN // origin markers never on board
426 && status != UNDO_REDO::PAGESETTINGS ) // nor are page settings proxy items
427 {
428 if( !GetBoard()->ResolveItem( eda_item->m_Uuid, true ) )
429 {
430 // Remove this non existent item
431 aList->RemovePicker( ii );
432 not_found = true;
433
434 if( aList->GetCount() == 0 )
435 break;
436
437 continue;
438 }
439 }
440
441 // see if we must rebuild ratsnets and pointers lists
442 switch( eda_item->Type() )
443 {
444 case PCB_FOOTPRINT_T:
445 deep_reBuild_ratsnest = true; // Pointers on pads can be invalid
447
448 case PCB_ZONE_T:
449 case PCB_TRACE_T:
450 case PCB_ARC_T:
451 case PCB_VIA_T:
452 case PCB_PAD_T:
453 reBuild_ratsnest = true;
454 break;
455
456 case PCB_NETINFO_T:
457 reBuild_ratsnest = true;
458 deep_reBuild_ratsnest = true;
459 break;
460
461 default:
462 break;
463 }
464
465 switch( eda_item->Type() )
466 {
467 case PCB_FOOTPRINT_T:
468 solder_mask_dirty = true;
469 break;
470
471 case PCB_VIA_T:
472 solder_mask_dirty = true;
473 break;
474
475 case PCB_ZONE_T:
476 case PCB_TRACE_T:
477 case PCB_ARC_T:
478 case PCB_PAD_T:
479 case PCB_SHAPE_T:
480 {
481 LSET layers = static_cast<BOARD_ITEM*>( eda_item )->GetLayerSet();
482
483 if( layers.test( F_Mask ) || layers.test( B_Mask ) )
484 solder_mask_dirty = true;
485
486 break;
487 }
488
489 default:
490 break;
491 }
492
493 switch( aList->GetPickedItemStatus( ii ) )
494 {
495 case UNDO_REDO::CHANGED: /* Exchange old and new data for each item */
496 if( eda_item->IsBOARD_ITEM() )
497 {
498 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( eda_item );
499 BOARD_ITEM* image = static_cast<BOARD_ITEM*>( aList->GetPickedItemLink( ii ) );
500 BOARD_ITEM_CONTAINER* parent = GetBoard();
501
502 if( item->GetParentFootprint() )
503 {
504 // We need the current item and it's parent, which may be different from what
505 // was stored if we're multiple frames up the undo stack.
506 item = GetBoard()->ResolveItem( item->m_Uuid );
507 parent = item->GetParentFootprint();
508 }
509
510 view->Remove( item );
511 parent->Remove( item );
512
513 item->SwapItemData( image );
514
515 clear_local_ratsnest_flags( item );
516 item->ClearFlags( UR_TRANSIENT );
517 image->SetFlags( UR_TRANSIENT );
518
519 view->Add( item );
520 view->Hide( item, false );
521 parent->Add( item );
522
523 if( item->Type() == PCB_ZONE_T && static_cast<ZONE*>( item )->GetIsRuleArea() )
524 {
525 dirty_rule_areas.push_back( item->GetBoundingBox() );
526 dirty_rule_areas.push_back( image->GetBoundingBox() );
527 }
528
529 update_item_change_state( item, ITEM_CHANGE_TYPE::CHANGED );
530 }
531
532 break;
533
534 case UNDO_REDO::NEWITEM: /* new items are deleted */
535 if( eda_item->IsBOARD_ITEM() )
536 {
538 GetModel()->Remove( static_cast<BOARD_ITEM*>( eda_item ), REMOVE_MODE::BULK );
539 update_item_change_state( eda_item, ITEM_CHANGE_TYPE::DELETED );
540
541 if( eda_item->Type() != PCB_NETINFO_T )
542 view->Remove( eda_item );
543
544 eda_item->SetFlags( UR_TRANSIENT );
545
546 if( eda_item->Type() == PCB_ZONE_T && static_cast<ZONE*>( eda_item )->GetIsRuleArea() )
547 dirty_rule_areas.push_back( eda_item->GetBoundingBox() );
548 }
549
550 break;
551
552 case UNDO_REDO::DELETED: /* deleted items are put in List, as new items */
553 if( eda_item->IsBOARD_ITEM() )
554 {
556
557 clear_local_ratsnest_flags( eda_item );
558 eda_item->ClearFlags( UR_TRANSIENT );
559
560 GetModel()->Add( static_cast<BOARD_ITEM*>( eda_item ), ADD_MODE::BULK_APPEND );
561 update_item_change_state( eda_item, ITEM_CHANGE_TYPE::ADDED );
562
563 if( eda_item->Type() != PCB_NETINFO_T )
564 view->Add( eda_item );
565
566 if( eda_item->Type() == PCB_ZONE_T && static_cast<ZONE*>( eda_item )->GetIsRuleArea() )
567 dirty_rule_areas.push_back( eda_item->GetBoundingBox() );
568 }
569
570 break;
571
574 {
575 // Warning: DRILLORIGIN and GRIDORIGIN undo/redo command create EDA_ITEMs
576 // that cannot be casted to BOARD_ITEMs
577 EDA_ITEM* image = aList->GetPickedItemLink( ii );
578 VECTOR2D origin = image->GetPosition();
579 image->SetPosition( eda_item->GetPosition() );
580
581 if( aList->GetPickedItemStatus( ii ) == UNDO_REDO::DRILLORIGIN )
582 BOARD_EDITOR_CONTROL::DoSetDrillOrigin( view, this, eda_item, origin );
583 else
584 PCB_CONTROL::DoSetGridOrigin( view, this, eda_item, origin );
585
586 break;
587 }
588
590 if( eda_item->Type() == WS_PROXY_UNDO_ITEM_T || eda_item->Type() == WS_PROXY_UNDO_ITEM_PLUS_T )
591 {
592 // swap current settings with stored settings
593 DS_PROXY_UNDO_ITEM alt_item( this );
594 DS_PROXY_UNDO_ITEM* item = static_cast<DS_PROXY_UNDO_ITEM*>( eda_item );
595 item->Restore( this );
596 *item = std::move( alt_item );
597 }
598
599 break;
600
601 default:
602 wxFAIL_MSG( wxString::Format( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
603 aList->GetPickedItemStatus( ii ) ) );
604 break;
605 }
606
607 if( eda_item->Type() == PCB_FOOTPRINT_T )
608 {
609 FOOTPRINT* fp = static_cast<FOOTPRINT*>( eda_item );
611 m_pcb->GetComponentClassManager().RebuildRequiredCaches( fp );
612 }
613 }
614
615 if( not_found )
616 wxMessageBox( _( "Incomplete undo/redo operation: some items not found" ) );
617
618 // We have now swapped all the group parent and group member pointers. But it is a
619 // risky proposition to bet on the pointers being invariant, so validate them all.
620 for( int ii = 0; ii < (int) aList->GetCount(); ++ii )
621 {
622 ITEM_PICKER& wrapper = aList->GetItemWrapper( ii );
623
624 if( wrapper.GetStatus() == UNDO_REDO::DELETED )
625 continue;
626
627 BOARD_ITEM* parentGroup = GetBoard()->ResolveItem( wrapper.GetGroupId(), true );
628 wrapper.GetItem()->SetParentGroup( dynamic_cast<PCB_GROUP*>( parentGroup ) );
629
630 if( EDA_GROUP* group = dynamic_cast<PCB_GROUP*>( wrapper.GetItem() ) )
631 {
632 // Items list may contain dodgy pointers, so don't use RemoveAll()
633 group->GetItems().clear();
634
635 for( const KIID& member : wrapper.GetGroupMembers() )
636 {
637 if( BOARD_ITEM* memberItem = GetBoard()->ResolveItem( member, true ) )
638 group->AddItem( memberItem );
639 }
640 }
641
642 // And prepare for a redo by updating group info based on current image
643 if( EDA_ITEM* item = wrapper.GetLink() )
644 wrapper.SetLink( item );
645 }
646
647 if( IsType( FRAME_PCB_EDITOR ) )
648 {
649 if( !dirty_rule_areas.empty() && ( GetPcbNewSettings()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
650 || GetPcbNewSettings()->m_Display.m_PadClearance ) )
651 {
652 view->UpdateCollidingItems( dirty_rule_areas, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T } );
653 }
654
655 if( reBuild_ratsnest || deep_reBuild_ratsnest )
656 {
657 // Connectivity may have changed; rebuild internal caches to remove stale items
659 Compile_Ratsnest( false );
660 }
661
662 if( solder_mask_dirty )
664 }
665
667
669 selTool->RebuildSelection();
670
672
673 // Invoke bulk BOARD_LISTENER callbacks
674 std::vector<BOARD_ITEM*> added_items, deleted_items, changed_items;
675
676 for( auto& [item, changeType] : item_changes )
677 {
678 switch( changeType )
679 {
680 case ITEM_CHANGE_TYPE::ADDED:
681 added_items.push_back( static_cast<BOARD_ITEM*>( item ) );
682 break;
683
684 case ITEM_CHANGE_TYPE::DELETED:
685 deleted_items.push_back( static_cast<BOARD_ITEM*>( item ) );
686 break;
687
688 case ITEM_CHANGE_TYPE::CHANGED:
689 changed_items.push_back( static_cast<BOARD_ITEM*>( item ) );
690 break;
691 }
692 }
693
694 if( aRehatchShapes )
696
697 if( added_items.size() > 0 || deleted_items.size() > 0 || changed_items.size() > 0 )
698 GetBoard()->OnItemsCompositeUpdate( added_items, deleted_items, changed_items );
699}
700
701
703{
704 if( aItemCount == 0 )
705 return;
706
707 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
708
709 if( aItemCount < 0 )
710 {
711 list.ClearCommandList();
712 }
713 else
714 {
715 for( int ii = 0; ii < aItemCount; ii++ )
716 {
717 if( list.m_CommandsList.size() == 0 )
718 break;
719
720 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
721 list.m_CommandsList.erase( list.m_CommandsList.begin() );
722 ClearListAndDeleteItems( curr_cmd );
723 delete curr_cmd; // Delete command
724 }
725 }
726}
727
728
730{
732 []( EDA_ITEM* item )
733 {
734 wxASSERT_MSG( item->HasFlag( UR_TRANSIENT ),
735 "Item on undo/redo list not owned by undo/redo!" );
736
737 delete item;
738 } );
739}
740
741
743{
747 delete undo;
748
749 m_pcb->UpdateBoardOutline();
750 GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
751 GetCanvas()->Refresh();
752}
static EDA_ITEM * MakeImage(EDA_ITEM *aItem)
static void DoSetDrillOrigin(KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, EDA_ITEM *aItem, const VECTOR2D &aPoint)
Abstract interface for BOARD_ITEMs capable of storing other items inside.
virtual void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL)=0
Removes an item from the container.
virtual void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)=0
Adds an item to the container.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
FOOTPRINT * GetParentFootprint() const
void SanitizeNetcodes()
Definition board.cpp:3212
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition board.cpp:191
void OnItemsCompositeUpdate(std::vector< BOARD_ITEM * > &aAddedItems, std::vector< BOARD_ITEM * > &aRemovedItems, std::vector< BOARD_ITEM * > &aChangedItems)
Notify the board and its listeners that items on the board have been modified in a composite operatio...
Definition board.cpp:3259
void IncrementTimeStamp()
Definition board.cpp:259
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
Definition board.h:1407
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:1780
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:563
void InvalidateComponentClasses()
Invalidates any caches component classes and recomputes caches if required.
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.
virtual int GetRedoCommandCount() const
UNDO_REDO_CONTAINER m_undoList
UNDO_REDO_LIST
Specify whether we are interacting with the undo or redo stacks.
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
Return the last command to undo and remove it from list, nothing is deleted.
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 int GetUndoCommandCount() const
virtual void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Add a command to redo in the redo list.
bool IsType(FRAME_T aType) const
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:99
virtual VECTOR2I GetPosition() const
Definition eda_item.h:278
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:120
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:148
const KIID m_Uuid
Definition eda_item.h:527
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:150
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:152
static const TOOL_EVENT UndoRedoPreEvent
Definition actions.h:368
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition actions.h:352
static const TOOL_EVENT UndoRedoPostEvent
Definition actions.h:369
void InvalidateComponentClassCache() const
Forces deferred (on next access) recalculation of the component class for this footprint.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition pcb_view.cpp:91
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:57
void UpdateCollidingItems(const std::vector< BOX2I > &aStaleAreas, std::initializer_list< KICAD_T > aTypes)
Sets the KIGFX::REPAINT on all items matching aTypes which intersect aStaleAreas.
Definition pcb_view.cpp:122
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition pcb_view.cpp:74
bool IsBOARD_ITEM() const
Definition view_item.h:102
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition view.cpp:1675
Definition kiid.h:49
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Definition pad.h:55
DISPLAY_OPTIONS m_Display
static TOOL_ACTION rehatchShapes
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Free the undo or redo list from List element.
void RestoreCopyFromUndoList(wxCommandEvent &aEvent)
Undo the last edit:
void saveCopyInUndoList(PICKED_ITEMS_LIST *commandToUndo, const PICKED_ITEMS_LIST &aItemsList, UNDO_REDO aCommandType)
void AppendCopyToUndoList(const PICKED_ITEMS_LIST &aItemsList, UNDO_REDO aCommandType) override
As SaveCopyInUndoList, but appends the changes to the last undo item on the stack.
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
void ClearListAndDeleteItems(PICKED_ITEMS_LIST *aList)
void RollbackFromUndo()
Perform an undo of the last edit without logging a corresponding redo.
bool UndoRedoBlocked() const
Check if the undo and redo operations are currently blocked.
void RestoreCopyFromRedoList(wxCommandEvent &aEvent)
Redo the last edit:
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList, bool aRehatchShapes=true)
Used in undo or redo command.
PCBNEW_SETTINGS * GetPcbNewSettings() const
void OnModify() override
Must be called after a change in order to set the "modify" flag and update other data structures and ...
EDA_ITEM * ResolveItem(const KIID &aId, bool aAllowNullptrReturn=false) const override
Fetch an item by KIID.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition ratsnest.cpp:36
static void DoSetGridOrigin(KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, EDA_ITEM *originViewItem, const VECTOR2D &aPoint)
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:53
The selection tool: currently supports:
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
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.
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
bool RemovePicker(unsigned aIdx)
Remove one entry (one picker) from the list of picked items.
const ITEM_PICKER & GetItemWrapper(unsigned int aIdx) const
unsigned GetCount() const
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...
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
TOOL_MANAGER * m_toolManager
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
A holder to handle a list of undo (or redo) commands.
Handle a list of polygons defining a copper zone.
Definition zone.h:73
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:719
#define _(s)
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack
@ FRAME_PCB_EDITOR
Definition frame_type.h:42
@ B_Mask
Definition layer_ids.h:98
@ F_Mask
Definition layer_ids.h:97
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition macros.h:83
Class to handle a set of BOARD_ITEMs.
@ SHOW_WITH_VIA_ALWAYS
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition tool_action.h:49
@ TA_UNDO_REDO_PRE
This event is sent before undo/redo command is performed.
Definition tool_event.h:106
@ TA_UNDO_REDO_POST
This event is sent after undo/redo command is performed.
Definition tool_event.h:109
@ TC_MESSAGE
Definition tool_event.h:58
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:97
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:93
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:108
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:92
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:90
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:86
@ WS_PROXY_UNDO_ITEM_T
Definition typeinfo.h:228
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:98
@ WS_PROXY_UNDO_ITEM_PLUS_T
Definition typeinfo.h:229
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:110
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:96
static bool undoListContainsShapesOrFootprints(const PICKED_ITEMS_LIST *aList)
Check whether the undo/redo list contains any items that could affect the board outline or shape hatc...
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
VECTOR2< double > VECTOR2D
Definition vector2d.h:694