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-2025 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
29#include <netedit/GNENet.h>
31#include <netedit/GNEUndoList.h>
32#include <netedit/GNEViewNet.h>
34
35#include "GNEDataHandler.h"
36
37// ===========================================================================
38// member method definitions
39// ===========================================================================
40
41GNEDataHandler::GNEDataHandler(GNENet* net, const std::string& file, const bool allowUndoRedo) :
42 DataHandler(file),
43 myNet(net),
44 myAllowUndoRedo(allowUndoRedo) {
45}
46
47
49
50
51bool
53 // nothing to do
54 return true;
55}
56
57
58bool
59GNEDataHandler::buildDataSet(const std::string& id) {
60 // first check if dataSet exist
62 return false;
63 } else if (!checkDuplicatedDataSet(id)) {
64 return false;
65 } else {
66 GNEDataSet* dataSet = new GNEDataSet(id, myNet, myFilename);
67 if (myAllowUndoRedo) {
68 myNet->getViewNet()->getUndoList()->begin(dataSet, TL("add data set"));
69 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataSet(dataSet, true), true);
71 } else {
72 // insert dataSet without allowing undo/redo
74 dataSet->incRef("buildDataSet");
75 }
76 return true;
77 }
78}
79
80
81bool
83 const std::string& dataSetID, const double begin, const double end) {
84 // get dataSet
85 GNEDataSet* dataSet = myNet->getAttributeCarriers()->retrieveDataSet(dataSetID, false);
86 // first check if dataSet exist
87 if (dataSet == nullptr) {
88 // create dataset AND data interval
89 dataSet = new GNEDataSet(dataSetID, myNet, myFilename);
90 GNEDataInterval* dataInterval = new GNEDataInterval(dataSet, begin, end);
91 if (myAllowUndoRedo) {
92 myNet->getViewNet()->getUndoList()->begin(dataInterval, TL("add data set and data interval"));
93 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataSet(dataSet, true), true);
94 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataInterval(dataInterval, true), true);
96 } else {
97 // insert dataSet allowing undo/redo
99 dataSet->incRef("buildDataInterval");
100 // insert dataInterval without allowing undo/redo
101 dataSet->addDataIntervalChild(dataInterval);
102 dataInterval->incRef("buildDataInterval");
103 }
104 return true;
105 } else if (dataSet->retrieveInterval(begin, end) == nullptr) {
106 GNEDataInterval* dataInterval = new GNEDataInterval(dataSet, begin, end);
107 if (myAllowUndoRedo) {
108 myNet->getViewNet()->getUndoList()->begin(dataInterval, TL("add data interval"));
109 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataInterval(dataInterval, true), true);
111 } else {
112 // insert dataInterval without allowing undo/redo
113 dataSet->addDataIntervalChild(dataInterval);
114 dataInterval->incRef("buildDataInterval");
115 }
116 return true;
117 } else {
118 return false;
119 }
120}
121
122
123bool
124GNEDataHandler::buildEdgeData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& edgeID,
125 const Parameterised::Map& parameters) {
126 // get dataSet
128 if (dataSet) {
129 // get interval
130 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
133 if (dataInterval) {
134 // get data
135 GNEEdge* edge = myNet->getAttributeCarriers()->retrieveEdge(edgeID, false);
136 if (edge == nullptr) {
138 } else if (dataInterval->edgeRelSingleExists(edge)) {
139 return writeError(TLF("There is already a edgeRel defined in edge '%'.", edge));
140 } else {
141 // create edge data
142 GNEGenericData* edgeData = new GNEEdgeData(dataInterval, edge, parameters);
143 if (myAllowUndoRedo) {
144 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add edge rel"));
145 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
147 } else {
148 dataInterval->addGenericDataChild(edgeData);
149 edge->addChildElement(edgeData);
150 edgeData->incRef("buildEdgeData");
151 }
152 return true;
153 }
154 } else {
156 }
157 } else {
159 }
160}
161
162
163bool
164GNEDataHandler::buildEdgeRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromEdgeID,
165 const std::string& toEdgeID, const Parameterised::Map& parameters) {
166 // get dataSet
168 if (dataSet != nullptr) {
169 // get interval
170 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
173 if (dataInterval != nullptr) {
174 // get data
175 GNEEdge* const fromEdge = myNet->getAttributeCarriers()->retrieveEdge(fromEdgeID, false);
176 GNEEdge* const toEdge = myNet->getAttributeCarriers()->retrieveEdge(toEdgeID, false);
177 if (fromEdge == nullptr) {
179 } else if (toEdge == nullptr) {
181 } else if (dataInterval->edgeRelExists(fromEdge, toEdge)) {
182 return writeError(TLF("There is already a edgeRel defined between '%' and '%'.", fromEdgeID, toEdgeID));
183 } else {
184 GNEGenericData* edgeData = new GNEEdgeRelData(dataInterval, fromEdge, toEdge, parameters);
185 if (myAllowUndoRedo) {
186 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add edge rel"));
187 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
189 } else {
190 dataInterval->addGenericDataChild(edgeData);
191 fromEdge->addChildElement(edgeData);
192 toEdge->addChildElement(edgeData);
193 edgeData->incRef("buildEdgeRelationData");
194 }
195 return true;
196 }
197 } else {
199 }
200 } else {
202 }
203}
204
205
206bool
207GNEDataHandler::buildTAZRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromTAZID,
208 const std::string& toTAZID, const Parameterised::Map& parameters) {
209 // get dataSet
211 if (dataSet != nullptr) {
212 // get interval
213 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
216 if (dataInterval != nullptr) {
217 // get from TAZs
220 if (fromTAZ == nullptr) {
222 } else if (toTAZ == nullptr) {
224 } else if ((fromTAZ != toTAZ) && dataInterval->TAZRelExists(fromTAZ, toTAZ)) {
225 return writeError(TLF("There is already a TAZ rel defined between '%' and '%'.", fromTAZID, toTAZID));
226 } else if ((fromTAZ == toTAZ) && dataInterval->TAZRelExists(fromTAZ)) {
227 return writeError(TLF("There is already a TAZ rel defined in '%'.", toTAZID));
228 } else if (fromTAZ == toTAZ) {
229 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, parameters);
230 if (myAllowUndoRedo) {
231 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add TAZ rel"));
232 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
234 } else {
235 dataInterval->addGenericDataChild(edgeData);
236 fromTAZ->addChildElement(edgeData);
237 edgeData->incRef("buildTAZRelationData");
238 }
239 return true;
240 } else {
241 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, toTAZ, parameters);
242 if (myAllowUndoRedo) {
243 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add TAZ rel"));
244 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
246 } else {
247 dataInterval->addGenericDataChild(edgeData);
248 fromTAZ->addChildElement(edgeData);
249 toTAZ->addChildElement(edgeData);
250 edgeData->incRef("buildTAZRelationData");
251 }
252 return true;
253 }
254 } else {
256 }
257 } else {
259 }
260}
261
262
263bool
265 // retrieve data set
266 auto dataSet = myNet->getAttributeCarriers()->retrieveDataSet(id, false);
267 // if demand exist, check if overwrite (delete)
268 if (dataSet) {
270 // delete data element (and all of their childrens)
272 } else if (myRemainElements) {
273 // duplicated dataset
275 } else {
276 // open overwrite dialog
277 GNEOverwriteElement overwriteElementDialog(this, dataSet);
278 // continue depending of result
279 if (overwriteElementDialog.getResult() == GNEOverwriteElement::Result::ACCEPT) {
280 // delete data element (and all of their childrens)
282 } else if (overwriteElementDialog.getResult() == GNEOverwriteElement::Result::CANCEL) {
283 // duplicated dataset
285 } else {
286 return false;
287 }
288 }
289 }
290 return true;
291}
292
293/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:305
#define TLF(string,...)
Definition MsgHandler.h:307
@ 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
bool writeError(const std::string &error)
write error and enable error creating element
bool writeErrorInvalidParent(const SumoXMLTag tag, const std::string &id, const SumoXMLTag parentTag, const std::string &parentID)
write error "invalid parent element" giving ids of current and parent element
bool writeWarningDuplicated(const SumoXMLTag tag, const std::string &id, const SumoXMLTag checkedTag)
write warning duplicated element
bool myOverwriteElements
overwrite elements
bool checkValidAdditionalID(const SumoXMLTag tag, const std::string &value)
check if the given additional ID is valid
const std::string myFilename
filename
bool myRemainElements
remain elements
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:36
~GNEDataHandler()
Destructor.
bool buildDataInterval(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &dataSetID, const double begin, const double end)
Builds DataInterval.
bool buildTAZRelationData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &fromTAZID, const std::string &toTAZID, const Parameterised::Map &parameters)
Builds TAZRelationData.
bool buildDataSet(const std::string &id)
Builds DataSet (exclusive of netedit)
const bool myAllowUndoRedo
allow undo/redo
bool buildEdgeRelationData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &fromEdgeID, const std::string &toEdgeID, const Parameterised::Map &parameters)
Builds edgeRelationData.
bool buildEdgeData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &edgeID, const Parameterised::Map &parameters)
Builds edgeData.
bool checkDuplicatedDataSet(const std::string &id)
check if given ID correspond to a duplicated dataSet
bool postParserTasks()
run post parser tasks
GNENet * myNet
pointer to GNENet
GNEDataHandler()=delete
invalidate default constructor
bool edgeRelExists(const GNEEdge *fromEdge, const GNEEdge *toEdge) const
check if there is already a edgeRel defined between two edges
bool TAZRelExists(const GNEAdditional *TAZ) const
check if there is already a TAZRel defined in one TAZ
bool edgeRelSingleExists(const GNEEdge *edge) const
check if there is already a edgeRel single defined in the given edge
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
Result getResult() const
get result to indicate if this dialog was closed accepting or rejecting changes
Definition GNEDialog.cpp:87
An Element which don't belong to GNENet but has influence in the simulation.
Definition GNEEdgeData.h:32
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.
void addChildElement(ChildType *element)
add child without updating parent (ONLY used if we're creating elements without undo-redo)
void insertDataSet(GNEDataSet *dataSet)
Insert a data set in 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:144
void deleteDataSet(GNEDataSet *dataSet, GNEUndoList *undoList)
remove data set
Definition GNENet.cpp:772
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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