SUMO - Simulation of Urban MObility
GNERouteProbe.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <iostream>
32 #include <utility>
38 #include <utils/common/ToString.h>
39 #include <utils/geom/GeomHelper.h>
46 #include <utils/gui/div/GLHelper.h>
50 
51 #include "GNEViewNet.h"
52 #include "GNERouteProbe.h"
53 #include "GNEEdge.h"
54 #include "GNELane.h"
55 #include "GNEViewNet.h"
56 #include "GNEUndoList.h"
57 #include "GNENet.h"
58 #include "GNEChange_Attribute.h"
59 
60 
61 // ===========================================================================
62 // member method definitions
63 // ===========================================================================
64 
65 GNERouteProbe::GNERouteProbe(const std::string& id, GNEViewNet* viewNet, GNEEdge* edge, double frequency, const std::string& filename, double begin) :
67  myFrequency(frequency),
68  myFilename(filename),
69  myBegin(begin),
70  myNumberOfLanes(0),
71  myRelativePosition(0) {
72  // This additional belongs to a edge
73  myEdge = edge;
74  // this additional ISN'T movable
75  myMovable = false;
76  // Update geometry;
78  // Center view in the position of routeProbe
79  myViewNet->centerTo(getGlID(), false);
80 }
81 
82 
84 }
85 
86 
87 void
89  // Clear all containers
90  myShapeRotations.clear();
91  myShapeLengths.clear();
92 
93  // clear Shape
94  myShape.clear();
95 
96  // obtain relative position of routeProbe in edge
98 
99  // get lanes of edge
100  GNELane* firstLane = myEdge->getLanes().at(0);
101 
102  // Save number of lanes
103  myNumberOfLanes = int(myEdge->getLanes().size());
104 
105  // Get shape of lane parent
106  myShape.push_back(firstLane->getShape().positionAtOffset(5));
107 
108  // Obtain first position
109  Position f = myShape[0] - Position(1, 0);
110 
111  // Obtain next position
112  Position s = myShape[0] + Position(1, 0);
113 
114  // Save rotation (angle) of the vector constructed by points f and s
115  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(5) * -1);
116 
117  // Set block icon position
119 
120  // Set offset of the block icon
121  myBlockIconOffset = Position(1.1, (-3.06) - myRelativePosition);
122 
123  // Set block icon rotation, and using their rotation for logo
124  setBlockIconRotation(firstLane);
125 
126  // Refresh element (neccesary to avoid grabbing problems)
128 }
129 
130 
131 Position
133  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(myPosition.x());
134  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(myPosition.x());
135 
136  // return Middle point
137  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
138 }
139 
140 
141 void
143  // This additional cannot be moved
144 }
145 
146 
147 void
149  // This additional cannot be moved
150 }
151 
152 void
154  // Write parameters
155  device.openTag(getTag());
156  device.writeAttr(SUMO_ATTR_ID, getID());
157  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
159  if (!myFilename.empty()) {
161  }
163  // Close tag
164  device.closeTag();
165 }
166 
167 
168 std::string
170  return myFilename;
171 }
172 
173 
174 double
176  return myFrequency;
177 }
178 
179 
180 double
182  return myBegin;
183 }
184 
185 
186 void
187 GNERouteProbe::setFilename(std::string filename) {
188  myFilename = filename;
189 }
190 
191 
192 void
193 GNERouteProbe::setFrequency(double frequency) {
194  myFrequency = frequency;
195 }
196 
197 
198 void
199 GNERouteProbe::setBegin(double begin) {
200  myBegin = begin;
201 }
202 
203 
204 const std::string&
206  return myEdge->getMicrosimID();
207 }
208 
209 
210 void
212  // get values
213  glPushName(getGlID());
214  double width = (double) 2.0 * s.scale;
215  glLineWidth(1.0);
216  const double exaggeration = s.addSize.getExaggeration(s);
217 
218  // draw shape
219  glColor3ub(255, 216, 0);
220  glPushMatrix();
221  glTranslated(0, 0, getType());
222  glTranslated(myShape[0].x(), myShape[0].y(), 0);
223  glRotated(myShapeRotations[0], 0, 0, 1);
224  glScaled(exaggeration, exaggeration, 1);
225  glTranslated(-1.6, -1.6, 0);
226  glBegin(GL_QUADS);
227  glVertex2d(0, 0.25);
228  glVertex2d(0, -0.25);
229  glVertex2d((myNumberOfLanes * 3.3), -0.25);
230  glVertex2d((myNumberOfLanes * 3.3), 0.25);
231  glEnd();
232  glTranslated(0, 0, .01);
233  glBegin(GL_LINES);
234  glVertex2d(0, 0.25 - .1);
235  glVertex2d(0, -0.25 + .1);
236  glEnd();
237 
238  // position indicator (White)
239  if (width * exaggeration > 1) {
240  glRotated(90, 0, 0, -1);
241  glColor3d(1, 1, 1);
242  glBegin(GL_LINES);
243  glVertex2d(0, 0);
244  glVertex2d(0, (myNumberOfLanes * 3.3));
245  glEnd();
246  }
247 
248  // Pop shape matrix
249  glPopMatrix();
250 
251  // Add a draw matrix for drawing logo
252  glPushMatrix();
253  glTranslated(myShape[0].x(), myShape[0].y(), getType());
254  glRotated(myShapeRotations[0], 0, 0, 1);
255  glTranslated((-2.56) - myRelativePosition, (-1.6), 0);
256  glColor3d(1, 1, 1);
257  glRotated(-90, 0, 0, 1);
258 
259  // Draw icon depending of detector is or isn't selected
260  if (isAdditionalSelected()) {
262  } else {
264  }
265 
266  // Pop logo matrix
267  glPopMatrix();
268 
269  // Check if the distance is enought to draw details
270  if (s.scale * exaggeration >= 10) {
271  // Show Lock icon depending of the Edit mode
272  drawLockIcon(0.4);
273  }
274 
275  // Finish draw
276  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
277  glPopName();
278 }
279 
280 
281 std::string
283  switch (key) {
284  case SUMO_ATTR_ID:
285  return getAdditionalID();
286  case SUMO_ATTR_EDGE:
287  return myEdge->getID();
288  case SUMO_ATTR_FILE:
289  return myFilename;
290  case SUMO_ATTR_FREQUENCY:
291  return toString(myFrequency);
292  case SUMO_ATTR_BEGIN:
293  return toString(myBegin);
294  default:
295  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
296  }
297 }
298 
299 
300 void
301 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
302  if (value == getAttribute(key)) {
303  return; //avoid needless changes, later logic relies on the fact that attributes have changed
304  }
305  switch (key) {
306  case SUMO_ATTR_ID:
307  case SUMO_ATTR_EDGE:
308  case SUMO_ATTR_FILE:
309  case SUMO_ATTR_FREQUENCY:
310  case SUMO_ATTR_BEGIN:
311  undoList->p_add(new GNEChange_Attribute(this, key, value));
312  updateGeometry();
313  break;
314  default:
315  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
316  }
317 }
318 
319 
320 bool
321 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
322  switch (key) {
323  case SUMO_ATTR_ID:
324  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
325  return true;
326  } else {
327  return false;
328  }
329  case SUMO_ATTR_EDGE:
330  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
331  return true;
332  } else {
333  return false;
334  }
335  case SUMO_ATTR_FILE:
336  return isValidFilename(value);
337  case SUMO_ATTR_FREQUENCY:
338  return (canParse<double>(value) && (parse<double>(value) >= 0));
339  case SUMO_ATTR_BEGIN:
340  return (canParse<double>(value) && (parse<double>(value) >= 0));
341  default:
342  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
343  }
344 }
345 
346 
347 void
348 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
349  switch (key) {
350  case SUMO_ATTR_ID:
351  setAdditionalID(value);
352  break;
353  case SUMO_ATTR_EDGE:
354  changeEdge(value);
355  break;
356  case SUMO_ATTR_FILE:
357  myFilename = value;
358  break;
359  case SUMO_ATTR_FREQUENCY:
360  myFrequency = parse<double>(value);
361  break;
362  case SUMO_ATTR_BEGIN:
363  myBegin = parse<double>(value);
364  break;
365  default:
366  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
367  }
368 }
369 
370 /****************************************************************************/
int myRelativePosition
relative position regarding to other route probes
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
a routeprobe detector
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:743
const std::string & getParentName() const
Returns the name of the parent object (if any)
double scale
information about a lane&#39;s width (temporary, used for a single view)
void commmitAdditionalGeometryMoved(double, double, GNEUndoList *)
updated geometry changes in the attributes of additional
GUIVisualizationTextSettings addName
const std::string & getAdditionalID() const
returns the ID of additional
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
void moveAdditionalGeometry(double, double)
change the position of the RouteProbe geometry
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1331
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:68
double myFrequency
Frequency of RouteProbe.
double x() const
Returns the x-position.
Definition: Position.h:63
weights: time range begin
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
std::string myFilename
filename of RouteProbe
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
void setBegin(double begin)
set begin of RouteProbe
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
int myNumberOfLanes
number of lanes of edge (To improve efficiency)
static bool isValidFilename(const std::string &value)
true if value is a valid file value
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
GNERouteProbe(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, double frequency, 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
std::string getFilename() const
get filename of RouteProbe
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:56
void changeEdge(const std::string &edgeID)
change edge of additional
bool myMovable
boolean to check if additional element is movable (with the mouse). By default true ...
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:825
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void setBlockIconRotation(GNELane *lane=NULL)
set Rotation of block Icon
friend class GNEChange_Attribute
declare friend class
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
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
double getFrequency() const
get frequency of RouteProbe
void setAdditionalID(const std::string &id)
set the ID of additional
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:57
int getRouteProbeRelativePosition(GNERouteProbe *routeProbe) const
obtain relative positions of RouteProbes
Definition: GNEEdge.cpp:475
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:621
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:543
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
double getBegin() const
get begin of RouteProbe
void setFilename(std::string filename)
set filename of RouteProbe
void updateGeometry()
update pre-computed geometry information
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
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
Position myPosition
The position in which this additional element is located.
bool closeTag()
Closes the most recently opened tag.
bool isAdditionalSelected() const
GNEEdge * myEdge
The edge this additional belongs.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Position getPositionInView() const
Returns position of RouteProbe in view.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Position myBlockIconPosition
position of the block icon
void setFrequency(double frequency)
set frequency of RouteProbe
SumoXMLTag getTag() const
get XML Tag assigned to this object