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 /****************************************************************************/
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GNETAZSourceSink::GNETAZSourceSink
GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional *TAZParent, GNEEdge *edge, double departWeight)
Constructor.
Definition: GNETAZSourceSink.cpp:35
GNEAdditional::setGenericParametersStr
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
Definition: GNEAdditional.cpp:704
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:578
GNETAZSourceSink::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNETAZSourceSink.cpp:69
GNETAZSourceSink::~GNETAZSourceSink
~GNETAZSourceSink()
destructor
Definition: GNETAZSourceSink.cpp:47
SUMO_TAG_TAZSOURCE
a source within a district (connection road)
Definition: SUMOXMLDefinitions.h:136
GNEAttributeCarrier::isGenericParametersValid
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
Definition: GNEAttributeCarrier.cpp:1354
GNETAZSourceSink::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNETAZSourceSink.cpp:81
GNETAZSourceSink::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNETAZSourceSink.cpp:63
SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:424
GNEHierarchicalElementParents::getEdgeParents
const std::vector< GNEEdge * > & getEdgeParents() const
get edge parents
Definition: GNEHierarchicalElementParents.cpp:150
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:42
SUMO_ATTR_WEIGHT
Definition: SUMOXMLDefinitions.h:422
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
GNE_ATTR_MAX_SOURCE
max source (used only by TAZs)
Definition: SUMOXMLDefinitions.h:992
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
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:132
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GNE_ATTR_MIN_SOURCE
min source (used only by TAZs)
Definition: SUMOXMLDefinitions.h:988
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:160
GNETAZSourceSink::getAttribute
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNETAZSourceSink.cpp:99
GNEViewNet.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
GNETAZSourceSink::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNETAZSourceSink.cpp:57
GNEEdge.h
GNETAZSourceSink::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNETAZSourceSink.cpp:87
GNETAZSourceSink::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNETAZSourceSink.cpp:75
GNETAZSourceSink::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNETAZSourceSink.cpp:181
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
SUMO_TAG_TAZSINK
a sink within a district (connection road)
Definition: SUMOXMLDefinitions.h:138
GNEHierarchicalElementParents::getAdditionalParents
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementParents.cpp:86
InvalidArgument
Definition: UtilExceptions.h:57
GNEAdditional::getGenericParametersStr
std::string getGenericParametersStr() const
return generic parameters in string format
Definition: GNEAdditional.cpp:678
GNETAZSourceSink.h
GNETAZSourceSink::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNETAZSourceSink.cpp:175
GNE_ATTR_TAZCOLOR
Color of TAZSources/TAZSinks.
Definition: SUMOXMLDefinitions.h:1000
config.h
GNETAZSourceSink::getDepartWeight
double getDepartWeight() const
get depart weight
Definition: GNETAZSourceSink.cpp:51
GNETAZSourceSink::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNETAZSourceSink.cpp:93
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEUndoList
Definition: GNEUndoList.h:49
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
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:138
GLO_TAZ
a TAZ
Definition: GUIGlObjectTypes.h:100
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:584
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNETAZSourceSink::myDepartWeight
double myDepartWeight
depart Weight
Definition: GNETAZSourceSink.h:127
GNEChange_Attribute.h
GNEUndoList.h
GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:984