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  // Center view in the position of routeProbe
81  myViewNet->centerTo(getGlID(), false);
82 }
83 
84 
86  if (myEdge) {
87  myEdge->removeAdditional(this);
88  }
89 }
90 
91 
92 void
94  // Clear all containers
95  myShapeRotations.clear();
96  myShapeLengths.clear();
97 
98  // clear Shape
99  myShape.clear();
100 
101  // get lanes of edge
102  GNELane* firstLane = myEdge->getLanes().at(0);
103 
104  // Save number of lanes
105  numberOfLanes = int(myEdge->getLanes().size());
106 
107  // Get shape of lane parent
108  myShape.push_back(firstLane->getShape().positionAtOffset(5));
109 
110  // Obtain first position
111  Position f = myShape[0] - Position(1, 0);
112 
113  // Obtain next position
114  Position s = myShape[0] + Position(1, 0);
115 
116  // Save rotation (angle) of the vector constructed by points f and s
117  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(5) * -1);
118 
119  // Set block icon position
121 
122  // Set offset of the block icon
123  myBlockIconOffset = Position(1.1, -3.06);
124 
125  // Set block icon rotation, and using their rotation for logo
126  setBlockIconRotation(firstLane);
127 }
128 
129 
130 Position
132  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(myPosition.x());
133  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(myPosition.x());
134 
135  // return Middle point
136  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
137 }
138 
139 
140 void
142  // This additional cannot be moved
143 }
144 
145 
146 void
147 GNERouteProbe::writeAdditional(OutputDevice& device, const std::string&) {
148  // Write parameters
149  device.openTag(getTag());
150  device.writeAttr(SUMO_ATTR_ID, getID());
151  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
153  if (!myFilename.empty()) {
155  }
157  // Close tag
158  device.closeTag();
159 }
160 
161 
162 GNEEdge*
164  return myEdge;
165 }
166 
167 void
169  myEdge = NULL;
170 }
171 
172 
173 std::string
175  return myFilename;
176 }
177 
178 
179 int
181  return myFrequency;
182 }
183 
184 
185 int
187  return myBegin;
188 }
189 
190 
191 void
192 GNERouteProbe::setFilename(std::string filename) {
193  myFilename = filename;
194 }
195 
196 
197 void
199  myFrequency = frequency;
200 }
201 
202 
203 void
205  myBegin = begin;
206 }
207 
208 
209 const std::string&
211  return myEdge->getMicrosimID();
212 }
213 
214 
215 void
217  // get values
218  glPushName(getGlID());
219  SUMOReal width = (SUMOReal) 2.0 * s.scale;
220  glLineWidth(1.0);
221  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
222 
223  // draw shape
224  glColor3ub(255, 216, 0);
225  glPushMatrix();
226  glTranslated(0, 0, getType());
227  glTranslated(myShape[0].x(), myShape[0].y(), 0);
228  glRotated(myShapeRotations[0], 0, 0, 1);
229  glScaled(exaggeration, exaggeration, 1);
230  glTranslated(-1.6, -1.6, 0);
231  glBegin(GL_QUADS);
232  glVertex2d(0, 0.25);
233  glVertex2d(0, -0.25);
234  glVertex2d((numberOfLanes * 3.3), -0.25);
235  glVertex2d((numberOfLanes * 3.3), 0.25);
236  glEnd();
237  glTranslated(0, 0, .01);
238  glBegin(GL_LINES);
239  glVertex2d(0, 0.25 - .1);
240  glVertex2d(0, -0.25 + .1);
241  glEnd();
242 
243  // position indicator (White)
244  if (width * exaggeration > 1) {
245  glRotated(90, 0, 0, -1);
246  glColor3d(1, 1, 1);
247  glBegin(GL_LINES);
248  glVertex2d(0, 0);
249  glVertex2d(0, (numberOfLanes * 3.3));
250  glEnd();
251  }
252 
253  // Pop shape matrix
254  glPopMatrix();
255 
256  // Add a draw matrix for drawing logo
257  glPushMatrix();
258  glTranslated(myShape[0].x(), myShape[0].y(), getType());
259  glRotated(myShapeRotations[0], 0, 0, 1);
260  glTranslated(-2.56, - 1.6, 0);
261  glColor3d(1, 1, 1);
262  glRotated(-90, 0, 0, 1);
263 
264  // Draw icon depending of detector is or isn't selected
265  if (isAdditionalSelected()) {
267  } else {
269  }
270 
271  // Pop logo matrix
272  glPopMatrix();
273 
274  // Check if the distance is enought to draw details
275  if (s.scale * exaggeration >= 10) {
276  // Show Lock icon depending of the Edit mode
277  drawLockIcon(0.4);
278  }
279 
280  // Finish draw
281  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
282  glPopName();
283 }
284 
285 
286 std::string
288  switch (key) {
289  case SUMO_ATTR_ID:
290  return getAdditionalID();
291  case SUMO_ATTR_EDGE:
292  return myEdge->getID();
293  case SUMO_ATTR_FILE:
294  return myFilename;
295  case SUMO_ATTR_FREQUENCY:
296  return toString(myFrequency);
297  case SUMO_ATTR_BEGIN:
298  return toString(myBegin);
299  default:
300  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
301  }
302 }
303 
304 
305 void
306 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
307  if (value == getAttribute(key)) {
308  return; //avoid needless changes, later logic relies on the fact that attributes have changed
309  }
310  switch (key) {
311  case SUMO_ATTR_ID:
312  case SUMO_ATTR_EDGE:
313  case SUMO_ATTR_FILE:
314  case SUMO_ATTR_FREQUENCY:
315  case SUMO_ATTR_BEGIN:
316  undoList->p_add(new GNEChange_Attribute(this, key, value));
317  updateGeometry();
318  break;
319  default:
320  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
321  }
322 }
323 
324 
325 bool
326 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
327  switch (key) {
328  case SUMO_ATTR_ID:
329  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
330  return true;
331  } else {
332  return false;
333  }
334  case SUMO_ATTR_EDGE:
335  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
336  return true;
337  } else {
338  return false;
339  }
340  case SUMO_ATTR_FILE:
341  return isValidFileValue(value);
342  case SUMO_ATTR_FREQUENCY:
343  return canParse<int>(value);
344  case SUMO_ATTR_BEGIN:
345  return canParse<int>(value);
346  default:
347  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
348  }
349 }
350 
351 
352 void
353 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
354  switch (key) {
355  case SUMO_ATTR_ID:
356  setAdditionalID(value);
357  break;
358  case SUMO_ATTR_EDGE:
359  myEdge->removeAdditional(this);
360  myEdge = myViewNet->getNet()->retrieveEdge(value);
361  myEdge->addAdditional(this);
362  updateGeometry();
363  getViewNet()->update();
364  break;
365  case SUMO_ATTR_FILE:
366  myFilename = value;
367  break;
368  case SUMO_ATTR_FREQUENCY:
369  myFrequency = parse<int>(value);
370  break;
371  case SUMO_ATTR_BEGIN:
372  myBegin = parse<int>(value);
373  break;
374  default:
375  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
376  }
377 }
378 
379 /****************************************************************************/
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
virtual void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist=20)
centers to the chosen artifact
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:821
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:835
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.
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:456
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:213
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
static void drawTexturedBox(int which, SUMOReal size)
Draws a named texture as a box with the given size.
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.