Path: blob/main/src/netedit/frames/demand/GNERouteFrame.cpp
169684 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 GNERouteFrame.cpp14/// @author Pablo Alvarez Lopez15/// @date Dec 201816///17// The Widget for remove network-elements18/****************************************************************************/1920#include <netedit/GNEApplicationWindow.h>21#include <netedit/GNENet.h>22#include <netedit/GNEViewParent.h>23#include <netedit/elements/demand/GNERouteHandler.h>24#include <netedit/frames/GNEAttributesEditor.h>25#include <netedit/frames/GNEFrame.h>26#include <netedit/frames/GNEPathCreator.h>27#include <netedit/frames/GNEPathLegendModule.h>28#include <utils/gui/div/GUIDesigns.h>29#include <utils/common/MsgHandler.h>3031#include "GNERouteFrame.h"3233// ===========================================================================34// FOX callback mapping35// ===========================================================================3637FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[] = {38FXMAPFUNC(SEL_COMMAND, MID_GNE_ROUTEFRAME_ROUTEMODE, GNERouteFrame::RouteModeSelector::onCmdSelectRouteMode),39FXMAPFUNC(SEL_COMMAND, MID_GNE_ROUTEFRAME_VCLASS, GNERouteFrame::RouteModeSelector::onCmdSelectVClass),40};4142// Object implementation43FXIMPLEMENT(GNERouteFrame::RouteModeSelector, MFXGroupBoxModule, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))444546// ===========================================================================47// method definitions48// ===========================================================================4950// ---------------------------------------------------------------------------51// GNERouteFrame::RouteModeSelector - methods52// ---------------------------------------------------------------------------5354GNERouteFrame::RouteModeSelector::RouteModeSelector(GNERouteFrame* routeFrameParent) :55MFXGroupBoxModule(routeFrameParent, TL("Route mode")),56myRouteFrameParent(routeFrameParent) {57const auto statictooltipMenu = routeFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();58// first fill myRouteModesStrings59myRouteModesStrings.push_back(std::make_pair(RouteMode::NONCONSECUTIVE_EDGES, TL("non consecutive edges")));60myRouteModesStrings.push_back(std::make_pair(RouteMode::CONSECUTIVE_EDGES, TL("consecutive edges")));61// Create MFXComboBoxIcon for Route mode62myRouteModeMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), statictooltipMenu, false, GUIDesignComboBoxVisibleItems,63this, MID_GNE_ROUTEFRAME_ROUTEMODE, GUIDesignComboBox);64// fill myRouteModeMatchBox with route modes65for (const auto& routeMode : myRouteModesStrings) {66myRouteModeMatchBox->appendIconItem(routeMode.second.c_str());67}68// Create MFXComboBoxIcon for VClass69myVClassMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), statictooltipMenu, false, GUIDesignComboBoxVisibleItems,70this, MID_GNE_ROUTEFRAME_VCLASS, GUIDesignComboBox);71// fill myVClassMatchBox with all VCLass72for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {73myVClassMatchBox->appendIconItem(vClass.c_str());74}75// set Passenger als default VCLass76myVClassMatchBox->setCurrentItem(7);77// RouteModeSelector is always shown78show();79}808182GNERouteFrame::RouteModeSelector::~RouteModeSelector() {83}848586const GNERouteFrame::RouteMode&87GNERouteFrame::RouteModeSelector::getCurrentRouteMode() const {88return myCurrentRouteMode;89}909192bool93GNERouteFrame::RouteModeSelector::isValidMode() const {94return (myCurrentRouteMode != RouteMode::INVALID);95}969798bool99GNERouteFrame::RouteModeSelector::isValidVehicleClass() const {100return myValidVClass;101}102103104void105GNERouteFrame::RouteModeSelector::areParametersValid() {106const auto routeTemplate = myRouteFrameParent->getViewNet()->getNet()->getACTemplates()->getTemplateAC(SUMO_TAG_ROUTE);107// check if current mode is valid108if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {109// check if create routes consecutively110const bool consecutiveEdges = (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES);111// show route attributes modul112myRouteFrameParent->myRouteAttributesEditor->showAttributesEditor(routeTemplate, true);113// show path creator114myRouteFrameParent->myPathCreator->showPathCreatorModule(routeTemplate->getTagProperty(), consecutiveEdges);115// update edge colors116myRouteFrameParent->myPathCreator->updateEdgeColors();117// show legend118myRouteFrameParent->myPathLegend->showPathLegendModule();119} else {120// hide all moduls if route mode isnt' valid121myRouteFrameParent->myRouteAttributesEditor->hideAttributesEditor();122myRouteFrameParent->myPathCreator->hidePathCreatorModule();123myRouteFrameParent->myPathLegend->hidePathLegendModule();124// reset all flags125for (const auto& edge : myRouteFrameParent->myViewNet->getNet()->getAttributeCarriers()->getEdges()) {126edge.second->resetCandidateFlags();127}128// update view net129myRouteFrameParent->myViewNet->update();130}131}132133134long135GNERouteFrame::RouteModeSelector::onCmdSelectRouteMode(FXObject*, FXSelector, void*) {136// first abort all current operations in moduls137myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);138// set invalid current route mode139myCurrentRouteMode = RouteMode::INVALID;140// set color of myTypeMatchBox to red (invalid)141myRouteModeMatchBox->setTextColor(GUIDesignTextColorRed);142// Check if value of myTypeMatchBox correspond of an allowed additional tags143for (const auto& routeMode : myRouteModesStrings) {144if (routeMode.second == myRouteModeMatchBox->getText().text()) {145// Set new current type146myCurrentRouteMode = routeMode.first;147// set color of myTypeMatchBox to black (valid)148myRouteModeMatchBox->setTextColor(GUIDesignTextColorBlack);149}150}151// check if parameters are valid152areParametersValid();153return 1;154}155156157long158GNERouteFrame::RouteModeSelector::onCmdSelectVClass(FXObject*, FXSelector, void*) {159// first abort all current operations in moduls160myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);161// set vClass flag invalid162myValidVClass = false;163// set color of myTypeMatchBox to red (invalid)164myVClassMatchBox->setTextColor(GUIDesignTextColorRed);165// Check if value of myTypeMatchBox correspond of an allowed additional tags166for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {167if (vClass == myVClassMatchBox->getText().text()) {168// change flag169myValidVClass = true;170// set color of myTypeMatchBox to black (valid)171myVClassMatchBox->setTextColor(GUIDesignTextColorBlack);172// set vClass in Path creator173myRouteFrameParent->myPathCreator->setVClass(SumoVehicleClassStrings.get(vClass));174}175}176// check if parameters are valid177areParametersValid();178return 1;179}180181// ---------------------------------------------------------------------------182// GNERouteFrame - methods183// ---------------------------------------------------------------------------184185GNERouteFrame::GNERouteFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :186GNEFrame(viewParent, viewNet, TL("Routes")),187myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {188189// create route mode Selector module190myRouteModeSelector = new RouteModeSelector(this);191192// Create route parameters193myRouteAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);194195// create consecutive edges module196myPathCreator = new GNEPathCreator(this, viewNet->getNet()->getDemandPathManager());197198// create legend label199myPathLegend = new GNEPathLegendModule(this);200}201202203GNERouteFrame::~GNERouteFrame() {204delete myRouteBaseObject;205}206207208void209GNERouteFrame::show() {210// call are parameters valid211myRouteModeSelector->areParametersValid();212// show route frame213GNEFrame::show();214}215216217void218GNERouteFrame::hide() {219// reset candidate edges220for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {221edge.second->resetCandidateFlags();222}223GNEFrame::hide();224}225226227bool228GNERouteFrame::addEdgeRoute(GNEEdge* clickedEdge, const GNEViewNetHelper::MouseButtonKeyPressed& mouseButtonKeyPressed) {229// first check if current vClass and mode are valid and edge exist230if (clickedEdge && myRouteModeSelector->isValidVehicleClass() && myRouteModeSelector->isValidMode()) {231// add edge in path232myPathCreator->addEdge(clickedEdge, mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());233// update view234myViewNet->updateViewNet();235return true;236} else {237return false;238}239}240241242GNEPathCreator*243GNERouteFrame::getPathCreator() const {244return myPathCreator;245}246247248bool249GNERouteFrame::createPath(const bool /*useLastRoute*/) {250// check that route attributes are valid251if (!myRouteAttributesEditor->checkAttributes(true)) {252return false;253} else if (myPathCreator->getSelectedEdges().size() > 0) {254// clear base object255myRouteBaseObject->clear();256// set tag257myRouteBaseObject->setTag(SUMO_TAG_ROUTE);258// obtain attributes259myRouteAttributesEditor->fillSumoBaseObject(myRouteBaseObject);260// add probability (needed for distributions)261myRouteBaseObject->addDoubleAttribute(SUMO_ATTR_PROB, 1.0);262// declare edge vector263std::vector<std::string> edges;264for (const auto& path : myPathCreator->getPath()) {265for (const auto& edgeID : path.getSubPath()) {266// get edge267GNEEdge* edge = myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(edgeID->getID());268// avoid double edges269if (edges.empty() || (edges.back() != edge->getID())) {270edges.push_back(edge->getID());271}272}273}274// set edges in route base object275myRouteBaseObject->addStringListAttribute(SUMO_ATTR_EDGES, edges);276// declare route handler277GNERouteHandler routeHandler(myViewNet->getNet(), myRouteBaseObject->hasStringAttribute(GNE_ATTR_DEMAND_FILE) ?278myRouteBaseObject->getStringAttribute(GNE_ATTR_DEMAND_FILE) : "",279myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());280// create route281routeHandler.parseSumoBaseObject(myRouteBaseObject);282// abort path creation283myPathCreator->abortPathCreation();284// refresh route attributes285myRouteAttributesEditor->refreshAttributesEditor();286// get new route287auto newRoute = myViewNet->getNet()->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_ROUTE, myRouteBaseObject->getStringAttribute(SUMO_ATTR_ID));288// compute path route289newRoute->computePathElement();290// set as last created route291myViewNet->setLastCreatedRoute(newRoute);292return true;293}294return false;295}296297/****************************************************************************/298299300