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-2018 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>
26 #include <netedit/GNEViewParent.h>
27 
28 #include "GNEChange_Shape.h"
29 
30 // ===========================================================================
31 // FOX-declarations
32 // ===========================================================================
33 FXIMPLEMENT_ABSTRACT(GNEChange_Shape, GNEChange, nullptr, 0)
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEChange_Shape::GNEChange_Shape(GNEShape* shape, bool forward) :
40  GNEChange(shape->getNet(), forward),
41  myShape(shape) {
42  assert(myNet);
43  myShape->incRef("GNEChange_Shape");
44 }
45 
46 
48  assert(myShape);
49  myShape->decRef("GNEChange_Shape");
50  if (myShape->unreferenced()) {
51  // make sure that shape are removed of ShapeContainer (net) AND grid
52  if (myNet->retrievePolygon(myShape->getID(), false) != nullptr) {
53  // show extra information for tests
54  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from net in ~GNEChange_Shape()");
55  myNet->removeGLObjectFromGrid(dynamic_cast<GUIGlObject*>(myShape));
56  myNet->myPolygons.remove(myShape->getID(), false);
57  } else if (myNet->retrievePOI(myShape->getID(), false) != nullptr) {
58  // show extra information for tests
59  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from net in ~GNEChange_Shape()");
60  myNet->removeGLObjectFromGrid(dynamic_cast<GUIGlObject*>(myShape));
61  myNet->myPOIs.remove(myShape->getID(), false);
62  }
63  // show extra information for tests
64  WRITE_DEBUG("delete " + myShape->getTagStr() + " '" + myShape->getID() + "' in ~GNEChange_Shape()");
65  delete myShape;
66  }
67 }
68 
69 
70 void
72  if (myForward) {
73  // show extra information for tests
74  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from viewNet");
75  // remove shape from net
77  } else {
78  // show extra information for tests
79  WRITE_DEBUG("Adding " + myShape->getTagStr() + " '" + myShape->getID() + "' into viewNet");
80  // Add shape in net
82  }
83  // check if inspector frame has to be updated
84  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
86  }
87 }
88 
89 
90 void
92  if (myForward) {
93  // show extra information for tests
94  WRITE_DEBUG("Adding " + myShape->getTagStr() + " '" + myShape->getID() + "' into viewNet");
95  // Add shape in net
97  } else {
98  // show extra information for tests
99  WRITE_DEBUG("Removing " + myShape->getTagStr() + " '" + myShape->getID() + "' from viewNet");
100  // remove shape from net
102  }
103  // check if inspector frame has to be updated
104  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
106  }
107 }
108 
109 
110 FXString
112  if (myForward) {
113  return ("Undo create " + myShape->getTagStr()).c_str();
114  } else {
115  return ("Undo delete " + myShape->getTagStr()).c_str();
116  }
117 }
118 
119 
120 FXString
122  if (myForward) {
123  return ("Redo create " + myShape->getTagStr()).c_str();
124  } else {
125  return ("Redo delete " + myShape->getTagStr()).c_str();
126  }
127 }
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
void redo()
redo action
FXString redoName() const
get Redo name
void removeShape(GNEShape *shape)
remove created shape (but NOT delete)
Definition: GNENet.cpp:2370
GNEViewParent * getViewParent() const
get the net object
POIs myPOIs
stored POIs
GNEShape * myShape
pointer to shape
Polygons myPolygons
stored Polygons
GNEPOI * retrievePOI(const std::string &id, bool failHard=true) const
get POI by id
Definition: GNENet.cpp:946
GNEPoly * retrievePolygon(const std::string &id, bool failHard=true) const
get Polygon by id
Definition: GNENet.cpp:933
void insertShape(GNEShape *shape)
insert shape
Definition: GNENet.cpp:2342
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
GNEFrame::ACHierarchy * getACHierarchy() const
get ACHierarchy
void refreshACHierarchy()
refresh ACHierarchy
Definition: GNEFrame.cpp:594
FXString undoName() const
return undoName
const std::string getID() const
function to support debugging
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:248
~GNEChange_Shape()
Destructor.
void decRef(const std::string &debugMsg="")
Decrease reference.
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
const std::string & getTagStr() const
get tag assigned to this object in string format
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:81
bool remove(const std::string &id, const bool del=true)
Removes an item.
void undo()
undo action
bool unreferenced()
check if object ins&#39;t referenced
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1730