Path: blob/main/src/netedit/dialogs/elements/lists/GNEElementList.cpp
169688 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 GNEElementList.cpp14/// @author Pablo Alvarez Lopez15/// @date Aug 202516///17// Table used in GNEElementList18/****************************************************************************/1920#include <netedit/changes/GNEChange_Additional.h>21#include <netedit/changes/GNEChange_DemandElement.h>22#include <netedit/elements/additional/GNEAdditional.h>23#include <netedit/elements/demand/GNEDemandElement.h>24#include <netedit/GNEApplicationWindow.h>25#include <netedit/GNENet.h>26#include <netedit/GNETagPropertiesDatabase.h>27#include <netedit/GNEUndoList.h>28#include <utils/gui/div/GUIDesigns.h>2930#include "GNEElementList.h"31#include "GNEElementTable.h"3233// ===========================================================================34// FOX callback mapping35// ===========================================================================3637FXDEFMAP(GNEElementList) GNEElementListMap[] = {38FXMAPFUNC(SEL_COMMAND, MID_GNE_ELEMENTLIST_ADD, GNEElementList::onCmdAddRow),39FXMAPFUNC(SEL_COMMAND, MID_GNE_ELEMENTLIST_SORT, GNEElementList::onCmdSort)40};4142// Object implementation43FXIMPLEMENT_ABSTRACT(GNEElementList, FXVerticalFrame, GNEElementListMap, ARRAYNUMBER(GNEElementListMap))4445// ===========================================================================46// method definitions47// ===========================================================================4849GNEElementList::GNEElementList(FXVerticalFrame* contentFrame, const GNETagProperties* tagProperty, GNEElementList::Options options) :50FXVerticalFrame(contentFrame, GUIDesignAuxiliarVerticalFrame),51myTagProperty(tagProperty) {52// horizontal frame for buttons53FXHorizontalFrame* buttonFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);54// create add button55myAddButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::ADD),56this, MID_GNE_ELEMENTLIST_ADD, GUIDesignButtonIcon);57// add label with tag58myLabel = new FXLabel(buttonFrame, TLF("%s", myTagProperty->getTagStr()).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));59// check if add sort button60if (options & GNEElementList::Options::SORTELEMENTS) {61mySortButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::RELOAD),62this, MID_GNE_ELEMENTLIST_SORT, GUIDesignButtonIcon);63}64// create element table65myElementTable = new GNEElementTable(this, myTagProperty, options);66}676869GNEElementList::~GNEElementList() {}707172void73GNEElementList::enableList() {74myLabel->enable();75myLabel->setText(TLF("%s", myTagProperty->getTagStr()).c_str());76myAddButton->enable();77mySortButton->enable();78myElementTable->enable();79}808182void83GNEElementList::disableList(const std::string& reason) {84myLabel->disable();85myLabel->setText(reason.c_str());86myAddButton->disable();87mySortButton->disable();88myElementTable->disable();89}909192bool93GNEElementList::isListValid() const {94return myElementTable->isValid();95}969798long99GNEElementList::onCmdAddRow(FXObject*, FXSelector, void*) {100return addNewElement();101}102103104long105GNEElementList::onCmdSort(FXObject*, FXSelector, void*) {106return sortRows();107}108109110void111GNEElementList::removeElementRecursively(GNEAdditional* additionalElement) const {112// iterate over all children and delete it recursively113const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = additionalElement->getChildAdditionals();114for (const auto& additionalChild : additionalChildren) {115removeElementRecursively(additionalChild);116}117const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = additionalElement->getChildDemandElements();118for (const auto& demandChild : demandChildren) {119removeElementRecursively(demandChild);120}121// delete element122additionalElement->getNet()->getViewNet()->getUndoList()->add(new GNEChange_Additional(additionalElement, false), true);123}124125126void127GNEElementList::removeElementRecursively(GNEDemandElement* demandElement) const {128// iterate over all children and delete it recursively129const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = demandElement->getChildAdditionals();130for (const auto& additionalChild : additionalChildren) {131removeElementRecursively(additionalChild);132}133const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = demandElement->getChildDemandElements();134for (const auto& demandChild : demandChildren) {135removeElementRecursively(demandChild);136}137// delete element138demandElement->getNet()->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(demandElement, false), true);139}140141/****************************************************************************/142143144