Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNETAZSourceSink.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18//
19/****************************************************************************/
20
23
24#include "GNETAZSourceSink.h"
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
31 GNEAttributeCarrier(sourceSinkTag, net) {
32}
33
34
35GNETAZSourceSink::GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional* TAZParent, GNEEdge* edge, const double departWeight) :
36 GNEAttributeCarrier(sourceSinkTag, TAZParent->getNet(), TAZParent->getFileBucket()),
37 myWeight(departWeight) {
38 // set parents
39 setParent<GNEEdge*>(edge);
40 setParent<GNEAdditional*>(TAZParent);
41 //check that this is a TAZ Source OR a TAZ Sink
42 if ((sourceSinkTag != SUMO_TAG_TAZSOURCE) && (sourceSinkTag != SUMO_TAG_TAZSINK)) {
43 throw InvalidArgument("Invalid TAZ Child Tag");
44 }
45}
46
47
49
50
55
56
59 return nullptr;
60}
61
62
65 return nullptr;
66}
67
68
69const Parameterised*
71 return nullptr;
72}
73
74
77 return getParentAdditionals().front()->getFileBucket();
78}
79
80void
82 // open source/sink tag
83 device.openTag(myTagProperty->getTag());
84 // write source/sink attributes
85 device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
87 // close tag
88 device.closeTag();
89}
90
91
92double
94 return myWeight;
95}
96
97
100 return nullptr;
101}
102
103
104const GUIGlObject*
106 return nullptr;
107}
108
109
110void
112 // nothing to update
113}
114
115
116bool
118 return false;
119}
120
121
122bool
124 return false;
125}
126
127
128bool
130 return false;
131}
132
133
134bool
136 return false;
137}
138
139
140bool
142 return false;
143}
144
145
146bool
148 return false;
149}
150
151
152bool
154 return false;
155}
156
157
158bool
160 return false;
161}
162
163
164std::string
166 switch (key) {
167 case SUMO_ATTR_ID:
168 return getParentAdditionals().front()->getID();
169 case SUMO_ATTR_EDGE:
170 return getParentEdges().front()->getID();
171 case SUMO_ATTR_WEIGHT:
172 return toString(myWeight);
173 case GNE_ATTR_PARENT:
174 return getParentAdditionals().at(0)->getID();
175 case GNE_ATTR_TAZCOLOR: {
176 // obtain max and min weight source
177 double maxWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MAX_SOURCE);
178 double minWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MIN_SOURCE);
179 // avoid division between zero
180 if ((maxWeightSource - minWeightSource) == 0) {
181 return "0";
182 } else {
183 // calculate percentage relative to the max and min weight
184 double percentage = (myWeight - minWeightSource) / (maxWeightSource - minWeightSource);
185 // convert percentage to a value between [0-9] (because we have only 10 colors)
186 if (percentage >= 1) {
187 return "9";
188 } else if (percentage < 0) {
189 return "0";
190 } else {
191 return toString((int)(percentage * 10));
192 }
193 }
194 }
195 default:
196 return getCommonAttribute(key);
197 }
198}
199
200double
202 switch (key) {
203 case SUMO_ATTR_WEIGHT:
204 return myWeight;
205 default:
206 return getCommonAttributeDouble(key);
207 }
208}
209
210
215
216
221
222
223void
224GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
225 // this TAZElement is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
226 if (undoList == nullptr) {
227 setAttribute(key, value);
228 } else {
229 if (value == getAttribute(key)) {
230 return; //avoid needless changes, later logic relies on the fact that attributes have changed
231 }
232 switch (key) {
233 case SUMO_ATTR_ID:
234 case SUMO_ATTR_WEIGHT:
235 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
236 break;
237 default:
238 setCommonAttribute(key, value, undoList);
239 break;
240 }
241 }
242}
243
244
245bool
246GNETAZSourceSink::isValid(SumoXMLAttr key, const std::string& value) {
247 switch (key) {
248 case SUMO_ATTR_ID:
249 return false;
250 case SUMO_ATTR_WEIGHT:
251 return canParse<double>(value) && (parse<double>(value) >= 0);
252 default:
253 return isCommonAttributeValid(key, value);
254 }
255}
256
257
258
259bool
261 switch (key) {
262 case SUMO_ATTR_EDGE:
263 return false;
264 default:
265 return true;
266 }
267}
268
269
270std::string
272 return getTagStr();
273}
274
275
276std::string
280
281// ===========================================================================
282// private
283// ===========================================================================
284
285void
286GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value) {
287 switch (key) {
288 case SUMO_ATTR_ID:
289 throw InvalidArgument(getTagStr() + " cannot edit '" + toString(key) + "'");
290 case SUMO_ATTR_WEIGHT:
291 myWeight = parse<double>(value);
292 break;
293 default:
294 setCommonAttribute(key, value);
295 break;
296 }
297}
298
299/****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TAZSINK
a sink within a district (connection road)
@ SUMO_TAG_TAZSOURCE
a source within a district (connection road)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_MAX_SOURCE
max source (used only by TAZs)
@ SUMO_ATTR_EDGE
@ GNE_ATTR_TAZCOLOR
Color of TAZSources/TAZSinks.
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_WEIGHT
@ SUMO_ATTR_ID
@ GNE_ATTR_MIN_SOURCE
min source (used only by TAZs)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
double getCommonAttributeDouble(SumoXMLAttr key) const
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNENet *net)
default Constructor
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
double getWeight() const
get weight
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
double getAttributeDouble(SumoXMLAttr key) const override
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
~GNETAZSourceSink()
destructor
GNEMoveElement * getMoveElement() const override
get GNEMoveElement associated with this TAZSourceSink
bool checkDrawFromContour() const override
check if draw from contour (green)
void updateGeometry() override
update pre-computed geometry information
bool checkDrawToContour() const override
check if draw from contour (magenta)
bool checkDrawSelectContour() const override
check if draw select contour (blue)
Parameterised * getParameters() override
get parameters associated with this TAZSourceSink
bool isAttributeEnabled(SumoXMLAttr key) const override
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
bool checkDrawMoveContour() const override
check if draw move contour (red)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
bool isValid(SumoXMLAttr key, const std::string &value) override
GUIGlObject * getGUIGlObject() override
get GUIGlObject associated with this AttributeCarrier
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void writeTAZSourceSink(OutputDevice &device) const
write TAZ sourceSink
Position getAttributePosition(SumoXMLAttr key) const override
bool checkDrawOverContour() const override
check if draw over contour (orange)
double myWeight
depart Weight
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this TAZSourceSink
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.