SUMO - Simulation of Urban MObility
GNEDetectorEntry.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 "GNEDetectorEntry.h"
51 #include "GNEDetectorE3.h"
52 #include "GNELane.h"
53 #include "GNEViewNet.h"
54 #include "GNEUndoList.h"
55 #include "GNENet.h"
56 #include "GNEChange_Attribute.h"
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif
61 
62 // ===========================================================================
63 // member method definitions
64 // ===========================================================================
65 
66 GNEDetectorEntry::GNEDetectorEntry(const std::string& id, GNEViewNet* viewNet, GNELane* lane, SUMOReal pos, GNEDetectorE3* parent, bool blocked) :
67  GNEDetector(id, viewNet, SUMO_TAG_DET_ENTRY, lane, pos, 0, "", blocked, parent) {
68  // Update geometry;
70  // Set colors
71  myBaseColor = RGBColor(0, 204, 0, 255);
72  myBaseColorSelected = RGBColor(125, 204, 0, 255);
73 }
74 
75 
77 
78 
79 void
81  // Clear all containers
82  myShapeRotations.clear();
83  myShapeLengths.clear();
84 
85  // clear Shape
86  myShape.clear();
87 
88  // Get shape of lane parent
90 
91  // Save rotation (angle) of the vector constructed by points f and s
93 
94  // Set block icon position
96 
97  // Set offset of logo
99 
100  // Set block icon rotation, and using their rotation for logo
102 
103  // Update parent geometry
105 
106  // Refresh element (neccesary to avoid grabbing problems)
108 }
109 
110 
111 Position
114 }
115 
116 
117 void
118 GNEDetectorEntry::writeAdditional(OutputDevice& device, const std::string&) {
119  // Write parameters
120  device.openTag(getTag());
121  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
123  if (myBlocked) {
125  }
126  // Close tag
127  device.closeTag();
128 }
129 
130 
131 void
133  // Start drawing adding gl identificator
134  glPushName(getGlID());
135 
136  // Push detector matrix
137  glPushMatrix();
138  glTranslated(0, 0, getType());
139 
140  // Set initial values
141  if (isAdditionalSelected()) {
143  } else {
144  glColor3d(myBaseColor.red(), myBaseColor.green(), myBaseColor.blue());
145  }
146  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
147  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
148 
149  // Push poligon matrix
150  glPushMatrix();
151  glScaled(exaggeration, exaggeration, 1);
152  glTranslated(myShape[0].x(), myShape[0].y(), 0);
153  glRotated(myShapeRotations[0], 0, 0, 1);
154 
155  // Draw poligon
156  glBegin(GL_LINES);
157  glVertex2d(1.7, 0);
158  glVertex2d(-1.7, 0);
159  glEnd();
160  glBegin(GL_QUADS);
161  glVertex2d(-1.7, .5);
162  glVertex2d(-1.7, -.5);
163  glVertex2d(1.7, -.5);
164  glVertex2d(1.7, .5);
165  glEnd();
166 
167  // first Arrow
168  glTranslated(1.5, 0, 0);
169  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
171 
172  // second Arrow
173  glTranslated(-3, 0, 0);
174  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
176 
177  // Pop poligon matrix
178  glPopMatrix();
179 
180  // Pop detector matrix
181  glPopMatrix();
182 
183  // Check if the distance is enought to draw details
184  if (s.scale * exaggeration >= 10) {
185  // Draw icon
187 
188  // Show Lock icon depending of the Edit mode
189  drawLockIcon(0.4);
190  }
191  // Draw name
192  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
193 
194  // pop gl identificator
195  glPopName();
196 }
197 
198 
199 std::string
201  switch (key) {
202  case SUMO_ATTR_ID:
203  return getAdditionalID();
204  case SUMO_ATTR_LANE:
206  case SUMO_ATTR_POSITION:
207  return toString(myPosition.x());
209  return toString(myBlocked);
210  default:
211  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
212  }
213 }
214 
215 
216 void
217 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
218  if (value == getAttribute(key)) {
219  return; //avoid needless changes, later logic relies on the fact that attributes have changed
220  }
221  switch (key) {
222  case SUMO_ATTR_ID:
223  case SUMO_ATTR_LANE:
224  case SUMO_ATTR_POSITION:
226  undoList->p_add(new GNEChange_Attribute(this, key, value));
227  updateGeometry();
228  break;
229  default:
230  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
231  }
232 }
233 
234 
235 bool
236 GNEDetectorEntry::isValid(SumoXMLAttr key, const std::string& value) {
237  switch (key) {
238  case SUMO_ATTR_ID:
239  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
240  return true;
241  } else {
242  return false;
243  }
244  case SUMO_ATTR_LANE:
245  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
246  return true;
247  } else {
248  return false;
249  }
250  case SUMO_ATTR_POSITION:
251  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) <= (myLane->getLaneParametricLenght()));
253  return canParse<bool>(value);
254  default:
255  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
256  }
257 }
258 
259 void
260 GNEDetectorEntry::setAttribute(SumoXMLAttr key, const std::string& value) {
261  switch (key) {
262  case SUMO_ATTR_ID:
263  setAdditionalID(value);
264  break;
265  case SUMO_ATTR_LANE:
266  changeLane(value);
267  break;
268  case SUMO_ATTR_POSITION:
269  myPosition = Position(parse<SUMOReal>(value), 0);
270  updateGeometry();
271  getViewNet()->update();
272  break;
274  myBlocked = parse<bool>(value);
275  getViewNet()->update();
276  break;
277  default:
278  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
279  }
280 }
281 
282 /****************************************************************************/
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
GUIVisualizationTextSettings addName
const std::string & getAdditionalID() const
returns the ID of additional
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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.
static void drawBoxLine(const Position &beg, SUMOReal rot, SUMOReal visLength, SUMOReal width, SUMOReal offset=0)
Draws a thick line.
Definition: GLHelper.cpp:130
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:55
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
~GNEDetectorEntry()
destructor
void updateGeometry()
update pre-computed geometry information
SUMOReal getLaneParametricLenght() const
returns the parameteric length of the lane
Definition: GNELane.cpp:681
static void drawTriangleAtEnd(const Position &p1, const Position &p2, SUMOReal tLength, SUMOReal tWidth)
Draws a triangle at the end of the given line.
Definition: GLHelper.cpp:422
Position getLineCenter() const
get line center
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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
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
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.
Position getPositionInView() const
Returns position of detector Entry in view.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
void writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
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
std::string getAttribute(SumoXMLAttr key) const
Definition: GNELane.cpp:788
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
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) ...
GNEAdditionalSet * myAdditionalSetParent
pointer to additional set parent, if belong to set
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:693
virtual void updateGeometry()=0
update pre-computed geometry information
RGBColor myBaseColor
base color (Default green)
std::string getAttribute(SumoXMLAttr key) const
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.
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
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
bool isAdditionalSelected() const
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
GNEDetectorEntry(const std::string &id, GNEViewNet *viewNet, GNELane *lane, SUMOReal pos, GNEDetectorE3 *parent, bool blocked=false)
Constructor.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get Tag assigned to this object