SUMO - Simulation of Urban MObility
GNERouteProbe.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <string>
30 #include <iostream>
31 #include <utility>
36 #include <utils/common/ToString.h>
37 #include <utils/geom/GeomHelper.h>
43 #include <utils/gui/div/GLHelper.h>
47 
48 #include "GNEViewNet.h"
49 #include "GNERouteProbe.h"
50 #include "GNEEdge.h"
51 #include "GNELane.h"
52 #include "GNEViewNet.h"
53 #include "GNEUndoList.h"
54 #include "GNENet.h"
55 #include "GNEChange_Attribute.h"
56 
57 
58 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
61 
62 GNERouteProbe::GNERouteProbe(const std::string& id, GNEViewNet* viewNet, GNEEdge* edge, double frequency, const std::string& filename, double begin) :
64  myEdge(edge),
65  myFrequency(frequency),
66  myFilename(filename),
67  myBegin(begin),
68  myNumberOfLanes(0),
69  myRelativePositionY(0) {
70 }
71 
72 
74 }
75 
76 
77 void
79  // Clear all containers
80  myShapeRotations.clear();
81  myShapeLengths.clear();
82 
83  // clear Shape
84  myShape.clear();
85 
86  // obtain relative position of routeProbe in edge
88 
89  // get lanes of edge
90  GNELane* firstLane = myEdge->getLanes().at(0);
91 
92  // Save number of lanes
93  myNumberOfLanes = int(myEdge->getLanes().size());
94 
95  // Get shape of lane parent
96  myShape.push_back(firstLane->getShape().positionAtOffset(0));
97 
98  // Obtain first position
99  Position f = myShape[0] - Position(1, 0);
100 
101  // Obtain next position
102  Position s = myShape[0] + Position(1, 0);
103 
104  // Save rotation (angle) of the vector constructed by points f and s
105  myShapeRotations.push_back(firstLane->getShape().rotationDegreeAtOffset(0) * -1);
106 
107  // Set block icon position
109 
110  // Set offset of the block icon
111  myBlockIconOffset = Position(1.1, (-3.06) - myRelativePositionY);
112 
113  // Set block icon rotation, and using their rotation for logo
114  setBlockIconRotation(firstLane);
115 
116  // Refresh element (neccesary to avoid grabbing problems)
117  myViewNet->getNet()->refreshElement(this);
118 }
119 
120 
121 Position
123  Position A = myEdge->getLanes().front()->getShape().positionAtOffset(5);
124  Position B = myEdge->getLanes().back()->getShape().positionAtOffset(5);
125 
126  // return Middle point
127  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
128 }
129 
130 
131 void
133  // This additional cannot be moved
134 }
135 
136 
137 void
139  // This additional cannot be moved
140 }
141 
142 void
144  // Write parameters
145  device.openTag(getTag());
146  device.writeAttr(SUMO_ATTR_ID, getID());
147  device.writeAttr(SUMO_ATTR_EDGE, myEdge->getID());
149  if (!myFilename.empty()) {
151  }
153  // Close tag
154  device.closeTag();
155 }
156 
157 
158 const std::string&
160  return myFilename;
161 }
162 
163 
164 double
166  return myFrequency;
167 }
168 
169 
170 double
172  return myBegin;
173 }
174 
175 
176 void
177 GNERouteProbe::setFilename(const std::string& filename) {
178  myFilename = filename;
179 }
180 
181 
182 void
183 GNERouteProbe::setFrequency(double frequency) {
184  myFrequency = frequency;
185 }
186 
187 
188 void
189 GNERouteProbe::setBegin(double begin) {
190  myBegin = begin;
191 }
192 
193 
194 const std::string&
196  return myEdge->getMicrosimID();
197 }
198 
199 
200 void
202  // get values
203  glPushName(getGlID());
204  double width = (double) 2.0 * s.scale;
205  glLineWidth(1.0);
206  const double exaggeration = s.addSize.getExaggeration(s);
207 
208  // set color
209  if (isAdditionalSelected()) {
211  } else {
212  GLHelper::setColor(RGBColor(255, 216, 0));
213  }
214  // draw shape
215  glPushMatrix();
216  glTranslated(0, 0, getType());
217  glTranslated(myShape[0].x(), myShape[0].y(), 0);
218  glRotated(myShapeRotations[0], 0, 0, 1);
219  glScaled(exaggeration, exaggeration, 1);
220  glTranslated(-1.6, -1.6, 0);
221  glBegin(GL_QUADS);
222  glVertex2d(0, 0.25);
223  glVertex2d(0, -0.25);
224  glVertex2d((myNumberOfLanes * 3.3), -0.25);
225  glVertex2d((myNumberOfLanes * 3.3), 0.25);
226  glEnd();
227  glTranslated(0, 0, .01);
228  glBegin(GL_LINES);
229  glVertex2d(0, 0.25 - .1);
230  glVertex2d(0, -0.25 + .1);
231  glEnd();
232 
233  // position indicator (White)
234  if (width * exaggeration > 1) {
235  if (isAdditionalSelected()) {
237  } else {
239  }
240  glRotated(90, 0, 0, -1);
241  glBegin(GL_LINES);
242  glVertex2d(0, 0);
243  glVertex2d(0, (myNumberOfLanes * 3.3));
244  glEnd();
245  }
246 
247  // Pop shape matrix
248  glPopMatrix();
249 
250  // Add a draw matrix for drawing logo
251  glPushMatrix();
252  glTranslated(myShape[0].x(), myShape[0].y(), getType());
253  glRotated(myShapeRotations[0], 0, 0, 1);
254  glTranslated((-2.56) - myRelativePositionY, (-1.6), 0);
255  glColor3d(1, 1, 1);
256  glRotated(-90, 0, 0, 1);
257 
258  // Draw icon depending of detector is or isn't selected
259  if (isAdditionalSelected()) {
261  } else {
263  }
264 
265  // Pop logo matrix
266  glPopMatrix();
267 
268  // Check if the distance is enought to draw details
269  if (s.scale * exaggeration >= 10) {
270  // Show Lock icon depending of the Edit mode
271  drawLockIcon(0.4);
272  }
273 
274  // Finish draw
275  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
276  glPopName();
277 }
278 
279 
280 std::string
282  switch (key) {
283  case SUMO_ATTR_ID:
284  return getAdditionalID();
285  case SUMO_ATTR_EDGE:
286  return myEdge->getID();
287  case SUMO_ATTR_FILE:
288  return myFilename;
289  case SUMO_ATTR_FREQUENCY:
290  return toString(myFrequency);
291  case SUMO_ATTR_BEGIN:
292  return toString(myBegin);
293  default:
294  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
295  }
296 }
297 
298 
299 void
300 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
301  if (value == getAttribute(key)) {
302  return; //avoid needless changes, later logic relies on the fact that attributes have changed
303  }
304  switch (key) {
305  case SUMO_ATTR_ID:
306  case SUMO_ATTR_EDGE:
307  case SUMO_ATTR_FILE:
308  case SUMO_ATTR_FREQUENCY:
309  case SUMO_ATTR_BEGIN:
310  undoList->p_add(new GNEChange_Attribute(this, key, value));
311  break;
312  default:
313  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
314  }
315 }
316 
317 
318 bool
319 GNERouteProbe::isValid(SumoXMLAttr key, const std::string& value) {
320  switch (key) {
321  case SUMO_ATTR_ID:
322  return isValidAdditionalID(value);
323  case SUMO_ATTR_EDGE:
324  if (myViewNet->getNet()->retrieveEdge(value, false) != NULL) {
325  return true;
326  } else {
327  return false;
328  }
329  case SUMO_ATTR_FILE:
330  return isValidFilename(value);
331  case SUMO_ATTR_FREQUENCY:
332  return canParse<double>(value) && (parse<double>(value) >= 0);
333  case SUMO_ATTR_BEGIN:
334  return canParse<double>(value) && (parse<double>(value) >= 0);
335  default:
336  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
337  }
338 }
339 
340 
341 void
342 GNERouteProbe::setAttribute(SumoXMLAttr key, const std::string& value) {
343  switch (key) {
344  case SUMO_ATTR_ID:
345  changeAdditionalID(value);
346  break;
347  case SUMO_ATTR_EDGE:
348  myEdge = changeEdge(myEdge, value);
349  break;
350  case SUMO_ATTR_FILE:
351  myFilename = value;
352  break;
353  case SUMO_ATTR_FREQUENCY:
354  myFrequency = parse<double>(value);
355  break;
356  case SUMO_ATTR_BEGIN:
357  myBegin = parse<double>(value);
358  break;
359  default:
360  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
361  }
362  // After setting attribute always update Geometry
363  updateGeometry();
364 }
365 
366 /****************************************************************************/
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:260
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
GNEEdge * myEdge
The edge in which this RouteProbe is placed.
a routeprobe detector
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:902
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 commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
GUIVisualizationTextSettings addName
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:1082
const std::string & getAdditionalID() const
returns Additional ID
static const RGBColor WHITE
Definition: RGBColor.h:185
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Stores the information about how to visualize structures.
void setFilename(const std::string &filename)
set filename of RouteProbe
double y() const
Returns the y-position.
Definition: Position.h:67
double myFrequency
Frequency of RouteProbe.
double x() const
Returns the x-position.
Definition: Position.h:62
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:53
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)
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
void changeAdditionalID(const std::string &newID)
change ID of additional
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
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:116
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:55
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:449
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
const std::string & getFilename() const
get filename of RouteProbe
friend class GNEChange_Attribute
declare friend class
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
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
This functions has to be implemented in all GNEAttributeCarriers.
Position myBlockIconOffset
The offSet of the block icon.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:56
int getRouteProbeRelativePosition(GNERouteProbe *routeProbe) const
obtain relative positions of RouteProbes
Definition: GNEEdge.cpp:538
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:599
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:653
GNEEdge * changeEdge(GNEEdge *oldEdge, const std::string &newEdgeID)
change edge of additional
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:59
void setBlockIconRotation(GNELane *additionalLane=NULL)
double getBegin() const
get begin 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:70
bool closeTag()
Closes the most recently opened tag.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isAdditionalSelected() const
static const RGBColor selectionColor
Definition: GNENet.h:107
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Position getPositionInView() const
Returns position of additional 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