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-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>
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 #ifdef CHECK_MEMORY_LEAKS
58 #include <foreign/nvwa/debug_new.h>
59 #endif
60 
61 // ===========================================================================
62 // member method definitions
63 // ===========================================================================
64 
65 GNEDetectorE1::GNEDetectorE1(const std::string& id, GNELane* lane, GNEViewNet* viewNet, SUMOReal pos, SUMOReal freq, const std::string& filename, bool splitByType, bool blocked) :
66  GNEDetector(id, viewNet, SUMO_TAG_E1DETECTOR, lane, pos, freq, filename, blocked),
67  mySplitByType(splitByType) {
68  // Update geometry;
70  // Set Colors
71  myBaseColor = RGBColor(255, 255, 50, 0);
72  myBaseColorSelected = RGBColor(255, 255, 125, 255);
73 }
74 
75 
77 }
78 
79 
80 void
82  // Clear all containers
83  myShapeRotations.clear();
84  myShapeLengths.clear();
85 
86  // clear Shape
87  myShape.clear();
88 
89  // Get shape of lane parent
91 
92  // Obtain first position
93  Position f = myShape[0] - Position(1, 0);
94 
95  // Obtain next position
96  Position s = myShape[0] + Position(1, 0);
97 
98  // Save rotation (angle) of the vector constructed by points f and s
100 
101  // Set offset of logo
102  myDetectorLogoOffset = Position(1, 0);
103 
104  // Set block icon position
106 
107  // Set offset of the block icon
108  myBlockIconOffset = Position(-1, 0);
109 
110  // Set block icon rotation, and using their rotation for logo
112 }
113 
114 
115 Position
118 }
119 
120 
121 void
122 GNEDetectorE1::writeAdditional(OutputDevice& device, const std::string&) {
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  // Close tag
134  device.closeTag();
135 }
136 
137 
138 void
140  // get values
141  glPushName(getGlID());
142  SUMOReal width = (SUMOReal) 2.0 * s.scale;
143  glLineWidth(1.0);
144  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
145 
146  // draw shape
147  glColor3d(1, 1, 0);
148  glPushMatrix();
149  glTranslated(0, 0, getType());
150  glTranslated(myShape[0].x(), myShape[0].y(), 0);
151  glRotated(myShapeRotations[0], 0, 0, 1);
152  glScaled(exaggeration, exaggeration, 1);
153  glBegin(GL_QUADS);
154  glVertex2d(-1.0, 2);
155  glVertex2d(-1.0, -2);
156  glVertex2d(1.0, -2);
157  glVertex2d(1.0, 2);
158  glEnd();
159  glTranslated(0, 0, .01);
160  glBegin(GL_LINES);
161  glVertex2d(0, 2 - .1);
162  glVertex2d(0, -2 + .1);
163  glEnd();
164 
165  // outline
166  if (width * exaggeration > 1) {
167  glColor3d(1, 1, 1);
168  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
169  glBegin(GL_QUADS);
170  glVertex2f(-1.0, 2);
171  glVertex2f(-1.0, -2);
172  glVertex2f(1.0, -2);
173  glVertex2f(1.0, 2);
174  glEnd();
175  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
176  }
177 
178  // position indicator
179  if (width * exaggeration > 1) {
180  glRotated(90, 0, 0, -1);
181  glColor3d(1, 1, 1);
182  glBegin(GL_LINES);
183  glVertex2d(0, 1.7);
184  glVertex2d(0, -1.7);
185  glEnd();
186  }
187 
188  // Pop shape matrix
189  glPopMatrix();
190 
191  // Check if the distance is enought to draw details
192  if (s.scale * exaggeration >= 10) {
193  // Add a draw matrix
195 
196  // Show Lock icon depending of the Edit mode
197  drawLockIcon();
198  }
199 
200  // Finish draw
201  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
202  glPopName();
203 }
204 
205 
206 std::string
208  switch (key) {
209  case SUMO_ATTR_ID:
210  return getAdditionalID();
211  case SUMO_ATTR_LANE:
213  case SUMO_ATTR_POSITION:
214  return toString(myPosition.x());
215  case SUMO_ATTR_FREQUENCY:
216  return toString(myFreq);
217  case SUMO_ATTR_FILE:
218  return myFilename;
220  return toString(mySplitByType);
221  default:
222  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
223  }
224 }
225 
226 
227 void
228 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
229  if (value == getAttribute(key)) {
230  return; //avoid needless changes, later logic relies on the fact that attributes have changed
231  }
232  switch (key) {
233  case SUMO_ATTR_ID:
234  case SUMO_ATTR_LANE:
235  case SUMO_ATTR_POSITION:
236  case SUMO_ATTR_FREQUENCY:
237  case SUMO_ATTR_FILE:
239  undoList->p_add(new GNEChange_Attribute(this, key, value));
240  updateGeometry();
241  break;
242  default:
243  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
244  }
245 
246 }
247 
248 
249 bool
250 GNEDetectorE1::isValid(SumoXMLAttr key, const std::string& value) {
251  switch (key) {
252  case SUMO_ATTR_ID:
253  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
254  return true;
255  } else {
256  return false;
257  }
258  case SUMO_ATTR_LANE:
259  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
260  return true;
261  } else {
262  return false;
263  }
264  case SUMO_ATTR_POSITION:
265  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) <= (myLane->getLaneParametricLenght()));
266  case SUMO_ATTR_FREQUENCY:
267  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0);
268  case SUMO_ATTR_FILE:
269  return isValidFileValue(value);
271  return canParse<bool>(value);
272  default:
273  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
274  }
275 }
276 
277 // ===========================================================================
278 // private
279 // ===========================================================================
280 
281 void
282 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value) {
283  switch (key) {
284  case SUMO_ATTR_ID:
285  setAdditionalID(value);
286  break;
287  case SUMO_ATTR_LANE:
289  break;
290  case SUMO_ATTR_POSITION:
291  myPosition = Position(parse<SUMOReal>(value), 0);
292  updateGeometry();
293  getViewNet()->update();
294  break;
295  case SUMO_ATTR_FREQUENCY:
296  myFreq = parse<SUMOReal>(value);
297  break;
298  case SUMO_ATTR_FILE:
299  myFilename = value;
300  break;
302  mySplitByType = parse<bool>(value);
303  break;
304  default:
305  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
306  }
307 }
308 
309 /****************************************************************************/
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.
bool isValid(SumoXMLAttr key, const std::string &value)
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
bool mySplitByType
attribute to enable or disable splitByType
void changeLane(GNELane *newLane)
change lane of detector
GUIVisualizationTextSettings addName
Stores the information about how to visualize structures.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
~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.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
RGBColor myBaseColorSelected
base color selected (Default blue)
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.
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.
Position getPositionInView() const
Returns position of detector E1 in view.
const std::string & getAdditionalID() const
returns the ID of additional
void drawDetectorIcon(const int GNELogoID, SUMOReal sizex=0.5, SUMOReal sizey=0.5) const
SUMOReal getLaneParametricLenght() const
returns the parameteric length of the lane
Definition: GNELane.cpp:518
void writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:530
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:658
void setBlockIconRotation(GNELane *lane=NULL)
Position myDetectorLogoOffset
The position of detector.
Definition: GNEDetector.h:173
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
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
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 myBlockIconOffset
The offSet of the block icon.
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:165
std::string getAttribute(SumoXMLAttr key) const
std::string getAttribute(SumoXMLAttr key) const
Definition: GNELane.cpp:601
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
void updateGeometry()
update pre-computed geometry information
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:456
RGBColor myBaseColor
base color (Default green)
GNELane * myLane
The lane this detector belongs.
Definition: GNEDetector.h:159
std::vector< SUMOReal > myShapeRotations
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:845
Position getLineCenter() const
get line center
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
GNEDetectorE1(const std::string &id, GNELane *lane, GNEViewNet *viewNet, SUMOReal pos, SUMOReal freq, const std::string &filename, bool splitByType, bool blocked)
Constructor.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
int myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:162
Position myBlockIconPosition
position of the block icon