Eclipse SUMO - Simulation of Urban MObility
GNEMeanData.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 // Class for representing MeanData
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
25 #include <netedit/GNEViewParent.h>
31 #include <utils/gui/div/GLHelper.h>
36 
37 #include "GNEMeanData.h"
38 
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
43 
44 GNEMeanData::GNEMeanData(GNENet* net, SumoXMLTag tag, const std::string& id) :
45  GNEHierarchicalElement(net, tag, {}, {}, {}, {}, {}, {}),
46 myID(id) {
47  // reset default values
49  // set file
50  if (myFile.empty()) {
51  myFile = (myID + ".xml");
52  }
53 }
54 
55 
56 GNEMeanData::GNEMeanData(GNENet* net, SumoXMLTag tag, std::string ID, std::string file, SUMOTime period,
57  SUMOTime begin, SUMOTime end, const bool trackVehicles, const std::vector<SumoXMLAttr>& writtenAttributes,
58  const bool aggregate, const std::vector<std::string>& edges, const std::string& edgeFile,
59  std::string excludeEmpty, const bool withInternal, const std::vector<std::string>& detectPersons,
60  const double minSamples, const double maxTravelTime, const std::vector<std::string>& vTypes, const double speedThreshold) :
61  GNEHierarchicalElement(net, tag, {}, {}, {}, {}, {}, {}),
62 myID(ID),
63 myFile(file),
64 myPeriod(period),
65 myBegin(begin),
66 myEnd(end),
67 myTrackVehicles(trackVehicles),
68 myWrittenAttributes(writtenAttributes),
69 myAggregate(aggregate),
70 myEdges(edges),
71 myEdgeFile(edgeFile),
72 myExcludeEmpty(excludeEmpty),
73 myWithInternal(withInternal),
74 myDetectPersons(detectPersons),
75 myMinSamples(minSamples),
76 myMaxTravelTime(maxTravelTime),
77 myVTypes(vTypes),
78 mySpeedThreshold(speedThreshold) {
79  // set file
80  if (myFile.empty()) {
81  myFile = (myID + ".xml");
82  }
83 }
84 
85 
87 
88 
89 void
91  device.openTag(getTagProperty().getTag());
92  // write needed attributes
93  device.writeAttr(SUMO_ATTR_ID, getID());
95  // write optional attributes
96  if (myPeriod != -1) {
98  }
99  if (myBegin != -1) {
101  }
102  if (myEnd != -1) {
103  device.writeAttr(SUMO_ATTR_END, myEnd);
104  }
105  if (myExcludeEmpty != "default") {
107  }
108  if (myWithInternal) {
109  device.writeAttr(SUMO_ATTR_WITH_INTERNAL, true);
110  }
111  if (myMaxTravelTime != 100000) {
113  }
114  if (myMinSamples != 0) {
116  }
117  if (mySpeedThreshold != 0.1) {
119  }
120  if (myVTypes.size() > 0) {
122  }
123  if (myTrackVehicles) {
124  device.writeAttr(SUMO_ATTR_TRACK_VEHICLES, true);
125  }
126  if (myDetectPersons.size() > 0) {
128  }
129  if (myWrittenAttributes.size() > 0) {
131  }
132  if (myEdges.size() > 0) {
134  }
135  if (myEdgeFile.size() > 0) {
137  }
138  if (myAggregate) {
139  device.writeAttr(SUMO_ATTR_AGGREGATE, true);
140  }
141  device.closeTag();
142 }
143 
144 
147  return nullptr;
148 }
149 
150 
151 const GUIGlObject*
153  return nullptr;
154 }
155 
156 
157 void
159  // nothing to update
160 }
161 
162 
163 Position
165  return Position();
166 }
167 
168 
169 bool
171  return false;
172 }
173 
174 
175 bool
177  return false;
178 }
179 
180 
181 bool
183  return false;
184 }
185 
186 
187 bool
189  return false;
190 }
191 
192 
193 bool
195  return false;
196 }
197 
198 
199 bool
201  return false;
202 }
203 
204 
205 bool
207  return false;
208 }
209 
210 
211 std::string
213  switch (key) {
214  case SUMO_ATTR_ID:
215  return myID;
216  case SUMO_ATTR_FILE:
217  return myFile;
218  case SUMO_ATTR_PERIOD:
219  if (myPeriod == -1) {
220  return "";
221  } else {
222  return time2string(myPeriod);
223  }
224  case SUMO_ATTR_BEGIN:
225  if (myBegin == -1) {
226  return "";
227  } else {
228  return time2string(myBegin);
229  }
230  case SUMO_ATTR_END:
231  if (myEnd == -1) {
232  return "";
233  } else {
234  return time2string(myEnd);
235  }
237  return myExcludeEmpty;
239  return toString(myWithInternal);
241  return toString(myMaxTravelTime);
243  return toString(myMinSamples);
245  return toString(mySpeedThreshold);
246  case SUMO_ATTR_VTYPES:
247  return toString(myVTypes);
249  return toString(myTrackVehicles);
251  return toString(myDetectPersons);
253  return joinToString(myWrittenAttributes, " ");
254  case SUMO_ATTR_EDGES:
255  return toString(myEdges);
256  case SUMO_ATTR_EDGESFILE:
257  return myEdgeFile;
258  case SUMO_ATTR_AGGREGATE:
259  return toString(myAggregate);
260  default:
261  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
262  }
263 }
264 
265 
266 double
268  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
269 }
270 
271 
272 void
273 GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
274  if (value == getAttribute(key)) {
275  return; //avoid needless changes, later logic relies on the fact that attributes have changed
276  }
277  switch (key) {
278  case SUMO_ATTR_ID:
279  case SUMO_ATTR_FILE:
280  case SUMO_ATTR_PERIOD:
281  case SUMO_ATTR_BEGIN:
282  case SUMO_ATTR_END:
288  case SUMO_ATTR_VTYPES:
292  case SUMO_ATTR_EDGES:
293  case SUMO_ATTR_EDGESFILE:
294  case SUMO_ATTR_AGGREGATE:
295  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
296  break;
297  default:
298  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
299  }
300 }
301 
302 
303 bool
304 GNEMeanData::isValid(SumoXMLAttr key, const std::string& value) {
305  switch (key) {
306  case SUMO_ATTR_ID:
307  return (myNet->getAttributeCarriers()->retrieveMeanData(myTagProperty.getTag(), value, false) == nullptr);
308  case SUMO_ATTR_FILE:
310  case SUMO_ATTR_PERIOD:
311  case SUMO_ATTR_BEGIN:
312  case SUMO_ATTR_END:
313  if (value.empty()) {
314  return true;
315  } else {
316  return (canParse<double>(value) && (parse<double>(value) >= 0));
317  }
319  if (canParse<bool>(value)) {
320  return true;
321  } else {
322  return (value == "default");
323  }
325  return (canParse<bool>(value));
327  if (value.empty()) {
328  return true;
329  } else {
330  return (canParse<double>(value) && (parse<double>(value) >= 0));
331  }
333  return (canParse<double>(value) && (parse<double>(value) >= 0));
335  return (canParse<double>(value) && (parse<double>(value) >= 0));
336  case SUMO_ATTR_VTYPES:
337  return true;
339  return (canParse<bool>(value));
341  if (value.empty()) {
342  return true;
343  } else {
344  return (value == "walk");
345  }
347  return canParse<std::vector<SumoXMLAttr> >(value);
348  case SUMO_ATTR_EDGES:
349  return canParse<std::vector<GNEEdge*> >(myNet, value, false);
350  case SUMO_ATTR_EDGESFILE:
352  case SUMO_ATTR_AGGREGATE:
353  return (canParse<bool>(value));
354  default:
355  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
356  }
357 }
358 
359 
360 std::string
362  return getTagStr();
363 }
364 
365 
366 std::string
368  return getTagStr();
369 }
370 
371 
372 const Parameterised::Map&
375 }
376 
377 
378 void
379 GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value) {
380  switch (key) {
381  case SUMO_ATTR_ID:
382  myID = value;
383  break;
384  case SUMO_ATTR_FILE:
385  myFile = value;
386  break;
387  case SUMO_ATTR_PERIOD:
388  if (value.empty()) {
389  myPeriod = -1;
390  } else {
391  myPeriod = string2time(value);
392  }
393  break;
394  case SUMO_ATTR_BEGIN:
395  if (value.empty()) {
396  myBegin = -1;
397  } else {
398  myBegin = string2time(value);
399  }
400  break;
401  case SUMO_ATTR_END:
402  if (value.empty()) {
403  myEnd = -1;
404  } else {
405  myEnd = string2time(value);
406  }
407  break;
409  myExcludeEmpty = value;
410  break;
412  myWithInternal = parse<bool>(value);
413  break;
415  if (value.empty()) {
416  myMaxTravelTime = 100000;
417  } else {
418  myMaxTravelTime = parse<double>(value);
419  }
420  break;
422  myMinSamples = parse<double>(value);
423  break;
425  mySpeedThreshold = parse<double>(value);
426  break;
427  case SUMO_ATTR_VTYPES:
428  myVTypes = parse<std::vector<std::string> >(value);
429  break;
431  myTrackVehicles = parse<bool>(value);
432  break;
434  myDetectPersons = parse<std::vector<std::string> >(value);
435  break;
437  myWrittenAttributes = parse<std::vector<SumoXMLAttr> >(value);
438  break;
439  case SUMO_ATTR_EDGES:
440  myEdges = parse<std::vector<std::string> >(value);
441  break;
442  case SUMO_ATTR_EDGESFILE:
443  myEdgeFile = value;
444  break;
445  case SUMO_ATTR_AGGREGATE:
446  myAggregate = parse<bool>(value);
447  break;
448  default:
449  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
450  }
451 }
452 
453 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
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 STEPS2TIME(x)
Definition: SUMOTime.h:55
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_FILE
@ SUMO_ATTR_TRACK_VEHICLES
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_WITH_INTERNAL
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_AGGREGATE
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_MAX_TRAVELTIME
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_HALTING_SPEED_THRESHOLD
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_MIN_SAMPLES
@ SUMO_ATTR_ID
@ SUMO_ATTR_WRITE_ATTRIBUTES
@ SUMO_ATTR_DETECT_PERSONS
@ SUMO_ATTR_EXCLUDE_EMPTY
@ SUMO_ATTR_EDGESFILE
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:283
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
const std::string getID() const
get ID (all Attribute Carriers have one)
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
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
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
SUMOTime myBegin
begin
Definition: GNEMeanData.h:141
double myMinSamples
minSamples
Definition: GNEMeanData.h:171
std::string myExcludeEmpty
exclude empty
Definition: GNEMeanData.h:162
std::string myEdgeFile
edge file
Definition: GNEMeanData.h:159
bool checkDrawOverContour() const
check if draw over contour (orange)
SUMOTime myEnd
end
Definition: GNEMeanData.h:144
bool myAggregate
whether the data for all edges shall be aggregated
Definition: GNEMeanData.h:153
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
bool checkDrawSelectContour() const
check if draw select contour (blue)
std::vector< std::string > myDetectPersons
detect persons
Definition: GNEMeanData.h:168
GNEMeanData(GNENet *net, SumoXMLTag tag, const std::string &id)
Default constructor.
Definition: GNEMeanData.cpp:44
std::vector< std::string > myVTypes
VTypes.
Definition: GNEMeanData.h:177
const Parameterised::Map & getACParametersMap() const
get parameters map
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform data set changes
SUMOTime myPeriod
period
Definition: GNEMeanData.h:138
std::vector< SumoXMLAttr > myWrittenAttributes
bit mask for checking attributes to be written
Definition: GNEMeanData.h:150
std::string myFile
filename
Definition: GNEMeanData.h:135
double getAttributeDouble(SumoXMLAttr key) const
std::string myID
id
Definition: GNEMeanData.h:132
double mySpeedThreshold
speed threshold
Definition: GNEMeanData.h:180
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::vector< std::string > myEdges
list of edges
Definition: GNEMeanData.h:156
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
bool checkDrawFromContour() const
check if draw from contour (green)
void updateGeometry()
update pre-computed geometry information
bool myWithInternal
width internal
Definition: GNEMeanData.h:165
bool myTrackVehicles
Whether vehicles are tracked.
Definition: GNEMeanData.h:147
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool checkDrawToContour() const
check if draw from contour (magenta)
std::string getAttribute(SumoXMLAttr key) const
Position getPositionInView() const
Returns element position in view.
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
bool checkDrawMoveContour() const
check if draw move contour (red)
double myMaxTravelTime
max travel time
Definition: GNEMeanData.h:174
~GNEMeanData()
Destructor.
Definition: GNEMeanData.cpp:86
void writeMeanData(OutputDevice &device) const
write meanData element into a xml file
Definition: GNEMeanData.cpp:90
GNEMeanData * retrieveMeanData(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named meanData.
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:123
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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.
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)