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
 

Protected Member Functions

void clear ()
 
virtual void makeEntry (EDA_ITEM *aItem, CHANGE_TYPE aType, EDA_ITEM *aCopy=NULL)
 
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:167

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

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

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

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 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
inline

Definition at line 135 of file commit.h.

References m_changes.

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

Definition at line 138 of file commit.cpp.

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

Referenced by Modified(), and 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 
)

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, m_changedItems, makeEntry(), and parentObject().

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

Implemented in BOARD_COMMIT.

Referenced by Modified(), 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::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
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(), 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  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 
)

Definition at line 96 of file commit.cpp.

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

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

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

Definition at line 113 of file commit.h.

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

Definition at line 166 of file commit.h.

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

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

Definition at line 167 of file commit.h.

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


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