Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEViewObjectSelector.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>
27
29#include "GNEFrame.h"
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
35FXDEFMAP(GNEViewObjectSelector) SelectorParentNetworkElementsMap[] = {
38};
39
40// Object implementation
41FXIMPLEMENT(GNEViewObjectSelector, MFXGroupBoxModule, SelectorParentNetworkElementsMap, ARRAYNUMBER(SelectorParentNetworkElementsMap))
42
43// ---------------------------------------------------------------------------
44// GNEViewObjectSelector - methods
45// ---------------------------------------------------------------------------
46
48 MFXGroupBoxModule(frameParent, TL("NetworkElements")),
49 myFrameParent(frameParent) {
50 // Create buttons
51 myClearSelection = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Clear selection"), "", "", nullptr, this, MID_GNE_CLEARSELECTION, GUIDesignButton);
52 myUseSelected = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Use selected"), "", "", nullptr, this, MID_GNE_USESELECTED, GUIDesignButton);
53 // list label
54 new FXLabel(getCollapsableFrame(), TL("Selected elements"), 0, GUIDesignLabelThick(JUSTIFY_NORMAL));
55 // Create list
56 myList = new FXList(getCollapsableFrame(), this, MID_GNE_SELECT, GUIDesignListFixedHeight);
57 // create information label
58 myLabel = new FXLabel(getCollapsableFrame(), "", 0, GUIDesignLabelFrameInformation);
59 // Hide List
60 hide();
61}
62
63
65
66
69 return myTag;
70}
71
72
73bool
75 return std::find(mySelectedACs.begin(), mySelectedACs.end(), AC) != mySelectedACs.end();
76}
77
78
79void
81 myTag = newTag;
82 myAttribute = attribute;
83 // update info
84 myLabel->setText((TL("-This additional requires to\n select at least\n one element") + std::string("\n") +
85 TLF("-Click over % to select", toString(newTag)) + std::string("\n") +
86 TL("-ESC to clear elements")).c_str());
87 myUseSelected->setText(TLF("Use selected %s", toString(newTag)).c_str());
88 // update groupBox elements
89 setText(TLF("% selector", toString(newTag)));
90 // clear items
91 myList->clearItems();
92 mySelectedACs.clear();
93 show();
94}
95
96
97void
101
102
103bool
105 if (shown() && AC) {
106 // Obtain Id's of list
107 for (int i = 0; i < myList->getNumItems(); i++) {
108 if (myList->getItem(i)->getText().text() == AC->getID()) {
109 // unselect element
110 myList->removeItem(i);
111 // remove it in list
112 mySelectedACs.erase(mySelectedACs.begin() + i);
113 // update viewNet
114 myFrameParent->getViewNet()->update();
115 return true;
116 }
117 }
118 // select element
119 myList->appendItem(AC->getID().c_str(), AC->getACIcon());
120 mySelectedACs.push_back(AC);
121 // update viewNet
122 myFrameParent->getViewNet()->update();
123 return true;
124 } else {
125 // nothing to toogle
126 return false;
127 }
128}
129
130
131bool
133 if (shown() && lane) {
134 if (myTag == SUMO_TAG_EDGE) {
135 return toggleSelectedElement(lane->getParentEdge());
136 } else {
137 return toggleSelectedElement(lane);
138 }
139 } else {
140 // nothing to toogle
141 return false;
142 }
143}
144
145
146bool
148 if (shown()) {
149 if (myList->getNumItems() == 0) {
150 WRITE_WARNING(TLF("List of % cannot be empty", toString(myTag)));
151 return false;
152 } else {
153 std::vector<std::string> selectedIDs;
154 selectedIDs.reserve(mySelectedACs.size());
155 // Obtain Id's of list
156 for (const auto AC : mySelectedACs) {
157 selectedIDs.push_back(AC->getID());
158 }
159 baseObject->addStringListAttribute(myAttribute, selectedIDs);
160 return true;
161 }
162 } else {
163 // nothing to fill
164 return true;
165 }
166}
167
168
169void
171 // clear list of egdge ids
172 myList->clearItems();
173 mySelectedACs.clear();
174 // update viewNet
175 myFrameParent->getViewNet()->update();
176}
177
178
179long
181 // clear list of egdge ids
182 myList->clearItems();
183 mySelectedACs.clear();
184 // get all selected ACs
185 const auto selectedACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getSelectedAttributeCarriers(false);
186 for (const auto AC : selectedACs) {
187 if (AC->getTagProperty()->getTag() == myTag) {
188 if (AC->isAttributeCarrierSelected()) {
189 myList->appendItem(AC->getID().c_str(), AC->getACIcon());
190 mySelectedACs.push_back(AC);
191 }
192 }
193 }
194 // Update Frame
195 update();
196 return 1;
197}
198
199
200long
201GNEViewObjectSelector::onCmdClearSelection(FXObject*, FXSelector, void*) {
203 return 1;
204}
205
206
208 myFrameParent(nullptr) {
209}
210
211/****************************************************************************/
FXDEFMAP(GNEViewObjectSelector) SelectorParentNetworkElementsMap[]
@ MID_GNE_CLEARSELECTION
clear selection of elements
@ MID_GNE_USESELECTED
use selected elements
@ MID_GNE_SELECT
select element
#define GUIDesignButton
Definition GUIDesigns.h:100
#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 GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:281
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_EDGE
begin/end of the description of an edge
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void addStringListAttribute(const SumoXMLAttr attr, const std::vector< std::string > &value)
add string list attribute into current SumoBaseObject node
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:152
GNEEdge * getParentEdge() const
get parent edge
Definition GNELane.cpp:214
std::vector< GNEAttributeCarrier * > getSelectedAttributeCarriers(const bool ignoreCurrentSupermode)
get all selected attribute carriers (or only relative to current supermode
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
GNENet * getNet() const
get the net object
std::vector< const GNEAttributeCarrier * > mySelectedACs
selected ACs
long onCmdUseSelectedElements(FXObject *, FXSelector, void *)
bool fillSumoBaseObject(CommonXMLStructure::SumoBaseObject *baseObject) const
@brie fill SUMO base object
FXButton * myUseSelected
button for use selected edges
void showNetworkElementsSelector(const SumoXMLTag tag, const SumoXMLAttr attribute)
show GNEViewObjectSelector Module
void clearSelection()
clear selection
bool toggleSelectedLane(const GNELane *lane)
toggle selected lane
long onCmdClearSelection(FXObject *, FXSelector, void *)
called when clear selection button is pressed
SumoXMLTag myTag
network element type
FXList * myList
List of GNEViewObjectSelector.
bool isNetworkElementSelected(const GNEAttributeCarrier *AC) const
check if the given AC is selected
FXLabel * myLabel
info label
GNEFrame * myFrameParent
pointer to frame parent
SumoXMLAttr myAttribute
attribute vinculated
void hideNetworkElementsSelector()
hide GNEViewObjectSelector Module
SumoXMLTag getTag() const
get tag with selected element type
bool toggleSelectedElement(const GNEAttributeCarrier *AC)
toggle selected element
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)
void setText(const std::string &text)
set text