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  // Refresh element (neccesary to avoid grabbing problems)
115 }
116 
117 
118 Position
121 }
122 
123 
124 void
125 GNEDetectorE1::writeAdditional(OutputDevice& device, const std::string&) {
126  // Write parameters
127  device.openTag(getTag());
128  device.writeAttr(SUMO_ATTR_ID, getID());
129  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
132  if (!myFilename.empty()) {
134  }
136  if (myBlocked) {
138  }
139  // Close tag
140  device.closeTag();
141 }
142 
143 
144 void
146  // get values
147  glPushName(getGlID());
148  SUMOReal width = (SUMOReal) 2.0 * s.scale;
149  glLineWidth(1.0);
150  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
151 
152  // draw shape
153  glColor3d(1, 1, 0);
154  glPushMatrix();
155  glTranslated(0, 0, getType());
156  glTranslated(myShape[0].x(), myShape[0].y(), 0);
157  glRotated(myShapeRotations[0], 0, 0, 1);
158  glScaled(exaggeration, exaggeration, 1);
159  glBegin(GL_QUADS);
160  glVertex2d(-1.0, 2);
161  glVertex2d(-1.0, -2);
162  glVertex2d(1.0, -2);
163  glVertex2d(1.0, 2);
164  glEnd();
165  glTranslated(0, 0, .01);
166  glBegin(GL_LINES);
167  glVertex2d(0, 2 - .1);
168  glVertex2d(0, -2 + .1);
169  glEnd();
170 
171  // outline
172  if (width * exaggeration > 1) {
173  glColor3d(1, 1, 1);
174  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
175  glBegin(GL_QUADS);
176  glVertex2f(-1.0, 2);
177  glVertex2f(-1.0, -2);
178  glVertex2f(1.0, -2);
179  glVertex2f(1.0, 2);
180  glEnd();
181  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
182  }
183 
184  // position indicator
185  if (width * exaggeration > 1) {
186  glRotated(90, 0, 0, -1);
187  glColor3d(1, 1, 1);
188  glBegin(GL_LINES);
189  glVertex2d(0, 1.7);
190  glVertex2d(0, -1.7);
191  glEnd();
192  }
193 
194  // Pop shape matrix
195  glPopMatrix();
196 
197  // Check if the distance is enought to draw details
198  if (s.scale * exaggeration >= 10) {
199  // Add a draw matrix
201 
202  // Show Lock icon depending of the Edit mode
203  drawLockIcon();
204  }
205 
206  // Finish draw
207  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
208  glPopName();
209 }
210 
211 
212 std::string
214  switch (key) {
215  case SUMO_ATTR_ID:
216  return getAdditionalID();
217  case SUMO_ATTR_LANE:
219  case SUMO_ATTR_POSITION:
220  return toString(myPosition.x());
221  case SUMO_ATTR_FREQUENCY:
222  return toString(myFreq);
223  case SUMO_ATTR_FILE:
224  return myFilename;
226  return toString(mySplitByType);
228  return toString(myBlocked);
229  default:
230  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
231  }
232 }
233 
234 
235 void
236 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
237  if (value == getAttribute(key)) {
238  return; //avoid needless changes, later logic relies on the fact that attributes have changed
239  }
240  switch (key) {
241  case SUMO_ATTR_ID:
242  case SUMO_ATTR_LANE:
243  case SUMO_ATTR_POSITION:
244  case SUMO_ATTR_FREQUENCY:
245  case SUMO_ATTR_FILE:
248  undoList->p_add(new GNEChange_Attribute(this, key, value));
249  updateGeometry();
250  break;
251  default:
252  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
253  }
254 
255 }
256 
257 
258 bool
259 GNEDetectorE1::isValid(SumoXMLAttr key, const std::string& value) {
260  switch (key) {
261  case SUMO_ATTR_ID:
262  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
263  return true;
264  } else {
265  return false;
266  }
267  case SUMO_ATTR_LANE:
268  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
269  return true;
270  } else {
271  return false;
272  }
273  case SUMO_ATTR_POSITION:
274  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) <= (myLane->getLaneParametricLenght()));
275  case SUMO_ATTR_FREQUENCY:
276  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0);
277  case SUMO_ATTR_FILE:
278  return isValidFileValue(value);
280  return canParse<bool>(value);
282  return canParse<bool>(value);
283  default:
284  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
285  }
286 }
287 
288 // ===========================================================================
289 // private
290 // ===========================================================================
291 
292 void
293 GNEDetectorE1::setAttribute(SumoXMLAttr key, const std::string& value) {
294  switch (key) {
295  case SUMO_ATTR_ID:
296  setAdditionalID(value);
297  break;
298  case SUMO_ATTR_LANE:
299  changeLane(value);
300  break;
301  case SUMO_ATTR_POSITION:
302  myPosition = Position(parse<SUMOReal>(value), 0);
303  updateGeometry();
304  getViewNet()->update();
305  break;
306  case SUMO_ATTR_FREQUENCY:
307  myFreq = parse<SUMOReal>(value);
308  break;
309  case SUMO_ATTR_FILE:
310  myFilename = value;
311  break;
313  mySplitByType = parse<bool>(value);
314  break;
316  myBlocked = parse<bool>(value);
317  getViewNet()->update();
318  break;
319  default:
320  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
321  }
322 }
323 
324 /****************************************************************************/
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
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:257
bool mySplitByType
attribute to enable or disable splitByType
GUIVisualizationTextSettings addName
const std::string & getAdditionalID() const
returns the ID of additional
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1250
GNELane * myLane
The lane this additional belongs NULL if additional doesnt&#39; belongs to a lane.
Stores the information about how to visualize structures.
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
~GNEDetectorE1()
Destructor.
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.
SUMOReal getLaneParametricLenght() const
returns the parameteric length of the lane
Definition: GNELane.cpp:681
Position getLineCenter() const
get line center
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
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
static bool isValidFileValue(const std::string &value)
true if value is a valid file value
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:784
void writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
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:744
void setBlockIconRotation(GNELane *lane=NULL)
Position myDetectorLogoOffset
The position of detector.
Definition: GNEDetector.h:159
friend class GNEChange_Attribute
declare friend class
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
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
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void changeLane(const std::string &laneID)
change lane of additional
void drawDetectorIcon(const int GNELogoID, SUMOReal sizex=0.5, SUMOReal sizey=0.5) const
Position myBlockIconOffset
The offSet of the block icon.
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:151
std::string getAttribute(SumoXMLAttr key) const
Definition: GNELane.cpp:788
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:583
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:693
RGBColor myBaseColor
base color (Default green)
std::vector< SUMOReal > myShapeRotations
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:912
GUIGlID getGlID() const
Returns the numerical id of the 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
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
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.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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:148
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get Tag assigned to this object