Path: blob/main/src/netedit/elements/GNEGeneralHandler.cpp
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNEGeneralHandler.cpp14/// @author Pablo Alvarez Lopez15/// @date Sep 202116///17// General element handler for netedit18/****************************************************************************/1920#include <utils/xml/XMLSubSys.h>2122#include "GNEGeneralHandler.h"2324// ===========================================================================25// method definitions26// ===========================================================================2728GNEGeneralHandler::GNEGeneralHandler(GNENet* net, const std::string& file, const bool allowUndoRedo) :29GeneralHandler(file),30myAdditionalHandler(net, file, allowUndoRedo),31myDemandHandler(net, file, allowUndoRedo),32myMeanDataHandler(net, file, allowUndoRedo) {33}343536GNEGeneralHandler::~GNEGeneralHandler() {}373839void40GNEGeneralHandler::forceOverwriteElements() {41myAdditionalHandler.forceOverwriteElements();42myDemandHandler.forceOverwriteElements();43myMeanDataHandler.forceOverwriteElements();44}454647bool48GNEGeneralHandler::postParserTasks() {49if (isAdditionalFile()) {50return myAdditionalHandler.postParserTasks();51} else if (isRouteFile()) {52return myDemandHandler.postParserTasks();53} else if (isMeanDataFile()) {54return myMeanDataHandler.postParserTasks();55} else {56return true;57}58}596061bool62GNEGeneralHandler::isErrorCreatingElement() const {63return (myAdditionalHandler.isErrorCreatingElement() ||64myDemandHandler.isErrorCreatingElement() ||65myMeanDataHandler.isErrorCreatingElement());66}676869bool70GNEGeneralHandler::isAdditionalFile() const {71return fileType == TagType::Type::ADDITIONAL;72}737475bool76GNEGeneralHandler::isRouteFile() const {77return fileType == TagType::Type::DEMAND;78}798081bool82GNEGeneralHandler::isMeanDataFile() const {83return fileType == TagType::Type::MEANDATA;84}858687void88GNEGeneralHandler::beginTag(SumoXMLTag tag, const SUMOSAXAttributes& attrs) {89// continue depending of tag90switch (tag) {91case SUMO_TAG_LOCATION:92// process in Network handler93myQueue.push_back(TagType(tag, TagType::Type::NETWORK));94break;95case SUMO_TAG_PARAM:96case SUMO_TAG_INTERVAL:97if (myQueue.size() > 0) {98// try to parse additional or demand element depending of last inserted tag99if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {100myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));101} else if (myQueue.back().isDemand() && myDemandHandler.beginParseAttributes(tag, attrs)) {102myQueue.push_back(TagType(tag, TagType::Type::DEMAND));103} else {104myQueue.push_back(TagType(tag, TagType::Type::NONE));105}106} else {107myQueue.push_back(TagType(tag, TagType::Type::NONE));108}109break;110case SUMO_TAG_FLOW:111if (myQueue.size() > 0) {112// try to parse additional or demand element depending of last inserted tag113if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {114myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));115} else if (myDemandHandler.beginParseAttributes(tag, attrs)) {116myQueue.push_back(TagType(tag, TagType::Type::DEMAND));117} else {118myQueue.push_back(TagType(tag, TagType::Type::NONE));119}120} else {121myQueue.push_back(TagType(tag, TagType::Type::NONE));122}123break;124default:125// try to parse additional or demand element126if (myAdditionalHandler.beginParseAttributes(tag, attrs)) {127myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));128} else if (myDemandHandler.beginParseAttributes(tag, attrs)) {129myQueue.push_back(TagType(tag, TagType::Type::DEMAND));130} else if (myMeanDataHandler.beginParseAttributes(tag, attrs)) {131myQueue.push_back(TagType(tag, TagType::Type::MEANDATA));132} else {133myQueue.push_back(TagType(tag, TagType::Type::NONE));134}135break;136}137// maximum 10 tagTypes138if (myQueue.size() > 10) {139myQueue.pop_front();140}141// check if update handlers142const bool abortLoading = myAdditionalHandler.isAbortLoading() ||143myDemandHandler.isAbortLoading() ||144myMeanDataHandler.isAbortLoading();145const bool forceOverwrite = myAdditionalHandler.isForceOverwriteElements() ||146myDemandHandler.isForceOverwriteElements() ||147myMeanDataHandler.isForceOverwriteElements();148const bool forceRemain = myAdditionalHandler.isForceRemainElements() ||149myDemandHandler.isForceRemainElements() ||150myMeanDataHandler.isForceRemainElements();151if (abortLoading) {152myAdditionalHandler.abortLoading();153myDemandHandler.abortLoading();154myMeanDataHandler.abortLoading();155} else if (forceOverwrite) {156myAdditionalHandler.forceOverwriteElements();157myDemandHandler.forceOverwriteElements();158myMeanDataHandler.forceOverwriteElements();159} else if (forceRemain) {160myAdditionalHandler.forceRemainElements();161myDemandHandler.forceRemainElements();162myMeanDataHandler.forceRemainElements();163}164}165166167void168GNEGeneralHandler::endTag() {169// check tagType170if (myQueue.back().isNetwork()) {171// currently ignored (will be implemented in the future)172} else if (myQueue.back().isAdditional()) {173// end parse additional elements174myAdditionalHandler.endParseAttributes();175// mark file as additional176fileType = TagType::Type::ADDITIONAL;177} else if (myQueue.back().isDemand()) {178// end parse demand elements179myDemandHandler.endParseAttributes();180// mark file as demand181fileType = TagType::Type::DEMAND;182} else if (myQueue.back().isMeanData()) {183// end parse meanData elements184myMeanDataHandler.endParseAttributes();185// mark file as mean data186fileType = TagType::Type::MEANDATA;187} else {188// mark file as demand189fileType = TagType::Type::NONE;190}191}192193194GNEGeneralHandler::TagType::TagType(SumoXMLTag tag_, GNEGeneralHandler::TagType::Type type) :195tag(tag_),196myType(type) {197}198199200bool201GNEGeneralHandler::TagType::isNetwork() const {202return (myType == Type::NETWORK);203}204205206bool207GNEGeneralHandler::TagType::isAdditional() const {208return (myType == Type::ADDITIONAL);209}210211212bool213GNEGeneralHandler::TagType::isDemand() const {214return (myType == Type::DEMAND);215}216217218bool219GNEGeneralHandler::TagType::isData() const {220return (myType == Type::DATA);221}222223224bool225GNEGeneralHandler::TagType::isMeanData() const {226return (myType == Type::MEANDATA);227}228229/****************************************************************************/230231232