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-2024 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#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
27
28#include "GNESelectorParent.h"
29
30
31// ===========================================================================
32// method definitions
33// ===========================================================================
34
36 MFXGroupBoxModule(frameParent, TL("Parent selector")),
37 myFrameParent(frameParent) {
38 // Create label with the type of GNESelectorParent
39 myParentsLabel = new FXLabel(getCollapsableFrame(), TL("No element selected"), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
40 // Create list
42 // Hide List
44}
45
46
48
49
50std::string
52 for (int i = 0; i < myParentsList->getNumItems(); i++) {
53 if (myParentsList->isItemSelected(i)) {
54 return myParentsList->getItem(i)->getText().text();
55 }
56 }
57 return "";
58}
59
60
61void
62GNESelectorParent::setIDSelected(const std::string& id) {
63 // first unselect all
64 for (int i = 0; i < myParentsList->getNumItems(); i++) {
65 myParentsList->getItem(i)->setSelected(false);
66 }
67 // select element if correspond to given ID
68 for (int i = 0; i < myParentsList->getNumItems(); i++) {
69 if (myParentsList->getItem(i)->getText().text() == id) {
70 myParentsList->getItem(i)->setSelected(true);
71 }
72 }
73 // recalc myFirstParentsList
74 myParentsList->recalc();
75}
76
77
78void
79GNESelectorParent::showSelectorParentModule(const std::vector<SumoXMLTag>& parentTags) {
80 if (parentTags.size() > 0) {
81 myParentTags = parentTags;
82 myParentsLabel->setText((TL("Parent type: ") + toString(parentTags.front())).c_str());
84 show();
85 } else {
86 myParentTags.clear();
87 hide();
88 }
89}
90
91
92void
97
98
99void
101 // save current edited elements
102 std::set<std::string> selectedItems;
103 for (int i = 0; i < myParentsList->getNumItems(); i++) {
104 if (myParentsList->isItemSelected(i)) {
105 selectedItems.insert(myParentsList->getItem(i)->getText().text());
106 }
107 }
108 myParentsList->clearItems();
109 if (myParentTags.size() > 0) {
110 // insert additionals sorted
111 std::set<std::string> IDs;
112 // fill list with IDs
113 for (const auto& parentTag : myParentTags) {
114 // check type
115 const auto tagProperty = GNEAttributeCarrier::getTagProperty(parentTag);
116 // additionals
117 if (tagProperty.isAdditionalElement()) {
118 for (const auto& additional : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getAdditionals().at(parentTag)) {
119 IDs.insert(additional.second->getID().c_str());
120 }
121 }
122 }
123 // fill list with IDs
124 for (const auto& ID : IDs) {
125 const int item = myParentsList->appendItem(ID.c_str());
126 if (selectedItems.find(ID) != selectedItems.end()) {
127 myParentsList->selectItem(item);
128 }
129 }
130 }
131}
132
133/****************************************************************************/
@ MID_GNE_SET_TYPE
used to select a type of element in a combo box
Definition GUIAppEnum.h:959
#define GUIDesignListSingleElementFixedHeight
design for FXLists that only allow a single selected elements selected and height fixed
Definition GUIDesigns.h:695
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:255
#define TL(string)
Definition MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
const std::unordered_map< SumoXMLTag, std::unordered_map< const GUIGlObject *, GNEAdditional * > > & getAdditionals() const
get additionals
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
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.
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)