Eclipse SUMO - Simulation of Urban MObility
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-2024 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 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 
26 #include <utils/xml/XMLSubSys.h>
27 
28 #include "GNEGeneralHandler.h"
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
35 GNEGeneralHandler::GNEGeneralHandler(GNENet* net, const std::string& file, const bool allowUndoRedo, const bool overwrite) :
36  GeneralHandler(file),
37  myAdditionalHandler(net, allowUndoRedo, overwrite),
38  myDemandHandler(file, net, allowUndoRedo, overwrite),
39  myMeanDataHandler(net, allowUndoRedo, overwrite) {
40 }
41 
42 
44 
45 
46 bool
51 }
52 
53 
54 bool
57 }
58 
59 
60 bool
63 }
64 
65 
66 bool
69 }
70 
71 
72 void
74  switch (tag) {
75  case SUMO_TAG_LOCATION:
76  // process in Network handler
77  myQueue.push_back(TagType(tag, TagType::Type::NETWORK));
78  break;
79  case SUMO_TAG_PARAM:
80  case SUMO_TAG_INTERVAL:
81  if (myQueue.size() > 0) {
82  // try to parse additional or demand element depending of last inserted tag
83  if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
84  myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));
85  } else if (myQueue.back().isDemand() && myDemandHandler.beginParseAttributes(tag, attrs)) {
86  myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
87  } else {
88  myQueue.push_back(TagType(tag, TagType::Type::NONE));
89  }
90  } else {
91  myQueue.push_back(TagType(tag, TagType::Type::NONE));
92  }
93  break;
94  case SUMO_TAG_FLOW:
95  if (myQueue.size() > 0) {
96  // try to parse additional or demand element depending of last inserted tag
97  if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
98  myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));
99  } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
100  myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
101  } else {
102  myQueue.push_back(TagType(tag, TagType::Type::NONE));
103  }
104  } else {
105  myQueue.push_back(TagType(tag, TagType::Type::NONE));
106  }
107  break;
108  default:
109  // try to parse additional or demand element
110  if (myAdditionalHandler.beginParseAttributes(tag, attrs)) {
111  myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));
112  } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
113  myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
114  } else if (myMeanDataHandler.beginParseAttributes(tag, attrs)) {
115  myQueue.push_back(TagType(tag, TagType::Type::MEANDATA));
116  } else {
117  myQueue.push_back(TagType(tag, TagType::Type::NONE));
118  }
119  break;
120  }
121  // maximum 10 tagTypes
122  if (myQueue.size() > 10) {
123  myQueue.pop_front();
124  }
125 }
126 
127 
128 void
130  // check tagType
131  if (myQueue.back().isNetwork()) {
132  // currently ignored (will be implemented in the future)
133  } else if (myQueue.back().isAdditional()) {
134  // end parse additional elements
136  // mark file as additional
138  } else if (myQueue.back().isDemand()) {
139  // end parse demand elements
141  // mark file as demand
143  } else if (myQueue.back().isMeanData()) {
144  // end parse meanData elements
146  // mark file as mean data
148  } else {
149  // mark file as demand
151  }
152 }
153 
154 
156  tag(tag_),
157  myType(type) {
158 }
159 
160 
161 bool
163  return (myType == Type::NETWORK);
164 }
165 
166 
167 bool
169  return (myType == Type::ADDITIONAL);
170 }
171 
172 
173 bool
175  return (myType == Type::DEMAND);
176 }
177 
178 
179 bool
181  return (myType == Type::DATA);
182 }
183 
184 
185 bool
187  return (myType == Type::MEANDATA);
188 }
189 
190 /****************************************************************************/
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
bool isErrorCreatingElement() const
get flag for check if a element wasn't created
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
GNEGeneralHandler(GNENet *net, const std::string &file, const bool allowUndoRedo, const bool overwrite)
Constructor.
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
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
void endParseAttributes()
end parse attributes
bool isErrorCreatingElement() const
get flag for check if a element wasn't created
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
bool isErrorCreatingElement() const
get flag for check if a element wasn't created
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