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.org/sumo
3// Copyright (C) 2001-2022 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 Parameterised::Map& parameters) :
52 GUIIconSubSys::getIcon(GUIIcon::ROUTEPROBE), name, {}, {edge}, {}, {}, {}, {}),
53Parameterised(parameters),
54myPeriod(period),
55myFilename(filename),
56myBegin(begin) {
57 // update centering boundary without updating grid
58 updateCenteringBoundary(false);
59}
60
61
63}
64
65
66void
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
89void
91 // calculate perpendicular line
93}
94
95
99}
100
101
102void
103GNERouteProbe::updateCenteringBoundary(const bool /*pdateGrid*/) {
105 // add center
107 // grow
109}
110
111
112void
113GNERouteProbe::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
114 // geometry of this element cannot be splitted
115}
116
117
120 // routeprobes cannot be moved
121 return nullptr;
122}
123
124
125std::string
127 return getParentEdges().front()->getID();
128}
129
130
131void
133 // Obtain exaggeration of the draw
134 const double routeProbeExaggeration = getExaggeration(s);
135 // first check if additional has to be drawn
136 if (s.drawAdditionals(routeProbeExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
137 // declare colors
138 RGBColor routeProbeColor, centralLineColor;
139 // set colors
140 if (drawUsingSelectColor()) {
141 routeProbeColor = s.colorSettings.selectedAdditionalColor;
142 centralLineColor = routeProbeColor.changedBrightness(-32);
143 } else {
144 routeProbeColor = s.additionalSettings.routeProbeColor;
145 centralLineColor = RGBColor::WHITE;
146 }
147 // draw parent and child lines
149 // Start drawing adding an gl identificator
151 // Add layer matrix matrix
153 // translate to front
155 // set base color
156 GLHelper::setColor(routeProbeColor);
157 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
159 // move to front
160 glTranslated(0, 0, .1);
161 // set central color
162 GLHelper::setColor(centralLineColor);
163 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
165 // move to icon position and front
166 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
167 // rotate over lane
169 // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
170 if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.laneTextures, routeProbeExaggeration)) {
171 // set color
172 glColor3d(1, 1, 1);
173 // rotate texture
174 glRotated(90, 0, 0, 1);
175 // draw texture
176 if (drawUsingSelectColor()) {
178 } else {
180 }
181 } else {
182 // set route probe color
183 GLHelper::setColor(routeProbeColor);
184 // just drawn a box
186 }
187 // pop layer matrix
189 // Pop name
191 // draw additional name
193 // check if mouse is over element
195 // inspect contour
198 routeProbeExaggeration, true, true);
199 }
200 // front contour
201 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
203 routeProbeExaggeration, true, true);
204 }
205 // delete contour
206 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
208 routeProbeExaggeration, true, true);
209 }
210 // delete contour
211 if (myNet->getViewNet()->drawSelectContour(this, this)) {
213 routeProbeExaggeration, true, true);
214 }
215 }
216}
217
218
219std::string
221 switch (key) {
222 case SUMO_ATTR_ID:
223 return getMicrosimID();
224 case SUMO_ATTR_EDGE:
225 return getParentEdges().front()->getID();
226 case SUMO_ATTR_NAME:
227 return myAdditionalName;
228 case SUMO_ATTR_FILE:
229 return myFilename;
230 case SUMO_ATTR_PERIOD:
233 return "";
234 } else {
235 return time2string(myPeriod);
236 }
237 case SUMO_ATTR_BEGIN:
238 return time2string(myBegin);
242 return getParametersStr();
243 default:
244 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
245 }
246}
247
248
249double
251 switch (key) {
252 case SUMO_ATTR_BEGIN:
253 return STEPS2TIME(myBegin);
254 default:
255 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
256 }
257}
258
259
262 return getParametersMap();
263}
264
265
266void
267GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
268 if (value == getAttribute(key)) {
269 return; //avoid needless changes, later logic relies on the fact that attributes have changed
270 }
271 switch (key) {
272 case SUMO_ATTR_ID:
273 case SUMO_ATTR_EDGE:
274 case SUMO_ATTR_NAME:
275 case SUMO_ATTR_FILE:
276 case SUMO_ATTR_PERIOD:
278 case SUMO_ATTR_BEGIN:
281 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
282 break;
283 default:
284 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
285 }
286}
287
288
289std::string
291 return getTagStr();
292}
293
294
295std::string
297 return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN);
298}
299
300// ===========================================================================
301// private
302// ===========================================================================
303
304bool
305GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
306 switch (key) {
307 case SUMO_ATTR_ID:
308 return isValidAdditionalID(value);
309 case SUMO_ATTR_EDGE:
310 if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
311 return true;
312 } else {
313 return false;
314 }
315 case SUMO_ATTR_NAME:
317 case SUMO_ATTR_FILE:
319 case SUMO_ATTR_PERIOD:
321 if (value.empty()) {
322 return true;
323 } else {
324 return (canParse<double>(value) && (parse<double>(value) >= 0));
325 }
326 case SUMO_ATTR_BEGIN:
327 return canParse<SUMOTime>(value);
329 return canParse<bool>(value);
331 return areParametersValid(value);
332 default:
333 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
334 }
335}
336
337
338void
339GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
340 switch (key) {
341 case SUMO_ATTR_ID:
342 // update microsimID
343 setMicrosimID(value);
344 break;
345 case SUMO_ATTR_EDGE:
347 break;
348 case SUMO_ATTR_NAME:
349 myAdditionalName = value;
350 break;
351 case SUMO_ATTR_FILE:
352 myFilename = value;
353 break;
354 case SUMO_ATTR_PERIOD:
356 if (value.empty()) {
358 } else {
359 myPeriod = string2time(value);
360 }
361 break;
362 case SUMO_ATTR_BEGIN:
363 myBegin = parse<SUMOTime>(value);
364 break;
366 if (parse<bool>(value)) {
368 } else {
370 }
371 break;
373 setParametersStr(value);
374 break;
375 default:
376 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
377 }
378}
379
380
381void
383 // nothing to do
384}
385
386
387void
388GNERouteProbe::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
389 // nothing to do
390}
391
392
393/****************************************************************************/
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
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define SUMOTime_MAX_PERIOD
Definition: SUMOTime.h:35
@ 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
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
void reset()
Resets the boundary.
Definition: Boundary.cpp:66
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:583
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
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:277
static void popName()
pop Name
Definition: GLHelper.cpp:148
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:48
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
Boundary myAdditionalBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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
friend class GNEChange_Attribute
declare friend class
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
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:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
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 (if any)
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
~GNERouteProbe()
Destructor.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
double getAttributeDouble(SumoXMLAttr key) const
GNERouteProbe(GNENet *net)
Constructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedContourShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given shape (used by additionals)
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 &s, const Position &mousePos, 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:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
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 drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
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 laneTextures
details for lane textures