KiCad PCB EDA Suite
COMMIT Class Referenceabstract

Represent a set of changes (additions, deletions or modifications) of a data model (e.g. More...

#include <commit.h>

Inheritance diagram for COMMIT:
BOARD_COMMIT

Classes

struct  COMMIT_LINE
 

Public Member Functions

 COMMIT ()
 
virtual ~COMMIT ()
 Add a new item to the model. More...
 
COMMITAdd (EDA_ITEM *aItem)
 Notify observers that aItem has been added. More...
 
COMMITAdded (EDA_ITEM *aItem)
 Remove a new item from the model. More...
 
COMMITRemove (EDA_ITEM *aItem)
 Notify observers that aItem has been removed. More...
 
COMMITRemoved (EDA_ITEM *aItem)
 Modify a given item in the model. More...
 
COMMITModify (EDA_ITEM *aItem)
 Create an undo entry for an item that has been already modified. More...
 
COMMITModified (EDA_ITEM *aItem, EDA_ITEM *aCopy)
 
template<class Range >
COMMITStageItems (const Range &aRange, CHANGE_TYPE aChangeType)
 Add a change of the item aItem of type aChangeType to the change list. More...
 
virtual COMMITStage (EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
 
virtual COMMITStage (std::vector< EDA_ITEM * > &container, CHANGE_TYPE aChangeType)
 
virtual COMMITStage (const PICKED_ITEMS_LIST &aItems, UNDO_REDO aModFlag=UNDO_REDO::UNSPECIFIED)
 Execute the changes. More...
 
virtual void Push (const wxString &aMessage=wxT("A commit"), int aFlags=0)=0
 Revert the commit by restoring the modified items state. More...
 
virtual void Revert ()=0
 
bool Empty () const
 Returns status of an item. More...
 
int GetStatus (EDA_ITEM *aItem)
 

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=nullptr)
 
COMMIT_LINEfindEntry (EDA_ITEM *aItem)
 Search for an entry describing change for a particular item. More...
 
virtual EDA_ITEMparentObject (EDA_ITEM *aItem) const =0
 
virtual EDA_ITEMmakeImage (EDA_ITEM *aItem) const =0
 
CHANGE_TYPE convert (UNDO_REDO aType) const
 

Protected Attributes

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

Detailed Description

Represent 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 33 of file commit.cpp.

34{
35}

◆ ~COMMIT()

COMMIT::~COMMIT ( )
virtual

Add a new item to the model.

Definition at line 38 of file commit.cpp.

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

References m_changes.

Member Function Documentation

◆ Add()

◆ Added()

COMMIT & COMMIT::Added ( EDA_ITEM aItem)
inline

Remove a new item from the model.

Definition at line 84 of file commit.h.

References CHT_ADD, CHT_DONE, and Stage().

Referenced by TEARDROP_MANAGER::addTeardropsOnTracks(), PCB_EDIT_FRAME::RunActionPlugin(), and TEARDROP_MANAGER::SetTeardrops().

◆ clear()

void COMMIT::clear ( )
inlineprotected

Definition at line 156 of file commit.h.

157 {
158 m_changedItems.clear();
159 m_changes.clear();
160 }
std::set< EDA_ITEM * > m_changedItems
Definition: commit.h:179

References m_changedItems, and m_changes.

Referenced by BOARD_COMMIT::Push(), and BOARD_COMMIT::Revert().

◆ convert()

CHANGE_TYPE COMMIT::convert ( UNDO_REDO  aType) const
protected

Definition at line 184 of file commit.cpp.

185{
186 switch( aType )
187 {
189 return CHT_ADD;
190
192 return CHT_REMOVE;
193
194 default:
195 assert( false );
196 // Can't fall through if the assert fires, so quiet our warning
197#ifdef NDEBUG
199#endif
200
202 return CHT_MODIFY;
203 }
204}
@ CHT_MODIFY
Definition: commit.h:42
@ CHT_REMOVE
Definition: commit.h:41
@ CHT_ADD
Definition: commit.h:40
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83

References CHANGED, CHT_ADD, CHT_MODIFY, CHT_REMOVE, DELETED, KI_FALLTHROUGH, and NEWITEM.

Referenced by Stage().

◆ createModified()

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

Definition at line 131 of file commit.cpp.

132{
133 EDA_ITEM* parent = parentObject( aItem );
134 auto entryIt = m_changedItems.find( parent );
135
136 if( entryIt != m_changedItems.end() )
137 {
138 delete aCopy;
139 return *this; // item has been already modified once
140 }
141
142 makeEntry( parent, CHT_MODIFY | aExtraFlags, aCopy );
143
144 return *this;
145}
virtual void makeEntry(EDA_ITEM *aItem, CHANGE_TYPE aType, EDA_ITEM *aCopy=nullptr)
Definition: commit.cpp:148
virtual EDA_ITEM * parentObject(EDA_ITEM *aItem) const =0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85

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

Referenced by Modified(), and Stage().

◆ Empty()

bool COMMIT::Empty ( ) const
inline

Returns status of an item.

Definition at line 139 of file commit.h.

References m_changes.

Referenced by DIALOG_CLEANUP_GRAPHICS::doCleanup(), DIALOG_CLEANUP_TRACKS_AND_VIAS::doCleanup(), and BOARD_COMMIT::Push().

◆ findEntry()

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

Search for an entry describing change for a particular item.

Returns
null if there is no related entry.

Definition at line 172 of file commit.cpp.

173{
174 for( COMMIT_LINE& change : m_changes )
175 {
176 if( change.m_item == aItem )
177 return &change;
178 }
179
180 return nullptr;
181}

References m_changes.

Referenced by GetStatus().

◆ GetStatus()

int COMMIT::GetStatus ( EDA_ITEM aItem)

Definition at line 123 of file commit.cpp.

124{
125 COMMIT_LINE* entry = findEntry( parentObject( aItem ) );
126
127 return entry ? entry->m_type : 0;
128}
COMMIT_LINE * findEntry(EDA_ITEM *aItem)
Search for an entry describing change for a particular item.
Definition: commit.cpp:172

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

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

◆ makeEntry()

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

Definition at line 148 of file commit.cpp.

149{
150 // Expect an item copy if it is going to be modified
151 wxASSERT( !!aCopy == ( ( aType & CHT_TYPE ) == CHT_MODIFY ) );
152
153 if( m_changedItems.find( aItem ) != m_changedItems.end() )
154 {
155 alg::delete_if( m_changes, [aItem]( const COMMIT_LINE& aEnt )
156 {
157 return aEnt.m_item == aItem;
158 } );
159 }
160
161 COMMIT_LINE ent;
162
163 ent.m_item = aItem;
164 ent.m_type = aType;
165 ent.m_copy = aCopy;
166
167 m_changedItems.insert( aItem );
168 m_changes.push_back( ent );
169}
@ CHT_TYPE
Flag to indicate the change is already applied, just notify observers (not compatible with CHT_MODIFY...
Definition: commit.h:43
void delete_if(_Container &__c, _Function &&__f)
Deletes all values from __c for which __f returns true.
Definition: kicad_algo.h:173

References CHT_MODIFY, CHT_TYPE, alg::delete_if(), 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().

◆ makeImage()

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

Implemented in BOARD_COMMIT.

Referenced by Stage().

◆ Modified()

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

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:131

References createModified().

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

◆ Modify()

COMMIT & COMMIT::Modify ( EDA_ITEM aItem)
inline

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

Requires a copy done before the modification.

Definition at line 103 of file commit.h.

References CHT_MODIFY, and Stage().

Referenced by PCB_POINT_EDITOR::addCorner(), AR_AUTOPLACER::AutoplaceFootprints(), doPushPadProperties(), DRAWING_TOOL::DrawVia(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), ZONE_FILLER::Fill(), ARRAY_CREATOR::Invoke(), TRACKS_CLEANER::mergeCollinearSegments(), mergeZones(), BOARD_EDITOR_CONTROL::modifyLockSelected(), FOOTPRINT_EDIT_FRAME::OnEditItemRequest(), PAD_TOOL::pastePadProperties(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), CN_CONNECTIVITY_ALGO::propagateConnections(), DIALOG_BOARD_REANNOTATE::ReannotateBoard(), PAD_TOOL::RecombinePad(), PCB_POINT_EDITOR::removeCorner(), GROUP_TOOL::RemoveFromGroup(), DRAWING_TOOL::SetAnchor(), BOARD_EDITOR_CONTROL::TrackWidthDec(), BOARD_EDITOR_CONTROL::TrackWidthInc(), DIALOG_DIMENSION_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_GROUP_PROPERTIES::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_UNUSED_PAD_LAYERS::TransferDataFromWindow(), BOARD_NETLIST_UPDATER::updateCopperZoneNets(), PCB_PROPERTIES_PANEL::valueChanged(), BOARD_EDITOR_CONTROL::ViaSizeDec(), BOARD_EDITOR_CONTROL::ViaSizeInc(), ZONE_FILLER_TOOL::ZoneUnfill(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

◆ 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"),
int  aFlags = 0 
)
pure virtual

Revert the commit by restoring the modified items state.

Implemented in BOARD_COMMIT.

Referenced by DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), and DIALOG_UNUSED_PAD_LAYERS::TransferDataFromWindow().

◆ Remove()

◆ Removed()

COMMIT & COMMIT::Removed ( EDA_ITEM aItem)
inline

◆ Revert()

virtual void COMMIT::Revert ( )
pure virtual

Implemented in BOARD_COMMIT.

◆ Stage() [1/3]

COMMIT & COMMIT::Stage ( const PICKED_ITEMS_LIST aItems,
UNDO_REDO  aModFlag = UNDO_REDO::UNSPECIFIED 
)
virtual

Execute the changes.

Reimplemented in BOARD_COMMIT.

Definition at line 96 of file commit.cpp.

97{
98 for( unsigned int i = 0; i < aItems.GetCount(); i++ )
99 {
100 UNDO_REDO change_type = aItems.GetPickedItemStatus( i );
101 EDA_ITEM* item = aItems.GetPickedItem( i );
102
103 if( change_type == UNDO_REDO::UNSPECIFIED )
104 change_type = aModFlag;
105
106 if( EDA_ITEM* copy = aItems.GetPickedItemLink( i ) )
107 {
108 assert( change_type == UNDO_REDO::CHANGED );
109
110 // There was already a copy created, so use it
111 Modified( item, copy );
112 }
113 else
114 {
115 Stage( item, convert( change_type ) );
116 }
117 }
118
119 return *this;
120}
virtual COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType)
Definition: commit.cpp:48
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Definition: commit.h:110
CHANGE_TYPE convert(UNDO_REDO aType) const
Definition: commit.cpp:184
UNDO_REDO GetPickedItemStatus(unsigned int aIdx) const
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
unsigned GetCount() const
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...

References CHANGED, convert(), copy, PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetPickedItem(), PICKED_ITEMS_LIST::GetPickedItemLink(), PICKED_ITEMS_LIST::GetPickedItemStatus(), Modified(), Stage(), and UNSPECIFIED.

◆ Stage() [2/3]

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

Reimplemented in BOARD_COMMIT.

Definition at line 48 of file commit.cpp.

49{
50 // CHT_MODIFY and CHT_DONE are not compatible
51 wxASSERT( ( aChangeType & ( CHT_MODIFY | CHT_DONE ) ) != ( CHT_MODIFY | CHT_DONE ) );
52
53 int flag = aChangeType & CHT_FLAGS;
54
55 switch( aChangeType & CHT_TYPE )
56 {
57 case CHT_ADD:
58 wxASSERT( m_changedItems.find( aItem ) == m_changedItems.end() );
59 makeEntry( aItem, CHT_ADD | flag );
60 return *this;
61
62 case CHT_REMOVE:
63 makeEntry( aItem, CHT_REMOVE | flag );
64 return *this;
65
66 case CHT_MODIFY:
67 {
68 EDA_ITEM* parent = parentObject( aItem );
69 EDA_ITEM* clone = makeImage( parent );
70
71 wxASSERT( clone );
72
73 if( clone )
74 return createModified( parent, clone, flag );
75
76 break;
77 }
78
79 default:
80 wxFAIL;
81 }
82
83 return *this;
84}
virtual EDA_ITEM * makeImage(EDA_ITEM *aItem) const =0
@ CHT_DONE
Definition: commit.h:47
@ CHT_FLAGS
Definition: commit.h:48

References CHT_ADD, CHT_DONE, CHT_FLAGS, CHT_MODIFY, CHT_REMOVE, CHT_TYPE, createModified(), flag, m_changedItems, makeEntry(), makeImage(), and parentObject().

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

◆ Stage() [3/3]

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

Reimplemented in BOARD_COMMIT.

Definition at line 87 of file commit.cpp.

88{
89 for( EDA_ITEM* item : container )
90 Stage( item, aChangeType );
91
92 return *this;
93}

References Stage().

◆ StageItems()

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

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

Definition at line 117 of file commit.h.

References Stage().

Referenced by PCB_POINT_EDITOR::OnSelectionChange().

Member Data Documentation

◆ m_changedItems

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

Definition at line 179 of file commit.h.

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

◆ m_changes

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

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