Eclipse 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-2019 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 changed (for undo/redo)
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
25 
26 #include "GNEChange_Attribute.h"
27 
28 // ===========================================================================
29 // FOX-declarations
30 // ===========================================================================
31 FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, nullptr, 0)
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
38  SumoXMLAttr key, const std::string& value,
39  bool customOrigValue, const std::string& origValue) :
40  GNEChange(net, true),
41  myAC(ac),
42  myKey(key),
43  myForceChange(false),
44  myOrigValue(customOrigValue ? origValue : ac->getAttribute(key)),
45  myNewValue(value) {
46  myAC->incRef("GNEChange_Attribute " + toString(myKey));
47 }
48 
49 
51  bool forceChange, SumoXMLAttr key, const std::string& value) :
52  GNEChange(net, true),
53  myAC(ac),
54  myKey(key),
55  myForceChange(forceChange),
56  myOrigValue(ac->getAttribute(key)),
57  myNewValue(value) {
58  myAC->incRef("GNEChange_Attribute " + toString(myKey));
59 }
60 
61 
63  // decrease reference
64  myAC->decRef("GNEChange_Attribute " + toString(myKey));
65  // remove if is unreferenced
66  if (myAC->unreferenced()) {
67  // show extra information for tests
68  WRITE_DEBUG("Deleting unreferenced " + myAC->getTagStr() + " '" + myAC->getID() + "' in GNEChange_Attribute");
69  // Check if attribute carrier is a shape
70  if (myAC->getTagProperty().isShape()) {
71  // remove shape using specific functions
76  }
77  } else {
78  delete myAC;
79  }
80  }
81 }
82 
83 
84 void
86  // show extra information for tests
87  WRITE_DEBUG("Setting previous attribute " + toString(myKey) + " '" + myOrigValue + "' into " + myAC->getTagStr() + " '" + myAC->getID() + "'");
88  // set original value
90  // certain attributes needs extra operations
91  if (myKey != GNE_ATTR_SELECTED) {
92  // check if updated attribute requieres a update geometry
95  }
96  // check if netElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
97  if (myAC->getTagProperty().isNetElement()) {
98  myNet->requiereSaveNet(true);
99  } else if (myAC->getTagProperty().isAdditional() || myAC->getTagProperty().isShape()) {
101  } else if (myAC->getTagProperty().isDemandElement()) {
103  }
104  }
105 }
106 
107 
108 void
110  // show extra information for tests
111  WRITE_DEBUG("Setting new attribute " + toString(myKey) + " '" + myNewValue + "' into " + myAC->getTagStr() + " '" + myAC->getID() + "'");
112  // set new value
114  // certain attributes needs extra operations
115  if (myKey != GNE_ATTR_SELECTED) {
116  // check if updated attribute requieres a update geometry
118  myAC->updateGeometry();
119  }
120  // check if netElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
121  if (myAC->getTagProperty().isNetElement()) {
122  myNet->requiereSaveNet(true);
123  } else if (myAC->getTagProperty().isAdditional() || myAC->getTagProperty().isShape()) {
125  } else if (myAC->getTagProperty().isDemandElement()) {
127  }
128  }
129 }
130 
131 
132 bool
134  // check if we're editing the value of an attribute or changing a disjoint attribute
135  if (myForceChange) {
136  return true;
137  } else {
138  return (myOrigValue != myNewValue);
139  }
140 }
141 
142 
143 FXString
145  return ("Undo change " + myAC->getTagStr() + " attribute").c_str();
146 }
147 
148 
149 FXString
151  return ("Redo change " + myAC->getTagStr() + " attribute").c_str();
152 }
153 
154 
155 /****************************************************************************/
GNEChange_Attribute::myOrigValue
const std::string myOrigValue
the original value
Definition: GNEChange_Attribute.h:112
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:79
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
GNEAttributeCarrier::updateGeometry
virtual void updateGeometry()=0
update pre-computed geometry information
GNEAttributeCarrier::TagProperties::isAdditional
bool isAdditional() const
return true if tag correspond to an additional
Definition: GNEAttributeCarrier.cpp:696
SUMO_TAG_POLY
begin/end of the description of a polygon
Definition: SUMOXMLDefinitions.h:58
GNENet::requiereSaveNet
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:933
GNENet
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:78
GNEAttributeCarrier::TagProperties::isNetElement
bool isNetElement() const
return true if tag correspond to a netElement
Definition: GNEAttributeCarrier.cpp:690
GNEChange_Attribute::~GNEChange_Attribute
~GNEChange_Attribute()
Destructor.
Definition: GNEChange_Attribute.cpp:62
SUMO_TAG_POI
begin/end of the description of a Point of interest
Definition: SUMOXMLDefinitions.h:54
GNEAttributeCarrier::TagProperties::isShape
bool isShape() const
return true if tag correspond to a shape
Definition: GNEAttributeCarrier.cpp:701
GNEAttributeCarrier::TagProperties::getTag
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
Definition: GNEAttributeCarrier.cpp:521
GNEAttributeCarrier::TagProperties::hasAttribute
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute attr
Definition: GNEAttributeCarrier.cpp:678
GNEAttributeCarrier::getTagProperty
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
Definition: GNEAttributeCarrier.cpp:1171
GNENet::requiereSaveAdditionals
void requiereSaveAdditionals(bool value)
inform that additionals has to be saved
Definition: GNENet.cpp:2186
SUMO_TAG_POILANE
begin/end of the description of a Point of interest over Lane (used by Netedit)
Definition: SUMOXMLDefinitions.h:56
GNEChange_Attribute::trueChange
bool trueChange()
wether original and new value differ
Definition: GNEChange_Attribute.cpp:133
GNEAttributeCarrier::TagProperties::isDemandElement
bool isDemandElement() const
return true if tag correspond to a demand element
Definition: GNEAttributeCarrier.cpp:713
GNENetElement.h
GNENet::requiereSaveDemandElements
void requiereSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2342
GNEChange_Attribute::myForceChange
bool myForceChange
flag used to force set attributes
Definition: GNEChange_Attribute.h:109
GNEChange_Attribute::myNewValue
const std::string myNewValue
the original value
Definition: GNEChange_Attribute.h:115
GNEChange_Attribute::GNEChange_Attribute
GNEChange_Attribute(GNEAttributeCarrier *ac, GNENet *net, const SumoXMLAttr key, const std::string &value, bool customOrigValue=false, const std::string &origValue="")
Constructor.
Definition: GNEChange_Attribute.cpp:37
GNEChange::myNet
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
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:53
GNEChange_Attribute::myKey
const SumoXMLAttr myKey
The attribute name (or the original attribute if we're editing a disjoint attribute)
Definition: GNEChange_Attribute.h:106
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNEChange_Attribute::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Attribute.cpp:144
GNEReferenceCounter::incRef
void incRef(const std::string &debugMsg="")
Increarse reference.
Definition: GNEReferenceCounter.h:68
GNEAttributeCarrier::AttributeProperties::requiereUpdateGeometry
bool requiereUpdateGeometry() const
return true if atribute requieres a update geometry in setAttribute(...)
Definition: GNEAttributeCarrier.cpp:470
GNEChange_Attribute::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Attribute.cpp:150
GNEChange_Attribute::myAC
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
Definition: GNEChange_Attribute.h:103
ShapeContainer::removePolygon
virtual bool removePolygon(const std::string &id, bool useLock=true)
Removes a polygon from the container.
Definition: ShapeContainer.cpp:154
GNEAttributeCarrier::TagProperties::getAttributeProperties
const AttributeProperties & getAttributeProperties(SumoXMLAttr attr) const
get attribute (throw error if doesn't exist)
Definition: GNEAttributeCarrier.cpp:621
config.h
GNEAttributeCarrier::setAttribute
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
GNE_ATTR_SELECTED
element is selected
Definition: SUMOXMLDefinitions.h:968
ShapeContainer::removePOI
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
Definition: ShapeContainer.cpp:164
GNEChange_Attribute
the function-object for an editing operation (abstract base)
Definition: GNEChange_Attribute.h:48
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
GNEAttributeCarrier
Definition: GNEAttributeCarrier.h:54
GNEChange_Attribute::redo
void redo()
redo action
Definition: GNEChange_Attribute.cpp:109
GNEChange_Attribute.h
GNENet.h
GNEChange_Attribute::undo
void undo()
undo action
Definition: GNEChange_Attribute.cpp:85