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.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
21#include <netedit/GNENet.h>
22#include <netedit/GNEUndoList.h>
23#include <netedit/GNEViewNet.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 myPeriod(0),
38 myFilename(""),
39 myTimeThreshold(0),
40mySpeedThreshold(0) {
41 // reset default values
42 resetDefaultValues();
43}
44
45
46GNEMultiEntryExitDetector::GNEMultiEntryExitDetector(const std::string& id, GNENet* net, const Position pos, const SUMOTime freq, const std::string& filename,
47 const std::vector<std::string>& vehicleTypes, const std::string& name, SUMOTime timeThreshold, double speedThreshold,
48 const Parameterised::Map& parameters) :
49 GNEAdditional(id, net, GLO_E3DETECTOR, SUMO_TAG_ENTRY_EXIT_DETECTOR, GUIIconSubSys::getIcon(GUIIcon::E3EXIT), name, {}, {}, {}, {}, {}, {}),
50Parameterised(parameters),
51myPosition(pos),
52myPeriod(freq),
53myFilename(filename),
54myVehicleTypes(vehicleTypes),
55myTimeThreshold(timeThreshold),
56mySpeedThreshold(speedThreshold) {
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
72void
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 }
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(myTagProperty.getTagStr() + " '" + getID() + "' needs at least one entry and one exit");
116 }
117}
118
119
120void
122 // update additional geometry
124}
125
126
129 return myPosition;
130}
131
132
133void
135 // remove additional from grid
136 if (updateGrid) {
138 }
139 // now update geometry
141 // add shape boundary
143 // add positions of all childrens
144 for (const auto& additionalChildren : getChildAdditionals()) {
145 myAdditionalBoundary.add(additionalChildren->getPositionInView());
146 }
147 // grow
149 // add additional into RTREE again
150 if (updateGrid) {
152 }
153}
154
155
156void
157GNEMultiEntryExitDetector::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
158 // geometry of this element cannot be splitted
159}
160
161
162std::string
164 return myNet->getMicrosimID();
165}
166
167
168void
170 // check if drawn
172 // draw parent and child lines
174 // draw E3
176 }
177}
178
179
180std::string
182 switch (key) {
183 case SUMO_ATTR_ID:
184 return getMicrosimID();
186 return toString(myPosition);
187 case SUMO_ATTR_PERIOD:
189 return "";
190 } else {
191 return time2string(myPeriod);
192 }
193 case SUMO_ATTR_NAME:
194 return myAdditionalName;
195 case SUMO_ATTR_FILE:
196 return myFilename;
197 case SUMO_ATTR_VTYPES:
198 return toString(myVehicleTypes);
206 return getParametersStr();
207 default:
208 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
209 }
210}
211
212
213double
215 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
216}
217
218
221 return getParametersMap();
222}
223
224
225void
226GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
227 if (value == getAttribute(key)) {
228 return; //avoid needless changes, later logic relies on the fact that attributes have changed
229 }
230 switch (key) {
231 case SUMO_ATTR_ID:
232 case SUMO_ATTR_PERIOD:
234 case SUMO_ATTR_NAME:
235 case SUMO_ATTR_FILE:
236 case SUMO_ATTR_VTYPES:
241 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
242 break;
243 default:
244 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
245 }
246}
247
248
249bool
250GNEMultiEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
251 switch (key) {
252 case SUMO_ATTR_ID:
253 return isValidDetectorID(value);
255 return canParse<Position>(value);
256 case SUMO_ATTR_PERIOD:
257 if (value.empty()) {
258 return true;
259 } else {
260 return (canParse<double>(value) && (parse<double>(value) >= 0));
261 }
262 case SUMO_ATTR_NAME:
264 case SUMO_ATTR_FILE:
266 case SUMO_ATTR_VTYPES:
267 if (value.empty()) {
268 return true;
269 } else {
271 }
273 return canParse<SUMOTime>(value);
275 return canParse<double>(value) && (parse<double>(value) >= 0);
277 return canParse<bool>(value);
279 return areParametersValid(value);
280 default:
281 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
282 }
283}
284
285
286bool
288 int numEntrys = 0;
289 int numExits = 0;
290 // iterate over additional chidls and obtain number of entrys and exits
291 for (auto i : getChildAdditionals()) {
292 if (i->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
293 numEntrys++;
294 } else if (i->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
295 numExits++;
296 }
297 }
298 // write warnings
299 if (numEntrys == 0) {
300 WRITE_WARNING("An " + toString(SUMO_TAG_ENTRY_EXIT_DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_ENTRY) + " detector");
301 }
302 if (numExits == 0) {
303 WRITE_WARNING("An " + toString(SUMO_TAG_ENTRY_EXIT_DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_EXIT) + " detector");
304 }
305 // return false depending of number of Entrys and Exits
306 return ((numEntrys != 0) && (numExits != 0));
307}
308
309
310std::string
312 return getTagStr() + ":" + getID();
313}
314
315
316std::string
318 return getTagStr();
319}
320
321// ===========================================================================
322// private
323// ===========================================================================
324
325void
327 switch (key) {
328 case SUMO_ATTR_ID:
329 // update microsimID
330 setMicrosimID(value);
331 // Change IDs of all Entry/Exits children
332 for (const auto& entryExit : getChildAdditionals()) {
333 entryExit->setMicrosimID(getID());
334 }
335 break;
337 myPosition = parse<Position>(value);
338 // update boundary (except for template)
339 if (getID().size() > 0) {
341 }
342 break;
343 case SUMO_ATTR_PERIOD:
344 if (value.empty()) {
346 } else {
347 myPeriod = string2time(value);
348 }
349 break;
350 case SUMO_ATTR_NAME:
351 myAdditionalName = value;
352 break;
353 case SUMO_ATTR_FILE:
354 myFilename = value;
355 break;
356 case SUMO_ATTR_VTYPES:
357 myVehicleTypes = parse<std::vector<std::string> >(value);
358 break;
360 myTimeThreshold = parse<SUMOTime>(value);
361 break;
363 mySpeedThreshold = parse<double>(value);
364 break;
366 if (parse<bool>(value)) {
368 } else {
370 }
371 break;
373 setParametersStr(value);
374 break;
375 default:
376 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
377 }
378}
379
380
381void
383 // update position
384 myPosition = moveResult.shapeToUpdate.front();
385 // update geometry
387}
388
389
390void
392 undoList->begin(GUIIcon::E3, "position of " + getTagStr());
393 undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
394 undoList->end();
395}
396
397
398/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
@ 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:265
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define SUMOTime_MAX_PERIOD
Definition: SUMOTime.h:35
@ 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_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
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
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
bool isValidDetectorID(const std::string &newID) const
check if a new detector ID is valid
Boundary myAdditionalBoundary
Additional Boundary.
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
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
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
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
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.
Position getPositionInView() const
Returns position of additional in view.
std::string getParentName() const
Returns the name of the parent object (if any)
~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
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:1245
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1257
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
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...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
Definition: GNEViewNet.cpp:874
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:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.