KiCad PCB EDA Suite
BOARD_COMMIT Class Reference

#include <board_commit.h>

Inheritance diagram for BOARD_COMMIT:
COMMIT

Public Member Functions

 BOARD_COMMIT (PCB_TOOL *aTool)
 
 BOARD_COMMIT (PCB_BASE_FRAME *aFrame)
 
virtual ~BOARD_COMMIT ()
 
virtual void Push (const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=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 36 of file board_commit.h.

Constructor & Destructor Documentation

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:47
bool EditingModules() const
Definition: pcb_tool.h:91
bool m_editModules
Definition: board_commit.h:48
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 ( PCB_BASE_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:47
TOOL_MANAGER * GetToolManager() const
Function GetToolManager returns the tool manager instance, if any.
Definition: draw_frame.h:877
bool m_editModules
Definition: board_commit.h:48
bool IsType(FRAME_T aType) const
Definition: wxstruct.h:229
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().

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:44
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 160 of file commit.h.

References COMMIT::m_changedItems, and COMMIT::m_changes.

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

Definition at line 185 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::Stage().

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

Definition at line 136 of file commit.cpp.

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

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

137 {
138  EDA_ITEM* parent = parentObject( aItem );
139  auto entryIt = m_changedItems.find( parent );
140 
141  if( entryIt != m_changedItems.end() )
142  return *this; // item has been already modified once
143 
144  makeEntry( parent, CHT_MODIFY | aExtraFlags, aCopy );
145 
146  return *this;
147 }
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:180
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
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:150
bool COMMIT::Empty ( ) const
inlineinherited

Definition at line 138 of file commit.h.

References COMMIT::m_changes.

139  {
140  return m_changes.empty();
141  }
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:181
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 173 of file commit.cpp.

References COMMIT::m_changes.

Referenced by COMMIT::GetStatus().

174 {
175  for( COMMIT_LINE& change : m_changes )
176  {
177  if( change.m_item == aItem )
178  return &change;
179  }
180 
181  return nullptr;
182 }
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:181
int COMMIT::GetStatus ( EDA_ITEM aItem)
inherited

Returns status of an item.

Definition at line 118 of file commit.cpp.

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

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

119 {
120  COMMIT_LINE* entry = findEntry( parentObject( aItem ) );
121 
122  return entry ? entry->m_type : 0;
123 }
COMMIT_LINE * findEntry(EDA_ITEM *aItem)
Searches for an entry describing change for a particular item.
Definition: commit.cpp:173
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 150 of file commit.cpp.

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

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

151 {
152  // Expect an item copy if it is going to be modified
153  assert( !!aCopy == ( ( aType & CHT_TYPE ) == CHT_MODIFY ) );
154 
155  if( m_changedItems.find( aItem ) != m_changedItems.end() )
156  {
157  eraseIf( m_changes, [aItem] ( const COMMIT_LINE& aEnt ) {
158  return aEnt.m_item == aItem;
159  } );
160  }
161 
162  COMMIT_LINE ent;
163 
164  ent.m_item = aItem;
165  ent.m_type = aType;
166  ent.m_copy = aCopy;
167 
168  m_changedItems.insert( aItem );
169  m_changes.push_back( ent );
170 }
void eraseIf(Container &c, F &&f)
Definition: commit.cpp:127
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:180
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:181
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:136
EDA_ITEM * BOARD_COMMIT::parentObject ( EDA_ITEM aItem) const
overrideprivatevirtual

Implements COMMIT.

Definition at line 299 of file board_commit.cpp.

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

300 {
301  switch( aItem->Type() )
302  {
303  case PCB_PAD_T:
304  case PCB_MODULE_EDGE_T:
305  case PCB_MODULE_TEXT_T:
306  return aItem->GetParent();
307  default:
308  return aItem;
309  }
310 
311  return aItem;
312 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
EDA_ITEM * GetParent() const
Definition: base_struct.h:222
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
void BOARD_COMMIT::Push ( const wxString &  aMessage = wxT("A commit"),
bool  aCreateUndoEntry = 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, mod, 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_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, PCB_ZONE_T, PICKED_ITEMS_LIST::PushItem(), PCB_DRAW_PANEL_GAL::RedrawRatsnest(), KIGFX::VIEW::Remove(), BOARD::Remove(), MODULE::RunOnChildren(), PCB_BASE_FRAME::SaveCopyInUndoList(), ITEM_PICKER::SetLink(), EDA_ITEM::SetParent(), TEXTE_MODULE::TEXT_is_DIVERS, TEXTE_MODULE::TEXT_is_REFERENCE, TEXTE_MODULE::TEXT_is_VALUE, EDA_ITEM::Type(), 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::AlignLeft(), ALIGN_DISTRIBUTE_TOOL::AlignRight(), ALIGN_DISTRIBUTE_TOOL::AlignTop(), PAD_TOOL::applyPadSettings(), PCB_EDIT_FRAME::Clean_Pcb(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawLine(), DRAWING_TOOL::drawSegment(), PCB_EDIT_FRAME::Edit_Zone_Params(), MODULE_EDITOR_TOOLS::EnumeratePads(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), PCB_EDIT_FRAME::Fill_Zone(), ARRAY_CREATOR::Invoke(), DIALOG_EXCHANGE_MODULE::OnOkClick(), TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick(), DIALOG_DIMENSION_EDITOR::OnOKClick(), POINT_EDITOR::OnSelectionChange(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), DRAWING_TOOL::PlaceText(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), PAD_TOOL::pushPadSettings(), PCB_EDIT_FRAME::RemoveMisConnectedTracks(), PCB_BASE_FRAME::ResetModuleTextSizes(), DRAWING_TOOL::SetAnchor(), DialogEditModuleText::TransferDataFromWindow(), DIALOG_PCB_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_MODULE_MODULE_EDITOR::TransferDataFromWindow(), DIALOG_MODULE_BOARD_EDITOR::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::TransferDataFromWindow(), BOARD_NETLIST_UPDATER::UpdateNetlist(), PCB_EDITOR_CONTROL::ZoneDuplicate(), PCB_EDITOR_CONTROL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneFillAll(), PCB_EDITOR_CONTROL::ZoneUnfill(), and PCB_EDITOR_CONTROL::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 
69  if( Empty() )
70  return;
71 
72  for( COMMIT_LINE& ent : m_changes )
73  {
74  int changeType = ent.m_type & CHT_TYPE;
75  int changeFlags = ent.m_type & CHT_FLAGS;
76  BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( ent.m_item );
77 
78  // Module items need to be saved in the undo buffer before modification
79  if( m_editModules )
80  {
81  // Be sure that we are storing a module
82  if( ent.m_item->Type() != PCB_MODULE_T )
83  ent.m_item = ent.m_item->GetParent();
84 
85  // We have not saved the module yet, so let's create an entry
86  if( savedModules.count( ent.m_item ) == 0 )
87  {
88  if( !ent.m_copy )
89  {
90  wxASSERT( changeType != CHT_MODIFY ); // too late to make a copy..
91  ent.m_copy = ent.m_item->Clone();
92  }
93 
94  wxASSERT( ent.m_item->Type() == PCB_MODULE_T );
95  wxASSERT( ent.m_copy->Type() == PCB_MODULE_T );
96 
97  if( aCreateUndoEntry )
98  {
99  ITEM_PICKER itemWrapper( ent.m_item, UR_CHANGED );
100  itemWrapper.SetLink( ent.m_copy );
101  undoList.PushItem( itemWrapper );
102  frame->SaveCopyInUndoList( undoList, UR_CHANGED );
103  }
104 
105  savedModules.insert( ent.m_item );
106  static_cast<MODULE*>( ent.m_item )->SetLastEditTime();
107  }
108  }
109 
110  switch( changeType )
111  {
112  case CHT_ADD:
113  {
114  if( !m_editModules )
115  {
116  if( aCreateUndoEntry )
117  {
118  undoList.PushItem( ITEM_PICKER( boardItem, UR_NEW ) );
119  }
120 
121  if( !( changeFlags & CHT_DONE ) )
122  board->Add( boardItem );
123 
124  //ratsnest->Add( boardItem ); // TODO currently done by BOARD::Add()
125 
126  if( boardItem->Type() == PCB_MODULE_T )
127  {
128  MODULE* mod = static_cast<MODULE*>( boardItem );
129  mod->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) );
130  }
131  }
132  else
133  {
134  // modules inside modules are not supported yet
135  wxASSERT( boardItem->Type() != PCB_MODULE_T );
136 
137  boardItem->SetParent( board->m_Modules.GetFirst() );
138  if( !( changeFlags & CHT_DONE ) )
139  board->m_Modules->Add( boardItem );
140  }
141 
142  view->Add( boardItem );
143  break;
144  }
145 
146  case CHT_REMOVE:
147  {
148  if( !m_editModules && aCreateUndoEntry )
149  {
150  undoList.PushItem( ITEM_PICKER( boardItem, UR_DELETED ) );
151  }
152 
153  switch( boardItem->Type() )
154  {
155  // Module items
156  case PCB_PAD_T:
157  case PCB_MODULE_EDGE_T:
158  case PCB_MODULE_TEXT_T:
159  {
160  // Do not allow footprint text removal when not editing a module
161  if( !m_editModules )
162  break;
163 
164  bool remove = true;
165 
166  if( boardItem->Type() == PCB_MODULE_TEXT_T )
167  {
168  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( boardItem );
169 
170  switch( text->GetType() )
171  {
173  //DisplayError( frame, _( "Cannot delete component reference." ) );
174  remove = false;
175  break;
176 
178  //DisplayError( frame, _( "Cannot delete component value." ) );
179  remove = false;
180  break;
181 
182  case TEXTE_MODULE::TEXT_is_DIVERS: // suppress warnings
183  break;
184 
185  default:
186  wxASSERT( false );
187  break;
188  }
189  }
190 
191  if( remove )
192  {
193  view->Remove( boardItem );
194 
195  if( !( changeFlags & CHT_DONE ) )
196  {
197  MODULE* module = static_cast<MODULE*>( boardItem->GetParent() );
198  wxASSERT( module && module->Type() == PCB_MODULE_T );
199  module->Delete( boardItem );
200  }
201 
202  board->m_Status_Pcb = 0; // it is done in the legacy view (ratsnest perhaps?)
203  }
204 
205  break;
206  }
207 
208  // Board items
209  case PCB_LINE_T: // a segment not on copper layers
210  case PCB_TEXT_T: // a text on a layer
211  case PCB_TRACE_T: // a track segment (segment on a copper layer)
212  case PCB_VIA_T: // a via (like track segment on a copper layer)
213  case PCB_DIMENSION_T: // a dimension (graphic item)
214  case PCB_TARGET_T: // a target (graphic item)
215  case PCB_MARKER_T: // a marker used to show something
216  case PCB_ZONE_T: // SEG_ZONE items are now deprecated
217  case PCB_ZONE_AREA_T:
218  view->Remove( boardItem );
219 
220  if( !( changeFlags & CHT_DONE ) )
221  board->Remove( boardItem );
222 
223  break;
224 
225  case PCB_MODULE_T:
226  {
227  // There are no modules inside a module yet
228  wxASSERT( !m_editModules );
229 
230  MODULE* module = static_cast<MODULE*>( boardItem );
231  module->ClearFlags();
232  module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) );
233 
234  view->Remove( module );
235 
236  if( !( changeFlags & CHT_DONE ) )
237  board->Remove( module );
238 
239  // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore
240  board->m_Status_Pcb = 0;
241  }
242  break;
243 
244  default: // other types do not need to (or should not) be handled
245  wxASSERT( false );
246  break;
247  }
248  break;
249  }
250 
251  case CHT_MODIFY:
252  {
253  if( !m_editModules && aCreateUndoEntry )
254  {
255  ITEM_PICKER itemWrapper( boardItem, UR_CHANGED );
256  wxASSERT( ent.m_copy );
257  itemWrapper.SetLink( ent.m_copy );
258  undoList.PushItem( itemWrapper );
259  }
260 
261  if( boardItem->Type() == PCB_MODULE_T )
262  {
263  MODULE* module = static_cast<MODULE*>( boardItem );
264  module->RunOnChildren( [&view] ( BOARD_ITEM* aItem ) { view->Update( aItem ); } );
265  }
266 
267  view->Update ( boardItem );
268  connectivity->MarkItemNetAsDirty( static_cast<BOARD_ITEM*>( ent.m_copy ) );
269  connectivity->Update( boardItem );
270  break;
271  }
272 
273  default:
274  wxASSERT( false );
275  break;
276  }
277  }
278 
279  if( !m_editModules && aCreateUndoEntry )
280  frame->SaveCopyInUndoList( undoList, UR_UNSPECIFIED );
281 
282  if( TOOL_MANAGER* toolMgr = frame->GetToolManager() )
283  toolMgr->PostEvent( { TC_MESSAGE, TA_MODEL_CHANGE, AS_GLOBAL } );
284 
285  if ( !m_editModules )
286  {
287  auto panel = static_cast<PCB_DRAW_PANEL_GAL*>( frame->GetGalCanvas() );
288  connectivity->RecalculateRatsnest();
289  panel->RedrawRatsnest();
290  }
291 
292  frame->OnModify();
293  frame->UpdateMsgPanel();
294 
295  clear();
296 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
BOARD_ITEM_CONTAINER * GetParent() const
void RunOnChildren(std::function< void(BOARD_ITEM *)> aFunction)
Function RunOnChildren.
void clear()
Definition: commit.h:160
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
Definition: commit.h:38
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:114
void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:342
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
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:102
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:47
bool Empty() const
Definition: commit.h:138
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
void RedrawRatsnest()
Forces refresh of the ratsnest visual representation
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
Class TOOL_MANAGER.
Definition: tool_manager.h:49
class MODULE, a footprint
Definition: typeinfo.h:101
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:227
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 SEGZONE, a segment used to fill a zone area (segment on a copper layer)
Definition: typeinfo.h:109
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
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:1385
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:112
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:113
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
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
Function GetToolManager returns the tool manager instance, if any.
Definition: draw_frame.h:877
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:111
EDA_ITEM * GetModel() const
Definition: tool_manager.h:262
bool m_editModules
Definition: board_commit.h:48
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
DLIST< MODULE > m_Modules
Definition: class_board.h:245
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:181
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:268
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the containter and deletes it.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:870
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:312
Class VIEW.
Definition: view.h:58
void UpdateMsgPanel() override
>
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
#define mod(a, n)
Definition: greymap.cpp:24
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:237
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(), and BOARD_NETLIST_UPDATER::replaceComponent().

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:44
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:44
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 315 of file board_commit.cpp.

References KIGFX::VIEW::Add(), CHT_ADD, CHT_MODIFY, CHT_REMOVE, 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(), MODULE::RunOnChildren(), SELECTED, BOARD_ITEM::SwapData(), and EDA_ITEM::Type().

Referenced by MODULE_EDITOR_TOOLS::EnumeratePads(), POINT_EDITOR::OnSelectionChange(), and PCB_EDITOR_CONTROL::ZoneFillAll().

316 {
317  PICKED_ITEMS_LIST undoList;
318  KIGFX::VIEW* view = m_toolMgr->GetView();
319  BOARD* board = (BOARD*) m_toolMgr->GetModel();
320  auto connectivity = board->GetConnectivity();
321 
322  for( auto it = m_changes.rbegin(); it != m_changes.rend(); ++it )
323  {
324  COMMIT_LINE& ent = *it;
325  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( ent.m_item );
326  BOARD_ITEM* copy = static_cast<BOARD_ITEM*>( ent.m_copy );
327 
328  switch( ent.m_type )
329  {
330  case CHT_ADD:
331  if( item->Type() == PCB_MODULE_T )
332  {
333  MODULE* oldModule = static_cast<MODULE*>( item );
334  oldModule->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) );
335  }
336 
337  view->Remove( item );
338  connectivity->Remove( item );
339  break;
340 
341  case CHT_REMOVE:
342  if( item->Type() == PCB_MODULE_T )
343  {
344  MODULE* newModule = static_cast<MODULE*>( item );
345  newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) );
346  newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) );
347  }
348 
349  view->Add( item );
350  connectivity->Add( item );
351  break;
352 
353  case CHT_MODIFY:
354  {
355  if( item->Type() == PCB_MODULE_T )
356  {
357  MODULE* oldModule = static_cast<MODULE*>( item );
358  oldModule->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) );
359  }
360 
361  view->Remove( item );
362  connectivity->Remove( item );
363 
364  item->SwapData( copy );
365 
366  item->ClearFlags( SELECTED );
367 
368  // Update all pads/drawings/texts, as they become invalid
369  // for the VIEW after SwapData() called for modules
370  if( item->Type() == PCB_MODULE_T )
371  {
372  MODULE* newModule = static_cast<MODULE*>( item );
373  newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) );
374  newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) );
375  }
376 
377  view->Add( item );
378  connectivity->Add( item );
379  delete copy;
380  break;
381  }
382 
383  default:
384  wxASSERT( false );
385  break;
386  }
387  }
388 
389  if ( !m_editModules )
390  connectivity->RecalculateRatsnest();
391 
392  clear();
393 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
void RunOnChildren(std::function< void(BOARD_ITEM *)> aFunction)
Function RunOnChildren.
void clear()
Definition: commit.h:160
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
Definition: commit.h:38
void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:342
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:47
void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: undo_redo.cpp:567
#define SELECTED
Definition: base_struct.h:134
class MODULE, a footprint
Definition: typeinfo.h:101
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:48
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:181
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:312
Class VIEW.
Definition: view.h:58
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:290
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 44 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().

45 {
46  // CHT_MODIFY and CHT_DONE are not compatible
47  assert( ( aChangeType & ( CHT_MODIFY | CHT_DONE ) ) != ( CHT_MODIFY | CHT_DONE ) );
48 
49  int flag = aChangeType & CHT_FLAGS;
50 
51  switch( aChangeType & CHT_TYPE )
52  {
53  case CHT_ADD:
54  assert( m_changedItems.find( aItem ) == m_changedItems.end() );
55  makeEntry( aItem, CHT_ADD | flag );
56  return *this;
57 
58  case CHT_REMOVE:
59  makeEntry( aItem, CHT_REMOVE | flag );
60  return *this;
61 
62  case CHT_MODIFY:
63  {
64  EDA_ITEM* parent = parentObject( aItem );
65  return createModified( parent, parent->Clone(), flag );
66  }
67 
68  default:
69  assert( false );
70  }
71 
72  return *this;
73 }
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:180
COMMIT & createModified(EDA_ITEM *aItem, EDA_ITEM *aCopy, int aExtraFlags=0)
Definition: commit.cpp:136
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
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:150
COMMIT & COMMIT::Stage ( std::vector< EDA_ITEM * > &  container,
CHANGE_TYPE  aChangeType 
)
inherited

Definition at line 76 of file commit.cpp.

References COMMIT::Stage().

77 {
78  for( EDA_ITEM* item : container )
79  {
80  Stage( item, aChangeType );
81  }
82 
83  return *this;
84 }
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:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
COMMIT & COMMIT::Stage ( const PICKED_ITEMS_LIST aItems,
UNDO_REDO_T  aModFlag = UR_UNSPECIFIED 
)
inherited

Definition at line 87 of file commit.cpp.

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

88 {
89  for( unsigned int i = 0; i < aItems.GetCount(); i++ )
90  {
91  UNDO_REDO_T change_type = aItems.GetPickedItemStatus( i );
92  EDA_ITEM* item = aItems.GetPickedItem( i );
93  EDA_ITEM* copy = NULL;
94 
95  if( change_type == UR_UNSPECIFIED )
96  change_type = aItems.m_Status;
97 
98  if( change_type == UR_UNSPECIFIED )
99  change_type = aModFlag;
100 
101  if( ( copy = aItems.GetPickedItemLink( i ) ) )
102  {
103  assert( change_type == UR_CHANGED );
104 
105  // There was already a copy created, so use it
106  Modified( item, copy );
107  }
108  else
109  {
110  Stage( item, convert( change_type ) );
111  }
112  }
113 
114  return *this;
115 }
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:44
CHANGE_TYPE convert(UNDO_REDO_T aType) const
Definition: commit.cpp:185
UNDO_REDO_T GetPickedItemStatus(unsigned int aIdx) const
Function GetPickedItemStatus.
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
Function GetPickedItemLink.
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
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.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
template<class Range >
COMMIT& COMMIT::StageItems ( const Range &  aRange,
CHANGE_TYPE  aChangeType 
)
inlineinherited

Definition at line 116 of file commit.h.

References COMMIT::Stage().

Referenced by ALIGN_DISTRIBUTE_TOOL::AlignBottom(), ALIGN_DISTRIBUTE_TOOL::AlignLeft(), ALIGN_DISTRIBUTE_TOOL::AlignRight(), ALIGN_DISTRIBUTE_TOOL::AlignTop(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), 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:44

Member Data Documentation

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

Definition at line 180 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 48 of file board_commit.h.

TOOL_MANAGER* BOARD_COMMIT::m_toolMgr
private

Definition at line 47 of file board_commit.h.


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