Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2023 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>
36
37#include "GNEMeanData.h"
38
39
40// ===========================================================================
41// member method definitions
42// ===========================================================================
43
44GNEMeanData::GNEMeanData(GNENet* net, SumoXMLTag tag, const std::string& id) :
45 GNEHierarchicalElement(net, tag, {}, {}, {}, {}, {}, {}),
46myID(id) {
47 // reset default values
49 // set file
50 if (myFile.empty()) {
51 myFile = (myID + ".xml");
52 }
53}
54
55
56GNEMeanData::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, {}, {}, {}, {}, {}, {}),
62myID(ID),
63myFile(file),
64myPeriod(period),
65myBegin(begin),
66myEnd(end),
67myTrackVehicles(trackVehicles),
68myWrittenAttributes(writtenAttributes),
69myAggregate(aggregate),
70myEdges(edges),
71myEdgeFile(edgeFile),
72myExcludeEmpty(excludeEmpty),
73myWithInternal(withInternal),
74myDetectPersons(detectPersons),
75myMinSamples(minSamples),
76myMaxTravelTime(maxTravelTime),
77myVTypes(vTypes),
78mySpeedThreshold(speedThreshold) {
79 // set file
80 if (myFile.empty()) {
81 myFile = (myID + ".xml");
82 }
83}
84
85
87
88
89void
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) {
104 }
105 if (myExcludeEmpty != "default") {
107 }
108 if (myWithInternal) {
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) {
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
151void
153 // nothing to update
154}
155
156
159 return Position();
160}
161
162
163std::string
165 switch (key) {
166 case SUMO_ATTR_ID:
167 return myID;
168 case SUMO_ATTR_FILE:
169 return myFile;
170 case SUMO_ATTR_PERIOD:
171 if (myPeriod == -1) {
172 return "";
173 } else {
174 return time2string(myPeriod);
175 }
176 case SUMO_ATTR_BEGIN:
177 if (myBegin == -1) {
178 return "";
179 } else {
180 return time2string(myBegin);
181 }
182 case SUMO_ATTR_END:
183 if (myEnd == -1) {
184 return "";
185 } else {
186 return time2string(myEnd);
187 }
189 return myExcludeEmpty;
191 return toString(myWithInternal);
195 return toString(myMinSamples);
198 case SUMO_ATTR_VTYPES:
199 return toString(myVTypes);
206 case SUMO_ATTR_EDGES:
207 return toString(myEdges);
209 return myEdgeFile;
211 return toString(myAggregate);
212 default:
213 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
214 }
215}
216
217
218double
220 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
221}
222
223
224void
225GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
226 if (value == getAttribute(key)) {
227 return; //avoid needless changes, later logic relies on the fact that attributes have changed
228 }
229 switch (key) {
230 case SUMO_ATTR_ID:
231 case SUMO_ATTR_FILE:
232 case SUMO_ATTR_PERIOD:
233 case SUMO_ATTR_BEGIN:
234 case SUMO_ATTR_END:
240 case SUMO_ATTR_VTYPES:
244 case SUMO_ATTR_EDGES:
247 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
248 break;
249 default:
250 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
251 }
252}
253
254
255bool
256GNEMeanData::isValid(SumoXMLAttr key, const std::string& value) {
257 switch (key) {
258 case SUMO_ATTR_ID:
259 return (myNet->getAttributeCarriers()->retrieveMeanData(myTagProperty.getTag(), value, false) == nullptr);
260 case SUMO_ATTR_FILE:
262 case SUMO_ATTR_PERIOD:
263 case SUMO_ATTR_BEGIN:
264 case SUMO_ATTR_END:
265 if (value.empty()) {
266 return true;
267 } else {
268 return (canParse<double>(value) && (parse<double>(value) >= 0));
269 }
271 if (canParse<bool>(value)) {
272 return true;
273 } else {
274 return (value == "default");
275 }
277 return (canParse<bool>(value));
279 if (value.empty()) {
280 return true;
281 } else {
282 return (canParse<double>(value) && (parse<double>(value) >= 0));
283 }
285 return (canParse<double>(value) && (parse<double>(value) >= 0));
287 return (canParse<double>(value) && (parse<double>(value) >= 0));
288 case SUMO_ATTR_VTYPES:
289 return true;
291 return (canParse<bool>(value));
293 if (value.empty()) {
294 return true;
295 } else {
296 return (value == "walk");
297 }
299 return canParse<std::vector<SumoXMLAttr> >(value);
300 case SUMO_ATTR_EDGES:
301 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
305 return (canParse<bool>(value));
306 default:
307 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
308 }
309}
310
311
312std::string
314 return getTagStr();
315}
316
317
318std::string
320 return getTagStr();
321}
322
323
328
329
330void
331GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value) {
332 switch (key) {
333 case SUMO_ATTR_ID:
334 myID = value;
335 break;
336 case SUMO_ATTR_FILE:
337 myFile = value;
338 break;
339 case SUMO_ATTR_PERIOD:
340 if (value.empty()) {
341 myPeriod = -1;
342 } else {
343 myPeriod = string2time(value);
344 }
345 break;
346 case SUMO_ATTR_BEGIN:
347 if (value.empty()) {
348 myBegin = -1;
349 } else {
350 myBegin = string2time(value);
351 }
352 break;
353 case SUMO_ATTR_END:
354 if (value.empty()) {
355 myEnd = -1;
356 } else {
357 myEnd = string2time(value);
358 }
359 break;
361 myExcludeEmpty = value;
362 break;
364 myWithInternal = parse<bool>(value);
365 break;
367 if (value.empty()) {
368 myMaxTravelTime = 100000;
369 } else {
370 myMaxTravelTime = parse<double>(value);
371 }
372 break;
374 myMinSamples = parse<double>(value);
375 break;
377 mySpeedThreshold = parse<double>(value);
378 break;
379 case SUMO_ATTR_VTYPES:
380 myVTypes = parse<std::vector<std::string> >(value);
381 break;
383 myTrackVehicles = parse<bool>(value);
384 break;
386 myDetectPersons = parse<std::vector<std::string> >(value);
387 break;
389 myWrittenAttributes = parse<std::vector<SumoXMLAttr> >(value);
390 break;
391 case SUMO_ATTR_EDGES:
392 myEdges = parse<std::vector<std::string> >(value);
393 break;
395 myEdgeFile = value;
396 break;
398 myAggregate = parse<bool>(value);
399 break;
400 default:
401 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
402 }
403}
404
405/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
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 toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string getID() const
get ID (all Attribute Carriers have one)
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
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
SUMOTime myBegin
begin
double myMinSamples
minSamples
std::string myExcludeEmpty
exclude empty
std::string myEdgeFile
edge file
SUMOTime myEnd
end
bool myAggregate
whether the data for all edges shall be aggregated
std::vector< std::string > myDetectPersons
detect persons
GNEMeanData(GNENet *net, SumoXMLTag tag, const std::string &id)
Default constructor.
std::vector< std::string > myVTypes
VTypes.
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
std::vector< SumoXMLAttr > myWrittenAttributes
bit mask for checking attributes to be written
std::string myFile
filename
double getAttributeDouble(SumoXMLAttr key) const
std::string myID
id
double mySpeedThreshold
speed threshold
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
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateGeometry()
update pre-computed geometry information
bool myWithInternal
width internal
bool myTrackVehicles
Whether vehicles are tracked.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
Position getPositionInView() const
Returns element position in view.
double myMaxTravelTime
max travel time
~GNEMeanData()
Destructor.
void writeMeanData(OutputDevice &device) const
write meanData element into a xml file
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:120
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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.
std::map< std::string, std::string > Map
parameters map
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)