SUMO - Simulation of Urban MObility
GNEDetectorExit.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 "GNEDetectorExit.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 // ===========================================================================
64 // member method definitions
65 // ===========================================================================
66 
67 GNEDetectorExit::GNEDetectorExit(const std::string& id, GNEViewNet* viewNet, GNELane* lane, SUMOReal pos, GNEDetectorE3* parent, bool blocked) :
68  GNEDetector(id, viewNet, SUMO_TAG_DET_EXIT, lane, pos, 0, "", blocked, parent) {
69  // Update geometry;
71  // Set colors
72  myBaseColor = RGBColor(204, 0, 0, 255);
73  myBaseColorSelected = RGBColor(204, 125, 0, 255);
74 }
75 
76 
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  // Save rotation (angle) of the vector constructed by points f and s
94 
95  // Set offset of logo
97 
98  // Set block icon position
100 
101  // Set block icon rotation, and using their rotation for logo
103 
104  // Update parent geometry
106 
107  // Refresh element (neccesary to avoid grabbing problems)
109 }
110 
111 
112 Position
115 }
116 
117 
118 void
119 GNEDetectorExit::writeAdditional(OutputDevice& device, const std::string&) {
120  // Write parameters
121  device.openTag(getTag());
122  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
124  if (myBlocked) {
126  }
127  // Close tag
128  device.closeTag();
129 }
130 
131 
132 void
134  // Start drawing adding gl identificator
135  glPushName(getGlID());
136 
137  // Push detector matrix
138  glPushMatrix();
139  glTranslated(0, 0, getType());
140 
141  // Set initial values
142  if (isAdditionalSelected()) {
144  } else {
145  glColor3d(myBaseColor.red(), myBaseColor.green(), myBaseColor.blue());
146  }
147  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
148  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
149 
150  // Push poligon matrix
151  glPushMatrix();
152  glScaled(exaggeration, exaggeration, 1);
153  glTranslated(myShape[0].x(), myShape[0].y(), 0);
154  glRotated(myShapeRotations[0], 0, 0, 1);
155 
156  // Draw poligon
157  glBegin(GL_LINES);
158  glVertex2d(1.7, 0);
159  glVertex2d(-1.7, 0);
160  glEnd();
161  glBegin(GL_QUADS);
162  glVertex2d(-1.7, .5);
163  glVertex2d(-1.7, -.5);
164  glVertex2d(1.7, -.5);
165  glVertex2d(1.7, .5);
166  glEnd();
167 
168  // first Arrow
169  glTranslated(1.5, 0, 0);
170  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
172 
173  // second Arrow
174  glTranslated(-3, 0, 0);
175  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
177 
178  // Pop poligon matrix
179  glPopMatrix();
180 
181  // Pop detector matrix
182  glPopMatrix();
183 
184  // Check if the distance is enought to draw details
185  if (s.scale * exaggeration >= 10) {
186  // Draw icon
188 
189  // Show Lock icon depending of the Edit mode
190  drawLockIcon(0.4);
191  }
192  // Draw name
193  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
194 
195  // pop gl identificator
196  glPopName();
197 }
198 
199 
200 std::string
202  switch (key) {
203  case SUMO_ATTR_ID:
204  return getAdditionalID();
205  case SUMO_ATTR_LANE:
207  case SUMO_ATTR_POSITION:
208  return toString(myPosition.x());
210  return toString(myBlocked);
211  default:
212  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
213  }
214 }
215 
216 
217 void
218 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
219  if (value == getAttribute(key)) {
220  return; //avoid needless changes, later logic relies on the fact that attributes have changed
221  }
222  switch (key) {
223  case SUMO_ATTR_ID:
224  case SUMO_ATTR_LANE:
225  case SUMO_ATTR_POSITION:
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 
237 bool
238 GNEDetectorExit::isValid(SumoXMLAttr key, const std::string& value) {
239  switch (key) {
240  case SUMO_ATTR_ID:
241  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
242  return true;
243  } else {
244  return false;
245  }
246  case SUMO_ATTR_LANE:
247  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
248  return true;
249  } else {
250  return false;
251  }
252  case SUMO_ATTR_POSITION:
253  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) <= (myLane->getLaneParametricLenght()));
255  return canParse<bool>(value);
256  default:
257  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
258  }
259 }
260 
261 void
262 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value) {
263  switch (key) {
264  case SUMO_ATTR_ID:
265  setAdditionalID(value);
266  break;
267  case SUMO_ATTR_LANE:
268  changeLane(value);
269  break;
270  case SUMO_ATTR_POSITION:
271  myPosition = Position(parse<SUMOReal>(value), 0);
272  updateGeometry();
273  getViewNet()->update();
274  break;
276  myBlocked = parse<bool>(value);
277  getViewNet()->update();
278  break;
279  default:
280  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
281  }
282 }
283 
284 /****************************************************************************/
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 setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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 writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
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.
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)
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
~GNEDetectorExit()
destructor
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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
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) ...
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEAdditionalSet * myAdditionalSetParent
pointer to additional set parent, if belong to set
Position getPositionInView() const
Returns position of detector Exit in view.
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::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
std::string getAttribute(SumoXMLAttr key) const
static GUIGlID getGif(GUITexture which)
returns a texture Gif previously defined in the enum GUITexture
void updateGeometry()
update pre-computed geometry information
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
GNEDetectorExit(const std::string &id, GNEViewNet *viewNet, GNELane *lane, SUMOReal pos, GNEDetectorE3 *parent, bool blocked=false)
Constructor.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get Tag assigned to this object