Eclipse SUMO - Simulation of Urban MObility
GNEMultiEntryExitDetector.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 
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
36  GNEAdditional("", net, GLO_E3DETECTOR, SUMO_TAG_ENTRY_EXIT_DETECTOR, GUIIconSubSys::getIcon(GUIIcon::E3ENTRY), "", {}, {}, {}, {}, {}, {}) {
37  // reset default values
38  resetDefaultValues();
39 }
40 
41 
42 GNEMultiEntryExitDetector::GNEMultiEntryExitDetector(const std::string& id, GNENet* net, const Position pos, const SUMOTime freq, const std::string& filename,
43  const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges, const std::string& detectPersons, const std::string& name,
44  const SUMOTime timeThreshold, const double speedThreshold, const bool openEntry, const bool expectedArrival, const Parameterised::Map& parameters) :
45  GNEAdditional(id, net, GLO_E3DETECTOR, SUMO_TAG_ENTRY_EXIT_DETECTOR, GUIIconSubSys::getIcon(GUIIcon::E3EXIT), name, {}, {}, {}, {}, {}, {}),
46  Parameterised(parameters),
47  myPosition(pos),
48  myPeriod(freq),
49  myFilename(filename),
50  myVehicleTypes(vehicleTypes),
51  myNextEdges(nextEdges),
52  myDetectPersons(detectPersons),
53  myTimeThreshold(timeThreshold),
54  mySpeedThreshold(speedThreshold),
55  myOpenEntry(openEntry),
56 myExpectedArrival(expectedArrival) {
57  // update centering boundary without updating grid
58  updateCenteringBoundary(false);
59 }
60 
61 
63 
64 
67  // return move operation for additional placed in view
68  return new GNEMoveOperation(this, myPosition);
69 }
70 
71 
72 void
74  bool entry = false;
75  bool exit = false;
76  // first check if E3 has at least one entry and one exit
77  for (const auto& additionalChild : getChildAdditionals()) {
78  if (additionalChild->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
79  entry = true;
80  } else if (additionalChild->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
81  exit = true;
82  }
83  }
84  // check entry/exits
85  if (entry && exit) {
86  device.openTag(getTagProperty().getTag());
87  device.writeAttr(SUMO_ATTR_ID, getID());
88  if (!myAdditionalName.empty()) {
90  }
92  if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
94  }
95  if (myFilename.size() > 0) {
97  }
98  if (myVehicleTypes.size() > 0) {
100  }
103  }
106  }
109  }
112  }
113  // write all entry/exits
114  for (const auto& access : getChildAdditionals()) {
115  access->writeAdditional(device);
116  }
117  // write parameters (Always after children to avoid problems with additionals.xsd)
118  writeParams(device);
119  device.closeTag();
120  } else {
121  WRITE_WARNING("E3 '" + getID() + TL("' needs at least one entry and one exit"));
122  }
123 }
124 
125 
126 bool
128  return true;
129 }
130 
131 
132 std::string
134  return "";
135 }
136 
137 
138 void
140  // nothing to fix
141 }
142 
143 
144 bool
146  // get edit modes
147  const auto& editModes = myNet->getViewNet()->getEditModes();
148  // check if we're in move mode
149  if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
151  (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
152  // only move the first element
154  } else {
155  return false;
156  }
157 }
158 
159 
160 void
162  // update additional geometry
164 }
165 
166 
167 Position
169  return myPosition;
170 }
171 
172 
173 void
175  // remove additional from grid
176  if (updateGrid) {
178  }
179  // now update geometry
180  updateGeometry();
181  // add shape boundary
183  // grow
185  // add additional into RTREE again
186  if (updateGrid) {
187  myNet->addGLObjectIntoGrid(this);
188  }
189 }
190 
191 
192 void
193 GNEMultiEntryExitDetector::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
194  // geometry of this element cannot be splitted
195 }
196 
197 
198 std::string
200  return myNet->getMicrosimID();
201 }
202 
203 
204 void
206  // first check if additional has to be drawn
209  // draw parent and child lines
211  // draw E3
213  }
214 }
215 
216 
217 std::string
219  switch (key) {
220  case SUMO_ATTR_ID:
221  return getMicrosimID();
222  case SUMO_ATTR_POSITION:
223  return toString(myPosition);
224  case SUMO_ATTR_PERIOD:
225  if (myPeriod == SUMOTime_MAX_PERIOD) {
226  return "";
227  } else {
228  return time2string(myPeriod);
229  }
230  case SUMO_ATTR_NAME:
231  return myAdditionalName;
232  case SUMO_ATTR_FILE:
233  return myFilename;
234  case SUMO_ATTR_VTYPES:
235  return toString(myVehicleTypes);
237  return toString(myNextEdges);
239  return toString(myDetectPersons);
243  return toString(mySpeedThreshold);
245  return toString(myOpenEntry);
247  return toString(myExpectedArrival);
248  case GNE_ATTR_SELECTED:
250  case GNE_ATTR_PARAMETERS:
251  return getParametersStr();
252  default:
253  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
254  }
255 }
256 
257 
258 double
260  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
261 }
262 
263 
264 const Parameterised::Map&
266  return getParametersMap();
267 }
268 
269 
270 void
271 GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
272  if (value == getAttribute(key)) {
273  return; //avoid needless changes, later logic relies on the fact that attributes have changed
274  }
275  switch (key) {
276  case SUMO_ATTR_ID:
277  case SUMO_ATTR_PERIOD:
278  case SUMO_ATTR_POSITION:
279  case SUMO_ATTR_NAME:
280  case SUMO_ATTR_FILE:
281  case SUMO_ATTR_VTYPES:
288  case GNE_ATTR_SELECTED:
289  case GNE_ATTR_PARAMETERS:
290  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
291  break;
292  default:
293  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
294  }
295 }
296 
297 
298 bool
299 GNEMultiEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
300  switch (key) {
301  case SUMO_ATTR_ID:
302  return isValidDetectorID(value);
303  case SUMO_ATTR_POSITION:
304  return canParse<Position>(value);
305  case SUMO_ATTR_PERIOD:
306  if (value.empty()) {
307  return true;
308  } else {
309  return (canParse<double>(value) && (parse<double>(value) >= 0));
310  }
311  case SUMO_ATTR_NAME:
313  case SUMO_ATTR_FILE:
315  case SUMO_ATTR_VTYPES:
316  if (value.empty()) {
317  return true;
318  } else {
320  }
322  if (value.empty()) {
323  return true;
324  } else {
326  }
328  if (value.empty()) {
329  return true;
330  } else {
332  }
335  return canParse<double>(value) && (parse<double>(value) >= 0);
338  return canParse<bool>(value);
339  case GNE_ATTR_SELECTED:
340  return canParse<bool>(value);
341  case GNE_ATTR_PARAMETERS:
342  return areParametersValid(value);
343  default:
344  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
345  }
346 }
347 
348 
349 bool
351  int numEntrys = 0;
352  int numExits = 0;
353  // iterate over additional chidls and obtain number of entrys and exits
354  for (auto i : getChildAdditionals()) {
355  if (i->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
356  numEntrys++;
357  } else if (i->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
358  numExits++;
359  }
360  }
361  // write warnings
362  if (numEntrys == 0) {
363  WRITE_WARNING(TL("An entry-exit detector needs at least one entry detector"));
364  }
365  if (numExits == 0) {
366  WRITE_WARNING(TL("An entry-exit detector needs at least one exit detector"));
367  }
368  // return false depending of number of Entrys and Exits
369  return ((numEntrys != 0) && (numExits != 0));
370 }
371 
372 
373 std::string
375  return getTagStr() + ":" + getID();
376 }
377 
378 
379 std::string
381  return getTagStr();
382 }
383 
384 // ===========================================================================
385 // private
386 // ===========================================================================
387 
388 void
389 GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
390  switch (key) {
391  case SUMO_ATTR_ID:
392  // update microsimID
393  setAdditionalID(value);
394  break;
395  case SUMO_ATTR_POSITION:
396  myPosition = parse<Position>(value);
397  // update boundary (except for template)
398  if (getID().size() > 0) {
400  }
401  break;
402  case SUMO_ATTR_PERIOD:
403  if (value.empty()) {
405  } else {
406  myPeriod = string2time(value);
407  }
408  break;
409  case SUMO_ATTR_NAME:
410  myAdditionalName = value;
411  break;
412  case SUMO_ATTR_FILE:
413  myFilename = value;
414  break;
415  case SUMO_ATTR_VTYPES:
416  myVehicleTypes = parse<std::vector<std::string> >(value);
417  break;
419  myNextEdges = parse<std::vector<std::string> >(value);
420  break;
422  myDetectPersons = value;
423  break;
425  myTimeThreshold = parse<SUMOTime>(value);
426  break;
428  mySpeedThreshold = parse<double>(value);
429  break;
431  myOpenEntry = parse<bool>(value);
432  break;
434  myExpectedArrival = parse<bool>(value);
435  break;
436  case GNE_ATTR_SELECTED:
437  if (parse<bool>(value)) {
439  } else {
441  }
442  break;
443  case GNE_ATTR_PARAMETERS:
444  setParametersStr(value);
445  break;
446  default:
447  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
448  }
449 }
450 
451 
452 void
454  // update position
455  myPosition = moveResult.shapeToUpdate.front();
456  // update geometry
457  updateGeometry();
458 }
459 
460 
461 void
463  undoList->begin(this, "position of " + getTagStr());
465  undoList->end();
466 }
467 
468 
469 /****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition: GUI.h:35
@ GLO_E3DETECTOR
a E3 detector
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:295
#define TL(string)
Definition: MsgHandler.h:315
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#define SUMOTime_MAX_PERIOD
Definition: SUMOTime.h:36
@ 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_EXPECT_ARRIVAL
@ SUMO_ATTR_NEXT_EDGES
@ SUMO_ATTR_FILE
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_HALTING_SPEED_THRESHOLD
@ SUMO_ATTR_ID
@ SUMO_ATTR_OPEN_ENTRY
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_DETECT_PERSONS
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:319
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
void setAdditionalID(const std::string &newID)
set additional ID
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
bool isValidDetectorID(const std::string &value) const
check if a new detector ID is valid
std::string myAdditionalName
name of additional
void drawSquaredAdditional(const GUIVisualizationSettings &s, const Position &pos, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
Boundary myAdditionalBoundary
Additional Boundary (used only by additionals placed over grid)
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
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
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
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
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool myExpectedArrival
flag for enable/disable expected arrival
bool checkDrawMoveContour() const
check if draw move contour (red)
std::string getAttribute(SumoXMLAttr key) const
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::vector< std::string > myNextEdges
next edges
std::vector< std::string > myVehicleTypes
attribute vehicle types
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
SUMOTime myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
bool checkChildAdditionalRestriction() const
check restriction with the number of children
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
Position myPosition
position of E3 in view
double getAttributeDouble(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
Position getPositionInView() const
Returns position of additional in view.
std::string getParentName() const
Returns the name of the parent object.
std::string myDetectPersons
detect persons
~GNEMultiEntryExitDetector()
GNEMultiEntryExitDetector Destructor.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
GNEMultiEntryExitDetector(GNENet *net)
default constructor
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
SUMOTime myPeriod
period of E3 detector
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
const Parameterised::Map & getACParametersMap() const
get parameters map
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
bool myOpenEntry
@brie open entry
void updateGeometry()
update pre-computed geometry information
GNEMoveOperation * getMoveOperation()
get move operation
std::string myFilename
fielname of E3 detector
double mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1368
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1378
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2136
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
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 GUIGlObject * getGUIGlObjectFront() const
get front attribute carrier or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:747
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:723
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
Definition: GNEViewNet.cpp:759
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
Definition: GNEViewNet.cpp:477
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
Definition: GNEViewNet.cpp:940
void updateSinglePosGeometry(const Position &position, const double rotation)
update position and rotation
const PositionVector & getShape() const
The shape of the additional element.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
Stores the information about how to visualize structures.
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.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
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"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static StringBijection< PersonMode > PersonModeValues
person modes
static bool isValidListOfNetIDs(const std::string &value)
whether the given string is a valid list of id for a network (empty aren't allowed)
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren't allowed)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
bool hasString(const std::string &str) const
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showAdditionals() const
check if additionals has to be drawn
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static const RGBColor connectionColor
connection color
static const double E3Size
E3 detector size.