SUMO - Simulation of Urban MObility
GNEDetectorExit.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 //
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, bool friendlyPos) :
64  GNEDetector(parent->generateExitID(), viewNet, SUMO_TAG_DET_EXIT, ICON_E3EXIT, lane, pos, 0, "", friendlyPos),
65  myE3Parent(parent) {
66  // Update geometry
68 }
69 
70 
72 
73 
74 void
77 }
78 
79 
80 void
82  // Clear all containers
83  myShapeRotations.clear();
84  myShapeLengths.clear();
85 
86  // clear Shape
87  myShape.clear();
88 
89  // obtain position over lane
90  double fixedPositionOverLane = myPositionOverLane > 1 ? 1 : myPositionOverLane < 0 ? 0 : myPositionOverLane;
91  myShape.push_back(myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getShape().length()));
92 
93  // Save rotation (angle) of the vector constructed by points f and s
94  myShapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane * myLane->getShape().length()) * -1);
95 
96  // Set block icon position
98 
99  // Set block icon rotation, and using their rotation for logo
101 
102  // Refresh element (neccesary to avoid grabbing problems)
104 }
105 
106 
109  return myE3Parent;
110 }
111 
112 
113 void
115  // This additional cannot be writted calling this function because is writted by their E3Parent
116 }
117 
118 
120  // with friendly position enabled position are "always fixed"
121  if (myFriendlyPosition) {
122  return true;
123  } else {
124  // floors are needed to avoid precision problems
125  return ((floor(myPositionOverLane * 1000) / 1000) >= 0) && ((floor(myPositionOverLane * 1000) / 1000) <= 1);
126  }
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  GLHelper::setColor(RGBColor(204, 0, 0));
144  }
145  const double exaggeration = s.addSize.getExaggeration(s);
146  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
147 
148  // Push polygon 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 polygon
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 polygon 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  // Push matrix
185  glPushMatrix();
186  // Traslate to center of detector
187  glTranslated(myShape.getLineCenter().x(), myShape.getLineCenter().y(), getType() + 0.1);
188  // Rotate depending of myBlockIconRotation
189  glRotated(myBlockIconRotation, 0, 0, -1);
190  //move to logo position
191  glTranslated(1.9, 0, 0);
192  // draw E2 logo
193  if (isAdditionalSelected()) {
195  } else {
196  GLHelper::drawText("E3", Position(), .1, 2.8, RGBColor(204, 0, 0));
197  }
198  //move to logo position
199  glTranslated(1.7, 0, 0);
200  // Rotate depending of myBlockIconRotation
201  glRotated(90, 0, 0, 1);
202  // draw E2 logo
203  if (isAdditionalSelected()) {
205  } else {
206  GLHelper::drawText("Exit", Position(), .1, 1, RGBColor(204, 0, 0));
207  }
208  // pop matrix
209  glPopMatrix();
210 
211  // Show Lock icon depending of the Edit mode
212  drawLockIcon(0.4);
213  }
214  // Draw name
215  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
216 
217  // pop gl identificator
218  glPopName();
219 }
220 
221 
222 std::string
224  switch (key) {
225  case SUMO_ATTR_ID:
226  return getAdditionalID();
227  case SUMO_ATTR_LANE:
229  case SUMO_ATTR_POSITION:
234  return toString(myBlocked);
235  default:
236  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
237  }
238 }
239 
240 
241 void
242 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
243  if (value == getAttribute(key)) {
244  return; //avoid needless changes, later logic relies on the fact that attributes have changed
245  }
246  switch (key) {
247  case SUMO_ATTR_ID:
248  case SUMO_ATTR_LANE:
249  case SUMO_ATTR_POSITION:
252  undoList->p_add(new GNEChange_Attribute(this, key, value));
253  updateGeometry();
254  break;
255  default:
256  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
257  }
258 
259 }
260 
261 
262 bool
263 GNEDetectorExit::isValid(SumoXMLAttr key, const std::string& value) {
264  switch (key) {
265  case SUMO_ATTR_ID:
266  if (isValidID(value) && (myViewNet->getNet()->getAdditional(getTag(), value) == NULL)) {
267  return true;
268  } else {
269  return false;
270  }
271  case SUMO_ATTR_LANE:
272  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
273  return true;
274  } else {
275  return false;
276  }
277  case SUMO_ATTR_POSITION:
278  return canParse<double>(value);
280  return canParse<bool>(value);
282  return canParse<bool>(value);
283  default:
284  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
285  }
286 }
287 
288 void
289 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value) {
290  switch (key) {
291  case SUMO_ATTR_ID:
292  setAdditionalID(value);
293  break;
294  case SUMO_ATTR_LANE:
295  changeLane(value);
296  break;
297  case SUMO_ATTR_POSITION:
298  myPositionOverLane = parse<double>(value) / myLane->getLaneParametricLength();
299  updateGeometry();
300  getViewNet()->update();
301  break;
303  myFriendlyPosition = parse<bool>(value);
304  getViewNet()->update();
305  break;
307  myBlocked = parse<bool>(value);
308  getViewNet()->update();
309  break;
310  default:
311  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
312  }
313 }
314 
315 /****************************************************************************/
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
void setBlockIconRotation()
bool isDetectorPositionFixed() const
check if Position of detector is fixed
double scale
information about a lane&#39;s width (temporary, used for a single view)
GUIVisualizationTextSettings addName
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
double x() const
Returns the x-position.
Definition: Position.h:63
GNELane * myLane
The lane this additional belongs.
Stores the information about how to visualize structures.
bool isAdditionalSelected() const
GNEDetectorE3 * getE3Parent() const
get E3 Detector parent
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
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::vector< double > myShapeRotations
GUIGlID getGlID() const
Returns the numerical id of the object.
GNEDetectorExit(GNEViewNet *viewNet, GNEDetectorE3 *parent, GNELane *lane, double pos, bool friendlyPos)
Constructor.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:112
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
const std::string & getAdditionalID() const
returns the ID of additional
void updateGeometry()
update pre-computed geometry information
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:998
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
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:958
friend class GNEChange_Attribute
declare friend class
double y() const
Returns the y-position.
Definition: Position.h:68
block movement of a graphic element
double length() const
Returns the length.
std::vector< double > myShapeLengths
The lengths of the shape parts.
double getAbsolutePositionOverLane() const
get absolute position over Lane
void setAdditionalID(const std::string &id)
set the ID of additional
void drawLockIcon(double size=0.5) const
draw lock icon
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:164
void changeLane(const std::string &laneID)
change lane of additional
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
Definition: GNELane.cpp:770
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1680
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:625
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
GNENet * getNet() const
get the net object
Position getLineCenter() const
get line center
SumoXMLTag getTag() const
get XML Tag assigned to this object
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:417
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
void writeAdditional(OutputDevice &device, bool volatileOptionsEnabled) const
writte additional element into a xml file
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:126
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0)
draw Text with given parameters
Definition: GLHelper.cpp:455
GNEDetectorE3 * myE3Parent
pointer to E3 parent
void updateGeometry()
update pre-computed geometry information
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:719
double myBlockIconRotation
The rotation of the block icon.
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:155
Position myBlockIconPosition
position of the block icon