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 /****************************************************************************/
15 // A network change in which a single poly is created or deleted
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
29 
30 #include "GNEChange_Shape.h"
31 
32 // ===========================================================================
33 // FOX-declarations
34 // ===========================================================================
35 FXIMPLEMENT_ABSTRACT(GNEChange_Shape, GNEChange, nullptr, 0)
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
41 GNEChange_Shape::GNEChange_Shape(GNEShape* shape, bool forward) :
42  GNEChange(shape->getNet(), forward),
43  myShape(shape),
44  myEdgeParents(shape->getEdgeParents()),
45  myLaneParents(shape->getLaneParents()),
46  myShapeParents(shape->getShapeParents()),
47  myAdditionalParents(shape->getAdditionalParents()),
48  myDemandElementParents(shape->getDemandElementParents()),
49  myEdgeChildren(shape->getEdgeChildren()),
50  myLaneChildren(shape->getLaneChildren()),
51  myShapeChildren(shape->getShapeChildren()),
52  myAdditionalChildren(shape->getAdditionalChildren()),
53  myDemandElementChildren(shape->getDemandElementChildren()) {
54  myShape->incRef("GNEChange_Shape");
55 }
56 
57 
59  assert(myShape);
60  myShape->decRef("GNEChange_Shape");
61  if (myShape->unreferenced()) {
62  // make sure that shape are removed of ShapeContainer (net) AND grid
63  if (myNet->retrievePolygon(myShape->getID(), false) != nullptr) {
64  // show extra information for tests
65  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from net in ~GNEChange_Shape()");
66  // all polygons are placed in RTREE
67  myNet->removeGLObjectFromGrid(dynamic_cast<GUIGlObject*>(myShape));
68  // remove polygon from container
69  myNet->myPolygons.remove(myShape->getID(), false);
70  // Remove element from parent elements
71  for (const auto& i : myEdgeParents) {
72  i->removeShapeChild(myShape);
73  }
74  for (const auto& i : myLaneParents) {
75  i->removeShapeChild(myShape);
76  }
77  for (const auto& i : myShapeParents) {
78  i->removeShapeChild(myShape);
79  }
80  for (const auto& i : myAdditionalParents) {
81  i->removeShapeChild(myShape);
82  }
83  for (const auto& i : myDemandElementParents) {
84  i->removeShapeChild(myShape);
85  }
86  // Remove element from child elements
87  for (const auto& i : myEdgeChildren) {
88  i->removeShapeParent(myShape);
89  }
90  for (const auto& i : myLaneChildren) {
91  i->removeShapeParent(myShape);
92  }
93  for (const auto& i : myShapeChildren) {
94  i->removeShapeParent(myShape);
95  }
96  for (const auto& i : myAdditionalChildren) {
97  i->removeShapeParent(myShape);
98  }
99  for (const auto& i : myDemandElementChildren) {
100  i->removeShapeParent(myShape);
101  }
102  } else if (myNet->retrievePOI(myShape->getID(), false) != nullptr) {
103  // show extra information for tests
104  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from net in ~GNEChange_Shape()");
105  // only certain POIS are placed in RTREE
107  myNet->removeGLObjectFromGrid(dynamic_cast<GUIGlObject*>(myShape));
108  }
109  // remove POI from container
110  myNet->myPOIs.remove(myShape->getID(), false);
111  // Remove element from parent elements
112  for (const auto& i : myEdgeParents) {
113  i->removeShapeChild(myShape);
114  }
115  for (const auto& i : myLaneParents) {
116  i->removeShapeChild(myShape);
117  }
118  for (const auto& i : myShapeParents) {
119  i->removeShapeChild(myShape);
120  }
121  for (const auto& i : myAdditionalParents) {
122  i->removeShapeChild(myShape);
123  }
124  for (const auto& i : myDemandElementParents) {
125  i->removeShapeChild(myShape);
126  }
127  // Remove element from child elements
128  for (const auto& i : myEdgeChildren) {
129  i->removeShapeParent(myShape);
130  }
131  for (const auto& i : myLaneChildren) {
132  i->removeShapeParent(myShape);
133  }
134  for (const auto& i : myShapeChildren) {
135  i->removeShapeParent(myShape);
136  }
137  for (const auto& i : myAdditionalChildren) {
138  i->removeShapeParent(myShape);
139  }
140  for (const auto& i : myDemandElementChildren) {
141  i->removeShapeParent(myShape);
142  }
143  }
144  // show extra information for tests
145  WRITE_DEBUG("delete " + myShape->getTagStr() + " '" + myShape->getID() + "' in ~GNEChange_Shape()");
146  delete myShape;
147  }
148 }
149 
150 
151 void
153  if (myForward) {
154  // show extra information for tests
155  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from viewNet");
156  // remove shape from net
157  myNet->removeShape(myShape, false);
158  // Remove element from parent elements
159  for (const auto& i : myEdgeParents) {
160  i->removeShapeChild(myShape);
161  }
162  for (const auto& i : myLaneParents) {
163  i->removeShapeChild(myShape);
164  }
165  for (const auto& i : myShapeParents) {
166  i->removeShapeChild(myShape);
167  }
168  for (const auto& i : myAdditionalParents) {
169  i->removeShapeChild(myShape);
170  }
171  for (const auto& i : myDemandElementParents) {
172  i->removeShapeChild(myShape);
173  }
174  // Remove element from child elements
175  for (const auto& i : myEdgeChildren) {
176  i->removeShapeParent(myShape);
177  }
178  for (const auto& i : myLaneChildren) {
179  i->removeShapeParent(myShape);
180  }
181  for (const auto& i : myShapeChildren) {
182  i->removeShapeParent(myShape);
183  }
184  for (const auto& i : myAdditionalChildren) {
185  i->removeShapeParent(myShape);
186  }
187  for (const auto& i : myDemandElementChildren) {
188  i->removeShapeParent(myShape);
189  }
190  } else {
191  // show extra information for tests
192  WRITE_DEBUG("Adding " + myShape->getTagStr() + " '" + myShape->getID() + "' into viewNet");
193  // Add shape in net
194  myNet->insertShape(myShape, false);
195  // add element in parent elements
196  for (const auto& i : myEdgeParents) {
197  i->addShapeChild(myShape);
198  }
199  for (const auto& i : myLaneParents) {
200  i->addShapeChild(myShape);
201  }
202  for (const auto& i : myShapeParents) {
203  i->addShapeChild(myShape);
204  }
205  for (const auto& i : myAdditionalParents) {
206  i->addShapeChild(myShape);
207  }
208  for (const auto& i : myDemandElementParents) {
209  i->addShapeChild(myShape);
210  }
211  // add element in child elements
212  for (const auto& i : myEdgeChildren) {
213  i->addShapeParent(myShape);
214  }
215  for (const auto& i : myLaneChildren) {
216  i->addShapeParent(myShape);
217  }
218  for (const auto& i : myShapeChildren) {
219  i->addShapeParent(myShape);
220  }
221  for (const auto& i : myAdditionalChildren) {
222  i->addShapeParent(myShape);
223  }
224  for (const auto& i : myDemandElementChildren) {
225  i->addShapeParent(myShape);
226  }
227  }
228 }
229 
230 
231 void
233  if (myForward) {
234  // show extra information for tests
235  WRITE_DEBUG("Adding " + myShape->getTagStr() + " '" + myShape->getID() + "' into viewNet");
236  // Add shape in net
237  myNet->insertShape(myShape, false);
238  // add element in parent elements
239  for (const auto& i : myEdgeParents) {
240  i->addShapeChild(myShape);
241  }
242  for (const auto& i : myLaneParents) {
243  i->addShapeChild(myShape);
244  }
245  for (const auto& i : myShapeParents) {
246  i->addShapeChild(myShape);
247  }
248  for (const auto& i : myAdditionalParents) {
249  i->addShapeChild(myShape);
250  }
251  for (const auto& i : myDemandElementParents) {
252  i->addShapeChild(myShape);
253  }
254  // add element in child elements
255  for (const auto& i : myEdgeChildren) {
256  i->addShapeParent(myShape);
257  }
258  for (const auto& i : myLaneChildren) {
259  i->addShapeParent(myShape);
260  }
261  for (const auto& i : myShapeChildren) {
262  i->addShapeParent(myShape);
263  }
264  for (const auto& i : myAdditionalChildren) {
265  i->addShapeParent(myShape);
266  }
267  for (const auto& i : myDemandElementChildren) {
268  i->addShapeParent(myShape);
269  }
270  } else {
271  // show extra information for tests
272  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from viewNet");
273  // remove shape from net
274  myNet->removeShape(myShape, false);
275  // Remove element from parent elements
276  for (const auto& i : myEdgeParents) {
277  i->removeShapeChild(myShape);
278  }
279  for (const auto& i : myLaneParents) {
280  i->removeShapeChild(myShape);
281  }
282  for (const auto& i : myShapeParents) {
283  i->removeShapeChild(myShape);
284  }
285  for (const auto& i : myAdditionalParents) {
286  i->removeShapeChild(myShape);
287  }
288  for (const auto& i : myDemandElementParents) {
289  i->removeShapeChild(myShape);
290  }
291  // Remove element from child elements
292  for (const auto& i : myEdgeChildren) {
293  i->removeShapeParent(myShape);
294  }
295  for (const auto& i : myLaneChildren) {
296  i->removeShapeParent(myShape);
297  }
298  for (const auto& i : myShapeChildren) {
299  i->removeShapeParent(myShape);
300  }
301  for (const auto& i : myAdditionalChildren) {
302  i->removeShapeParent(myShape);
303  }
304  for (const auto& i : myDemandElementChildren) {
305  i->removeShapeParent(myShape);
306  }
307  }
308 }
309 
310 
311 FXString
313  if (myForward) {
314  return ("Undo create " + myShape->getTagStr()).c_str();
315  } else {
316  return ("Undo delete " + myShape->getTagStr()).c_str();
317  }
318 }
319 
320 
321 FXString
323  if (myForward) {
324  return ("Redo create " + myShape->getTagStr()).c_str();
325  } else {
326  return ("Redo delete " + myShape->getTagStr()).c_str();
327  }
328 }
GNEChange_Shape::myLaneChildren
const std::vector< GNELane * > & myLaneChildren
reference to vector of lane children
Definition: GNEChange_Shape.h:94
GNEChange_Shape::undo
void undo()
undo action
Definition: GNEChange_Shape.cpp:152
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:79
GNEAdditional.h
GNENet::removeShape
void removeShape(GNEShape *shape, bool updateViewAfterDeleting)
remove created shape (but NOT delete)
Definition: GNENet.cpp:2975
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
GNENet::retrievePOI
GNEPOI * retrievePOI(const std::string &id, bool failHard=true) const
get POI by id
Definition: GNENet.cpp:1066
GNEChange_Shape::myEdgeParents
const std::vector< GNEEdge * > & myEdgeParents
reference to vector of edge parents
Definition: GNEChange_Shape.h:76
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:863
GNEChange_Shape::myShapeParents
const std::vector< GNEShape * > & myShapeParents
reference to vector of shape parents
Definition: GNEChange_Shape.h:82
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:81
GNENet::removeGLObjectFromGrid
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1279
GNEChange_Shape::myEdgeChildren
const std::vector< GNEEdge * > & myEdgeChildren
reference to vector of edge children
Definition: GNEChange_Shape.h:91
GNENet::retrievePolygon
GNEPoly * retrievePolygon(const std::string &id, bool failHard=true) const
get Polygon by id
Definition: GNENet.cpp:1053
GNEChange_Shape::redo
void redo()
redo action
Definition: GNEChange_Shape.cpp:232
GNEAttributeCarrier::getTagProperty
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
Definition: GNEAttributeCarrier.cpp:1171
GNEChange_Shape::myAdditionalParents
const std::vector< GNEAdditional * > & myAdditionalParents
reference to vector of additional parents
Definition: GNEChange_Shape.h:85
GNEShape
Definition: GNEShape.h:35
GNEChange_Shape.h
NamedObjectCont::remove
bool remove(const std::string &id, const bool del=true)
Removes an item.
Definition: NamedObjectCont.h:79
GNEDemandElement.h
GNEChange_Shape::~GNEChange_Shape
~GNEChange_Shape()
Destructor.
Definition: GNEChange_Shape.cpp:58
GNEChange_Shape::myDemandElementChildren
const std::vector< GNEDemandElement * > & myDemandElementChildren
reference to vector of demand element children
Definition: GNEChange_Shape.h:103
GNEEdge.h
ShapeContainer::myPOIs
POIs myPOIs
stored POIs
Definition: ShapeContainer.h:216
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:76
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:53
GNELane.h
GNEChange_Shape::myLaneParents
const std::vector< GNELane * > & myLaneParents
reference to vector of lane parents
Definition: GNEChange_Shape.h:79
GNEShape.h
GNEChange_Shape::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Shape.cpp:322
GNEChange_Shape::myDemandElementParents
const std::vector< GNEDemandElement * > & myDemandElementParents
reference to vector of demand element parents
Definition: GNEChange_Shape.h:88
config.h
GNEChange_Shape::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Shape.cpp:312
GNEChange_Shape::myAdditionalChildren
const std::vector< GNEAdditional * > & myAdditionalChildren
reference to vector of additional children
Definition: GNEChange_Shape.h:100
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEChange_Shape::myShape
GNEShape * myShape
pointer to shape
Definition: GNEChange_Shape.h:73
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
ShapeContainer::myPolygons
Polygons myPolygons
stored Polygons
Definition: ShapeContainer.h:200
GNEChange_Shape
Definition: GNEChange_Shape.h:43
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
GNENet.h
GNENet::insertShape
void insertShape(GNEShape *shape, bool updateViewAfterDeleting)
insert shape
Definition: GNENet.cpp:2943
GNEChange_Shape::myShapeChildren
const std::vector< GNEShape * > & myShapeChildren
reference to vector of shape children
Definition: GNEChange_Shape.h:97