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-2026 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
74bool
78
79
80bool
84
85
86bool
90
91
92void
94 // continue depending of tag
95 switch (tag) {
97 // process in Network handler
98 myQueue.push_back(TagType(tag, TagType::Type::NETWORK));
99 break;
100 case SUMO_TAG_PARAM:
102 if (myQueue.size() > 0) {
103 // try to parse additional or demand element depending of last inserted tag
104 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
106 } else if (myQueue.back().isDemand() && myDemandHandler.beginParseAttributes(tag, attrs)) {
107 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
108 } else {
109 myQueue.push_back(TagType(tag, TagType::Type::NONE));
110 }
111 } else {
112 myQueue.push_back(TagType(tag, TagType::Type::NONE));
113 }
114 break;
115 case SUMO_TAG_FLOW:
116 if (myQueue.size() > 0) {
117 // try to parse additional or demand element depending of last inserted tag
118 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
120 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
121 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
122 } else {
123 myQueue.push_back(TagType(tag, TagType::Type::NONE));
124 }
125 } else {
126 myQueue.push_back(TagType(tag, TagType::Type::NONE));
127 }
128 break;
129 default:
130 // try to parse additional or demand element
133 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
134 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
135 } else if (myMeanDataHandler.beginParseAttributes(tag, attrs)) {
136 myQueue.push_back(TagType(tag, TagType::Type::MEANDATA));
137 } else {
138 myQueue.push_back(TagType(tag, TagType::Type::NONE));
139 }
140 break;
141 }
142 // maximum 10 tagTypes
143 if (myQueue.size() > 10) {
144 myQueue.pop_front();
145 }
146 // check if update handlers
147 const bool abortLoading = myAdditionalHandler.isAbortLoading() ||
150 const bool forceOverwrite = myAdditionalHandler.isForceOverwriteElements() ||
153 const bool forceRemain = myAdditionalHandler.isForceRemainElements() ||
156 if (abortLoading) {
160 } else if (forceOverwrite) {
164 } else if (forceRemain) {
168 }
169}
170
171
172void
174 // check tagType
175 if (myQueue.back().isNetwork()) {
176 // currently ignored (will be implemented in the future)
177 } else if (myQueue.back().isAdditional()) {
178 // end parse additional elements
181 } else if (myQueue.back().isDemand()) {
182 // end parse demand elements
184 myHasDemandElements = true;
185 } else if (myQueue.back().isMeanData()) {
186 // end parse meanData elements
189 }
190}
191
192
194 tag(tag_),
195 myType(type) {
196}
197
198
199bool
201 return (myType == Type::NETWORK);
202}
203
204
205bool
207 return (myType == Type::ADDITIONAL);
208}
209
210
211bool
213 return (myType == Type::DEMAND);
214}
215
216
217bool
219 return (myType == Type::DATA);
220}
221
222
223bool
225 return (myType == Type::MEANDATA);
226}
227
228/****************************************************************************/
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 myHasMeanDataElements
flag for meanData elements
bool myHasDemandElements
flag for demand elements
bool isErrorCreatingMeanData() const
check if error creating meanData element
void endTag()
end element
bool isErrorCreatingAdditional() const
check if error creating additional element
bool myHasAdditionalElements
flag for additional elements
bool isErrorCreatingDemand() const
check if error creating demand 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
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