Eclipse SUMO - Simulation of Urban MObility
GNEDataHandler.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// Builds data objects for netedit
19/****************************************************************************/
20
21// ===========================================================================
22// included modules
23// ===========================================================================
24#include <config.h>
25
33#include <netedit/GNEViewNet.h>
34#include <netedit/GNENet.h>
35#include <netedit/GNEUndoList.h>
37
38#include "GNEDataHandler.h"
39
40
41// ===========================================================================
42// member method definitions
43// ===========================================================================
44
45GNEDataHandler::GNEDataHandler(GNENet* net, const std::string& file, const bool allowUndoRedo) :
46 DataHandler(file),
47 myNet(net),
48 myAllowUndoRedo(allowUndoRedo) {
49}
50
51
53
54
55void
56GNEDataHandler::buildDataSet(const std::string& dataSetID) {
57 // first check if dataSet exist
58 if (myNet->getAttributeCarriers()->retrieveDataSet(dataSetID, false) == nullptr) {
59 GNEDataSet* dataSet = new GNEDataSet(myNet, dataSetID);
60 if (myAllowUndoRedo) {
62 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataSet(dataSet, true), true);
64 } else {
65 // insert dataSet without allowing undo/redo
67 dataSet->incRef("buildDataSet");
68 }
69 } else {
71 }
72}
73
74
75void
77 const std::string& dataSetID, const double begin, const double end) {
78 // get dataSet
79 GNEDataSet* dataSet = myNet->getAttributeCarriers()->retrieveDataSet(dataSetID, false);
80 // first check if dataSet exist
81 if (dataSet == nullptr) {
82 // create dataset AND data interval
83 dataSet = new GNEDataSet(myNet, dataSetID);
84 GNEDataInterval* dataInterval = new GNEDataInterval(dataSet, begin, end);
85 if (myAllowUndoRedo) {
87 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataSet(dataSet, true), true);
88 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataInterval(dataInterval, true), true);
90 } else {
91 // insert dataInterval without allowing undo/redo
93 dataSet->addDataIntervalChild(dataInterval);
94 dataInterval->incRef("buildDataInterval");
95 }
96 } else if (dataSet->retrieveInterval(begin, end) == nullptr) {
97 GNEDataInterval* dataInterval = new GNEDataInterval(dataSet, begin, end);
98 if (myAllowUndoRedo) {
100 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataInterval(dataInterval, true), true);
102 } else {
103 // insert dataInterval without allowing undo/redo
104 dataSet->addDataIntervalChild(dataInterval);
105 dataInterval->incRef("buildDataInterval");
106 }
107 }
108}
109
110
111void
112GNEDataHandler::buildEdgeData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& edgeID,
113 const Parameterised::Map& parameters) {
114 // get dataSet
116 if (dataSet != nullptr) {
117 // get interval
118 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
121 if (dataInterval != nullptr) {
122 // get data
123 GNEEdge* edge = myNet->getAttributeCarriers()->retrieveEdge(edgeID, false);
124 if (edge) {
125 GNEGenericData* edgeData = new GNEEdgeData(dataInterval, edge, parameters);
126 if (myAllowUndoRedo) {
128 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
130 } else {
131 dataInterval->addGenericDataChild(edgeData);
132 edge->addChildElement(edgeData);
133 edgeData->incRef("buildEdgeData");
134 }
135 } else {
137 }
138 } else {
140 }
141 } else {
143 }
144}
145
146
147void
148GNEDataHandler::buildEdgeRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromEdgeID,
149 const std::string& toEdgeID, const Parameterised::Map& parameters) {
150 // get dataSet
152 if (dataSet != nullptr) {
153 // get interval
154 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
157 if (dataInterval != nullptr) {
158 // get data
159 GNEEdge* fromEdge = myNet->getAttributeCarriers()->retrieveEdge(fromEdgeID, false);
160 GNEEdge* toEdge = myNet->getAttributeCarriers()->retrieveEdge(toEdgeID, false);
161 if (fromEdge && toEdge) {
162 GNEGenericData* edgeData = new GNEEdgeRelData(dataInterval, fromEdge, toEdge, parameters);
163 if (myAllowUndoRedo) {
165 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
167 } else {
168 dataInterval->addGenericDataChild(edgeData);
169 fromEdge->addChildElement(edgeData);
170 toEdge->addChildElement(edgeData);
171 edgeData->incRef("buildEdgeData");
172 }
173 } else {
175 }
176 } else {
178 }
179 } else {
181 }
182}
183
184
185void
186GNEDataHandler::buildTAZRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromTAZID,
187 const std::string& toTAZID, const Parameterised::Map& parameters) {
188 // get dataSet
190 if (dataSet != nullptr) {
191 // get interval
192 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
195 if (dataInterval != nullptr) {
196 // get from TAZs
199 if (fromTAZ == nullptr) {
201 } else if (toTAZ == nullptr) {
203 } else if ((fromTAZ != toTAZ) && dataInterval->TAZRelExists(fromTAZ, toTAZ)) {
204 writeError("There is already a " + toString(SUMO_TAG_TAZREL) + " defined between '" + toTAZID + "' and '" + toTAZID + "'.");
205 } else if ((fromTAZ == toTAZ) && dataInterval->TAZRelExists(fromTAZ)) {
206 writeError("There is already a " + toString(SUMO_TAG_TAZREL) + " defined in '" + toTAZID + "'.");
207 } else if (fromTAZ == toTAZ) {
208 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, parameters);
209 if (myAllowUndoRedo) {
211 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
213 } else {
214 dataInterval->addGenericDataChild(edgeData);
215 fromTAZ->addChildElement(edgeData);
216 edgeData->incRef("buildEdgeData");
217 }
218 } else {
219 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, toTAZ, parameters);
220 if (myAllowUndoRedo) {
222 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
224 } else {
225 dataInterval->addGenericDataChild(edgeData);
226 fromTAZ->addChildElement(edgeData);
227 toTAZ->addChildElement(edgeData);
228 edgeData->incRef("buildEdgeData");
229 }
230 }
231 } else {
233 }
234 } else {
236 }
237}
238
239
240void
241GNEDataHandler::writeErrorDuplicated(const SumoXMLTag tag, const std::string& id) {
242 writeError("Could not build " + toString(tag) + " with ID '" + id + "' in netedit; declared twice.");
243}
244
245
246void
248 writeError("Could not build " + toString(tag) + " in netedit; " + toString(parent) + " doesn't exist.");
249}
250
251
252void
253GNEDataHandler::writeErrorInvalidParent(const SumoXMLTag tag, const SumoXMLTag parent, const std::string& ID) {
254 writeError("Could not build " + toString(tag) + " in netedit; " + toString(parent) + " with ID '" + ID + "' doesn't exist.");
255}
256
257/****************************************************************************/
@ DATAINTERVAL
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_EDGEREL
a relation between two edges
@ SUMO_TAG_DATAINTERVAL
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_MEANDATA_EDGE
an edge based mean data detector
@ SUMO_TAG_DATASET
@ SUMO_TAG_TAZREL
a relation between two TAZs
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
SumoBaseObject * getParentSumoBaseObject() const
get pointer to mySumoBaseObjectParent SumoBaseObject (if is null, then is the root)
double getDoubleAttribute(const SumoXMLAttr attr) const
get double attribute
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
The XML-Handler for network loading.
Definition: DataHandler.h:38
void writeError(const std::string &error)
write error and enable error creating element
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
GNEDataHandler(GNENet *net, const std::string &file, const bool allowUndoRedo)
Constructor.
~GNEDataHandler()
Destructor.
void buildDataSet(const std::string &dataSetID)
Builds DataSet (exclusive of NETEDIT)
void buildTAZRelationData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &fromTAZID, const std::string &toTAZID, const Parameterised::Map &parameters)
Builds TAZRelationData.
const bool myAllowUndoRedo
allow undo/redo
void writeErrorDuplicated(const SumoXMLTag tag, const std::string &id)
write error "duplicated additional"
void writeErrorInvalidParent(const SumoXMLTag tag, const SumoXMLTag parent)
write error "invalid parent element"
void buildEdgeData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &edgeID, const Parameterised::Map &parameters)
Builds edgeData.
void buildDataInterval(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &dataSetID, const double begin, const double end)
Builds DataInterval.
void buildEdgeRelationData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &fromEdgeID, const std::string &toEdgeID, const Parameterised::Map &parameters)
Builds edgeRelationData.
GNENet * myNet
pointer to GNENet
An Element which don't belong to GNENet but has influence in the simulation.
bool TAZRelExists(const GNEAdditional *TAZ) const
check if there is already a TAZRel defined in one TAZ
void addGenericDataChild(GNEGenericData *genericData)
add generic data child
GNEDataInterval * retrieveInterval(const double begin, const double end) const
return interval
Definition: GNEDataSet.cpp:280
void addDataIntervalChild(GNEDataInterval *dataInterval)
add data interval child
Definition: GNEDataSet.cpp:206
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEEdgeData.h:38
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
An Element which don't belong to GNENet but has influence in the simulation.
An Element which don't belong to GNENet but has influence in the simulation.
void addChildElement(T *element)
add child element
void insertDataSet(GNEDataSet *dataSet)
Insert a demand element element int GNENet container.
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
GNEDataSet * retrieveDataSet(const std::string &id, bool hardFail=true) const
Returns the named data set.
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:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
void incRef(const std::string &debugMsg="")
Increase reference.
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNETAZRelData.h:38
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
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45