Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/GNESelectorParent.cpp
169678 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 GNESelectorParent.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Mar 2022
17
///
18
// Frame for select parents
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagPropertiesDatabase.h>
23
#include <netedit/GNEViewNet.h>
24
#include <netedit/frames/common/GNEInspectorFrame.h>
25
#include <utils/gui/div/GUIDesigns.h>
26
#include <utils/gui/windows/GUIAppEnum.h>
27
28
#include "GNESelectorParent.h"
29
30
// ===========================================================================
31
// method definitions
32
// ===========================================================================
33
34
GNESelectorParent::GNESelectorParent(GNEFrame* frameParent) :
35
MFXGroupBoxModule(frameParent, TL("Parent selector")),
36
myFrameParent(frameParent) {
37
// Create label with the type of GNESelectorParent
38
myParentsLabel = new FXLabel(getCollapsableFrame(), TL("No element selected"), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
39
// Create list
40
myParentsList = new FXList(getCollapsableFrame(), this, MID_GNE_SET_TYPE, GUIDesignListFixedHeight);
41
// Hide List
42
hideSelectorParentModule();
43
}
44
45
46
GNESelectorParent::~GNESelectorParent() {}
47
48
49
std::string
50
GNESelectorParent::getIdSelected() const {
51
for (int i = 0; i < myParentsList->getNumItems(); i++) {
52
if (myParentsList->isItemSelected(i)) {
53
return myParentsList->getItem(i)->getText().text();
54
}
55
}
56
return "";
57
}
58
59
60
void
61
GNESelectorParent::setIDSelected(const std::string& id) {
62
// first unselect all
63
for (int i = 0; i < myParentsList->getNumItems(); i++) {
64
myParentsList->getItem(i)->setSelected(false);
65
}
66
// select element if correspond to given ID
67
for (int i = 0; i < myParentsList->getNumItems(); i++) {
68
if (myParentsList->getItem(i)->getText().text() == id) {
69
myParentsList->getItem(i)->setSelected(true);
70
}
71
}
72
// recalc myFirstParentsList
73
myParentsList->recalc();
74
}
75
76
77
void
78
GNESelectorParent::showSelectorParentModule(const std::vector<SumoXMLTag>& parentTags) {
79
if (parentTags.size() > 0) {
80
myParentTags = parentTags;
81
myParentsLabel->setText((TL("Parent type: ") + toString(parentTags.front())).c_str());
82
refreshSelectorParentModule();
83
show();
84
} else {
85
myParentTags.clear();
86
hide();
87
}
88
}
89
90
91
void
92
GNESelectorParent::hideSelectorParentModule() {
93
myParentTags.clear();
94
hide();
95
}
96
97
98
void
99
GNESelectorParent::refreshSelectorParentModule() {
100
// save current edited elements
101
std::set<std::string> selectedItems;
102
for (int i = 0; i < myParentsList->getNumItems(); i++) {
103
if (myParentsList->isItemSelected(i)) {
104
selectedItems.insert(myParentsList->getItem(i)->getText().text());
105
}
106
}
107
myParentsList->clearItems();
108
if (myParentTags.size() > 0) {
109
// insert additionals sorted
110
std::set<std::string> IDs;
111
// fill list with IDs
112
for (const auto& parentTag : myParentTags) {
113
// check type
114
const auto tagProperty = myFrameParent->getViewNet()->getNet()->getTagPropertiesDatabase()->getTagProperty(parentTag, true);
115
// additionals
116
if (tagProperty->isAdditionalElement()) {
117
for (const auto& additional : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getAdditionals().at(parentTag)) {
118
IDs.insert(additional.second->getID().c_str());
119
}
120
}
121
}
122
// fill list with IDs
123
for (const auto& ID : IDs) {
124
const int item = myParentsList->appendItem(ID.c_str());
125
if (selectedItems.find(ID) != selectedItems.end()) {
126
myParentsList->selectItem(item);
127
}
128
}
129
}
130
}
131
132
/****************************************************************************/
133
134