Path: blob/main/src/netedit/frames/network/GNEWireFrame.cpp
193972 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2021-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 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(),70TL("Experimental Part"),71TL("Warning: The netedit overhead editor is still in experimental state."));72myWarnedExperimental = true;73}74}757677bool78GNEWireFrame::addWire(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {79// first check that current selected wire is valid80if (myWireTagSelector->getCurrentTemplateAC() == nullptr) {81myViewNet->setStatusBarText(TL("Current selected wire isn't valid."));82return false;83}84// show warning dialogbox and stop check if input parameters are valid85if (!myWireAttributesEditor->checkAttributes(true)) {86return false;87}88// obtain tagproperty (only for improve code legibility)89const auto& tagProperties = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();90// create base wire91if (!createBaseWireObject(tagProperties)) {92return false;93}94// obtain attributes and values95myWireAttributesEditor->fillSumoBaseObject(myBaseWire);96if (tagProperties->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {97return myConsecutiveLaneSelector->addLane(viewObjects.getLaneFront());98} else {99// build wire over view100return buildWireOverView(tagProperties);101}102}103104105GNEConsecutiveSelector*106GNEWireFrame::getConsecutiveLaneSelector() const {107return myConsecutiveLaneSelector;108}109110111bool112GNEWireFrame::createPath(const bool /* useLastRoute */) {113// obtain tagproperty (only for improve code legibility)114const auto tagProperty = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();115// first check that current tag is valid (currently only for overhead wires)116if (tagProperty->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {117if (myConsecutiveLaneSelector->getLanePath().size() == 1) {118WRITE_WARNINGF(TL("A % needs at least two lane positions"), toString(SUMO_TAG_OVERHEAD_WIRE_SECTION));119} else if (createBaseWireObject(tagProperty)) {120// get attributes and values121myWireAttributesEditor->fillSumoBaseObject(myBaseWire);122// Check if ID has to be generated123if (!myBaseWire->hasStringAttribute(SUMO_ATTR_ID)) {124myBaseWire->addStringAttribute(SUMO_ATTR_ID, myViewNet->getNet()->getAttributeCarriers()->generateAdditionalID(tagProperty->getTag()));125}126// add lane IDs127myBaseWire->addStringListAttribute(SUMO_ATTR_LANES, myConsecutiveLaneSelector->getLaneIDPath());128// set positions129myBaseWire->addDoubleAttribute(SUMO_ATTR_STARTPOS, myConsecutiveLaneSelector->getLanePath().front().second);130myBaseWire->addDoubleAttribute(SUMO_ATTR_ENDPOS, myConsecutiveLaneSelector->getLanePath().back().second);131// show warning dialogbox and stop check if input parameters are valid132if (myWireAttributesEditor->checkAttributes(true)) {133// declare additional handler134GNEAdditionalHandler additionalHandler(myViewNet->getNet(), myViewNet->getNet()->getACTemplates()->getTemplateAC(tagProperty->getTag())->getFileBucket(),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(), myViewNet->getNet()->getACTemplates()->getTemplateAC(tagProperty->getTag())->getFileBucket(),251myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());252// build wire253additionalHandler.parseSumoBaseObject(myBaseWire);254// Refresh wire Parent Selector (For wires that have a limited number of children)255mySelectorWireParent->refreshSelectorParentModule();256// refresh wire attributes257myWireAttributesEditor->refreshAttributesEditor();258return true;259}260}261262/****************************************************************************/263264265