Path: blob/main/src/netedit/frames/demand/GNEContainerFrame.cpp
169685 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 GNEContainerFrame.cpp14/// @author Pablo Alvarez Lopez15/// @date May 201916///17// The Widget for add Container elements18/****************************************************************************/1920#include <netedit/GNEApplicationWindow.h>21#include <netedit/GNENet.h>22#include <netedit/GNEUndoList.h>23#include <netedit/GNEViewParent.h>24#include <netedit/elements/additional/GNETAZ.h>25#include <netedit/elements/demand/GNERouteHandler.h>26#include <netedit/frames/GNEAttributesEditor.h>27#include <netedit/frames/GNEDemandSelector.h>28#include <netedit/frames/GNEPlanCreator.h>29#include <netedit/frames/GNEPlanCreatorLegend.h>30#include <utils/vehicle/SUMOVehicleParserHelper.h>31#include <utils/xml/SUMOSAXAttributesImpl_Cached.h>3233#include "GNEContainerFrame.h"3435// ===========================================================================36// method definitions37// ===========================================================================3839GNEContainerFrame::GNEContainerFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :40GNEFrame(viewParent, viewNet, TL("Containers")),41myContainerBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {4243// create tag Selector module for containers44myContainerTagSelector = new GNETagSelector(this, GNETagProperties::Type::CONTAINER, SUMO_TAG_CONTAINER);4546// create container types selector module and set DEFAULT_PEDTYPE_ID as default element47myTypeSelector = new GNEDemandElementSelector(this, SUMO_TAG_VTYPE, GNETagProperties::Type::CONTAINER);4849// Create attributes editor50myContainerAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);5152// create plan selector module for container plans53myPlanSelector = new GNEPlanSelector(this, SUMO_TAG_CONTAINER);5455// Create attributes editor56myContainerPlanAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);5758// create GNEPlanCreator Module59myPlanCreator = new GNEPlanCreator(this, viewNet->getNet()->getDemandPathManager());6061// create plan creator legend62myPlanCreatorLegend = new GNEPlanCreatorLegend(this);63}646566GNEContainerFrame::~GNEContainerFrame() {67delete myContainerBaseObject;68}697071void72GNEContainerFrame::show() {73// refresh tag selector74myContainerTagSelector->refreshTagSelector();75myTypeSelector->refreshDemandElementSelector();76myPlanSelector->refreshPlanSelector();77// show frame78GNEFrame::show();79}808182void83GNEContainerFrame::hide() {84// reset candidate edges85for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {86edge.second->resetCandidateFlags();87}88// hide frame89GNEFrame::hide();90}919293bool94GNEContainerFrame::addContainer(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {95// first check that we clicked over an AC96if (viewObjects.getAttributeCarrierFront() == nullptr) {97return false;98}99// obtain tags (only for improve code legibility)100SumoXMLTag containerTag = myContainerTagSelector->getCurrentTemplateAC()->getTagProperty()->getTag();101// first check that current selected container is valid102if (containerTag == SUMO_TAG_NOTHING) {103myViewNet->setStatusBarText(TL("Current selected container isn't valid."));104return false;105}106// now check that pType is valid107if (myTypeSelector->getCurrentDemandElement() == nullptr) {108myViewNet->setStatusBarText(TL("Current selected container type isn't valid."));109return false;110}111// finally check that container plan selected is valid112if (myPlanSelector->getCurrentPlanTemplate() == nullptr) {113myViewNet->setStatusBarText(TL("Current selected container plan isn't valid."));114return false;115}116for (GNEAdditional* o : viewObjects.getAdditionals()) {117if (o->getTagProperty()->isStoppingPlace()) {118return myPlanCreator->addStoppingPlace(o);119}120}121for (GNEDemandElement* o : viewObjects.getDemandElements()) {122if (o->getTagProperty()->getTag() == SUMO_TAG_ROUTE) {123return myPlanCreator->addRoute(o);124}125}126if (viewObjects.getAttributeCarrierFront() == viewObjects.getJunctionFront()) {127return myPlanCreator->addJunction(viewObjects.getJunctions().front());128}129if (viewObjects.getAttributeCarrierFront() == viewObjects.getLaneFront()) {130return myPlanCreator->addEdge(viewObjects.getLanes().front());131}132if (viewObjects.getAttributeCarrierFront() == viewObjects.getTAZFront()) {133return myPlanCreator->addTAZ(viewObjects.getTAZs().front());134}135return false;136}137138139GNEPlanCreator*140GNEContainerFrame::getPlanCreator() const {141return myPlanCreator;142}143144145GNEDemandElementSelector*146GNEContainerFrame::getTypeSelector() const {147return myTypeSelector;148}149150151GNEPlanSelector*152GNEContainerFrame::getPlanSelector() const {153return myPlanSelector;154}155156157GNEAttributesEditor*158GNEContainerFrame::getContainerAttributesEditor() const {159return myContainerAttributesEditor;160}161162// ===========================================================================163// protected164// ===========================================================================165166void167GNEContainerFrame::tagSelected() {168// first check if container is valid169if (myContainerTagSelector->getCurrentTemplateAC()) {170// show PType selector and container plan selector171myTypeSelector->showDemandElementSelector();172// check if current container type selected is valid173if (myTypeSelector->getCurrentDemandElement()) {174// show container attributes175myContainerAttributesEditor->showAttributesEditor(myContainerTagSelector->getCurrentTemplateAC(), true);176// show container plan tag selector177myPlanSelector->showPlanSelector();178// check current plan template179if (myPlanSelector->getCurrentPlanTemplate()) {180// show container plan attributes181myContainerPlanAttributesEditor->showAttributesEditor(myPlanSelector->getCurrentPlanTemplate(), false);182// show edge path creator module183myPlanCreator->showPlanCreatorModule(myPlanSelector, nullptr);184// show path legend185myPlanCreatorLegend->showPlanCreatorLegend();186} else {187// hide modules188myContainerAttributesEditor->hideAttributesEditor();189myContainerPlanAttributesEditor->hideAttributesEditor();190myPlanCreator->hidePathCreatorModule();191myPlanCreatorLegend->hidePlanCreatorLegend();192}193} else {194// hide modules195myPlanSelector->hidePlanSelector();196myContainerAttributesEditor->hideAttributesEditor();197myContainerPlanAttributesEditor->hideAttributesEditor();198myPlanCreator->hidePathCreatorModule();199myPlanCreatorLegend->hidePlanCreatorLegend();200}201} else {202// hide all modules if container isn't valid203myTypeSelector->hideDemandElementSelector();204myPlanSelector->hidePlanSelector();205myContainerAttributesEditor->hideAttributesEditor();206myContainerPlanAttributesEditor->hideAttributesEditor();207myPlanCreator->hidePathCreatorModule();208myPlanCreatorLegend->hidePlanCreatorLegend();209}210}211212213void214GNEContainerFrame::demandElementSelected() {215if (myTypeSelector->getCurrentDemandElement() && myPlanSelector->getCurrentPlanTemplate()) {216// show container attributes217myContainerAttributesEditor->showAttributesEditor(myContainerTagSelector->getCurrentTemplateAC(), true);218// show container plan tag selector219myPlanSelector->showPlanSelector();220// now check if container plan selected is valid221if (myPlanSelector->getCurrentPlanTagProperties()->getTag() != SUMO_TAG_NOTHING) {222// show container plan attributes223myContainerPlanAttributesEditor->showAttributesEditor(myPlanSelector->getCurrentPlanTemplate(), false);224// show edge path creator module225myPlanCreator->showPlanCreatorModule(myPlanSelector, nullptr);226// show legend227myPlanCreatorLegend->showPlanCreatorLegend();228} else {229// hide modules230myContainerAttributesEditor->hideAttributesEditor();231myContainerPlanAttributesEditor->hideAttributesEditor();232myPlanCreator->hidePathCreatorModule();233}234} else {235// hide modules236myPlanSelector->hidePlanSelector();237myContainerAttributesEditor->hideAttributesEditor();238myContainerPlanAttributesEditor->hideAttributesEditor();239myPlanCreator->hidePathCreatorModule();240}241}242243244bool245GNEContainerFrame::createPath(const bool /*useLastRoute*/) {246// first check that all attributes are valid247if (!myContainerAttributesEditor->checkAttributes(true) || !myContainerPlanAttributesEditor->checkAttributes(true)) {248return false;249} else if (myPlanCreator->planCanBeCreated(myPlanSelector->getCurrentPlanTemplate())) {250// begin undo-redo operation251myViewNet->getUndoList()->begin(myContainerTagSelector->getCurrentTemplateAC(), "create " +252myContainerTagSelector->getCurrentTemplateAC()->getTagProperty()->getTagStr() + " and " +253myPlanSelector->getCurrentPlanTagProperties()->getTagStr());254// create container255GNEDemandElement* container = buildContainer();256// declare route handler257GNERouteHandler routeHandler(myViewNet->getNet(), container->getAttribute(GNE_ATTR_DEMAND_FILE),258myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());259// check if container and container plan can be created260if (routeHandler.buildContainerPlan(myPlanSelector->getCurrentPlanTemplate(),261container, myContainerPlanAttributesEditor, myPlanCreator, true)) {262// end undo-redo operation263myViewNet->getUndoList()->end();264// abort path creation265myPlanCreator->abortPathCreation();266// refresh container and containerPlan attributes267myContainerAttributesEditor->refreshAttributesEditor();268myContainerPlanAttributesEditor->refreshAttributesEditor();269// compute container270container->computePathElement();271// enable show all container plans272myViewNet->getDemandViewOptions().menuCheckShowAllContainerPlans->setChecked(TRUE);273return true;274} else {275// abort container creation276myViewNet->getUndoList()->abortAllChangeGroups();277return false;278}279} else {280return false;281}282}283284// ---------------------------------------------------------------------------285// GNEContainerFrame - private methods286// ---------------------------------------------------------------------------287288GNEDemandElement*289GNEContainerFrame::buildContainer() {290// first container base object291myContainerBaseObject->clear();292// obtain container tag (only for improve code legibility)293SumoXMLTag containerTag = myContainerTagSelector->getCurrentTemplateAC()->getTagProperty()->getTag();294// set tag295myContainerBaseObject->setTag(containerTag);296// get attributes297myContainerAttributesEditor->fillSumoBaseObject(myContainerBaseObject);298// add pType parameter299myContainerBaseObject->addStringAttribute(SUMO_ATTR_TYPE, myTypeSelector->getCurrentDemandElement()->getID());300// declare route handler301GNERouteHandler routeHandler(myViewNet->getNet(), myContainerBaseObject->hasStringAttribute(GNE_ATTR_DEMAND_FILE) ? myContainerBaseObject->getStringAttribute(GNE_ATTR_DEMAND_FILE) : "",302myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());303// check if we're creating a container or containerFlow304if (containerTag == SUMO_TAG_CONTAINER) {305// Add parameter departure306if (!myContainerBaseObject->hasStringAttribute(SUMO_ATTR_DEPART) || myContainerBaseObject->getStringAttribute(SUMO_ATTR_DEPART).empty()) {307myContainerBaseObject->addStringAttribute(SUMO_ATTR_DEPART, "0");308}309// declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes310SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(myContainerBaseObject->getAllAttributes(), getPredefinedTagsMML(), toString(containerTag));311// obtain container parameters312SUMOVehicleParameter* containerParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_CONTAINER, SUMOSAXAttrs, false, false, false);313// check containerParameters314if (containerParameters) {315myContainerBaseObject->setVehicleParameter(containerParameters);316// parse vehicle317routeHandler.parseSumoBaseObject(myContainerBaseObject);318// delete containerParameters319delete containerParameters;320}321} else {322// set begin and end attributes323if (!myContainerBaseObject->hasStringAttribute(SUMO_ATTR_BEGIN) || myContainerBaseObject->getStringAttribute(SUMO_ATTR_BEGIN).empty()) {324myContainerBaseObject->addStringAttribute(SUMO_ATTR_BEGIN, "0");325}326// adjust poisson value327if (myContainerBaseObject->hasDoubleAttribute(GNE_ATTR_POISSON)) {328myContainerBaseObject->addStringAttribute(SUMO_ATTR_PERIOD, "exp(" + toString(myContainerBaseObject->getDoubleAttribute(GNE_ATTR_POISSON)) + ")");329}330// declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes331SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(myContainerBaseObject->getAllAttributes(), getPredefinedTagsMML(), toString(containerTag));332// obtain containerFlow parameters333SUMOVehicleParameter* containerFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_CONTAINERFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);334// check containerParameters335if (containerFlowParameters) {336myContainerBaseObject->setVehicleParameter(containerFlowParameters);337// parse vehicle338routeHandler.parseSumoBaseObject(myContainerBaseObject);339// delete containerParameters340delete containerFlowParameters;341}342}343// refresh container and containerPlan attributes344myContainerAttributesEditor->refreshAttributesEditor();345myContainerPlanAttributesEditor->refreshAttributesEditor();346// return created container347return myViewNet->getNet()->getAttributeCarriers()->retrieveDemandElement(containerTag, myContainerBaseObject->getStringAttribute(SUMO_ATTR_ID));348}349350351/****************************************************************************/352353354