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-2020 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 
37 GNERouteProbe::GNERouteProbe(const std::string& id, GNENet* net, GNEEdge* edge, const std::string& frequency,
38  const std::string& name, const std::string& filename, SUMOTime begin) :
39  GNEAdditional(id, net, GLO_ROUTEPROBE, SUMO_TAG_ROUTEPROBE, name, false,
40 {}, {edge}, {}, {}, {}, {}, {}, {}),
41 myFrequency(frequency),
42 myFilename(filename),
43 myBegin(begin) {
44  // update centering boundary without updating grid
45  updateCenteringBoundary(false);
46 }
47 
48 
50 }
51 
52 
53 void
55  // calculate perpendicular line
57 }
58 
59 
60 void
61 GNERouteProbe::updateCenteringBoundary(const bool /*pdateGrid*/) {
62  // update geometry
64  // add shape boundary
66  // grow
67  myBoundary.grow(10);
68 }
69 
70 
71 void
72 GNERouteProbe::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
73  // geometry of this element cannot be splitted
74 }
75 
76 
78 GNERouteProbe::getMoveOperation(const double /*shapeOffset*/) {
79  // routeprobes cannot be moved
80  return nullptr;
81 }
82 
83 
84 std::string
86  return getParentEdges().front()->getID();
87 }
88 
89 
90 void
92  // Obtain exaggeration of the draw
93  const double routeProbeExaggeration = s.addSize.getExaggeration(s, this);
94  // first check if additional has to be drawn
95  if (s.drawAdditionals(routeProbeExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
96  // declare colors
97  RGBColor routeProbeColor, centralLineColor;
98  // set colors
99  if (drawUsingSelectColor()) {
100  routeProbeColor = s.colorSettings.selectedAdditionalColor;
101  centralLineColor = routeProbeColor.changedBrightness(-32);
102  } else {
103  routeProbeColor = s.additionalSettings.routeProbeColor;
104  centralLineColor = RGBColor::WHITE;
105  }
106  // Start drawing adding an gl identificator
107  glPushName(getGlID());
108  // Add layer matrix matrix
109  glPushMatrix();
110  // translate to front
112  // set base color
113  GLHelper::setColor(routeProbeColor);
114  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
115  GNEGeometry::drawGeometry(myNet->getViewNet(), myAdditionalGeometry, 0.3 * routeProbeExaggeration);
116  // move to front
117  glTranslated(0, 0, .1);
118  // set central color
119  GLHelper::setColor(centralLineColor);
120  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
121  GNEGeometry::drawGeometry(myNet->getViewNet(), myAdditionalGeometry, 0.05 * routeProbeExaggeration);
122  // move to icon position and front
123  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), .1);
124  // rotate over lane
126  // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
127  if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.laneTextures, routeProbeExaggeration)) {
128  // set color
129  glColor3d(1, 1, 1);
130  // rotate texture
131  glRotated(180, 0, 0, 1);
132  // draw texture
133  if (drawUsingSelectColor()) {
135  } else {
137  }
138  } else {
139  // set route probe color
140  GLHelper::setColor(routeProbeColor);
141  // just drawn a box
143  }
144  // pop layer matrix
145  glPopMatrix();
146  // Pop name
147  glPopName();
148  // draw additional name
150  // check if dotted contours has to be drawn
153  }
154  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
156  }
157  }
158 }
159 
160 
161 std::string
163  switch (key) {
164  case SUMO_ATTR_ID:
165  return getID();
166  case SUMO_ATTR_EDGE:
167  return getParentEdges().front()->getID();
168  case SUMO_ATTR_NAME:
169  return myAdditionalName;
170  case SUMO_ATTR_FILE:
171  return myFilename;
172  case SUMO_ATTR_FREQUENCY:
173  return toString(myFrequency);
174  case SUMO_ATTR_BEGIN:
175  return time2string(myBegin);
176  case GNE_ATTR_SELECTED:
178  case GNE_ATTR_PARAMETERS:
179  return getParametersStr();
180  default:
181  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
182  }
183 }
184 
185 
186 double
188  switch (key) {
189  case SUMO_ATTR_BEGIN:
190  return STEPS2TIME(myBegin);
191  default:
192  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
193  }
194 }
195 
196 
197 void
198 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
199  if (value == getAttribute(key)) {
200  return; //avoid needless changes, later logic relies on the fact that attributes have changed
201  }
202  switch (key) {
203  case SUMO_ATTR_ID:
204  case SUMO_ATTR_EDGE:
205  case SUMO_ATTR_NAME:
206  case SUMO_ATTR_FILE:
207  case SUMO_ATTR_FREQUENCY:
208  case SUMO_ATTR_BEGIN:
209  case GNE_ATTR_SELECTED:
210  case GNE_ATTR_PARAMETERS:
211  undoList->p_add(new GNEChange_Attribute(this, key, value));
212  break;
213  default:
214  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
215  }
216 }
217 
218 
219 bool
221  return true;
222 }
223 
224 
225 std::string
227  return getTagStr();
228 }
229 
230 
231 std::string
233  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN);
234 }
235 
236 // ===========================================================================
237 // private
238 // ===========================================================================
239 
240 bool
241 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
242  switch (key) {
243  case SUMO_ATTR_ID:
244  return isValidAdditionalID(value);
245  case SUMO_ATTR_EDGE:
246  if (myNet->retrieveEdge(value, false) != nullptr) {
247  return true;
248  } else {
249  return false;
250  }
251  case SUMO_ATTR_NAME:
253  case SUMO_ATTR_FILE:
255  case SUMO_ATTR_FREQUENCY:
256  if (value.empty()) {
257  return true;
258  } else {
259  return canParse<SUMOTime>(value);
260  }
261  case SUMO_ATTR_BEGIN:
262  return canParse<SUMOTime>(value);
263  case GNE_ATTR_SELECTED:
264  return canParse<bool>(value);
265  case GNE_ATTR_PARAMETERS:
266  return Parameterised::areParametersValid(value);
267  default:
268  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
269  }
270 }
271 
272 
273 void
274 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
275  switch (key) {
276  case SUMO_ATTR_ID:
277  myNet->getAttributeCarriers()->updateID(this, value);
278  break;
279  case SUMO_ATTR_EDGE:
281  break;
282  case SUMO_ATTR_NAME:
283  myAdditionalName = value;
284  break;
285  case SUMO_ATTR_FILE:
286  myFilename = value;
287  break;
288  case SUMO_ATTR_FREQUENCY:
289  myFrequency = value;
290  break;
291  case SUMO_ATTR_BEGIN:
292  myBegin = parse<SUMOTime>(value);
293  break;
294  case GNE_ATTR_SELECTED:
295  if (parse<bool>(value)) {
297  } else {
299  }
300  break;
301  case GNE_ATTR_PARAMETERS:
302  setParametersStr(value);
303  break;
304  default:
305  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
306  }
307 }
308 
309 
310 void
312  // nothing to do
313 }
314 
315 
316 void
317 GNERouteProbe::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
318  // nothing to do
319 }
320 
321 
322 /****************************************************************************/
@ GLO_ROUTEPROBE
a RouteProbe
@ GNETEXTURE_ROUTEPROBESELECTED
Definition: GUITextures.h:43
@ GNETEXTURE_ROUTEPROBE
Definition: GUITextures.h:42
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:31
@ 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:44
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:446
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
GNEGeometry::Geometry 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
Boundary myBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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:49
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
move operation
move result
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true) const
get edge by id
Definition: GNENet.cpp:1141
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
SUMOTime myBegin
begin of rerouter
GNERouteProbe(const std::string &id, GNENet *net, GNEEdge *edge, const std::string &frequency, const std::string &name, const std::string &filename, SUMOTime begin)
Constructor.
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
~GNERouteProbe()
Destructor.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
double getAttributeDouble(SumoXMLAttr key) const
std::string myFrequency
Frequency of RouteProbe.
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 p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
GUIGlID getGlID() const
Returns the numerical id of the object.
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
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
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 bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, 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"
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:36
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor WHITE
Definition: RGBColor.h:187
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
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 void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration)
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.)
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
bool showAdditionals() const
check if additionals has to be drawn
static const double routeProbeSize
RouteProbe size.
static const RGBColor routeProbeColor
color for route probes
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double laneTextures
details for lane textures
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values