Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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// ---------------------------------------------------------------------------
45// GNEViewObjectSelector - methods
46// ---------------------------------------------------------------------------
47
49 MFXGroupBoxModule(frameParent, TL("NetworkElements")),
50 myFrameParent(frameParent) {
51 // Create buttons
52 myClearSelection = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Clear selection"), "", "", nullptr, this, MID_GNE_CLEARSELECTION, GUIDesignButton);
53 myUseSelected = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Use selected"), "", "", nullptr, this, MID_GNE_USESELECTED, GUIDesignButton);
54 // list label
55 new FXLabel(getCollapsableFrame(), TL("Selected elements"), 0, GUIDesignLabelThick(JUSTIFY_NORMAL));
56 // Create list
57 myList = new FXList(getCollapsableFrame(), this, MID_GNE_SELECT, GUIDesignListFixedHeight);
58 // create information label
59 myLabel = new FXLabel(getCollapsableFrame(), "", 0, GUIDesignLabelFrameInformation);
60 // Hide List
61 hide();
62}
63
64
66
67
70 return myTag;
71}
72
73
74bool
76 return std::find(mySelectedACs.begin(), mySelectedACs.end(), AC) != mySelectedACs.end();
77}
78
79
80void
82 myTag = tag;
83 myAttribute = attribute;
84 // update info
85 myLabel->setText((TL("-This additional requires to\n select at least\n one element") + std::string("\n") +
86 TLF("-Click over % to select", toString(tag)) + std::string("\n") +
87 TL("-ESC to clear elements")).c_str());
88 myUseSelected->setText(TLF("Use selected %s", toString(tag)).c_str());
89 // update groupBox elements
90 setText(TLF("% selector", toString(tag)));
91 // clear items
92 myList->clearItems();
93 mySelectedACs.clear();
94 show();
95}
96
97
98void
102
103
104bool
106 if (shown() && AC) {
107 // Obtain Id's of list
108 for (int i = 0; i < myList->getNumItems(); i++) {
109 if (myList->getItem(i)->getText().text() == AC->getID()) {
110 // unselect element
111 myList->removeItem(i);
112 // remove it in list
113 mySelectedACs.erase(mySelectedACs.begin() + i);
114 // update viewNet
115 myFrameParent->getViewNet()->update();
116 return true;
117 }
118 }
119 // select element
120 myList->appendItem(AC->getID().c_str(), AC->getACIcon());
121 mySelectedACs.push_back(AC);
122 // update viewNet
123 myFrameParent->getViewNet()->update();
124 return true;
125 } else {
126 // nothing to toogle
127 return false;
128 }
129}
130
131
132bool
134 if (shown() && lane) {
135 if (myTag == SUMO_TAG_EDGE) {
136 return toggleSelectedElement(lane->getParentEdge());
137 } else {
138 return toggleSelectedElement(lane);
139 }
140 } else {
141 // nothing to toogle
142 return false;
143 }
144}
145
146
147bool
149 if (shown()) {
150 if (myList->getNumItems() == 0) {
151 WRITE_WARNING(TLF("List of % cannot be empty", toString(myTag)));
152 return false;
153 } else {
154 std::vector<std::string> selectedIDs;
155 selectedIDs.reserve(mySelectedACs.size());
156 // Obtain Id's of list
157 for (const auto AC : mySelectedACs) {
158 selectedIDs.push_back(AC->getID());
159 }
160 baseObject->addStringListAttribute(myAttribute, selectedIDs);
161 return true;
162 }
163 } else {
164 // nothing to fill
165 return true;
166 }
167}
168
169
170void
172 // clear list of egdge ids
173 myList->clearItems();
174 mySelectedACs.clear();
175 // update viewNet
176 myFrameParent->getViewNet()->update();
177}
178
179
180long
182 // clear list of egdge ids
183 myList->clearItems();
184 mySelectedACs.clear();
185 // get all selected ACs
186 const auto selectedACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getSelectedAttributeCarriers(false);
187 for (const auto AC : selectedACs) {
188 if (AC->getTagProperty()->getTag() == myTag) {
189 if (AC->isAttributeCarrierSelected()) {
190 myList->appendItem(AC->getID().c_str(), AC->getACIcon());
191 mySelectedACs.push_back(AC);
192 }
193 }
194 }
195 // Update Frame
196 update();
197 return 1;
198}
199
200
201long
202GNEViewObjectSelector::onCmdClearSelection(FXObject*, FXSelector, void*) {
204 return 1;
205}
206
207
209 myFrameParent(nullptr) {
210}
211
212/****************************************************************************/
FXDEFMAP(GNEViewObjectSelector) SelectorParentNetworkElementsMap[]
@ MID_GNE_CLEARSELECTION
clear selection of elements
@ MID_GNE_USESELECTED
use selected elements
@ MID_GNE_SELECT
select element
Definition GUIAppEnum.h:957
#define GUIDesignButton
Definition GUIDesigns.h:82
#define GUIDesignListFixedHeight
design for FXLists that only allow a single selected elements selected and height fixed
Definition GUIDesigns.h:689
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:249
#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 WRITE_WARNING(msg)
Definition MsgHandler.h:283
#define TL(string)
Definition MsgHandler.h:301
#define TLF(string,...)
Definition MsgHandler.h:303
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:154
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
GNEEdge * getParentEdge() const
get parent edge
Definition GNELane.cpp:202
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:146
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