KiCad PCB EDA Suite
COMMIT Class Referenceabstract

Class COMMIT. More...

#include <commit.h>

Inheritance diagram for COMMIT:
BOARD_COMMIT

Classes

struct  COMMIT_LINE
 

Public Member Functions

 COMMIT ()
 
virtual ~COMMIT ()
 
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)
 
virtual void Push (const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true)=0
 

Executes the changes.

More...
 
virtual void Revert ()=0
 

Revertes the commit by restoring the modifed items state.

More...
 
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...
 
virtual EDA_ITEMparentObject (EDA_ITEM *aItem) const =0
 
CHANGE_TYPE convert (UNDO_REDO_T aType) const
 

Protected Attributes

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

Detailed Description

Class COMMIT.

Represents a set of changes (additions, deletions or modifications) of a data model (e.g. the BOARD) class.

The class can be used to propagate changes to subscribed objects (e.g. views, ratsnest), and automatically create undo/redo points.

Definition at line 71 of file commit.h.

Constructor & Destructor Documentation

◆ COMMIT()

COMMIT::COMMIT ( )

Definition at line 31 of file commit.cpp.

32 {
33 }

◆ ~COMMIT()

COMMIT::~COMMIT ( )
virtual

Definition at line 36 of file commit.cpp.

37 {
38  for( COMMIT_LINE& ent : m_changes )
39  {
40  if( ent.m_copy )
41  delete ent.m_copy;
42  }
43 }
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182

References m_changes.

Member Function Documentation

◆ Add()

◆ Added()

COMMIT& COMMIT::Added ( EDA_ITEM aItem)
inline

Notifies observers that aItem has been added

Definition at line 84 of file commit.h.

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

References CHT_ADD, CHT_DONE, and Stage().

◆ clear()

void COMMIT::clear ( )
inlineprotected

Definition at line 161 of file commit.h.

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

References m_changedItems, and m_changes.

◆ convert()

CHANGE_TYPE COMMIT::convert ( UNDO_REDO_T  aType) const
protected

Definition at line 202 of file commit.cpp.

203 {
204  switch( aType )
205  {
206  case UR_NEW:
207  return CHT_ADD;
208 
209  case UR_DELETED:
210  return CHT_REMOVE;
211 
212  default:
213  assert( false );
214  // fall through
215 
216  case UR_CHANGED:
217  case UR_MOVED:
218  case UR_MIRRORED_X:
219  case UR_MIRRORED_Y:
220  case UR_ROTATED:
222  case UR_FLIPPED:
223  return CHT_MODIFY;
224  }
225 }
Definition: commit.h:38

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 Stage().

◆ createModified()

COMMIT & COMMIT::createModified ( EDA_ITEM aItem,
EDA_ITEM aCopy,
int  aExtraFlags = 0 
)
protected

Definition at line 150 of file commit.cpp.

151 {
152  EDA_ITEM* parent = parentObject( aItem );
153  auto entryIt = m_changedItems.find( parent );
154 
155  if( entryIt != m_changedItems.end() )
156  {
157  delete aCopy;
158  return *this; // item has been already modified once
159  }
160 
161  makeEntry( parent, CHT_MODIFY | aExtraFlags, aCopy );
162 
163  return *this;
164 }
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:167

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

Referenced by Modified(), and Stage().

◆ Empty()

bool COMMIT::Empty ( ) const
inline

Definition at line 139 of file commit.h.

140  {
141  return m_changes.empty();
142  }
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182

References m_changes.

Referenced by DRAWING_TOOL::drawSegment().

◆ findEntry()

COMMIT::COMMIT_LINE * COMMIT::findEntry ( EDA_ITEM aItem)
protected

Searches for an entry describing change for a particular item.

Returns
null if there is no related entry.

Definition at line 190 of file commit.cpp.

191 {
192  for( COMMIT_LINE& change : m_changes )
193  {
194  if( change.m_item == aItem )
195  return &change;
196  }
197 
198  return nullptr;
199 }
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182

References m_changes.

Referenced by GetStatus().

◆ GetStatus()

int COMMIT::GetStatus ( EDA_ITEM aItem)

Returns status of an item.

Definition at line 132 of file commit.cpp.

133 {
134  COMMIT_LINE* entry = findEntry( parentObject( aItem ) );
135 
136  return entry ? entry->m_type : 0;
137 }
COMMIT_LINE * findEntry(EDA_ITEM *aItem)
Searches for an entry describing change for a particular item.
Definition: commit.cpp:190
virtual EDA_ITEM * parentObject(EDA_ITEM *aItem) const =0

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

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

◆ makeEntry()

void COMMIT::makeEntry ( EDA_ITEM aItem,
CHANGE_TYPE  aType,
EDA_ITEM aCopy = NULL 
)
protectedvirtual

Definition at line 167 of file commit.cpp.

168 {
169  // Expect an item copy if it is going to be modified
170  assert( !!aCopy == ( ( aType & CHT_TYPE ) == CHT_MODIFY ) );
171 
172  if( m_changedItems.find( aItem ) != m_changedItems.end() )
173  {
174  eraseIf( m_changes, [aItem] ( const COMMIT_LINE& aEnt ) {
175  return aEnt.m_item == aItem;
176  } );
177  }
178 
179  COMMIT_LINE ent;
180 
181  ent.m_item = aItem;
182  ent.m_type = aType;
183  ent.m_copy = aCopy;
184 
185  m_changedItems.insert( aItem );
186  m_changes.push_back( ent );
187 }
void eraseIf(Container &c, F &&f)
Definition: commit.cpp:141
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:181
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:182

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

Referenced by createModified(), and Stage().

◆ Modified()

COMMIT& COMMIT::Modified ( EDA_ITEM aItem,
EDA_ITEM aCopy 
)
inline

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.

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

References createModified().

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

◆ Modify()

◆ parentObject()

virtual EDA_ITEM* COMMIT::parentObject ( EDA_ITEM aItem) const
protectedpure virtual

Implemented in BOARD_COMMIT.

Referenced by createModified(), GetStatus(), and Stage().

◆ Push()

virtual void COMMIT::Push ( const wxString &  aMessage = wxT("A commit"),
bool  aCreateUndoEntry = true,
bool  aSetDirtyBit = true 
)
pure virtual

Executes the changes.

Implemented in BOARD_COMMIT.

Referenced by ZONE_FILLER::Fill(), and DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow().

◆ Remove()

COMMIT& COMMIT::Remove ( EDA_ITEM aItem)
inline

Removes a new item from the model

Definition at line 90 of file commit.h.

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

References CHT_REMOVE, and 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(), POINT_EDITOR::removeCorner(), and ZONE_FILLER_TOOL::SegzoneDeleteFill().

◆ Removed()

COMMIT& COMMIT::Removed ( EDA_ITEM aItem)
inline

Notifies observers that aItem has been removed

Definition at line 96 of file commit.h.

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

References CHT_DONE, CHT_REMOVE, and Stage().

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

◆ Revert()

virtual void COMMIT::Revert ( )
pure virtual

Revertes the commit by restoring the modifed items state.

Implemented in BOARD_COMMIT.

Referenced by ZONE_FILLER::Fill().

◆ Stage() [1/3]

COMMIT & COMMIT::Stage ( EDA_ITEM aItem,
CHANGE_TYPE  aChangeType 
)

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

Definition at line 46 of file commit.cpp.

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  EDA_ITEM* clone = nullptr;
68 
69  assert( parent );
70 
71  if( parent )
72  clone = parent->Clone();
73 
74  assert( clone );
75 
76  if( clone )
77  return createModified( parent, clone, flag );
78 
79  break;
80  }
81 
82  default:
83  assert( false );
84  }
85 
86  return *this;
87 }
Definition: commit.h:38
Flag to indicate the change is already applied, just notify observers (not compatible with CHT_MODIFY...
Definition: commit.h:45
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:181
COMMIT & createModified(EDA_ITEM *aItem, EDA_ITEM *aCopy, int aExtraFlags=0)
Definition: commit.cpp:150
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:167

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

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

◆ Stage() [2/3]

COMMIT & COMMIT::Stage ( std::vector< EDA_ITEM * > &  container,
CHANGE_TYPE  aChangeType 
)

Definition at line 90 of file commit.cpp.

91 {
92  for( EDA_ITEM* item : container )
93  {
94  Stage( item, aChangeType );
95  }
96 
97  return *this;
98 }
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

References Stage().

◆ Stage() [3/3]

COMMIT & COMMIT::Stage ( const PICKED_ITEMS_LIST aItems,
UNDO_REDO_T  aModFlag = UR_UNSPECIFIED 
)

Definition at line 101 of file commit.cpp.

102 {
103  for( unsigned int i = 0; i < aItems.GetCount(); i++ )
104  {
105  UNDO_REDO_T change_type = aItems.GetPickedItemStatus( i );
106  EDA_ITEM* item = aItems.GetPickedItem( i );
107  EDA_ITEM* copy = NULL;
108 
109  if( change_type == UR_UNSPECIFIED )
110  change_type = aItems.m_Status;
111 
112  if( change_type == UR_UNSPECIFIED )
113  change_type = aModFlag;
114 
115  if( ( copy = aItems.GetPickedItemLink( i ) ) )
116  {
117  assert( change_type == UR_CHANGED );
118 
119  // There was already a copy created, so use it
120  Modified( item, copy );
121  }
122  else
123  {
124  Stage( item, convert( change_type ) );
125  }
126  }
127 
128  return *this;
129 }
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
Function GetPickedItemLink.
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...
unsigned GetCount() const
Function GetCount.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.h:110
UNDO_REDO_T GetPickedItemStatus(unsigned int aIdx) const
Function GetPickedItemStatus.
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
CHANGE_TYPE convert(UNDO_REDO_T aType) const
Definition: commit.cpp:202

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

◆ StageItems()

template<class Range >
COMMIT& COMMIT::StageItems ( const Range &  aRange,
CHANGE_TYPE  aChangeType 
)
inline

Definition at line 116 of file commit.h.

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

References Stage().

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().

Member Data Documentation

◆ m_changedItems

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

Definition at line 181 of file commit.h.

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

◆ m_changes

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

Definition at line 182 of file commit.h.

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


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