Eclipse SUMO - Simulation of Urban MObility
GNEDetectorE3.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>
23 
24 #include "GNEDetectorE3.h"
25 
26 
27 // ===========================================================================
28 // member method definitions
29 // ===========================================================================
30 
33 {}, {}, {}, {}, {}, {}, {}, {},
34 std::map<std::string, std::string>()),
35  myFreq(0),
36  myFilename(""),
37  myTimeThreshold(0),
38 mySpeedThreshold(0) {
39  // reset default values
40  resetDefaultValues();
41 }
42 
43 
44 GNEDetectorE3::GNEDetectorE3(const std::string& id, GNENet* net, const Position pos, const SUMOTime freq, const std::string& filename,
45  const std::vector<std::string>& vehicleTypes, const std::string& name, SUMOTime timeThreshold, double speedThreshold,
46  const std::map<std::string, std::string>& parameters) :
48 {}, {}, {}, {}, {}, {}, {}, {},
49 parameters),
50 myPosition(pos),
51 myFreq(freq),
52 myFilename(filename),
53 myVehicleTypes(vehicleTypes),
54 myTimeThreshold(timeThreshold),
55 mySpeedThreshold(speedThreshold) {
56  // update centering boundary without updating grid
57  updateCenteringBoundary(false);
58 }
59 
60 
62 
63 
66  // return move operation for additional placed in view
67  return new GNEMoveOperation(this, myPosition);
68 }
69 
70 
71 void
73  device.openTag(getTagProperty().getTag());
74  device.writeAttr(SUMO_ATTR_ID, getID());
75  if (!myAdditionalName.empty()) {
77  }
80  if (myFilename.size() > 0) {
82  }
83  if (myVehicleTypes.size() > 0) {
85  }
88  }
91  }
92  // write all entry/exits
93  for (const auto& access : getChildAdditionals()) {
94  access->writeAdditional(device);
95  }
96  // write parameters (Always after children to avoid problems with additionals.xsd)
97  writeParams(device);
98  device.closeTag();
99 }
100 
101 
102 void
104  // update additional geometry
106 }
107 
108 
109 Position
111  return myPosition;
112 }
113 
114 
115 void
117  // remove additional from grid
118  if (updateGrid) {
120  }
121  // now update geometry
122  updateGeometry();
123  // add shape boundary
125  // add positions of all childrens
126  for (const auto& additionalChildren : getChildAdditionals()) {
127  myAdditionalBoundary.add(additionalChildren->getPositionInView());
128  }
129  // grow
131  // add additional into RTREE again
132  if (updateGrid) {
133  myNet->addGLObjectIntoGrid(this);
134  }
135 }
136 
137 
138 void
139 GNEDetectorE3::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
140  // geometry of this element cannot be splitted
141 }
142 
143 
144 std::string
146  return myNet->getMicrosimID();
147 }
148 
149 
150 void
152  // draw parent and child lines
154  // draw E3
156 }
157 
158 
159 std::string
161  switch (key) {
162  case SUMO_ATTR_ID:
163  return getID();
164  case SUMO_ATTR_POSITION:
165  return toString(myPosition);
166  case SUMO_ATTR_FREQUENCY:
167  return time2string(myFreq);
168  case SUMO_ATTR_NAME:
169  return myAdditionalName;
170  case SUMO_ATTR_FILE:
171  return myFilename;
172  case SUMO_ATTR_VTYPES:
173  return toString(myVehicleTypes);
177  return toString(mySpeedThreshold);
178  case GNE_ATTR_SELECTED:
180  case GNE_ATTR_PARAMETERS:
181  return getParametersStr();
182  default:
183  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
184  }
185 }
186 
187 
188 double
190  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
191 }
192 
193 
194 void
195 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
196  if (value == getAttribute(key)) {
197  return; //avoid needless changes, later logic relies on the fact that attributes have changed
198  }
199  switch (key) {
200  case SUMO_ATTR_ID:
201  case SUMO_ATTR_FREQUENCY:
202  case SUMO_ATTR_POSITION:
203  case SUMO_ATTR_NAME:
204  case SUMO_ATTR_FILE:
205  case SUMO_ATTR_VTYPES:
208  case GNE_ATTR_SELECTED:
209  case GNE_ATTR_PARAMETERS:
210  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
211  break;
212  default:
213  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
214  }
215 }
216 
217 
218 bool
219 GNEDetectorE3::isValid(SumoXMLAttr key, const std::string& value) {
220  switch (key) {
221  case SUMO_ATTR_ID:
222  return isValidDetectorID(value);
223  case SUMO_ATTR_POSITION:
224  return canParse<Position>(value);
225  case SUMO_ATTR_FREQUENCY:
226  return canParse<SUMOTime>(value);
227  case SUMO_ATTR_NAME:
229  case SUMO_ATTR_FILE:
231  case SUMO_ATTR_VTYPES:
232  if (value.empty()) {
233  return true;
234  } else {
236  }
238  return canParse<SUMOTime>(value);
240  return canParse<double>(value) && (parse<double>(value) >= 0);
241  case GNE_ATTR_SELECTED:
242  return canParse<bool>(value);
243  case GNE_ATTR_PARAMETERS:
244  return Parameterised::areParametersValid(value);
245  default:
246  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
247  }
248 }
249 
250 
251 bool
253  int numEntrys = 0;
254  int numExits = 0;
255  // iterate over additional chidls and obtain number of entrys and exits
256  for (auto i : getChildAdditionals()) {
257  if (i->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
258  numEntrys++;
259  } else if (i->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
260  numExits++;
261  }
262  }
263  // write warnings
264  if (numEntrys == 0) {
265  WRITE_WARNING("An " + toString(SUMO_TAG_E3DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_ENTRY) + " detector");
266  }
267  if (numExits == 0) {
268  WRITE_WARNING("An " + toString(SUMO_TAG_E3DETECTOR) + " need at least one " + toString(SUMO_TAG_DET_EXIT) + " detector");
269  }
270  // return false depending of number of Entrys and Exits
271  return ((numEntrys != 0) && (numExits != 0));
272 }
273 
274 
275 bool
277  return true;
278 }
279 
280 
281 std::string
283  return getTagStr() + ":" + getID();
284 }
285 
286 
287 std::string
289  return getTagStr();
290 }
291 
292 // ===========================================================================
293 // private
294 // ===========================================================================
295 
296 void
297 GNEDetectorE3::setAttribute(SumoXMLAttr key, const std::string& value) {
298  switch (key) {
299  case SUMO_ATTR_ID:
300  // update microsimID
301  setMicrosimID(value);
302  // Change IDs of all Entry/Exits children
303  for (const auto& entryExit : getChildAdditionals()) {
304  entryExit->setMicrosimID(getID());
305  }
306  break;
307  case SUMO_ATTR_POSITION:
308  myPosition = parse<Position>(value);
309  // update boundary (except for template)
310  if (getID().size() > 0) {
312  }
313  break;
314  case SUMO_ATTR_FREQUENCY:
315  myFreq = string2time(value);
316  break;
317  case SUMO_ATTR_NAME:
318  myAdditionalName = value;
319  break;
320  case SUMO_ATTR_FILE:
321  myFilename = value;
322  break;
323  case SUMO_ATTR_VTYPES:
324  myVehicleTypes = parse<std::vector<std::string> >(value);
325  break;
327  myTimeThreshold = parse<SUMOTime>(value);
328  break;
330  mySpeedThreshold = parse<double>(value);
331  break;
332  case GNE_ATTR_SELECTED:
333  if (parse<bool>(value)) {
335  } else {
337  }
338  break;
339  case GNE_ATTR_PARAMETERS:
340  setParametersStr(value);
341  break;
342  default:
343  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
344  }
345 }
346 
347 
348 void
350  // update position
351  myPosition = moveResult.shapeToUpdate.front();
352  // update geometry
353  updateGeometry();
354 }
355 
356 
357 void
359  undoList->begin(GUIIcon::E3, "position of " + getTagStr());
360  undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
361  undoList->end();
362 }
363 
364 
365 /****************************************************************************/
@ GLO_E3DETECTOR
a E3 detector
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
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
long long int SUMOTime
Definition: SUMOTime.h:32
@ 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_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_HALTING_SPEED_THRESHOLD
@ SUMO_ATTR_FREQUENCY
@ 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:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
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
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
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
std::string getAttribute(SumoXMLAttr key) const
std::string myFilename
fielname of E3 detector
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 updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool isAttributeEnabled(SumoXMLAttr key) const
double mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting.
double getAttributeDouble(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNEDetectorE3()
GNEDetectorE3 Destructor.
GNEDetectorE3(GNENet *net)
default constructor
GNEMoveOperation * getMoveOperation()
get move operation
bool checkChildAdditionalRestriction() const
check restriction with the number of children
std::vector< std::string > myVehicleTypes
attribute vehicle types
std::string getParentName() const
Returns the name of the parent object (if any)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Position myPosition
position of E3 in view
Position getPositionInView() const
Returns position of additional in view.
SUMOTime myFreq
frequency of E3 detector
SUMOTime myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1210
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1222
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
void updateSinglePosGeometry(const Position &position, const double rotation)
update position and rotation
const PositionVector & getShape() const
The shape of the additional element.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
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 & 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"
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.