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-2026 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
22
24#include <netedit/GNENet.h>
27
28#include "GNERouteProbe.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
37
38
39GNERouteProbe::GNERouteProbe(const std::string& id, GNENet* net, FileBucket* fileBucket, GNEEdge* edge, const SUMOTime period, const std::string& name,
40 const std::string& outputFilename, SUMOTime begin, const std::vector<std::string>& vehicleTypes,
41 const Parameterised::Map& parameters) :
42 GNEAdditional(id, net, SUMO_TAG_ROUTEPROBE, fileBucket, name),
43 Parameterised(parameters),
44 myPeriod(period),
45 myOutputFilename(outputFilename),
46 myBegin(begin),
47 myVehicleTypes(vehicleTypes) {
48 // set parents
49 setParent<GNEEdge*>(edge);
50 // update centering boundary without updating grid
52 // set default output filename if not set
53 if (myOutputFilename.empty()) {
54 myOutputFilename = getID() + ".xml";
55 }
56}
57
58
61
62
65 return nullptr;
66}
67
68
71 return this;
72}
73
74
75const Parameterised*
77 return this;
78}
79
80
81void
83 // open tag
85 // write common additional attributes
87 // write specific attributes
89 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
91 }
92 device.writeAttr(SUMO_ATTR_EDGE, getParentEdges().front()->getID());
93 if (!myOutputFilename.empty()) {
95 }
96 if (!myVehicleTypes.empty()) {
98 }
99 // write parameters (Always after children to avoid problems with additionals.xsd)
100 XMLHelpers::writeParams(device, *this);
101 device.closeTag();
102}
103
104
105bool
107 return true;
108}
109
110
111std::string
113 return "";
114}
115
116
117void
119 // nothing to fix
120}
121
122
123void
125 // calculate perpendicular line
127}
128
129
134
135
136void
137GNERouteProbe::updateCenteringBoundary(const bool /*pdateGrid*/) {
138 // nothing to do
139}
140
141
142void
143GNERouteProbe::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
144 // geometry of this element cannot be splitted
145}
146
147
148bool
150 return false;
151}
152
153
154std::string
156 return getParentEdges().front()->getID();
157}
158
159
160void
162 // first check if additional has to be drawn
164 // Obtain exaggeration of the draw
165 const double routeProbeExaggeration = getExaggeration(s);
166 // declare colors
167 RGBColor routeProbeColor, centralLineColor;
168 // set colors
169 if (drawUsingSelectColor()) {
170 routeProbeColor = s.colorSettings.selectedAdditionalColor;
171 centralLineColor = routeProbeColor.changedBrightness(-32);
172 } else {
173 routeProbeColor = s.additionalSettings.routeProbeColor;
174 centralLineColor = RGBColor::WHITE;
175 }
176 // get detail level
177 const auto d = s.getDetailLevel(routeProbeExaggeration);
178 // draw geometry only if we'rent in drawForObjectUnderCursor mode
180 // draw parent and child lines
182 // Add layer matrix matrix
184 // translate to front
186 // set base color
187 GLHelper::setColor(routeProbeColor);
188 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
189 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.3 * routeProbeExaggeration);
190 // move to front
191 glTranslated(0, 0, .1);
192 // set central color
193 GLHelper::setColor(centralLineColor);
194 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
195 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.05 * routeProbeExaggeration);
196 // move to icon position and front
197 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
198 // rotate over lane
200 // Draw icon depending of level of detail
202 // set color
203 glColor3d(1, 1, 1);
204 // rotate texture
205 glRotated(90, 0, 0, 1);
206 // draw texture
207 if (drawUsingSelectColor()) {
209 } else {
211 }
212 } else {
213 // set route probe color
214 GLHelper::setColor(routeProbeColor);
215 // just drawn a box
217 }
218 // pop layer matrix
220 // draw additional name
222 // draw dotted contour
225 }
226 // calculate contour and draw dotted geometry
228 s.additionalSettings.routeProbeSize, getType(), 0, 0, (myAdditionalGeometry.getShapeRotations().front() * -1), routeProbeExaggeration, getParentEdges().front());
229 mySymbolBaseContour.calculateContourExtrudedShape(s, d, this, myAdditionalGeometry.getShape(), getType(), 0.3, routeProbeExaggeration,
230 true, true, 0, nullptr, getParentEdges().front());
231 }
232}
233
234
235std::string
237 switch (key) {
238 case SUMO_ATTR_ID:
239 return getMicrosimID();
240 case SUMO_ATTR_EDGE:
241 return getParentEdges().front()->getID();
242 case SUMO_ATTR_NAME:
243 return myAdditionalName;
244 case SUMO_ATTR_FILE:
245 return myOutputFilename;
246 case SUMO_ATTR_PERIOD:
249 return "";
250 } else {
251 return time2string(myPeriod);
252 }
253 case SUMO_ATTR_BEGIN:
254 return time2string(myBegin);
255 case SUMO_ATTR_VTYPES:
256 return toString(myVehicleTypes);
257 default:
258 return getCommonAttribute(key);
259 }
260}
261
262
263double
265 switch (key) {
266 case SUMO_ATTR_BEGIN:
267 return STEPS2TIME(myBegin);
268 default:
269 return getCommonAttributeDouble(key);
270 }
271}
272
273
278
279
284
285
286void
287GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
288 if (value == getAttribute(key)) {
289 return; //avoid needless changes, later logic relies on the fact that attributes have changed
290 }
291 switch (key) {
292 case SUMO_ATTR_ID:
293 case SUMO_ATTR_EDGE:
294 case SUMO_ATTR_NAME:
295 case SUMO_ATTR_FILE:
296 case SUMO_ATTR_PERIOD:
298 case SUMO_ATTR_BEGIN:
299 case SUMO_ATTR_VTYPES:
300 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
301 break;
302 default:
303 setCommonAttribute(key, value, undoList);
304 break;
305 }
306}
307
308
309std::string
311 return getTagStr();
312}
313
314
315std::string
319
320// ===========================================================================
321// private
322// ===========================================================================
323
324bool
325GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
326 switch (key) {
327 case SUMO_ATTR_ID:
328 return isValidAdditionalID(value);
329 case SUMO_ATTR_EDGE:
330 if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
331 return true;
332 } else {
333 return false;
334 }
335 case SUMO_ATTR_NAME:
336 return StringUtils::isValidAttribute(value);
337 case SUMO_ATTR_FILE:
338 return StringUtils::isValidFilename(value);
339 case SUMO_ATTR_PERIOD:
341 if (value.empty()) {
342 return true;
343 } else {
344 return (canParse<double>(value) && (parse<double>(value) >= 0));
345 }
346 case SUMO_ATTR_BEGIN:
347 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0);
348 case SUMO_ATTR_VTYPES:
349 if (value.empty()) {
350 return true;
351 } else {
353 }
354 default:
355 return isCommonAttributeValid(key, value);
356 }
357}
358
359
360void
361GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
362 switch (key) {
363 case SUMO_ATTR_ID:
364 // update microsimID
365 setAdditionalID(value);
366 break;
367 case SUMO_ATTR_EDGE:
369 break;
370 case SUMO_ATTR_NAME:
371 myAdditionalName = value;
372 break;
373 case SUMO_ATTR_FILE:
374 myOutputFilename = value;
375 break;
376 case SUMO_ATTR_PERIOD:
378 if (value.empty()) {
380 } else {
381 myPeriod = string2time(value);
382 }
383 break;
384 case SUMO_ATTR_BEGIN:
385 myBegin = parse<SUMOTime>(value);
386 break;
387 case SUMO_ATTR_VTYPES:
388 myVehicleTypes = parse<std::vector<std::string> >(value);
389 break;
390 default:
391 setCommonAttribute(key, value);
392 break;
393 }
394}
395
396/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_ROUTEPROBE
a RouteProbe
@ ROUTEPROBE_SELECTED
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:47
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#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
@ 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:57
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
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
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
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
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
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
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
double getCommonAttributeDouble(SumoXMLAttr key) const
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
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.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
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)
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
SUMOTime myBegin
begin of rerouter
std::vector< std::string > myVehicleTypes
vehicle types
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getAttribute(SumoXMLAttr key) const override
SUMOTime myPeriod
RouteProbe period.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
double getAttributeDouble(SumoXMLAttr key) const override
std::string myOutputFilename
output filename
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
Parameterised * getParameters() override
get parameters associated with this routeProbe
~GNERouteProbe()
Destructor.
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
GNEContour mySymbolBaseContour
symbol base contour
GNERouteProbe(GNENet *net)
Constructor.
void updateGeometry() override
update pre-computed geometry information
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this routeProbe
Position getPositionInView() const override
Returns position of additional in view.
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
std::string getParentName() const override
Returns the name of the parent object.
Position getAttributePosition(SumoXMLAttr key) const override
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
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.
std::map< std::string, std::string > Map
parameters map
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
static const RGBColor WHITE
Definition RGBColor.h:211
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:228
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 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)
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
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