SUMO - Simulation of Urban MObility
GNEDetectorE3.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>
38 #include <utils/common/ToString.h>
39 #include <utils/geom/GeomHelper.h>
46 #include <utils/gui/div/GLHelper.h>
51 
52 #include "GNEDetectorE3.h"
53 #include "GNELane.h"
54 #include "GNEViewNet.h"
55 #include "GNEUndoList.h"
56 #include "GNENet.h"
57 #include "GNEChange_Attribute.h"
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif
62 
63 // ===========================================================================
64 // member method definitions
65 // ===========================================================================
66 
67 GNEDetectorE3::GNEDetectorE3(const std::string& id, GNEViewNet* viewNet, Position pos, int freq, const std::string& filename, SUMOTime timeThreshold, SUMOReal speedThreshold, bool blocked) :
68  GNEAdditionalSet(id, viewNet, pos, SUMO_TAG_E3DETECTOR, blocked),
69  myFreq(freq),
70  myFilename(filename),
71  myTimeThreshold(timeThreshold),
72  mySpeedThreshold(speedThreshold) {
73  // Update geometry;
75  // Set colors
76  myBaseColor = RGBColor(76, 170, 50, 255);
77  myBaseColorSelected = RGBColor(161, 255, 135, 255);
78 }
79 
80 
82 }
83 
84 
85 void
87  // Clear shape
88  myShape.clear();
89 
90  // Set block icon position
92 
93  // Set block icon offset
94  myBlockIconOffset = Position(-0.5, -0.5);
95 
96  // Set block icon rotation, and using their rotation for draw logo
98 
99  // Set position
100  myShape.push_back(myPosition);
101 
102  // Add shape of childs (To avoid graphics errors)
103  for (childAdditionals::iterator i = myChildAdditionals.begin(); i != myChildAdditionals.end(); i++) {
104  myShape.append((*i)->getShape());
105  }
106 
107  // Update connections
109 }
110 
111 
112 Position
114  return myPosition;
115 }
116 
117 
118 void
120  // if item isn't blocked
121  if (myBlocked == false) {
122  // change Position
123  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(Position(posx, posy, 0))));
124  }
125 }
126 
127 
128 void
129 GNEDetectorE3::writeAdditional(OutputDevice& device, const std::string& currentDirectory) {
130  // Only save E3 if have Entry/Exits
131  if (getNumberOfAdditionalChilds() > 0) {
132  // Write parameters
133  device.openTag(getTag());
134  device.writeAttr(SUMO_ATTR_ID, getID());
136  if (!myFilename.empty()) {
138  }
141  device.writeAttr(SUMO_ATTR_X, myPosition.x());
142  device.writeAttr(SUMO_ATTR_Y, myPosition.y());
143  // Write childs of this element
144  writeAdditionalChildrens(device, currentDirectory);
145  // Close tag
146  device.closeTag();
147  } else {
148  WRITE_WARNING(toString(getTag()) + " with ID = '" + getID() + "' cannot be writed in additional file because don't have childs.");
149  }
150 }
151 
152 
153 const std::string&
155  return myViewNet->getNet()->getMicrosimID();
156 }
157 
158 
159 void
161  // Start drawing adding an gl identificator
162  glPushName(getGlID());
163 
164  // Add a draw matrix for drawing logo
165  glPushMatrix();
166  glTranslated(myShape[0].x(), myShape[0].y(), getType());
167  glColor3d(1, 1, 1);
168  glRotated(180, 0, 0, 1);
169 
170  // Draw icon depending of detector is or isn't selected
171  if (isAdditionalSelected()) {
173  } else {
175  }
176 
177  // Pop logo matrix
178  glPopMatrix();
179 
180  // Show Lock icon depending of the Edit mode
181  drawLockIcon(0.4);
182 
183  // Draw connections
184  drawConnections();
185 
186  // Pop name
187  glPopName();
188 
189  // Draw name
190  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
191 }
192 
193 
194 std::string
196  switch (key) {
197  case SUMO_ATTR_ID:
198  return getAdditionalID();
199  case SUMO_ATTR_POSITION:
200  return toString(myPosition);
201  case SUMO_ATTR_FREQUENCY:
202  return toString(myFreq);
203  case SUMO_ATTR_FILE:
204  return myFilename;
206  return toString(myTimeThreshold);
208  return toString(mySpeedThreshold);
209  default:
210  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
211  }
212 }
213 
214 
215 void
216 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
217  if (value == getAttribute(key)) {
218  return; //avoid needless changes, later logic relies on the fact that attributes have changed
219  }
220  switch (key) {
221  case SUMO_ATTR_ID:
222  case SUMO_ATTR_FREQUENCY:
223  case SUMO_ATTR_POSITION:
224  case SUMO_ATTR_FILE:
227  undoList->p_add(new GNEChange_Attribute(this, key, value));
228  updateGeometry();
229  break;
230  default:
231  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
232  }
233 }
234 
235 
236 bool
237 GNEDetectorE3::isValid(SumoXMLAttr key, const std::string& value) {
238  switch (key) {
239  case SUMO_ATTR_ID:
240  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
241  return true;
242  } else {
243  return false;
244  }
245  case SUMO_ATTR_POSITION:
246  bool ok;
247  return GeomConvHelper::parseShapeReporting(value, "user-supplied position", 0, ok, false).size() == 1;
248  case SUMO_ATTR_FREQUENCY:
249  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0);
250  case SUMO_ATTR_FILE:
251  return isValidFileValue(value);
253  // @ToDo SUMOTIME
254  return canParse<int>(value);
256  return canParse<SUMOReal>(value);
257  default:
258  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
259  }
260 }
261 
262 
263 void
264 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value) {
265  switch (key) {
266  case SUMO_ATTR_ID:
267  setAdditionalID(value);
268  break;
269  case SUMO_ATTR_POSITION:
270  bool ok;
271  myPosition = GeomConvHelper::parseShapeReporting(value, "user-supplied position", 0, ok, false)[0];
272  updateGeometry();
273  getViewNet()->update();
274  break;
275  case SUMO_ATTR_FREQUENCY:
276  myFreq = parse<SUMOReal>(value);
277  break;
278  case SUMO_ATTR_FILE:
279  myFilename = value;
280  break;
282  // @todo SUMOTIME
283  myTimeThreshold = parse<int>(value);
284  break;
286  mySpeedThreshold = parse<SUMOReal>(value);
287  break;
288  default:
289  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
290  }
291 }
292 
293 /****************************************************************************/
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:257
long long int SUMOTime
Definition: SUMOTime.h:43
int getNumberOfAdditionalChilds() const
get number of additional childs of this additionalSet
GUIVisualizationTextSettings addName
const std::string & getParentName() const
Returns the name of the parent object (if any)
Stores the information about how to visualize structures.
bool isAdditionalSelected() const
Position getPositionInView() const
Returns position of detector E3 in view.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
An Element wich group additionalSet elements.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
bool isValid(SumoXMLAttr key, const std::string &value)
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
RGBColor myBaseColorSelected
base color selected (Default blue)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void writeAdditional(OutputDevice &device, const std::string &currentDirectory)
writte additionalSet element into a xml file
void updateConnections()
update connections.
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.
const std::string & getAdditionalID() const
returns the ID of additional
void updateGeometry()
update pre-computed geometry information
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
int myFreq
frequency of E3 detector
void setBlockIconRotation(GNELane *lane=NULL)
friend class GNEChange_Attribute
declare friend class
void drawLockIcon(SUMOReal size=0.5) const
draw lock icon
SUMOTime myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
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
void moveAdditional(SUMOReal posx, SUMOReal posy, GNEUndoList *undoList)
change the position of the E3 geometry
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void drawConnections() const
draw connections.
Position myBlockIconOffset
The offSet of the block icon.
std::vector< GNEAdditional * > myChildAdditionals
list of additional childs (Position and rotations is derived from additional)
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1093
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
SUMOReal mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting...
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
RGBColor myBaseColor
base color (Default green)
std::string getAttribute(SumoXMLAttr key) const
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:845
~GNEDetectorE3()
GNEDetectorE3 6Destructor.
void writeAdditionalChildrens(OutputDevice &device, const std::string &currentDirectory)
writte children of this additionalSet
GNEDetectorE3(const std::string &id, GNEViewNet *viewNet, Position pos, int freq, const std::string &filename, SUMOTime timeThreshold, SUMOReal speedThreshold, bool blocked)
GNEDetectorE3 Constructor.
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
static void drawTexturedBox(int which, SUMOReal size)
Draws a named texture as a box with the given size.
static PositionVector parseShapeReporting(const std::string &shpdef, const std::string &objecttype, const char *objectid, bool &ok, bool allowEmpty, bool report=true)
Builds a PositionVector from a string representation, reporting occured errors.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::string myFilename
fielname of E3 detector
void append(const PositionVector &v, SUMOReal sameThreshold=2.0)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position myBlockIconPosition
position of the block icon
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)