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
 

Protected Member Functions

void clear ()
 
virtual void makeEntry (EDA_ITEM *aItem, CHANGE_TYPE aType, EDA_ITEM *aCopy=NULL)
 
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 37 of file board_commit.cpp.

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

38 {
39  m_toolMgr = aTool->GetManager();
40  m_editModules = aTool->EditingModules();
41 }
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:47
bool EditingModules() const
Definition: pcb_tool.h:78
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 44 of file board_commit.cpp.

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

45 {
46  m_toolMgr = aFrame->GetToolManager();
48 }
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:810
bool m_editModules
Definition: board_commit.h:48
bool IsType(FRAME_T aType) const
Definition: wxstruct.h:216
BOARD_COMMIT::~BOARD_COMMIT ( )
virtual

Definition at line 51 of file board_commit.cpp.

52 {
53 }

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 PCBNEW_CONTROL::AppendBoard().

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 154 of file commit.h.

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

155  {
156  m_changedItems.clear();
157  m_changes.clear();
158  }
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:166
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:167
CHANGE_TYPE COMMIT::convert ( UNDO_REDO_T  aType) const
protectedinherited

Definition at line 154 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().

155 {
156  switch( aType )
157  {
158  case UR_NEW:
159  return CHT_ADD;
160 
161  case UR_DELETED:
162  return CHT_REMOVE;
163 
164  default:
165  assert( false );
166  // fall through
167 
168  case UR_CHANGED:
169  case UR_MOVED:
170  case UR_MIRRORED_X:
171  case UR_MIRRORED_Y:
172  case UR_ROTATED:
174  case UR_FLIPPED:
175  return CHT_MODIFY;
176  }
177 }
Definition: commit.h:38
bool COMMIT::Empty ( ) const
inlineinherited

Definition at line 135 of file commit.h.

References COMMIT::m_changes.

Referenced by PCBNEW_CONTROL::AppendBoard().

136  {
137  return m_changes.empty();
138  }
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:167
void COMMIT::makeEntry ( EDA_ITEM aItem,
CHANGE_TYPE  aType,
EDA_ITEM aCopy = NULL 
)
protectedvirtualinherited

Definition at line 138 of file commit.cpp.

References CHT_MODIFY, CHT_TYPE, 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::Modified(), and COMMIT::Stage().

139 {
140  // Expect an item copy if it is going to be modified
141  assert( !!aCopy == ( ( aType & CHT_TYPE ) == CHT_MODIFY ) );
142 
143  COMMIT_LINE ent;
144 
145  ent.m_item = aItem;
146  ent.m_type = aType;
147  ent.m_copy = aCopy;
148 
149  m_changedItems.insert( aItem );
150  m_changes.push_back( ent );
151 }
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:166
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:167
COMMIT & COMMIT::Modified ( EDA_ITEM aItem,
EDA_ITEM aCopy 
)
inherited

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

Requires a copy done

before the modification.

Definition at line 83 of file commit.cpp.

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

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

84 {
85  EDA_ITEM* parent = parentObject( aItem );
86 
87  if( m_changedItems.find( parent ) != m_changedItems.end() )
88  return *this; // item has been already modified once
89 
90  makeEntry( parent, CHT_MODIFY, aCopy );
91 
92  return *this;
93 }
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:166
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
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:138
EDA_ITEM * BOARD_COMMIT::parentObject ( EDA_ITEM aItem) const
overrideprivatevirtual

Implements COMMIT.

Definition at line 289 of file board_commit.cpp.

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

290 {
291  switch( aItem->Type() )
292  {
293  case PCB_PAD_T:
294  case PCB_MODULE_EDGE_T:
295  case PCB_MODULE_TEXT_T:
296  return aItem->GetParent();
297  default:
298  return aItem;
299  }
300 
301  return aItem;
302 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
EDA_ITEM * GetParent() const
Definition: base_struct.h:208
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 56 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_ITEM::GetParent(), BOARD::GetRatsnest(), 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(), RN_DATA::Recalculate(), KIGFX::VIEW::Remove(), BOARD::Remove(), MODULE::RunOnChildren(), PCB_BASE_FRAME::SaveCopyInUndoList(), ITEM_PICKER::SetLink(), TEXTE_MODULE::TEXT_is_DIVERS, TEXTE_MODULE::TEXT_is_REFERENCE, TEXTE_MODULE::TEXT_is_VALUE, EDA_ITEM::Type(), KIGFX::VIEW::Update(), RN_DATA::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(), PLACEMENT_TOOL::AlignBottom(), PLACEMENT_TOOL::AlignLeft(), PLACEMENT_TOOL::AlignRight(), PLACEMENT_TOOL::AlignTop(), PCBNEW_CONTROL::AppendBoard(), PAD_TOOL::applyPadSettings(), PCB_EDIT_FRAME::Clean_Pcb(), MICROWAVE_TOOL::createInductorBetween(), PLACEMENT_TOOL::DistributeHorizontally(), PLACEMENT_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(), ARRAY_CREATOR::Invoke(), DIALOG_EXCHANGE_MODULE::OnOkClick(), TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick(), DIALOG_DIMENSION_EDITOR::OnOKClick(), POINT_EDITOR::OnSelectionChange(), MODULE_EDITOR_TOOLS::PasteItems(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), MODULE_EDITOR_TOOLS::PlacePad(), 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().

57 {
58  // Objects potentially interested in changes:
59  PICKED_ITEMS_LIST undoList;
60  KIGFX::VIEW* view = m_toolMgr->GetView();
61  BOARD* board = (BOARD*) m_toolMgr->GetModel();
63  RN_DATA* ratsnest = board->GetRatsnest();
64  std::set<EDA_ITEM*> savedModules;
65 
66  if( Empty() )
67  return;
68 
69  for( COMMIT_LINE& ent : m_changes )
70  {
71  int changeType = ent.m_type & CHT_TYPE;
72  int changeFlags = ent.m_type & CHT_FLAGS;
73  BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( ent.m_item );
74 
75  // Module items need to be saved in the undo buffer before modification
76  if( m_editModules )
77  {
78  // Be sure that we are storing a module
79  if( ent.m_item->Type() != PCB_MODULE_T )
80  ent.m_item = ent.m_item->GetParent();
81 
82  // We have not saved the module yet, so let's create an entry
83  if( savedModules.count( ent.m_item ) == 0 )
84  {
85  if( !ent.m_copy )
86  {
87  assert( changeType != CHT_MODIFY ); // too late to make a copy..
88  ent.m_copy = ent.m_item->Clone();
89  }
90 
91  assert( ent.m_item->Type() == PCB_MODULE_T );
92  assert( ent.m_copy->Type() == PCB_MODULE_T );
93 
94  if( aCreateUndoEntry )
95  {
96  ITEM_PICKER itemWrapper( ent.m_item, UR_CHANGED );
97  itemWrapper.SetLink( ent.m_copy );
98  undoList.PushItem( itemWrapper );
99  frame->SaveCopyInUndoList( undoList, UR_CHANGED );
100  }
101 
102  savedModules.insert( ent.m_item );
103  static_cast<MODULE*>( ent.m_item )->SetLastEditTime();
104  }
105  }
106 
107  switch( changeType )
108  {
109  case CHT_ADD:
110  {
111  if( !m_editModules )
112  {
113  if( aCreateUndoEntry )
114  {
115  undoList.PushItem( ITEM_PICKER( boardItem, UR_NEW ) );
116  }
117 
118  if( !( changeFlags & CHT_DONE ) )
119  board->Add( boardItem );
120 
121  //ratsnest->Add( boardItem ); // TODO currently done by BOARD::Add()
122 
123  if( boardItem->Type() == PCB_MODULE_T )
124  {
125  MODULE* mod = static_cast<MODULE*>( boardItem );
126  mod->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) );
127  }
128  }
129  else
130  {
131  // modules inside modules are not supported yet
132  assert( boardItem->Type() != PCB_MODULE_T );
133 
134  if( !( changeFlags & CHT_DONE ) )
135  board->m_Modules->Add( boardItem );
136  }
137 
138  view->Add( boardItem );
139  break;
140  }
141 
142  case CHT_REMOVE:
143  {
144  if( !m_editModules && aCreateUndoEntry )
145  {
146  undoList.PushItem( ITEM_PICKER( boardItem, UR_DELETED ) );
147  }
148 
149  switch( boardItem->Type() )
150  {
151  // Module items
152  case PCB_PAD_T:
153  case PCB_MODULE_EDGE_T:
154  case PCB_MODULE_TEXT_T:
155  {
156  // Do not allow footprint text removal when not editing a module
157  if( !m_editModules )
158  break;
159 
160  bool remove = true;
161 
162  if( boardItem->Type() == PCB_MODULE_TEXT_T )
163  {
164  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( boardItem );
165 
166  switch( text->GetType() )
167  {
169  //DisplayError( frame, _( "Cannot delete component reference." ) );
170  remove = false;
171  break;
172 
174  //DisplayError( frame, _( "Cannot delete component value." ) );
175  remove = false;
176  break;
177 
178  case TEXTE_MODULE::TEXT_is_DIVERS: // suppress warnings
179  break;
180 
181  default:
182  assert( false );
183  break;
184  }
185  }
186 
187  if( remove )
188  {
189  view->Remove( boardItem );
190 
191  if( !( changeFlags & CHT_DONE ) )
192  {
193  MODULE* module = static_cast<MODULE*>( boardItem->GetParent() );
194  assert( module && module->Type() == PCB_MODULE_T );
195  module->Delete( boardItem );
196  }
197 
198  board->m_Status_Pcb = 0; // it is done in the legacy view (ratsnest perhaps?)
199  }
200 
201  break;
202  }
203 
204  // Board items
205  case PCB_LINE_T: // a segment not on copper layers
206  case PCB_TEXT_T: // a text on a layer
207  case PCB_TRACE_T: // a track segment (segment on a copper layer)
208  case PCB_VIA_T: // a via (like track segment on a copper layer)
209  case PCB_DIMENSION_T: // a dimension (graphic item)
210  case PCB_TARGET_T: // a target (graphic item)
211  case PCB_MARKER_T: // a marker used to show something
212  case PCB_ZONE_T: // SEG_ZONE items are now deprecated
213  case PCB_ZONE_AREA_T:
214  view->Remove( boardItem );
215 
216  if( !( changeFlags & CHT_DONE ) )
217  board->Remove( boardItem );
218 
219  //ratsnest->Remove( boardItem ); // currently done by BOARD::Remove()
220  break;
221 
222  case PCB_MODULE_T:
223  {
224  // There are no modules inside a module yet
225  assert( !m_editModules );
226 
227  MODULE* module = static_cast<MODULE*>( boardItem );
228  module->ClearFlags();
229  module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) );
230 
231  view->Remove( module );
232 
233  if( !( changeFlags & CHT_DONE ) )
234  board->Remove( module );
235 
236  // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore
237  board->m_Status_Pcb = 0;
238  }
239  break;
240 
241  default: // other types do not need to (or should not) be handled
242  assert( false );
243  break;
244  }
245  break;
246  }
247 
248  case CHT_MODIFY:
249  {
250  if( !m_editModules && aCreateUndoEntry )
251  {
252  ITEM_PICKER itemWrapper( boardItem, UR_CHANGED );
253  assert( ent.m_copy );
254  itemWrapper.SetLink( ent.m_copy );
255  undoList.PushItem( itemWrapper );
256  }
257 
258  if( boardItem->Type() == PCB_MODULE_T )
259  {
260  MODULE* module = static_cast<MODULE*>( boardItem );
261  module->RunOnChildren( [&view] ( BOARD_ITEM* aItem ) { view->Update( aItem ); } );
262  }
263 
264  view->Update ( boardItem );
265  ratsnest->Update( boardItem );
266  break;
267  }
268 
269  default:
270  assert( false );
271  break;
272  }
273  }
274 
275  if( !m_editModules && aCreateUndoEntry )
276  frame->SaveCopyInUndoList( undoList, UR_UNSPECIFIED );
277 
278  if( TOOL_MANAGER* toolMgr = frame->GetToolManager() )
279  toolMgr->PostEvent( { TC_MESSAGE, TA_MODEL_CHANGE, AS_GLOBAL } );
280 
281  ratsnest->Recalculate();
282  frame->OnModify();
283  frame->UpdateMsgPanel();
284 
285  clear();
286 }
void Add(BOARD_ITEM *aBoardItem, ADD_MODE aMode=ADD_INSERT) override
>
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
BOARD_ITEM_CONTAINER * GetParent() const
void RunOnChildren(std::function< void(BOARD_ITEM *)> aFunction)
Function RunOnChildren.
void clear()
Definition: commit.h:154
Class RN_DATA.
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:258
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:341
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
bool Update(const BOARD_ITEM *aItem)
Function Update() Updates the ratsnest data for an item.
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:47
bool Empty() const
Definition: commit.h:135
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
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
>
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.
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:112
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
RN_DATA * GetRatsnest() const
Function GetRatsnest() returns list of missing connections between components/tracks.
Definition: class_board.h:287
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:113
void Recalculate(int aNet=-1)
Function Recalculate() Recomputes ratsnest for selected net number or all nets that need updating...
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:810
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:111
EDA_ITEM * GetModel() const
Definition: tool_manager.h:253
bool m_editModules
Definition: board_commit.h:48
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
DLIST< MODULE > m_Modules
Definition: class_board.h:243
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:167
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:254
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the containter and deletes it.
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:311
Class VIEW.
Definition: view.h:58
void UpdateMsgPanel() override
>
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:243
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
#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
>
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
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(), 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::clean_vias(), TRACKS_CLEANER::delete_null_segments(), TRACKS_CLEANER::deleteDanglingTracks(), TRACKS_CLEANER::merge_collinear_of_track(), TRACKS_CLEANER::remove_duplicates_of_track(), TRACKS_CLEANER::remove_duplicates_of_via(), and TRACKS_CLEANER::removeBadTrackSegments().

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 305 of file board_commit.cpp.

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

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

306 {
307  PICKED_ITEMS_LIST undoList;
308  KIGFX::VIEW* view = m_toolMgr->GetView();
309  BOARD* board = (BOARD*) m_toolMgr->GetModel();
310  RN_DATA* ratsnest = board->GetRatsnest();
311 
312  for( auto it = m_changes.rbegin(); it != m_changes.rend(); ++it )
313  {
314  COMMIT_LINE& ent = *it;
315  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( ent.m_item );
316  BOARD_ITEM* copy = static_cast<BOARD_ITEM*>( ent.m_copy );
317 
318  switch( ent.m_type )
319  {
320  case CHT_ADD:
321  if( item->Type() == PCB_MODULE_T )
322  {
323  MODULE* oldModule = static_cast<MODULE*>( item );
324  oldModule->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) );
325  }
326 
327  view->Remove( item );
328  ratsnest->Remove( item );
329  break;
330 
331  case CHT_REMOVE:
332  if( item->Type() == PCB_MODULE_T )
333  {
334  MODULE* newModule = static_cast<MODULE*>( item );
335  newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) );
336  newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) );
337  }
338 
339  view->Add( item );
340  ratsnest->Add( item );
341  break;
342 
343  case CHT_MODIFY:
344  {
345  if( item->Type() == PCB_MODULE_T )
346  {
347  MODULE* oldModule = static_cast<MODULE*>( item );
348  oldModule->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) );
349  }
350 
351  view->Remove( item );
352  ratsnest->Remove( item );
353 
354  item->SwapData( copy );
355 
356  item->ClearFlags( SELECTED );
357 
358  // Update all pads/drawings/texts, as they become invalid
359  // for the VIEW after SwapData() called for modules
360  if( item->Type() == PCB_MODULE_T )
361  {
362  MODULE* newModule = static_cast<MODULE*>( item );
363  newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) );
364  newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) );
365  }
366 
367  view->Add( item );
368  ratsnest->Add( item );
369  delete copy;
370  break;
371  }
372 
373  default:
374  assert( false );
375  break;
376  }
377  }
378 
379  ratsnest->Recalculate();
380 
381  clear();
382 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
void RunOnChildren(std::function< void(BOARD_ITEM *)> aFunction)
Function RunOnChildren.
void clear()
Definition: commit.h:154
Class RN_DATA.
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:341
TOOL_MANAGER * m_toolMgr
Definition: board_commit.h:47
bool Remove(const BOARD_ITEM *aItem)
Function Remove() Removes an item from the ratsnest data.
void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: undo_redo.cpp:577
#define SELECTED
Definition: base_struct.h:120
class MODULE, a footprint
Definition: typeinfo.h:101
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
RN_DATA * GetRatsnest() const
Function GetRatsnest() returns list of missing connections between components/tracks.
Definition: class_board.h:287
void Recalculate(int aNet=-1)
Function Recalculate() Recomputes ratsnest for selected net number or all nets that need updating...
EDA_ITEM * GetModel() const
Definition: tool_manager.h:253
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:167
bool Add(const BOARD_ITEM *aItem)
Function Add() Adds an item to the ratsnest data.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:311
Class VIEW.
Definition: view.h:58
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:243
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::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  assert( m_changedItems.find( aItem ) == m_changedItems.end() );
60  makeEntry( aItem, CHT_REMOVE | flag );
61  return *this;
62 
63  case CHT_MODIFY:
64  {
65  EDA_ITEM* parent = parentObject( aItem );
66 
67  if( m_changedItems.find( parent ) != m_changedItems.end() )
68  return *this; // item has been already modified once
69 
70  makeEntry( parent, CHT_MODIFY | flag, parent->Clone() );
71 
72  return *this;
73  }
74 
75  default:
76  assert( false );
77  }
78 
79  return *this;
80 }
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:166
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
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:138
COMMIT & COMMIT::Stage ( std::vector< EDA_ITEM * > &  container,
CHANGE_TYPE  aChangeType 
)
inherited

Definition at line 96 of file commit.cpp.

References COMMIT::Stage().

97 {
98  for( EDA_ITEM* item : container )
99  {
100  Stage( item, aChangeType );
101  }
102 
103  return *this;
104 }
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:151
COMMIT & COMMIT::Stage ( const PICKED_ITEMS_LIST aItems,
UNDO_REDO_T  aModFlag = UR_UNSPECIFIED 
)
inherited

Definition at line 107 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.

108 {
109  for( unsigned int i = 0; i < aItems.GetCount(); i++ )
110  {
111  UNDO_REDO_T change_type = aItems.GetPickedItemStatus( i );
112  EDA_ITEM* item = aItems.GetPickedItem( i );
113  EDA_ITEM* copy = NULL;
114 
115  if( change_type == UR_UNSPECIFIED )
116  change_type = aItems.m_Status;
117 
118  if( change_type == UR_UNSPECIFIED )
119  change_type = aModFlag;
120 
121  if( ( copy = aItems.GetPickedItemLink( i ) ) )
122  {
123  assert( change_type == UR_CHANGED );
124 
125  // There was already a copy created, so use it
126  Modified( item, copy );
127  }
128  else
129  {
130  Stage( item, convert( change_type ) );
131  }
132  }
133 
134  return *this;
135 }
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 & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.cpp:83
CHANGE_TYPE convert(UNDO_REDO_T aType) const
Definition: commit.cpp:154
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.
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:151
template<class Range >
COMMIT& COMMIT::StageItems ( const Range &  aRange,
CHANGE_TYPE  aChangeType 
)
inlineinherited

Definition at line 113 of file commit.h.

References COMMIT::Stage().

Referenced by PLACEMENT_TOOL::AlignBottom(), PLACEMENT_TOOL::AlignLeft(), PLACEMENT_TOOL::AlignRight(), PLACEMENT_TOOL::AlignTop(), PLACEMENT_TOOL::DistributeHorizontally(), PLACEMENT_TOOL::DistributeVertically(), and POINT_EDITOR::OnSelectionChange().

114  {
115  for( const auto& item : aRange )
116  Stage( item, aChangeType );
117 
118  return *this;
119  }
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 166 of file commit.h.

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

std::vector<COMMIT_LINE> COMMIT::m_changes
protectedinherited

Definition at line 167 of file commit.h.

Referenced by COMMIT::clear(), COMMIT::Empty(), COMMIT::makeEntry(), and COMMIT::~COMMIT().

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: