Eclipse SUMO - Simulation of Urban MObility
GNEDetectorEntryExit.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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <netedit/GNENet.h>
21 #include <netedit/GNEUndoList.h>
22 #include <netedit/GNEViewNet.h>
24 #include <utils/gui/div/GLHelper.h>
26 
27 #include "GNEDetectorEntryExit.h"
28 #include "GNEAdditionalHandler.h"
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
35 GNEDetectorEntryExit::GNEDetectorEntryExit(SumoXMLTag entryExitTag, GNENet* net, GNEAdditional* parent, GNELane* lane, double pos, bool friendlyPos, bool blockMovement) :
36  GNEDetector(parent, net, GLO_DET_ENTRY, entryExitTag, pos, "", "", "", friendlyPos, blockMovement, {
37  lane
38 }) {
39  // check that this is a Entry/Exit
40  if ((entryExitTag != SUMO_TAG_DET_ENTRY) && (entryExitTag != SUMO_TAG_DET_EXIT)) {
41  throw InvalidArgument("Invalid E3 Child Tag");
42  }
43  // update centering boundary without updating grid
44  updateCenteringBoundary(false);
45 }
46 
47 
49 
50 
51 bool
53  // with friendly position enabled position are "always fixed"
54  if (myFriendlyPosition) {
55  return true;
56  } else {
57  return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
58  }
59 }
60 
61 
62 std::string
64  // declare variable for error position
65  std::string errorPosition;
66  const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
67  // check positions over lane
68  if (myPositionOverLane < -len) {
69  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
70  }
71  if (myPositionOverLane > len) {
72  errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
73  }
74  return errorPosition;
75 }
76 
77 
78 void
80  // declare new position
81  double newPositionOverLane = myPositionOverLane;
82  // fix pos and length checkAndFixDetectorPosition
83  GNEAdditionalHandler::checkAndFixDetectorPosition(newPositionOverLane, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), true);
84  // set new position
86 }
87 
88 
89 void
91  // update geometry
93  // update E3 parent children
94  getParentAdditionals().at(0)->updateHierarchicalConnections();
95 }
96 
97 
98 void
100  // Set initial values
101  const double entryExitExaggeration = s.addSize.getExaggeration(s, this);
102  // first check if additional has to be drawn
103  if (s.drawAdditionals(entryExitExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
104  // Start drawing adding gl identificator
105  glPushName(getGlID());
106  // Push layer matrix
107  glPushMatrix();
108  // translate to front
110  // Set color
111  if (drawUsingSelectColor()) {
113  } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
115  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
117  }
118  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
119  // Push polygon matrix
120  glPushMatrix();
121  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
122  // rotate over lane
124  // scale
125  glScaled(entryExitExaggeration, entryExitExaggeration, 1);
126  // draw details if isn't being drawn for selecting
127  if (!s.drawForRectangleSelection) {
128  // Draw polygon
129  glBegin(GL_LINES);
130  glVertex2d(1.7, 0);
131  glVertex2d(-1.7, 0);
132  glEnd();
133  glBegin(GL_QUADS);
134  glVertex2d(-1.7, .5);
135  glVertex2d(-1.7, -.5);
136  glVertex2d(1.7, -.5);
137  glVertex2d(1.7, .5);
138  glEnd();
139  // first Arrow
140  glTranslated(1.5, 0, 0);
141  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
142  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
143  // second Arrow
144  glTranslated(-3, 0, 0);
145  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
146  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
147  } else {
148  // Draw square in drawy for selecting mode
149  glBegin(GL_QUADS);
150  glVertex2d(-1.7, 4.3);
151  glVertex2d(-1.7, -.5);
152  glVertex2d(1.7, -.5);
153  glVertex2d(1.7, 4.3);
154  glEnd();
155  }
156  // Pop polygon matrix
157  glPopMatrix();
158  // Check if the distance is enought to draw details
159  if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.detectorDetails, entryExitExaggeration)) {
160  // Push matrix
161  glPushMatrix();
162  // Traslate to center of detector
163  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
164  // rotate over lane
166  //move to logo position
167  glTranslated(1.9, 0, 0);
168  // scale
169  glScaled(entryExitExaggeration, entryExitExaggeration, 1);
170  // draw Entry or Exit logo if isn't being drawn for selecting
173  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
174  } else if (drawUsingSelectColor()) {
176  } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
177  GLHelper::drawText("E3", Position(), .1, 2.8, s.detectorSettings.E3EntryColor, 180);
178  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
179  GLHelper::drawText("E3", Position(), .1, 2.8, s.detectorSettings.E3ExitColor, 180);
180  }
181  //move to logo position
182  glTranslated(1.7, 0, 0);
183  // rotate 90 degrees lane
184  glRotated(90, 0, 0, 1);
185  // draw Entry or Exit text if isn't being drawn for selecting
188  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
189  } else if (drawUsingSelectColor()) {
192  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
194  }
195  } else {
197  GLHelper::drawText("Entry", Position(), .1, 1, s.detectorSettings.E3EntryColor, 180);
198  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
199  GLHelper::drawText("Exit", Position(), .1, 1, s.detectorSettings.E3ExitColor, 180);
200  }
201  }
202  // pop matrix
203  glPopMatrix();
204  }
205  // draw lock icon
206  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, entryExitExaggeration, 0, 0, true, 0.4);
207  // Pop layer matrix
208  glPopMatrix();
209  // check if dotted contour has to be drawn
211  // GNEGeometry::drawShapeDottedContour(s, getType(), entryExitExaggeration, myDottedGeometry);
212  }
213  // pop gl identificator
214  glPopName();
215  // draw additional name
217  }
218 }
219 
220 
221 std::string
223  switch (key) {
224  case SUMO_ATTR_ID:
225  return getParentAdditionals().front()->getID();
226  case SUMO_ATTR_LANE:
227  return getParentLanes().front()->getID();
228  case SUMO_ATTR_POSITION:
233  return toString(myBlockMovement);
234  case GNE_ATTR_PARENT:
235  return getParentAdditionals().at(0)->getID();
236  case GNE_ATTR_SELECTED:
238  case GNE_ATTR_PARAMETERS:
239  return getParametersStr();
240  default:
241  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
242  }
243 }
244 
245 
246 void
247 GNEDetectorEntryExit::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
248  if (value == getAttribute(key)) {
249  return; //avoid needless changes, later logic relies on the fact that attributes have changed
250  }
251  switch (key) {
252  case SUMO_ATTR_LANE:
253  case SUMO_ATTR_POSITION:
256  case GNE_ATTR_PARENT:
257  case GNE_ATTR_SELECTED:
258  case GNE_ATTR_PARAMETERS:
259  undoList->p_add(new GNEChange_Attribute(this, key, value));
260  break;
261  default:
262  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
263  }
264 }
265 
266 
267 bool
268 GNEDetectorEntryExit::isValid(SumoXMLAttr key, const std::string& value) {
269  switch (key) {
270  case SUMO_ATTR_LANE:
271  return (myNet->retrieveLane(value, false) != nullptr);
272  case SUMO_ATTR_POSITION:
273  return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
275  return canParse<bool>(value);
277  return canParse<bool>(value);
278  case GNE_ATTR_PARENT:
279  return (myNet->retrieveAdditional(SUMO_TAG_E3DETECTOR, value, false) != nullptr);
280  case GNE_ATTR_SELECTED:
281  return canParse<bool>(value);
282  case GNE_ATTR_PARAMETERS:
283  return Parameterised::areParametersValid(value);
284  default:
285  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
286  }
287 }
288 
289 
290 bool
292  return true;
293 }
294 
295 
296 void
297 GNEDetectorEntryExit::setAttribute(SumoXMLAttr key, const std::string& value) {
298  switch (key) {
299  case SUMO_ATTR_LANE:
301  break;
302  case SUMO_ATTR_POSITION:
303  myPositionOverLane = parse<double>(value);
304  break;
306  myFriendlyPosition = parse<bool>(value);
307  break;
309  myBlockMovement = parse<bool>(value);
310  break;
311  case GNE_ATTR_PARENT:
313  break;
314  case GNE_ATTR_SELECTED:
315  if (parse<bool>(value)) {
317  } else {
319  }
320  break;
321  case GNE_ATTR_PARAMETERS:
322  setParametersStr(value);
323  break;
324  default:
325  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
326  }
327 }
328 
329 
330 /****************************************************************************/
@ GLO_DET_ENTRY
a DetEntry detector
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_DET_ENTRY
an e3 entry point
@ SUMO_TAG_DET_EXIT
an e3 exit point
@ SUMO_TAG_E3DETECTOR
an e3 detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
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:425
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
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, const int align=0, double width=-1)
Definition: GLHelper.cpp:498
static bool checkAndFixDetectorPosition(double &pos, const double laneLength, const bool friendlyPos)
check if the position of a detector over a lane is valid
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
GNEDetectorEntryExit(SumoXMLTag entryExitTag, GNENet *net, GNEAdditional *parent, GNELane *lane, double pos, bool friendlyPos, bool blockMovement)
Constructor.
std::string getAdditionalProblem() const
return a string with the current additional problem
bool isAttributeEnabled(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getAttribute(SumoXMLAttr key) const
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (by default true, can be reimplemented in ...
void fixAdditionalProblem()
fix additional problem
~GNEDetectorEntryExit()
destructor
void updateGeometry()
update pre-computed geometry information
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:163
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:175
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1337
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2316
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
Stores the information about how to visualize structures.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawDottedContour() const
check if dotted contour can be drawn
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationDetectorSettings detectorSettings
Detector settings.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double detectorDetails
details for detectors
static const RGBColor E3ExitColor
color for Exits
static const RGBColor E3EntryColor
color for Entrys
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values