Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEGeneralHandler.cpp
169678 views
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
/****************************************************************************/
14
/// @file GNEGeneralHandler.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Sep 2021
17
///
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
29
GNEGeneralHandler::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
37
GNEGeneralHandler::~GNEGeneralHandler() {}
38
39
40
void
41
GNEGeneralHandler::forceOverwriteElements() {
42
myAdditionalHandler.forceOverwriteElements();
43
myDemandHandler.forceOverwriteElements();
44
myMeanDataHandler.forceOverwriteElements();
45
}
46
47
48
bool
49
GNEGeneralHandler::postParserTasks() {
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
62
bool
63
GNEGeneralHandler::isErrorCreatingElement() const {
64
return (myAdditionalHandler.isErrorCreatingElement() ||
65
myDemandHandler.isErrorCreatingElement() ||
66
myMeanDataHandler.isErrorCreatingElement());
67
}
68
69
70
bool
71
GNEGeneralHandler::isAdditionalFile() const {
72
return fileType == TagType::Type::ADDITIONAL;
73
}
74
75
76
bool
77
GNEGeneralHandler::isRouteFile() const {
78
return fileType == TagType::Type::DEMAND;
79
}
80
81
82
bool
83
GNEGeneralHandler::isMeanDataFile() const {
84
return fileType == TagType::Type::MEANDATA;
85
}
86
87
88
void
89
GNEGeneralHandler::beginTag(SumoXMLTag tag, const SUMOSAXAttributes& attrs) {
90
// continue depending of tag
91
switch (tag) {
92
case SUMO_TAG_LOCATION:
93
// process in Network handler
94
myQueue.push_back(TagType(tag, TagType::Type::NETWORK));
95
break;
96
case SUMO_TAG_PARAM:
97
case SUMO_TAG_INTERVAL:
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)) {
101
myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));
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)) {
115
myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));
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)) {
128
myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));
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
168
void
169
GNEGeneralHandler::endTag() {
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
177
fileType = TagType::Type::ADDITIONAL;
178
} else if (myQueue.back().isDemand()) {
179
// end parse demand elements
180
myDemandHandler.endParseAttributes();
181
// mark file as demand
182
fileType = TagType::Type::DEMAND;
183
} else if (myQueue.back().isMeanData()) {
184
// end parse meanData elements
185
myMeanDataHandler.endParseAttributes();
186
// mark file as mean data
187
fileType = TagType::Type::MEANDATA;
188
} else {
189
// mark file as demand
190
fileType = TagType::Type::NONE;
191
}
192
}
193
194
195
GNEGeneralHandler::TagType::TagType(SumoXMLTag tag_, GNEGeneralHandler::TagType::Type type) :
196
tag(tag_),
197
myType(type) {
198
}
199
200
201
bool
202
GNEGeneralHandler::TagType::isNetwork() const {
203
return (myType == Type::NETWORK);
204
}
205
206
207
bool
208
GNEGeneralHandler::TagType::isAdditional() const {
209
return (myType == Type::ADDITIONAL);
210
}
211
212
213
bool
214
GNEGeneralHandler::TagType::isDemand() const {
215
return (myType == Type::DEMAND);
216
}
217
218
219
bool
220
GNEGeneralHandler::TagType::isData() const {
221
return (myType == Type::DATA);
222
}
223
224
225
bool
226
GNEGeneralHandler::TagType::isMeanData() const {
227
return (myType == Type::MEANDATA);
228
}
229
230
/****************************************************************************/
231
232