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-2022 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>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
29
30#include "GNETAZSourceSink.h"
31
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
38 GNEAdditional(net, GLO_TAZ, tag, GUIIconSubSys::getIcon(GUIIcon::MODETAZ), "", {}, {}, {}, {}, {}, {}),
39myDepartWeight(0) {
40 // reset default values
42}
43
44
45GNETAZSourceSink::GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional* TAZParent, GNEEdge* edge, double departWeight) :
46 GNEAdditional(TAZParent->getNet(), GLO_TAZ, sourceSinkTag, GUIIconSubSys::getIcon(GUIIcon::MODETAZ), "", {}, {edge}, {}, {TAZParent}, {}, {}),
47myDepartWeight(departWeight) {
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
60 // nothing to move
61 return nullptr;
62}
63
64
65void
67 // open source/sink tag
69 // write source/sink attributes
70 device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
72 // close tag
73 device.closeTag();
74}
75
76
77double
79 return myDepartWeight;
80}
81
82
83void
85 // This TAZElement doesn't own a geometry
86}
87
88
91 return getParentAdditionals().at(0)->getPositionInView();
92}
93
94
95double
97 return 1;
98}
99
100
103 return getParentEdges().front()->getCenteringBoundary();
104}
105
106
107void
109 // nothing to update
110}
111
112
113void
114GNETAZSourceSink::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
115 // geometry of this element cannot be splitted
116}
117
118
119std::string
121 return getParentAdditionals().at(0)->getID();
122}
123
124
127 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
128 // build header
129 buildPopupHeader(ret, app);
130 // build menu command for center button and copy cursor position to clipboard
132 buildPositionCopyEntry(ret, app);
133 // buld menu commands for names
134 GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " name to clipboard", nullptr, ret, MID_COPY_NAME);
135 GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
136 new FXMenuSeparator(ret);
137 // build selection and show parameters menu
140 return ret;
141}
142
143
144void
146 // Currently This TAZElement isn't drawn
147}
148
149
150std::string
152 switch (key) {
153 case SUMO_ATTR_ID:
154 return getMicrosimID();
155 case SUMO_ATTR_EDGE:
156 return getParentEdges().front()->getID();
157 case SUMO_ATTR_WEIGHT:
158 return toString(myDepartWeight);
159 case GNE_ATTR_PARENT:
160 return getParentAdditionals().at(0)->getID();
164 return getParametersStr();
165 case GNE_ATTR_TAZCOLOR: {
166 // obtain max and min weight source
167 double maxWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MAX_SOURCE);
168 double minWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MIN_SOURCE);
169 // avoid division between zero
170 if ((maxWeightSource - minWeightSource) == 0) {
171 return "0";
172 } else {
173 // calculate percentage relative to the max and min weight
174 double percentage = (myDepartWeight - minWeightSource) / (maxWeightSource - minWeightSource);
175 // convert percentage to a value between [0-9] (because we have only 10 colors)
176 if (percentage >= 1) {
177 return "9";
178 } else if (percentage < 0) {
179 return "0";
180 } else {
181 return toString((int)(percentage * 10));
182 }
183 }
184 }
185 default:
186 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
187 }
188}
189
190double
192 switch (key) {
193 case SUMO_ATTR_WEIGHT:
194 return myDepartWeight;
195 default:
196 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
197 }
198}
199
200
203 return PARAMETERS_EMPTY;
204}
205
206
209 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
210}
211
212
213void
214GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
215 // this TAZElement is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
216 if (undoList == nullptr) {
217 setAttribute(key, value);
218 } else {
219 if (value == getAttribute(key)) {
220 return; //avoid needless changes, later logic relies on the fact that attributes have changed
221 }
222 switch (key) {
223 case SUMO_ATTR_ID:
224 case SUMO_ATTR_WEIGHT:
227 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
228 break;
229 default:
230 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
231 }
232 }
233}
234
235
236bool
237GNETAZSourceSink::isValid(SumoXMLAttr key, const std::string& value) {
238 switch (key) {
239 case SUMO_ATTR_ID:
241 (myNet->getAttributeCarriers()->retrieveAdditional(myTagProperty.getTag(), value, false) == nullptr);
242 case SUMO_ATTR_WEIGHT:
243 return canParse<double>(value) && (parse<double>(value) >= 0);
245 return canParse<bool>(value);
247 return areParametersValid(value);
248 default:
249 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
250 }
251}
252
253
254
255bool
257 switch (key) {
258 case SUMO_ATTR_EDGE:
259 return false;
260 default:
261 return true;
262 }
263}
264
265
266std::string
268 return getTagStr();
269}
270
271
272std::string
274 return getTagStr() + ": " + getAttribute(SUMO_ATTR_WEIGHT);
275}
276
277// ===========================================================================
278// private
279// ===========================================================================
280
281void
282GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value) {
283 switch (key) {
284 case SUMO_ATTR_ID:
285 // update microsimID
286 setMicrosimID(value);
287 break;
288 case SUMO_ATTR_WEIGHT:
289 myDepartWeight = parse<double>(value);
290 break;
292 if (parse<bool>(value)) {
294 } else {
296 }
297 break;
299 setParametersStr(value);
300 break;
301 default:
302 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
303 }
304}
305
306
307void
309 // nothing to move
310}
311
312
313void
314GNETAZSourceSink::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
315 // nothing to move
316}
317
318/****************************************************************************/
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:450
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:448
@ GLO_TAZ
Traffic Assignment Zones (TAZs)
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
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
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ 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
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
move operation
move result
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
void updateGeometry()
update pre-computed geometry information
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
double getDepartWeight() const
get depart weight
~GNETAZSourceSink()
destructor
GNEMoveOperation * getMoveOperation()
get move operation
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
double myDepartWeight
depart Weight
const Parameterised::Map & getACParametersMap() const
get parameters map
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
GNETAZSourceSink(SumoXMLTag tag, GNENet *net)
default Constructor
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
double getAttributeDouble(SumoXMLAttr key) const
bool isAttributeEnabled(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of additional in view.
Position getAttributePosition(SumoXMLAttr key) const
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:474
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:42
The popup menu of a globject.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
static bool isValidAdditionalID(const std::string &value)
whether the given string is a valid id for an additional object