Path: blob/main/src/netedit/dialogs/elements/lists/GNEElementList.cpp
193763 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 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(GNEDialog* parentDialog, FXVerticalFrame* contentFrame, SumoXMLTag tag, GNEElementList::Options options) :50FXVerticalFrame(contentFrame, GUIDesignAuxiliarVerticalFrame),51myDialogParent(parentDialog),52myTagProperty(parentDialog->getApplicationWindow()->getTagPropertiesDatabase()->getTagProperty(tag, true)) {53// horizontal frame for buttons54FXHorizontalFrame* buttonFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);55// create add button56myAddButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::ADD),57this, MID_GNE_ELEMENTLIST_ADD, GUIDesignButtonIcon);58// add label with tag59myLabel = new FXLabel(buttonFrame, TLF("%s", myTagProperty->getTagStr()).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));60// check if add sort button61if (options & GNEElementList::Options::SORTELEMENTS) {62mySortButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::RELOAD),63this, MID_GNE_ELEMENTLIST_SORT, GUIDesignButtonIcon);64}65// create element table66myElementTable = new GNEElementTable(this, myTagProperty, options);67}686970GNEElementList::~GNEElementList() {}717273void74GNEElementList::enableList() {75myLabel->enable();76myLabel->setText(TLF("%s", myTagProperty->getTagStr()).c_str());77myAddButton->enable();78if (mySortButton) {79mySortButton->enable();80}81myElementTable->enable();82}838485void86GNEElementList::disableList(const std::string& reason) {87myLabel->disable();88myLabel->setText(reason.c_str());89myAddButton->disable();90if (mySortButton) {91mySortButton->disable();92}93myElementTable->disable();94}959697bool98GNEElementList::isListValid() const {99return myElementTable->isValid();100}101102103GNEDialog*104GNEElementList::getDialogParent() {105return myDialogParent;106}107108109long110GNEElementList::onCmdAddRow(FXObject*, FXSelector, void*) {111return addNewElement();112}113114115long116GNEElementList::onCmdSort(FXObject*, FXSelector, void*) {117return sortRows();118}119120121void122GNEElementList::removeElementRecursively(GNEAdditional* additionalElement) const {123// iterate over all children and delete it recursively124const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = additionalElement->getChildAdditionals();125for (const auto& additionalChild : additionalChildren) {126removeElementRecursively(additionalChild);127}128const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = additionalElement->getChildDemandElements();129for (const auto& demandChild : demandChildren) {130removeElementRecursively(demandChild);131}132// delete element133additionalElement->getNet()->getUndoList()->add(new GNEChange_Additional(additionalElement, false), true);134}135136137void138GNEElementList::removeElementRecursively(GNEDemandElement* demandElement) const {139// iterate over all children and delete it recursively140const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = demandElement->getChildAdditionals();141for (const auto& additionalChild : additionalChildren) {142removeElementRecursively(additionalChild);143}144const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = demandElement->getChildDemandElements();145for (const auto& demandChild : demandChildren) {146removeElementRecursively(demandChild);147}148// delete element149demandElement->getNet()->getUndoList()->add(new GNEChange_DemandElement(demandElement, false), true);150}151152/****************************************************************************/153154155