Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNESelectorParent.cpp
Go to the documentation of this file.
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/****************************************************************************/
18// Frame for select parents
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
27
28#include "GNESelectorParent.h"
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33
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
41 // Hide List
43}
44
45
47
48
49std::string
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
60void
61GNESelectorParent::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
77void
78GNESelectorParent::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());
83 show();
84 } else {
85 myParentTags.clear();
86 hide();
87 }
88}
89
90
91void
96
97
98void
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/****************************************************************************/
@ MID_GNE_SET_TYPE
used to select a type of element in a combo box
#define GUIDesignListFixedHeight
design for FXLists that only allow a single selected elements selected and height fixed
Definition GUIDesigns.h:705
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:251
#define TL(string)
Definition MsgHandler.h:305
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:152
const std::unordered_map< SumoXMLTag, std::unordered_map< const GUIGlObject *, GNEAdditional * >, std::hash< int > > & getAdditionals() const
get additionals
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
const GNETagPropertiesDatabase * getTagPropertiesDatabase() const
get tag properties database
Definition GNENet.cpp:138
FXList * myParentsList
List of parents.
GNESelectorParent(GNEFrame *frameParent)
constructor
std::vector< SumoXMLTag > myParentTags
current parent additional tag
void setIDSelected(const std::string &id)
select manually a element of the list
GNEFrame * myFrameParent
pointer to Frame Parent
void showSelectorParentModule(const std::vector< SumoXMLTag > &parentTags)
Show list of GNESelectorParent Module.
~GNESelectorParent()
destructor
void refreshSelectorParentModule()
Refresh list of Additional Parents Module.
std::string getIdSelected() const
get currently parent additional selected
void hideSelectorParentModule()
hide GNESelectorParent Module
FXLabel * myParentsLabel
Label with parent name.
const GNETagProperties * getTagProperty(const SumoXMLTag tag, const bool hardFail) const
get tagProperty associated to the given tag
GNENet * getNet() const
get the net object
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)