Path: blob/main/src/netedit/frames/network/GNEWireFrame.cpp
169685 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2021-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 GNEWireFrame.cpp14/// @author Pablo Alvarez Lopez15/// @date Nov 202116///17// The Widget for editing wires18/****************************************************************************/1920#include <netedit/GNEApplicationWindow.h>21#include <netedit/GNENet.h>22#include <netedit/GNEViewParent.h>23#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>24#include <netedit/elements/additional/GNEAdditionalHandler.h>25#include <netedit/frames/GNEAttributesEditor.h>26#include <netedit/frames/GNEConsecutiveSelector.h>27#include <netedit/frames/GNESelectorParent.h>28#include <netedit/frames/GNETagSelector.h>2930#include "GNEWireFrame.h"3132// ===========================================================================33// method definitions34// ===========================================================================3536GNEWireFrame::GNEWireFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :37GNEFrame(viewParent, viewNet, TL("Wires")) {3839// create item Selector module for wires40myWireTagSelector = new GNETagSelector(this, GNETagProperties::Type::WIRE, SUMO_TAG_TRACTION_SUBSTATION);4142// Create wire parameters43myWireAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);4445// Create selector parent46mySelectorWireParent = new GNESelectorParent(this);4748// Create list for E2Multilane lane selector49myConsecutiveLaneSelector = new GNEConsecutiveSelector(this, true);50}515253GNEWireFrame::~GNEWireFrame() {54// check if we have to delete base wire object55if (myBaseWire) {56delete myBaseWire;57}58}596061void62GNEWireFrame::show() {63// refresh tag selector64myWireTagSelector->refreshTagSelector();65// show frame66GNEFrame::show();67if (!myWarnedExperimental) {68// show warning dialogbox about experimental state (only once)69GNEWarningBasicDialog(myViewNet->getViewParent()->getGNEAppWindows(), TL("Experimental Part"),70TL("Warning: The netedit overhead editor is still in experimental state."));71myWarnedExperimental = true;72}73}747576bool77GNEWireFrame::addWire(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {78// first check that current selected wire is valid79if (myWireTagSelector->getCurrentTemplateAC() == nullptr) {80myViewNet->setStatusBarText(TL("Current selected wire isn't valid."));81return false;82}83// show warning dialogbox and stop check if input parameters are valid84if (!myWireAttributesEditor->checkAttributes(true)) {85return false;86}87// obtain tagproperty (only for improve code legibility)88const auto& tagProperties = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();89// create base wire90if (!createBaseWireObject(tagProperties)) {91return false;92}93// obtain attributes and values94myWireAttributesEditor->fillSumoBaseObject(myBaseWire);95if (tagProperties->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {96return myConsecutiveLaneSelector->addLane(viewObjects.getLaneFront());97} else {98// build wire over view99return buildWireOverView(tagProperties);100}101}102103104GNEConsecutiveSelector*105GNEWireFrame::getConsecutiveLaneSelector() const {106return myConsecutiveLaneSelector;107}108109110bool111GNEWireFrame::createPath(const bool /* useLastRoute */) {112// obtain tagproperty (only for improve code legibility)113const auto tagProperty = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();114// first check that current tag is valid (currently only for overhead wires)115if (tagProperty->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {116if (myConsecutiveLaneSelector->getLanePath().size() == 1) {117WRITE_WARNINGF(TL("A % needs at least two lane positions"), toString(SUMO_TAG_OVERHEAD_WIRE_SECTION));118} else if (createBaseWireObject(tagProperty)) {119// get attributes and values120myWireAttributesEditor->fillSumoBaseObject(myBaseWire);121// Check if ID has to be generated122if (!myBaseWire->hasStringAttribute(SUMO_ATTR_ID)) {123myBaseWire->addStringAttribute(SUMO_ATTR_ID, myViewNet->getNet()->getAttributeCarriers()->generateAdditionalID(tagProperty->getTag()));124}125// add lane IDs126myBaseWire->addStringListAttribute(SUMO_ATTR_LANES, myConsecutiveLaneSelector->getLaneIDPath());127// set positions128myBaseWire->addDoubleAttribute(SUMO_ATTR_STARTPOS, myConsecutiveLaneSelector->getLanePath().front().second);129myBaseWire->addDoubleAttribute(SUMO_ATTR_ENDPOS, myConsecutiveLaneSelector->getLanePath().back().second);130// show warning dialogbox and stop check if input parameters are valid131if (myWireAttributesEditor->checkAttributes(true)) {132// declare additional handler133GNEAdditionalHandler additionalHandler(myViewNet->getNet(), myBaseWire->hasStringAttribute(GNE_ATTR_ADDITIONAL_FILE) ?134myBaseWire->getStringAttribute(GNE_ATTR_ADDITIONAL_FILE) : "",135myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());136// build additional137additionalHandler.parseSumoBaseObject(myBaseWire);138// Refresh wire Parent Selector (For additionals that have a limited number of children)139mySelectorWireParent->refreshSelectorParentModule();140// abort overhead wire creation141myConsecutiveLaneSelector->abortPathCreation();142// refresh additional attributes143myWireAttributesEditor->refreshAttributesEditor();144return true;145}146}147}148return false;149}150151152void153GNEWireFrame::tagSelected() {154// get template AC155const auto templateAC = myWireTagSelector->getCurrentTemplateAC();156// check if templateAC Exist157if (templateAC) {158// show wire attributes module159myWireAttributesEditor->showAttributesEditor(templateAC, true);160// check if we're creating a overhead wire section161if (templateAC->getTagProperty()->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {162myConsecutiveLaneSelector->showConsecutiveLaneSelectorModule();163mySelectorWireParent->showSelectorParentModule({SUMO_TAG_TRACTION_SUBSTATION});164} else {165myConsecutiveLaneSelector->hideConsecutiveLaneSelectorModule();166mySelectorWireParent->hideSelectorParentModule();167}168} else {169// hide all modules if wire isn't valid170myWireAttributesEditor->hideAttributesEditor();171myConsecutiveLaneSelector->hideConsecutiveLaneSelectorModule();172mySelectorWireParent->hideSelectorParentModule();173}174}175176177bool178GNEWireFrame::createBaseWireObject(const GNETagProperties* tagProperty) {179// check if baseWire exist, and if yes, delete it180if (myBaseWire) {181// go to base wire root182while (myBaseWire->getParentSumoBaseObject()) {183myBaseWire = myBaseWire->getParentSumoBaseObject();184}185// delete baseWire (and all children)186delete myBaseWire;187// reset baseWire188myBaseWire = nullptr;189}190// create a base wire object191myBaseWire = new CommonXMLStructure::SumoBaseObject(nullptr);192// check if wire is a overheadWIre193if (tagProperty->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {194// get wire under cursor195const GNEAdditional* wireUnderCursor = myViewNet->getViewObjectsSelector().getAdditionalFront();196// if user click over a traction substation, mark int in ParentWireSelector197if (wireUnderCursor && (wireUnderCursor->getTagProperty()->getTag() == SUMO_TAG_TRACTION_SUBSTATION)) {198// update parent wire selected199mySelectorWireParent->setIDSelected(wireUnderCursor->getID());200}201// stop if currently there isn't a valid selected parent202if (mySelectorWireParent->getIdSelected().empty()) {203WRITE_WARNING(TLF("A % must be selected before insertion of %.", toString(SUMO_TAG_TRACTION_SUBSTATION), toString(SUMO_TAG_TRACTION_SUBSTATION)));204return false;205} else {206// add tractionsubstation id207myBaseWire->addStringAttribute(SUMO_ATTR_SUBSTATIONID, mySelectorWireParent->getIdSelected());208}209}210// set baseWire tag211myBaseWire->setTag(tagProperty->getTag());212// BaseWire created, then return true213return true;214}215216217bool218GNEWireFrame::buildWireOverView(const GNETagProperties* tagProperty) {219// disable intervals (temporal)220if ((tagProperty->getTag() == SUMO_TAG_INTERVAL) ||221(tagProperty->getTag() == SUMO_TAG_DEST_PROB_REROUTE) ||222(tagProperty->getTag() == SUMO_TAG_CLOSING_REROUTE) ||223(tagProperty->getTag() == SUMO_TAG_CLOSING_LANE_REROUTE) ||224(tagProperty->getTag() == SUMO_TAG_ROUTE_PROB_REROUTE) ||225(tagProperty->getTag() == SUMO_TAG_PARKING_AREA_REROUTE)) {226WRITE_WARNING(TL("Currently unsupported. Create rerouter elements using rerouter dialog"));227return false;228}229// disable intervals (temporal)230if (tagProperty->getTag() == SUMO_TAG_STEP) {231WRITE_WARNING(TL("Currently unsupported. Create VSS steps elements using VSS dialog"));232return false;233}234// Check if ID has to be generated235if (!myBaseWire->hasStringAttribute(SUMO_ATTR_ID)) {236myBaseWire->addStringAttribute(SUMO_ATTR_ID, myViewNet->getNet()->getAttributeCarriers()->generateAdditionalID(tagProperty->getTag()));237}238// Obtain position as the clicked position over view239const Position viewPos = myViewNet->snapToActiveGrid(myViewNet->getPositionInformation());240// add position and X-Y-Z attributes241myBaseWire->addPositionAttribute(SUMO_ATTR_POSITION, viewPos);242myBaseWire->addDoubleAttribute(SUMO_ATTR_X, viewPos.x());243myBaseWire->addDoubleAttribute(SUMO_ATTR_Y, viewPos.y());244myBaseWire->addDoubleAttribute(SUMO_ATTR_Z, viewPos.z());245// show warning dialogbox and stop check if input parameters are valid246if (!myWireAttributesEditor->checkAttributes(true)) {247return false;248} else {249// declare additional handler250GNEAdditionalHandler additionalHandler(myViewNet->getNet(), myBaseWire->hasStringAttribute(GNE_ATTR_ADDITIONAL_FILE) ?251myBaseWire->getStringAttribute(GNE_ATTR_ADDITIONAL_FILE) : "",252myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());253// build wire254additionalHandler.parseSumoBaseObject(myBaseWire);255// Refresh wire Parent Selector (For wires that have a limited number of children)256mySelectorWireParent->refreshSelectorParentModule();257// refresh wire attributes258myWireAttributesEditor->refreshAttributesEditor();259return true;260}261}262263/****************************************************************************/264265266