Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDataHandler.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// 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, const bool overwrite) :
46 DataHandler(file),
47 myNet(net),
48 myAllowUndoRedo(allowUndoRedo),
49 myOverwrite(overwrite) {
50}
51
52
54
55
56void
57GNEDataHandler::buildDataSet(const std::string& dataSetID) {
58 // first check if dataSet exist
59 if (myNet->getAttributeCarriers()->retrieveDataSet(dataSetID, false) == nullptr) {
60 GNEDataSet* dataSet = new GNEDataSet(myNet, dataSetID);
61 if (myAllowUndoRedo) {
62 myNet->getViewNet()->getUndoList()->begin(GUIIcon::DATASET, TL("add data set"));
63 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataSet(dataSet, true), true);
65 } else {
66 // insert dataSet without allowing undo/redo
68 dataSet->incRef("buildDataSet");
69 }
70 } else {
72 }
73}
74
75
76void
78 const std::string& dataSetID, const double begin, const double end) {
79 // get dataSet
80 GNEDataSet* dataSet = myNet->getAttributeCarriers()->retrieveDataSet(dataSetID, false);
81 // first check if dataSet exist
82 if (dataSet == nullptr) {
83 // create dataset AND data interval
84 dataSet = new GNEDataSet(myNet, dataSetID);
85 GNEDataInterval* dataInterval = new GNEDataInterval(dataSet, begin, end);
86 if (myAllowUndoRedo) {
87 myNet->getViewNet()->getUndoList()->begin(GUIIcon::DATASET, TL("add data set and data interval"));
88 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataSet(dataSet, true), true);
89 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataInterval(dataInterval, true), true);
91 } else {
92 // insert dataSet allowing undo/redo
94 dataSet->incRef("buildDataInterval");
95 // insert dataInterval without allowing undo/redo
96 dataSet->addDataIntervalChild(dataInterval);
97 dataInterval->incRef("buildDataInterval");
98 }
99 } else if (dataSet->retrieveInterval(begin, end) == nullptr) {
100 GNEDataInterval* dataInterval = new GNEDataInterval(dataSet, begin, end);
101 if (myAllowUndoRedo) {
102 myNet->getViewNet()->getUndoList()->begin(GUIIcon::DATAINTERVAL, TL("add data interval"));
103 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataInterval(dataInterval, true), true);
105 } else {
106 // insert dataInterval without allowing undo/redo
107 dataSet->addDataIntervalChild(dataInterval);
108 dataInterval->incRef("buildDataInterval");
109 }
110 }
111}
112
113
114void
115GNEDataHandler::buildEdgeData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& edgeID,
116 const Parameterised::Map& parameters) {
117 // get dataSet
119 if (dataSet != nullptr) {
120 // get interval
121 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
124 if (dataInterval != nullptr) {
125 // get data
126 GNEEdge* edge = myNet->getAttributeCarriers()->retrieveEdge(edgeID, false);
127 if (edge) {
128 GNEGenericData* edgeData = new GNEEdgeData(dataInterval, edge, parameters);
129 if (myAllowUndoRedo) {
130 myNet->getViewNet()->getUndoList()->begin(GUIIcon::EDGEDATA, TL("add edge rel"));
131 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
133 } else {
134 dataInterval->addGenericDataChild(edgeData);
135 edge->addChildElement(edgeData);
136 edgeData->incRef("buildEdgeData");
137 }
138 } else {
140 }
141 } else {
143 }
144 } else {
146 }
147}
148
149
150void
151GNEDataHandler::buildEdgeRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromEdgeID,
152 const std::string& toEdgeID, const Parameterised::Map& parameters) {
153 // get dataSet
155 if (dataSet != nullptr) {
156 // get interval
157 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
160 if (dataInterval != nullptr) {
161 // get data
162 GNEEdge* fromEdge = myNet->getAttributeCarriers()->retrieveEdge(fromEdgeID, false);
163 GNEEdge* toEdge = myNet->getAttributeCarriers()->retrieveEdge(toEdgeID, false);
164 if (fromEdge && toEdge) {
165 GNEGenericData* edgeData = new GNEEdgeRelData(dataInterval, fromEdge, toEdge, parameters);
166 if (myAllowUndoRedo) {
167 myNet->getViewNet()->getUndoList()->begin(GUIIcon::EDGERELDATA, TL("add edge rel"));
168 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
170 } else {
171 dataInterval->addGenericDataChild(edgeData);
172 fromEdge->addChildElement(edgeData);
173 toEdge->addChildElement(edgeData);
174 edgeData->incRef("buildEdgeRelationData");
175 }
176 } else {
178 }
179 } else {
181 }
182 } else {
184 }
185}
186
187
188void
189GNEDataHandler::buildTAZRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromTAZID,
190 const std::string& toTAZID, const Parameterised::Map& parameters) {
191 // get dataSet
193 if (dataSet != nullptr) {
194 // get interval
195 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
198 if (dataInterval != nullptr) {
199 // get from TAZs
202 if (fromTAZ == nullptr) {
204 } else if (toTAZ == nullptr) {
206 } else if ((fromTAZ != toTAZ) && dataInterval->TAZRelExists(fromTAZ, toTAZ)) {
207 writeError(TLF("There is already a TAZ rel defined between '%' and '%'.", fromTAZID, toTAZID));
208 } else if ((fromTAZ == toTAZ) && dataInterval->TAZRelExists(fromTAZ)) {
209 writeError(TLF("There is already a TAZ rel defined in '%'.", toTAZID));
210 } else if (fromTAZ == toTAZ) {
211 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, parameters);
212 if (myAllowUndoRedo) {
213 myNet->getViewNet()->getUndoList()->begin(GUIIcon::TAZRELDATA, TL("add TAZ rel"));
214 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
216 } else {
217 dataInterval->addGenericDataChild(edgeData);
218 fromTAZ->addChildElement(edgeData);
219 edgeData->incRef("buildTAZRelationData");
220 }
221 } else {
222 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, toTAZ, parameters);
223 if (myAllowUndoRedo) {
224 myNet->getViewNet()->getUndoList()->begin(GUIIcon::TAZRELDATA, TL("add TAZ rel"));
225 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
227 } else {
228 dataInterval->addGenericDataChild(edgeData);
229 fromTAZ->addChildElement(edgeData);
230 toTAZ->addChildElement(edgeData);
231 edgeData->incRef("buildTAZRelationData");
232 }
233 }
234 } else {
236 }
237 } else {
239 }
240}
241
242
243void
244GNEDataHandler::writeErrorDuplicated(const SumoXMLTag tag, const std::string& id) {
245 writeError(TLF("Could not build % with ID '%' in netedit", toString(tag), id) + std::string("; ") + TL("Declared twice."));
246}
247
248
249void
251 writeError(TLF("Could not build % in netedit", toString(tag)) + std::string("; ") + TLF("% doesn't exist.", toString(parent)));
252}
253
254
255void
256GNEDataHandler::writeErrorInvalidParent(const SumoXMLTag tag, const SumoXMLTag parent, const std::string& ID) {
257 writeError(TLF("Could not build % with ID '%' in netedit", toString(tag), ID) + std::string("; ") + TLF("% doesn't exist.", toString(parent)));
258}
259
260/****************************************************************************/
@ DATAINTERVAL
#define TL(string)
Definition MsgHandler.h:287
#define TLF(string,...)
Definition MsgHandler.h:288
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
@ GNE_TAG_EDGEREL_SINGLE
@ 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.
~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"
GNEDataHandler(GNENet *net, const std::string &file, const bool allowUndoRedo, const bool overwrite)
Constructor.
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
void addDataIntervalChild(GNEDataInterval *dataInterval)
add data interval child
An Element which don't belong to GNENet but has influence in the simulation.
Definition GNEEdgeData.h:37
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:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
void incRef(const std::string &debugMsg="")
Increase reference.
An Element which don't belong to GNENet but has influence in the simulation.
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