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.dev/sumo
3 // Copyright (C) 2001-2024 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), "", {}, {}, {}, {}, {}, {}),
39 myDepartWeight(0) {
40  // reset default values
42 }
43 
44 
45 GNETAZSourceSink::GNETAZSourceSink(SumoXMLTag sourceSinkTag, GNEAdditional* TAZParent, GNEEdge* edge, double departWeight) :
46  GNEAdditional(TAZParent->getNet(), GLO_TAZ, sourceSinkTag, GUIIconSubSys::getIcon(GUIIcon::MODETAZ), "", {}, {edge}, {}, {TAZParent}, {}, {}),
47 myDepartWeight(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 
65 void
67  // open source/sink tag
68  device.openTag(myTagProperty.getTag());
69  // write source/sink attributes
70  device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
72  // close tag
73  device.closeTag();
74 }
75 
76 
77 bool
79  return true;
80 }
81 
82 
83 std::string
85  return "";
86 }
87 
88 
89 void
91  // nothing to fix
92 }
93 
94 
95 bool
97  return false;
98 }
99 
100 
101 double
103  return myDepartWeight;
104 }
105 
106 
107 void
109  // This TAZElement doesn't own a geometry
110 }
111 
112 
113 Position
115  return getParentAdditionals().at(0)->getPositionInView();
116 }
117 
118 
119 Boundary
121  return getParentEdges().front()->getCenteringBoundary();
122 }
123 
124 
125 void
126 GNETAZSourceSink::updateCenteringBoundary(const bool /*updateGrid*/) {
127  // nothing to update
128 }
129 
130 
131 void
132 GNETAZSourceSink::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
133  // geometry of this element cannot be splitted
134 }
135 
136 
137 std::string
139  return getParentAdditionals().at(0)->getID();
140 }
141 
142 
145  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
146  // build header
147  buildPopupHeader(ret, app);
148  // build menu command for center button and copy cursor position to clipboard
150  buildPositionCopyEntry(ret, app);
151  // build menu commands for names
152  GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % name to clipboard", getTagStr()), nullptr, ret, MID_COPY_NAME);
153  GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % typed name to clipboard", getTagStr()), nullptr, ret, MID_COPY_TYPED_NAME);
154  new FXMenuSeparator(ret);
155  // build selection and show parameters menu
158  return ret;
159 }
160 
161 
162 void
164  // Currently This TAZElement isn't drawn
165 }
166 
167 
168 std::string
170  switch (key) {
171  case SUMO_ATTR_ID:
172  return getMicrosimID();
173  case SUMO_ATTR_EDGE:
174  return getParentEdges().front()->getID();
175  case SUMO_ATTR_WEIGHT:
176  return toString(myDepartWeight);
177  case GNE_ATTR_PARENT:
178  return getParentAdditionals().at(0)->getID();
179  case GNE_ATTR_SELECTED:
181  case GNE_ATTR_PARAMETERS:
182  return getParametersStr();
183  case GNE_ATTR_TAZCOLOR: {
184  // obtain max and min weight source
185  double maxWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MAX_SOURCE);
186  double minWeightSource = getParentAdditionals().at(0)->getAttributeDouble(GNE_ATTR_MIN_SOURCE);
187  // avoid division between zero
188  if ((maxWeightSource - minWeightSource) == 0) {
189  return "0";
190  } else {
191  // calculate percentage relative to the max and min weight
192  double percentage = (myDepartWeight - minWeightSource) / (maxWeightSource - minWeightSource);
193  // convert percentage to a value between [0-9] (because we have only 10 colors)
194  if (percentage >= 1) {
195  return "9";
196  } else if (percentage < 0) {
197  return "0";
198  } else {
199  return toString((int)(percentage * 10));
200  }
201  }
202  }
203  default:
204  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
205  }
206 }
207 
208 double
210  switch (key) {
211  case SUMO_ATTR_WEIGHT:
212  return myDepartWeight;
213  default:
214  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
215  }
216 }
217 
218 
219 const Parameterised::Map&
221  return PARAMETERS_EMPTY;
222 }
223 
224 
225 Position
227  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
228 }
229 
230 
231 void
232 GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
233  // this TAZElement is the only that can edit a variable directly, see GNEAdditionalHandler::buildTAZEdge(...)
234  if (undoList == nullptr) {
235  setAttribute(key, value);
236  } else {
237  if (value == getAttribute(key)) {
238  return; //avoid needless changes, later logic relies on the fact that attributes have changed
239  }
240  switch (key) {
241  case SUMO_ATTR_ID:
242  case SUMO_ATTR_WEIGHT:
243  case GNE_ATTR_SELECTED:
244  case GNE_ATTR_PARAMETERS:
245  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
246  break;
247  default:
248  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
249  }
250  }
251 }
252 
253 
254 bool
255 GNETAZSourceSink::isValid(SumoXMLAttr key, const std::string& value) {
256  switch (key) {
257  case SUMO_ATTR_ID:
258  return isValidAdditionalID(value);
259  case SUMO_ATTR_WEIGHT:
260  return canParse<double>(value) && (parse<double>(value) >= 0);
261  case GNE_ATTR_SELECTED:
262  return canParse<bool>(value);
263  case GNE_ATTR_PARAMETERS:
264  return areParametersValid(value);
265  default:
266  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
267  }
268 }
269 
270 
271 
272 bool
274  switch (key) {
275  case SUMO_ATTR_EDGE:
276  return false;
277  default:
278  return true;
279  }
280 }
281 
282 
283 std::string
285  return getTagStr();
286 }
287 
288 
289 std::string
291  return getTagStr() + ": " + getAttribute(SUMO_ATTR_WEIGHT);
292 }
293 
294 // ===========================================================================
295 // private
296 // ===========================================================================
297 
298 void
299 GNETAZSourceSink::setAttribute(SumoXMLAttr key, const std::string& value) {
300  switch (key) {
301  case SUMO_ATTR_ID:
302  // update microsimID
303  setAdditionalID(value);
304  break;
305  case SUMO_ATTR_WEIGHT:
306  myDepartWeight = parse<double>(value);
307  break;
308  case GNE_ATTR_SELECTED:
309  if (parse<bool>(value)) {
311  } else {
313  }
314  break;
315  case GNE_ATTR_PARAMETERS:
316  setParametersStr(value);
317  break;
318  default:
319  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
320  }
321 }
322 
323 
324 void
326  // nothing to move
327 }
328 
329 
330 void
331 GNETAZSourceSink::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
332  // nothing to move
333 }
334 
335 /****************************************************************************/
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:453
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:451
@ 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:317
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:49
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
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
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 std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
move operation
move result
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2022
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 written into XML (must be reimplemented in all detector ch...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
bool checkDrawMoveContour() const
check if draw move contour (red)
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 buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:538
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel, const bool disable=false)
build menu command
Definition: GUIDesigns.cpp:42
The popup menu of a globject.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
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.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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