Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/lists/GNEElementList.cpp
169688 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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(FXVerticalFrame* contentFrame, const GNETagProperties* tagProperty, GNEElementList::Options options) :
51
FXVerticalFrame(contentFrame, GUIDesignAuxiliarVerticalFrame),
52
myTagProperty(tagProperty) {
53
// horizontal frame for buttons
54
FXHorizontalFrame* buttonFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
55
// create add button
56
myAddButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::ADD),
57
this, MID_GNE_ELEMENTLIST_ADD, GUIDesignButtonIcon);
58
// add label with tag
59
myLabel = new FXLabel(buttonFrame, TLF("%s", myTagProperty->getTagStr()).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
60
// check if add sort button
61
if (options & GNEElementList::Options::SORTELEMENTS) {
62
mySortButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::RELOAD),
63
this, MID_GNE_ELEMENTLIST_SORT, GUIDesignButtonIcon);
64
}
65
// create element table
66
myElementTable = new GNEElementTable(this, myTagProperty, options);
67
}
68
69
70
GNEElementList::~GNEElementList() {}
71
72
73
void
74
GNEElementList::enableList() {
75
myLabel->enable();
76
myLabel->setText(TLF("%s", myTagProperty->getTagStr()).c_str());
77
myAddButton->enable();
78
mySortButton->enable();
79
myElementTable->enable();
80
}
81
82
83
void
84
GNEElementList::disableList(const std::string& reason) {
85
myLabel->disable();
86
myLabel->setText(reason.c_str());
87
myAddButton->disable();
88
mySortButton->disable();
89
myElementTable->disable();
90
}
91
92
93
bool
94
GNEElementList::isListValid() const {
95
return myElementTable->isValid();
96
}
97
98
99
long
100
GNEElementList::onCmdAddRow(FXObject*, FXSelector, void*) {
101
return addNewElement();
102
}
103
104
105
long
106
GNEElementList::onCmdSort(FXObject*, FXSelector, void*) {
107
return sortRows();
108
}
109
110
111
void
112
GNEElementList::removeElementRecursively(GNEAdditional* additionalElement) const {
113
// iterate over all children and delete it recursively
114
const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = additionalElement->getChildAdditionals();
115
for (const auto& additionalChild : additionalChildren) {
116
removeElementRecursively(additionalChild);
117
}
118
const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = additionalElement->getChildDemandElements();
119
for (const auto& demandChild : demandChildren) {
120
removeElementRecursively(demandChild);
121
}
122
// delete element
123
additionalElement->getNet()->getViewNet()->getUndoList()->add(new GNEChange_Additional(additionalElement, false), true);
124
}
125
126
127
void
128
GNEElementList::removeElementRecursively(GNEDemandElement* demandElement) const {
129
// iterate over all children and delete it recursively
130
const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = demandElement->getChildAdditionals();
131
for (const auto& additionalChild : additionalChildren) {
132
removeElementRecursively(additionalChild);
133
}
134
const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = demandElement->getChildDemandElements();
135
for (const auto& demandChild : demandChildren) {
136
removeElementRecursively(demandChild);
137
}
138
// delete element
139
demandElement->getNet()->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(demandElement, false), true);
140
}
141
142
/****************************************************************************/
143
144