SUMO - Simulation of Urban MObility
GNEDetectorE1.cpp
Go to the documentation of this file.
1 /****************************************************************************/
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>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
45 #include <utils/gui/div/GLHelper.h>
49 
50 #include "GNEDetectorE1.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 GNEDetectorE1::GNEDetectorE1(const std::string& id, GNELane* lane, GNEViewNet* viewNet, double pos, double freq, const std::string& filename, bool splitByType) :
63  GNEDetector(id, viewNet, SUMO_TAG_E1DETECTOR, ICON_E1, lane, pos, freq, filename),
64  mySplitByType(splitByType) {
65  // Update geometry;
67  // Set Colors
68  myBaseColor = RGBColor(255, 255, 50, 0);
69  myBaseColorSelected = RGBColor(255, 255, 125, 255);
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  // Get shape of lane parent
88 
89  // Obtain first position
90  Position f = myShape[0] - Position(1, 0);
91 
92  // Obtain next position
93  Position s = myShape[0] + Position(1, 0);
94 
95  // Save rotation (angle) of the vector constructed by points f and s
97 
98  // Set offset of logo
99  myDetectorLogoOffset = Position(1, 0);
100 
101  // Set block icon position
103 
104  // Set offset of the block icon
105  myBlockIconOffset = Position(-1, 0);
106 
107  // Set block icon rotation, and using their rotation for logo
109 
110  // Refresh element (neccesary to avoid grabbing problems)
112 }
113 
114 
115 Position
118 }
119 
120 
121 void
123  // Write parameters
124  device.openTag(getTag());
125  device.writeAttr(SUMO_ATTR_ID, getID());
126  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
129  if (!myFilename.empty()) {
131  }
133  if (myBlocked) {
135  }
136  // Close tag
137  device.closeTag();
138 }
139 
140 
141 void
143  // get values
144  glPushName(getGlID());
145  double width = (double) 2.0 * s.scale;
146  glLineWidth(1.0);
147  const double exaggeration = s.addSize.getExaggeration(s);
148 
149  // draw shape
150  glColor3d(1, 1, 0);
151  glPushMatrix();
152  glTranslated(0, 0, getType());
153  glTranslated(myShape[0].x(), myShape[0].y(), 0);
154  glRotated(myShapeRotations[0], 0, 0, 1);
155  glScaled(exaggeration, exaggeration, 1);
156  glBegin(GL_QUADS);
157  glVertex2d(-1.0, 2);
158  glVertex2d(-1.0, -2);
159  glVertex2d(1.0, -2);
160  glVertex2d(1.0, 2);
161  glEnd();
162  glTranslated(0, 0, .01);
163  glBegin(GL_LINES);
164  glVertex2d(0, 2 - .1);
165  glVertex2d(0, -2 + .1);
166  glEnd();
167 
168  // outline
169  if (width * exaggeration > 1) {
170  glColor3d(1, 1, 1);
171  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
172  glBegin(GL_QUADS);
173  glVertex2f(-1.0, 2);
174  glVertex2f(-1.0, -2);
175  glVertex2f(1.0, -2);
176  glVertex2f(1.0, 2);
177  glEnd();
178  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
179  }
180 
181  // position indicator
182  if (width * exaggeration > 1) {
183  glRotated(90, 0, 0, -1);
184  glColor3d(1, 1, 1);
185  glBegin(GL_LINES);
186  glVertex2d(0, 1.7);
187  glVertex2d(0, -1.7);
188  glEnd();
189  }
190 
191  // Pop shape matrix
192  glPopMatrix();
193 
194  // Check if the distance is enought to draw details
195  if (s.scale * exaggeration >= 10) {
196  // Add a draw matrix
198 
199  // Show Lock icon depending of the Edit mode
200  drawLockIcon();
201  }
202 
203  // Finish draw
204  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
205  glPopName();
206 }
207 
208 
209 std::string
211  switch (key) {
212  case SUMO_ATTR_ID:
213  return getAdditionalID();
214  case SUMO_ATTR_LANE:
216  case SUMO_ATTR_POSITION:
217  return toString(myPosition.x());
218  case SUMO_ATTR_FREQUENCY:
219  return toString(myFreq);
220  case SUMO_ATTR_FILE:
221  return myFilename;
223  return toString(mySplitByType);
225  return toString(myBlocked);
226  default:
227  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
228  }
229 }
230 
231 
232 void
233 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
234  if (value == getAttribute(key)) {
235  return; //avoid needless changes, later logic relies on the fact that attributes have changed
236  }
237  switch (key) {
238  case SUMO_ATTR_ID:
239  case SUMO_ATTR_LANE:
240  case SUMO_ATTR_POSITION:
241  case SUMO_ATTR_FREQUENCY:
242  case SUMO_ATTR_FILE:
245  undoList->p_add(new GNEChange_Attribute(this, key, value));
246  updateGeometry();
247  break;
248  default:
249  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
250  }
251 
252 }
253 
254 
255 bool
256 GNEDetectorE1::isValid(SumoXMLAttr key, const std::string& value) {
257  switch (key) {
258  case SUMO_ATTR_ID:
259  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
260  return true;
261  } else {
262  return false;
263  }
264  case SUMO_ATTR_LANE:
265  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
266  return true;
267  } else {
268  return false;
269  }
270  case SUMO_ATTR_POSITION:
271  return (canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= (myLane->getLaneParametricLength()));
272  case SUMO_ATTR_FREQUENCY:
273  return (canParse<double>(value) && parse<double>(value) >= 0);
274  case SUMO_ATTR_FILE:
275  return isValidFilename(value);
277  return canParse<bool>(value);
279  return canParse<bool>(value);
280  default:
281  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
282  }
283 }
284 
285 // ===========================================================================
286 // private
287 // ===========================================================================
288 
289 void
290 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value) {
291  switch (key) {
292  case SUMO_ATTR_ID:
293  setAdditionalID(value);
294  break;
295  case SUMO_ATTR_LANE:
296  changeLane(value);
297  break;
298  case SUMO_ATTR_POSITION:
299  myPosition = Position(parse<double>(value), 0);
300  updateGeometry();
301  getViewNet()->update();
302  break;
303  case SUMO_ATTR_FREQUENCY:
304  myFreq = parse<double>(value);
305  break;
306  case SUMO_ATTR_FILE:
307  myFilename = value;
308  break;
310  mySplitByType = parse<bool>(value);
311  break;
313  myBlocked = parse<bool>(value);
314  getViewNet()->update();
315  break;
316  default:
317  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
318  }
319 }
320 
321 /****************************************************************************/
Position getPositionInView() const
Returns position of detector E1 in view.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
bool mySplitByType
attribute to enable or disable splitByType
double scale
information about a lane&#39;s width (temporary, used for a single view)
GUIVisualizationTextSettings addName
const std::string & getAdditionalID() const
returns the ID of additional
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1331
GNELane * myLane
The lane this additional belongs.
Stores the information about how to visualize structures.
double getPositionRelativeToParametricLength(double position) const
Definition: GNELane.cpp:727
double x() const
Returns the x-position.
Definition: Position.h:63
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
double myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:147
~GNEDetectorE1()
Destructor.
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.
static bool isValidFilename(const std::string &value)
true if value is a valid file value
std::vector< double > myShapeRotations
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.
RGBColor myBaseColorSelected
base color selected (Default blue)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:715
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:56
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:825
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:785
void setBlockIconRotation(GNELane *lane=NULL)
set Rotation of block Icon
Position myDetectorLogoOffset
The position of detector.
Definition: GNEDetector.h:158
friend class GNEChange_Attribute
declare friend class
block movement of a graphic element
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
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
void changeLane(const std::string &laneID)
change lane of additional
Position myBlockIconOffset
The offSet of the block icon.
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:150
std::string getAttribute(SumoXMLAttr key) const
Definition: GNELane.cpp:780
void drawDetectorIcon(const int GNELogoID, double sizex=0.5, double sizey=0.5) const
void updateGeometry()
update pre-computed geometry information
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::string getAttribute(SumoXMLAttr key) const
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:621
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
RGBColor myBaseColor
base color (Default green)
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
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:71
Position myPosition
The position in which this additional element is located.
bool closeTag()
Closes the most recently opened tag.
GNEDetectorE1(const std::string &id, GNELane *lane, GNEViewNet *viewNet, double pos, double freq, const std::string &filename, bool splitByType)
Constructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object