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
46
47
48bool
50 if (isAdditionalFile()) {
52 } else if (isRouteFile()) {
54 } else if (isMeanDataFile()) {
56 } else {
57 return true;
58 }
59}
60
61
62bool
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
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() ||
146 const bool forceOverwrite = myAdditionalHandler.isForceOverwriteElements() ||
149 const bool forceRemain = myAdditionalHandler.isForceRemainElements() ||
152 if (abortLoading) {
156 } else if (forceOverwrite) {
160 } else if (forceRemain) {
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
176 // mark file as additional
178 } else if (myQueue.back().isDemand()) {
179 // end parse demand elements
181 // mark file as demand
183 } else if (myQueue.back().isMeanData()) {
184 // end parse meanData elements
186 // mark file as mean data
188 } else {
189 // mark file as demand
191 }
192}
193
194
196 tag(tag_),
197 myType(type) {
198}
199
200
201bool
203 return (myType == Type::NETWORK);
204}
205
206
207bool
209 return (myType == Type::ADDITIONAL);
210}
211
212
213bool
215 return (myType == Type::DEMAND);
216}
217
218
219bool
221 return (myType == Type::DATA);
222}
223
224
225bool
227 return (myType == Type::MEANDATA);
228}
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
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
void endParseAttributes()
end parse attributes
void forceRemainElements()
force remain elements (used if we're reloading elements)
bool isForceRemainElements() const
force remain elements (used if we're reloading elements)
bool isForceOverwriteElements() const
force overwritte elements (used if we're reloading elements)
void abortLoading()
abort loading
bool isAbortLoading() const
abort loading
bool isErrorCreatingElement() const
get flag for mark if a element wasn't created
void forceOverwriteElements()
force overwritte elements (used if we're reloading elements)
bool postParserTasks()
run post parser tasks
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
bool postParserTasks()
run post parser tasks
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
bool postParserTasks()
run post parser tasks
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
void endParseAttributes()
end parse attributes
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
void endParseAttributes()
end parse attributes
Encapsulated SAX-Attributes.
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