SUMO - Simulation of Urban MObility
GNEChange_Attribute.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A network change in which something is moved (for undo/redo)
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <cassert>
32 
33 #include "GNEChange_Attribute.h"
34 #include "GNEAttributeCarrier.h"
35 #include "GNENet.h"
36 #include "GNEViewNet.h"
37 #include "GNEAdditional.h"
38 #include "GNEShape.h"
39 
40 // ===========================================================================
41 // FOX-declarations
42 // ===========================================================================
43 FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, NULL, 0)
44 
45 // ===========================================================================
46 // member method definitions
47 // ===========================================================================
48 
50  SumoXMLAttr key, const std::string& value,
51  bool customOrigValue, const std::string& origValue) :
52  GNEChange(0, true),
53  myAC(ac),
54  myKey(key),
55  myOrigValue(customOrigValue ? origValue : ac->getAttribute(key)),
56  myNewValue(value),
57  myAdditional(NULL),
58  myShape(NULL) {
59  myAC->incRef("GNEChange_Attribute " + toString(myKey));
60  // try to cast AC as additional and Shape
61  myAdditional = dynamic_cast<GNEAdditional*>(myAC);
62  myShape = dynamic_cast<GNEShape*>(myAC);
63 }
64 
65 
67  assert(myAC);
68  myAC->decRef("GNEChange_Attribute " + toString(myKey));
69  if (myAC->unreferenced()) {
70  // show extra information for tests
71  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
72  WRITE_WARNING("Deleting unreferenced " + toString(myAC->getTag()) + " '" + myAC->getID() + "' in GNEChange_Attribute");
73  }
74  // Check if attribute carrier is a shape
75  if (myShape) {
76  // remove shape using pecify functions
77  if (myShape->getTag() == SUMO_TAG_POLY) {
79  } else if ((myShape->getTag() == SUMO_TAG_POI) || (myShape->getTag() == SUMO_TAG_POILANE)) {
81  }
82  } else {
83  delete myAC;
84  }
85  }
86 }
87 
88 
89 void
91  // show extra information for tests
92  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
93  WRITE_WARNING("Setting previous attribute " + toString(myKey) + " '" + myOrigValue + "' into " + toString(myAC->getTag()) + " '" + myAC->getID() + "'");
94  }
95  // set original value
97  // check if additional or shapes has to be saved
98  if (myAdditional) {
100  } else if (myShape) {
102  }
103 }
104 
105 
106 void
108  // show extra information for tests
109  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
110  WRITE_WARNING("Setting new attribute " + toString(myKey) + " '" + myNewValue + "' into " + toString(myAC->getTag()) + " '" + myAC->getID() + "'");
111  }
112  // set new value
114  // check if additional or shapes has to be saved
115  if (myAdditional) {
117  } else if (myShape) {
119  }
120 }
121 
122 
123 bool
125  return myOrigValue != myNewValue;
126 }
127 
128 
129 FXString
131  return ("Undo change " + toString(myAC->getTag()) + " attribute").c_str();
132 }
133 
134 
135 FXString
137  return ("Redo change " + toString(myAC->getTag()) + " attribute").c_str();
138 }
139 
140 
141 /****************************************************************************/
void redo()
redo action
void requiereSaveAdditionals()
inform that additionals has to be saved
Definition: GNENet.cpp:1736
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:48
SumoXMLAttr myKey
The attribute name.
void undo()
undo action
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
begin/end of the description of a Point of interest
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
the function-object for an editing operation (abstract base)
bool trueChange()
wether original and new value differ
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
std::string myNewValue
the original value
~GNEChange_Attribute()
Destructor.
virtual bool removePolygon(const std::string &id)
Removes a polygon from the container.
FXString undoName() const
return undoName
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
GNEAdditional * myAdditional
used if Ac is an additional element
const std::string getID() const
function to support debugging
void decRef(const std::string &debugMsg="")
Decrease reference.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
GNENet * getNet() const
get Net in which this element is placed
Definition: GNEShape.cpp:56
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:59
FXString redoName() const
get Redo name
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
GNEShape * myShape
used if Ac is a shape element
GNENet * getNet() const
get the net object
void requiereSaveShapes()
inform that shapes has to be saved
Definition: GNENet.cpp:1982
std::string myOrigValue
the original value
begin/end of the description of a Point of interest over Lane (used by Netedit)
bool unreferenced()
check if object ins&#39;t referenced
begin/end of the description of a polygon
SumoXMLTag getTag() const
get XML Tag assigned to this object