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 <utils/gui/div/GLHelper.h>
24 #include <netedit/GNEViewNet.h>
25 #include <netedit/GNEUndoList.h>
26 #include <netedit/GNENet.h>
29 
30 #include "GNERouteProbe.h"
31 
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
39 {}, {}, {}, {}, {}, {}, {}, {},
40 std::map<std::string, std::string>()),
41  myFrequency(0),
42 myBegin(0) {
43  // update centering boundary without updating grid
44  updateCenteringBoundary(false);
45 }
46 
47 
48 GNERouteProbe::GNERouteProbe(const std::string& id, GNENet* net, GNEEdge* edge, const SUMOTime frequency, const std::string& name,
49  const std::string& filename, SUMOTime begin, const std::map<std::string, std::string>& parameters) :
51 {}, {edge}, {}, {}, {}, {}, {}, {},
52 parameters),
53 myFrequency(frequency),
54 myFilename(filename),
55 myBegin(begin) {
56  // update centering boundary without updating grid
57  updateCenteringBoundary(false);
58 }
59 
60 
62 }
63 
64 
65 void
67  // open tag
69  // write parameters
70  device.writeAttr(SUMO_ATTR_ID, getID());
73  device.writeAttr(SUMO_ATTR_EDGE, getParentEdges().front()->getID());
74  if (!myAdditionalName.empty()) {
76  }
77  if (!myFilename.empty()) {
79  }
80  // write parameters (Always after children to avoid problems with additionals.xsd)
81  writeParams(device);
82  device.closeTag();
83 }
84 
85 
86 void
88  // calculate perpendicular line
90 }
91 
92 
96 }
97 
98 
99 void
100 GNERouteProbe::updateCenteringBoundary(const bool /*pdateGrid*/) {
102  // add center
104  // grow
106 }
107 
108 
109 void
110 GNERouteProbe::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
111  // geometry of this element cannot be splitted
112 }
113 
114 
117  // routeprobes cannot be moved
118  return nullptr;
119 }
120 
121 
122 std::string
124  return getParentEdges().front()->getID();
125 }
126 
127 
128 void
130  // Obtain exaggeration of the draw
131  const double routeProbeExaggeration = getExaggeration(s);
132  // first check if additional has to be drawn
133  if (s.drawAdditionals(routeProbeExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
134  // declare colors
135  RGBColor routeProbeColor, centralLineColor;
136  // set colors
137  if (drawUsingSelectColor()) {
138  routeProbeColor = s.colorSettings.selectedAdditionalColor;
139  centralLineColor = routeProbeColor.changedBrightness(-32);
140  } else {
141  routeProbeColor = s.additionalSettings.routeProbeColor;
142  centralLineColor = RGBColor::WHITE;
143  }
144  // draw parent and child lines
146  // Start drawing adding an gl identificator
148  // Add layer matrix matrix
150  // translate to front
152  // set base color
153  GLHelper::setColor(routeProbeColor);
154  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
156  // move to front
157  glTranslated(0, 0, .1);
158  // set central color
159  GLHelper::setColor(centralLineColor);
160  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
162  // move to icon position and front
163  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
164  // rotate over lane
166  // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
167  if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.laneTextures, routeProbeExaggeration)) {
168  // set color
169  glColor3d(1, 1, 1);
170  // rotate texture
171  glRotated(90, 0, 0, 1);
172  // draw texture
173  if (drawUsingSelectColor()) {
175  } else {
177  }
178  } else {
179  // set route probe color
180  GLHelper::setColor(routeProbeColor);
181  // just drawn a box
183  }
184  // pop layer matrix
186  // Pop name
188  // draw additional name
190  // check if dotted contours has to be drawn
193  routeProbeExaggeration, true, true);
194  }
195  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
197  routeProbeExaggeration, true, true);
198  }
199  }
200 }
201 
202 
203 std::string
205  switch (key) {
206  case SUMO_ATTR_ID:
207  return getID();
208  case SUMO_ATTR_EDGE:
209  return getParentEdges().front()->getID();
210  case SUMO_ATTR_NAME:
211  return myAdditionalName;
212  case SUMO_ATTR_FILE:
213  return myFilename;
214  case SUMO_ATTR_FREQUENCY:
215  return time2string(myFrequency);
216  case SUMO_ATTR_BEGIN:
217  return time2string(myBegin);
218  case GNE_ATTR_SELECTED:
220  case GNE_ATTR_PARAMETERS:
221  return getParametersStr();
222  default:
223  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
224  }
225 }
226 
227 
228 double
230  switch (key) {
231  case SUMO_ATTR_BEGIN:
232  return STEPS2TIME(myBegin);
233  default:
234  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
235  }
236 }
237 
238 
239 void
240 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
241  if (value == getAttribute(key)) {
242  return; //avoid needless changes, later logic relies on the fact that attributes have changed
243  }
244  switch (key) {
245  case SUMO_ATTR_ID:
246  case SUMO_ATTR_EDGE:
247  case SUMO_ATTR_NAME:
248  case SUMO_ATTR_FILE:
249  case SUMO_ATTR_FREQUENCY:
250  case SUMO_ATTR_BEGIN:
251  case GNE_ATTR_SELECTED:
252  case GNE_ATTR_PARAMETERS:
253  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
254  break;
255  default:
256  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
257  }
258 }
259 
260 
261 bool
263  return true;
264 }
265 
266 
267 std::string
269  return getTagStr();
270 }
271 
272 
273 std::string
275  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN);
276 }
277 
278 // ===========================================================================
279 // private
280 // ===========================================================================
281 
282 bool
283 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
284  switch (key) {
285  case SUMO_ATTR_ID:
286  return isValidAdditionalID(value);
287  case SUMO_ATTR_EDGE:
288  if (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) {
289  return true;
290  } else {
291  return false;
292  }
293  case SUMO_ATTR_NAME:
295  case SUMO_ATTR_FILE:
297  case SUMO_ATTR_FREQUENCY:
298  if (value.empty()) {
299  return true;
300  } else {
301  return canParse<SUMOTime>(value);
302  }
303  case SUMO_ATTR_BEGIN:
304  return canParse<SUMOTime>(value);
305  case GNE_ATTR_SELECTED:
306  return canParse<bool>(value);
307  case GNE_ATTR_PARAMETERS:
308  return Parameterised::areParametersValid(value);
309  default:
310  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
311  }
312 }
313 
314 
315 void
316 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
317  switch (key) {
318  case SUMO_ATTR_ID:
319  // update microsimID
320  setMicrosimID(value);
321  break;
322  case SUMO_ATTR_EDGE:
324  break;
325  case SUMO_ATTR_NAME:
326  myAdditionalName = value;
327  break;
328  case SUMO_ATTR_FILE:
329  myFilename = value;
330  break;
331  case SUMO_ATTR_FREQUENCY:
332  myFrequency = parse<SUMOTime>(value);
333  break;
334  case SUMO_ATTR_BEGIN:
335  myBegin = parse<SUMOTime>(value);
336  break;
337  case GNE_ATTR_SELECTED:
338  if (parse<bool>(value)) {
340  } else {
342  }
343  break;
344  case GNE_ATTR_PARAMETERS:
345  setParametersStr(value);
346  break;
347  default:
348  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
349  }
350 }
351 
352 
353 void
355  // nothing to do
356 }
357 
358 
359 void
360 GNERouteProbe::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
361  // nothing to do
362 }
363 
364 
365 /****************************************************************************/
@ GLO_ROUTEPROBE
a RouteProbe
@ ROUTEPROBE_SELECTED
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:32
@ 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_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:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:231
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getID() const
get ID
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 asociated 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
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:125
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
SUMOTime myBegin
begin of rerouter
void writeAdditional(OutputDevice &device) const
writte 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
bool isAttributeEnabled(SumoXMLAttr key) const
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
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
GNEMoveOperation * getMoveOperation()
get move operation
SUMOTime myFrequency
Frequency of RouteProbe.
~GNERouteProbe()
Destructor.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond 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:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
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 DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth=-1)
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.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
GUIGlID getGlID() const
Returns the numerical id of the object.
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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|....
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"
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:197
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