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 
24 #include <utils/gui/div/GLHelper.h>
25 #include <netedit/GNEViewNet.h>
28 #include <netedit/GNEUndoList.h>
29 #include <netedit/GNENet.h>
32 
33 #include "GNERouteProbe.h"
34 
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
40 GNERouteProbe::GNERouteProbe(const std::string& id, GNEViewNet* viewNet, GNEEdge* edge, const std::string& frequency, const std::string& name, const std::string& filename, double begin) :
41  GNEAdditional(id, viewNet, GLO_ROUTEPROBE, SUMO_TAG_ROUTEPROBE, name, false),
42  myEdge(edge),
43  myFrequency(frequency),
44  myFilename(filename),
45  myBegin(begin),
46  myRelativePositionY(0) {
47 }
48 
49 
51 }
52 
53 
54 void
56  // first check if object has to be removed from grid (SUMOTree)
57  if (updateGrid) {
59  }
60 
61  // Clear all containers
63 
64  // obtain relative position of routeProbe in edge
66 
67  // get lanes of edge
68  GNELane* firstLane = myEdge->getLanes().at(0);
69 
70  // Get shape of lane parent
71  double offset = firstLane->getShape().length() < 0.5 ? firstLane->getShape().length() : 0.5;
72  myGeometry.shape.push_back(firstLane->getShape().positionAtOffset(offset));
73 
74  // Obtain first position
75  Position f = myGeometry.shape[0] - Position(1, 0);
76 
77  // Obtain next position
78  Position s = myGeometry.shape[0] + Position(1, 0);
79 
80  // Save rotation (angle) of the vector constructed by points f and s
81  myGeometry.shapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(offset) * -1);
82 
83  // Set block icon position
85 
86  // Set offset of the block icon
88 
89  // Set block icon rotation, and using their rotation for logo
90  myBlockIcon.setRotation(firstLane);
91 
92  // last step is to check if object has to be added into grid (SUMOTree) again
93  if (updateGrid) {
95  }
96 }
97 
98 
101  if (myEdge->getLanes().front()->getShape().length() < 0.5) {
102  return myEdge->getLanes().front()->getShape().front();
103  } else {
104  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(0.5);
105  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(0.5);
106 
107  // return Middle point
108  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
109  }
110 }
111 
112 
113 void
115  // This additional cannot be moved
116 }
117 
118 
119 void
121  // This additional cannot be moved
122 }
123 
124 
125 std::string
127  return myEdge->getMicrosimID();
128 }
129 
130 
131 void
133  // get values
134  glPushName(getGlID());
135  double width = (double) 2.0 * s.scale;
136  glLineWidth(1.0);
137  const double exaggeration = s.addSize.getExaggeration(s, this);
138  const int numberOfLanes = int(myEdge->getLanes().size());
139 
140  // set color
143  } else {
144  GLHelper::setColor(RGBColor(255, 216, 0));
145  }
146 
147  // draw shape
148  glPushMatrix();
149  glTranslated(0, 0, getType());
150  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), 0);
151  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
152  glScaled(exaggeration, exaggeration, 1);
153  glTranslated(-1.6, -1.6, 0);
154  glBegin(GL_QUADS);
155  glVertex2d(0, 0.25);
156  glVertex2d(0, -0.25);
157  glVertex2d((numberOfLanes * 3.3), -0.25);
158  glVertex2d((numberOfLanes * 3.3), 0.25);
159  glEnd();
160  glTranslated(0, 0, .01);
161  glBegin(GL_LINES);
162  glVertex2d(0, 0.25 - .1);
163  glVertex2d(0, -0.25 + .1);
164  glEnd();
165 
166  // position indicator (White)
167  if ((width * exaggeration > 1) && !s.drawForSelecting) {
170  } else {
172  }
173  glRotated(90, 0, 0, -1);
174  glBegin(GL_LINES);
175  glVertex2d(0, 0);
176  glVertex2d(0, (numberOfLanes * 3.3));
177  glEnd();
178  }
179 
180  // Pop shape matrix
181  glPopMatrix();
182 
183  // Add a draw matrix for drawing logo
184  glPushMatrix();
185  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), getType());
186  glRotated(myGeometry.shapeRotations[0], 0, 0, 1);
187  glTranslated((-2.56) - myRelativePositionY, (-1.6), 0);
188 
189  // Draw icon depending of Route Probe is selected and if isn't being drawn for selecting
190  if (s.drawForSelecting) {
192  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
193  } else {
194  glColor3d(1, 1, 1);
195  glRotated(-90, 0, 0, 1);
198  } else {
200  }
201  }
202 
203  // Pop logo matrix
204  glPopMatrix();
205 
206  // Check if the distance is enought to draw details
207  if ((s.scale * exaggeration >= 10) && !s.drawForSelecting) {
208  // Show Lock icon depending of the Edit mode
209  myBlockIcon.draw(0.4);
210  }
211 
212  // draw name
213  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
214 
215  // check if dotted contour has to be drawn
216  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
218  }
219 
220  // pop name
221  glPopName();
222 }
223 
224 
225 std::string
227  switch (key) {
228  case SUMO_ATTR_ID:
229  return getAdditionalID();
230  case SUMO_ATTR_EDGE:
231  return myEdge->getID();
232  case SUMO_ATTR_NAME:
233  return myAdditionalName;
234  case SUMO_ATTR_FILE:
235  return myFilename;
236  case SUMO_ATTR_FREQUENCY:
237  return toString(myFrequency);
238  case SUMO_ATTR_BEGIN:
239  return toString(myBegin);
240  case GNE_ATTR_SELECTED:
242  case GNE_ATTR_GENERIC:
243  return getGenericParametersStr();
244  default:
245  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
246  }
247 }
248 
249 
250 void
251 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
252  if (value == getAttribute(key)) {
253  return; //avoid needless changes, later logic relies on the fact that attributes have changed
254  }
255  switch (key) {
256  case SUMO_ATTR_ID:
257  case SUMO_ATTR_EDGE:
258  case SUMO_ATTR_NAME:
259  case SUMO_ATTR_FILE:
260  case SUMO_ATTR_FREQUENCY:
261  case SUMO_ATTR_BEGIN:
262  case GNE_ATTR_SELECTED:
263  case GNE_ATTR_GENERIC:
264  undoList->p_add(new GNEChange_Attribute(this, key, value));
265  break;
266  default:
267  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
268  }
269 }
270 
271 
272 std::string
274  return getTagStr();
275 }
276 
277 
278 std::string
280  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN);
281 }
282 
283 // ===========================================================================
284 // private
285 // ===========================================================================
286 
287 bool
288 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
289  switch (key) {
290  case SUMO_ATTR_ID:
291  return isValidAdditionalID(value);
292  case SUMO_ATTR_EDGE:
293  if (myViewNet->getNet()->retrieveEdge(value, false) != nullptr) {
294  return true;
295  } else {
296  return false;
297  }
298  case SUMO_ATTR_NAME:
300  case SUMO_ATTR_FILE:
302  case SUMO_ATTR_FREQUENCY:
303  if (value.empty()) {
304  return true;
305  } else {
306  return canParse<double>(value) && (parse<double>(value) >= 0);
307  }
308  case SUMO_ATTR_BEGIN:
309  return canParse<double>(value) && (parse<double>(value) >= 0);
310  case GNE_ATTR_SELECTED:
311  return canParse<bool>(value);
312  case GNE_ATTR_GENERIC:
313  return isGenericParametersValid(value);
314  default:
315  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
316  }
317 }
318 
319 
320 void
321 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
322  switch (key) {
323  case SUMO_ATTR_ID:
324  changeAdditionalID(value);
325  break;
326  case SUMO_ATTR_EDGE:
327  myEdge = changeEdge(myEdge, value);
328  break;
329  case SUMO_ATTR_NAME:
330  myAdditionalName = value;
331  break;
332  case SUMO_ATTR_FILE:
333  myFilename = value;
334  break;
335  case SUMO_ATTR_FREQUENCY:
336  myFrequency = value;
337  break;
338  case SUMO_ATTR_BEGIN:
339  myBegin = parse<double>(value);
340  break;
341  case GNE_ATTR_SELECTED:
342  if (parse<bool>(value)) {
344  } else {
346  }
347  break;
348  case GNE_ATTR_GENERIC:
350  break;
351  default:
352  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
353  }
354  // Update Geometry after setting a new attribute (but avoided for certain attributes)
355  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
356  updateGeometry(true);
357  }
358 }
359 
360 /****************************************************************************/
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.
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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:900
double scale
information about a lane&#39;s width (temporary, used for a single view)
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
std::vector< double > shapeRotations
The rotations of the single shape parts.
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:191
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Stores the information about how to visualize structures.
Position offset
The offSet of the block icon.
double y() const
Returns the y-position.
Definition: Position.h:62
double x() const
Returns the x-position.
Definition: Position.h:57
weights: time range begin
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
std::string myFilename
filename of RouteProbe
BlockIcon myBlockIcon
variable BlockIcon
void clearGeometry()
reset geometry
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
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 ...
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
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
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:1160
std::string myFrequency
Frequency of RouteProbe.
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
RGBColor selectionColor
NETEDIT special colors.
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
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:771
static const RGBColor YELLOW
Definition: RGBColor.h:187
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:669
void updateGeometry(bool updateGrid)
update pre-computed geometry information
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:873
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:48
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
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.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
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.
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
void draw(double size=0.5) const
draw lock icon