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 <cassert>
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNEViewParent.h>
34 
35 #include "GNEChange_Attribute.h"
36 
37 // ===========================================================================
38 // FOX-declarations
39 // ===========================================================================
40 FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, nullptr, 0)
41 
42 // ===========================================================================
43 // member method definitions
44 // ===========================================================================
45 
47  SumoXMLAttr key, const std::string& value,
48  bool customOrigValue, const std::string& origValue) :
49  GNEChange(0, true),
50  myAC(netElement),
51  myKey(key),
52  myOrigValue(customOrigValue ? origValue : netElement->getAttribute(key)),
53  myNewValue(value),
54  myNet(netElement->getNet()),
55  myNetElement(netElement),
56  myAdditional(nullptr),
57  myShape(nullptr) {
58  assert(myAC && (myNetElement || myAdditional || myShape));
59  myAC->incRef("GNEChange_Attribute " + toString(myKey));
60 }
61 
62 
64  SumoXMLAttr key, const std::string& value,
65  bool customOrigValue, const std::string& origValue) :
66  GNEChange(0, true),
67  myAC(additional),
68  myKey(key),
69  myOrigValue(customOrigValue ? origValue : additional->getAttribute(key)),
70  myNewValue(value),
71  myNet(additional->getViewNet()->getNet()),
72  myNetElement(nullptr),
73  myAdditional(additional),
74  myShape(nullptr) {
75  assert(myAC && (myNetElement || myAdditional || myShape));
76  myAC->incRef("GNEChange_Attribute " + toString(myKey));
77 }
78 
79 
81  SumoXMLAttr key, const std::string& value,
82  bool customOrigValue, const std::string& origValue) :
83  GNEChange(0, true),
84  myAC(shape),
85  myKey(key),
86  myOrigValue(customOrigValue ? origValue : shape->getAttribute(key)),
87  myNewValue(value),
88  myNet(shape->getNet()),
89  myNetElement(nullptr),
90  myAdditional(nullptr),
91  myShape(shape) {
92  assert(myAC && (myNetElement || myAdditional || myShape));
93  myAC->incRef("GNEChange_Attribute " + toString(myKey));
94 }
95 
96 
98  assert(myAC);
99  myAC->decRef("GNEChange_Attribute " + toString(myKey));
100  if (myAC->unreferenced()) {
101  // show extra information for tests
102  WRITE_DEBUG("Deleting unreferenced " + toString(myAC->getTag()) + " '" + myAC->getID() + "' in GNEChange_Attribute");
103  // Check if attribute carrier is a shape
104  if (myShape) {
105  // remove shape using pecify functions
106  if (myShape->getTag() == SUMO_TAG_POLY) {
108  } else if ((myShape->getTag() == SUMO_TAG_POI) || (myShape->getTag() == SUMO_TAG_POILANE)) {
110  }
111  } else {
112  delete myAC;
113  }
114  }
115 }
116 
117 
118 void
120  // show extra information for tests
121  WRITE_DEBUG("Setting previous attribute " + toString(myKey) + " '" + myOrigValue + "' into " + toString(myAC->getTag()) + " '" + myAC->getID() + "'");
122  // set original value
124  // check if netElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
125  if (myKey != GNE_ATTR_SELECTED) {
126  if (myNetElement) {
127  myNet->requiereSaveNet(true);
128  } else if (myAdditional) {
130  } else if (myShape) {
131  myNet->requiereSaveShapes(true);
132  }
133  }
134 }
135 
136 
137 void
139  // show extra information for tests
140  WRITE_DEBUG("Setting new attribute " + toString(myKey) + " '" + myNewValue + "' into " + toString(myAC->getTag()) + " '" + myAC->getID() + "'");
141  // set new value
143  // check if netElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
144  if (myKey != GNE_ATTR_SELECTED) {
145  if (myNetElement) {
146  myNet->requiereSaveNet(true);
147  } else if (myAdditional) {
149  } else if (myShape) {
150  myNet->requiereSaveShapes(true);
151  }
152  }
153 }
154 
155 
156 bool
158  return myOrigValue != myNewValue;
159 }
160 
161 
162 FXString
164  return ("Undo change " + toString(myAC->getTag()) + " attribute").c_str();
165 }
166 
167 
168 FXString
170  return ("Redo change " + toString(myAC->getTag()) + " attribute").c_str();
171 }
172 
173 
174 /****************************************************************************/
void redo()
redo action
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
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
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:1846
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:249
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:53
FXString redoName() const
get Redo name
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:844
element is selected
GNEShape * myShape
used if AC is a shape element
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:2057
begin/end of the description of a polygon
SumoXMLTag getTag() const
get XML Tag assigned to this object