SUMO - Simulation of Urban MObility
GNEChange_Attribute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A network change in which something is moved (for undo/redo)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <cassert>
33 
34 #include "GNEChange_Attribute.h"
35 #include "GNEAttributeCarrier.h"
36 #include "GNENet.h"
37 #include "GNEViewNet.h"
38 #include "GNEAdditional.h"
39 #include "GNEShape.h"
40 
41 // ===========================================================================
42 // FOX-declarations
43 // ===========================================================================
44 FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, NULL, 0)
45 
46 // ===========================================================================
47 // member method definitions
48 // ===========================================================================
49 
51  SumoXMLAttr key, const std::string& value,
52  bool customOrigValue, const std::string& origValue) :
53  GNEChange(0, true),
54  myAC(ac),
55  myKey(key),
56  myOrigValue(customOrigValue ? origValue : ac->getAttribute(key)),
57  myNewValue(value),
58  myAdditional(NULL),
59  myShape(NULL) {
60  myAC->incRef("GNEChange_Attribute " + toString(myKey));
61  // try to cast AC as additional and Shape
62  myAdditional = dynamic_cast<GNEAdditional*>(myAC);
63  myShape = dynamic_cast<GNEShape*>(myAC);
64 }
65 
66 
68  assert(myAC);
69  myAC->decRef("GNEChange_Attribute " + toString(myKey));
70  if (myAC->unreferenced()) {
71  // show extra information for tests
72  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
73  WRITE_WARNING("Deleting unreferenced " + toString(myAC->getTag()) + " '" + myAC->getID() + "' in GNEChange_Attribute");
74  }
75  delete myAC;
76  }
77 }
78 
79 
80 void
82  // show extra information for tests
83  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
84  WRITE_WARNING("Setting previous attribute " + toString(myKey) + " '" + myOrigValue + "' into " + toString(myAC->getTag()) + " '" + myAC->getID() + "'");
85  }
86  // set original value
88  // check if additional or shapes has to be saved
89  if(myAdditional) {
91  } else if(myShape) {
93  }
94 }
95 
96 
97 void
99  // show extra information for tests
100  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
101  WRITE_WARNING("Setting new attribute " + toString(myKey) + " '" + myNewValue + "' into " + toString(myAC->getTag()) + " '" + myAC->getID() + "'");
102  }
103  // set new value
105  // check if additional or shapes has to be saved
106  if(myAdditional) {
108  } else if(myShape) {
110  }
111 }
112 
113 
114 bool
116  return myOrigValue != myNewValue;
117 }
118 
119 
120 FXString
122  return ("Undo change " + toString(myAC->getTag()) + " attribute").c_str();
123 }
124 
125 
126 FXString
128  return ("Redo change " + toString(myAC->getTag()) + " attribute").c_str();
129 }
130 
131 
132 /****************************************************************************/
void redo()
redo action
void requiereSaveAdditionals()
inform that additionals has to be saved
Definition: GNENet.cpp:1237
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:49
SumoXMLAttr myKey
The attribute name.
void undo()
undo action
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
FXString redoName() const
get Redo name
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
the function-object for an editing operation (abstract base)
bool trueChange()
wether original and new value differ
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
std::string myNewValue
the original value
~GNEChange_Attribute()
Destructor.
GNENet * getNet() const
get Net in which this element is placed
Definition: GNEShape.cpp:57
GNEAdditional * myAdditional
used if Ac is an additional element
const std::string getID() const
function to support debugging
void decRef(const std::string &debugMsg="")
Decrease reference.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
GNEShape * myShape
used if Ac is a shape element
GNENet * getNet() const
get the net object
SumoXMLTag getTag() const
get XML Tag assigned to this object
void requiereSaveShapes()
inform that shapes has to be saved
Definition: GNENet.cpp:1247
FXString undoName() const
return undoName
std::string myOrigValue
the original value
bool unreferenced()
check if object ins&#39;t referenced