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 
24 #include <utils/common/RGBColor.h>
26 #include <netedit/GNEViewNet.h>
27 #include <netedit/GNENet.h>
30 #include <netedit/GNEViewParent.h>
31 
32 #include "GNEChange_Shape.h"
33 
34 // ===========================================================================
35 // FOX-declarations
36 // ===========================================================================
37 FXIMPLEMENT_ABSTRACT(GNEChange_Shape, GNEChange, nullptr, 0)
38 
39 // ===========================================================================
40 // member method definitions
41 // ===========================================================================
42 
43 GNEChange_Shape::GNEChange_Shape(GNEShape* shape, bool forward) :
44  GNEChange(shape->getNet(), forward),
45  myShape(shape) {
46  assert(myNet);
47  myShape->incRef("GNEChange_Shape");
48 }
49 
50 
52  assert(myShape);
53  myShape->decRef("GNEChange_Shape");
54  if (myShape->unreferenced()) {
55  // make sure that shape are removed of ShapeContainer (net) AND grid
56  if (myNet->retrievePolygon(myShape->getID(), false) != nullptr) {
57  // show extra information for tests
58  WRITE_DEBUG("Removing " + toString(myShape->getTag()) + " '" + myShape->getID() + "' from net in ~GNEChange_Shape()");
59  myNet->removeGLObjectFromGrid(dynamic_cast<GUIGlObject*>(myShape));
60  myNet->myPolygons.remove(myShape->getID(), false);
61  } else if (myNet->retrievePOI(myShape->getID(), false) != nullptr) {
62  // show extra information for tests
63  WRITE_DEBUG("Removing " + toString(myShape->getTag()) + " '" + myShape->getID() + "' from net in ~GNEChange_Shape()");
64  myNet->removeGLObjectFromGrid(dynamic_cast<GUIGlObject*>(myShape));
65  myNet->myPOIs.remove(myShape->getID(), false);
66  }
67  // show extra information for tests
68  WRITE_DEBUG("delete " + toString(myShape->getTag()) + " '" + myShape->getID() + "' in ~GNEChange_Shape()");
69  delete myShape;
70  }
71 }
72 
73 
74 void
76  if (myForward) {
77  // show extra information for tests
78  WRITE_DEBUG("Removing " + toString(myShape->getTag()) + " '" + myShape->getID() + "' from viewNet");
79  // remove shape from net
81  } else {
82  // show extra information for tests
83  WRITE_DEBUG("Adding " + toString(myShape->getTag()) + " '" + myShape->getID() + "' into viewNet");
84  // Add shape in net
86  }
87  // check if inspector frame has to be updated
88  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
90  }
91 }
92 
93 
94 void
96  if (myForward) {
97  // show extra information for tests
98  WRITE_DEBUG("Adding " + toString(myShape->getTag()) + " '" + myShape->getID() + "' into viewNet");
99  // Add shape in net
101  } else {
102  // show extra information for tests
103  WRITE_DEBUG("Removing " + toString(myShape->getTag()) + " '" + myShape->getID() + "' from viewNet");
104  // remove shape from net
106  }
107  // check if inspector frame has to be updated
108  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
110  }
111 }
112 
113 
114 FXString
116  if (myForward) {
117  return ("Undo create " + toString(myShape->getTag())).c_str();
118  } else {
119  return ("Undo delete " + toString(myShape->getTag())).c_str();
120  }
121 }
122 
123 
124 FXString
126  if (myForward) {
127  return ("Redo create " + toString(myShape->getTag())).c_str();
128  } else {
129  return ("Redo delete " + toString(myShape->getTag())).c_str();
130  }
131 }
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
void redo()
redo action
FXString redoName() const
get Redo name
void removeShape(GNEShape *shape)
remove created shape (but NOT delete)
Definition: GNENet.cpp:2356
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:961
GNEPoly * retrievePolygon(const std::string &id, bool failHard=true) const
get Polygon by id
Definition: GNENet.cpp:948
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void insertShape(GNEShape *shape)
insert shape
Definition: GNENet.cpp:2328
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1175
GNEFrame::ACHierarchy * getACHierarchy() const
get ACHierarchy
void refreshACHierarchy()
refresh ACHierarchy
Definition: GNEFrame.cpp:117
FXString undoName() const
return undoName
const std::string getID() const
function to support debugging
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:249
~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:75
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:80
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:1745
SumoXMLTag getTag() const
get XML Tag assigned to this object