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, "", true) {
32}
33
34
35GNETAZSourceSink::GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional* TAZParent, GNEEdge* edge, const double departWeight) :
36 GNEAttributeCarrier(sourceSinkTag, TAZParent->getNet(), TAZParent->getFilename(), false),
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
53 return nullptr;
54}
55
56
59 return nullptr;
60}
61
62
63const Parameterised*
65 return nullptr;
66}
67
68
73
74
75void
77 // open source/sink tag
78 device.openTag(myTagProperty->getTag());
79 // write source/sink attributes
80 device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
82 // close tag
83 device.closeTag();
84}
85
86
87double
89 return myWeight;
90}
91
92
95 return nullptr;
96}
97
98
99const GUIGlObject*
101 return nullptr;
102}
103
104
105void
107 // nothing to update
108}
109
110
111bool
113 return false;
114}
115
116
117bool
119 return false;
120}
121
122
123bool
125 return false;
126}
127
128
129bool
131 return false;
132}
133
134
135bool
137 return false;
138}
139
140
141bool
143 return false;
144}
145
146
147bool
149 return false;
150}
151
152
153bool
155 return false;
156}
157
158
159std::string
161 switch (key) {
162 case SUMO_ATTR_ID:
163 return getParentAdditionals().front()->getID();
164 case SUMO_ATTR_EDGE:
165 return getParentEdges().front()->getID();
166 case SUMO_ATTR_WEIGHT:
167 return toString(myWeight);
168 case GNE_ATTR_PARENT:
169 return getParentAdditionals().at(0)->getID();
170 case GNE_ATTR_TAZCOLOR: {
171 // obtain max and min weight source
172 double maxWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MAX_SOURCE);
173 double minWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MIN_SOURCE);
174 // avoid division between zero
175 if ((maxWeightSource - minWeightSource) == 0) {
176 return "0";
177 } else {
178 // calculate percentage relative to the max and min weight
179 double percentage = (myWeight - minWeightSource) / (maxWeightSource - minWeightSource);
180 // convert percentage to a value between [0-9] (because we have only 10 colors)
181 if (percentage >= 1) {
182 return "9";
183 } else if (percentage < 0) {
184 return "0";
185 } else {
186 return toString((int)(percentage * 10));
187 }
188 }
189 }
190 default:
191 return getCommonAttribute(key);
192 }
193}
194
195double
197 switch (key) {
198 case SUMO_ATTR_WEIGHT:
199 return myWeight;
200 default:
201 return getCommonAttributeDouble(key);
202 }
203}
204
205
210
211
216
217
218void
219GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
220 // this TAZElement is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
221 if (undoList == nullptr) {
222 setAttribute(key, value);
223 } else {
224 if (value == getAttribute(key)) {
225 return; //avoid needless changes, later logic relies on the fact that attributes have changed
226 }
227 switch (key) {
228 case SUMO_ATTR_ID:
229 case SUMO_ATTR_WEIGHT:
230 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
231 break;
232 default:
233 setCommonAttribute(key, value, undoList);
234 break;
235 }
236 }
237}
238
239
240bool
241GNETAZSourceSink::isValid(SumoXMLAttr key, const std::string& value) {
242 switch (key) {
243 case SUMO_ATTR_ID:
244 return false;
245 case SUMO_ATTR_WEIGHT:
246 return canParse<double>(value) && (parse<double>(value) >= 0);
247 default:
248 return isCommonAttributeValid(key, value);
249 }
250}
251
252
253
254bool
256 switch (key) {
257 case SUMO_ATTR_EDGE:
258 return false;
259 default:
260 return true;
261 }
262}
263
264
265std::string
267 return getTagStr();
268}
269
270
271std::string
275
276// ===========================================================================
277// private
278// ===========================================================================
279
280void
281GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value) {
282 switch (key) {
283 case SUMO_ATTR_ID:
284 throw InvalidArgument(getTagStr() + " cannot edit '" + toString(key) + "'");
285 case SUMO_ATTR_WEIGHT:
286 myWeight = parse<double>(value);
287 break;
288 default:
289 setCommonAttribute(key, value);
290 break;
291 }
292}
293
294/****************************************************************************/
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
const std::string getID() const
get ID (all Attribute Carriers have one)
double getCommonAttributeDouble(SumoXMLAttr key) const
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNENet *net)
default Constructor
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
double getWeight() const
get weight
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
methods to retrieve the elements linked to 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)
GNEHierarchicalElement * getHierarchicalElement()
get GNEHierarchicalElement associated with this AttributeCarrier
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
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.