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