Eclipse SUMO - Simulation of Urban MObility
GNERouteProbe.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 <utils/gui/div/GLHelper.h>
23 #include <netedit/GNEViewNet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNENet.h>
29 
30 #include "GNERouteProbe.h"
31 
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
39  GUIIconSubSys::getIcon(GUIIcon::ROUTEPROBE), "", {}, {}, {}, {}, {}, {}),
40  myPeriod(SUMOTime_MAX_PERIOD),
41 myBegin(0) {
42  // reset default values
43  resetDefaultValues();
44  // update centering boundary without updating grid
45  updateCenteringBoundary(false);
46 }
47 
48 
49 GNERouteProbe::GNERouteProbe(const std::string& id, GNENet* net, GNEEdge* edge, const SUMOTime period, const std::string& name,
50  const std::string& filename, SUMOTime begin, const Parameterised::Map& parameters) :
52  GUIIconSubSys::getIcon(GUIIcon::ROUTEPROBE), name, {}, {edge}, {}, {}, {}, {}),
53 Parameterised(parameters),
54 myPeriod(period),
55 myFilename(filename),
56 myBegin(begin) {
57  // update centering boundary without updating grid
58  updateCenteringBoundary(false);
59 }
60 
61 
63 }
64 
65 
66 void
68  // open tag
70  // write parameters
71  device.writeAttr(SUMO_ATTR_ID, getID());
73  if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
75  }
76  device.writeAttr(SUMO_ATTR_EDGE, getParentEdges().front()->getID());
77  if (!myAdditionalName.empty()) {
79  }
80  if (!myFilename.empty()) {
82  }
83  // write parameters (Always after children to avoid problems with additionals.xsd)
84  writeParams(device);
85  device.closeTag();
86 }
87 
88 
89 bool
91  return true;
92 }
93 
94 
95 std::string
97  return "";
98 }
99 
100 
101 void
103  // nothing to fix
104 }
105 
106 
107 void
109  // calculate perpendicular line
111 }
112 
113 
114 Position
117 }
118 
119 
120 void
121 GNERouteProbe::updateCenteringBoundary(const bool /*pdateGrid*/) {
122  // nothing to do
123 }
124 
125 
126 void
127 GNERouteProbe::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
128  // geometry of this element cannot be splitted
129 }
130 
131 
132 bool
134  return false;
135 }
136 
137 
140  // routeprobes cannot be moved
141  return nullptr;
142 }
143 
144 
145 std::string
147  return getParentEdges().front()->getID();
148 }
149 
150 
151 void
153  // first check if additional has to be drawn
155  // Obtain exaggeration of the draw
156  const double routeProbeExaggeration = getExaggeration(s);
157  // declare colors
158  RGBColor routeProbeColor, centralLineColor;
159  // set colors
160  if (drawUsingSelectColor()) {
161  routeProbeColor = s.colorSettings.selectedAdditionalColor;
162  centralLineColor = routeProbeColor.changedBrightness(-32);
163  } else {
164  routeProbeColor = s.additionalSettings.routeProbeColor;
165  centralLineColor = RGBColor::WHITE;
166  }
167  // get detail level
168  const auto d = s.getDetailLevel(routeProbeExaggeration);
169  // draw geometry only if we'rent in drawForObjectUnderCursor mode
171  // draw parent and child lines
173  // Add layer matrix matrix
175  // translate to front
177  // set base color
178  GLHelper::setColor(routeProbeColor);
179  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
180  GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.3 * routeProbeExaggeration);
181  // move to front
182  glTranslated(0, 0, .1);
183  // set central color
184  GLHelper::setColor(centralLineColor);
185  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
186  GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.05 * routeProbeExaggeration);
187  // move to icon position and front
188  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
189  // rotate over lane
191  // Draw icon depending of level of detail
193  // set color
194  glColor3d(1, 1, 1);
195  // rotate texture
196  glRotated(90, 0, 0, 1);
197  // draw texture
198  if (drawUsingSelectColor()) {
200  } else {
202  }
203  } else {
204  // set route probe color
205  GLHelper::setColor(routeProbeColor);
206  // just drawn a box
208  }
209  // pop layer matrix
211  // draw additional name
213  // draw dotted contour
216  }
217  // calculate contour and draw dotted geometry
219  s.additionalSettings.routeProbeSize, 0, 0, 0, routeProbeExaggeration);
220  mySymbolBaseContour.calculateContourExtrudedShape(s, d, this, myAdditionalGeometry.getShape(), 0.3, routeProbeExaggeration, true, true, 0);
221  }
222 }
223 
224 
225 std::string
227  switch (key) {
228  case SUMO_ATTR_ID:
229  return getMicrosimID();
230  case SUMO_ATTR_EDGE:
231  return getParentEdges().front()->getID();
232  case SUMO_ATTR_NAME:
233  return myAdditionalName;
234  case SUMO_ATTR_FILE:
235  return myFilename;
236  case SUMO_ATTR_PERIOD:
237  case SUMO_ATTR_FREQUENCY:
238  if (myPeriod == SUMOTime_MAX_PERIOD) {
239  return "";
240  } else {
241  return time2string(myPeriod);
242  }
243  case SUMO_ATTR_BEGIN:
244  return time2string(myBegin);
245  case GNE_ATTR_SELECTED:
247  case GNE_ATTR_PARAMETERS:
248  return getParametersStr();
249  default:
250  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
251  }
252 }
253 
254 
255 double
257  switch (key) {
258  case SUMO_ATTR_BEGIN:
259  return STEPS2TIME(myBegin);
260  default:
261  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
262  }
263 }
264 
265 
266 const Parameterised::Map&
268  return getParametersMap();
269 }
270 
271 
272 void
273 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
274  if (value == getAttribute(key)) {
275  return; //avoid needless changes, later logic relies on the fact that attributes have changed
276  }
277  switch (key) {
278  case SUMO_ATTR_ID:
279  case SUMO_ATTR_EDGE:
280  case SUMO_ATTR_NAME:
281  case SUMO_ATTR_FILE:
282  case SUMO_ATTR_PERIOD:
283  case SUMO_ATTR_FREQUENCY:
284  case SUMO_ATTR_BEGIN:
285  case GNE_ATTR_SELECTED:
286  case GNE_ATTR_PARAMETERS:
287  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
288  break;
289  default:
290  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
291  }
292 }
293 
294 
295 std::string
297  return getTagStr();
298 }
299 
300 
301 std::string
303  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN);
304 }
305 
306 // ===========================================================================
307 // private
308 // ===========================================================================
309 
310 bool
311 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
312  switch (key) {
313  case SUMO_ATTR_ID:
314  return isValidAdditionalID(value);
315  case SUMO_ATTR_EDGE:
316  if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
317  return true;
318  } else {
319  return false;
320  }
321  case SUMO_ATTR_NAME:
323  case SUMO_ATTR_FILE:
325  case SUMO_ATTR_PERIOD:
326  case SUMO_ATTR_FREQUENCY:
327  if (value.empty()) {
328  return true;
329  } else {
330  return (canParse<double>(value) && (parse<double>(value) >= 0));
331  }
332  case SUMO_ATTR_BEGIN:
333  return canParse<SUMOTime>(value);
334  case GNE_ATTR_SELECTED:
335  return canParse<bool>(value);
336  case GNE_ATTR_PARAMETERS:
337  return areParametersValid(value);
338  default:
339  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
340  }
341 }
342 
343 
344 void
345 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
346  switch (key) {
347  case SUMO_ATTR_ID:
348  // update microsimID
349  setAdditionalID(value);
350  break;
351  case SUMO_ATTR_EDGE:
353  break;
354  case SUMO_ATTR_NAME:
355  myAdditionalName = value;
356  break;
357  case SUMO_ATTR_FILE:
358  myFilename = value;
359  break;
360  case SUMO_ATTR_PERIOD:
361  case SUMO_ATTR_FREQUENCY:
362  if (value.empty()) {
364  } else {
365  myPeriod = string2time(value);
366  }
367  break;
368  case SUMO_ATTR_BEGIN:
369  myBegin = parse<SUMOTime>(value);
370  break;
371  case GNE_ATTR_SELECTED:
372  if (parse<bool>(value)) {
374  } else {
376  }
377  break;
378  case GNE_ATTR_PARAMETERS:
379  setParametersStr(value);
380  break;
381  default:
382  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
383  }
384 }
385 
386 
387 void
389  // nothing to do
390 }
391 
392 
393 void
394 GNERouteProbe::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
395  // nothing to do
396 }
397 
398 
399 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
@ GLO_ROUTEPROBE
a RouteProbe
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ ROUTEPROBE_SELECTED
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#define STEPS2TIME(x)
Definition: SUMOTime.h:55
#define SUMOTime_MAX_PERIOD
Definition: SUMOTime.h:36
@ SUMO_TAG_ROUTEPROBE
a routeprobe detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_FILE
@ SUMO_ATTR_EDGE
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_NAME
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_FREQUENCY
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:654
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:295
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
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
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentEdges(const std::string &value)
replace additional parent edges
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void calculatePerpendicularLine(const double endLaneposition)
calculate perpendicular line between lane parents
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
const GUIGeometry & getAdditionalGeometry() const
obtain additional geometry
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
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
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourExtrudedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset) const
calculate contour extruded (used in elements formed by a central shape)
Definition: GNEContour.cpp:88
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double scale) const
calculate contour (for rectangled elements)
Definition: GNEContour.cpp:103
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:265
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
move operation
move result
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
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:123
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2136
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
SUMOTime myBegin
begin of rerouter
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
Position getPositionInView() const
Returns position of additional in view.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getParentName() const
Returns the name of the parent object.
bool checkDrawMoveContour() const
check if draw move contour (red)
std::string myFilename
filename of RouteProbe
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void updateGeometry()
update pre-computed geometry information
SUMOTime myPeriod
RouteProbe period.
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
GNEMoveOperation * getMoveOperation()
get move operation
const Parameterised::Map & getACParametersMap() const
get parameters map
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
~GNERouteProbe()
Destructor.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
GNEContour mySymbolBaseContour
symbol base contour
double getAttributeDouble(SumoXMLAttr key) const
GNERouteProbe(GNENet *net)
Constructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:747
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Stores the information about how to visualize structures.
bool checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
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.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
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"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
static const RGBColor WHITE
Definition: RGBColor.h:192
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:200
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
bool showAdditionals() const
check if additionals has to be drawn
static const double routeProbeSize
RouteProbe size.
static const RGBColor connectionColor
connection color
static const RGBColor routeProbeColor
color for route probes
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double segmentWidthSmall
width of small dotted contour segments
static const double segmentWidth
width of dotted contour segments