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.dlr.de/
10 // Copyright (C) 2001-2017 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 
59 // ===========================================================================
60 // member method definitions
61 // ===========================================================================
62 
63 GNEDetectorExit::GNEDetectorExit(GNEViewNet* viewNet, GNEDetectorE3* parent, GNELane* lane, double pos) :
64  GNEDetector(parent->generateExitID(), viewNet, SUMO_TAG_DET_EXIT, ICON_E3EXIT, lane, pos, 0, ""),
65  myE3Parent(parent) {
66  // Update geometry
68  // Set colors
69  myBaseColor = RGBColor(204, 0, 0, 255);
70  myBaseColorSelected = RGBColor(204, 125, 0, 255);
71 }
72 
73 
75 
76 
77 void
80 }
81 
82 
83 void
85  // Clear all containers
86  myShapeRotations.clear();
87  myShapeLengths.clear();
88 
89  // clear Shape
90  myShape.clear();
91 
92  // Get shape of lane parent
94 
95  // Save rotation (angle) of the vector constructed by points f and s
97 
98  // Set offset of logo
100 
101  // Set block icon position
103 
104  // Set block icon rotation, and using their rotation for logo
106 
107  // Refresh element (neccesary to avoid grabbing problems)
109 }
110 
111 
112 Position
115 }
116 
117 
120  return myE3Parent;
121 }
122 
123 
124 void
126  // This additional cannot be writted calling this function because is writted by their E3Parent
127 }
128 
129 
130 void
132  // Start drawing adding gl identificator
133  glPushName(getGlID());
134 
135  // Push detector matrix
136  glPushMatrix();
137  glTranslated(0, 0, getType());
138 
139  // Set initial values
140  if (isAdditionalSelected()) {
142  } else {
143  glColor3d(myBaseColor.red(), myBaseColor.green(), myBaseColor.blue());
144  }
145  const double exaggeration = s.addSize.getExaggeration(s);
146  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
147 
148  // Push poligon matrix
149  glPushMatrix();
150  glScaled(exaggeration, exaggeration, 1);
151  glTranslated(myShape[0].x(), myShape[0].y(), 0);
152  glRotated(myShapeRotations[0], 0, 0, 1);
153 
154  // Draw poligon
155  glBegin(GL_LINES);
156  glVertex2d(1.7, 0);
157  glVertex2d(-1.7, 0);
158  glEnd();
159  glBegin(GL_QUADS);
160  glVertex2d(-1.7, .5);
161  glVertex2d(-1.7, -.5);
162  glVertex2d(1.7, -.5);
163  glVertex2d(1.7, .5);
164  glEnd();
165 
166  // first Arrow
167  glTranslated(1.5, 0, 0);
168  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
169  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
170 
171  // second Arrow
172  glTranslated(-3, 0, 0);
173  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
174  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
175 
176  // Pop poligon matrix
177  glPopMatrix();
178 
179  // Pop detector matrix
180  glPopMatrix();
181 
182  // Check if the distance is enought to draw details
183  if (s.scale * exaggeration >= 10) {
184  // Draw icon
186 
187  // Show Lock icon depending of the Edit mode
188  drawLockIcon(0.4);
189  }
190  // Draw name
191  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
192 
193  // pop gl identificator
194  glPopName();
195 }
196 
197 
198 std::string
200  switch (key) {
201  case SUMO_ATTR_ID:
202  return getAdditionalID();
203  case SUMO_ATTR_LANE:
205  case SUMO_ATTR_POSITION:
206  return toString(myPosition.x());
208  return toString(myBlocked);
209  default:
210  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
211  }
212 }
213 
214 
215 void
216 GNEDetectorExit::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_LANE:
223  case SUMO_ATTR_POSITION:
225  undoList->p_add(new GNEChange_Attribute(this, key, value));
226  updateGeometry();
227  break;
228  default:
229  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
230  }
231 
232 }
233 
234 
235 bool
236 GNEDetectorExit::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<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= (myLane->getLaneParametricLength())));
253  return canParse<bool>(value);
254  default:
255  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
256  }
257 }
258 
259 void
260 GNEDetectorExit::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<double>(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(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
279  }
280 }
281 
282 /****************************************************************************/
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
double scale
information about a lane&#39;s width (temporary, used for a single view)
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 ...
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1331
GNELane * myLane
The lane this additional belongs.
Stores the information about how to visualize structures.
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
double getPositionRelativeToParametricLength(double position) const
Definition: GNELane.cpp:727
double x() const
Returns the x-position.
Definition: Position.h:63
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
void updateGeometryByParent()
update pre-computed geometry information called by E3 parent
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEDetectorExit(GNEViewNet *viewNet, GNEDetectorE3 *parent, GNELane *lane, double pos)
Constructor.
std::vector< double > myShapeRotations
Position getLineCenter() const
get line center
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
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:715
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawLockIcon(double size=0.5) const
draw lock icon
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void updateGeometry()
update pre-computed geometry information
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:825
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
an e3 exit point
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:785
void setBlockIconRotation(GNELane *lane=NULL)
set Rotation of block Icon
Position myDetectorLogoOffset
The position of detector.
Definition: GNEDetector.h:158
friend class GNEChange_Attribute
declare friend class
block movement of a graphic element
std::vector< double > myShapeLengths
The lengths of the shape parts.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
void setAdditionalID(const std::string &id)
set the ID of additional
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void changeLane(const std::string &laneID)
change lane of additional
std::string getAttribute(SumoXMLAttr key) const
Definition: GNELane.cpp:780
void drawDetectorIcon(const int GNELogoID, double sizex=0.5, double sizey=0.5) const
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:621
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.
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
RGBColor myBaseColor
base color (Default green)
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
static void drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth)
Draws a triangle at the end of the given line.
Definition: GLHelper.cpp:418
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 isAdditionalSelected() const
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:126
std::string getAttribute(SumoXMLAttr key) const
GNEDetectorE3 * myE3Parent
pointer to E3 parent
void updateGeometry()
update pre-computed geometry information
GNEDetectorE3 * getE3Parent() const
get E3 Detector parent
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object