Eclipse SUMO - Simulation of Urban MObility
GNEChange.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // The reification of a NETEDIT editing operation (see command pattern)
19 // inherits from FXCommand and is used to for undo/redo
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include <netbuild/NBEdge.h>
25 #include <netbuild/NBNode.h>
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
45 class GNEAdditional;
46 class GNEDataSet;
47 class GNEDemandElement;
48 class GNEGenericData;
49 class GNEDataInterval;
50 class GNEEdge;
51 class GNELane;
52 class GNEShape;
53 class GNETAZElement;
54 class GNENet;
55 class GNEViewNet;
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
64 class GNEChange : public FXObject {
65  FXDECLARE_ABSTRACT(GNEChange)
66 
67 public:
69  friend class GNEChangeGroup;
70  friend class GNEUndoList;
71 
77  GNEChange(Supermode supermode, bool forward, const bool selectedElement);
78 
85  GNEChange(Supermode supermode, GNEHierarchicalElement* element, bool forward, const bool selectedElement);
86 
88  ~GNEChange();
89 
91  virtual void undo() = 0;
92 
94  virtual void redo() = 0;
95 
97  virtual std::string undoName() const = 0;
98 
100  virtual std::string redoName() const = 0;
101 
103  virtual int size() const;
104 
106  Supermode getSupermode() const;
107 
114  bool canMerge() const;
115 
121  bool mergeWith(GNEChange* command);
122 
123 protected:
125  GNEChange();
126 
129 
131  template<typename T>
133  // add element in parents
134  for (const auto& junction : myOriginalHierarchicalContainer.getParents<std::vector<GNEJunction*> >()) {
135  junction->addChildElement(element);
136  }
137  for (const auto& edge : myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >()) {
138  edge->addChildElement(element);
139  }
140  for (const auto& lane : myOriginalHierarchicalContainer.getParents<std::vector<GNELane*> >()) {
141  lane->addChildElement(element);
142  }
143  for (const auto& additional : myOriginalHierarchicalContainer.getParents<std::vector<GNEAdditional*> >()) {
144  additional->addChildElement(element);
145  }
146  for (const auto& shape : myOriginalHierarchicalContainer.getParents<std::vector<GNEShape*> >()) {
147  shape->addChildElement(element);
148  }
149  for (const auto& TAZElement : myOriginalHierarchicalContainer.getParents<std::vector<GNETAZElement*> >()) {
150  TAZElement->addChildElement(element);
151  }
152  for (const auto& demandElement : myOriginalHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >()) {
153  demandElement->addChildElement(element);
154  }
155  for (const auto& genericData : myOriginalHierarchicalContainer.getParents<std::vector<GNEGenericData*> >()) {
156  genericData->addChildElement(element);
157  }
158  // add element in children
159  for (const auto& junction : myOriginalHierarchicalContainer.getChildren<std::vector<GNEJunction*> >()) {
160  junction->addParentElement(element);
161  }
162  for (const auto& edge : myOriginalHierarchicalContainer.getChildren<std::vector<GNEEdge*> >()) {
163  edge->addParentElement(element);
164  }
165  for (const auto& lane : myOriginalHierarchicalContainer.getChildren<std::vector<GNELane*> >()) {
166  lane->addParentElement(element);
167  }
168  for (const auto& additional : myOriginalHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >()) {
169  additional->addParentElement(element);
170  }
171  for (const auto& shape : myOriginalHierarchicalContainer.getChildren<std::vector<GNEShape*> >()) {
172  shape->addParentElement(element);
173  }
174  for (const auto& TAZElement : myOriginalHierarchicalContainer.getChildren<std::vector<GNETAZElement*> >()) {
175  TAZElement->addParentElement(element);
176  }
177  for (const auto& demandElement : myOriginalHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >()) {
178  demandElement->addParentElement(element);
179  }
180  for (const auto& genericData : myOriginalHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >()) {
181  genericData->addParentElement(element);
182  }
183  }
184 
186  template<typename T>
188  // Remove element from parents
189  for (const auto& junction : myOriginalHierarchicalContainer.getParents<std::vector<GNEJunction*> >()) {
190  junction->removeChildElement(element);
191  }
192  for (const auto& edge : myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >()) {
193  edge->removeChildElement(element);
194  }
195  for (const auto& lane : myOriginalHierarchicalContainer.getParents<std::vector<GNELane*> >()) {
196  lane->removeChildElement(element);
197  }
198  for (const auto& additional : myOriginalHierarchicalContainer.getParents<std::vector<GNEAdditional*> >()) {
199  additional->removeChildElement(element);
200  }
201  for (const auto& shape : myOriginalHierarchicalContainer.getParents<std::vector<GNEShape*> >()) {
202  shape->removeChildElement(element);
203  }
204  for (const auto& TAZElement : myOriginalHierarchicalContainer.getParents<std::vector<GNETAZElement*> >()) {
205  TAZElement->removeChildElement(element);
206  }
207  for (const auto& demandElement : myOriginalHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >()) {
208  demandElement->removeChildElement(element);
209  }
210  for (const auto& genericData : myOriginalHierarchicalContainer.getParents<std::vector<GNEGenericData*> >()) {
211  genericData->removeChildElement(element);
212  }
213  // Remove element from children
214  for (const auto& junction : myOriginalHierarchicalContainer.getChildren<std::vector<GNEJunction*> >()) {
215  junction->removeParentElement(element);
216  }
217  for (const auto& edge : myOriginalHierarchicalContainer.getChildren<std::vector<GNEEdge*> >()) {
218  edge->removeParentElement(element);
219  }
220  for (const auto& lane : myOriginalHierarchicalContainer.getChildren<std::vector<GNELane*> >()) {
221  lane->removeParentElement(element);
222  }
223  for (const auto& additional : myOriginalHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >()) {
224  additional->removeParentElement(element);
225  }
226  for (const auto& shape : myOriginalHierarchicalContainer.getChildren<std::vector<GNEShape*> >()) {
227  shape->removeParentElement(element);
228  }
229  for (const auto& TAZElement : myOriginalHierarchicalContainer.getChildren<std::vector<GNETAZElement*> >()) {
230  TAZElement->removeParentElement(element);
231  }
232  for (const auto& demandElement : myOriginalHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >()) {
233  demandElement->removeParentElement(element);
234  }
235  for (const auto& genericData : myOriginalHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >()) {
236  genericData->removeParentElement(element);
237  }
238  }
239 
242 
244  bool myForward;
245 
247  const bool mySelectedElement;
248 
251 
253  std::map<GNEHierarchicalElement*, GNEHierarchicalContainer> myHierarchicalContainers;
254 
255 private:
256  // @brief next GNEChange (can be access by GNEChangeGroup and GNEUndoList)
258 
260  GNEChange(const GNEChange&) = delete;
261 
263  GNEChange& operator=(const GNEChange&) = delete;
264 };
Supermode
@brie enum for supermodes
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:64
virtual void redo()=0
redo action/operation
std::map< GNEHierarchicalElement *, GNEHierarchicalContainer > myHierarchicalContainers
map with hierarchical container of all parent and children elements
Definition: GNEChange.h:253
virtual int size() const
Return the size of the command group.
Definition: GNEChange.cpp:61
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:244
virtual void undo()=0
undo action/operation
Supermode getSupermode() const
get supermode
Definition: GNEChange.cpp:68
GNEChange(const GNEChange &)=delete
Invalidated copy constructor.
GNEChange()
FOX need this.
Definition: GNEChange.cpp:85
bool mergeWith(GNEChange *command)
Called by the undo system to try and merge the new incoming command with this command; should return ...
Definition: GNEChange.cpp:80
const bool mySelectedElement
flag for check if element is selected
Definition: GNEChange.h:247
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition: GNEChange.h:132
~GNEChange()
Destructor.
Definition: GNEChange.cpp:57
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition: GNEChange.h:187
const Supermode mySupermode
supermode related with this change
Definition: GNEChange.h:241
virtual std::string redoName() const =0
return rendoName
GNEChange * next
Definition: GNEChange.h:257
virtual std::string undoName() const =0
return undoName
void restoreHierarchicalContainers()
restore container (only use in undo() function)
Definition: GNEChange.cpp:94
GNEChange & operator=(const GNEChange &)=delete
Invalidated assignment operator.
const GNEHierarchicalContainer myOriginalHierarchicalContainer
Hierarchical container with parent and children.
Definition: GNEChange.h:250
bool canMerge() const
Return TRUE if this command can be merged with previous undo commands. This is useful to combine e....
Definition: GNEChange.cpp:74
An Element which don't belongs to GNENet but has influency in the simulation.
An Element which don't belongs to GNENet but has influency in the simulation.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
An Element which don't belongs to GNENet but has influency in the simulation.
Hierarchical container (used for keep myParent and myChildren.
const T & getParents() const
get parents
const T & getChildren() const
get children
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNETAZElement.h:45