Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMeanDataHandler.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// Builds meanData objects for netedit
19/****************************************************************************/
20
21// ===========================================================================
22// included modules
23// ===========================================================================
24#include <config.h>
25
26
29#include <netedit/GNEViewNet.h>
30#include <netedit/GNENet.h>
31#include <netedit/GNEUndoList.h>
33
34#include "GNEMeanDataHandler.h"
35
36
37// ===========================================================================
38// member method definitions
39// ===========================================================================
40
41GNEMeanDataHandler::GNEMeanDataHandler(GNENet* net, const bool allowUndoRedo, const bool overwrite) :
42 myNet(net),
43 myAllowUndoRedo(allowUndoRedo),
44 myOverwrite(overwrite) {
45}
46
47
49
50
51void
52GNEMeanDataHandler::buildEdgeMeanData(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const std::string& ID,
53 const std::string& file, SUMOTime period, SUMOTime begin, SUMOTime end, const bool trackVehicles,
54 const std::vector<std::string>& writtenAttributes, const bool aggregate, const std::vector<std::string>& edgeIDs,
55 const std::string& edgeFile, std::string excludeEmpty, const bool withInternal,
56 const std::vector<std::string>& detectPersons, const double minSamples, const double maxTravelTime,
57 const std::vector<std::string>& vTypes, const double speedThreshold) {
58 // parse attributes
59 const auto edges = parseEdges(SUMO_TAG_MEANDATA_EDGE, edgeIDs);
60 // parse edges
61 const auto attributes = parseAttributes(SUMO_TAG_MEANDATA_EDGE, writtenAttributes);
62 // check if meanData edge exists
64 writeError(TL("Could not build meanDataEdge; ") + TLF("% already exists", ID));
65 } else if ((edges.size() == edgeIDs.size()) && (attributes.size() == writtenAttributes.size())) {
66 GNEMeanData* edgeMeanData = new GNEMeanData(myNet, SUMO_TAG_MEANDATA_EDGE, ID, file, period, begin, end,
67 trackVehicles, attributes, aggregate, edgeIDs, edgeFile, excludeEmpty, withInternal,
68 detectPersons, minSamples, maxTravelTime, vTypes, speedThreshold);
69 if (myAllowUndoRedo) {
70 myNet->getViewNet()->getUndoList()->begin(edgeMeanData, TL("add meanDataEdge"));
71 myNet->getViewNet()->getUndoList()->add(new GNEChange_MeanData(edgeMeanData, true), true);
73 } else {
74 edgeMeanData->incRef("buildEdgeMeanData");
75 }
76 }
77}
78
79
80void
81GNEMeanDataHandler::buildLaneMeanData(const CommonXMLStructure::SumoBaseObject* /*sumoBaseObject*/, const std::string& ID,
82 const std::string& file, SUMOTime period, SUMOTime begin, SUMOTime end, const bool trackVehicles,
83 const std::vector<std::string>& writtenAttributes, const bool aggregate, const std::vector<std::string>& edgeIDs,
84 const std::string& edgeFile, std::string excludeEmpty, const bool withInternal,
85 const std::vector<std::string>& detectPersons, const double minSamples, const double maxTravelTime,
86 const std::vector<std::string>& vTypes, const double speedThreshold) {
87 // parse attributes
88 const auto edges = parseEdges(SUMO_TAG_MEANDATA_LANE, edgeIDs);
89 // parse edges
90 const auto attributes = parseAttributes(SUMO_TAG_MEANDATA_LANE, writtenAttributes);
91 // check if meanData edge exists
93 writeError(TL("Could not build meanDataLane; ") + TLF("% already exists", ID));
94 } else if ((edges.size() == edgeIDs.size()) && (attributes.size() == writtenAttributes.size())) {
95 GNEMeanData* edgeMeanData = new GNEMeanData(myNet, SUMO_TAG_MEANDATA_LANE, ID, file, period, begin, end,
96 trackVehicles, attributes, aggregate, edgeIDs, edgeFile, excludeEmpty, withInternal,
97 detectPersons, minSamples, maxTravelTime, vTypes, speedThreshold);
98 if (myAllowUndoRedo) {
99 myNet->getViewNet()->getUndoList()->begin(edgeMeanData, TL("add meanDataLane"));
100 myNet->getViewNet()->getUndoList()->add(new GNEChange_MeanData(edgeMeanData, true), true);
102 } else {
103 edgeMeanData->incRef("buildEdgeMeanData");
104 }
105 }
106}
107
108
109std::vector<GNEEdge*>
110GNEMeanDataHandler::parseEdges(const SumoXMLTag tag, const std::vector<std::string>& edgeIDs) {
111 std::vector<GNEEdge*> edges;
112 for (const auto& edgeID : edgeIDs) {
113 GNEEdge* edge = myNet->getAttributeCarriers()->retrieveEdge(edgeID, false);
114 // empty edges aren't allowed. If edge is empty, write error, clear edges and stop
115 if (edge == nullptr) {
116 writeError(TLF("Could not build % in netedit", toString(tag)) + std::string("; ") + TL("Edge doesn't exist."));
117 edges.clear();
118 return edges;
119 } else {
120 edges.push_back(edge);
121 }
122 }
123 return edges;
124}
125
126
127std::vector<SumoXMLAttr>
128GNEMeanDataHandler::parseAttributes(const SumoXMLTag tag, const std::vector<std::string>& attrStrs) {
129 std::vector<SumoXMLAttr> attrs;
130 for (const auto& attrStr : attrStrs) {
131 if (SUMOXMLDefinitions::Tags.hasString(attrStr)) {
132 writeError(TLF("Could not build % in netedit", toString(tag)) + std::string("; ") + TLF("Attribute '%' doesn't exist.", attrStr));
133 attrs.clear();
134 return attrs;
135 } else {
136 attrs.push_back(static_cast<SumoXMLAttr>(SUMOXMLDefinitions::Attrs.get(attrStr)));
137 }
138 }
139 return attrs;
140}
141
142/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_MEANDATA_LANE
a lane based mean data detector
@ SUMO_TAG_MEANDATA_EDGE
an edge based mean data detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
GNEMeanDataHandler(GNENet *net, const bool allowUndoRedo, const bool overwrite)
Constructor.
std::vector< SumoXMLAttr > parseAttributes(const SumoXMLTag tag, const std::vector< std::string > &attrStrs)
parse attributes
void buildEdgeMeanData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &ID, const std::string &file, SUMOTime period, SUMOTime begin, SUMOTime end, const bool trackVehicles, const std::vector< std::string > &writtenAttributes, const bool aggregate, const std::vector< std::string > &edgeIDs, const std::string &edgeFile, std::string excludeEmpty, const bool withInternal, const std::vector< std::string > &detectPersons, const double minSamples, const double maxTravelTime, const std::vector< std::string > &vTypes, const double speedThreshold)
virtual ~GNEMeanDataHandler()
Destructor.
const bool myAllowUndoRedo
allow undo/redo
void buildLaneMeanData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &ID, const std::string &file, SUMOTime period, SUMOTime begin, SUMOTime end, const bool trackVehicles, const std::vector< std::string > &writtenAttributes, const bool aggregate, const std::vector< std::string > &edgeIDs, const std::string &edgeFile, std::string excludeEmpty, const bool withInternal, const std::vector< std::string > &detectPersons, const double minSamples, const double maxTravelTime, const std::vector< std::string > &vTypes, const double speedThreshold)
Builds laneMeanData.
std::vector< GNEEdge * > parseEdges(const SumoXMLTag tag, const std::vector< std::string > &edgeIDs)
parse edges
GNENet * myNet
pointer to GNENet
An Element which don't belong to GNENet but has influence in the simulation.
Definition GNEMeanData.h:33
GNEMeanData * retrieveMeanData(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named meanData.
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
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:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
void incRef(const std::string &debugMsg="")
Increase reference.
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 add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
GNEUndoList * getUndoList() const
get the undoList object
void writeError(const std::string &error)
write error and enable error creating element
static SequentialStringBijection Attrs
The names of SUMO-XML attributes for use in netbuild.
static SequentialStringBijection Tags
The names of SUMO-XML elements for use in netbuild.