Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEGeneralHandler.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// General element handler for netedit
19/****************************************************************************/
20
21#include <utils/xml/XMLSubSys.h>
22
23#include "GNEGeneralHandler.h"
24
25// ===========================================================================
26// method definitions
27// ===========================================================================
28
29GNEGeneralHandler::GNEGeneralHandler(GNENet* net, const std::string& file, const bool allowUndoRedo) :
30 GeneralHandler(file),
31 myAdditionalHandler(net, file, allowUndoRedo),
32 myDemandHandler(net, file, allowUndoRedo),
33 myMeanDataHandler(net, file, allowUndoRedo) {
34}
35
36
38
39
40void
42 myAdditionalHandler.forceOverwriteElements();
43 myDemandHandler.forceOverwriteElements();
44 myMeanDataHandler.forceOverwriteElements();
45}
46
47
48bool
50 if (isAdditionalFile()) {
51 return myAdditionalHandler.postParserTasks();
52 } else if (isRouteFile()) {
53 return myDemandHandler.postParserTasks();
54 } else if (isMeanDataFile()) {
55 return myMeanDataHandler.postParserTasks();
56 } else {
57 return true;
58 }
59}
60
61
62bool
64 return (myAdditionalHandler.isErrorCreatingElement() ||
65 myDemandHandler.isErrorCreatingElement() ||
66 myMeanDataHandler.isErrorCreatingElement());
67}
68
69
70bool
74
75
76bool
80
81
82bool
86
87
88void
90 // continue depending of tag
91 switch (tag) {
93 // process in Network handler
94 myQueue.push_back(TagType(tag, TagType::Type::NETWORK));
95 break;
96 case SUMO_TAG_PARAM:
98 if (myQueue.size() > 0) {
99 // try to parse additional or demand element depending of last inserted tag
100 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
102 } else if (myQueue.back().isDemand() && myDemandHandler.beginParseAttributes(tag, attrs)) {
103 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
104 } else {
105 myQueue.push_back(TagType(tag, TagType::Type::NONE));
106 }
107 } else {
108 myQueue.push_back(TagType(tag, TagType::Type::NONE));
109 }
110 break;
111 case SUMO_TAG_FLOW:
112 if (myQueue.size() > 0) {
113 // try to parse additional or demand element depending of last inserted tag
114 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
116 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
117 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
118 } else {
119 myQueue.push_back(TagType(tag, TagType::Type::NONE));
120 }
121 } else {
122 myQueue.push_back(TagType(tag, TagType::Type::NONE));
123 }
124 break;
125 default:
126 // try to parse additional or demand element
127 if (myAdditionalHandler.beginParseAttributes(tag, attrs)) {
129 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
130 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
131 } else if (myMeanDataHandler.beginParseAttributes(tag, attrs)) {
132 myQueue.push_back(TagType(tag, TagType::Type::MEANDATA));
133 } else {
134 myQueue.push_back(TagType(tag, TagType::Type::NONE));
135 }
136 break;
137 }
138 // maximum 10 tagTypes
139 if (myQueue.size() > 10) {
140 myQueue.pop_front();
141 }
142 // check if update handlers
143 const bool abortLoading = myAdditionalHandler.isAbortLoading() ||
144 myDemandHandler.isAbortLoading() ||
145 myMeanDataHandler.isAbortLoading();
146 const bool forceOverwrite = myAdditionalHandler.isForceOverwriteElements() ||
147 myDemandHandler.isForceOverwriteElements() ||
148 myMeanDataHandler.isForceOverwriteElements();
149 const bool forceRemain = myAdditionalHandler.isForceRemainElements() ||
150 myDemandHandler.isForceRemainElements() ||
151 myMeanDataHandler.isForceRemainElements();
152 if (abortLoading) {
153 myAdditionalHandler.abortLoading();
154 myDemandHandler.abortLoading();
155 myMeanDataHandler.abortLoading();
156 } else if (forceOverwrite) {
157 myAdditionalHandler.forceOverwriteElements();
158 myDemandHandler.forceOverwriteElements();
159 myMeanDataHandler.forceOverwriteElements();
160 } else if (forceRemain) {
161 myAdditionalHandler.forceRemainElements();
162 myDemandHandler.forceRemainElements();
163 myMeanDataHandler.forceRemainElements();
164 }
165}
166
167
168void
170 // check tagType
171 if (myQueue.back().isNetwork()) {
172 // currently ignored (will be implemented in the future)
173 } else if (myQueue.back().isAdditional()) {
174 // end parse additional elements
175 myAdditionalHandler.endParseAttributes();
176 // mark file as additional
178 } else if (myQueue.back().isDemand()) {
179 // end parse demand elements
180 myDemandHandler.endParseAttributes();
181 // mark file as demand
183 } else if (myQueue.back().isMeanData()) {
184 // end parse meanData elements
185 myMeanDataHandler.endParseAttributes();
186 // mark file as mean data
188 } else {
189 // mark file as demand
191 }
192}
193
194
199
200
201bool
205
206
207bool
211
212
213bool
217
218
219bool
223
224
225bool
229
230/****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_LOCATION
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ SUMO_TAG_PARAM
parameter associated to a certain key
GNEGeneralHandler(GNENet *net, const std::string &file, const bool allowUndoRedo)
Constructor.
void endTag()
end element
bool isAdditionalFile() const
check if the parser file is a additional file
void beginTag(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
start element
bool isRouteFile() const
check if the parser file is a route file
~GNEGeneralHandler()
Destructor.
std::list< TagType > myQueue
queue with the inserted tags
bool isMeanDataFile() const
check if the parser file is a meanData file
void forceOverwriteElements()
force overwritte elements (used if we're reloading elements)
bool postParserTasks()
run post parser tasks
GNEAdditionalHandler myAdditionalHandler
additional handler
bool isErrorCreatingElement() const
get flag for check if a element wasn't created
TagType::Type fileType
flag for set file type
GNEMeanDataHandler myMeanDataHandler
meanData handler
GNERouteHandler myDemandHandler
demand handler
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GeneralHandler(const std::string &file)
Constructor.
Encapsulated SAX-Attributes.
const SumoXMLTag tag
tag related with this TagType
bool isDemand() const
is network element
bool isData() const
is network element
bool isMeanData() const
is network element
TagType(SumoXMLTag tag, Type type)
constructor
bool isNetwork() const
is network element
bool isAdditional() const
is network element