Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNENetworkSelector.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// NetworkElement selector module
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22#include <netedit/GNEViewNet.h>
25
26#include "GNENetworkSelector.h"
27#include "GNEFrame.h"
28
29// ===========================================================================
30// FOX callback mapping
31// ===========================================================================
32
33FXDEFMAP(GNENetworkSelector) SelectorParentNetworkElementsMap[] = {
36};
37
38// Object implementation
39FXIMPLEMENT(GNENetworkSelector, MFXGroupBoxModule, SelectorParentNetworkElementsMap, ARRAYNUMBER(SelectorParentNetworkElementsMap))
40
41
42// ---------------------------------------------------------------------------
43// GNENetworkSelector - methods
44// ---------------------------------------------------------------------------
45
46GNENetworkSelector::GNENetworkSelector(GNEFrame* frameParent, const Type networkElementType) :
47 MFXGroupBoxModule(frameParent, TL("NetworkElements")),
48 myFrameParent(frameParent),
49 myNetworkElementType(networkElementType) {
50 // Create horizontal frame
51 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
52 // Create buttons
53 myClearSelection = GUIDesigns::buildFXButton(buttonsFrame, TL("Clear"), "", "", nullptr, this, MID_GNE_CLEARSELECTION, GUIDesignButtonFixed(100));
54 myUseSelected = GUIDesigns::buildFXButton(buttonsFrame, TL("Use selected"), "", "", nullptr, this, MID_GNE_USESELECTED, GUIDesignButtonFixed(100));
55 // Create list
56 myList = new FXList(getCollapsableFrame(), this, MID_GNE_SELECT, GUIDesignListFixedHeight, 0, 0, 0, 100);
57 // create information label and update modul name
58 switch (myNetworkElementType) {
59 case Type::EDGE:
60 new FXLabel(this,
61 (TL("-Click over an edge to select") + std::string("\n") + std::string("-ESC to clear selection")).c_str(),
63 setText(TL("Edges"));
64 break;
65 case Type::LANE:
66 new FXLabel(this,
67 (TL("-Click over an lane to select") + std::string("\n") + std::string("-ESC to clear selection")).c_str(),
69 setText(TL("Lanes"));
70 break;
71 default:
72 throw ProcessError(TL("Invalid NetworkElementType"));
73 }
74 // Hide List
75 hide();
76}
77
78
80
81
82std::vector<std::string>
84 // declare solution
85 std::vector<std::string> solution;
86 // reserve
87 solution.reserve(myList->getNumItems());
88 // fill IDs
89 for (int i = 0; i < myList->getNumItems(); i++) {
90 solution.push_back(myList->getItem(i)->getText().text());
91 }
92 return solution;
93}
94
95
96bool
98 if (myFrameParent->shown() && shown()) {
99 // check if id is selected
100 for (int i = 0; i < myList->getNumItems(); i++) {
101 if (myList->getItem(i)->getText().text() == networkElement->getID()) {
102 return true;
103 }
104 }
105 }
106 return false;
107}
108
109
110void
112 // clear list of egdge ids
113 myList->clearItems();
114 // Show dialog
115 show();
116}
117
118
119void
123
124
125bool
127 return shown();
128}
129
130
131bool
133 // Obtain Id's of list
134 for (int i = 0; i < myList->getNumItems(); i++) {
135 if (myList->getItem(i)->getText().text() == networkElement->getID()) {
136 // unselect element
137 myList->removeItem(i);
138 // update viewNet
139 myFrameParent->getViewNet()->update();
140 return true;
141 }
142 }
143 // select element
144 myList->appendItem(networkElement->getID().c_str(), networkElement->getACIcon());
145 // update viewNet
146 myFrameParent->getViewNet()->update();
147 return true;
148}
149
150
151void
153 // clear list of egdge ids
154 myList->clearItems();
155 // update viewNet
156 myFrameParent->getViewNet()->update();
157}
158
159
160long
161GNENetworkSelector::onCmdUseSelectedElements(FXObject*, FXSelector, void*) {
162 // clear list of egdge ids
163 myList->clearItems();
164 // set modul name
165 switch (myNetworkElementType) {
166 case Type::EDGE:
167 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
168 if (edge.second->isAttributeCarrierSelected()) {
169 myList->appendItem(edge.first.c_str(), edge.second->getACIcon());
170 }
171 }
172 break;
173 case Type::LANE:
174 for (const auto& lane : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getLanes()) {
175 if (lane.second->isAttributeCarrierSelected()) {
176 myList->appendItem(lane.second->getID().c_str(), lane.second->getACIcon());
177 }
178 }
179 break;
180 default:
181 throw ProcessError(TL("Invalid NetworkElementType"));
182 }
183 // Update Frame
184 update();
185 return 1;
186}
187
188
189long
190GNENetworkSelector::onCmdClearSelection(FXObject*, FXSelector, void*) {
192 return 1;
193}
194
195
197 myFrameParent(nullptr),
198 myNetworkElementType(Type::EDGE) {
199}
200
201/****************************************************************************/
FXDEFMAP(GNENetworkSelector) SelectorParentNetworkElementsMap[]
@ MID_GNE_CLEARSELECTION
clear selection of elements
@ MID_GNE_USESELECTED
use selected elements
@ MID_GNE_SELECT
select element
Definition GUIAppEnum.h:957
#define GUIDesignListFixedHeight
design for FXLists with height fixed
Definition GUIDesigns.h:689
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignButtonFixed(width)
button rectangular with thick and raise frame with the given width
Definition GUIDesigns.h:97
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:279
#define TL(string)
Definition MsgHandler.h:301
const std::string getID() const
get ID (all Attribute Carriers have one)
FXIcon * getACIcon() const
get FXIcon associated to this AC
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:154
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
const std::unordered_map< const GUIGlObject *, GNELane * > & getLanes() const
get lanes
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:146
void hideNetworkElementsSelector()
hide GNENetworkSelector Module
bool toggleSelectedElement(const GNENetworkElement *networkElement)
toggle selected networkElement
bool isNetworkElementSelected(const GNENetworkElement *networkElement) const
check if the given networkElement is being selected
bool isShown() const
return true if module is shown
long onCmdUseSelectedElements(FXObject *, FXSelector, void *)
void clearSelection()
clear selection
long onCmdClearSelection(FXObject *, FXSelector, void *)
called when clear selection button is pressed
void showNetworkElementsSelector()
show GNENetworkSelector Module
std::vector< std::string > getSelectedIDs() const
get selected IDs
FXList * myList
List of GNENetworkSelector.
GNEFrame * myFrameParent
pointer to frame parent
GNENetworkSelector()
FOX need this.
const Type myNetworkElementType
@brrief network element type
GNENet * getNet() const
get the net object
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
MFXGroupBoxModule (based on FXGroupBox)