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-sim.org/
10 // Copyright (C) 2001-2013 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 #ifdef CHECK_MEMORY_LEAKS
61 #include <foreign/nvwa/debug_new.h>
62 #endif
63 
64 // ===========================================================================
65 // member method definitions
66 // ===========================================================================
67 
68 GNERouteProbe::GNERouteProbe(const std::string& id, GNEViewNet* viewNet, GNEEdge* edge, int frequency, const std::string& filename, int begin, bool blocked) :
69  GNEAdditional(id, viewNet, Position(), SUMO_TAG_ROUTEPROBE, NULL, blocked),
70  myEdge(edge),
71  myFrequency(frequency),
72  myFilename(filename),
73  myBegin(begin) {
74  // this additional ISN'T movable
75  myMovable = false;
76  // Add additional to edge parent
77  myEdge->addAdditional(this);
78  // Update geometry;
80 }
81 
82 
84  if (myEdge) {
85  myEdge->removeAdditional(this);
86  }
87 }
88 
89 
90 void
92  // Clear all containers
93  myShapeRotations.clear();
94  myShapeLengths.clear();
95 
96  // clear Shape
97  myShape.clear();
98 
99  // get lanes of edge
100  GNELane* firstLane = myEdge->getLanes().at(0);
101 
102  // Save number of lanes
103  numberOfLanes = 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);
122 
123  // Set block icon rotation, and using their rotation for logo
124  setBlockIconRotation(firstLane);
125 }
126 
127 
128 Position
130  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(myPosition.x());
131  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(myPosition.x());
132 
133  // return Middle point
134  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
135 }
136 
137 
138 void
140  // This additional cannot be moved
141 }
142 
143 
144 void
145 GNERouteProbe::writeAdditional(OutputDevice& device, const std::string&) {
146  // Write parameters
147  device.openTag(getTag());
148  device.writeAttr(SUMO_ATTR_ID, getID());
149  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
151  if (!myFilename.empty()) {
153  }
155  // Close tag
156  device.closeTag();
157 }
158 
159 
160 GNEEdge*
162  return myEdge;
163 }
164 
165 void
167  myEdge = NULL;
168 }
169 
170 
171 std::string
173  return myFilename;
174 }
175 
176 
177 int
179  return myFrequency;
180 }
181 
182 
183 int
185  return myBegin;
186 }
187 
188 
189 void
190 GNERouteProbe::setFilename(std::string filename) {
191  myFilename = filename;
192 }
193 
194 
195 void
197  myFrequency = frequency;
198 }
199 
200 
201 void
203  myBegin = begin;
204 }
205 
206 
207 const std::string&
209  return myEdge->getMicrosimID();
210 }
211 
212 
213 void
215  // get values
216  glPushName(getGlID());
217  SUMOReal width = (SUMOReal) 2.0 * s.scale;
218  glLineWidth(1.0);
219  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
220 
221  // draw shape
222  glColor3ub(255, 216, 0);
223  glPushMatrix();
224  glTranslated(0, 0, getType());
225  glTranslated(myShape[0].x(), myShape[0].y(), 0);
226  glRotated(myShapeRotations[0], 0, 0, 1);
227  glScaled(exaggeration, exaggeration, 1);
228  glTranslated(-1.6, -1.6, 0);
229  glBegin(GL_QUADS);
230  glVertex2d(0, 0.25);
231  glVertex2d(0, -0.25);
232  glVertex2d((numberOfLanes * 3.3), -0.25);
233  glVertex2d((numberOfLanes * 3.3), 0.25);
234  glEnd();
235  glTranslated(0, 0, .01);
236  glBegin(GL_LINES);
237  glVertex2d(0, 0.25 - .1);
238  glVertex2d(0, -0.25 + .1);
239  glEnd();
240 
241  // position indicator (White)
242  if (width * exaggeration > 1) {
243  glRotated(90, 0, 0, -1);
244  glColor3d(1, 1, 1);
245  glBegin(GL_LINES);
246  glVertex2d(0, 0);
247  glVertex2d(0, (numberOfLanes * 3.3));
248  glEnd();
249  }
250 
251  // Pop shape matrix
252  glPopMatrix();
253 
254  // Add a draw matrix for drawing logo
255  glPushMatrix();
256  glTranslated(myShape[0].x(), myShape[0].y(), getType());
257  glRotated(myShapeRotations[0], 0, 0, 1);
258  glTranslated(-2.56, - 1.6, 0);
259  glColor3d(1, 1, 1);
260  glRotated(-90, 0, 0, 1);
261 
262  // Draw icon depending of detector is or isn't selected
263  if (isAdditionalSelected()) {
265  } else {
267  }
268 
269  // Pop logo matrix
270  glPopMatrix();
271 
272  // Check if the distance is enought to draw details
273  if (s.scale * exaggeration >= 10) {
274  // Show Lock icon depending of the Edit mode
275  drawLockIcon(0.4);
276  }
277 
278  // Finish draw
279  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
280  glPopName();
281 }
282 
283 
284 std::string
286  switch (key) {
287  case SUMO_ATTR_ID:
288  return getAdditionalID();
289  case SUMO_ATTR_EDGE:
290  return myEdge->getID();
291  case SUMO_ATTR_FILE:
292  return myFilename;
293  case SUMO_ATTR_FREQUENCY:
294  return toString(myFrequency);
295  case SUMO_ATTR_BEGIN:
296  return toString(myBegin);
297  default:
298  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
299  }
300 }
301 
302 
303 void
304 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
305  if (value == getAttribute(key)) {
306  return; //avoid needless changes, later logic relies on the fact that attributes have changed
307  }
308  switch (key) {
309  case SUMO_ATTR_ID:
310  case SUMO_ATTR_EDGE:
311  case SUMO_ATTR_FILE:
312  case SUMO_ATTR_FREQUENCY:
313  case SUMO_ATTR_BEGIN:
314  undoList->p_add(new GNEChange_Attribute(this, key, value));
315  updateGeometry();
316  break;
317  default:
318  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
319  }
320 }
321 
322 
323 bool
324 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
325  switch (key) {
326  case SUMO_ATTR_ID:
327  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
328  return true;
329  } else {
330  return false;
331  }
332  case SUMO_ATTR_EDGE:
333  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
334  return true;
335  } else {
336  return false;
337  }
338  case SUMO_ATTR_FILE:
339  return isValidFileValue(value);
340  case SUMO_ATTR_FREQUENCY:
341  return canParse<int>(value);
342  case SUMO_ATTR_BEGIN:
343  return canParse<int>(value);
344  default:
345  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
346  }
347 }
348 
349 
350 void
351 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
352  switch (key) {
353  case SUMO_ATTR_ID:
354  setAdditionalID(value);
355  break;
356  case SUMO_ATTR_EDGE:
357  myEdge->removeAdditional(this);
358  myEdge = myViewNet->getNet()->retrieveEdge(value);
359  myEdge->addAdditional(this);
360  updateGeometry();
361  getViewNet()->update();
362  break;
363  case SUMO_ATTR_FILE:
364  myFilename = value;
365  break;
366  case SUMO_ATTR_FREQUENCY:
367  myFrequency = parse<int>(value);
368  break;
369  case SUMO_ATTR_BEGIN:
370  myBegin = parse<int>(value);
371  break;
372  default:
373  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
374  }
375 }
376 
377 /****************************************************************************/
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
GNEEdge * myEdge
edge of routeProbe
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:616
void removeEdgeReference()
remove reference to edge
GUIVisualizationTextSettings addName
void writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
Stores the information about how to visualize structures.
int getFrequency() const
get frequency of RouteProbe
void setBegin(int begin)
set begin of RouteProbe
bool isAdditionalSelected() const
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
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
bool addAdditional(GNEAdditional *additional)
add additional to this edge
Definition: GNEEdge.cpp:822
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
GNERouteProbe(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, int frequency, const std::string &filename, int begin, bool blocked)
Constructor.
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
bool removeAdditional(GNEAdditional *additional)
remove additional from this edge
Definition: GNEEdge.cpp:836
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
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.
int getBegin() const
get begin of RouteProbe
static bool isValidFileValue(const std::string &value)
true if value is a valid file value
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
static void drawTexturedBox(unsigned int which, SUMOReal size)
Draws a named texture as a box with the given size.
bool myMovable
boolean to check if additional element is movable (with the mouse). By default true ...
const std::string & getAdditionalID() const
returns the ID of additional
GNEEdge * getEdge() const
get edge in which the RouteProbe is placed
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)
friend class GNEChange_Attribute
declare friend class
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
void drawLockIcon(SUMOReal size=0.5) const
draw lock icon
bool isValid(SumoXMLAttr key, const std::string &value)
int numberOfLanes
number of lanes of edge (To improve efficiency)
void setAdditionalID(const std::string &id)
set the ID of additional
std::string getFilename() const
get filename of RouteProbe
const std::string getID() const
function to support debugging
std::string getAttribute(SumoXMLAttr key) const
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
Position getPositionInView() const
Returns position of RouteProbe in view.
int myBegin
begin of rerouter
Position myBlockIconOffset
The offSet of the block icon.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:54
void moveAdditional(SUMOReal, SUMOReal, GNEUndoList *)
change the position of the RouteProbe geometry
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1093
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:434
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:424
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:63
const std::string & getParentName() const
Returns the name of the parent object (if any)
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
void setFilename(std::string filename)
set filename of RouteProbe
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::vector< SUMOReal > myShapeRotations
void updateGeometry()
update pre-computed geometry information
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:845
Position getLineCenter() const
get line center
~GNERouteProbe()
Destructor.
SumoXMLTag getTag() const
get Tag assigned to this object
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.
#define SUMOReal
Definition: config.h:214
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void setFrequency(int frequency)
set frequency of RouteProbe
Position myBlockIconPosition
position of the block icon
int myFrequency
Frequency of RouteProbe.