Path: blob/main/src/netedit/frames/GNESelectorParent.cpp
169678 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 GNESelectorParent.cpp14/// @author Pablo Alvarez Lopez15/// @date Mar 202216///17// Frame for select parents18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/GNETagPropertiesDatabase.h>22#include <netedit/GNEViewNet.h>23#include <netedit/frames/common/GNEInspectorFrame.h>24#include <utils/gui/div/GUIDesigns.h>25#include <utils/gui/windows/GUIAppEnum.h>2627#include "GNESelectorParent.h"2829// ===========================================================================30// method definitions31// ===========================================================================3233GNESelectorParent::GNESelectorParent(GNEFrame* frameParent) :34MFXGroupBoxModule(frameParent, TL("Parent selector")),35myFrameParent(frameParent) {36// Create label with the type of GNESelectorParent37myParentsLabel = new FXLabel(getCollapsableFrame(), TL("No element selected"), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));38// Create list39myParentsList = new FXList(getCollapsableFrame(), this, MID_GNE_SET_TYPE, GUIDesignListFixedHeight);40// Hide List41hideSelectorParentModule();42}434445GNESelectorParent::~GNESelectorParent() {}464748std::string49GNESelectorParent::getIdSelected() const {50for (int i = 0; i < myParentsList->getNumItems(); i++) {51if (myParentsList->isItemSelected(i)) {52return myParentsList->getItem(i)->getText().text();53}54}55return "";56}575859void60GNESelectorParent::setIDSelected(const std::string& id) {61// first unselect all62for (int i = 0; i < myParentsList->getNumItems(); i++) {63myParentsList->getItem(i)->setSelected(false);64}65// select element if correspond to given ID66for (int i = 0; i < myParentsList->getNumItems(); i++) {67if (myParentsList->getItem(i)->getText().text() == id) {68myParentsList->getItem(i)->setSelected(true);69}70}71// recalc myFirstParentsList72myParentsList->recalc();73}747576void77GNESelectorParent::showSelectorParentModule(const std::vector<SumoXMLTag>& parentTags) {78if (parentTags.size() > 0) {79myParentTags = parentTags;80myParentsLabel->setText((TL("Parent type: ") + toString(parentTags.front())).c_str());81refreshSelectorParentModule();82show();83} else {84myParentTags.clear();85hide();86}87}888990void91GNESelectorParent::hideSelectorParentModule() {92myParentTags.clear();93hide();94}959697void98GNESelectorParent::refreshSelectorParentModule() {99// save current edited elements100std::set<std::string> selectedItems;101for (int i = 0; i < myParentsList->getNumItems(); i++) {102if (myParentsList->isItemSelected(i)) {103selectedItems.insert(myParentsList->getItem(i)->getText().text());104}105}106myParentsList->clearItems();107if (myParentTags.size() > 0) {108// insert additionals sorted109std::set<std::string> IDs;110// fill list with IDs111for (const auto& parentTag : myParentTags) {112// check type113const auto tagProperty = myFrameParent->getViewNet()->getNet()->getTagPropertiesDatabase()->getTagProperty(parentTag, true);114// additionals115if (tagProperty->isAdditionalElement()) {116for (const auto& additional : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getAdditionals().at(parentTag)) {117IDs.insert(additional.second->getID().c_str());118}119}120}121// fill list with IDs122for (const auto& ID : IDs) {123const int item = myParentsList->appendItem(ID.c_str());124if (selectedItems.find(ID) != selectedItems.end()) {125myParentsList->selectItem(item);126}127}128}129}130131/****************************************************************************/132133134