SUMO - Simulation of Urban MObility
GNEDetectorExit.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
26 #include <netbuild/NBEdge.h>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
41 #include <netedit/GNEViewNet.h>
42 #include <netedit/GNEUndoList.h>
43 #include <netedit/GNENet.h>
45 #include <netedit/GNEViewParent.h>
47 
48 #include "GNEDetectorExit.h"
49 #include "GNEDetectorE3.h"
50 
51 
52 // ===========================================================================
53 // member method definitions
54 // ===========================================================================
55 
56 GNEDetectorExit::GNEDetectorExit(GNEViewNet* viewNet, GNEAdditional* parent, GNELane* lane, double pos, bool friendlyPos, bool blockMovement) :
57  GNEDetector(parent, viewNet, GLO_DET_EXIT, SUMO_TAG_DET_EXIT, lane, pos, 0, "", "", friendlyPos, blockMovement) {
58 }
59 
60 
62 
63 
64 void
66  // first check if object has to be removed from grid (SUMOTree)
67  if (updateGrid) {
69  }
70 
71  // Clear all containers
72  myShapeRotations.clear();
73  myShapeLengths.clear();
74 
75  // clear Shape
76  myShape.clear();
77 
78  // obtain position over lane
80  myShape.push_back(myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getLengthGeometryFactor()));
81 
82  // Save rotation (angle) of the vector constructed by points f and s
83  myShapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane) * -1);
84 
85  // Set block icon position
87 
88  // Set block icon rotation, and using their rotation for logo
90 
91  // last step is to check if object has to be added into grid (SUMOTree) again
92  if (updateGrid) {
94  }
95 
96  // update E3 parent Geometry
98 }
99 
100 
102  // with friendly position enabled position are "always fixed"
103  if (myFriendlyPosition) {
104  return true;
105  } else {
107  }
108 }
109 
110 
111 void
113  // Start drawing adding gl identificator
114  glPushName(getGlID());
115 
116  // Push detector matrix
117  glPushMatrix();
118  glTranslated(0, 0, getType());
119 
120  // Set initial values
123  } else {
125  }
126  const double exaggeration = s.addSize.getExaggeration(s);
127  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
128 
129  // Push polygon matrix
130  glPushMatrix();
131  glScaled(exaggeration, exaggeration, 1);
132  glTranslated(myShape[0].x(), myShape[0].y(), 0);
133  glRotated(myShapeRotations[0], 0, 0, 1);
134 
135  // Draw polygon
136  glBegin(GL_LINES);
137  glVertex2d(1.7, 0);
138  glVertex2d(-1.7, 0);
139  glEnd();
140  glBegin(GL_QUADS);
141  glVertex2d(-1.7, .5);
142  glVertex2d(-1.7, -.5);
143  glVertex2d(1.7, -.5);
144  glVertex2d(1.7, .5);
145  glEnd();
146 
147  // draw details if isn't being drawn for selecting
148  if (!s.drawForSelecting) {
149  // first Arrow
150  glTranslated(1.5, 0, 0);
151  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
152  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
153 
154  // second Arrow
155  glTranslated(-3, 0, 0);
156  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
157  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
158  }
159 
160  // Pop polygon matrix
161  glPopMatrix();
162 
163  // Pop detector matrix
164  glPopMatrix();
165 
166  // Check if the distance is enought to draw details
167  if (((s.scale * exaggeration) >= 10)) {
168  // Push matrix
169  glPushMatrix();
170  // Traslate to center of detector
171  glTranslated(myShape.getLineCenter().x(), myShape.getLineCenter().y(), getType() + 0.1);
172  // Rotate depending of myBlockIconRotation
173  glRotated(myBlockIconRotation, 0, 0, -1);
174  //move to logo position
175  glTranslated(1.9, 0, 0);
176  // draw Entry logo if isn't being drawn for selecting
177  if (s.drawForSelecting) {
179  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
180  } else if (isAttributeCarrierSelected()) {
182  } else {
183  GLHelper::drawText("E3", Position(), .1, 2.8, s.SUMO_color_E3Exit);
184  }
185  //move to logo position
186  glTranslated(1.7, 0, 0);
187  // Rotate depending of myBlockIconRotation
188  glRotated(90, 0, 0, 1);
189  // draw Entry text if isn't being drawn for selecting
190  if (s.drawForSelecting) {
192  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
193  } else if (isAttributeCarrierSelected()) {
195  } else {
196  GLHelper::drawText("Exit", Position(), .1, 1, s.SUMO_color_E3Exit);
197  }
198  // pop matrix
199  glPopMatrix();
200  // Show Lock icon depending of the Edit mode and if isn't being drawn for selecting
201  if (!s.drawForSelecting) {
202  drawLockIcon(0.4);
203  }
204  }
205  // Draw name if isn't being drawn for selecting
206  if (!s.drawForSelecting) {
207  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
208  }
209  // check if dotted contour has to be drawn
210  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
212  }
213  // pop gl identificator
214  glPopName();
215 }
216 
217 
218 std::string
220  switch (key) {
221  case SUMO_ATTR_ID:
222  return getAdditionalID();
223  case SUMO_ATTR_LANE:
224  return myLane->getID();
225  case SUMO_ATTR_POSITION:
230  return toString(myBlockMovement);
231  case GNE_ATTR_PARENT:
232  return myFirstAdditionalParent->getID();
233  case GNE_ATTR_SELECTED:
235  case GNE_ATTR_GENERIC:
236  return getGenericParametersStr();
237  default:
238  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
239  }
240 }
241 
242 
243 void
244 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
245  if (value == getAttribute(key)) {
246  return; //avoid needless changes, later logic relies on the fact that attributes have changed
247  }
248  switch (key) {
249  case SUMO_ATTR_ID:
250  case SUMO_ATTR_LANE:
251  case SUMO_ATTR_POSITION:
254  case GNE_ATTR_PARENT:
255  case GNE_ATTR_SELECTED:
256  case GNE_ATTR_GENERIC:
257  undoList->p_add(new GNEChange_Attribute(this, key, value));
258  break;
259  default:
260  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
261  }
262 }
263 
264 
265 bool
266 GNEDetectorExit::isValid(SumoXMLAttr key, const std::string& value) {
267  switch (key) {
268  case SUMO_ATTR_ID:
269  return isValidAdditionalID(value);
270  case SUMO_ATTR_LANE:
271  return (myViewNet->getNet()->retrieveLane(value, false) != nullptr);
272  case SUMO_ATTR_POSITION:
273  return canParse<double>(value);
275  return canParse<bool>(value);
277  return canParse<bool>(value);
278  case GNE_ATTR_PARENT:
279  return (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_E3DETECTOR, value, false) != nullptr);
280  case GNE_ATTR_SELECTED:
281  return canParse<bool>(value);
282  case GNE_ATTR_GENERIC:
283  return isGenericParametersValid(value);
284  default:
285  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
286  }
287 }
288 
289 void
290 GNEDetectorExit::setAttribute(SumoXMLAttr key, const std::string& value) {
291  switch (key) {
292  case SUMO_ATTR_ID:
293  changeAdditionalID(value);
294  break;
295  case SUMO_ATTR_LANE:
296  myLane = changeLane(myLane, value);
297  break;
298  case SUMO_ATTR_POSITION:
299  myPositionOverLane = parse<double>(value);
300  break;
302  myFriendlyPosition = parse<bool>(value);
303  break;
305  myBlockMovement = parse<bool>(value);
306  break;
307  case GNE_ATTR_PARENT:
309  break;
310  case GNE_ATTR_SELECTED:
311  if (parse<bool>(value)) {
313  } else {
315  }
316  break;
317  case GNE_ATTR_GENERIC:
319  break;
320  default:
321  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
322  }
323  // After setting attribute always update Geometry
324  updateGeometry(true);
325 }
326 
327 /****************************************************************************/
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
GUIVisualizationTextSettings addName
void updateGeometry(bool updateGrid)
update pre-computed geometry information
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
void changeFirstAdditionalParent(const std::string &newAdditionalParentID)
change first additional parent of additional
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:61
double x() const
Returns the x-position.
Definition: Position.h:56
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, int align=0, double width=-1)
Definition: GLHelper.cpp:611
GNEDetectorExit(GNEViewNet *viewNet, GNEAdditional *parent, GNELane *lane, double pos, bool friendlyPos, bool blockMovement)
Constructor.
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::vector< double > myShapeRotations
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
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.
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1787
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
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:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1230
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
~GNEDetectorExit()
destructor
an e3 exit point
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1167
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
double getLengthGeometryFactor() const
get lenght geometry factor
Definition: GNELane.cpp:1287
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
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
virtual void updateGeometry(bool updateGrid)=0
update pre-computed geometry information
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:162
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3523
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:613
bool isDetectorPositionFixed() const
check if Position of detector is fixed
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
element is selected
GNELane * myLane
The lane in which this detector is placed.
Definition: GNEDetector.h:147
std::string getGenericParametersStr() const
return generic parameters in string format
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
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:436
static const RGBColor SUMO_color_E3Exit
color for Exits
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:586
std::string getAttribute(SumoXMLAttr key) const
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1066
double myBlockIconRotation
The rotation of the block icon.
a DetExit detector
GNEAdditional * myFirstAdditionalParent
pointer to first Addititional parent
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:150
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object