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-2026 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
23#include <netedit/GNENet.h>
25
26#include "GNEMeanData.h"
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
32GNEMeanData::GNEMeanData(SumoXMLTag tag, std::string ID, GNENet* net, FileBucket* fileBucket) :
33 GNEAttributeCarrier(tag, net, fileBucket),
34 myID(ID) {
35 // reset default values
36 resetDefaultValues(false);
37}
38
39
40GNEMeanData::GNEMeanData(SumoXMLTag tag, std::string ID, GNENet* net, FileBucket* fileBucket, const std::string& file,
41 const std::string& type, const SUMOTime period, const SUMOTime begin, const SUMOTime end,
42 const bool trackVehicles, const std::vector<SumoXMLAttr>& writtenAttributes, const bool aggregate,
43 const std::vector<std::string>& edges, const std::string& edgeFile, const std::string& excludeEmpty,
44 const bool withInternal, const std::vector<std::string>& detectPersons, const double minSamples,
45 const double maxTravelTime, const std::vector<std::string>& vTypes, const double speedThreshold) :
46 GNEAttributeCarrier(tag, net, fileBucket),
47 myID(ID),
48 myFile(file),
49 myType(type),
50 myPeriod(period),
51 myBegin(begin),
52 myEnd(end),
53 myTrackVehicles(trackVehicles),
54 myWrittenAttributes(writtenAttributes),
55 myAggregate(aggregate),
56 myEdges(edges),
57 myEdgeFile(edgeFile),
58 myExcludeEmpty(excludeEmpty),
59 myWithInternal(withInternal),
60 myDetectPersons(detectPersons),
61 myMinSamples(minSamples),
62 myMaxTravelTime(maxTravelTime),
63 myVTypes(vTypes),
64 mySpeedThreshold(speedThreshold) {
65 // set file
66 if (myFile.empty()) {
67 myFile = (myID + ".xml");
68 }
69}
70
71
73
74
79
80
83 return nullptr;
84}
85
86
89 return nullptr;
90}
91
92
93const Parameterised*
95 return nullptr;
96}
97
98
101 return nullptr;
102}
103
104
105const GUIGlObject*
107 return nullptr;
108}
109
110
113 return myFileBucket;
114}
115
116
117void
119 device.openTag(getTagProperty()->getTag());
120 // write needed attributes
121 device.writeAttr(SUMO_ATTR_ID, getID());
122 if (myFile.empty()) {
123 device.writeAttr(SUMO_ATTR_FILE, myID + ".xml");
124 } else {
126 }
127 // write optional attributes
131 }
134 }
137 }
140 }
143 }
144 if (myWithInternal) {
146 }
149 }
152 }
155 }
156 if (myVTypes.size() > 0) {
158 }
159 if (myTrackVehicles) {
161 }
164 }
165 if (myWrittenAttributes.size() > 0) {
167 }
168 if (myEdges.size() > 0) {
170 }
171 if (myEdgeFile.size() > 0) {
173 }
174 if (myAggregate) {
175 device.writeAttr(SUMO_ATTR_AGGREGATE, true);
176 }
177 device.closeTag();
178}
179
180
181void
183 // nothing to update
184}
185
186
189 return Position();
190}
191
192
193bool
195 return false;
196}
197
198
199bool
201 return false;
202}
203
204
205bool
207 return false;
208}
209
210
211bool
213 return false;
214}
215
216
217bool
219 return false;
220}
221
222
223bool
225 return false;
226}
227
228
229bool
231 return false;
232}
233
234
235bool
237 return false;
238}
239
240
241std::string
243 switch (key) {
244 case SUMO_ATTR_ID:
245 return myID;
246 case SUMO_ATTR_FILE:
247 return myFile;
248 case SUMO_ATTR_TYPE:
249 return myType;
250 case SUMO_ATTR_PERIOD:
252 return "";
253 } else {
254 return time2string(myPeriod);
255 }
256 case SUMO_ATTR_BEGIN:
258 return "";
259 } else {
260 return time2string(myBegin);
261 }
262 case SUMO_ATTR_END:
264 return "";
265 } else {
266 return time2string(myEnd);
267 }
269 return myExcludeEmpty;
271 return toString(myWithInternal);
275 return toString(myMinSamples);
278 case SUMO_ATTR_VTYPES:
279 return toString(myVTypes);
286 case SUMO_ATTR_EDGES:
287 return toString(myEdges);
289 return myEdgeFile;
291 return toString(myAggregate);
292 default:
293 return getCommonAttribute(key);
294 }
295}
296
297
298double
302
303
308
309
314
315
316void
317GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
318 if (value == getAttribute(key)) {
319 return; //avoid needless changes, later logic relies on the fact that attributes have changed
320 }
321 switch (key) {
322 case SUMO_ATTR_ID:
323 case SUMO_ATTR_FILE:
324 case SUMO_ATTR_TYPE:
325 case SUMO_ATTR_PERIOD:
326 case SUMO_ATTR_BEGIN:
327 case SUMO_ATTR_END:
333 case SUMO_ATTR_VTYPES:
337 case SUMO_ATTR_EDGES:
340 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
341 break;
342 default:
343 setCommonAttribute(key, value, undoList);
344 break;
345 }
346}
347
348
349bool
350GNEMeanData::isValid(SumoXMLAttr key, const std::string& value) {
351 switch (key) {
352 case SUMO_ATTR_ID:
353 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveMeanData(myTagProperty->getTag(), value, false) == nullptr);
354 case SUMO_ATTR_FILE:
356 case SUMO_ATTR_TYPE:
358 case SUMO_ATTR_PERIOD:
359 case SUMO_ATTR_BEGIN:
360 case SUMO_ATTR_END:
361 if (value.empty()) {
362 return true;
363 } else {
364 return (canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0));
365 }
367 if (canParse<bool>(value)) {
368 return true;
369 } else {
371 }
373 return (canParse<bool>(value));
375 if (value.empty()) {
376 return true;
377 } else {
378 return (canParse<double>(value) && (parse<double>(value) >= 0));
379 }
381 return (canParse<double>(value) && (parse<double>(value) >= 0));
383 return (canParse<double>(value) && (parse<double>(value) >= 0));
384 case SUMO_ATTR_VTYPES:
385 return true;
387 return (canParse<bool>(value));
389 if (value.empty()) {
390 return true;
391 } else {
393 }
395 return canParse<std::vector<SumoXMLAttr> >(value);
396 case SUMO_ATTR_EDGES:
397 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
401 return (canParse<bool>(value));
402 default:
403 return isCommonAttributeValid(key, value);
404 }
405}
406
407
408std::string
410 return getTagStr();
411}
412
413
414std::string
416 return getTagStr();
417}
418
419
420void
421GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value) {
422 switch (key) {
423 case SUMO_ATTR_ID:
425 myID = value;
426 break;
427 case SUMO_ATTR_FILE:
428 if (value.empty()) {
429 myFile = (myID + ".xml");
430 } else {
431 myFile = value;
432 }
433 break;
434 case SUMO_ATTR_TYPE:
435 myType = value;
436 break;
437 case SUMO_ATTR_PERIOD:
438 if (value.empty()) {
440 } else {
441 myPeriod = string2time(value);
442 }
443 break;
444 case SUMO_ATTR_BEGIN:
445 if (value.empty()) {
447 } else {
448 myBegin = string2time(value);
449 }
450 break;
451 case SUMO_ATTR_END:
452 if (value.empty()) {
454 } else {
455 myEnd = string2time(value);
456 }
457 break;
460 myExcludeEmpty = value;
461 } else if (parse<bool>(value)) {
463 } else {
465 }
466 break;
468 myWithInternal = parse<bool>(value);
469 break;
471 if (value.empty()) {
473 } else {
474 myMaxTravelTime = parse<double>(value);
475 }
476 break;
478 if (value.empty()) {
480 } else {
481 myMinSamples = parse<double>(value);
482 }
483 break;
485 if (value.empty()) {
487 } else {
488 mySpeedThreshold = parse<double>(value);
489 }
490 break;
491 case SUMO_ATTR_VTYPES:
492 myVTypes = parse<std::vector<std::string> >(value);
493 break;
495 myTrackVehicles = parse<bool>(value);
496 break;
498 myDetectPersons.clear();
499 if (value.empty()) {
501 } else {
502 myDetectPersons = parse<std::vector<std::string> >(value);
503 }
504 break;
506 myWrittenAttributes = parse<std::vector<SumoXMLAttr> >(value);
507 break;
508 case SUMO_ATTR_EDGES:
509 myEdges = parse<std::vector<std::string> >(value);
510 break;
512 myEdgeFile = value;
513 break;
515 myAggregate = parse<bool>(value);
516 break;
517 default:
518 setCommonAttribute(key, value);
519 break;
520 }
521}
522
523/****************************************************************************/
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:91
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_TYPE
@ 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:289
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
double getCommonAttributeDouble(SumoXMLAttr key) const
FileBucket * myFileBucket
filebucket vinculated whith this AC
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
void resetDefaultValues(const bool allowUndoRedo)
reset attribute carrier to their default values
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
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
double myMinSamples
minSamples
GUIGlObject * getGUIGlObject() override
get GUIGlObject associated with this meanData
std::string myExcludeEmpty
exclude empty
std::string myEdgeFile
edge file
void updateGeometry() override
update pre-computed geometry information
Parameterised * getParameters() override
get parameters associated with this meanData
SUMOTime myEnd
end
bool myAggregate
whether the data for all edges shall be aggregated
bool checkDrawMoveContour() const override
check if draw move contour (red)
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::vector< std::string > myDetectPersons
detect persons
std::vector< std::string > myVTypes
VTypes.
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
std::string getAttribute(SumoXMLAttr key) const override
GNEMeanData(SumoXMLTag tag, std::string ID, GNENet *net, FileBucket *fileBucket)
Default constructor.
SUMOTime myPeriod
period
std::vector< SumoXMLAttr > myWrittenAttributes
bit mask for checking attributes to be written
std::string myFile
filename
std::string myID
id
double mySpeedThreshold
speed threshold
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
std::vector< std::string > myEdges
list of edges
bool checkDrawToContour() const override
check if draw from contour (magenta)
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this meanData
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
bool myWithInternal
width internal
bool myTrackVehicles
Whether vehicles are tracked.
bool checkDrawOverContour() const override
check if draw over contour (orange)
bool isValid(SumoXMLAttr key, const std::string &value) override
method for checking if the key and their conrrespond attribute are valids
std::string myType
type
double getAttributeDouble(SumoXMLAttr key) const override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
method for setting the attribute and letting the object perform data set changes
GNEMoveElement * getMoveElement() const override
get GNEMoveElement associated with this meanData
bool checkDrawSelectContour() const override
check if draw select contour (blue)
Position getAttributePosition(SumoXMLAttr key) const override
bool checkDrawFromContour() const override
check if draw from contour (green)
Position getPositionInView() const
Returns element position in view.
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
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.
void updateMeanDataID(GNEMeanData *meanData, const std::string &newID)
update meanData ID in container
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SUMOTime getDefaultTimeValue(SumoXMLAttr attr) const
get default time value
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const std::string & getDefaultStringValue(SumoXMLAttr attr) const
default values
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.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
static StringBijection< MeanDataType > MeanDataTypes
reference positions (used creating certain elements in netedit)
static StringBijection< PersonMode > PersonModeValues
person modes
static StringBijection< ExcludeEmpty > ExcludeEmptys
exclude empty values
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
const std::string & getString(const T key) const
get string
bool hasString(const std::string &str) const
check if the given string exist