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 
108 
109 Position
112 }
113 
114 
115 void
116 GNEDetectorExit::writeAdditional(OutputDevice& device, const std::string&) {
117  // Write parameters
118  device.openTag(getTag());
119  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
121  // Close tag
122  device.closeTag();
123 }
124 
125 
126 void
128  // Start drawing adding gl identificator
129  glPushName(getGlID());
130 
131  // Push detector matrix
132  glPushMatrix();
133  glTranslated(0, 0, getType());
134 
135  // Set initial values
136  if (isAdditionalSelected()) {
138  } else {
139  glColor3d(myBaseColor.red(), myBaseColor.green(), myBaseColor.blue());
140  }
141  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
142  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
143 
144  // Push poligon matrix
145  glPushMatrix();
146  glScaled(exaggeration, exaggeration, 1);
147  glTranslated(myShape[0].x(), myShape[0].y(), 0);
148  glRotated(myShapeRotations[0], 0, 0, 1);
149 
150  // Draw poligon
151  glBegin(GL_LINES);
152  glVertex2d(1.7, 0);
153  glVertex2d(-1.7, 0);
154  glEnd();
155  glBegin(GL_QUADS);
156  glVertex2d(-1.7, .5);
157  glVertex2d(-1.7, -.5);
158  glVertex2d(1.7, -.5);
159  glVertex2d(1.7, .5);
160  glEnd();
161 
162  // first Arrow
163  glTranslated(1.5, 0, 0);
164  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
166 
167  // second Arrow
168  glTranslated(-3, 0, 0);
169  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
171 
172  // Pop poligon matrix
173  glPopMatrix();
174 
175  // Pop detector matrix
176  glPopMatrix();
177 
178  // Check if the distance is enought to draw details
179  if (s.scale * exaggeration >= 10) {
180  // Draw icon
182 
183  // Show Lock icon depending of the Edit mode
184  drawLockIcon(0.4);
185  }
186  // Draw name
187  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
188 
189  // pop gl identificator
190  glPopName();
191 }
192 
193 
194 std::string
196  switch (key) {
197  case SUMO_ATTR_ID:
198  return getAdditionalID();
199  case SUMO_ATTR_LANE:
201  case SUMO_ATTR_POSITION:
202  return toString(myPosition.x());
203  default:
204  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
205  }
206 }
207 
208 
209 void
210 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
211  if (value == getAttribute(key)) {
212  return; //avoid needless changes, later logic relies on the fact that attributes have changed
213  }
214  switch (key) {
215  case SUMO_ATTR_ID:
216  setAdditionalID(value);
217  break;
218  case SUMO_ATTR_LANE:
220  break;
221  case SUMO_ATTR_POSITION:
222  undoList->p_add(new GNEChange_Attribute(this, key, value));
223  updateGeometry();
224  break;
225  default:
226  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
227  }
228 
229 }
230 
231 
232 bool
233 GNEDetectorExit::isValid(SumoXMLAttr key, const std::string& value) {
234  switch (key) {
235  case SUMO_ATTR_ID:
236  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
237  return true;
238  } else {
239  return false;
240  }
241  case SUMO_ATTR_LANE:
242  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
243  return true;
244  } else {
245  return false;
246  }
247  case SUMO_ATTR_POSITION:
248  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) <= (myLane->getLaneParametricLenght()));
249  default:
250  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
251  }
252 }
253 
254 void
255 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value) {
256  switch (key) {
257  case SUMO_ATTR_ID:
258  setAdditionalID(value);
259  break;
260  case SUMO_ATTR_LANE:
262  break;
263  case SUMO_ATTR_POSITION:
264  myPosition = Position(parse<SUMOReal>(value), 0);
265  updateGeometry();
266  getViewNet()->update();
267  break;
268  default:
269  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
270  }
271 }
272 
273 /****************************************************************************/
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.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
void changeLane(GNELane *newLane)
change lane of detector
GUIVisualizationTextSettings addName
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Stores the information about how to visualize structures.
bool isAdditionalSelected() const
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: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.
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
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
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.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
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
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
~GNEDetectorExit()
destructor
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 getPositionInView() const
Returns position of detector Exit in view.
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
bool isValid(SumoXMLAttr key, const std::string &value)
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
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
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:456
GNEAdditionalSet * myAdditionalSetParent
pointer to additional set parent, if belong to set
virtual void updateGeometry()=0
update pre-computed geometry information
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.
std::string getAttribute(SumoXMLAttr key) const
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
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
void updateGeometry()
update pre-computed geometry information
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
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