Eclipse SUMO - Simulation of Urban MObility
GNETAZSourceSink.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 //
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
26 
27 #include "GNETAZSourceSink.h"
28 
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
34 GNETAZSourceSink::GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional* TAZParent, GNEEdge* edge, double departWeight) :
35  GNEAdditional(TAZParent, TAZParent->getViewNet(), GLO_TAZ, sourceSinkTag, "", false, {
36  edge
37 }, {}, {}, {TAZParent}, {}, {}, {}, {}, {}, {}),
38 myDepartWeight(departWeight) {
39  //check that this is a TAZ Source OR a TAZ Sink
40  if ((sourceSinkTag != SUMO_TAG_TAZSOURCE) && (sourceSinkTag != SUMO_TAG_TAZSINK)) {
41  throw InvalidArgument("Invalid TAZ Child Tag");
42  }
43 }
44 
45 
47 
48 
49 double
51  return myDepartWeight;
52 }
53 
54 
55 void
57  // This additional cannot be moved
58 }
59 
60 
61 void
63  // This additional cannot be moved
64 }
65 
66 
67 void
69  // Currently this additional doesn't own a Geometry
70 }
71 
72 
75  return getParentAdditionals().at(0)->getPositionInView();
76 }
77 
78 
81  return getParentEdges().front()->getCenteringBoundary();
82 }
83 
84 
85 void
86 GNETAZSourceSink::splitEdgeGeometry(const double /*splitPosition*/, const GNENetElement* /*originalElement*/, const GNENetElement* /*newElement*/, GNEUndoList* /*undoList*/) {
87  // geometry of this element cannot be splitted
88 }
89 
90 
91 std::string
93  return getParentAdditionals().at(0)->getID();
94 }
95 
96 
97 void
99  // Currently This additional isn't drawn
100 }
101 
102 
103 std::string
105  switch (key) {
106  case SUMO_ATTR_ID:
107  return getAdditionalID();
108  case SUMO_ATTR_EDGE:
109  return getParentEdges().front()->getID();
110  case SUMO_ATTR_WEIGHT:
111  return toString(myDepartWeight);
112  case GNE_ATTR_PARENT:
113  return getParentAdditionals().at(0)->getID();
114  case GNE_ATTR_PARAMETERS:
115  return getParametersStr();
116  case GNE_ATTR_TAZCOLOR: {
117  // obtain max and min weight source
118  double maxWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MAX_SOURCE);
119  double minWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MIN_SOURCE);
120  // avoid division between zero
121  if ((maxWeightSource - minWeightSource) == 0) {
122  return "0";
123  } else {
124  // calculate percentage relative to the max and min weight
125  double percentage = (myDepartWeight - minWeightSource) / (maxWeightSource - minWeightSource);
126  // convert percentage to a value between [0-9] (because we have only 10 colors)
127  if (percentage >= 1) {
128  return "9";
129  } else if (percentage < 0) {
130  return "0";
131  } else {
132  return toString((int)(percentage * 10));
133  }
134  }
135  }
136  default:
137  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
138  }
139 }
140 
141 double
143  switch (key) {
144  case SUMO_ATTR_WEIGHT:
145  return myDepartWeight;
146  default:
147  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
148  }
149 }
150 
151 
152 void
153 GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
154  // this additional is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
155  if (undoList == nullptr) {
156  setAttribute(key, value);
157  } else {
158  if (value == getAttribute(key)) {
159  return; //avoid needless changes, later logic relies on the fact that attributes have changed
160  }
161  switch (key) {
162  case SUMO_ATTR_ID:
163  case SUMO_ATTR_WEIGHT:
164  case GNE_ATTR_PARAMETERS:
165  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
166  break;
167  default:
168  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
169  }
170  }
171 }
172 
173 
174 bool
175 GNETAZSourceSink::isValid(SumoXMLAttr key, const std::string& value) {
176  switch (key) {
177  case SUMO_ATTR_ID:
178  return isValidAdditionalID(value);
179  case SUMO_ATTR_WEIGHT:
180  return canParse<double>(value) && (parse<double>(value) >= 0);
181  case GNE_ATTR_PARAMETERS:
182  return Parameterised::areParametersValid(value);
183  default:
184  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
185  }
186 }
187 
188 
189 
190 bool
192  switch (key) {
193  case SUMO_ATTR_EDGE:
194  return false;
195  default:
196  return true;
197  }
198 }
199 
200 
201 std::string
203  return getTagStr();
204 }
205 
206 
207 std::string
209  return getTagStr() + ": " + getAttribute(SUMO_ATTR_WEIGHT);
210 }
211 
212 // ===========================================================================
213 // private
214 // ===========================================================================
215 
216 void
217 GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value) {
218  switch (key) {
219  case SUMO_ATTR_ID:
220  changeAdditionalID(value);
221  break;
222  case SUMO_ATTR_WEIGHT:
223  myDepartWeight = parse<double>(value);
224  // update statictis of TAZ parent
225  getParentAdditionals().at(0)->updateParentAdditional();
226  break;
227  case GNE_ATTR_PARAMETERS:
228  setParametersStr(value);
229  break;
230  default:
231  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
232  }
233 }
234 
235 
236 /****************************************************************************/
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
GNETAZSourceSink::GNETAZSourceSink
GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional *TAZParent, GNEEdge *edge, double departWeight)
Constructor.
Definition: GNETAZSourceSink.cpp:34
Parameterised::getParametersStr
std::string getParametersStr() const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
Definition: Parameterised.cpp:112
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:476
GNETAZSourceSink::splitEdgeGeometry
void splitEdgeGeometry(const double splitPosition, const GNENetElement *originalElement, const GNENetElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNETAZSourceSink.cpp:86
GNEHierarchicalParentElements::getParentEdges
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
Definition: GNEHierarchicalParentElements.cpp:181
GNETAZSourceSink::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNETAZSourceSink.cpp:68
GNETAZSourceSink::~GNETAZSourceSink
~GNETAZSourceSink()
destructor
Definition: GNETAZSourceSink.cpp:46
SUMO_TAG_TAZSOURCE
@ SUMO_TAG_TAZSOURCE
a source within a district (connection road)
Definition: SUMOXMLDefinitions.h:135
GNETAZSourceSink::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNETAZSourceSink.cpp:80
GNETAZSourceSink::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNETAZSourceSink.cpp:62
SUMO_ATTR_EDGE
@ SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:423
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:502
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:41
SUMO_ATTR_WEIGHT
@ SUMO_ATTR_WEIGHT
Definition: SUMOXMLDefinitions.h:421
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:335
GNE_ATTR_MAX_SOURCE
@ GNE_ATTR_MAX_SOURCE
max source (used only by TAZs)
Definition: SUMOXMLDefinitions.h:995
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:51
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:131
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:1014
GNE_ATTR_MIN_SOURCE
@ GNE_ATTR_MIN_SOURCE
min source (used only by TAZs)
Definition: SUMOXMLDefinitions.h:991
GNEHierarchicalParentElements::getParentAdditionals
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
Definition: GNEHierarchicalParentElements.cpp:85
GNETAZSourceSink::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNETAZSourceSink.cpp:175
GNETAZSourceSink::getAttribute
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNETAZSourceSink.cpp:104
GNEViewNet.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GNE_ATTR_PARAMETERS
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
Definition: SUMOXMLDefinitions.h:989
GNETAZSourceSink::getAttributeDouble
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNETAZSourceSink.cpp:142
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
GNETAZSourceSink::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNETAZSourceSink.cpp:56
GNEEdge.h
GNETAZSourceSink::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNETAZSourceSink.cpp:92
GNENetElement
Definition: GNENetElement.h:43
Parameterised::setParametersStr
void setParametersStr(const std::string &paramsString)
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
Definition: Parameterised.cpp:139
GNETAZSourceSink::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNETAZSourceSink.cpp:74
GNETAZSourceSink::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNETAZSourceSink.cpp:208
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
SUMO_TAG_TAZSINK
@ SUMO_TAG_TAZSINK
a sink within a district (connection road)
Definition: SUMOXMLDefinitions.h:137
Parameterised::areParametersValid
static bool areParametersValid(const std::string &value, bool report=false)
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
Definition: Parameterised.cpp:166
InvalidArgument
Definition: UtilExceptions.h:56
GNETAZSourceSink.h
GNETAZSourceSink::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNETAZSourceSink.cpp:202
GNE_ATTR_TAZCOLOR
@ GNE_ATTR_TAZCOLOR
Color of TAZSources/TAZSinks.
Definition: SUMOXMLDefinitions.h:1003
config.h
GNETAZSourceSink::getDepartWeight
double getDepartWeight() const
get depart weight
Definition: GNETAZSourceSink.cpp:50
GNETAZSourceSink::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNETAZSourceSink.cpp:98
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEUndoList
Definition: GNEUndoList.h:48
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GNETAZSourceSink::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNETAZSourceSink.cpp:153
GLO_TAZ
@ GLO_TAZ
a TAZ
Definition: GUIGlObjectTypes.h:99
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:482
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
GNETAZSourceSink::isAttributeEnabled
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNETAZSourceSink.cpp:191
GNETAZSourceSink::myDepartWeight
double myDepartWeight
depart Weight
Definition: GNETAZSourceSink.h:140
GNEChange_Attribute.h
GNEUndoList.h
GNE_ATTR_PARENT
@ GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:987