SUMO - Simulation of Urban MObility
GNERouteProbe.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 //
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  myRelativePositionY(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(0));
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(0) * -1);
116 
117  // Set block icon position
119 
120  // Set offset of the block icon
121  myBlockIconOffset = Position(1.1, (-3.06) - myRelativePositionY);
122 
123  // Set block icon rotation, and using their rotation for logo
125 
126  // Refresh element (neccesary to avoid grabbing problems)
128 }
129 
130 
131 Position
133  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(5);
134  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(5);
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
153 GNERouteProbe::writeAdditional(OutputDevice& device, bool /*volatileOptionsEnabled*/) const {
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 const 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(const 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  // set color
219  if (isAdditionalSelected()) {
221  } else {
222  GLHelper::setColor(RGBColor(255, 216, 0));
223  }
224  // draw shape
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((myNumberOfLanes * 3.3), -0.25);
235  glVertex2d((myNumberOfLanes * 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  if (isAdditionalSelected()) {
247  } else {
249  }
250  glRotated(90, 0, 0, -1);
251  glBegin(GL_LINES);
252  glVertex2d(0, 0);
253  glVertex2d(0, (myNumberOfLanes * 3.3));
254  glEnd();
255  }
256 
257  // Pop shape matrix
258  glPopMatrix();
259 
260  // Add a draw matrix for drawing logo
261  glPushMatrix();
262  glTranslated(myShape[0].x(), myShape[0].y(), getType());
263  glRotated(myShapeRotations[0], 0, 0, 1);
264  glTranslated((-2.56) - myRelativePositionY, (-1.6), 0);
265  glColor3d(1, 1, 1);
266  glRotated(-90, 0, 0, 1);
267 
268  // Draw icon depending of detector is or isn't selected
269  if (isAdditionalSelected()) {
271  } else {
273  }
274 
275  // Pop logo matrix
276  glPopMatrix();
277 
278  // Check if the distance is enought to draw details
279  if (s.scale * exaggeration >= 10) {
280  // Show Lock icon depending of the Edit mode
281  drawLockIcon(0.4);
282  }
283 
284  // Finish draw
285  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
286  glPopName();
287 }
288 
289 
290 std::string
292  switch (key) {
293  case SUMO_ATTR_ID:
294  return getAdditionalID();
295  case SUMO_ATTR_EDGE:
296  return myEdge->getID();
297  case SUMO_ATTR_FILE:
298  return myFilename;
299  case SUMO_ATTR_FREQUENCY:
300  return toString(myFrequency);
301  case SUMO_ATTR_BEGIN:
302  return toString(myBegin);
303  default:
304  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
305  }
306 }
307 
308 
309 void
310 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
311  if (value == getAttribute(key)) {
312  return; //avoid needless changes, later logic relies on the fact that attributes have changed
313  }
314  switch (key) {
315  case SUMO_ATTR_ID:
316  case SUMO_ATTR_EDGE:
317  case SUMO_ATTR_FILE:
318  case SUMO_ATTR_FREQUENCY:
319  case SUMO_ATTR_BEGIN:
320  undoList->p_add(new GNEChange_Attribute(this, key, value));
321  updateGeometry();
322  break;
323  default:
324  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
325  }
326 }
327 
328 
329 bool
330 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
331  switch (key) {
332  case SUMO_ATTR_ID:
333  if (isValidID(value) && (myViewNet->getNet()->getAdditional(getTag(), value) == NULL)) {
334  return true;
335  } else {
336  return false;
337  }
338  case SUMO_ATTR_EDGE:
339  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
340  return true;
341  } else {
342  return false;
343  }
344  case SUMO_ATTR_FILE:
345  return isValidFilename(value);
346  case SUMO_ATTR_FREQUENCY:
347  return canParse<double>(value) && (parse<double>(value) >= 0);
348  case SUMO_ATTR_BEGIN:
349  return canParse<double>(value) && (parse<double>(value) >= 0);
350  default:
351  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
352  }
353 }
354 
355 
356 void
357 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
358  switch (key) {
359  case SUMO_ATTR_ID:
360  setAdditionalID(value);
361  break;
362  case SUMO_ATTR_EDGE:
363  changeEdge(value);
364  break;
365  case SUMO_ATTR_FILE:
366  myFilename = value;
367  break;
368  case SUMO_ATTR_FREQUENCY:
369  myFrequency = parse<double>(value);
370  break;
371  case SUMO_ATTR_BEGIN:
372  myBegin = parse<double>(value);
373  break;
374  default:
375  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
376  }
377 }
378 
379 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
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:261
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
void setBlockIconRotation()
a routeprobe detector
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:899
double scale
information about a lane&#39;s width (temporary, used for a single view)
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
GUIVisualizationTextSettings addName
void writeAdditional(OutputDevice &device, bool volatileOptionsEnabled) const
writte additional element into a xml file
static const RGBColor WHITE
Definition: RGBColor.h:186
double getBegin() const
get begin of RouteProbe
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
double x() const
Returns the x-position.
Definition: Position.h:63
Stores the information about how to visualize structures.
void setFilename(const std::string &filename)
set filename of RouteProbe
bool isAdditionalSelected() const
double myFrequency
Frequency of RouteProbe.
weights: time range begin
std::string myFilename
filename of RouteProbe
void moveGeometry(const Position &newPosition)
change the position of the element geometry without saving in undoList
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
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
int getRouteProbeRelativePosition(GNERouteProbe *routeProbe) const
obtain relative positions of RouteProbes
Definition: GNEEdge.cpp:514
int myNumberOfLanes
number of lanes of edge (To improve efficiency)
int myRelativePositionY
relative position regarding to other route probes
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
GUIGlID getGlID() const
Returns the numerical id of the object.
GNERouteProbe(const std::string &id, GNEViewNet *viewNet, GNEEdge *edge, double frequency, const std::string &filename, double begin)
Constructor.
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
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
const std::string & getFilename() const
get filename of RouteProbe
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
double getFrequency() const
get frequency of RouteProbe
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:112
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void changeEdge(const std::string &edgeID)
change edge of additional
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
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:998
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
friend class GNEChange_Attribute
declare friend class
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
double y() const
Returns the y-position.
Definition: Position.h:68
std::vector< double > myShapeLengths
The lengths of the shape parts.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
void drawLockIcon(double size=0.5) const
draw lock icon
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
Position getPositionInView() const
Returns position of additional in view.
Position myBlockIconOffset
The offSet of the block icon.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:58
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1680
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:625
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:599
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
const std::string & getParentName() const
Returns the name of the parent object (if any)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void updateGeometry()
update pre-computed geometry information
GNENet * getNet() const
get the net object
double myBegin
begin of rerouter
Position getLineCenter() const
get line center
~GNERouteProbe()
Destructor.
SumoXMLTag getTag() const
get XML Tag assigned to this object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
static const RGBColor selectionColor
Definition: GNENet.h:103
GNEEdge * myEdge
The edge this additional belongs.
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