SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  myFrequency(frequency),
71  myFilename(filename),
72  myBegin(begin) {
73  // This additional belongs to a edge
74  myEdge = edge;
75  // this additional ISN'T movable
76  myMovable = false;
77  // Update geometry;
79  // Center view in the position of routeProbe
80  myViewNet->centerTo(getGlID(), false);
81 }
82 
83 
85 }
86 
87 
88 void
90  // Clear all containers
91  myShapeRotations.clear();
92  myShapeLengths.clear();
93 
94  // clear Shape
95  myShape.clear();
96 
97  // get lanes of edge
98  GNELane* firstLane = myEdge->getLanes().at(0);
99 
100  // Save number of lanes
101  numberOfLanes = int(myEdge->getLanes().size());
102 
103  // Get shape of lane parent
104  myShape.push_back(firstLane->getShape().positionAtOffset(5));
105 
106  // Obtain first position
107  Position f = myShape[0] - Position(1, 0);
108 
109  // Obtain next position
110  Position s = myShape[0] + Position(1, 0);
111 
112  // Save rotation (angle) of the vector constructed by points f and s
113  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(5) * -1);
114 
115  // Set block icon position
117 
118  // Set offset of the block icon
119  myBlockIconOffset = Position(1.1, -3.06);
120 
121  // Set block icon rotation, and using their rotation for logo
122  setBlockIconRotation(firstLane);
123 
124  // Refresh element (neccesary to avoid grabbing problems)
126 }
127 
128 
129 Position
131  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(myPosition.x());
132  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(myPosition.x());
133 
134  // return Middle point
135  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
136 }
137 
138 
139 void
141  // This additional cannot be moved
142 }
143 
144 
145 void
147  // This additional cannot be moved
148 }
149 
150 void
151 GNERouteProbe::writeAdditional(OutputDevice& device, const std::string&) {
152  // Write parameters
153  device.openTag(getTag());
154  device.writeAttr(SUMO_ATTR_ID, getID());
155  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
157  if (!myFilename.empty()) {
159  }
161  // Close tag
162  device.closeTag();
163 }
164 
165 
166 std::string
168  return myFilename;
169 }
170 
171 
172 int
174  return myFrequency;
175 }
176 
177 
178 int
180  return myBegin;
181 }
182 
183 
184 void
185 GNERouteProbe::setFilename(std::string filename) {
186  myFilename = filename;
187 }
188 
189 
190 void
192  myFrequency = frequency;
193 }
194 
195 
196 void
198  myBegin = begin;
199 }
200 
201 
202 const std::string&
204  return myEdge->getMicrosimID();
205 }
206 
207 
208 void
210  // get values
211  glPushName(getGlID());
212  SUMOReal width = (SUMOReal) 2.0 * s.scale;
213  glLineWidth(1.0);
214  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
215 
216  // draw shape
217  glColor3ub(255, 216, 0);
218  glPushMatrix();
219  glTranslated(0, 0, getType());
220  glTranslated(myShape[0].x(), myShape[0].y(), 0);
221  glRotated(myShapeRotations[0], 0, 0, 1);
222  glScaled(exaggeration, exaggeration, 1);
223  glTranslated(-1.6, -1.6, 0);
224  glBegin(GL_QUADS);
225  glVertex2d(0, 0.25);
226  glVertex2d(0, -0.25);
227  glVertex2d((numberOfLanes * 3.3), -0.25);
228  glVertex2d((numberOfLanes * 3.3), 0.25);
229  glEnd();
230  glTranslated(0, 0, .01);
231  glBegin(GL_LINES);
232  glVertex2d(0, 0.25 - .1);
233  glVertex2d(0, -0.25 + .1);
234  glEnd();
235 
236  // position indicator (White)
237  if (width * exaggeration > 1) {
238  glRotated(90, 0, 0, -1);
239  glColor3d(1, 1, 1);
240  glBegin(GL_LINES);
241  glVertex2d(0, 0);
242  glVertex2d(0, (numberOfLanes * 3.3));
243  glEnd();
244  }
245 
246  // Pop shape matrix
247  glPopMatrix();
248 
249  // Add a draw matrix for drawing logo
250  glPushMatrix();
251  glTranslated(myShape[0].x(), myShape[0].y(), getType());
252  glRotated(myShapeRotations[0], 0, 0, 1);
253  glTranslated(-2.56, - 1.6, 0);
254  glColor3d(1, 1, 1);
255  glRotated(-90, 0, 0, 1);
256 
257  // Draw icon depending of detector is or isn't selected
258  if (isAdditionalSelected()) {
260  } else {
262  }
263 
264  // Pop logo matrix
265  glPopMatrix();
266 
267  // Check if the distance is enought to draw details
268  if (s.scale * exaggeration >= 10) {
269  // Show Lock icon depending of the Edit mode
270  drawLockIcon(0.4);
271  }
272 
273  // Finish draw
274  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
275  glPopName();
276 }
277 
278 
279 std::string
281  switch (key) {
282  case SUMO_ATTR_ID:
283  return getAdditionalID();
284  case SUMO_ATTR_EDGE:
285  return myEdge->getID();
286  case SUMO_ATTR_FILE:
287  return myFilename;
288  case SUMO_ATTR_FREQUENCY:
289  return toString(myFrequency);
290  case SUMO_ATTR_BEGIN:
291  return toString(myBegin);
292  default:
293  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
294  }
295 }
296 
297 
298 void
299 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
300  if (value == getAttribute(key)) {
301  return; //avoid needless changes, later logic relies on the fact that attributes have changed
302  }
303  switch (key) {
304  case SUMO_ATTR_ID:
305  case SUMO_ATTR_EDGE:
306  case SUMO_ATTR_FILE:
307  case SUMO_ATTR_FREQUENCY:
308  case SUMO_ATTR_BEGIN:
309  undoList->p_add(new GNEChange_Attribute(this, key, value));
310  updateGeometry();
311  break;
312  default:
313  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
314  }
315 }
316 
317 
318 bool
319 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
320  switch (key) {
321  case SUMO_ATTR_ID:
322  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
323  return true;
324  } else {
325  return false;
326  }
327  case SUMO_ATTR_EDGE:
328  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
329  return true;
330  } else {
331  return false;
332  }
333  case SUMO_ATTR_FILE:
334  return isValidFileValue(value);
335  case SUMO_ATTR_FREQUENCY:
336  return canParse<int>(value);
337  case SUMO_ATTR_BEGIN:
338  return canParse<int>(value);
339  default:
340  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
341  }
342 }
343 
344 
345 void
346 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
347  switch (key) {
348  case SUMO_ATTR_ID:
349  setAdditionalID(value);
350  break;
351  case SUMO_ATTR_EDGE:
352  changeEdge(value);
353  break;
354  case SUMO_ATTR_FILE:
355  myFilename = value;
356  break;
357  case SUMO_ATTR_FREQUENCY:
358  myFrequency = parse<int>(value);
359  break;
360  case SUMO_ATTR_BEGIN:
361  myBegin = parse<int>(value);
362  break;
363  default:
364  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
365  }
366 }
367 
368 /****************************************************************************/
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
void commmitAdditionalGeometryMoved(SUMOReal, SUMOReal, GNEUndoList *)
updated geometry changes in the attributes of additional
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 * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:702
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
void moveAdditionalGeometry(SUMOReal, SUMOReal)
change the position of the RouteProbe geometry
std::string myFilename
filename of RouteProbe
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:55
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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's width (temporary, used for a single view)
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
void changeEdge(const std::string &edgeID)
change edge of additional
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
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:784
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)
method for checking if the key and their conrrespond attribute are valids
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:55
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:1250
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:583
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:485
An Element which don'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:912
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
GNEEdge * myEdge
The edge this additional belongs NULL if additional doesnt' belongs to a edge.
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.