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-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 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
56bool
58 // nothing to do
59 return true;
60}
61
62
63bool
64GNEDataHandler::buildDataSet(const std::string& id) {
65 // first check if dataSet exist
67 return false;
68 } else if (!checkDuplicatedDataSet(id)) {
69 return false;
70 } else {
71 GNEDataSet* dataSet = new GNEDataSet(myNet, id);
72 if (myAllowUndoRedo) {
73 myNet->getViewNet()->getUndoList()->begin(dataSet, TL("add data set"));
74 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataSet(dataSet, true), true);
76 } else {
77 // insert dataSet without allowing undo/redo
79 dataSet->incRef("buildDataSet");
80 }
81 return true;
82 }
83}
84
85
86bool
88 const std::string& dataSetID, const double begin, const double end) {
89 // get dataSet
90 GNEDataSet* dataSet = myNet->getAttributeCarriers()->retrieveDataSet(dataSetID, false);
91 // first check if dataSet exist
92 if (dataSet == nullptr) {
93 // create dataset AND data interval
94 dataSet = new GNEDataSet(myNet, dataSetID);
95 GNEDataInterval* dataInterval = new GNEDataInterval(dataSet, begin, end);
96 if (myAllowUndoRedo) {
97 myNet->getViewNet()->getUndoList()->begin(dataInterval, TL("add data set and data interval"));
98 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataSet(dataSet, true), true);
99 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataInterval(dataInterval, true), true);
101 } else {
102 // insert dataSet allowing undo/redo
104 dataSet->incRef("buildDataInterval");
105 // insert dataInterval without allowing undo/redo
106 dataSet->addDataIntervalChild(dataInterval);
107 dataInterval->incRef("buildDataInterval");
108 }
109 return true;
110 } else if (dataSet->retrieveInterval(begin, end) == nullptr) {
111 GNEDataInterval* dataInterval = new GNEDataInterval(dataSet, begin, end);
112 if (myAllowUndoRedo) {
113 myNet->getViewNet()->getUndoList()->begin(dataInterval, TL("add data interval"));
114 myNet->getViewNet()->getUndoList()->add(new GNEChange_DataInterval(dataInterval, true), true);
116 } else {
117 // insert dataInterval without allowing undo/redo
118 dataSet->addDataIntervalChild(dataInterval);
119 dataInterval->incRef("buildDataInterval");
120 }
121 return true;
122 } else {
123 return false;
124 }
125}
126
127
128bool
129GNEDataHandler::buildEdgeData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& edgeID,
130 const Parameterised::Map& parameters) {
131 // get dataSet
133 if (dataSet != nullptr) {
134 // get interval
135 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
138 if (dataInterval != nullptr) {
139 // get data
140 GNEEdge* edge = myNet->getAttributeCarriers()->retrieveEdge(edgeID, false);
141 if (edge) {
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 } else {
155 }
156 } else {
158 }
159 } else {
161 }
162}
163
164
165bool
166GNEDataHandler::buildEdgeRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromEdgeID,
167 const std::string& toEdgeID, const Parameterised::Map& parameters) {
168 // get dataSet
170 if (dataSet != nullptr) {
171 // get interval
172 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
175 if (dataInterval != nullptr) {
176 // get data
177 GNEEdge* const fromEdge = myNet->getAttributeCarriers()->retrieveEdge(fromEdgeID, false);
178 GNEEdge* const toEdge = myNet->getAttributeCarriers()->retrieveEdge(toEdgeID, false);
179 if (fromEdge == nullptr) {
181 } else if (toEdge == nullptr) {
183 } else {
184 // avoid duplicated edgeRel in the same interval
185 if (dataInterval->edgeRelExists(fromEdge, toEdge)) {
186 return writeError(TLF("There is already a edgeRel defined between '%' and '%'.", fromEdgeID, toEdgeID));
187 } else {
188 GNEGenericData* edgeData = new GNEEdgeRelData(dataInterval, fromEdge, toEdge, parameters);
189 if (myAllowUndoRedo) {
190 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add edge rel"));
191 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
193 } else {
194 dataInterval->addGenericDataChild(edgeData);
195 fromEdge->addChildElement(edgeData);
196 toEdge->addChildElement(edgeData);
197 edgeData->incRef("buildEdgeRelationData");
198 }
199 return true;
200 }
201 }
202 } else {
204 }
205 } else {
207 }
208}
209
210
211bool
212GNEDataHandler::buildTAZRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromTAZID,
213 const std::string& toTAZID, const Parameterised::Map& parameters) {
214 // get dataSet
216 if (dataSet != nullptr) {
217 // get interval
218 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
221 if (dataInterval != nullptr) {
222 // get from TAZs
225 if (fromTAZ == nullptr) {
227 } else if (toTAZ == nullptr) {
229 } else if ((fromTAZ != toTAZ) && dataInterval->TAZRelExists(fromTAZ, toTAZ)) {
230 return writeError(TLF("There is already a TAZ rel defined between '%' and '%'.", fromTAZID, toTAZID));
231 } else if ((fromTAZ == toTAZ) && dataInterval->TAZRelExists(fromTAZ)) {
232 return writeError(TLF("There is already a TAZ rel defined in '%'.", toTAZID));
233 } else if (fromTAZ == toTAZ) {
234 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, parameters);
235 if (myAllowUndoRedo) {
236 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add TAZ rel"));
237 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
239 } else {
240 dataInterval->addGenericDataChild(edgeData);
241 fromTAZ->addChildElement(edgeData);
242 edgeData->incRef("buildTAZRelationData");
243 }
244 return true;
245 } else {
246 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, toTAZ, parameters);
247 if (myAllowUndoRedo) {
248 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add TAZ rel"));
249 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
251 } else {
252 dataInterval->addGenericDataChild(edgeData);
253 fromTAZ->addChildElement(edgeData);
254 toTAZ->addChildElement(edgeData);
255 edgeData->incRef("buildTAZRelationData");
256 }
257 return true;
258 }
259 } else {
261 }
262 } else {
264 }
265}
266
267
268bool
270 // retrieve data set
271 auto dataSet = myNet->getAttributeCarriers()->retrieveDataSet(id, false);
272 // if demand exist, check if overwrite (delete)
273 if (dataSet) {
274 if (!myAllowUndoRedo) {
275 // only overwrite if allow undo-redo
277 } else if (myOverwrite) {
278 // delete demand element (and all of their childrens)
280 } else {
281 // duplicated dataSet
283 }
284 }
285 return true;
286}
287
288/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
@ 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 writeErrorDuplicated(const SumoXMLTag tag, const std::string &id, const SumoXMLTag checkedTag)
write error "duplicated additional"
bool checkValidAdditionalID(const SumoXMLTag tag, const std::string &value)
check if the given additional ID is valid
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
An Element which don't belong to GNENet but has influence in the simulation.
~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
GNEDataHandler(GNENet *net, const std::string &file, const bool allowUndoRedo, const bool overwrite)
Constructor.
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.
const bool myOverwrite
check if overwrite
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
An Element which don't belong to GNENet but has influence in the simulation.
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
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 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:127
void deleteDataSet(GNEDataSet *dataSet, GNEUndoList *undoList)
remove data set
Definition GNENet.cpp:723
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
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