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#include <config.h>
21
22#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
30
31#include "GNETAZSourceSink.h"
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
38 GNEAttributeCarrier(sourceSinkTag, net, "", true) {
39}
40
41
42GNETAZSourceSink::GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional* TAZParent, GNEEdge* edge, const double departWeight) :
43 GNEAttributeCarrier(sourceSinkTag, TAZParent->getNet(), TAZParent->getFilename(), false),
44 myWeight(departWeight) {
45 // set parents
46 setParent<GNEEdge*>(edge);
47 setParent<GNEAdditional*>(TAZParent);
48 //check that this is a TAZ Source OR a TAZ Sink
49 if ((sourceSinkTag != SUMO_TAG_TAZSOURCE) && (sourceSinkTag != SUMO_TAG_TAZSINK)) {
50 throw InvalidArgument("Invalid TAZ Child Tag");
51 }
52}
53
54
56
57
62
63
64void
66 // open source/sink tag
67 device.openTag(myTagProperty->getTag());
68 // write source/sink attributes
69 device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
71 // close tag
72 device.closeTag();
73}
74
75
76double
78 return myWeight;
79}
80
81
84 return nullptr;
85}
86
87
88const GUIGlObject*
90 return nullptr;
91}
92
93
94void
96 // nothing to update
97}
98
99
100bool
102 return false;
103}
104
105
106bool
108 return false;
109}
110
111
112bool
114 return false;
115}
116
117
118bool
120 return false;
121}
122
123
124bool
126 return false;
127}
128
129
130bool
132 return false;
133}
134
135
136bool
138 return false;
139}
140
141
142bool
144 return false;
145}
146
147
148std::string
150 switch (key) {
151 case SUMO_ATTR_ID:
152 return getParentAdditionals().front()->getID();
153 case SUMO_ATTR_EDGE:
154 return getParentEdges().front()->getID();
155 case SUMO_ATTR_WEIGHT:
156 return toString(myWeight);
157 case GNE_ATTR_PARENT:
158 return getParentAdditionals().at(0)->getID();
159 case GNE_ATTR_TAZCOLOR: {
160 // obtain max and min weight source
161 double maxWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MAX_SOURCE);
162 double minWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MIN_SOURCE);
163 // avoid division between zero
164 if ((maxWeightSource - minWeightSource) == 0) {
165 return "0";
166 } else {
167 // calculate percentage relative to the max and min weight
168 double percentage = (myWeight - minWeightSource) / (maxWeightSource - minWeightSource);
169 // convert percentage to a value between [0-9] (because we have only 10 colors)
170 if (percentage >= 1) {
171 return "9";
172 } else if (percentage < 0) {
173 return "0";
174 } else {
175 return toString((int)(percentage * 10));
176 }
177 }
178 }
179 default:
180 return getCommonAttribute(this, key);
181 }
182}
183
184double
186 switch (key) {
187 case SUMO_ATTR_WEIGHT:
188 return myWeight;
189 default:
190 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
191 }
192}
193
194
199
200
203 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
204}
205
206
207void
208GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
209 // this TAZElement is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
210 if (undoList == nullptr) {
211 setAttribute(key, value);
212 } else {
213 if (value == getAttribute(key)) {
214 return; //avoid needless changes, later logic relies on the fact that attributes have changed
215 }
216 switch (key) {
217 case SUMO_ATTR_ID:
218 case SUMO_ATTR_WEIGHT:
219 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
220 break;
221 default:
222 setCommonAttribute(key, value, undoList);
223 break;
224 }
225 }
226}
227
228
229bool
230GNETAZSourceSink::isValid(SumoXMLAttr key, const std::string& value) {
231 switch (key) {
232 case SUMO_ATTR_ID:
233 return false;
234 case SUMO_ATTR_WEIGHT:
235 return canParse<double>(value) && (parse<double>(value) >= 0);
236 default:
237 return isCommonValid(key, value);
238 }
239}
240
241
242
243bool
245 switch (key) {
246 case SUMO_ATTR_EDGE:
247 return false;
248 default:
249 return true;
250 }
251}
252
253
254std::string
256 return getTagStr();
257}
258
259
260std::string
264
265// ===========================================================================
266// private
267// ===========================================================================
268
269void
270GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value) {
271 switch (key) {
272 case SUMO_ATTR_ID:
273 throw InvalidArgument(getTagStr() + " cannot edit '" + toString(key) + "'");
274 case SUMO_ATTR_WEIGHT:
275 myWeight = parse<double>(value);
276 break;
277 default:
278 setCommonAttribute(this, key, value);
279 break;
280 }
281}
282
283/****************************************************************************/
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)
std::string getCommonAttribute(const Parameterised *parameterised, 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
bool isCommonValid(SumoXMLAttr key, const std::string &value) 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
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
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
bool isValid(SumoXMLAttr key, const std::string &value)
GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNENet *net)
default Constructor
void updateGeometry()
update pre-computed geometry information
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
double getWeight() const
get weight
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
~GNETAZSourceSink()
destructor
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
bool checkDrawFromContour() const
check if draw from contour (green)
const Parameterised::Map & getACParametersMap() const
get parameters map
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
bool checkDrawMoveContour() const
check if draw move contour (red)
GNEHierarchicalElement * getHierarchicalElement()
get GNEHierarchicalElement associated with this AttributeCarrier
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool checkDrawDeleteContourSmall() const
check if draw delete contour small (pink/white)
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
GUIGlObject * getGUIGlObject()
bool checkDrawSelectContour() const
check if draw select contour (blue)
bool checkDrawOverContour() const
check if draw over contour (orange)
double getAttributeDouble(SumoXMLAttr key) const
bool isAttributeEnabled(SumoXMLAttr key) const
void writeTAZSourceSink(OutputDevice &device) const
write TAZ sourceSink
bool checkDrawToContour() const
check if draw from contour (magenta)
Position getAttributePosition(SumoXMLAttr key) const
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.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37