25using namespace std::placeholders;
104 int preExisting = (int) commandToUndo->
GetCount();
106 for(
unsigned ii = 0; ii < aItemsList.
GetCount(); ii++ )
109 for(
unsigned ii = preExisting; ii < commandToUndo->
GetCount(); ii++ )
116 command = aCommandType;
139 wxFAIL_MSG( wxString::Format( wxT(
"Unrecognized undo command: %X" ), command ) );
156 delete commandToUndo;
202 for(
unsigned ii = 0; ii < aList->
GetCount(); ++ii )
224 for(
unsigned ii = 0; ii < aList->
GetCount(); ++ii )
257 if( drillMapChanged )
264 list->ReversePickersListOrder();
274 m_pcb->UpdateBoardOutline();
303 if( drillMapChanged )
310 list->ReversePickersListOrder();
320 m_pcb->UpdateBoardOutline();
331 bool not_found =
false;
332 bool reBuild_ratsnest =
false;
333 bool deep_reBuild_ratsnest =
false;
334 bool solder_mask_dirty =
false;
336 std::vector<BOX2I> dirty_rule_areas;
345 enum ITEM_CHANGE_TYPE
352 std::unordered_map<EDA_ITEM*, ITEM_CHANGE_TYPE> item_changes;
354 auto clear_local_ratsnest_flags =
357 switch( item->Type() )
362 static_cast<PCB_TRACK*
>( item )->SetLocalRatsnestVisible( current_show_ratsnest );
366 static_cast<ZONE*
>( item )->SetLocalRatsnestVisible( current_show_ratsnest );
371 pad->SetLocalRatsnestVisible( current_show_ratsnest );
380 auto update_item_change_state =
381 [&](
EDA_ITEM* item, ITEM_CHANGE_TYPE change_type )
383 auto item_itr = item_changes.find( item );
385 if( item_itr == item_changes.end() )
388 item_changes.insert( { item, change_type } );
393 switch( item_itr->second )
395 case ITEM_CHANGE_TYPE::ADDED:
396 if( change_type == ITEM_CHANGE_TYPE::DELETED )
400 item_changes.erase( item_itr );
402 else if( change_type == ITEM_CHANGE_TYPE::ADDED )
405 wxASSERT_MSG(
false, wxT(
"UndoRedo: should not add already added item" ) );
411 case ITEM_CHANGE_TYPE::DELETED:
414 wxASSERT_MSG(
false, wxT(
"UndoRedo: should not alter already deleted item" ) );
417 case ITEM_CHANGE_TYPE::CHANGED:
418 if( change_type == ITEM_CHANGE_TYPE::DELETED )
420 item_itr->second = ITEM_CHANGE_TYPE::DELETED;
422 else if( change_type == ITEM_CHANGE_TYPE::ADDED )
426 wxASSERT_MSG(
false, wxT(
"UndoRedo: should not add already changed item" ) );
438 for(
int ii = (
int) aList->
GetCount() - 1; ii >= 0 ; ii-- )
470 switch( eda_item->
Type() )
473 deep_reBuild_ratsnest =
true;
481 reBuild_ratsnest =
true;
485 reBuild_ratsnest =
true;
486 deep_reBuild_ratsnest =
true;
493 switch( eda_item->
Type() )
496 solder_mask_dirty =
true;
500 solder_mask_dirty =
true;
509 LSET layers =
static_cast<BOARD_ITEM*
>( eda_item )->GetLayerSet();
512 solder_mask_dirty =
true;
544 clear_local_ratsnest_flags( item );
549 view->
Hide( item,
false );
555 dirty_rule_areas.push_back(
image->GetBoundingBox() );
558 update_item_change_state( item, ITEM_CHANGE_TYPE::CHANGED );
571 parentFP->Remove( boardItem );
575 update_item_change_state( eda_item, ITEM_CHANGE_TYPE::DELETED );
595 clear_local_ratsnest_flags( eda_item );
599 parentFP->Add( boardItem );
603 update_item_change_state( eda_item, ITEM_CHANGE_TYPE::ADDED );
606 view->
Add( eda_item );
638 *item = std::move( alt_item );
644 wxFAIL_MSG( wxString::Format( wxT(
"PutDataInPreviousState() error (unknown code %X)" ),
653 m_pcb->GetComponentClassManager().RebuildRequiredCaches( fp );
658 wxMessageBox(
_(
"Incomplete undo/redo operation: some items not found" ) );
662 for(
int ii = 0; ii < (int) aList->
GetCount(); ++ii )
677 parentPcbGroup->GetItems().insert( boardItem );
682 group->GetItems().clear();
684 for(
const KIID& member :
wrapper.GetGroupMembers() )
687 group->AddItem( memberItem );
704 if( reBuild_ratsnest || deep_reBuild_ratsnest )
711 if( solder_mask_dirty )
723 std::vector<BOARD_ITEM*> added_items, deleted_items, changed_items;
725 for(
auto& [item, changeType] : item_changes )
729 case ITEM_CHANGE_TYPE::ADDED:
730 added_items.push_back(
static_cast<BOARD_ITEM*
>( item ) );
733 case ITEM_CHANGE_TYPE::DELETED:
734 deleted_items.push_back(
static_cast<BOARD_ITEM*
>( item ) );
737 case ITEM_CHANGE_TYPE::CHANGED:
738 changed_items.push_back(
static_cast<BOARD_ITEM*
>( item ) );
746 if( added_items.size() > 0 || deleted_items.size() > 0 || changed_items.size() > 0 )
753 if( aItemCount == 0 )
760 list.ClearCommandList();
764 for(
int ii = 0; ii < aItemCount; ii++ )
766 if( list.m_CommandsList.size() == 0 )
770 list.m_CommandsList.erase( list.m_CommandsList.begin() );
784 "Item on undo/redo list not owned by undo/redo!" );
798 m_pcb->UpdateBoardOutline();
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...
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
FOOTPRINT * GetParentFootprint() const
void CompileRatsnest()
Rebuild the entire board ratsnest.
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
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...
void IncrementTimeStamp()
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
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).
A base class for most all the KiCad significant classes used in schematics and boards.
virtual VECTOR2I GetPosition() const
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual void SetParentGroup(EDA_GROUP *aGroup)
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
static const TOOL_EVENT UndoRedoPreEvent
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
static const TOOL_EVENT UndoRedoPostEvent
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...
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
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.
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
bool IsBOARD_ITEM() const
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
LSET is a set of PCB_LAYER_IDs.
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.
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.
The main frame for Pcbnew.
A set of BOARD_ITEMs (i.e., without duplicates).
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
A holder to handle a list of undo (or redo) commands.
Handle a list of polygons defining a copper zone.
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack
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 ...
@ REPAINT
Item needs to be redrawn.
@ GEOMETRY
Position or shape has changed.
@ LAYERS
Layers have changed.
void RefreshDrillMapOutlines(const BOARD &aBoard, KIGFX::VIEW *aView)
Repaint every drill map after an Edge.Cuts edit.
Class to handle a set of BOARD_ITEMs.
bool m_ShowGlobalRatsnest
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ WS_PROXY_UNDO_ITEM_PLUS_T
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
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...
static bool undoListContainsDrillMap(const PICKED_ITEMS_LIST *aList)
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
VECTOR2< double > VECTOR2D