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

Definition at line 29 of file commit.cpp.

30 {
31 }
COMMIT::~COMMIT ( )
virtual

Definition at line 34 of file commit.cpp.

References m_changes.

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

Member Function Documentation

COMMIT& COMMIT::Added ( EDA_ITEM aItem)
inline

Notifies observers that aItem has been added

Definition at line 84 of file commit.h.

References CHT_ADD, CHT_DONE, and 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 ( )
inlineprotected

Definition at line 160 of file commit.h.

References m_changedItems, and 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
protected

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 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 
)
protected

Definition at line 136 of file commit.cpp.

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

Referenced by Modified(), and 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: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:150
bool COMMIT::Empty ( ) const
inline

Definition at line 138 of file commit.h.

References m_changes.

Referenced by PCBNEW_CONTROL::AppendBoard().

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)
protected

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 m_changes.

Referenced by 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)

Returns status of an item.

Definition at line 118 of file commit.cpp.

References findEntry(), COMMIT::COMMIT_LINE::m_type, and 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 
)
protectedvirtual

Definition at line 150 of file commit.cpp.

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

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

References createModified().

Referenced by 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
virtual EDA_ITEM* COMMIT::parentObject ( EDA_ITEM aItem) const
protectedpure virtual

Implemented in BOARD_COMMIT.

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

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

Executes the changes.

Implemented in BOARD_COMMIT.

COMMIT& COMMIT::Remove ( EDA_ITEM aItem)
inline

Removes a new item from the model

Definition at line 90 of file commit.h.

References CHT_REMOVE, and 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)
inline

Notifies observers that aItem has been removed

Definition at line 96 of file commit.h.

References CHT_DONE, CHT_REMOVE, and 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
virtual void COMMIT::Revert ( )
pure virtual

Revertes the commit by restoring the modifed items state.

Implemented in BOARD_COMMIT.

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

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

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: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:150
COMMIT & COMMIT::Stage ( std::vector< EDA_ITEM * > &  container,
CHANGE_TYPE  aChangeType 
)

Definition at line 76 of file commit.cpp.

References 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:151
COMMIT & COMMIT::Stage ( const PICKED_ITEMS_LIST aItems,
UNDO_REDO_T  aModFlag = UR_UNSPECIFIED 
)

Definition at line 87 of file commit.cpp.

References convert(), PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetPickedItem(), PICKED_ITEMS_LIST::GetPickedItemLink(), PICKED_ITEMS_LIST::GetPickedItemStatus(), PICKED_ITEMS_LIST::m_Status, Modified(), 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:151
template<class Range >
COMMIT& COMMIT::StageItems ( const Range &  aRange,
CHANGE_TYPE  aChangeType 
)
inline

Definition at line 116 of file commit.h.

References 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
protected

Definition at line 180 of file commit.h.

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

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

Definition at line 181 of file commit.h.

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


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