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-2023 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
77bool
79 return true;
80}
81
82
83std::string
85 return "";
86}
87
88
89void
91 // nothing to fix
92}
93
94
95double
99
100
101void
103 // This TAZElement doesn't own a geometry
104}
105
106
109 return getParentAdditionals().at(0)->getPositionInView();
110}
111
112
115 return getParentEdges().front()->getCenteringBoundary();
116}
117
118
119void
121 // nothing to update
122}
123
124
125void
126GNETAZSourceSink::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
127 // geometry of this element cannot be splitted
128}
129
130
131std::string
133 return getParentAdditionals().at(0)->getID();
134}
135
136
139 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
140 // build header
141 buildPopupHeader(ret, app);
142 // build menu command for center button and copy cursor position to clipboard
144 buildPositionCopyEntry(ret, app);
145 // buld menu commands for names
146 GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % name to clipboard", getTagStr()), nullptr, ret, MID_COPY_NAME);
147 GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % typed name to clipboard", getTagStr()), nullptr, ret, MID_COPY_TYPED_NAME);
148 new FXMenuSeparator(ret);
149 // build selection and show parameters menu
152 return ret;
153}
154
155
156void
158 // Currently This TAZElement isn't drawn
159}
160
161
162std::string
164 switch (key) {
165 case SUMO_ATTR_ID:
166 return getMicrosimID();
167 case SUMO_ATTR_EDGE:
168 return getParentEdges().front()->getID();
169 case SUMO_ATTR_WEIGHT:
170 return toString(myDepartWeight);
171 case GNE_ATTR_PARENT:
172 return getParentAdditionals().at(0)->getID();
176 return getParametersStr();
177 case GNE_ATTR_TAZCOLOR: {
178 // obtain max and min weight source
179 double maxWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MAX_SOURCE);
180 double minWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MIN_SOURCE);
181 // avoid division between zero
182 if ((maxWeightSource - minWeightSource) == 0) {
183 return "0";
184 } else {
185 // calculate percentage relative to the max and min weight
186 double percentage = (myDepartWeight - minWeightSource) / (maxWeightSource - minWeightSource);
187 // convert percentage to a value between [0-9] (because we have only 10 colors)
188 if (percentage >= 1) {
189 return "9";
190 } else if (percentage < 0) {
191 return "0";
192 } else {
193 return toString((int)(percentage * 10));
194 }
195 }
196 }
197 default:
198 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
199 }
200}
201
202double
204 switch (key) {
205 case SUMO_ATTR_WEIGHT:
206 return myDepartWeight;
207 default:
208 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
209 }
210}
211
212
217
218
221 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
222}
223
224
225void
226GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
227 // this TAZElement is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
228 if (undoList == nullptr) {
229 setAttribute(key, value);
230 } else {
231 if (value == getAttribute(key)) {
232 return; //avoid needless changes, later logic relies on the fact that attributes have changed
233 }
234 switch (key) {
235 case SUMO_ATTR_ID:
236 case SUMO_ATTR_WEIGHT:
239 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
240 break;
241 default:
242 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
243 }
244 }
245}
246
247
248bool
249GNETAZSourceSink::isValid(SumoXMLAttr key, const std::string& value) {
250 switch (key) {
251 case SUMO_ATTR_ID:
253 (myNet->getAttributeCarriers()->retrieveAdditional(myTagProperty.getTag(), value, false) == nullptr);
254 case SUMO_ATTR_WEIGHT:
255 return canParse<double>(value) && (parse<double>(value) >= 0);
257 return canParse<bool>(value);
259 return areParametersValid(value);
260 default:
261 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
262 }
263}
264
265
266
267bool
269 switch (key) {
270 case SUMO_ATTR_EDGE:
271 return false;
272 default:
273 return true;
274 }
275}
276
277
278std::string
280 return getTagStr();
281}
282
283
284std::string
288
289// ===========================================================================
290// private
291// ===========================================================================
292
293void
294GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value) {
295 switch (key) {
296 case SUMO_ATTR_ID:
297 // update microsimID
298 setMicrosimID(value);
299 break;
300 case SUMO_ATTR_WEIGHT:
301 myDepartWeight = parse<double>(value);
302 break;
304 if (parse<bool>(value)) {
306 } else {
308 }
309 break;
311 setParametersStr(value);
312 break;
313 default:
314 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
315 }
316}
317
318
319void
321 // nothing to move
322}
323
324
325void
326GNETAZSourceSink::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
327 // nothing to move
328}
329
330/****************************************************************************/
@ 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
#define TLF(string,...)
Definition MsgHandler.h:288
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.
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:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
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
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (must be reimplemented in all detector chi...
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.
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
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.
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
The popup menu of a globject.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
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.
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.
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
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