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, see <https://www.gnu.org/licenses/>.
22 */
23
24#include <functional>
25using namespace std::placeholders;
27#include <macros.h>
28#include <pcb_edit_frame.h>
29#include <pcb_track.h>
30#include <pcb_group.h>
31#include <pcb_shape.h>
32#include <pcb_generator.h>
33#include <footprint.h>
34#include <lset.h>
35#include <pad.h>
36#include <origin_viewitem.h>
38#include <tool/tool_manager.h>
39#include <tool/actions.h>
40#include <tools/pcb_actions.h>
42#include <tools/pcb_control.h>
44#include <board_commit.h>
46#include <wx/msgdlg.h>
47#include <pcb_board_outline.h>
48
49/* Functions to undo and redo edit commands.
50 * commands to undo are stored in CurrentScreen->m_UndoList
51 * commands to redo are stored in CurrentScreen->m_RedoList
52 *
53 * m_UndoList and m_RedoList handle a std::vector of PICKED_ITEMS_LIST
54 * Each PICKED_ITEMS_LIST handle a std::vector of pickers (class ITEM_PICKER),
55 * that store the list of schematic items that are concerned by the command to undo or redo
56 * and is created for each command to undo (handle also a command to redo).
57 * each picker has a pointer pointing to an item to undo or redo (in fact: deleted, added or
58 * modified),
59 * and has a pointer to a copy of this item, when this item has been modified
60 * (the old values of parameters are therefore saved)
61 *
62 * there are 3 cases:
63 * - delete item(s) command
64 * - change item(s) command
65 * - add item(s) command
66 *
67 * Undo command
68 * - delete item(s) command:
69 * => deleted items are moved in undo list
70 *
71 * - change item(s) command
72 * => A copy of item(s) is made (a DrawPickedStruct list of wrappers)
73 * the .m_Link member of each wrapper points the modified item.
74 * the .m_Item member of each wrapper points the old copy of this item.
75 *
76 * - add item(s) command
77 * =>A list of item(s) is made. The .m_Item member of each wrapper points the new item.
78 *
79 * Redo command
80 * - delete item(s) old command:
81 * => deleted items are moved in EEDrawList list, and in
82 *
83 * - change item(s) command
84 * => the copy of item(s) is moved in Undo list
85 *
86 * - add item(s) command
87 * => The list of item(s) is used to create a deleted list in undo list(same as a delete
88 * command)
89 *
90 * Some block operations that change items can be undone without memorize items, just the
91 * coordinates of the transform:
92 * move list of items (undo/redo is made by moving with the opposite move vector)
93 * mirror (Y) and flip list of items (undo/redo is made by mirror or flip items)
94 * so they are handled specifically.
95 *
96 */
97
98
100 const PICKED_ITEMS_LIST& aItemsList,
101 UNDO_REDO aCommandType )
102{
103 int preExisting = (int) commandToUndo->GetCount();
104
105 for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
106 commandToUndo->PushItem( aItemsList.GetItemWrapper(ii) );
107
108 for( unsigned ii = preExisting; ii < commandToUndo->GetCount(); ii++ )
109 {
110 EDA_ITEM* item = commandToUndo->GetPickedItem( ii );
111 UNDO_REDO command = commandToUndo->GetPickedItemStatus( ii );
112
113 if( command == UNDO_REDO::UNSPECIFIED )
114 {
115 command = aCommandType;
116 commandToUndo->SetPickedItemStatus( command, ii );
117 }
118
119 wxASSERT( item );
120
121 switch( command )
122 {
126 // If we don't yet have a copy in the link, set one up
127 if( !commandToUndo->GetPickedItemLink( ii ) )
128 commandToUndo->SetPickedItemLink( BOARD_COMMIT::MakeImage( item ), ii );
129
130 break;
131
135 break;
136
137 default:
138 wxFAIL_MSG( wxString::Format( wxT( "Unrecognized undo command: %X" ), command ) );
139 break;
140 }
141 }
142
143 if( commandToUndo->GetCount() )
144 {
145 /* Save the copy in undo list */
146 PushCommandToUndoList( commandToUndo );
147
148 /* Clear redo list, because after a new command one cannot redo a command */
150 }
151 else
152 {
153 // Should not occur
154 wxASSERT( false );
155 delete commandToUndo;
156 }
157}
158
159
161{
162 PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
163 PICKED_ITEMS_LIST itemsList;
164
165 itemsList.PushItem( ITEM_PICKER( nullptr, aItem, aCommandType ) );
166 saveCopyInUndoList( commandToUndo, itemsList, aCommandType );
167}
168
169
171 UNDO_REDO aCommandType )
172{
173 PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
174 commandToUndo->SetDescription( aItemsList.GetDescription() );
175
176 saveCopyInUndoList( commandToUndo, aItemsList, aCommandType );
177}
178
179
181 UNDO_REDO aCommandType )
182{
183 PICKED_ITEMS_LIST* commandToUndo = PopCommandFromUndoList();
184
185 if( !commandToUndo )
186 {
187 commandToUndo = new PICKED_ITEMS_LIST();
188 commandToUndo->SetDescription( aItemsList.GetDescription() );
189 }
190
191 saveCopyInUndoList( commandToUndo, aItemsList, aCommandType );
192}
193
194
200{
201 for( unsigned ii = 0; ii < aList->GetCount(); ++ii )
202 {
203 switch( aList->GetPickedItem( ii )->Type() )
204 {
205 case PCB_SHAPE_T:
206 case PCB_FOOTPRINT_T:
207 case PCB_TEXT_T:
208 case PCB_TEXTBOX_T:
209 case PCB_FIELD_T:
210 return true;
211
212 default:
213 break;
214 }
215 }
216
217 return false;
218}
219
220
222{
223 if( UndoRedoBlocked() )
224 return;
225
226 if( GetUndoCommandCount() <= 0 )
227 return;
228
229 // Inform tools that undo command was issued
230 m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
231
232 // Get the old list
234
235 bool shapesChanged = undoListContainsShapesOrFootprints( list );
236
237 // Undo the command
238 PutDataInPreviousState( list, shapesChanged );
239
240 // Put the old list in RedoList
241 list->ReversePickersListOrder();
242 PushCommandToRedoList( list );
243
244 OnModify();
245
248
249 if( shapesChanged )
250 {
251 m_pcb->UpdateBoardOutline();
252 GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
253 }
254
255 GetCanvas()->Refresh();
256}
257
258
260{
261 if( UndoRedoBlocked() )
262 return;
263
264 if( GetRedoCommandCount() == 0 )
265 return;
266
267 // Inform tools that redo command was issued
269
270 // Get the old list
272
273 bool shapesChanged = undoListContainsShapesOrFootprints( list );
274
275 // Redo the command
276 PutDataInPreviousState( list, shapesChanged );
277
278 // Put the old list in UndoList
279 list->ReversePickersListOrder();
280 PushCommandToUndoList( list );
281
282 OnModify();
283
286
287 if( shapesChanged )
288 {
289 m_pcb->UpdateBoardOutline();
290 GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
291 }
292
293 GetCanvas()->Refresh();
294}
295
296
298{
299 bool not_found = false;
300 bool reBuild_ratsnest = false;
301 bool deep_reBuild_ratsnest = false; // true later if pointers must be rebuilt
302 bool solder_mask_dirty = false;
303 bool current_show_ratsnest = GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest;
304 std::vector<BOX2I> dirty_rule_areas;
305
306 KIGFX::PCB_VIEW* view = GetCanvas()->GetView();
307 std::shared_ptr<CONNECTIVITY_DATA> connectivity = GetBoard()->GetConnectivity();
308
309 GetBoard()->IncrementTimeStamp(); // clear caches
310
311 // Enum to track the modification type of items. Used to enable bulk BOARD_LISTENER
312 // callbacks at the end of the undo / redo operation
313 enum ITEM_CHANGE_TYPE
314 {
315 ADDED,
316 DELETED,
317 CHANGED
318 };
319
320 std::unordered_map<EDA_ITEM*, ITEM_CHANGE_TYPE> item_changes;
321
322 auto clear_local_ratsnest_flags =
323 [&]( EDA_ITEM* item )
324 {
325 switch( item->Type() )
326 {
327 case PCB_TRACE_T:
328 case PCB_ARC_T:
329 case PCB_VIA_T:
330 static_cast<PCB_TRACK*>( item )->SetLocalRatsnestVisible( current_show_ratsnest );
331 break;
332
333 case PCB_ZONE_T:
334 static_cast<ZONE*>( item )->SetLocalRatsnestVisible( current_show_ratsnest );
335 break;
336
337 case PCB_FOOTPRINT_T:
338 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
339 pad->SetLocalRatsnestVisible( current_show_ratsnest );
340
341 break;
342
343 default:
344 break;
345 }
346 };
347
348 auto update_item_change_state =
349 [&]( EDA_ITEM* item, ITEM_CHANGE_TYPE change_type )
350 {
351 auto item_itr = item_changes.find( item );
352
353 if( item_itr == item_changes.end() )
354 {
355 // First time we've seen this item - tag the current change type
356 item_changes.insert( { item, change_type } );
357 return;
358 }
359
360 // Update the item state based on the current and next change type
361 switch( item_itr->second )
362 {
363 case ITEM_CHANGE_TYPE::ADDED:
364 if( change_type == ITEM_CHANGE_TYPE::DELETED )
365 {
366 // The item was previously added, now deleted - as far as bulk callbacks
367 // are concerned, the item has never existed
368 item_changes.erase( item_itr );
369 }
370 else if( change_type == ITEM_CHANGE_TYPE::ADDED )
371 {
372 // Error condition - added an already added item
373 wxASSERT_MSG( false, wxT( "UndoRedo: should not add already added item" ) );
374 }
375
376 // For all other cases, the item remains as ADDED as seen by the bulk callbacks
377 break;
378
379 case ITEM_CHANGE_TYPE::DELETED:
380 // This is an error condition - item has already been deleted so should not
381 // be operated on further
382 wxASSERT_MSG( false, wxT( "UndoRedo: should not alter already deleted item" ) );
383 break;
384
385 case ITEM_CHANGE_TYPE::CHANGED:
386 if( change_type == ITEM_CHANGE_TYPE::DELETED )
387 {
388 item_itr->second = ITEM_CHANGE_TYPE::DELETED;
389 }
390 else if( change_type == ITEM_CHANGE_TYPE::ADDED )
391 {
392 // This is an error condition - item has already been changed so should not
393 // be added
394 wxASSERT_MSG( false, wxT( "UndoRedo: should not add already changed item" ) );
395 }
396
397 // Otherwise, item remains CHANGED
398 break;
399 }
400 };
401
402 // Undo in the reverse order of list creation: (this can allow stacked changes
403 // like the same item can be changes and deleted in the same complex command
404
405 // Restore changes in reverse order
406 for( int ii = (int) aList->GetCount() - 1; ii >= 0 ; ii-- )
407 {
408 EDA_ITEM* eda_item = aList->GetPickedItem( (unsigned) ii );
409
410 /* Test for existence of item on board.
411 * It could be deleted, and no more on board:
412 * - if a call to SaveCopyInUndoList was forgotten in Pcbnew
413 * - in zones outlines, when a change in one zone merges this zone with an other
414 * This test avoids a Pcbnew crash
415 * Obviously, this test is not made for deleted items
416 */
417 UNDO_REDO status = aList->GetPickedItemStatus( ii );
418
419 if( status != UNDO_REDO::DELETED
420 && status != UNDO_REDO::DRILLORIGIN // origin markers never on board
421 && status != UNDO_REDO::GRIDORIGIN // origin markers never on board
422 && status != UNDO_REDO::PAGESETTINGS ) // nor are page settings proxy items
423 {
424 if( !GetBoard()->ResolveItem( eda_item->m_Uuid, true ) )
425 {
426 // Remove this non existent item
427 aList->RemovePicker( ii );
428 not_found = true;
429
430 if( aList->GetCount() == 0 )
431 break;
432
433 continue;
434 }
435 }
436
437 // see if we must rebuild ratsnets and pointers lists
438 switch( eda_item->Type() )
439 {
440 case PCB_FOOTPRINT_T:
441 deep_reBuild_ratsnest = true; // Pointers on pads can be invalid
443
444 case PCB_ZONE_T:
445 case PCB_TRACE_T:
446 case PCB_ARC_T:
447 case PCB_VIA_T:
448 case PCB_PAD_T:
449 reBuild_ratsnest = true;
450 break;
451
452 case PCB_NETINFO_T:
453 reBuild_ratsnest = true;
454 deep_reBuild_ratsnest = true;
455 break;
456
457 default:
458 break;
459 }
460
461 switch( eda_item->Type() )
462 {
463 case PCB_FOOTPRINT_T:
464 solder_mask_dirty = true;
465 break;
466
467 case PCB_VIA_T:
468 solder_mask_dirty = true;
469 break;
470
471 case PCB_ZONE_T:
472 case PCB_TRACE_T:
473 case PCB_ARC_T:
474 case PCB_PAD_T:
475 case PCB_SHAPE_T:
476 {
477 LSET layers = static_cast<BOARD_ITEM*>( eda_item )->GetLayerSet();
478
479 if( layers.test( F_Mask ) || layers.test( B_Mask ) )
480 solder_mask_dirty = true;
481
482 break;
483 }
484
485 default:
486 break;
487 }
488
489 switch( aList->GetPickedItemStatus( ii ) )
490 {
491 case UNDO_REDO::CHANGED: /* Exchange old and new data for each item */
492 if( eda_item->IsBOARD_ITEM() )
493 {
494 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( eda_item );
495 BOARD_ITEM* image = static_cast<BOARD_ITEM*>( aList->GetPickedItemLink( ii ) );
496 BOARD_ITEM_CONTAINER* parent = GetBoard();
497
498 // The stored pointer can be stale if a swap (e.g. ExchangeFootprint)
499 // replaced the live item earlier. Resolve by UUID to find the current one.
500 if( BOARD_ITEM* resolved = GetBoard()->ResolveItem( item->m_Uuid, true ) )
501 item = resolved;
502
503 if( item->GetParentFootprint() )
504 parent = item->GetParentFootprint();
505
506 view->Remove( item );
507 parent->Remove( item, REMOVE_MODE::BULK );
508
509 if( item->Type() != PCB_MARKER_T )
510 item->SwapItemData( image );
511
512 clear_local_ratsnest_flags( item );
513 item->ClearFlags( UR_TRANSIENT );
514 image->SetFlags( UR_TRANSIENT );
515
516 view->Add( item );
517 view->Hide( item, false );
518 parent->Add( item, ADD_MODE::BULK_INSERT );
519
520 if( item->Type() == PCB_ZONE_T && static_cast<ZONE*>( item )->GetIsRuleArea() )
521 {
522 dirty_rule_areas.push_back( item->GetBoundingBox() );
523 dirty_rule_areas.push_back( image->GetBoundingBox() );
524 }
525
526 update_item_change_state( item, ITEM_CHANGE_TYPE::CHANGED );
527 }
528
529 break;
530
531 case UNDO_REDO::NEWITEM: /* new items are deleted */
532 if( eda_item->IsBOARD_ITEM() )
533 {
534 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( eda_item );
535
537
538 if( FOOTPRINT* parentFP = boardItem->GetParentFootprint() )
539 parentFP->Remove( boardItem );
540 else
541 GetModel()->Remove( boardItem, REMOVE_MODE::BULK );
542
543 update_item_change_state( eda_item, ITEM_CHANGE_TYPE::DELETED );
544
545 if( eda_item->Type() != PCB_NETINFO_T )
546 view->Remove( eda_item );
547
548 eda_item->SetFlags( UR_TRANSIENT );
549
550 if( eda_item->Type() == PCB_ZONE_T && static_cast<ZONE*>( eda_item )->GetIsRuleArea() )
551 dirty_rule_areas.push_back( eda_item->GetBoundingBox() );
552 }
553
554 break;
555
556 case UNDO_REDO::DELETED: /* deleted items are put in List, as new items */
557 if( eda_item->IsBOARD_ITEM() )
558 {
559 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( eda_item );
560
562
563 clear_local_ratsnest_flags( eda_item );
564 eda_item->ClearFlags( UR_TRANSIENT );
565
566 if( FOOTPRINT* parentFP = boardItem->GetParentFootprint() )
567 parentFP->Add( boardItem );
568 else
569 GetModel()->Add( boardItem, ADD_MODE::BULK_APPEND );
570
571 update_item_change_state( eda_item, ITEM_CHANGE_TYPE::ADDED );
572
573 if( eda_item->Type() != PCB_NETINFO_T )
574 view->Add( eda_item );
575
576 if( eda_item->Type() == PCB_ZONE_T && static_cast<ZONE*>( eda_item )->GetIsRuleArea() )
577 dirty_rule_areas.push_back( eda_item->GetBoundingBox() );
578 }
579
580 break;
581
584 {
585 // Warning: DRILLORIGIN and GRIDORIGIN undo/redo command create EDA_ITEMs
586 // that cannot be casted to BOARD_ITEMs
587 EDA_ITEM* image = aList->GetPickedItemLink( ii );
588 VECTOR2D origin = image->GetPosition();
589 image->SetPosition( eda_item->GetPosition() );
590
591 if( aList->GetPickedItemStatus( ii ) == UNDO_REDO::DRILLORIGIN )
592 BOARD_EDITOR_CONTROL::DoSetDrillOrigin( view, this, eda_item, origin );
593 else
594 PCB_CONTROL::DoSetGridOrigin( view, this, eda_item, origin );
595
596 break;
597 }
598
600 if( eda_item->Type() == WS_PROXY_UNDO_ITEM_T || eda_item->Type() == WS_PROXY_UNDO_ITEM_PLUS_T )
601 {
602 // swap current settings with stored settings
603 DS_PROXY_UNDO_ITEM alt_item( this );
604 DS_PROXY_UNDO_ITEM* item = static_cast<DS_PROXY_UNDO_ITEM*>( eda_item );
605 item->Restore( this );
606 *item = std::move( alt_item );
607 }
608
609 break;
610
611 default:
612 wxFAIL_MSG( wxString::Format( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
613 aList->GetPickedItemStatus( ii ) ) );
614 break;
615 }
616
617 if( eda_item->Type() == PCB_FOOTPRINT_T )
618 {
619 FOOTPRINT* fp = static_cast<FOOTPRINT*>( eda_item );
621 m_pcb->GetComponentClassManager().RebuildRequiredCaches( fp );
622 }
623 }
624
625 if( not_found )
626 wxMessageBox( _( "Incomplete undo/redo operation: some items not found" ) );
627
628 // We have now swapped all the group parent and group member pointers. But it is a
629 // risky proposition to bet on the pointers being invariant, so validate them all.
630 for( int ii = 0; ii < (int) aList->GetCount(); ++ii )
631 {
632 ITEM_PICKER& wrapper = aList->GetItemWrapper( ii );
633
634 if( wrapper.GetStatus() == UNDO_REDO::DELETED )
635 continue;
636
637 BOARD_ITEM* parentGroup = GetBoard()->ResolveItem( wrapper.GetGroupId(), true );
638 wrapper.GetItem()->SetParentGroup( dynamic_cast<PCB_GROUP*>( parentGroup ) );
639
640 // Restore the group's member list, which BOARD::Remove() cleared above.
641 if( PCB_GROUP* parentPcbGroup = dynamic_cast<PCB_GROUP*>( parentGroup ) )
642 parentPcbGroup->GetItems().insert( wrapper.GetItem() );
643
644 if( EDA_GROUP* group = dynamic_cast<PCB_GROUP*>( wrapper.GetItem() ) )
645 {
646 // Items list may contain dodgy pointers, so don't use RemoveAll()
647 group->GetItems().clear();
648
649 for( const KIID& member : wrapper.GetGroupMembers() )
650 {
651 if( BOARD_ITEM* memberItem = GetBoard()->ResolveItem( member, true ) )
652 group->AddItem( memberItem );
653 }
654 }
655
656 // And prepare for a redo by updating group info based on current image
657 if( EDA_ITEM* item = wrapper.GetLink() )
658 wrapper.SetLink( item );
659 }
660
661 if( IsType( FRAME_PCB_EDITOR ) )
662 {
663 if( !dirty_rule_areas.empty() && ( GetPcbNewSettings()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
664 || GetPcbNewSettings()->m_Display.m_PadClearance ) )
665 {
666 view->UpdateCollidingItems( dirty_rule_areas, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T } );
667 }
668
669 if( reBuild_ratsnest || deep_reBuild_ratsnest )
670 {
671 // Connectivity may have changed; rebuild internal caches to remove stale items
674 }
675
676 if( solder_mask_dirty )
678 }
679
681
683 selTool->RebuildSelection();
684
686
687 // Invoke bulk BOARD_LISTENER callbacks
688 std::vector<BOARD_ITEM*> added_items, deleted_items, changed_items;
689
690 for( auto& [item, changeType] : item_changes )
691 {
692 switch( changeType )
693 {
694 case ITEM_CHANGE_TYPE::ADDED:
695 added_items.push_back( static_cast<BOARD_ITEM*>( item ) );
696 break;
697
698 case ITEM_CHANGE_TYPE::DELETED:
699 deleted_items.push_back( static_cast<BOARD_ITEM*>( item ) );
700 break;
701
702 case ITEM_CHANGE_TYPE::CHANGED:
703 changed_items.push_back( static_cast<BOARD_ITEM*>( item ) );
704 break;
705 }
706 }
707
708 if( aRehatchShapes )
710
711 if( added_items.size() > 0 || deleted_items.size() > 0 || changed_items.size() > 0 )
712 GetBoard()->OnItemsCompositeUpdate( added_items, deleted_items, changed_items );
713}
714
715
717{
718 if( aItemCount == 0 )
719 return;
720
721 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
722
723 if( aItemCount < 0 )
724 {
725 list.ClearCommandList();
726 }
727 else
728 {
729 for( int ii = 0; ii < aItemCount; ii++ )
730 {
731 if( list.m_CommandsList.size() == 0 )
732 break;
733
734 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
735 list.m_CommandsList.erase( list.m_CommandsList.begin() );
736 ClearListAndDeleteItems( curr_cmd );
737 delete curr_cmd; // Delete command
738 }
739 }
740}
741
742
744{
746 []( EDA_ITEM* item )
747 {
748 wxASSERT_MSG( item->HasFlag( UR_TRANSIENT ),
749 "Item on undo/redo list not owned by undo/redo!" );
750
751 delete item;
752 } );
753}
754
755
757{
761 delete undo;
762
763 m_pcb->UpdateBoardOutline();
764 GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
765 GetCanvas()->Refresh();
766}
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:81
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
FOOTPRINT * GetParentFootprint() const
void CompileRatsnest()
Rebuild the entire board ratsnest.
Definition board.cpp:3595
void SanitizeNetcodes()
Definition board.cpp:3535
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:201
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:3582
void IncrementTimeStamp()
Definition board.cpp:283
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
Definition board.h:1521
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:1846
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:634
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:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
virtual VECTOR2I GetPosition() const
Definition eda_item.h:282
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:135
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:152
const KIID m_Uuid
Definition eda_item.h:531
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:154
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:156
static const TOOL_EVENT UndoRedoPreEvent
Definition actions.h:364
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition actions.h:348
static const TOOL_EVENT UndoRedoPostEvent
Definition actions.h:365
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:87
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:53
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:118
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition pcb_view.cpp:70
bool IsBOARD_ITEM() const
Definition view_item.h:98
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition view.cpp:1780
Definition kiid.h:44
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Definition pad.h:61
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)
Definition undo_redo.cpp:99
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
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:49
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:70
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:811
#define _(s)
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ B_Mask
Definition layer_ids.h:94
@ F_Mask
Definition layer_ids.h:93
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:79
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:45
@ TA_UNDO_REDO_PRE
This event is sent before undo/redo command is performed.
Definition tool_event.h:102
@ TA_UNDO_REDO_POST
This event is sent after undo/redo command is performed.
Definition tool_event.h:105
@ TC_MESSAGE
Definition tool_event.h:54
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:81
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:86
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:101
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:85
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:83
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:92
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:79
@ WS_PROXY_UNDO_ITEM_T
Definition typeinfo.h:221
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:80
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:91
@ WS_PROXY_UNDO_ITEM_PLUS_T
Definition typeinfo.h:222
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:103
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:89
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:682