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,
43  const std::string& filename, const std::vector<std::string>& vehicleTypes, const std::string& name, SUMOTime timeThreshold,
44  double speedThreshold, 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  myTimeThreshold(timeThreshold),
52  mySpeedThreshold(speedThreshold),
53 myExpectedArrival(expectedArrival) {
54  // update centering boundary without updating grid
55  updateCenteringBoundary(false);
56 }
57 
58 
60 
61 
64  // return move operation for additional placed in view
65  return new GNEMoveOperation(this, myPosition);
66 }
67 
68 
69 void
71  bool entry = false;
72  bool exit = false;
73  // first check if E3 has at least one entry and one exit
74  for (const auto& additionalChild : getChildAdditionals()) {
75  if (additionalChild->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
76  entry = true;
77  } else if (additionalChild->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
78  exit = true;
79  }
80  }
81  // check entry/exits
82  if (entry && exit) {
83  device.openTag(getTagProperty().getTag());
84  device.writeAttr(SUMO_ATTR_ID, getID());
85  if (!myAdditionalName.empty()) {
87  }
89  if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
91  }
92  if (myFilename.size() > 0) {
94  }
95  if (myVehicleTypes.size() > 0) {
97  }
100  }
103  }
106  }
107  // write all entry/exits
108  for (const auto& access : getChildAdditionals()) {
109  access->writeAdditional(device);
110  }
111  // write parameters (Always after children to avoid problems with additionals.xsd)
112  writeParams(device);
113  device.closeTag();
114  } else {
115  WRITE_WARNING("E3 '" + getID() + TL("' needs at least one entry and one exit"));
116  }
117 }
118 
119 
120 bool
122  return true;
123 }
124 
125 
126 std::string
128  return "";
129 }
130 
131 
132 void
134  // nothing to fix
135 }
136 
137 
138 bool
140  // get edit modes
141  const auto& editModes = myNet->getViewNet()->getEditModes();
142  // check if we're in move mode
143  if (!myNet->getViewNet()->isMovingElement() && editModes.isCurrentSupermodeNetwork() &&
144  (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
145  // only move the first element
147  } else {
148  return false;
149  }
150 }
151 
152 
153 void
155  // update additional geometry
157 }
158 
159 
160 Position
162  return myPosition;
163 }
164 
165 
166 void
168  // remove additional from grid
169  if (updateGrid) {
171  }
172  // now update geometry
173  updateGeometry();
174  // add shape boundary
176  // grow
178  // add additional into RTREE again
179  if (updateGrid) {
180  myNet->addGLObjectIntoGrid(this);
181  }
182 }
183 
184 
185 void
186 GNEMultiEntryExitDetector::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
187  // geometry of this element cannot be splitted
188 }
189 
190 
191 std::string
193  return myNet->getMicrosimID();
194 }
195 
196 
197 void
199  // check if drawn
201  // draw parent and child lines
203  // draw E3
205  }
206 }
207 
208 
209 std::string
211  switch (key) {
212  case SUMO_ATTR_ID:
213  return getMicrosimID();
214  case SUMO_ATTR_POSITION:
215  return toString(myPosition);
216  case SUMO_ATTR_PERIOD:
217  if (myPeriod == SUMOTime_MAX_PERIOD) {
218  return "";
219  } else {
220  return time2string(myPeriod);
221  }
222  case SUMO_ATTR_NAME:
223  return myAdditionalName;
224  case SUMO_ATTR_FILE:
225  return myFilename;
226  case SUMO_ATTR_VTYPES:
227  return toString(myVehicleTypes);
231  return toString(mySpeedThreshold);
233  return toString(myExpectedArrival);
234  case GNE_ATTR_SELECTED:
236  case GNE_ATTR_PARAMETERS:
237  return getParametersStr();
238  default:
239  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
240  }
241 }
242 
243 
244 double
246  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
247 }
248 
249 
250 const Parameterised::Map&
252  return getParametersMap();
253 }
254 
255 
256 void
257 GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
258  if (value == getAttribute(key)) {
259  return; //avoid needless changes, later logic relies on the fact that attributes have changed
260  }
261  switch (key) {
262  case SUMO_ATTR_ID:
263  case SUMO_ATTR_PERIOD:
264  case SUMO_ATTR_POSITION:
265  case SUMO_ATTR_NAME:
266  case SUMO_ATTR_FILE:
267  case SUMO_ATTR_VTYPES:
271  case GNE_ATTR_SELECTED:
272  case GNE_ATTR_PARAMETERS:
273  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
274  break;
275  default:
276  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
277  }
278 }
279 
280 
281 bool
282 GNEMultiEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
283  switch (key) {
284  case SUMO_ATTR_ID:
285  return isValidDetectorID(value);
286  case SUMO_ATTR_POSITION:
287  return canParse<Position>(value);
288  case SUMO_ATTR_PERIOD:
289  if (value.empty()) {
290  return true;
291  } else {
292  return (canParse<double>(value) && (parse<double>(value) >= 0));
293  }
294  case SUMO_ATTR_NAME:
296  case SUMO_ATTR_FILE:
298  case SUMO_ATTR_VTYPES:
299  if (value.empty()) {
300  return true;
301  } else {
303  }
306  return canParse<double>(value) && (parse<double>(value) >= 0);
308  return canParse<bool>(value);
309  case GNE_ATTR_SELECTED:
310  return canParse<bool>(value);
311  case GNE_ATTR_PARAMETERS:
312  return areParametersValid(value);
313  default:
314  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
315  }
316 }
317 
318 
319 bool
321  int numEntrys = 0;
322  int numExits = 0;
323  // iterate over additional chidls and obtain number of entrys and exits
324  for (auto i : getChildAdditionals()) {
325  if (i->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
326  numEntrys++;
327  } else if (i->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
328  numExits++;
329  }
330  }
331  // write warnings
332  if (numEntrys == 0) {
333  WRITE_WARNING(TL("An entry-exit detector needs at least one entry detector"));
334  }
335  if (numExits == 0) {
336  WRITE_WARNING(TL("An entry-exit detector needs at least one exit detector"));
337  }
338  // return false depending of number of Entrys and Exits
339  return ((numEntrys != 0) && (numExits != 0));
340 }
341 
342 
343 std::string
345  return getTagStr() + ":" + getID();
346 }
347 
348 
349 std::string
351  return getTagStr();
352 }
353 
354 // ===========================================================================
355 // private
356 // ===========================================================================
357 
358 void
359 GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
360  switch (key) {
361  case SUMO_ATTR_ID:
362  // update microsimID
363  setAdditionalID(value);
364  break;
365  case SUMO_ATTR_POSITION:
366  myPosition = parse<Position>(value);
367  // update boundary (except for template)
368  if (getID().size() > 0) {
370  }
371  break;
372  case SUMO_ATTR_PERIOD:
373  if (value.empty()) {
375  } else {
376  myPeriod = string2time(value);
377  }
378  break;
379  case SUMO_ATTR_NAME:
380  myAdditionalName = value;
381  break;
382  case SUMO_ATTR_FILE:
383  myFilename = value;
384  break;
385  case SUMO_ATTR_VTYPES:
386  myVehicleTypes = parse<std::vector<std::string> >(value);
387  break;
389  myTimeThreshold = parse<SUMOTime>(value);
390  break;
392  mySpeedThreshold = parse<double>(value);
393  break;
395  myExpectedArrival = parse<bool>(value);
396  break;
397  case GNE_ATTR_SELECTED:
398  if (parse<bool>(value)) {
400  } else {
402  }
403  break;
404  case GNE_ATTR_PARAMETERS:
405  setParametersStr(value);
406  break;
407  default:
408  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
409  }
410 }
411 
412 
413 void
415  // update position
416  myPosition = moveResult.shapeToUpdate.front();
417  // update geometry
418  updateGeometry();
419 }
420 
421 
422 void
424  undoList->begin(this, "position of " + getTagStr());
426  undoList->end();
427 }
428 
429 
430 /****************************************************************************/
@ 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_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_POSITION
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 > 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.
~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
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:1282
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1291
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
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
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:703
bool isMovingElement() const
check if an element is being moved
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:468
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
Definition: GNEViewNet.cpp:911
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 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)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static const RGBColor connectionColor
connection color
static const double E3Size
E3 detector size.