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
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(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(dataInterval, 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(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(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* const fromEdge = myNet->getAttributeCarriers()->retrieveEdge(fromEdgeID, false);
163 GNEEdge* const toEdge = myNet->getAttributeCarriers()->retrieveEdge(toEdgeID, false);
164 if (fromEdge == nullptr) {
166 } else if (toEdge == nullptr) {
168 } else {
169 // avoid duplicated edgeRel in the same interval
170 if (dataInterval->edgeRelExists(fromEdge, toEdge)) {
171 writeError(TLF("There is already a edgeRel defined between '%' and '%'.", fromEdgeID, toEdgeID));
172 } else {
173 GNEGenericData* edgeData = new GNEEdgeRelData(dataInterval, fromEdge, toEdge, parameters);
174 if (myAllowUndoRedo) {
175 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add edge rel"));
176 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
178 } else {
179 dataInterval->addGenericDataChild(edgeData);
180 fromEdge->addChildElement(edgeData);
181 toEdge->addChildElement(edgeData);
182 edgeData->incRef("buildEdgeRelationData");
183 }
184 }
185 }
186 } else {
188 }
189 } else {
191 }
192}
193
194
195void
196GNEDataHandler::buildTAZRelationData(const CommonXMLStructure::SumoBaseObject* sumoBaseObject, const std::string& fromTAZID,
197 const std::string& toTAZID, const Parameterised::Map& parameters) {
198 // get dataSet
200 if (dataSet != nullptr) {
201 // get interval
202 GNEDataInterval* dataInterval = dataSet->retrieveInterval(
205 if (dataInterval != nullptr) {
206 // get from TAZs
209 if (fromTAZ == nullptr) {
211 } else if (toTAZ == nullptr) {
213 } else if ((fromTAZ != toTAZ) && dataInterval->TAZRelExists(fromTAZ, toTAZ)) {
214 writeError(TLF("There is already a TAZ rel defined between '%' and '%'.", fromTAZID, toTAZID));
215 } else if ((fromTAZ == toTAZ) && dataInterval->TAZRelExists(fromTAZ)) {
216 writeError(TLF("There is already a TAZ rel defined in '%'.", toTAZID));
217 } else if (fromTAZ == toTAZ) {
218 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, parameters);
219 if (myAllowUndoRedo) {
220 myNet->getViewNet()->getUndoList()->begin(edgeData, TL("add TAZ rel"));
221 myNet->getViewNet()->getUndoList()->add(new GNEChange_GenericData(edgeData, true), true);
223 } else {
224 dataInterval->addGenericDataChild(edgeData);
225 fromTAZ->addChildElement(edgeData);
226 edgeData->incRef("buildTAZRelationData");
227 }
228 } else {
229 GNEGenericData* edgeData = new GNETAZRelData(dataInterval, fromTAZ, toTAZ, 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 toTAZ->addChildElement(edgeData);
238 edgeData->incRef("buildTAZRelationData");
239 }
240 }
241 } else {
243 }
244 } else {
246 }
247}
248
249
250void
251GNEDataHandler::writeErrorDuplicated(const SumoXMLTag tag, const std::string& id) {
252 writeError(TLF("Could not build % with ID '%'", toString(tag), id) + std::string("; ") + TL("declared twice."));
253}
254
255
256void
258 writeError(TLF("Could not build %", toString(tag)) + std::string("; ") + TLF("% doesn't exist.", toString(parent)));
259}
260
261
262void
263GNEDataHandler::writeErrorInvalidParent(const SumoXMLTag tag, const SumoXMLTag parent, const std::string& id) {
264 writeError(TLF("Could not build %", toString(tag)) + std::string("; ") + TLF("% '%' doesn't exist.", toString(parent), id));
265}
266
267/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
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 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
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
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