Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2025 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 "GNERouteProbe.h"
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
39
40
41GNERouteProbe::GNERouteProbe(const std::string& id, GNENet* net, const std::string& filename, GNEEdge* edge, const SUMOTime period, const std::string& name,
42 const std::string& outputFilename, SUMOTime begin, const std::vector<std::string>& vehicleTypes,
43 const Parameterised::Map& parameters) :
44 GNEAdditional(id, net, filename, SUMO_TAG_ROUTEPROBE, name),
45 Parameterised(parameters),
46 myPeriod(period),
47 myOutputFilename(outputFilename),
48 myBegin(begin),
49 myVehicleTypes(vehicleTypes) {
50 // set parents
51 setParent<GNEEdge*>(edge);
52 // update centering boundary without updating grid
54}
55
56
59
60
61void
63 // open tag
65 // write parameters
66 device.writeAttr(SUMO_ATTR_ID, getID());
68 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
70 }
71 device.writeAttr(SUMO_ATTR_EDGE, getParentEdges().front()->getID());
72 if (!myOutputFilename.empty()) {
74 }
75 if (!myAdditionalName.empty()) {
77 }
78 if (!myVehicleTypes.empty()) {
80 }
81 // write parameters (Always after children to avoid problems with additionals.xsd)
82 writeParams(device);
83 device.closeTag();
84}
85
86
87bool
89 return true;
90}
91
92
93std::string
95 return "";
96}
97
98
99void
101 // nothing to fix
102}
103
104
105void
107 // calculate perpendicular line
109}
110
111
116
117
118void
119GNERouteProbe::updateCenteringBoundary(const bool /*pdateGrid*/) {
120 // nothing to do
121}
122
123
124void
125GNERouteProbe::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
126 // geometry of this element cannot be splitted
127}
128
129
130bool
132 return false;
133}
134
135
138 // routeprobes cannot be moved
139 return nullptr;
140}
141
142
143std::string
145 return getParentEdges().front()->getID();
146}
147
148
149void
151 // first check if additional has to be drawn
153 // Obtain exaggeration of the draw
154 const double routeProbeExaggeration = getExaggeration(s);
155 // declare colors
156 RGBColor routeProbeColor, centralLineColor;
157 // set colors
158 if (drawUsingSelectColor()) {
159 routeProbeColor = s.colorSettings.selectedAdditionalColor;
160 centralLineColor = routeProbeColor.changedBrightness(-32);
161 } else {
162 routeProbeColor = s.additionalSettings.routeProbeColor;
163 centralLineColor = RGBColor::WHITE;
164 }
165 // get detail level
166 const auto d = s.getDetailLevel(routeProbeExaggeration);
167 // draw geometry only if we'rent in drawForObjectUnderCursor mode
169 // draw parent and child lines
171 // Add layer matrix matrix
173 // translate to front
175 // set base color
176 GLHelper::setColor(routeProbeColor);
177 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
178 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.3 * routeProbeExaggeration);
179 // move to front
180 glTranslated(0, 0, .1);
181 // set central color
182 GLHelper::setColor(centralLineColor);
183 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
184 GUIGeometry::drawGeometry(d, myAdditionalGeometry, 0.05 * routeProbeExaggeration);
185 // move to icon position and front
186 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
187 // rotate over lane
189 // Draw icon depending of level of detail
191 // set color
192 glColor3d(1, 1, 1);
193 // rotate texture
194 glRotated(90, 0, 0, 1);
195 // draw texture
196 if (drawUsingSelectColor()) {
198 } else {
200 }
201 } else {
202 // set route probe color
203 GLHelper::setColor(routeProbeColor);
204 // just drawn a box
206 }
207 // pop layer matrix
209 // draw additional name
211 // draw dotted contour
214 }
215 // calculate contour and draw dotted geometry
217 s.additionalSettings.routeProbeSize, getType(), 0, 0, 0, routeProbeExaggeration, getParentEdges().front());
218 mySymbolBaseContour.calculateContourExtrudedShape(s, d, this, myAdditionalGeometry.getShape(), getType(), 0.3, routeProbeExaggeration,
219 true, true, 0, nullptr, getParentEdges().front());
220 }
221}
222
223
224std::string
226 switch (key) {
227 case SUMO_ATTR_ID:
228 return getMicrosimID();
229 case SUMO_ATTR_EDGE:
230 return getParentEdges().front()->getID();
231 case SUMO_ATTR_NAME:
232 return myAdditionalName;
233 case SUMO_ATTR_FILE:
234 return myOutputFilename;
235 case SUMO_ATTR_PERIOD:
238 return "";
239 } else {
240 return time2string(myPeriod);
241 }
242 case SUMO_ATTR_BEGIN:
243 return time2string(myBegin);
244 case SUMO_ATTR_VTYPES:
245 return toString(myVehicleTypes);
246 default:
247 return getCommonAttribute(this, key);
248 }
249}
250
251
252double
254 switch (key) {
255 case SUMO_ATTR_BEGIN:
256 return STEPS2TIME(myBegin);
257 default:
258 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
259 }
260}
261
262
267
268
269void
270GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
271 if (value == getAttribute(key)) {
272 return; //avoid needless changes, later logic relies on the fact that attributes have changed
273 }
274 switch (key) {
275 case SUMO_ATTR_ID:
276 case SUMO_ATTR_EDGE:
277 case SUMO_ATTR_NAME:
278 case SUMO_ATTR_FILE:
279 case SUMO_ATTR_PERIOD:
281 case SUMO_ATTR_BEGIN:
282 case SUMO_ATTR_VTYPES:
283 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
284 break;
285 default:
286 setCommonAttribute(key, value, undoList);
287 break;
288 }
289}
290
291
292std::string
294 return getTagStr();
295}
296
297
298std::string
302
303// ===========================================================================
304// private
305// ===========================================================================
306
307bool
308GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
309 switch (key) {
310 case SUMO_ATTR_ID:
311 return isValidAdditionalID(value);
312 case SUMO_ATTR_EDGE:
313 if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
314 return true;
315 } else {
316 return false;
317 }
318 case SUMO_ATTR_NAME:
320 case SUMO_ATTR_FILE:
322 case SUMO_ATTR_PERIOD:
324 if (value.empty()) {
325 return true;
326 } else {
327 return (canParse<double>(value) && (parse<double>(value) >= 0));
328 }
329 case SUMO_ATTR_BEGIN:
330 return canParse<SUMOTime>(value);
331 case SUMO_ATTR_VTYPES:
332 if (value.empty()) {
333 return true;
334 } else {
336 }
337 default:
338 return isCommonValid(key, value);
339 }
340}
341
342
343void
344GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
345 switch (key) {
346 case SUMO_ATTR_ID:
347 // update microsimID
348 setAdditionalID(value);
349 break;
350 case SUMO_ATTR_EDGE:
352 break;
353 case SUMO_ATTR_NAME:
354 myAdditionalName = value;
355 break;
356 case SUMO_ATTR_FILE:
357 myOutputFilename = value;
358 break;
359 case SUMO_ATTR_PERIOD:
361 if (value.empty()) {
363 } else {
364 myPeriod = string2time(value);
365 }
366 break;
367 case SUMO_ATTR_BEGIN:
368 myBegin = parse<SUMOTime>(value);
369 break;
370 case SUMO_ATTR_VTYPES:
371 myVehicleTypes = parse<std::vector<std::string> >(value);
372 break;
373 default:
374 setCommonAttribute(this, key, value);
375 break;
376 }
377}
378
379
380void
382 // nothing to do
383}
384
385
386void
387GNERouteProbe::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
388 // nothing to do
389}
390
391
392/****************************************************************************/
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:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#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
@ 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
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
std::string getCommonAttribute(const Parameterised *parameterised, 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
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) 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 GNEHierarchicalContainerParents< 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:146
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
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)
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 myOutputFilename
output filename
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.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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:195
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