Eclipse SUMO - Simulation of Urban MObility
GNEEntryExitDetector.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 
21 #include <netedit/GNENet.h>
22 #include <netedit/GNEUndoList.h>
23 #include <netedit/GNEViewNet.h>
24 #include <netedit/GNEViewParent.h>
27 #include <utils/gui/div/GLHelper.h>
30 
31 #include "GNEEntryExitDetector.h"
32 #include "GNEAdditionalHandler.h"
33 
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
40  GNEDetector("", net, GLO_DET_ENTRY, entryExitTag, GUIIconSubSys::getIcon(GUIIcon::E3ENTRY), 0, 0, {}, "", {}, "", false, Parameterised::Map()) {
41  // reset default values
42  resetDefaultValues();
43 }
44 
45 
46 GNEEntryExitDetector::GNEEntryExitDetector(SumoXMLTag entryExitTag, GNENet* net, GNEAdditional* parent, GNELane* lane, const double pos,
47  const bool friendlyPos, const Parameterised::Map& parameters) :
48  GNEDetector(parent, net, GLO_DET_ENTRY, entryExitTag, GUIIconSubSys::getIcon(GUIIcon::E3ENTRY), pos, 0, {
49  lane
50 }, "", "", friendlyPos, parameters) {
51  // update centering boundary without updating grid
52  updateCenteringBoundary(false);
53 }
54 
55 
57 
58 
59 void
61  device.openTag(getTagProperty().getTag());
62  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
64  if (myFriendlyPosition) {
65  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
66  }
67  device.closeTag();
68 }
69 
70 
71 bool
73  // with friendly position enabled position are "always fixed"
74  if (myFriendlyPosition) {
75  return true;
76  } else {
77  return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
78  }
79 }
80 
81 
82 std::string
84  // obtain final length
85  const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
86  // check if detector has a problem
88  return "";
89  } else {
90  // declare variable for error position
91  std::string errorPosition;
92  // check positions over lane
93  if (myPositionOverLane < 0) {
94  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
95  }
96  if (myPositionOverLane > len) {
97  errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
98  }
99  return errorPosition;
100  }
101 }
102 
103 
104 void
106  // declare new position
107  double newPositionOverLane = myPositionOverLane;
108  // fix pos and length checkAndFixDetectorPosition
109  double length = 0;
110  GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
111  // set new position
112  setAttribute(SUMO_ATTR_POSITION, toString(newPositionOverLane), myNet->getViewNet()->getUndoList());
113 }
114 
115 
116 void
118  // update geometry
120  // update centering boundary without updating grid
122 }
123 
124 
125 void
127  // Set initial values
128  const double entryExitExaggeration = getExaggeration(s);
129  // first check if additional has to be drawn
131  // get detail level
132  const auto d = s.getDetailLevel(entryExitExaggeration);
133  // draw geometry only if we'rent in drawForObjectUnderCursor mode
134  if (!s.drawForViewObjectsHandler) {
135  // draw parent and child lines
137  // Push layer matrix
139  // translate to front
141  // Set color
142  RGBColor color;
143  if (drawUsingSelectColor()) {
145  } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
146  color = s.detectorSettings.E3EntryColor;
147  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
148  color = s.detectorSettings.E3ExitColor;
149  }
150  // draw parts
151  drawBody(d, color, entryExitExaggeration);
152  drawEntryLogo(d, color, entryExitExaggeration);
153  drawE3Logo(d, color, entryExitExaggeration);
154  // pop layer matrix
156  // draw additional name
158  // draw lock icon
160  // draw dotted contour
162  }
163  // calculate contour
165  myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration);
166  }
167 }
168 
169 
170 std::string
172  switch (key) {
173  case SUMO_ATTR_ID:
174  return getParentAdditionals().front()->getID();
175  case SUMO_ATTR_LANE:
176  return getParentLanes().front()->getID();
177  case SUMO_ATTR_POSITION:
181  case GNE_ATTR_PARENT:
182  return getParentAdditionals().at(0)->getID();
183  case GNE_ATTR_SELECTED:
185  case GNE_ATTR_PARAMETERS:
186  return getParametersStr();
188  return "";
189  default:
190  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
191  }
192 }
193 
194 
195 double
197  switch (key) {
198  case SUMO_ATTR_POSITION:
199  return myPositionOverLane;
200  default:
201  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
202  }
203 }
204 
205 
206 void
207 GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
208  switch (key) {
209  case SUMO_ATTR_LANE:
210  case SUMO_ATTR_POSITION:
212  case GNE_ATTR_PARENT:
213  case GNE_ATTR_SELECTED:
214  case GNE_ATTR_PARAMETERS:
216  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
217  break;
218  default:
219  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
220  }
221 }
222 
223 
224 bool
225 GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
226  switch (key) {
227  case SUMO_ATTR_LANE:
228  return (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr);
229  case SUMO_ATTR_POSITION:
230  return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
232  return canParse<bool>(value);
233  case GNE_ATTR_PARENT:
234  return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
235  case GNE_ATTR_SELECTED:
236  return canParse<bool>(value);
237  case GNE_ATTR_PARAMETERS:
238  return areParametersValid(value);
239  default:
240  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
241  }
242 }
243 
244 
245 void
247  const RGBColor& color, const double exaggeration) const {
248  // check detail level
250  // Push polygon matrix
252  // set color
253  GLHelper::setColor(color);
254  // set polygon mode
255  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
256  // move to position
257  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
258  // rotate over lane
260  // scale
261  glScaled(exaggeration, exaggeration, 1);
262  // check detail level
264  // Draw polygon
265  glBegin(GL_LINES);
266  glVertex2d(1.7, 0);
267  glVertex2d(-1.7, 0);
268  glEnd();
269  glBegin(GL_QUADS);
270  glVertex2d(-1.7, .5);
271  glVertex2d(-1.7, -.5);
272  glVertex2d(1.7, -.5);
273  glVertex2d(1.7, .5);
274  glEnd();
275  // first Arrow
276  glTranslated(1.5, 0, 0);
277  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
278  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
279  // second Arrow
280  glTranslated(-3, 0, 0);
281  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
282  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
283  } else {
284  // Draw square in drawy for selecting mode
285  glBegin(GL_QUADS);
286  glVertex2d(-1.7, 4.3);
287  glVertex2d(-1.7, -.5);
288  glVertex2d(1.7, -.5);
289  glVertex2d(1.7, 4.3);
290  glEnd();
291  }
292  // Pop polygon matrix
294  }
295 }
296 
297 
298 void
300  const RGBColor& color, const double exaggeration) const {
301  // check detail level
303  // Push matrix
305  // set color
306  GLHelper::setColor(color);
307  // Traslate to center of detector
308  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
309  // rotate over lane
311  //move to logo position
312  glTranslated(1.9, 0, 0);
313  // scale
314  glScaled(exaggeration, exaggeration, 1);
315  //move to logo position
316  glTranslated(1.7, 0, 0);
317  // rotate 90 degrees lane
318  glRotated(90, 0, 0, 1);
319  // draw Entry or Exit text if isn't being drawn for selecting
322  GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
323  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
324  GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
325  }
326  } else {
327  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
328  }
329  // pop matrix
331  }
332 }
333 
334 
335 void
337  const RGBColor& color, const double exaggeration) const {
338  // check detail level
340  // Push matrix
342  // set color
343  GLHelper::setColor(color);
344  // Traslate to center of detector
345  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
346  // rotate over lane
348  //move to logo position
349  glTranslated(1.9, 0, 0);
350  // scale
351  glScaled(exaggeration, exaggeration, 1);
352  // draw E3 logo
353  GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
354  // pop matrix
356  }
357 }
358 
359 
360 void
361 GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
362  switch (key) {
363  case SUMO_ATTR_LANE:
365  break;
366  case SUMO_ATTR_POSITION:
367  myPositionOverLane = parse<double>(value);
368  break;
370  myFriendlyPosition = parse<bool>(value);
371  break;
372  case GNE_ATTR_PARENT:
374  break;
375  case GNE_ATTR_SELECTED:
376  if (parse<bool>(value)) {
378  } else {
380  }
381  break;
382  case GNE_ATTR_PARAMETERS:
383  setParametersStr(value);
384  break;
386  shiftLaneIndex();
387  break;
388  default:
389  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
390  }
391 }
392 
393 
394 void
396  // change position
397  myPositionOverLane = moveResult.newFirstPos;
398  // set lateral offset
400  // update geometry
401  updateGeometry();
402 }
403 
404 
405 void
407  // reset lateral offset
409  // begin change attribute
410  undoList->begin(this, "position of " + getTagStr());
411  // set startPosition
412  setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
413  // check if lane has to be changed
414  if (moveResult.newFirstLane) {
415  // set new lane
416  setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
417  }
418  // end change attribute
419  undoList->end();
420 }
421 
422 /****************************************************************************/
@ GLO_DET_ENTRY
a DetEntry detector
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
#define TL(string)
Definition: MsgHandler.h:315
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_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ 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
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:655
static void drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth, const double extraOffset=0)
Draws a triangle at the end of the given line.
Definition: GLHelper.cpp:630
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:295
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
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:757
static bool checkLanePosition(double pos, const double length, const double laneLength, const bool friendlyPos)
check if the given position over a lane is valid
static void fixLanePosition(double &pos, double &length, const double laneLength)
fix given position over lane
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
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
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double scale) const
calculate contour (for rectangled elements)
Definition: GNEContour.cpp:103
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:263
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:188
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:200
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
double getAttributeDouble(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
std::string getAdditionalProblem() const
return a string with the current additional problem
bool isAdditionalValid() const
check if current additional is valid to be written into XML
void fixAdditionalProblem()
fix additional problem
void drawBody(const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw body
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void updateGeometry()
update pre-computed geometry information
~GNEEntryExitDetector()
destructor
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
void drawE3Logo(const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw E3 logo
void drawEntryLogo(const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw entry logo
GNEEntryExitDetector(SumoXMLTag entryExitTag, GNENet *net)
default Constructor
std::string getAttribute(SumoXMLAttr key) const
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:46
double myMoveElementLateralOffset
move element lateral offset (used by elements placed over lanes
move result
const GNELane * newFirstLane
new first Lane
double newFirstPos
new first position
double firstLaneOffset
lane offset
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:121
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2022
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:727
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEUndoList * getUndoList() const
get the undoList object
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
Definition: GNEViewNet.cpp:945
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
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)
update entire geometry
Definition: GUIGeometry.cpp:59
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:156
Stores the information about how to visualize structures.
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
GUIVisualizationDetectorSettings detectorSettings
Detector settings.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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:37
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const RGBColor E3ExitColor
color for Exits
static const RGBColor E3EntryColor
color for Entrys
static const double segmentWidth
width of dotted contour segments