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, FileBucket* fileBucket, const bool allowUndoRedo) :
30 GeneralHandler(fileBucket),
31 myAdditionalHandler(net, fileBucket, allowUndoRedo),
32 myDemandHandler(net, fileBucket, allowUndoRedo, true),
33 myMeanDataHandler(net, fileBucket, allowUndoRedo) {
34}
35
36
38
39
40void
46
47
48bool
54
55
56bool
60
61
62bool
66
67
68bool
72
73
74void
76 // continue depending of tag
77 switch (tag) {
79 // process in Network handler
80 myQueue.push_back(TagType(tag, TagType::Type::NETWORK));
81 break;
82 case SUMO_TAG_PARAM:
84 if (myQueue.size() > 0) {
85 // try to parse additional or demand element depending of last inserted tag
86 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
88 } else if (myQueue.back().isDemand() && myDemandHandler.beginParseAttributes(tag, attrs)) {
89 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
90 } else {
91 myQueue.push_back(TagType(tag, TagType::Type::NONE));
92 }
93 } else {
94 myQueue.push_back(TagType(tag, TagType::Type::NONE));
95 }
96 break;
97 case SUMO_TAG_FLOW:
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 (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 default:
112 // try to parse additional or demand element
115 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
116 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
117 } else if (myMeanDataHandler.beginParseAttributes(tag, attrs)) {
118 myQueue.push_back(TagType(tag, TagType::Type::MEANDATA));
119 } else {
120 myQueue.push_back(TagType(tag, TagType::Type::NONE));
121 }
122 break;
123 }
124 // maximum 10 tagTypes
125 if (myQueue.size() > 10) {
126 myQueue.pop_front();
127 }
128 // check if update handlers
129 const bool abortLoading = myAdditionalHandler.isAbortLoading() ||
132 const bool forceOverwrite = myAdditionalHandler.isForceOverwriteElements() ||
135 const bool forceRemain = myAdditionalHandler.isForceRemainElements() ||
138 if (abortLoading) {
142 } else if (forceOverwrite) {
146 } else if (forceRemain) {
150 }
151}
152
153
154void
156 // check tagType
157 if (myQueue.back().isNetwork()) {
158 // currently ignored (will be implemented in the future)
159 } else if (myQueue.back().isAdditional()) {
160 // end parse additional elements
162 // mark file as additional
164 } else if (myQueue.back().isDemand()) {
165 // end parse demand elements
167 // mark file as demand
169 } else if (myQueue.back().isMeanData()) {
170 // end parse meanData elements
172 // mark file as mean data
174 } else {
175 // mark file as demand
177 }
178}
179
180
182 tag(tag_),
183 myType(type) {
184}
185
186
187bool
189 return (myType == Type::NETWORK);
190}
191
192
193bool
195 return (myType == Type::ADDITIONAL);
196}
197
198
199bool
201 return (myType == Type::DEMAND);
202}
203
204
205bool
207 return (myType == Type::DATA);
208}
209
210
211bool
213 return (myType == Type::MEANDATA);
214}
215
216/****************************************************************************/
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)
void endTag()
end element
GNEGeneralHandler(GNENet *net, FileBucket *bucket, const bool allowUndoRedo)
Constructor.
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)
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 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