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-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// NetworkElement selector module
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
26
27#include "GNENetworkSelector.h"
28#include "GNEFrame.h"
29
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
35FXDEFMAP(GNENetworkSelector) SelectorParentNetworkElementsMap[] = {
38};
39
40// Object implementation
41FXIMPLEMENT(GNENetworkSelector, MFXGroupBoxModule, SelectorParentNetworkElementsMap, ARRAYNUMBER(SelectorParentNetworkElementsMap))
42
43
44// ---------------------------------------------------------------------------
45// GNENetworkSelector - methods
46// ---------------------------------------------------------------------------
47
48GNENetworkSelector::GNENetworkSelector(GNEFrame* frameParent, const Type networkElementType) :
49 MFXGroupBoxModule(frameParent, TL("NetworkElements")),
50 myFrameParent(frameParent),
51 myNetworkElementType(networkElementType) {
52 // Create horizontal frame
53 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
54 // Create buttons
55 myClearSelection = GUIDesigns::buildFXButton(buttonsFrame, TL("Clear"), "", "", nullptr, this, MID_GNE_CLEARSELECTION, GUIDesignButtonFixed(100));
56 myUseSelected = GUIDesigns::buildFXButton(buttonsFrame, TL("Use selected"), "", "", nullptr, this, MID_GNE_USESELECTED, GUIDesignButtonFixed(100));
57 // Create list
58 myList = new FXList(getCollapsableFrame(), this, MID_GNE_SELECT, GUIDesignListFixedHeight, 0, 0, 0, 100);
59 // create information label and update modul name
60 switch (myNetworkElementType) {
61 case Type::EDGE:
62 new FXLabel(this,
63 (TL("-Click over an edge to select") + std::string("\n") + std::string("-ESC to clear selection")).c_str(),
65 setText(TL("Edges"));
66 break;
67 case Type::LANE:
68 new FXLabel(this,
69 (TL("-Click over an lane to select") + std::string("\n") + std::string("-ESC to clear selection")).c_str(),
71 setText(TL("Lanes"));
72 break;
73 default:
74 throw ProcessError(TL("Invalid NetworkElementType"));
75 }
76 // Hide List
77 hide();
78}
79
80
82
83
84std::vector<std::string>
86 // declare solution
87 std::vector<std::string> solution;
88 // reserve
89 solution.reserve(myList->getNumItems());
90 // fill IDs
91 for (int i = 0; i < myList->getNumItems(); i++) {
92 solution.push_back(myList->getItem(i)->getText().text());
93 }
94 return solution;
95}
96
97
98bool
100 if (myFrameParent->shown() && shown()) {
101 // check if id is selected
102 for (int i = 0; i < myList->getNumItems(); i++) {
103 if (myList->getItem(i)->getText().text() == networkElement->getID()) {
104 return true;
105 }
106 }
107 }
108 return false;
109}
110
111
112void
114 // clear list of egdge ids
115 myList->clearItems();
116 // Show dialog
117 show();
118}
119
120
121void
125
126
127bool
129 return shown();
130}
131
132
133bool
135 // Obtain Id's of list
136 for (int i = 0; i < myList->getNumItems(); i++) {
137 if (myList->getItem(i)->getText().text() == networkElement->getID()) {
138 // unselect element
139 myList->removeItem(i);
140 // update viewNet
141 myFrameParent->getViewNet()->update();
142 return true;
143 }
144 }
145 // select element
146 myList->appendItem(networkElement->getID().c_str(), networkElement->getACIcon());
147 // update viewNet
148 myFrameParent->getViewNet()->update();
149 return true;
150}
151
152
153void
155 // clear list of egdge ids
156 myList->clearItems();
157 // update viewNet
158 myFrameParent->getViewNet()->update();
159}
160
161
162long
163GNENetworkSelector::onCmdUseSelectedElements(FXObject*, FXSelector, void*) {
164 // clear list of egdge ids
165 myList->clearItems();
166 // set modul name
167 switch (myNetworkElementType) {
168 case Type::EDGE:
169 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
170 if (edge.second->isAttributeCarrierSelected()) {
171 myList->appendItem(edge.first.c_str(), edge.second->getACIcon());
172 }
173 }
174 break;
175 case Type::LANE:
176 for (const auto& lane : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getLanes()) {
177 if (lane.second->isAttributeCarrierSelected()) {
178 myList->appendItem(lane.second->getID().c_str(), lane.second->getACIcon());
179 }
180 }
181 break;
182 default:
183 throw ProcessError(TL("Invalid NetworkElementType"));
184 }
185 // Update Frame
186 update();
187 return 1;
188}
189
190
191long
192GNENetworkSelector::onCmdClearSelection(FXObject*, FXSelector, void*) {
194 return 1;
195}
196
197
199 myFrameParent(nullptr),
200 myNetworkElementType(Type::EDGE) {
201}
202
203/****************************************************************************/
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:692
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:405
#define GUIDesignButtonFixed(width)
button rectangular with thick and raise frame with the given width
Definition GUIDesigns.h:103
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:285
#define TL(string)
Definition MsgHandler.h:315
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:150
const std::map< const 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:127
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)