Path: blob/main/src/netedit/elements/GNEGeneralHandler.cpp
193723 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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, FileBucket* fileBucket, const bool allowUndoRedo) :29GeneralHandler(fileBucket),30myAdditionalHandler(net, fileBucket, allowUndoRedo),31myDemandHandler(net, fileBucket, allowUndoRedo, true),32myMeanDataHandler(net, fileBucket, allowUndoRedo) {33}343536GNEGeneralHandler::~GNEGeneralHandler() {}373839void40GNEGeneralHandler::forceOverwriteElements() {41myAdditionalHandler.forceOverwriteElements();42myDemandHandler.forceOverwriteElements();43myMeanDataHandler.forceOverwriteElements();44}454647bool48GNEGeneralHandler::isErrorCreatingElement() const {49return (myAdditionalHandler.isErrorCreatingElement() ||50myDemandHandler.isErrorCreatingElement() ||51myMeanDataHandler.isErrorCreatingElement());52}535455bool56GNEGeneralHandler::isAdditionalFile() const {57return fileType == TagType::Type::ADDITIONAL;58}596061bool62GNEGeneralHandler::isRouteFile() const {63return fileType == TagType::Type::DEMAND;64}656667bool68GNEGeneralHandler::isMeanDataFile() const {69return fileType == TagType::Type::MEANDATA;70}717273void74GNEGeneralHandler::beginTag(SumoXMLTag tag, const SUMOSAXAttributes& attrs) {75// continue depending of tag76switch (tag) {77case SUMO_TAG_LOCATION:78// process in Network handler79myQueue.push_back(TagType(tag, TagType::Type::NETWORK));80break;81case SUMO_TAG_PARAM:82case SUMO_TAG_INTERVAL:83if (myQueue.size() > 0) {84// try to parse additional or demand element depending of last inserted tag85if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {86myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));87} else if (myQueue.back().isDemand() && myDemandHandler.beginParseAttributes(tag, attrs)) {88myQueue.push_back(TagType(tag, TagType::Type::DEMAND));89} else {90myQueue.push_back(TagType(tag, TagType::Type::NONE));91}92} else {93myQueue.push_back(TagType(tag, TagType::Type::NONE));94}95break;96case SUMO_TAG_FLOW: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 (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;110default:111// try to parse additional or demand element112if (myAdditionalHandler.beginParseAttributes(tag, attrs)) {113myQueue.push_back(TagType(tag, TagType::Type::ADDITIONAL));114} else if (myDemandHandler.beginParseAttributes(tag, attrs)) {115myQueue.push_back(TagType(tag, TagType::Type::DEMAND));116} else if (myMeanDataHandler.beginParseAttributes(tag, attrs)) {117myQueue.push_back(TagType(tag, TagType::Type::MEANDATA));118} else {119myQueue.push_back(TagType(tag, TagType::Type::NONE));120}121break;122}123// maximum 10 tagTypes124if (myQueue.size() > 10) {125myQueue.pop_front();126}127// check if update handlers128const bool abortLoading = myAdditionalHandler.isAbortLoading() ||129myDemandHandler.isAbortLoading() ||130myMeanDataHandler.isAbortLoading();131const bool forceOverwrite = myAdditionalHandler.isForceOverwriteElements() ||132myDemandHandler.isForceOverwriteElements() ||133myMeanDataHandler.isForceOverwriteElements();134const bool forceRemain = myAdditionalHandler.isForceRemainElements() ||135myDemandHandler.isForceRemainElements() ||136myMeanDataHandler.isForceRemainElements();137if (abortLoading) {138myAdditionalHandler.abortLoading();139myDemandHandler.abortLoading();140myMeanDataHandler.abortLoading();141} else if (forceOverwrite) {142myAdditionalHandler.forceOverwriteElements();143myDemandHandler.forceOverwriteElements();144myMeanDataHandler.forceOverwriteElements();145} else if (forceRemain) {146myAdditionalHandler.forceRemainElements();147myDemandHandler.forceRemainElements();148myMeanDataHandler.forceRemainElements();149}150}151152153void154GNEGeneralHandler::endTag() {155// check tagType156if (myQueue.back().isNetwork()) {157// currently ignored (will be implemented in the future)158} else if (myQueue.back().isAdditional()) {159// end parse additional elements160myAdditionalHandler.endParseAttributes();161// mark file as additional162fileType = TagType::Type::ADDITIONAL;163} else if (myQueue.back().isDemand()) {164// end parse demand elements165myDemandHandler.endParseAttributes();166// mark file as demand167fileType = TagType::Type::DEMAND;168} else if (myQueue.back().isMeanData()) {169// end parse meanData elements170myMeanDataHandler.endParseAttributes();171// mark file as mean data172fileType = TagType::Type::MEANDATA;173} else {174// mark file as demand175fileType = TagType::Type::NONE;176}177}178179180GNEGeneralHandler::TagType::TagType(SumoXMLTag tag_, GNEGeneralHandler::TagType::Type type) :181tag(tag_),182myType(type) {183}184185186bool187GNEGeneralHandler::TagType::isNetwork() const {188return (myType == Type::NETWORK);189}190191192bool193GNEGeneralHandler::TagType::isAdditional() const {194return (myType == Type::ADDITIONAL);195}196197198bool199GNEGeneralHandler::TagType::isDemand() const {200return (myType == Type::DEMAND);201}202203204bool205GNEGeneralHandler::TagType::isData() const {206return (myType == Type::DATA);207}208209210bool211GNEGeneralHandler::TagType::isMeanData() const {212return (myType == Type::MEANDATA);213}214215/****************************************************************************/216217218