Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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
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),
41myBegin(0) {
42 // reset default values
43 resetDefaultValues();
44 // update centering boundary without updating grid
45 updateCenteringBoundary(false);
46}
47
48
49GNERouteProbe::GNERouteProbe(const std::string& id, GNENet* net, GNEEdge* edge, const SUMOTime period, const std::string& name,
50 const std::string& filename, SUMOTime begin, const std::vector<std::string>& vehicleTypes,
51 const Parameterised::Map& parameters) :
53 GUIIconSubSys::getIcon(GUIIcon::ROUTEPROBE), name, {}, {edge}, {}, {}, {}, {}),
54Parameterised(parameters),
55myPeriod(period),
56myFilename(filename),
57myBegin(begin),
58myVehicleTypes(vehicleTypes) {
59 // update centering boundary without updating grid
60 updateCenteringBoundary(false);
61}
62
63
66
67
68void
70 // open tag
72 // write parameters
73 device.writeAttr(SUMO_ATTR_ID, getID());
75 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
77 }
78 device.writeAttr(SUMO_ATTR_EDGE, getParentEdges().front()->getID());
79 if (!myFilename.empty()) {
81 }
82 if (!myAdditionalName.empty()) {
84 }
85 if (!myVehicleTypes.empty()) {
87 }
88 // write parameters (Always after children to avoid problems with additionals.xsd)
89 writeParams(device);
90 device.closeTag();
91}
92
93
94bool
96 return true;
97}
98
99
100std::string
102 return "";
103}
104
105
106void
108 // nothing to fix
109}
110
111
112void
114 // calculate perpendicular line
116}
117
118
123
124
125void
126GNERouteProbe::updateCenteringBoundary(const bool /*pdateGrid*/) {
127 // nothing to do
128}
129
130
131void
132GNERouteProbe::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
133 // geometry of this element cannot be splitted
134}
135
136
137bool
139 return false;
140}
141
142
145 // routeprobes cannot be moved
146 return nullptr;
147}
148
149
150std::string
152 return getParentEdges().front()->getID();
153}
154
155
156void
158 // first check if additional has to be drawn
160 // Obtain exaggeration of the draw
161 const double routeProbeExaggeration = getExaggeration(s);
162 // declare colors
163 RGBColor routeProbeColor, centralLineColor;
164 // set colors
165 if (drawUsingSelectColor()) {
166 routeProbeColor = s.colorSettings.selectedAdditionalColor;
167 centralLineColor = routeProbeColor.changedBrightness(-32);
168 } else {
169 routeProbeColor = s.additionalSettings.routeProbeColor;
170 centralLineColor = RGBColor::WHITE;
171 }
172 // get detail level
173 const auto d = s.getDetailLevel(routeProbeExaggeration);
174 // draw geometry only if we'rent in drawForObjectUnderCursor mode
176 // draw parent and child lines
178 // Add layer matrix matrix
180 // translate to front
182 // set base color
183 GLHelper::setColor(routeProbeColor);
184 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
185 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.3 * routeProbeExaggeration);
186 // move to front
187 glTranslated(0, 0, .1);
188 // set central color
189 GLHelper::setColor(centralLineColor);
190 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
191 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.05 * routeProbeExaggeration);
192 // move to icon position and front
193 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
194 // rotate over lane
196 // Draw icon depending of level of detail
198 // set color
199 glColor3d(1, 1, 1);
200 // rotate texture
201 glRotated(90, 0, 0, 1);
202 // draw texture
203 if (drawUsingSelectColor()) {
205 } else {
207 }
208 } else {
209 // set route probe color
210 GLHelper::setColor(routeProbeColor);
211 // just drawn a box
213 }
214 // pop layer matrix
216 // draw additional name
218 // draw dotted contour
221 }
222 // calculate contour and draw dotted geometry
224 s.additionalSettings.routeProbeSize, getType(), 0, 0, 0, routeProbeExaggeration, getParentEdges().front());
225 mySymbolBaseContour.calculateContourExtrudedShape(s, d, this, myAdditionalGeometry.getShape(), getType(), 0.3, routeProbeExaggeration,
226 true, true, 0, nullptr, getParentEdges().front());
227 }
228}
229
230
231std::string
233 switch (key) {
234 case SUMO_ATTR_ID:
235 return getMicrosimID();
236 case SUMO_ATTR_EDGE:
237 return getParentEdges().front()->getID();
238 case SUMO_ATTR_NAME:
239 return myAdditionalName;
240 case SUMO_ATTR_FILE:
241 return myFilename;
242 case SUMO_ATTR_PERIOD:
245 return "";
246 } else {
247 return time2string(myPeriod);
248 }
249 case SUMO_ATTR_BEGIN:
250 return time2string(myBegin);
251 case SUMO_ATTR_VTYPES:
252 return toString(myVehicleTypes);
254 return getParametersStr();
255 default:
256 return getCommonAttribute(key);
257 }
258}
259
260
261double
263 switch (key) {
264 case SUMO_ATTR_BEGIN:
265 return STEPS2TIME(myBegin);
266 default:
267 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
268 }
269}
270
271
276
277
278void
279GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
280 if (value == getAttribute(key)) {
281 return; //avoid needless changes, later logic relies on the fact that attributes have changed
282 }
283 switch (key) {
284 case SUMO_ATTR_ID:
285 case SUMO_ATTR_EDGE:
286 case SUMO_ATTR_NAME:
287 case SUMO_ATTR_FILE:
288 case SUMO_ATTR_PERIOD:
290 case SUMO_ATTR_BEGIN:
291 case SUMO_ATTR_VTYPES:
293 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
294 break;
295 default:
296 setCommonAttribute(key, value, undoList);
297 break;
298 }
299}
300
301
302std::string
304 return getTagStr();
305}
306
307
308std::string
312
313// ===========================================================================
314// private
315// ===========================================================================
316
317bool
318GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
319 switch (key) {
320 case SUMO_ATTR_ID:
321 return isValidAdditionalID(value);
322 case SUMO_ATTR_EDGE:
323 if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
324 return true;
325 } else {
326 return false;
327 }
328 case SUMO_ATTR_NAME:
330 case SUMO_ATTR_FILE:
332 case SUMO_ATTR_PERIOD:
334 if (value.empty()) {
335 return true;
336 } else {
337 return (canParse<double>(value) && (parse<double>(value) >= 0));
338 }
339 case SUMO_ATTR_BEGIN:
340 return canParse<SUMOTime>(value);
341 case SUMO_ATTR_VTYPES:
342 if (value.empty()) {
343 return true;
344 } else {
346 }
348 return areParametersValid(value);
349 default:
350 return isCommonValid(key, value);
351 }
352}
353
354
355void
356GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
357 switch (key) {
358 case SUMO_ATTR_ID:
359 // update microsimID
360 setAdditionalID(value);
361 break;
362 case SUMO_ATTR_EDGE:
364 break;
365 case SUMO_ATTR_NAME:
366 myAdditionalName = value;
367 break;
368 case SUMO_ATTR_FILE:
369 myFilename = value;
370 break;
371 case SUMO_ATTR_PERIOD:
373 if (value.empty()) {
375 } else {
376 myPeriod = string2time(value);
377 }
378 break;
379 case SUMO_ATTR_BEGIN:
380 myBegin = parse<SUMOTime>(value);
381 break;
382 case SUMO_ATTR_VTYPES:
383 myVehicleTypes = parse<std::vector<std::string> >(value);
384 break;
386 setParametersStr(value);
387 break;
388 default:
389 setCommonAttribute(key, value);
390 break;
391 }
392}
393
394
395void
397 // nothing to do
398}
399
400
401void
402GNERouteProbe::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
403 // nothing to do
404}
405
406
407/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ 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
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_VTYPES
@ 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:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:296
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
An Element which don't belong to GNENet but has influence in the simulation.
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
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 drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
bool isCommonValid(SumoXMLAttr key, const std::string &value)
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
GNENet * myNet
pointer to net
std::string getCommonAttribute(SumoXMLAttr key) const
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 layer, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset, const GNESegment *segment, const GUIGlObject *boundaryParent, const bool addToSelectedObjects=true) const
calculate contour extruded (used in elements formed by a central shape)
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double layer, const double offsetX, const double offsetY, const double rot, const double scale, const GUIGlObject *boundaryParent) const
calculate contour (for rectangled elements)
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:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
SUMOTime myBegin
begin of rerouter
std::vector< std::string > myVehicleTypes
vehicle types
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
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.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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.
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.
An upper class for objects with additional parameters.
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"
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 isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren't allowed)
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