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-2022 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 
36  GNEDetector("", net, GLO_DET_ENTRY, entryExitTag, 0, 0, {}, "", {}, "", false, std::map<std::string, std::string>()) {
37  // reset default values
38  resetDefaultValues();
39 }
40 
41 
42 GNEDetectorEntryExit::GNEDetectorEntryExit(SumoXMLTag entryExitTag, GNENet* net, GNEAdditional* parent, GNELane* lane, const double pos,
43  const bool friendlyPos, const std::map<std::string, std::string>& parameters) :
44  GNEDetector(parent, net, GLO_DET_ENTRY, entryExitTag, pos, 0, {
45  lane
46 }, "", "", friendlyPos, parameters) {
47  // update centering boundary without updating grid
48  updateCenteringBoundary(false);
49 }
50 
51 
53 
54 
55 void
57  device.openTag(getTagProperty().getTag());
58  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
60  if (myFriendlyPosition) {
61  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
62  }
63  device.closeTag();
64 }
65 
66 
67 bool
69  // with friendly position enabled position are "always fixed"
70  if (myFriendlyPosition) {
71  return true;
72  } else {
73  return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
74  }
75 }
76 
77 
78 std::string
80  // obtain final lenght
81  const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
82  // check if detector has a problem
84  return "";
85  } else {
86  // declare variable for error position
87  std::string errorPosition;
88  // check positions over lane
89  if (myPositionOverLane < 0) {
90  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
91  }
92  if (myPositionOverLane > len) {
93  errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
94  }
95  return errorPosition;
96  }
97 }
98 
99 
100 void
102  // declare new position
103  double newPositionOverLane = myPositionOverLane;
104  // fix pos and length checkAndFixDetectorPosition
105  GNEAdditionalHandler::fixSinglePositionOverLane(newPositionOverLane, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
106  // set new position
107  setAttribute(SUMO_ATTR_POSITION, toString(newPositionOverLane), myNet->getViewNet()->getUndoList());
108 }
109 
110 
111 void
113  // update geometry
115  // update centering boundary without updating grid
117 }
118 
119 
120 void
122  // Set initial values
123  const double entryExitExaggeration = getExaggeration(s);
124  // first check if additional has to be drawn
125  if (s.drawAdditionals(entryExitExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
126  // draw parent and child lines
128  // Start drawing adding gl identificator
130  // Push layer matrix
132  // translate to front
134  // Set color
135  if (drawUsingSelectColor()) {
137  } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
139  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
141  }
142  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
143  // Push polygon matrix
145  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
146  // rotate over lane
148  // scale
149  glScaled(entryExitExaggeration, entryExitExaggeration, 1);
150  // draw details if isn't being drawn for selecting
151  if (!s.drawForRectangleSelection) {
152  // Draw polygon
153  glBegin(GL_LINES);
154  glVertex2d(1.7, 0);
155  glVertex2d(-1.7, 0);
156  glEnd();
157  glBegin(GL_QUADS);
158  glVertex2d(-1.7, .5);
159  glVertex2d(-1.7, -.5);
160  glVertex2d(1.7, -.5);
161  glVertex2d(1.7, .5);
162  glEnd();
163  // first Arrow
164  glTranslated(1.5, 0, 0);
165  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
166  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
167  // second Arrow
168  glTranslated(-3, 0, 0);
169  GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
170  GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
171  } else {
172  // Draw square in drawy for selecting mode
173  glBegin(GL_QUADS);
174  glVertex2d(-1.7, 4.3);
175  glVertex2d(-1.7, -.5);
176  glVertex2d(1.7, -.5);
177  glVertex2d(1.7, 4.3);
178  glEnd();
179  }
180  // Pop polygon matrix
182  // Check if the distance is enought to draw details
183  if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.detectorDetails, entryExitExaggeration)) {
184  // Push matrix
186  // Traslate to center of detector
187  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
188  // rotate over lane
190  //move to logo position
191  glTranslated(1.9, 0, 0);
192  // scale
193  glScaled(entryExitExaggeration, entryExitExaggeration, 1);
194  // draw Entry or Exit logo if isn't being drawn for selecting
197  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
198  } else if (drawUsingSelectColor()) {
200  } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
201  GLHelper::drawText("E3", Position(), .1, 2.8, s.detectorSettings.E3EntryColor, 180);
202  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
203  GLHelper::drawText("E3", Position(), .1, 2.8, s.detectorSettings.E3ExitColor, 180);
204  }
205  //move to logo position
206  glTranslated(1.7, 0, 0);
207  // rotate 90 degrees lane
208  glRotated(90, 0, 0, 1);
209  // draw Entry or Exit text if isn't being drawn for selecting
212  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
213  } else if (drawUsingSelectColor()) {
216  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
218  }
219  } else {
221  GLHelper::drawText("Entry", Position(), .1, 1, s.detectorSettings.E3EntryColor, 180);
222  } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
223  GLHelper::drawText("Exit", Position(), .1, 1, s.detectorSettings.E3ExitColor, 180);
224  }
225  }
226  // pop matrix
228  }
229  // Pop layer matrix
231  // draw lock icon
233  // check if dotted contour has to be drawn
236  myAdditionalGeometry.getShape().front(), 2.7, 1.6, 2, 0,
237  myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration);
238  }
239  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
241  myAdditionalGeometry.getShape().front(), 2.7, 1.6, 2, 0,
242  myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration);
243  }
244  // pop gl identificator
246  // draw additional name
248  }
249 }
250 
251 
252 std::string
254  switch (key) {
255  case SUMO_ATTR_ID:
256  return getParentAdditionals().front()->getID();
257  case SUMO_ATTR_LANE:
258  return getParentLanes().front()->getID();
259  case SUMO_ATTR_POSITION:
263  case GNE_ATTR_PARENT:
264  return getParentAdditionals().at(0)->getID();
265  case GNE_ATTR_SELECTED:
267  case GNE_ATTR_PARAMETERS:
268  return getParametersStr();
270  return "";
271  default:
272  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
273  }
274 }
275 
276 
277 double
279  switch (key) {
280  case SUMO_ATTR_POSITION:
281  return myPositionOverLane;
282  default:
283  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
284  }
285 }
286 
287 
288 void
289 GNEDetectorEntryExit::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
290  switch (key) {
291  case SUMO_ATTR_LANE:
292  case SUMO_ATTR_POSITION:
294  case GNE_ATTR_PARENT:
295  case GNE_ATTR_SELECTED:
296  case GNE_ATTR_PARAMETERS:
298  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
299  break;
300  default:
301  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
302  }
303 }
304 
305 
306 bool
307 GNEDetectorEntryExit::isValid(SumoXMLAttr key, const std::string& value) {
308  switch (key) {
309  case SUMO_ATTR_LANE:
310  return (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr);
311  case SUMO_ATTR_POSITION:
312  return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
314  return canParse<bool>(value);
315  case GNE_ATTR_PARENT:
316  return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_E3DETECTOR, value, false) != nullptr);
317  case GNE_ATTR_SELECTED:
318  return canParse<bool>(value);
319  case GNE_ATTR_PARAMETERS:
320  return Parameterised::areParametersValid(value);
321  default:
322  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
323  }
324 }
325 
326 
327 bool
329  return true;
330 }
331 
332 
333 void
334 GNEDetectorEntryExit::setAttribute(SumoXMLAttr key, const std::string& value) {
335  switch (key) {
336  case SUMO_ATTR_LANE:
338  break;
339  case SUMO_ATTR_POSITION:
340  myPositionOverLane = parse<double>(value);
341  break;
343  myFriendlyPosition = parse<bool>(value);
344  break;
345  case GNE_ATTR_PARENT:
347  break;
348  case GNE_ATTR_SELECTED:
349  if (parse<bool>(value)) {
351  } else {
353  }
354  break;
355  case GNE_ATTR_PARAMETERS:
356  setParametersStr(value);
357  break;
359  shiftLaneIndex();
360  break;
361  default:
362  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
363  }
364 }
365 
366 
367 void
369  // change position
370  myPositionOverLane = moveResult.newFirstPos;
371  // set lateral offset
373  // update geometry
374  updateGeometry();
375 }
376 
377 
378 void
380  // reset lateral offset
382  // begin change attribute
383  undoList->begin(myTagProperty.getGUIIcon(), "position of " + getTagStr());
384  // set startPosition
385  setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
386  // check if lane has to be changed
387  if (moveResult.newFirstLane) {
388  // set new lane
389  setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
390  }
391  // end change attribute
392  undoList->end();
393 }
394 
395 /****************************************************************************/
@ 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_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:507
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:485
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:231
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
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:609
static bool checkSinglePositionOverLane(double pos, const double laneLength, const bool friendlyPos)
check if the given position over a lane is valid
static void fixSinglePositionOverLane(double &pos, const double laneLength)
fix given position over lane
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getID() const
get ID
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
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 asociated 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
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
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
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.
GNEDetectorEntryExit(SumoXMLTag entryExitTag, GNENet *net)
default Constructor
std::string getAttribute(SumoXMLAttr key) const
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
bool isAdditionalValid() const
check if current additional is valid to be writed into XML
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 writeAdditional(OutputDevice &device) const
writte additional element into a xml file
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
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:174
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:186
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
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:125
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
const std::string & getID() const
get ID
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
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...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
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:58
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
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
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...
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:248
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|....
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 GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, 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 double detectorDetails
details for detectors
static const RGBColor E3ExitColor
color for Exits
static const RGBColor E3EntryColor
color for Entrys