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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
40 #include <netedit/GNEViewNet.h>
43 #include <netedit/GNEUndoList.h>
44 #include <netedit/GNENet.h>
46 #include <netedit/GNEViewParent.h>
47 
48 #include "GNERouteProbe.h"
49 
50 
51 // ===========================================================================
52 // member method definitions
53 // ===========================================================================
54 
55 GNERouteProbe::GNERouteProbe(const std::string& id, GNEViewNet* viewNet, GNEEdge* edge, const std::string& frequency, const std::string& name, const std::string& filename, double begin) :
56  GNEAdditional(id, viewNet, GLO_ROUTEPROBE, SUMO_TAG_ROUTEPROBE, name, false),
57  myEdge(edge),
58  myFrequency(frequency),
59  myFilename(filename),
60  myBegin(begin),
61  myRelativePositionY(0) {
62 }
63 
64 
66 }
67 
68 
69 void
71  // first check if object has to be removed from grid (SUMOTree)
72  if (updateGrid) {
74  }
75 
76  // Clear all containers
77  myShapeRotations.clear();
78  myShapeLengths.clear();
79 
80  // clear Shape
81  myShape.clear();
82 
83  // obtain relative position of routeProbe in edge
85 
86  // get lanes of edge
87  GNELane* firstLane = myEdge->getLanes().at(0);
88 
89  // Get shape of lane parent
90  double offset = firstLane->getShape().length() < 0.5 ? firstLane->getShape().length() : 0.5;
91  myShape.push_back(firstLane->getShape().positionAtOffset(offset));
92 
93  // Obtain first position
94  Position f = myShape[0] - Position(1, 0);
95 
96  // Obtain next position
97  Position s = myShape[0] + Position(1, 0);
98 
99  // Save rotation (angle) of the vector constructed by points f and s
100  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(offset) * -1);
101 
102  // Set block icon position
104 
105  // Set offset of the block icon
106  myBlockIconOffset = Position(1.1, (-3.06) - myRelativePositionY);
107 
108  // Set block icon rotation, and using their rotation for logo
109  setBlockIconRotation(firstLane);
110 
111  // last step is to check if object has to be added into grid (SUMOTree) again
112  if (updateGrid) {
114  }
115 }
116 
117 
118 Position
120  if (myEdge->getLanes().front()->getShape().length() < 0.5) {
121  return myEdge->getLanes().front()->getShape().front();
122  } else {
123  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(0.5);
124  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(0.5);
125 
126  // return Middle point
127  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
128  }
129 }
130 
131 
132 void
134  // This additional cannot be moved
135 }
136 
137 
138 void
140  // This additional cannot be moved
141 }
142 
143 
144 std::string
146  return myEdge->getMicrosimID();
147 }
148 
149 
150 void
152  // get values
153  glPushName(getGlID());
154  double width = (double) 2.0 * s.scale;
155  glLineWidth(1.0);
156  const double exaggeration = s.addSize.getExaggeration(s);
157  const int numberOfLanes = int(myEdge->getLanes().size());
158 
159  // set color
162  } else {
163  GLHelper::setColor(RGBColor(255, 216, 0));
164  }
165 
166  // draw shape
167  glPushMatrix();
168  glTranslated(0, 0, getType());
169  glTranslated(myShape[0].x(), myShape[0].y(), 0);
170  glRotated(myShapeRotations[0], 0, 0, 1);
171  glScaled(exaggeration, exaggeration, 1);
172  glTranslated(-1.6, -1.6, 0);
173  glBegin(GL_QUADS);
174  glVertex2d(0, 0.25);
175  glVertex2d(0, -0.25);
176  glVertex2d((numberOfLanes * 3.3), -0.25);
177  glVertex2d((numberOfLanes * 3.3), 0.25);
178  glEnd();
179  glTranslated(0, 0, .01);
180  glBegin(GL_LINES);
181  glVertex2d(0, 0.25 - .1);
182  glVertex2d(0, -0.25 + .1);
183  glEnd();
184 
185  // position indicator (White)
186  if ((width * exaggeration > 1) && !s.drawForSelecting) {
189  } else {
191  }
192  glRotated(90, 0, 0, -1);
193  glBegin(GL_LINES);
194  glVertex2d(0, 0);
195  glVertex2d(0, (numberOfLanes * 3.3));
196  glEnd();
197  }
198 
199  // Pop shape matrix
200  glPopMatrix();
201 
202  // Add a draw matrix for drawing logo
203  glPushMatrix();
204  glTranslated(myShape[0].x(), myShape[0].y(), getType());
205  glRotated(myShapeRotations[0], 0, 0, 1);
206  glTranslated((-2.56) - myRelativePositionY, (-1.6), 0);
207 
208  // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
209  if (s.drawForSelecting) {
211  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
212  } else {
213  glColor3d(1, 1, 1);
214  glRotated(-90, 0, 0, 1);
217  } else {
219  }
220  }
221 
222  // Pop logo matrix
223  glPopMatrix();
224 
225  // Check if the distance is enought to draw details
226  if ((s.scale * exaggeration >= 10) && !s.drawForSelecting) {
227  // Show Lock icon depending of the Edit mode
228  drawLockIcon(0.4);
229  }
230 
231  // draw name
232  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
233 
234  // check if dotted contour has to be drawn
235  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
237  }
238 
239  // pop name
240  glPopName();
241 }
242 
243 
244 std::string
246  switch (key) {
247  case SUMO_ATTR_ID:
248  return getAdditionalID();
249  case SUMO_ATTR_EDGE:
250  return myEdge->getID();
251  case SUMO_ATTR_NAME:
252  return myAdditionalName;
253  case SUMO_ATTR_FILE:
254  return myFilename;
255  case SUMO_ATTR_FREQUENCY:
256  return toString(myFrequency);
257  case SUMO_ATTR_BEGIN:
258  return toString(myBegin);
259  case GNE_ATTR_SELECTED:
261  case GNE_ATTR_GENERIC:
262  return getGenericParametersStr();
263  default:
264  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
265  }
266 }
267 
268 
269 void
270 GNERouteProbe::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_FREQUENCY:
280  case SUMO_ATTR_BEGIN:
281  case GNE_ATTR_SELECTED:
282  case GNE_ATTR_GENERIC:
283  undoList->p_add(new GNEChange_Attribute(this, key, value));
284  break;
285  default:
286  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
287  }
288 }
289 
290 
291 std::string
293  return toString(getTag());
294 }
295 
296 
297 std::string
299  return toString(getTag()) + ": " + getAttribute(SUMO_ATTR_BEGIN);
300 }
301 
302 // ===========================================================================
303 // private
304 // ===========================================================================
305 
306 bool
307 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
308  switch (key) {
309  case SUMO_ATTR_ID:
310  return isValidAdditionalID(value);
311  case SUMO_ATTR_EDGE:
312  if (myViewNet->getNet()->retrieveEdge(value, false) != nullptr) {
313  return true;
314  } else {
315  return false;
316  }
317  case SUMO_ATTR_NAME:
319  case SUMO_ATTR_FILE:
321  case SUMO_ATTR_FREQUENCY:
322  if (value.empty()) {
323  return true;
324  } else {
325  return canParse<double>(value) && (parse<double>(value) >= 0);
326  }
327  case SUMO_ATTR_BEGIN:
328  return canParse<double>(value) && (parse<double>(value) >= 0);
329  case GNE_ATTR_SELECTED:
330  return canParse<bool>(value);
331  case GNE_ATTR_GENERIC:
332  return isGenericParametersValid(value);
333  default:
334  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
335  }
336 }
337 
338 
339 void
340 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
341  switch (key) {
342  case SUMO_ATTR_ID:
343  changeAdditionalID(value);
344  break;
345  case SUMO_ATTR_EDGE:
346  myEdge = changeEdge(myEdge, value);
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_FREQUENCY:
355  myFrequency = value;
356  break;
357  case SUMO_ATTR_BEGIN:
358  myBegin = parse<double>(value);
359  break;
360  case GNE_ATTR_SELECTED:
361  if (parse<bool>(value)) {
363  } else {
365  }
366  break;
367  case GNE_ATTR_GENERIC:
369  break;
370  default:
371  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
372  }
373  // After setting attribute always update Geometry
374  updateGeometry(true);
375 }
376 
377 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
GNEEdge * myEdge
The edge in which this RouteProbe is placed.
a routeprobe detector
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:907
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
GUIVisualizationTextSettings addName
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
static const RGBColor WHITE
Definition: RGBColor.h:179
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:61
double x() const
Returns the x-position.
Definition: Position.h:56
weights: time range begin
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
std::string myFilename
filename of RouteProbe
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
int myRelativePositionY
relative position regarding to other route probes
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
std::vector< double > myShapeRotations
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
GNERouteProbe(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, const std::string &frequency, const std::string &name, const std::string &filename, double begin)
Constructor.
Position getLineCenter() const
get line center
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawLockIcon(double size=0.5) const
draw lock icon
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
std::string myAdditionalName
name of additional
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1167
std::string myFrequency
Frequency of RouteProbe.
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
std::vector< double > myShapeLengths
The lengths of the shape parts.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
std::string getAttribute(SumoXMLAttr key) const
Position myBlockIconOffset
The offSet of the block icon.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
int getRouteProbeRelativePosition(GNERouteProbe *routeProbe) const
obtain relative positions of RouteProbes
Definition: GNEEdge.cpp:735
static const RGBColor YELLOW
Definition: RGBColor.h:175
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:613
void updateGeometry(bool updateGrid)
update pre-computed geometry information
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:832
double length() const
Returns the length.
GNEEdge * changeEdge(GNEEdge *oldEdge, const std::string &newEdgeID)
change edge of additional
a RouteProbe
std::string getParentName() const
Returns the name of the parent object (if any)
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
element is selected
std::string getGenericParametersStr() const
return generic parameters in string format
double myBegin
begin of rerouter
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
~GNERouteProbe()
Destructor.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
static const RGBColor selectionColor
Definition: GNENet.h:96
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Position getPositionInView() const
Returns position of additional in view.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object