Eclipse SUMO - Simulation of Urban MObility
GNEChange_EnableAttribute.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 
26 
27 // ===========================================================================
28 // FOX-declarations
29 // ===========================================================================
30 FXIMPLEMENT_ABSTRACT(GNEChange_EnableAttribute, GNEChange, nullptr, 0)
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
36 GNEChange_EnableAttribute::GNEChange_EnableAttribute(GNEAttributeCarrier* ac, GNENet* net, const int originalAttributes, const int newAttributes) :
37  GNEChange(net, true),
38  myAC(ac),
39  myOriginalAttributes(originalAttributes),
40  myNewAttributes(newAttributes) {
41  myAC->incRef("GNEChange_EnableAttribute " + myAC->getTagProperty().getTagStr());
42 }
43 
44 
46  // decrease reference
47  myAC->decRef("GNEChange_EnableAttribute " + myAC->getTagProperty().getTagStr());
48  // remove if is unreferenced
49  if (myAC->unreferenced()) {
50  // show extra information for tests
51  WRITE_DEBUG("Deleting unreferenced " + myAC->getTagStr() + " '" + myAC->getID() + "' in GNEChange_EnableAttribute");
52  // Check if attribute carrier is a shape
53  if (myAC->getTagProperty().isShape()) {
54  // remove shape using specific functions
59  }
60  } else {
61  delete myAC;
62  }
63  }
64 }
65 
66 
67 void
69  // show extra information for tests
70  WRITE_DEBUG("Setting previous attribute into " + myAC->getTagStr() + " '" + myAC->getID() + "'");
71  // set original attributes
73  // check if netElements, additional or shapes has to be saved
74  if (myAC->getTagProperty().isNetElement()) {
75  myNet->requireSaveNet(true);
76  } else if (myAC->getTagProperty().isAdditional() || myAC->getTagProperty().isShape()) {
78  } else if (myAC->getTagProperty().isDemandElement()) {
80  }
81 }
82 
83 
84 void
86  // show extra information for tests
87  WRITE_DEBUG("Setting new attribute into " + myAC->getTagStr() + " '" + myAC->getID() + "'");
88  // set new attributes
90  // check if netElements, additional or shapes has to be saved
91  if (myAC->getTagProperty().isNetElement()) {
92  myNet->requireSaveNet(true);
93  } else if (myAC->getTagProperty().isAdditional() || myAC->getTagProperty().isShape()) {
95  } else if (myAC->getTagProperty().isDemandElement()) {
97  }
98 }
99 
100 
101 FXString
103  return ("Undo change " + myAC->getTagStr() + " attribute").c_str();
104 }
105 
106 
107 FXString
109  return ("Redo change " + myAC->getTagStr() + " attribute").c_str();
110 }
111 
112 
113 /****************************************************************************/
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::TagProperties::isAdditional
bool isAdditional() const
return true if tag correspond to an additional
Definition: GNEAttributeCarrier.cpp:698
SUMO_TAG_POLY
@ SUMO_TAG_POLY
begin/end of the description of a polygon
Definition: SUMOXMLDefinitions.h:57
GNEAttributeCarrier::TagProperties::getTagStr
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
Definition: GNEAttributeCarrier.cpp:529
GNEChange_EnableAttribute::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_EnableAttribute.cpp:108
GNEChange_EnableAttribute::redo
void redo()
redo action
Definition: GNEChange_EnableAttribute.cpp:85
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
SUMO_TAG_POI
@ 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
GNEChange_EnableAttribute::undoName
FXString undoName() const
return undoName
Definition: GNEChange_EnableAttribute.cpp:102
GNEChange_EnableAttribute::myOriginalAttributes
const int myOriginalAttributes
original attributes
Definition: GNEChange_EnableAttribute.h:81
GNEAttributeCarrier::TagProperties::getTag
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
Definition: GNEAttributeCarrier.cpp:523
GNEAttributeCarrier::setEnabledAttribute
virtual void setEnabledAttribute(const int enabledAttributes)=0
method for enabling the attribute and nothing else (used in GNEChange_EnableAttribute)
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
@ SUMO_TAG_POILANE
begin/end of the description of a Point of interest over Lane (used by Netedit)
Definition: SUMOXMLDefinitions.h:55
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_EnableAttribute::~GNEChange_EnableAttribute
~GNEChange_EnableAttribute()
Destructor.
Definition: GNEChange_EnableAttribute.cpp:45
GNEChange_EnableAttribute
the function-object for an editing operation (abstract base)
Definition: GNEChange_EnableAttribute.h:44
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_EnableAttribute::myAC
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
Definition: GNEChange_EnableAttribute.h:78
GNEChange_EnableAttribute.h
GNEChange_EnableAttribute::undo
void undo()
undo action
Definition: GNEChange_EnableAttribute.cpp:68
GNEChange_EnableAttribute::myNewAttributes
const int myNewAttributes
original attributes
Definition: GNEChange_EnableAttribute.h:84
ShapeContainer::removePolygon
virtual bool removePolygon(const std::string &id, bool useLock=true)
Removes a polygon from the container.
Definition: ShapeContainer.cpp:153
config.h
ShapeContainer::removePOI
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
Definition: ShapeContainer.cpp:163
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
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
GNENet.h