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 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
25 #include <netedit/GNEUndoList.h>
26 #include <netedit/GNEViewNet.h>
27 
28 #include "GNETAZSourceSink.h"
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
35 GNETAZSourceSink::GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional* TAZParent, GNEEdge* edge, double departWeight) :
36  GNEAdditional(TAZParent, TAZParent->getViewNet(), GLO_TAZ, sourceSinkTag, "", false, {
37  edge
38 }, {}, {}, {TAZParent}, {}, {}, {}, {}, {}, {}),
39 myDepartWeight(departWeight) {
40  //check that this is a TAZ Source OR a TAZ Sink
41  if ((sourceSinkTag != SUMO_TAG_TAZSOURCE) && (sourceSinkTag != SUMO_TAG_TAZSINK)) {
42  throw InvalidArgument("Invalid TAZ Child Tag");
43  }
44 }
45 
46 
48 
49 
50 double
52  return myDepartWeight;
53 }
54 
55 
56 void
58  // This additional cannot be moved
59 }
60 
61 
62 void
64  // This additional cannot be moved
65 }
66 
67 
68 void
70  // Currently this additional doesn't own a Geometry
71 }
72 
73 
76  return getAdditionalParents().at(0)->getPositionInView();
77 }
78 
79 
82  return getEdgeParents().front()->getCenteringBoundary();
83 }
84 
85 
86 std::string
88  return getAdditionalParents().at(0)->getID();
89 }
90 
91 
92 void
94  // Currently This additional isn't drawn
95 }
96 
97 
98 std::string
100  switch (key) {
101  case SUMO_ATTR_ID:
102  return getAdditionalID();
103  case SUMO_ATTR_EDGE:
104  return getEdgeParents().front()->getID();
105  case SUMO_ATTR_WEIGHT:
106  return toString(myDepartWeight);
107  case GNE_ATTR_PARENT:
108  return getAdditionalParents().at(0)->getID();
109  case GNE_ATTR_GENERIC:
110  return getGenericParametersStr();
111  case GNE_ATTR_TAZCOLOR: {
112  // obtain max and min weight source
113  double maxWeightSource = parse<double>(getAdditionalParents().at(0)->getAttribute(GNE_ATTR_MAX_SOURCE));
114  double minWeightSource = parse<double>(getAdditionalParents().at(0)->getAttribute(GNE_ATTR_MIN_SOURCE));
115  // avoid division between zero
116  if ((maxWeightSource - minWeightSource) == 0) {
117  return "0";
118  } else {
119  // calculate percentage relative to the max and min weight
120  double percentage = (myDepartWeight - minWeightSource) / (maxWeightSource - minWeightSource);
121  // convert percentage to a value between [0-9] (because we have only 10 colors)
122  if (percentage >= 1) {
123  return "9";
124  } else if (percentage < 0) {
125  return "0";
126  } else {
127  return toString((int)(percentage * 10));
128  }
129  }
130  }
131  default:
132  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
133  }
134 }
135 
136 
137 void
138 GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
139  // this additional is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
140  if (undoList == nullptr) {
141  setAttribute(key, value);
142  } else {
143  if (value == getAttribute(key)) {
144  return; //avoid needless changes, later logic relies on the fact that attributes have changed
145  }
146  switch (key) {
147  case SUMO_ATTR_ID:
148  case SUMO_ATTR_WEIGHT:
149  case GNE_ATTR_GENERIC:
150  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
151  break;
152  default:
153  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
154  }
155  }
156 }
157 
158 
159 bool
160 GNETAZSourceSink::isValid(SumoXMLAttr key, const std::string& value) {
161  switch (key) {
162  case SUMO_ATTR_ID:
163  return isValidAdditionalID(value);
164  case SUMO_ATTR_WEIGHT:
165  return canParse<double>(value) && (parse<double>(value) >= 0);
166  case GNE_ATTR_GENERIC:
167  return isGenericParametersValid(value);
168  default:
169  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
170  }
171 }
172 
173 
174 std::string
176  return getTagStr();
177 }
178 
179 
180 std::string
182  return getTagStr() + ": " + getAttribute(SUMO_ATTR_WEIGHT);
183 }
184 
185 // ===========================================================================
186 // private
187 // ===========================================================================
188 
189 void
190 GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value) {
191  switch (key) {
192  case SUMO_ATTR_ID:
193  changeAdditionalID(value);
194  break;
195  case SUMO_ATTR_WEIGHT:
196  myDepartWeight = parse<double>(value);
197  // update statictis of TAZ parent
198  getAdditionalParents().at(0)->updateAdditionalParent();
199  break;
200  case GNE_ATTR_GENERIC:
202  break;
203  default:
204  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
205  }
206 }
207 
208 
209 /****************************************************************************/
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
SumoXMLTag
Numbers representing SUMO-XML - element names.
~GNETAZSourceSink()
destructor
a source within a district (connection road)
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
double getDepartWeight() const
get depart weight
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional *TAZParent, GNEEdge *edge, double departWeight)
Constructor.
Stores the information about how to visualize structures.
Color of TAZSources/TAZSinks.
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
max source (used only by TAZs)
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
const std::vector< GNEEdge * > & getEdgeParents() const
get edge parents
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
min source (used only by TAZs)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
std::string getParentName() const
Returns the name of the parent object.
double myDepartWeight
depart Weight
a sink within a district (connection road)
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getTagStr() const
get tag assigned to this object in string format
std::string getGenericParametersStr() const
return generic parameters in string format
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
Position getPositionInView() const
Returns position of additional in view.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
void updateGeometry()
update pre-computed geometry information
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.