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-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 something is moved (for undo/redo)
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEViewNet.h>
28 
29 #include "GNEChange_Attribute.h"
30 
31 // ===========================================================================
32 // FOX-declarations
33 // ===========================================================================
34 FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, nullptr, 0)
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
41  SumoXMLAttr key, const std::string& value,
42  bool customOrigValue, const std::string& origValue) :
43  GNEChange(nullptr, true),
44  myAC(netElement),
45  myKey(key),
46  myOrigValue(customOrigValue ? origValue : netElement->getAttribute(key)),
47  myNewValue(value),
48  myNet(netElement->getNet()),
49  myNetElement(netElement),
50  myAdditional(nullptr),
51  myShape(nullptr) {
52  assert(myAC && (myNetElement || myAdditional || myShape));
53  myAC->incRef("GNEChange_Attribute " + toString(myKey));
54 }
55 
56 
58  SumoXMLAttr key, const std::string& value,
59  bool customOrigValue, const std::string& origValue) :
60  GNEChange(nullptr, true),
61  myAC(additional),
62  myKey(key),
63  myOrigValue(customOrigValue ? origValue : additional->getAttribute(key)),
64  myNewValue(value),
65  myNet(additional->getViewNet()->getNet()),
66  myNetElement(nullptr),
67  myAdditional(additional),
68  myShape(nullptr) {
69  assert(myAC && (myNetElement || myAdditional || myShape));
70  myAC->incRef("GNEChange_Attribute " + toString(myKey));
71 }
72 
73 
75  SumoXMLAttr key, const std::string& value,
76  bool customOrigValue, const std::string& origValue) :
77  GNEChange(nullptr, true),
78  myAC(shape),
79  myKey(key),
80  myOrigValue(customOrigValue ? origValue : shape->getAttribute(key)),
81  myNewValue(value),
82  myNet(shape->getNet()),
83  myNetElement(nullptr),
84  myAdditional(nullptr),
85  myShape(shape) {
86  assert(myAC && (myNetElement || myAdditional || myShape));
87  myAC->incRef("GNEChange_Attribute " + toString(myKey));
88 }
89 
90 
92  assert(myAC);
93  myAC->decRef("GNEChange_Attribute " + toString(myKey));
94  if (myAC->unreferenced()) {
95  // show extra information for tests
96  WRITE_DEBUG("Deleting unreferenced " + myAC->getTagStr() + " '" + myAC->getID() + "' in GNEChange_Attribute");
97  // Check if attribute carrier is a shape
98  if (myShape) {
99  // remove shape using pecify functions
104  }
105  } else {
106  delete myAC;
107  }
108  }
109 }
110 
111 
112 void
114  // show extra information for tests
115  WRITE_DEBUG("Setting previous attribute " + toString(myKey) + " '" + myOrigValue + "' into " + myAC->getTagStr() + " '" + myAC->getID() + "'");
116  // set original value
118  // check if netElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
119  if (myKey != GNE_ATTR_SELECTED) {
120  if (myNetElement) {
121  myNet->requiereSaveNet(true);
122  } else if (myAdditional) {
124  } else if (myShape) {
125  myNet->requiereSaveShapes(true);
126  }
127  }
128 }
129 
130 
131 void
133  // show extra information for tests
134  WRITE_DEBUG("Setting new attribute " + toString(myKey) + " '" + myNewValue + "' into " + myAC->getTagStr() + " '" + myAC->getID() + "'");
135  // set new value
137  // check if netElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
138  if (myKey != GNE_ATTR_SELECTED) {
139  if (myNetElement) {
140  myNet->requiereSaveNet(true);
141  } else if (myAdditional) {
143  } else if (myShape) {
144  myNet->requiereSaveShapes(true);
145  }
146  }
147 }
148 
149 
150 bool
152  return myOrigValue != myNewValue;
153 }
154 
155 
156 FXString
158  return ("Undo change " + myAC->getTagStr() + " attribute").c_str();
159 }
160 
161 
162 FXString
164  return ("Redo change " + myAC->getTagStr() + " attribute").c_str();
165 }
166 
167 
168 /****************************************************************************/
void redo()
redo action
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
SumoXMLAttr myKey
The attribute name.
GNEChange_Attribute(GNENetElement *netElement, const SumoXMLAttr key, const std::string &value, bool customOrigValue=false, const std::string &origValue="")
Constructor for NetElements.
void undo()
undo action
GNENet * myNet
pointer to Net (used to simplify code)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
begin/end of the description of a Point of interest
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
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:49
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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.
void requiereSaveAdditionals(bool value)
inform that additionals has to be saved
Definition: GNENet.cpp:1844
GNEAdditional * myAdditional
used if AC is an additional element
const std::string getID() const
function to support debugging
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:248
void incRef(const std::string &debugMsg="")
Increarse reference.
void decRef(const std::string &debugMsg="")
Decrease reference.
GNENetElement * myNetElement
used if AC is an net element
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
FXString redoName() const
get Redo name
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
const std::string & getTagStr() const
get tag assigned to this object in string format
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:837
element is selected
GNEShape * myShape
used if AC is a shape element
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
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
void requiereSaveShapes(bool value)
inform that shapes has to be saved
Definition: GNENet.cpp:2052
begin/end of the description of a polygon