SUMO - Simulation of Urban MObility
GNETAZSink.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 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
25 #include <netedit/GNEUndoList.h>
26 
27 #include "GNETAZSink.h"
28 
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
34 GNETAZSink::GNETAZSink(GNEAdditional* TAZParent, GNEEdge* edge, double arrivalWeight) :
35  GNEAdditional(TAZParent, TAZParent->getViewNet(), GLO_TAZ, SUMO_TAG_TAZSINK, "", false),
36  myEdge(edge),
37  myArrivalWeight(arrivalWeight) {
38  // set edge as child
39  addEdgeChild(edge);
40 }
41 
42 
44 
45 
46 void
48  // This additional cannot be moved
49 }
50 
51 
52 void
54  // This additional cannot be moved
55 }
56 
57 
58 void
59 GNETAZSink::updateGeometry(bool /*updateGrid*/) {
60  // Currently this additional doesn't own a Geometry
61 }
62 
63 
67 }
68 
69 
70 std::string
73 }
74 
75 
76 void
78  // Currently This additional isn't drawn
79 }
80 
81 
82 std::string
84  switch (key) {
85  case SUMO_ATTR_ID:
86  return getAdditionalID();
87  case SUMO_ATTR_EDGE:
88  return myEdge->getID();
89  case SUMO_ATTR_WEIGHT:
90  return toString(myArrivalWeight);
91  case GNE_ATTR_PARENT:
93  case GNE_ATTR_GENERIC:
94  return getGenericParametersStr();
95  case GNE_ATTR_TAZCOLOR: {
96  // obtain max and min weight source
97  double maxWeightSink = parse<double>(myFirstAdditionalParent->getAttribute(GNE_ATTR_MAX_SINK));
98  double minWeightSink = parse<double>(myFirstAdditionalParent->getAttribute(GNE_ATTR_MIN_SINK));
99  // avoid division between zero
100  if ((maxWeightSink - minWeightSink) == 0) {
101  return "0";
102  } else {
103  // calculate percentage relative to the max and min weight
104  double percentage = (myArrivalWeight - minWeightSink) / (maxWeightSink - minWeightSink);
105  // convert percentage to a value between [0-9] (because we have only 10 colors)
106  if(percentage >= 1) {
107  return "9";
108  } else if(percentage < 0) {
109  return "0";
110  } else {
111  return toString((int)(percentage*10));
112  }
113  }
114  }
115  default:
116  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
117  }
118 }
119 
120 
121 void
122 GNETAZSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
123  // this additional is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
124  if(undoList == nullptr) {
125  setAttribute(key, value);
126  } else {
127  if (value == getAttribute(key)) {
128  return; //avoid needless changes, later logic relies on the fact that attributes have changed
129  }
130  switch (key) {
131  case SUMO_ATTR_ID:
132  case SUMO_ATTR_WEIGHT:
133  case GNE_ATTR_GENERIC:
134  undoList->p_add(new GNEChange_Attribute(this, key, value));
135  break;
136  default:
137  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
138  }
139  }
140 }
141 
142 
143 bool
144 GNETAZSink::isValid(SumoXMLAttr key, const std::string& value) {
145  switch (key) {
146  case SUMO_ATTR_ID:
147  return isValidAdditionalID(value);
148  case SUMO_ATTR_WEIGHT:
149  return canParse<double>(value) && (parse<double>(value) >= 0);
150  case GNE_ATTR_GENERIC:
151  return isGenericParametersValid(value);
152  default:
153  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
154  }
155 }
156 
157 
158 std::string
160  return getTagStr();
161 }
162 
163 
164 std::string
166  return getTagStr() + ": " + getAttribute(SUMO_ATTR_WEIGHT);
167 }
168 
169 // ===========================================================================
170 // private
171 // ===========================================================================
172 
173 void
174 GNETAZSink::setAttribute(SumoXMLAttr key, const std::string& value) {
175  switch (key) {
176  case SUMO_ATTR_ID:
177  changeAdditionalID(value);
178  break;
179  case SUMO_ATTR_WEIGHT:
180  myArrivalWeight = parse<double>(value);
181  // update statictis of TAZ parent
183  break;
184  case GNE_ATTR_GENERIC:
186  break;
187  default:
188  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
189  }
190 }
191 
192 
193 /****************************************************************************/
GNETAZSink(GNEAdditional *TAZParent, GNEEdge *edge, double arrivalWeight)
constructor
Definition: GNETAZSink.cpp:34
void addEdgeChild(GNEEdge *edge)
add edge child
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNETAZSink.cpp:83
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
Position getPositionInView() const
Returns position of additional in view.
Definition: GNETAZSink.cpp:65
Stores the information about how to visualize structures.
Color of TAZSources/TAZChilds.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
min sink (used only by TAZs)
void updateGeometry(bool updateGrid)
update pre-computed geometry information
Definition: GNETAZSink.cpp:59
~GNETAZSink()
destructor
Definition: GNETAZSink.cpp:43
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
virtual std::string getAttribute(SumoXMLAttr key) const =0
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
max sink (used only by TAZs)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
friend class GNEChange_Attribute
declare friend class
const std::string getID() const
function to support debugging
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNETAZSink.cpp:144
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Definition: GNETAZSink.cpp:53
virtual void updateAdditionalParent()
update parent after add or remove a child (can be reimplemented, for example used for stadistics) ...
a sink within a district (connection road)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Definition: GNETAZSink.cpp:122
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getTagStr() const
get tag assigned to this object in string format
std::string getGenericParametersStr() const
return generic parameters in string format
double myArrivalWeight
arrival Weight
Definition: GNETAZSink.h:118
GNEEdge * myEdge
edge
Definition: GNETAZSink.h:115
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNETAZSink.cpp:77
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNETAZSink.cpp:47
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNETAZSink.cpp:165
std::string getParentName() const
Returns the name of the parent object.
Definition: GNETAZSink.cpp:71
GNEAdditional * myFirstAdditionalParent
pointer to first Additional parent
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNETAZSink.cpp:159
virtual Position getPositionInView() const =0
Returns position of additional in view.