Eclipse SUMO - Simulation of Urban MObility
GNEChange_Shape.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // A network change in which a single poly is created or deleted
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
28 
29 #include "GNEChange_Shape.h"
30 
31 // ===========================================================================
32 // FOX-declarations
33 // ===========================================================================
34 FXIMPLEMENT_ABSTRACT(GNEChange_Shape, GNEChange, nullptr, 0)
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
40 GNEChange_Shape::GNEChange_Shape(GNEShape* shape, bool forward) :
41  GNEChange(shape->getNet(), forward),
42  myShape(shape),
43  myParentEdges(shape->getParentEdges()),
44  myParentLanes(shape->getParentLanes()),
45  myParentShapes(shape->getParentShapes()),
46  myParentAdditionals(shape->getParentAdditionals()),
47  myParentDemandElements(shape->getParentDemandElements()),
48  myChildEdges(shape->getChildEdges()),
49  myChildLanes(shape->getChildLanes()),
50  myChildShapes(shape->getChildShapes()),
51  myChildAdditionals(shape->getChildAdditionals()),
52  myChildDemandElements(shape->getChildDemandElements()) {
53  myShape->incRef("GNEChange_Shape");
54 }
55 
56 
58  assert(myShape);
59  myShape->decRef("GNEChange_Shape");
60  if (myShape->unreferenced()) {
61  // make sure that shape are removed of ShapeContainer (net) AND grid
62  if (myNet->retrievePolygon(myShape->getID(), false) != nullptr) {
63  // show extra information for tests
64  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from net in ~GNEChange_Shape()");
65  // all polygons are placed in RTREE
66  myNet->removeGLObjectFromGrid(dynamic_cast<GUIGlObject*>(myShape));
67  // remove polygon from container
68  myNet->myPolygons.remove(myShape->getID(), false);
69  // Remove element from parent elements
70  for (const auto& i : myParentEdges) {
71  i->removeChildShape(myShape);
72  }
73  for (const auto& i : myParentLanes) {
74  i->removeChildShape(myShape);
75  }
76  for (const auto& i : myParentShapes) {
77  i->removeChildShape(myShape);
78  }
79  for (const auto& i : myParentAdditionals) {
80  i->removeChildShape(myShape);
81  }
82  for (const auto& i : myParentDemandElements) {
83  i->removeChildShape(myShape);
84  }
85  // Remove element from child elements
86  for (const auto& i : myChildEdges) {
87  i->removeParentShape(myShape);
88  }
89  for (const auto& i : myChildLanes) {
90  i->removeParentShape(myShape);
91  }
92  for (const auto& i : myChildShapes) {
93  i->removeParentShape(myShape);
94  }
95  for (const auto& i : myChildAdditionals) {
96  i->removeParentShape(myShape);
97  }
98  for (const auto& i : myChildDemandElements) {
99  i->removeParentShape(myShape);
100  }
101  } else if (myNet->retrievePOI(myShape->getID(), false) != nullptr) {
102  // show extra information for tests
103  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from net in ~GNEChange_Shape()");
104  // only certain POIS are placed in RTREE
106  myNet->removeGLObjectFromGrid(dynamic_cast<GUIGlObject*>(myShape));
107  }
108  // remove POI from container
109  myNet->myPOIs.remove(myShape->getID(), false);
110  // Remove element from parent elements
111  for (const auto& i : myParentEdges) {
112  i->removeChildShape(myShape);
113  }
114  for (const auto& i : myParentLanes) {
115  i->removeChildShape(myShape);
116  }
117  for (const auto& i : myParentShapes) {
118  i->removeChildShape(myShape);
119  }
120  for (const auto& i : myParentAdditionals) {
121  i->removeChildShape(myShape);
122  }
123  for (const auto& i : myParentDemandElements) {
124  i->removeChildShape(myShape);
125  }
126  // Remove element from child elements
127  for (const auto& i : myChildEdges) {
128  i->removeParentShape(myShape);
129  }
130  for (const auto& i : myChildLanes) {
131  i->removeParentShape(myShape);
132  }
133  for (const auto& i : myChildShapes) {
134  i->removeParentShape(myShape);
135  }
136  for (const auto& i : myChildAdditionals) {
137  i->removeParentShape(myShape);
138  }
139  for (const auto& i : myChildDemandElements) {
140  i->removeParentShape(myShape);
141  }
142  }
143  // show extra information for tests
144  WRITE_DEBUG("delete " + myShape->getTagStr() + " '" + myShape->getID() + "' in ~GNEChange_Shape()");
145  delete myShape;
146  }
147 }
148 
149 
150 void
152  if (myForward) {
153  // show extra information for tests
154  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from viewNet");
155  // remove shape from net
156  myNet->removeShape(myShape, false);
157  // Remove element from parent elements
158  for (const auto& i : myParentEdges) {
159  i->removeChildShape(myShape);
160  }
161  for (const auto& i : myParentLanes) {
162  i->removeChildShape(myShape);
163  }
164  for (const auto& i : myParentShapes) {
165  i->removeChildShape(myShape);
166  }
167  for (const auto& i : myParentAdditionals) {
168  i->removeChildShape(myShape);
169  }
170  for (const auto& i : myParentDemandElements) {
171  i->removeChildShape(myShape);
172  }
173  // Remove element from child elements
174  for (const auto& i : myChildEdges) {
175  i->removeParentShape(myShape);
176  }
177  for (const auto& i : myChildLanes) {
178  i->removeParentShape(myShape);
179  }
180  for (const auto& i : myChildShapes) {
181  i->removeParentShape(myShape);
182  }
183  for (const auto& i : myChildAdditionals) {
184  i->removeParentShape(myShape);
185  }
186  for (const auto& i : myChildDemandElements) {
187  i->removeParentShape(myShape);
188  }
189  } else {
190  // show extra information for tests
191  WRITE_DEBUG("Adding " + myShape->getTagStr() + " '" + myShape->getID() + "' into viewNet");
192  // Add shape in net
193  myNet->insertShape(myShape, false);
194  // add element in parent elements
195  for (const auto& i : myParentEdges) {
196  i->addChildShape(myShape);
197  }
198  for (const auto& i : myParentLanes) {
199  i->addChildShape(myShape);
200  }
201  for (const auto& i : myParentShapes) {
202  i->addChildShape(myShape);
203  }
204  for (const auto& i : myParentAdditionals) {
205  i->addChildShape(myShape);
206  }
207  for (const auto& i : myParentDemandElements) {
208  i->addChildShape(myShape);
209  }
210  // add element in child elements
211  for (const auto& i : myChildEdges) {
212  i->addParentShape(myShape);
213  }
214  for (const auto& i : myChildLanes) {
215  i->addParentShape(myShape);
216  }
217  for (const auto& i : myChildShapes) {
218  i->addParentShape(myShape);
219  }
220  for (const auto& i : myChildAdditionals) {
221  i->addParentShape(myShape);
222  }
223  for (const auto& i : myChildDemandElements) {
224  i->addParentShape(myShape);
225  }
226  }
227 }
228 
229 
230 void
232  if (myForward) {
233  // show extra information for tests
234  WRITE_DEBUG("Adding " + myShape->getTagStr() + " '" + myShape->getID() + "' into viewNet");
235  // Add shape in net
236  myNet->insertShape(myShape, false);
237  // add element in parent elements
238  for (const auto& i : myParentEdges) {
239  i->addChildShape(myShape);
240  }
241  for (const auto& i : myParentLanes) {
242  i->addChildShape(myShape);
243  }
244  for (const auto& i : myParentShapes) {
245  i->addChildShape(myShape);
246  }
247  for (const auto& i : myParentAdditionals) {
248  i->addChildShape(myShape);
249  }
250  for (const auto& i : myParentDemandElements) {
251  i->addChildShape(myShape);
252  }
253  // add element in child elements
254  for (const auto& i : myChildEdges) {
255  i->addParentShape(myShape);
256  }
257  for (const auto& i : myChildLanes) {
258  i->addParentShape(myShape);
259  }
260  for (const auto& i : myChildShapes) {
261  i->addParentShape(myShape);
262  }
263  for (const auto& i : myChildAdditionals) {
264  i->addParentShape(myShape);
265  }
266  for (const auto& i : myChildDemandElements) {
267  i->addParentShape(myShape);
268  }
269  } else {
270  // show extra information for tests
271  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from viewNet");
272  // remove shape from net
273  myNet->removeShape(myShape, false);
274  // Remove element from parent elements
275  for (const auto& i : myParentEdges) {
276  i->removeChildShape(myShape);
277  }
278  for (const auto& i : myParentLanes) {
279  i->removeChildShape(myShape);
280  }
281  for (const auto& i : myParentShapes) {
282  i->removeChildShape(myShape);
283  }
284  for (const auto& i : myParentAdditionals) {
285  i->removeChildShape(myShape);
286  }
287  for (const auto& i : myParentDemandElements) {
288  i->removeChildShape(myShape);
289  }
290  // Remove element from child elements
291  for (const auto& i : myChildEdges) {
292  i->removeParentShape(myShape);
293  }
294  for (const auto& i : myChildLanes) {
295  i->removeParentShape(myShape);
296  }
297  for (const auto& i : myChildShapes) {
298  i->removeParentShape(myShape);
299  }
300  for (const auto& i : myChildAdditionals) {
301  i->removeParentShape(myShape);
302  }
303  for (const auto& i : myChildDemandElements) {
304  i->removeParentShape(myShape);
305  }
306  }
307 }
308 
309 
310 FXString
312  if (myForward) {
313  return ("Undo create " + myShape->getTagStr()).c_str();
314  } else {
315  return ("Undo delete " + myShape->getTagStr()).c_str();
316  }
317 }
318 
319 
320 FXString
322  if (myForward) {
323  return ("Redo create " + myShape->getTagStr()).c_str();
324  } else {
325  return ("Redo delete " + myShape->getTagStr()).c_str();
326  }
327 }
GNEChange_Shape::myChildAdditionals
const std::vector< GNEAdditional * > & myChildAdditionals
reference to vector of child additional
Definition: GNEChange_Shape.h:99
GNEChange_Shape::myChildLanes
const std::vector< GNELane * > & myChildLanes
reference to vector of child lanes
Definition: GNEChange_Shape.h:93
GNEChange_Shape::undo
void undo()
undo action
Definition: GNEChange_Shape.cpp:151
GNEChange_Shape::myParentShapes
const std::vector< GNEShape * > & myParentShapes
reference to vector of parent shapes
Definition: GNEChange_Shape.h:81
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:78
GNEAdditional.h
GNENet::removeShape
void removeShape(GNEShape *shape, bool updateViewAfterDeleting)
remove created shape (but NOT delete)
Definition: GNENet.cpp:3032
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNENet::retrievePOI
GNEPOI * retrievePOI(const std::string &id, bool failHard=true) const
get POI by id
Definition: GNENet.cpp:1115
GNEAttributeCarrier::TagProperties::isPlacedInRTree
bool isPlacedInRTree() const
return true if Tag correspond to an element that has has to be placed in RTREE
Definition: GNEAttributeCarrier.cpp:865
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:80
GNENet::removeGLObjectFromGrid
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1328
GNEChange_Shape::myChildDemandElements
const std::vector< GNEDemandElement * > & myChildDemandElements
reference to vector of child demand elements
Definition: GNEChange_Shape.h:102
GNEChange_Shape::myParentAdditionals
const std::vector< GNEAdditional * > & myParentAdditionals
reference to vector of parent additionals
Definition: GNEChange_Shape.h:84
GNEChange_Shape::myParentEdges
const std::vector< GNEEdge * > & myParentEdges
reference to vector of parent edges
Definition: GNEChange_Shape.h:75
GNENet::retrievePolygon
GNEPoly * retrievePolygon(const std::string &id, bool failHard=true) const
get Polygon by id
Definition: GNENet.cpp:1102
GNEChange_Shape::redo
void redo()
redo action
Definition: GNEChange_Shape.cpp:231
GNEChange_Shape::myChildShapes
const std::vector< GNEShape * > & myChildShapes
reference to vector of child shapes
Definition: GNEChange_Shape.h:96
GNEAttributeCarrier::getTagProperty
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
Definition: GNEAttributeCarrier.cpp:1273
GNEShape
Definition: GNEShape.h:34
GNEChange_Shape.h
NamedObjectCont::remove
bool remove(const std::string &id, const bool del=true)
Removes an item.
Definition: NamedObjectCont.h:78
GNEDemandElement.h
GNEChange_Shape::~GNEChange_Shape
~GNEChange_Shape()
Destructor.
Definition: GNEChange_Shape.cpp:57
GNEEdge.h
ShapeContainer::myPOIs
POIs myPOIs
stored POIs
Definition: ShapeContainer.h:215
GNEChange_Shape::myChildEdges
const std::vector< GNEEdge * > & myChildEdges
reference to vector of child edges
Definition: GNEChange_Shape.h:90
GNEChange::myNet
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:75
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:52
GNELane.h
GNEShape.h
GNEChange_Shape::myParentDemandElements
const std::vector< GNEDemandElement * > & myParentDemandElements
reference to vector of parent demand elements
Definition: GNEChange_Shape.h:87
GNEChange_Shape::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Shape.cpp:321
config.h
GNEChange_Shape::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Shape.cpp:311
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEChange_Shape::myShape
GNEShape * myShape
pointer to shape
Definition: GNEChange_Shape.h:72
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
ShapeContainer::myPolygons
Polygons myPolygons
stored Polygons
Definition: ShapeContainer.h:199
GNEChange_Shape
Definition: GNEChange_Shape.h:42
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:284
GNENet.h
GNENet::insertShape
void insertShape(GNEShape *shape, bool updateViewAfterDeleting)
insert shape
Definition: GNENet.cpp:3000
GNEChange_Shape::myParentLanes
const std::vector< GNELane * > & myParentLanes
reference to vector of parent lanes
Definition: GNEChange_Shape.h:78