Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/lists/GNEElementList.cpp
193763 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GNEElementList.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Aug 2025
17
///
18
// Table used in GNEElementList
19
/****************************************************************************/
20
21
#include <netedit/changes/GNEChange_Additional.h>
22
#include <netedit/changes/GNEChange_DemandElement.h>
23
#include <netedit/elements/additional/GNEAdditional.h>
24
#include <netedit/elements/demand/GNEDemandElement.h>
25
#include <netedit/GNEApplicationWindow.h>
26
#include <netedit/GNENet.h>
27
#include <netedit/GNETagPropertiesDatabase.h>
28
#include <netedit/GNEUndoList.h>
29
#include <utils/gui/div/GUIDesigns.h>
30
31
#include "GNEElementList.h"
32
#include "GNEElementTable.h"
33
34
// ===========================================================================
35
// FOX callback mapping
36
// ===========================================================================
37
38
FXDEFMAP(GNEElementList) GNEElementListMap[] = {
39
FXMAPFUNC(SEL_COMMAND, MID_GNE_ELEMENTLIST_ADD, GNEElementList::onCmdAddRow),
40
FXMAPFUNC(SEL_COMMAND, MID_GNE_ELEMENTLIST_SORT, GNEElementList::onCmdSort)
41
};
42
43
// Object implementation
44
FXIMPLEMENT_ABSTRACT(GNEElementList, FXVerticalFrame, GNEElementListMap, ARRAYNUMBER(GNEElementListMap))
45
46
// ===========================================================================
47
// method definitions
48
// ===========================================================================
49
50
GNEElementList::GNEElementList(GNEDialog* parentDialog, FXVerticalFrame* contentFrame, SumoXMLTag tag, GNEElementList::Options options) :
51
FXVerticalFrame(contentFrame, GUIDesignAuxiliarVerticalFrame),
52
myDialogParent(parentDialog),
53
myTagProperty(parentDialog->getApplicationWindow()->getTagPropertiesDatabase()->getTagProperty(tag, true)) {
54
// horizontal frame for buttons
55
FXHorizontalFrame* buttonFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
56
// create add button
57
myAddButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::ADD),
58
this, MID_GNE_ELEMENTLIST_ADD, GUIDesignButtonIcon);
59
// add label with tag
60
myLabel = new FXLabel(buttonFrame, TLF("%s", myTagProperty->getTagStr()).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
61
// check if add sort button
62
if (options & GNEElementList::Options::SORTELEMENTS) {
63
mySortButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::RELOAD),
64
this, MID_GNE_ELEMENTLIST_SORT, GUIDesignButtonIcon);
65
}
66
// create element table
67
myElementTable = new GNEElementTable(this, myTagProperty, options);
68
}
69
70
71
GNEElementList::~GNEElementList() {}
72
73
74
void
75
GNEElementList::enableList() {
76
myLabel->enable();
77
myLabel->setText(TLF("%s", myTagProperty->getTagStr()).c_str());
78
myAddButton->enable();
79
if (mySortButton) {
80
mySortButton->enable();
81
}
82
myElementTable->enable();
83
}
84
85
86
void
87
GNEElementList::disableList(const std::string& reason) {
88
myLabel->disable();
89
myLabel->setText(reason.c_str());
90
myAddButton->disable();
91
if (mySortButton) {
92
mySortButton->disable();
93
}
94
myElementTable->disable();
95
}
96
97
98
bool
99
GNEElementList::isListValid() const {
100
return myElementTable->isValid();
101
}
102
103
104
GNEDialog*
105
GNEElementList::getDialogParent() {
106
return myDialogParent;
107
}
108
109
110
long
111
GNEElementList::onCmdAddRow(FXObject*, FXSelector, void*) {
112
return addNewElement();
113
}
114
115
116
long
117
GNEElementList::onCmdSort(FXObject*, FXSelector, void*) {
118
return sortRows();
119
}
120
121
122
void
123
GNEElementList::removeElementRecursively(GNEAdditional* additionalElement) const {
124
// iterate over all children and delete it recursively
125
const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = additionalElement->getChildAdditionals();
126
for (const auto& additionalChild : additionalChildren) {
127
removeElementRecursively(additionalChild);
128
}
129
const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = additionalElement->getChildDemandElements();
130
for (const auto& demandChild : demandChildren) {
131
removeElementRecursively(demandChild);
132
}
133
// delete element
134
additionalElement->getNet()->getUndoList()->add(new GNEChange_Additional(additionalElement, false), true);
135
}
136
137
138
void
139
GNEElementList::removeElementRecursively(GNEDemandElement* demandElement) const {
140
// iterate over all children and delete it recursively
141
const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = demandElement->getChildAdditionals();
142
for (const auto& additionalChild : additionalChildren) {
143
removeElementRecursively(additionalChild);
144
}
145
const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = demandElement->getChildDemandElements();
146
for (const auto& demandChild : demandChildren) {
147
removeElementRecursively(demandChild);
148
}
149
// delete element
150
demandElement->getNet()->getUndoList()->add(new GNEChange_DemandElement(demandElement, false), true);
151
}
152
153
/****************************************************************************/
154
155