KiCad PCB EDA Suite
BOARD_COMMIT Class Reference

#include <board_commit.h>

Inheritance diagram for BOARD_COMMIT:
COMMIT

Public Member Functions

 BOARD_COMMIT (EDA_DRAW_FRAME *aFrame)
 
 BOARD_COMMIT (PCB_TOOL *aTool)
 
virtual ~BOARD_COMMIT ()
 
virtual void Push (const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
 

Executes the changes.

More...
 
virtual void Revert () override
 

Revertes the commit by restoring the modifed items state.

More...
 
COMMITAdd (EDA_ITEM *aItem)
 

Adds a new item to the model

More...
 
COMMITAdded (EDA_ITEM *aItem)
 

Notifies observers that aItem has been added

More...
 
COMMITRemove (EDA_ITEM *aItem)
 

Removes a new item from the model

More...
 
COMMITRemoved (EDA_ITEM *aItem)
 

Notifies observers that aItem has been removed

More...
 
COMMITModify (EDA_ITEM *aItem)
 

Modifies a given item in the model.

More...
 
COMMITModified (EDA_ITEM *aItem, EDA_ITEM *aCopy)
 

Creates an undo entry for an item that has been already modified.

More...
 
template<class Range >
COMMITStageItems (const Range &aRange, CHANGE_TYPE aChangeType)
 
COMMITStage (EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
 

Adds a change of the item aItem of type aChangeType to the change list.

More...
 
COMMITStage (std::vector< EDA_ITEM * > &container, CHANGE_TYPE aChangeType)
 
COMMITStage (const PICKED_ITEMS_LIST &aItems, UNDO_REDO_T aModFlag=UR_UNSPECIFIED)
 
bool Empty () const
 
int GetStatus (EDA_ITEM *aItem)
 

Returns status of an item.

More...
 

Protected Member Functions

void clear ()
 
COMMITcreateModified (EDA_ITEM *aItem, EDA_ITEM *aCopy, int aExtraFlags=0)
 
virtual void makeEntry (EDA_ITEM *aItem, CHANGE_TYPE aType, EDA_ITEM *aCopy=NULL)
 
COMMIT_LINEfindEntry (EDA_ITEM *aItem)
 Searches for an entry describing change for a particular item. More...
 
CHANGE_TYPE convert (UNDO_REDO_T aType) const
 

Protected Attributes

std::set< EDA_ITEM * > m_changedItems
 
std::vector< COMMIT_LINEm_changes
 

Private Member Functions

virtual EDA_ITEMparentObject (EDA_ITEM *aItem) const override
 

Private Attributes

TOOL_MANAGERm_toolMgr
 
bool m_editModules
 

Detailed Description

Definition at line 37 of file board_commit.h.

Constructor & Destructor Documentation

BOARD_COMMIT::BOARD_COMMIT ( EDA_DRAW_FRAME aFrame)

Definition at line 47 of file board_commit.cpp.

References FRAME_PCB_MODULE_EDITOR, EDA_DRAW_FRAME::GetToolManager(), and EDA_BASE_FRAME::IsType().

48 {
49  m_toolMgr = aFrame->GetToolManager();
51 }
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:51
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:934
bool m_editModules
Definition: board_commit.h:52
bool IsType(FRAME_T aType) const
BOARD_COMMIT::BOARD_COMMIT ( PCB_TOOL aTool)

Definition at line 40 of file board_commit.cpp.

References PCB_TOOL::EditingModules(), and TOOL_BASE::GetManager().

41 {
42  m_toolMgr = aTool->GetManager();
43  m_editModules = aTool->EditingModules();
44 }
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:51
bool EditingModules() const
Definition: pcb_tool.h:102
bool m_editModules
Definition: board_commit.h:52
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool...
Definition: tool_base.h:144
BOARD_COMMIT::~BOARD_COMMIT ( )
virtual

Definition at line 54 of file board_commit.cpp.

55 {
56 }

Member Function Documentation

COMMIT& COMMIT::Added ( EDA_ITEM aItem)
inlineinherited

Notifies observers that aItem has been added

Definition at line 84 of file commit.h.

References CHT_ADD, CHT_DONE, and COMMIT::Stage().

Referenced by PCB_EDITOR_CONTROL::PlaceModule().

85  {
86  return Stage( aItem, CHT_ADD | CHT_DONE );
87  }
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
Adds a change of the item aItem of type aChangeType to the change list.
Definition: commit.cpp:46
Definition: commit.h:38
Flag to indicate the change is already applied, just notify observers (not compatible with CHT_MODIFY...
Definition: commit.h:45
void COMMIT::clear ( )
inlineprotectedinherited

Definition at line 161 of file commit.h.

References COMMIT::convert(), COMMIT::createModified(), COMMIT::findEntry(), COMMIT::m_changedItems, COMMIT::m_changes, COMMIT::makeEntry(), and COMMIT::parentObject().

162  {
163  m_changedItems.clear();
164  m_changes.clear();
165  }
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:181
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182
CHANGE_TYPE COMMIT::convert ( UNDO_REDO_T  aType) const
protectedinherited

Definition at line 190 of file commit.cpp.

References CHT_ADD, CHT_MODIFY, CHT_REMOVE, UR_CHANGED, UR_DELETED, UR_FLIPPED, UR_MIRRORED_X, UR_MIRRORED_Y, UR_MOVED, UR_NEW, UR_ROTATED, and UR_ROTATED_CLOCKWISE.

Referenced by COMMIT::clear(), and COMMIT::Stage().

191 {
192  switch( aType )
193  {
194  case UR_NEW:
195  return CHT_ADD;
196 
197  case UR_DELETED:
198  return CHT_REMOVE;
199 
200  default:
201  assert( false );
202  // fall through
203 
204  case UR_CHANGED:
205  case UR_MOVED:
206  case UR_MIRRORED_X:
207  case UR_MIRRORED_Y:
208  case UR_ROTATED:
210  case UR_FLIPPED:
211  return CHT_MODIFY;
212  }
213 }
Definition: commit.h:38
COMMIT & COMMIT::createModified ( EDA_ITEM aItem,
EDA_ITEM aCopy,
int  aExtraFlags = 0 
)
protectedinherited

Definition at line 138 of file commit.cpp.

References CHT_MODIFY, COMMIT::m_changedItems, COMMIT::makeEntry(), and COMMIT::parentObject().

Referenced by COMMIT::clear(), COMMIT::Modified(), and COMMIT::Stage().

139 {
140  EDA_ITEM* parent = parentObject( aItem );
141  auto entryIt = m_changedItems.find( parent );
142 
143  if( entryIt != m_changedItems.end() )
144  {
145  delete aCopy;
146  return *this; // item has been already modified once
147  }
148 
149  makeEntry( parent, CHT_MODIFY | aExtraFlags, aCopy );
150 
151  return *this;
152 }
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:181
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
virtual EDA_ITEM * parentObject(EDA_ITEM *aItem) const =0
virtual void makeEntry(EDA_ITEM *aItem, CHANGE_TYPE aType, EDA_ITEM *aCopy=NULL)
Definition: commit.cpp:155
bool COMMIT::Empty ( ) const
inlineinherited

Definition at line 139 of file commit.h.

References COMMIT::GetStatus(), and COMMIT::m_changes.

Referenced by DRAWING_TOOL::drawSegment().

140  {
141  return m_changes.empty();
142  }
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182
COMMIT::COMMIT_LINE * COMMIT::findEntry ( EDA_ITEM aItem)
protectedinherited

Searches for an entry describing change for a particular item.

Returns
null if there is no related entry.

Definition at line 178 of file commit.cpp.

References COMMIT::m_changes.

Referenced by COMMIT::clear(), and COMMIT::GetStatus().

179 {
180  for( COMMIT_LINE& change : m_changes )
181  {
182  if( change.m_item == aItem )
183  return &change;
184  }
185 
186  return nullptr;
187 }
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182
int COMMIT::GetStatus ( EDA_ITEM aItem)
inherited

Returns status of an item.

Definition at line 120 of file commit.cpp.

References COMMIT::findEntry(), COMMIT::COMMIT_LINE::m_type, and COMMIT::parentObject().

Referenced by COMMIT::Empty(), BOARD_NETLIST_UPDATER::updateComponentPadConnections(), and BOARD_NETLIST_UPDATER::updateComponentParameters().

121 {
122  COMMIT_LINE* entry = findEntry( parentObject( aItem ) );
123 
124  return entry ? entry->m_type : 0;
125 }
COMMIT_LINE * findEntry(EDA_ITEM *aItem)
Searches for an entry describing change for a particular item.
Definition: commit.cpp:178
virtual EDA_ITEM * parentObject(EDA_ITEM *aItem) const =0
void COMMIT::makeEntry ( EDA_ITEM aItem,
CHANGE_TYPE  aType,
EDA_ITEM aCopy = NULL 
)
protectedvirtualinherited

Definition at line 155 of file commit.cpp.

References CHT_MODIFY, CHT_TYPE, eraseIf(), COMMIT::m_changedItems, COMMIT::m_changes, and COMMIT::COMMIT_LINE::m_item.

Referenced by COMMIT::clear(), COMMIT::createModified(), and COMMIT::Stage().

156 {
157  // Expect an item copy if it is going to be modified
158  assert( !!aCopy == ( ( aType & CHT_TYPE ) == CHT_MODIFY ) );
159 
160  if( m_changedItems.find( aItem ) != m_changedItems.end() )
161  {
162  eraseIf( m_changes, [aItem] ( const COMMIT_LINE& aEnt ) {
163  return aEnt.m_item == aItem;
164  } );
165  }
166 
167  COMMIT_LINE ent;
168 
169  ent.m_item = aItem;
170  ent.m_type = aType;
171  ent.m_copy = aCopy;
172 
173  m_changedItems.insert( aItem );
174  m_changes.push_back( ent );
175 }
void eraseIf(Container &c, F &&f)
Definition: commit.cpp:129
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:181
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182
COMMIT& COMMIT::Modified ( EDA_ITEM aItem,
EDA_ITEM aCopy 
)
inlineinherited

Creates an undo entry for an item that has been already modified.

Requires a copy done

before the modification.

Definition at line 110 of file commit.h.

References COMMIT::createModified().

Referenced by COMMIT::Stage(), BOARD_NETLIST_UPDATER::updateComponentPadConnections(), and BOARD_NETLIST_UPDATER::updateComponentParameters().

111  {
112  return createModified( aItem, aCopy );
113  }
COMMIT & createModified(EDA_ITEM *aItem, EDA_ITEM *aCopy, int aExtraFlags=0)
Definition: commit.cpp:138
EDA_ITEM * BOARD_COMMIT::parentObject ( EDA_ITEM aItem) const
overrideprivatevirtual

Implements COMMIT.

Definition at line 281 of file board_commit.cpp.

References EDA_ITEM::GetParent(), PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, and EDA_ITEM::Type().

282 {
283  switch( aItem->Type() )
284  {
285  case PCB_PAD_T:
286  case PCB_MODULE_EDGE_T:
287  case PCB_MODULE_TEXT_T:
288  return aItem->GetParent();
289  default:
290  return aItem;
291  }
292 
293  return aItem;
294 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
EDA_ITEM * GetParent() const
Definition: base_struct.h:211
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
void BOARD_COMMIT::Push ( const wxString &  aMessage = wxT("A commit"),
bool  aCreateUndoEntry = true,
bool  aSetDirtyBit = true 
)
overridevirtual

Executes the changes.

Implements COMMIT.

Definition at line 59 of file board_commit.cpp.

References KIGFX::VIEW::Add(), MODULE::Add(), BOARD::Add(), CHT_ADD, CHT_DONE, CHT_FLAGS, CHT_MODIFY, CHT_REMOVE, CHT_TYPE, EDA_ITEM::ClearFlags(), BOARD_ITEM_CONTAINER::Delete(), BOARD::GetConnectivity(), DLIST< T >::GetFirst(), EDA_DRAW_FRAME::GetGalCanvas(), BOARD_ITEM::GetParent(), EDA_DRAW_FRAME::GetToolManager(), TEXTE_MODULE::GetType(), BOARD::m_Modules, BOARD::m_Status_Pcb, PCB_BASE_FRAME::OnModify(), PCB_DIMENSION_T, PCB_LINE_T, PCB_MARKER_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_SEGZONE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, PICKED_ITEMS_LIST::PushItem(), PCB_DRAW_PANEL_GAL::RedrawRatsnest(), KIGFX::VIEW::Remove(), BOARD::Remove(), PCB_BASE_FRAME::SaveCopyInUndoList(), ITEM_PICKER::SetLink(), EDA_ITEM::SetParent(), TEXTE_MODULE::TEXT_is_DIVERS, EDA_ITEM::Type(), PCB_ACTIONS::unselectItems, KIGFX::VIEW::Update(), PCB_BASE_FRAME::UpdateMsgPanel(), UR_CHANGED, UR_DELETED, UR_NEW, and UR_UNSPECIFIED.

Referenced by DIALOG_GLOBAL_DELETION::AcceptPcbDelete(), POINT_EDITOR::addCorner(), DRC::addMarkerToPcb(), ALIGN_DISTRIBUTE_TOOL::AlignBottom(), ALIGN_DISTRIBUTE_TOOL::AlignCenterX(), ALIGN_DISTRIBUTE_TOOL::AlignCenterY(), ALIGN_DISTRIBUTE_TOOL::AlignTop(), AUTOPLACE_TOOL::autoplace(), PCB_EDIT_FRAME::Clean_Pcb(), ZONE_CREATE_HELPER::commitZone(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), ALIGN_DISTRIBUTE_TOOL::doAlignLeft(), ALIGN_DISTRIBUTE_TOOL::doAlignRight(), PCB_TOOL::doInteractiveItemPlacement(), DRC::doTrackDrc(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), PCB_EDIT_FRAME::Edit_Zone_Params(), MODULE_EDITOR_TOOLS::EnumeratePads(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), ARRAY_CREATOR::Invoke(), DIALOG_EXCHANGE_FOOTPRINTS::OnApplyClicked(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), ZONE_CREATE_HELPER::performZoneCutout(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), DRAWING_TOOL::PlaceText(), PAD_TOOL::pushPadSettings(), PCB_EDIT_FRAME::RemoveMisConnectedTracks(), FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard(), ZONE_FILLER_TOOL::SegzoneDeleteFill(), DRAWING_TOOL::SetAnchor(), PCB_EDIT_FRAME::Swap_Layers(), DRC::TestZoneToZoneOutline(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataFromWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::TransferDataFromWindow(), BOARD_NETLIST_UPDATER::UpdateNetlist(), PCB_EDITOR_CONTROL::ZoneDuplicate(), ZONE_FILLER_TOOL::ZoneUnfill(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

60 {
61  // Objects potentially interested in changes:
62  PICKED_ITEMS_LIST undoList;
63  KIGFX::VIEW* view = m_toolMgr->GetView();
64  BOARD* board = (BOARD*) m_toolMgr->GetModel();
66  auto connectivity = board->GetConnectivity();
67  std::set<EDA_ITEM*> savedModules;
68  std::vector<BOARD_ITEM*> itemsToDeselect;
69 
70  if( Empty() )
71  return;
72 
73  for( COMMIT_LINE& ent : m_changes )
74  {
75  int changeType = ent.m_type & CHT_TYPE;
76  int changeFlags = ent.m_type & CHT_FLAGS;
77  BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( ent.m_item );
78 
79  // Module items need to be saved in the undo buffer before modification
80  if( m_editModules )
81  {
82  // Be sure that we are storing a module
83  if( ent.m_item->Type() != PCB_MODULE_T )
84  ent.m_item = ent.m_item->GetParent();
85 
86  // We have not saved the module yet, so let's create an entry
87  if( savedModules.count( ent.m_item ) == 0 )
88  {
89  if( !ent.m_copy )
90  {
91  wxASSERT( changeType != CHT_MODIFY ); // too late to make a copy..
92  ent.m_copy = ent.m_item->Clone();
93  }
94 
95  wxASSERT( ent.m_item->Type() == PCB_MODULE_T );
96  wxASSERT( ent.m_copy->Type() == PCB_MODULE_T );
97 
98  if( aCreateUndoEntry )
99  {
100  ITEM_PICKER itemWrapper( ent.m_item, UR_CHANGED );
101  itemWrapper.SetLink( ent.m_copy );
102  undoList.PushItem( itemWrapper );
103  frame->SaveCopyInUndoList( undoList, UR_CHANGED );
104  }
105 
106  savedModules.insert( ent.m_item );
107  static_cast<MODULE*>( ent.m_item )->SetLastEditTime();
108  }
109  }
110 
111  switch( changeType )
112  {
113  case CHT_ADD:
114  {
115  if( !m_editModules )
116  {
117  if( aCreateUndoEntry )
118  {
119  undoList.PushItem( ITEM_PICKER( boardItem, UR_NEW ) );
120  }
121 
122  if( !( changeFlags & CHT_DONE ) )
123  board->Add( boardItem ); // handles connectivity
124 
125  }
126  else
127  {
128  // modules inside modules are not supported yet
129  wxASSERT( boardItem->Type() != PCB_MODULE_T );
130 
131  boardItem->SetParent( board->m_Modules.GetFirst() );
132 
133  if( !( changeFlags & CHT_DONE ) )
134  board->m_Modules->Add( boardItem );
135  }
136 
137  view->Add( boardItem );
138  break;
139  }
140 
141  case CHT_REMOVE:
142  {
143  if( !m_editModules && aCreateUndoEntry )
144  undoList.PushItem( ITEM_PICKER( boardItem, UR_DELETED ) );
145 
146  switch( boardItem->Type() )
147  {
148  // Module items
149  case PCB_PAD_T:
150  case PCB_MODULE_EDGE_T:
151  case PCB_MODULE_TEXT_T:
152  // This level can only handle module items when editing modules
153  if( !m_editModules )
154  break;
155 
156  if( boardItem->Type() == PCB_MODULE_TEXT_T )
157  {
158  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( boardItem );
159 
160  // don't allow deletion of Reference or Value
161  if( text->GetType() != TEXTE_MODULE::TEXT_is_DIVERS )
162  break;
163  }
164 
165  view->Remove( boardItem );
166 
167  if( !( changeFlags & CHT_DONE ) )
168  {
169  MODULE* module = static_cast<MODULE*>( boardItem->GetParent() );
170  wxASSERT( module && module->Type() == PCB_MODULE_T );
171  module->Delete( boardItem );
172  }
173 
174  board->m_Status_Pcb = 0; // it is done in the legacy view (ratsnest perhaps?)
175 
176  break;
177 
178  // Board items
179  case PCB_LINE_T: // a segment not on copper layers
180  case PCB_TEXT_T: // a text on a layer
181  case PCB_TRACE_T: // a track segment (segment on a copper layer)
182  case PCB_VIA_T: // a via (like track segment on a copper layer)
183  case PCB_DIMENSION_T: // a dimension (graphic item)
184  case PCB_TARGET_T: // a target (graphic item)
185  case PCB_MARKER_T: // a marker used to show something
186  case PCB_SEGZONE_T: // SEG_ZONE items are now deprecated
187  case PCB_ZONE_AREA_T:
188  itemsToDeselect.push_back( boardItem );
189 
190  view->Remove( boardItem );
191 
192  if( !( changeFlags & CHT_DONE ) )
193  board->Remove( boardItem );
194 
195  break;
196 
197  case PCB_MODULE_T:
198  {
199  itemsToDeselect.push_back( boardItem );
200 
201  // There are no modules inside a module yet
202  wxASSERT( !m_editModules );
203 
204  MODULE* module = static_cast<MODULE*>( boardItem );
205  view->Remove( module );
206  module->ClearFlags();
207 
208  if( !( changeFlags & CHT_DONE ) )
209  board->Remove( module ); // handles connectivity
210 
211  // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore
212  board->m_Status_Pcb = 0;
213  }
214  break;
215 
216  default: // other types do not need to (or should not) be handled
217  wxASSERT( false );
218  break;
219  }
220 
221  break;
222  }
223 
224  case CHT_MODIFY:
225  {
226  if( !m_editModules && aCreateUndoEntry )
227  {
228  ITEM_PICKER itemWrapper( boardItem, UR_CHANGED );
229  wxASSERT( ent.m_copy );
230  itemWrapper.SetLink( ent.m_copy );
231  undoList.PushItem( itemWrapper );
232  }
233 
234  if( ent.m_copy )
235  connectivity->MarkItemNetAsDirty( static_cast<BOARD_ITEM*>( ent.m_copy ) );
236 
237  connectivity->Update( boardItem );
238  view->Update( boardItem );
239 
240  // if no undo entry is needed, the copy would create a memory leak
241  if( !aCreateUndoEntry )
242  delete ent.m_copy;
243 
244  break;
245  }
246 
247  default:
248  wxASSERT( false );
249  break;
250  }
251  }
252 
253  // Removing an item should trigger the unselect action
254  // but only after all items are removed otherwise we can get
255  // flickering depending on the system
256  if( itemsToDeselect.size() > 0 )
257  m_toolMgr->RunAction( PCB_ACTIONS::unselectItems, true, &itemsToDeselect );
258 
259  if( !m_editModules && aCreateUndoEntry )
260  frame->SaveCopyInUndoList( undoList, UR_UNSPECIFIED );
261 
262  if( TOOL_MANAGER* toolMgr = frame->GetToolManager() )
263  toolMgr->PostEvent( { TC_MESSAGE, TA_MODEL_CHANGE, AS_GLOBAL } );
264 
265  if ( !m_editModules )
266  {
267  auto panel = static_cast<PCB_DRAW_PANEL_GAL*>( frame->GetGalCanvas() );
268  connectivity->RecalculateRatsnest();
269  panel->RedrawRatsnest();
270  }
271 
272  if( aSetDirtyBit )
273  frame->OnModify();
274 
275  frame->UpdateMsgPanel();
276 
277  clear();
278 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
BOARD_ITEM_CONTAINER * GetParent() const
void clear()
Definition: commit.h:161
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
TEXT_TYPE GetType() const
wxWindow * GetEditFrame() const
Definition: tool_manager.h:267
static TOOL_ACTION unselectItems
Unselects a list of items (specified as the event parameter)
Definition: pcb_actions.h:65
Definition: commit.h:38
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
Flag to indicate the change is already applied, just notify observers (not compatible with CHT_MODIFY...
Definition: commit.h:45
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:51
bool Empty() const
Definition: commit.h:139
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
void RedrawRatsnest()
Forces refresh of the ratsnest visual representation
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
Class TOOL_MANAGER.
Definition: tool_manager.h:49
class MODULE, a footprint
Definition: typeinfo.h:89
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:216
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1530
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:934
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
EDA_ITEM * GetModel() const
Definition: tool_manager.h:262
bool m_editModules
Definition: board_commit.h:52
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
DLIST< MODULE > m_Modules
Definition: class_board.h:249
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182
virtual void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))=0
Function SaveCopyInUndoList (virtual pure) Creates a new entry in undo list of commands.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the containter and deletes it.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:928
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
Class VIEW.
Definition: view.h:61
void UpdateMsgPanel() override
>
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
class SEGZONE, a segment used to fill a zone area (segment on a
Definition: typeinfo.h:97
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:297
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:241
COMMIT& COMMIT::Remove ( EDA_ITEM aItem)
inlineinherited

Removes a new item from the model

Definition at line 90 of file commit.h.

References CHT_REMOVE, and COMMIT::Stage().

Referenced by DIALOG_GLOBAL_DELETION::AcceptPcbDelete(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), BOARD_NETLIST_UPDATER::deleteUnusedComponents(), PCB_EDIT_FRAME::Exchange_Module(), mergeZones(), ZONE_CREATE_HELPER::performZoneCutout(), and ZONE_FILLER_TOOL::SegzoneDeleteFill().

91  {
92  return Stage( aItem, CHT_REMOVE );
93  }
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
Adds a change of the item aItem of type aChangeType to the change list.
Definition: commit.cpp:46
COMMIT& COMMIT::Removed ( EDA_ITEM aItem)
inlineinherited

Notifies observers that aItem has been removed

Definition at line 96 of file commit.h.

References CHT_DONE, CHT_REMOVE, and COMMIT::Stage().

Referenced by TRACKS_CLEANER::deleteDanglingTracks(), TRACKS_CLEANER::MergeCollinearTracks(), and TRACKS_CLEANER::removeItems().

97  {
98  return Stage( aItem, CHT_REMOVE | CHT_DONE );
99  }
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
Adds a change of the item aItem of type aChangeType to the change list.
Definition: commit.cpp:46
Flag to indicate the change is already applied, just notify observers (not compatible with CHT_MODIFY...
Definition: commit.h:45
void BOARD_COMMIT::Revert ( )
overridevirtual

Revertes the commit by restoring the modifed items state.

Implements COMMIT.

Definition at line 297 of file board_commit.cpp.

References KIGFX::VIEW::Add(), BOARD::Add(), CHT_ADD, CHT_DONE, CHT_FLAGS, CHT_MODIFY, CHT_REMOVE, CHT_TYPE, EDA_ITEM::ClearFlags(), BOARD::GetConnectivity(), COMMIT::COMMIT_LINE::m_copy, COMMIT::COMMIT_LINE::m_item, COMMIT::COMMIT_LINE::m_type, PCB_MODULE_T, KIGFX::VIEW::Remove(), BOARD::Remove(), MODULE::RunOnChildren(), SELECTED, BOARD_ITEM::SwapData(), and EDA_ITEM::Type().

Referenced by AUTOPLACE_TOOL::autoplace(), MODULE_EDITOR_TOOLS::EnumeratePads(), POINT_EDITOR::OnSelectionChange(), and PCB_EDITOR_CONTROL::PlaceModule().

298 {
299  PICKED_ITEMS_LIST undoList;
300  KIGFX::VIEW* view = m_toolMgr->GetView();
301  BOARD* board = (BOARD*) m_toolMgr->GetModel();
302  auto connectivity = board->GetConnectivity();
303 
304  for( auto it = m_changes.rbegin(); it != m_changes.rend(); ++it )
305  {
306  COMMIT_LINE& ent = *it;
307  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( ent.m_item );
308  BOARD_ITEM* copy = static_cast<BOARD_ITEM*>( ent.m_copy );
309  int changeType = ent.m_type & CHT_TYPE;
310  int changeFlags = ent.m_type & CHT_FLAGS;
311 
312  switch( changeType )
313  {
314  case CHT_ADD:
315  if( !( changeFlags & CHT_DONE ) )
316  break;
317 
318  view->Remove( item );
319  connectivity->Remove( item );
320  board->Remove( item );
321  break;
322 
323  case CHT_REMOVE:
324  if( !( changeFlags & CHT_DONE ) )
325  break;
326 
327  if( item->Type() == PCB_MODULE_T )
328  {
329  MODULE* newModule = static_cast<MODULE*>( item );
330  newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) );
331  }
332 
333  view->Add( item );
334  connectivity->Add( item );
335  board->Add( item );
336  break;
337 
338  case CHT_MODIFY:
339  {
340  view->Remove( item );
341  connectivity->Remove( item );
342 
343  item->SwapData( copy );
344  item->ClearFlags( SELECTED );
345 
346  // Update all pads/drawings/texts, as they become invalid
347  // for the VIEW after SwapData() called for modules
348  if( item->Type() == PCB_MODULE_T )
349  {
350  MODULE* newModule = static_cast<MODULE*>( item );
351  newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) );
352  }
353 
354  view->Add( item );
355  connectivity->Add( item );
356  delete copy;
357  break;
358  }
359 
360  default:
361  wxASSERT( false );
362  break;
363  }
364  }
365 
366  if ( !m_editModules )
367  connectivity->RecalculateRatsnest();
368 
369  clear();
370 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void clear()
Definition: commit.h:161
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
Definition: commit.h:38
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
Flag to indicate the change is already applied, just notify observers (not compatible with CHT_MODIFY...
Definition: commit.h:45
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:51
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
#define SELECTED
Definition: base_struct.h:121
class MODULE, a footprint
Definition: typeinfo.h:89
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
EDA_ITEM * GetModel() const
Definition: tool_manager.h:262
bool m_editModules
Definition: board_commit.h:52
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
Class VIEW.
Definition: view.h:61
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:297
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
COMMIT & COMMIT::Stage ( EDA_ITEM aItem,
CHANGE_TYPE  aChangeType 
)
inherited

Adds a change of the item aItem of type aChangeType to the change list.

Definition at line 46 of file commit.cpp.

References CHT_ADD, CHT_DONE, CHT_FLAGS, CHT_MODIFY, CHT_REMOVE, CHT_TYPE, EDA_ITEM::Clone(), COMMIT::createModified(), COMMIT::m_changedItems, COMMIT::makeEntry(), and COMMIT::parentObject().

Referenced by COMMIT::Add(), COMMIT::Added(), PCB_EDIT_FRAME::Edit_Zone_Params(), COMMIT::Modify(), COMMIT::Remove(), COMMIT::Removed(), COMMIT::Stage(), and COMMIT::StageItems().

47 {
48  // CHT_MODIFY and CHT_DONE are not compatible
49  assert( ( aChangeType & ( CHT_MODIFY | CHT_DONE ) ) != ( CHT_MODIFY | CHT_DONE ) );
50 
51  int flag = aChangeType & CHT_FLAGS;
52 
53  switch( aChangeType & CHT_TYPE )
54  {
55  case CHT_ADD:
56  assert( m_changedItems.find( aItem ) == m_changedItems.end() );
57  makeEntry( aItem, CHT_ADD | flag );
58  return *this;
59 
60  case CHT_REMOVE:
61  makeEntry( aItem, CHT_REMOVE | flag );
62  return *this;
63 
64  case CHT_MODIFY:
65  {
66  EDA_ITEM* parent = parentObject( aItem );
67  return createModified( parent, parent->Clone(), flag );
68  }
69 
70  default:
71  assert( false );
72  }
73 
74  return *this;
75 }
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: commit.h:38
Flag to indicate the change is already applied, just notify observers (not compatible with CHT_MODIFY...
Definition: commit.h:45
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:181
COMMIT & createModified(EDA_ITEM *aItem, EDA_ITEM *aCopy, int aExtraFlags=0)
Definition: commit.cpp:138
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
virtual EDA_ITEM * parentObject(EDA_ITEM *aItem) const =0
virtual void makeEntry(EDA_ITEM *aItem, CHANGE_TYPE aType, EDA_ITEM *aCopy=NULL)
Definition: commit.cpp:155
COMMIT & COMMIT::Stage ( std::vector< EDA_ITEM * > &  container,
CHANGE_TYPE  aChangeType 
)
inherited

Definition at line 78 of file commit.cpp.

References COMMIT::Stage().

79 {
80  for( EDA_ITEM* item : container )
81  {
82  Stage( item, aChangeType );
83  }
84 
85  return *this;
86 }
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
Adds a change of the item aItem of type aChangeType to the change list.
Definition: commit.cpp:46
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
COMMIT & COMMIT::Stage ( const PICKED_ITEMS_LIST aItems,
UNDO_REDO_T  aModFlag = UR_UNSPECIFIED 
)
inherited

Definition at line 89 of file commit.cpp.

References COMMIT::convert(), PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetPickedItem(), PICKED_ITEMS_LIST::GetPickedItemLink(), PICKED_ITEMS_LIST::GetPickedItemStatus(), i, PICKED_ITEMS_LIST::m_Status, COMMIT::Modified(), COMMIT::Stage(), UR_CHANGED, and UR_UNSPECIFIED.

90 {
91  for( unsigned int i = 0; i < aItems.GetCount(); i++ )
92  {
93  UNDO_REDO_T change_type = aItems.GetPickedItemStatus( i );
94  EDA_ITEM* item = aItems.GetPickedItem( i );
95  EDA_ITEM* copy = NULL;
96 
97  if( change_type == UR_UNSPECIFIED )
98  change_type = aItems.m_Status;
99 
100  if( change_type == UR_UNSPECIFIED )
101  change_type = aModFlag;
102 
103  if( ( copy = aItems.GetPickedItemLink( i ) ) )
104  {
105  assert( change_type == UR_CHANGED );
106 
107  // There was already a copy created, so use it
108  Modified( item, copy );
109  }
110  else
111  {
112  Stage( item, convert( change_type ) );
113  }
114  }
115 
116  return *this;
117 }
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
Adds a change of the item aItem of type aChangeType to the change list.
Definition: commit.cpp:46
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
CHANGE_TYPE convert(UNDO_REDO_T aType) const
Definition: commit.cpp:190
UNDO_REDO_T GetPickedItemStatus(unsigned int aIdx) const
Function GetPickedItemStatus.
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
Function GetPickedItemLink.
unsigned GetCount() const
Function GetCount.
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.h:110
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
size_t i
Definition: json11.cpp:597
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
template<class Range >
COMMIT& COMMIT::StageItems ( const Range &  aRange,
CHANGE_TYPE  aChangeType 
)
inlineinherited

Definition at line 116 of file commit.h.

References COMMIT::Push(), COMMIT::Revert(), COMMIT::Stage(), and UR_UNSPECIFIED.

Referenced by ALIGN_DISTRIBUTE_TOOL::AlignBottom(), ALIGN_DISTRIBUTE_TOOL::AlignCenterX(), ALIGN_DISTRIBUTE_TOOL::AlignCenterY(), ALIGN_DISTRIBUTE_TOOL::AlignTop(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), ALIGN_DISTRIBUTE_TOOL::doAlignLeft(), ALIGN_DISTRIBUTE_TOOL::doAlignRight(), and POINT_EDITOR::OnSelectionChange().

117  {
118  for( const auto& item : aRange )
119  Stage( item, aChangeType );
120 
121  return *this;
122  }
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
Adds a change of the item aItem of type aChangeType to the change list.
Definition: commit.cpp:46

Member Data Documentation

std::set<EDA_ITEM*> COMMIT::m_changedItems
protectedinherited

Definition at line 181 of file commit.h.

Referenced by COMMIT::clear(), COMMIT::createModified(), COMMIT::makeEntry(), and COMMIT::Stage().

std::vector<COMMIT_LINE> COMMIT::m_changes
protectedinherited
bool BOARD_COMMIT::m_editModules
private

Definition at line 52 of file board_commit.h.

TOOL_MANAGER* BOARD_COMMIT::m_toolMgr
private

Definition at line 51 of file board_commit.h.


The documentation for this class was generated from the following files: