Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEOverlappedInspection.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// Frame for overlapped elements
19/****************************************************************************/
20
21#include <netedit/GNEViewNet.h>
27
29
30// ===========================================================================
31// FOX callback mapping
32// ===========================================================================
33
41
42// Object implementation
43FXIMPLEMENT(GNEOverlappedInspection, MFXGroupBoxModule, OverlappedInspectionMap, ARRAYNUMBER(OverlappedInspectionMap))
44
45// ===========================================================================
46// method definitions
47// ===========================================================================
48
49GNEOverlappedInspection::GNEOverlappedInspection(GNEFrame* frameParent, const bool onlyJunctions) :
50 MFXGroupBoxModule(frameParent, onlyJunctions ? TL("Overlapped junctions") : TL("Overlapped elements")),
51 myFrameParent(frameParent),
52 myOnlyJunctions(onlyJunctions) {
53 FXHorizontalFrame* frameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
54 // Create previous Item Button
56 // create current index button
57 myCurrentIndexButton = GUIDesigns::buildFXButton(frameButtons, "", "", "", nullptr, this, MID_GNE_OVERLAPPED_SHOWLIST, GUIDesignButton);
58 // Create next Item Button
60 // Create list of overlapped elements (by default hidden)
61 myOverlappedElementList = new FXList(getCollapsableFrame(), this, MID_GNE_OVERLAPPED_ITEMSELECTED, GUIDesignListFixedHeight);
62 // by default list of overlapped elements is hidden)
63 myOverlappedElementList->hide();
64 // Create help button
65 myHelpButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Help"), "", "", nullptr, this, MID_HELP, GUIDesignButtonRectangular);
66 // by default hidden
67 hide();
68}
69
70
72
73
74void
75GNEOverlappedInspection::showOverlappedInspection(GNEViewNetHelper::ViewObjectsSelector& viewObjects, const Position& clickedPosition, const bool shiftKeyPressed) {
76 // check if filter all except junctions
77 if (myOnlyJunctions) {
78 viewObjects.filterAllExcept(GLO_JUNCTION);
79 } else {
80 // filter by supermode
81 viewObjects.filterBySuperMode();
82 // filtger edges if we clicked over a lane
83 if (viewObjects.getAttributeCarrierFront() && viewObjects.getAttributeCarrierFront() == viewObjects.getLaneFront()) {
84 viewObjects.filterEdges();
85 }
86 }
87 // check if previously we clicked an edge and now we want to inspect their lane
88 bool toogleInspectEdgeLane = false;
89 if (!myOnlyJunctions && (myOverlappedACs.size() > 0) && (myOverlappedACs.front()->getTagProperty()->getTag() == SUMO_TAG_EDGE) && shiftKeyPressed) {
90 toogleInspectEdgeLane = true;
91 }
92 // in this point, check if we want to iterate over existent overlapped inspection, or we want to inspet a new set of elements
93 if (!toogleInspectEdgeLane && (myOverlappedACs.size() > 0) && (myClickedPosition != Position::INVALID) && (myClickedPosition.distanceSquaredTo(clickedPosition) < 0.05) && (myShiftKeyPressed == shiftKeyPressed)) {
94 onCmdInspectNextElement(nullptr, 0, nullptr);
95 } else {
97 myItemIndex = 0;
99 }
100 // update clicked position and refresh overlapped inspection
101 myClickedPosition = clickedPosition;
102 myShiftKeyPressed = shiftKeyPressed;
104}
105
106
107void
114
115
116void
120
121void
123 // show modul depending of number of overlapped elements
124 if (myOverlappedACs.size() > 1) {
125 // update text of current index button
126 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
127 // clear and fill list again
128 myOverlappedElementList->clearItems();
129 for (int i = 0; i < (int)myOverlappedACs.size(); i++) {
130 myOverlappedElementList->insertItem(i, myOverlappedACs.at(i)->getID().c_str(), myOverlappedACs.at(i)->getACIcon());
131 }
132 // select current item
133 myOverlappedElementList->getItem(myItemIndex)->setSelected(TRUE);
134 // show modul
135 show();
136 // call selectedOverlappedElement
138 } else {
139 if (myOverlappedACs.size() > 0) {
141 } else {
143 }
144 hide();
145 }
146}
147
148
149bool
151 // show GNEOverlappedInspection modul
152 return shown();
153}
154
155
156int
160
161
164 if (myOverlappedACs.size() > 0) {
165 return myOverlappedACs.at(myItemIndex);
166 } else {
167 return nullptr;
168 }
169}
170
171long
173 // check if there is items
174 if (myOverlappedElementList->getNumItems() > 0) {
175 // set index (it works as a ring)
176 if (myItemIndex > 0) {
177 myItemIndex--;
178 } else {
179 myItemIndex = ((int)myOverlappedACs.size() - 1);
180 }
182 }
183 return 1;
184}
185
186
187long
189 // check if there is items
190 if (myOverlappedElementList->getNumItems() > 0) {
191 // set index (it works as a ring)
192 myItemIndex = (myItemIndex + 1) % myOverlappedACs.size();
194 }
195 return 1;
196}
197
198
199long
200GNEOverlappedInspection::onCmdShowList(FXObject*, FXSelector, void*) {
201 // show or hide element list
202 if (myOverlappedElementList->shown()) {
204 } else {
206 }
207 if (myOverlappedElementList->getNumItems() <= 10) {
208 myOverlappedElementList->setHeight(23 * myOverlappedElementList->getNumItems());
209 } else {
210 myOverlappedElementList->setHeight(230);
211 }
212 myOverlappedElementList->recalc();
213 // recalc and update frame
214 recalc();
215 return 1;
216}
217
218long
220 for (int i = 0; i < myOverlappedElementList->getNumItems(); i++) {
221 if (myOverlappedElementList->getItem(i)->isSelected()) {
222 myItemIndex = i;
224 return 1;
225 }
226 }
227 return 0;
228}
229
230
231long
233 FXDialogBox* helpDialog = new FXDialogBox(getCollapsableFrame(), TL("GEO attributes Help"), GUIDesignDialogBox);
234 std::ostringstream help;
235 help
236 << TL(" - Click in the same position") << "\n"
237 << TL(" to inspect next element") << "\n"
238 << TL(" - Shift + Click in the same") << "\n"
239 << TL(" position to inspect") << "\n"
240 << TL(" previous element");
241 new FXLabel(helpDialog, help.str().c_str(), nullptr, GUIDesignLabelFrameInformation);
242 // "OK"
243 GUIDesigns::buildFXButton(helpDialog, TL("OK"), "", TL("close"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), helpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
244 helpDialog->create();
245 helpDialog->show(PLACEMENT_SCREEN);
246 return 1;
247}
248
249
251
252/****************************************************************************/
FXDEFMAP(GNEOverlappedInspection) OverlappedInspectionMap[]
@ MID_GNE_OVERLAPPED_PREVIOUS
inspect previous element in overlapped module
@ MID_GNE_OVERLAPPED_ITEMSELECTED
list item selected in overlapped module
@ MID_HELP
help button
Definition GUIAppEnum.h:653
@ MID_GNE_OVERLAPPED_SHOWLIST
show list of overlapped elements
@ MID_GNE_OVERLAPPED_NEXT
inspect next element in overlapped module
#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 GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignDialogBox
Definition GUIDesigns.h:599
#define GUIDesignButtonRectangular
little rectangular button used in frames (For example, in "help" buttons)
Definition GUIDesigns.h:94
#define GUIDesignButtonOK
Definition GUIDesigns.h:153
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:279
@ GLO_JUNCTION
a junction
@ BIGARROWLEFT
@ BIGARROWRIGHT
#define TL(string)
Definition MsgHandler.h:305
@ SUMO_TAG_EDGE
begin/end of the description of an edge
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
virtual void selectedOverlappedElement(GNEAttributeCarrier *AC)
open GNEAttributesCreator extended dialog
Definition GNEFrame.cpp:301
void clearOverlappedInspection()
clear overlapped inspection
GNEAttributeCarrier * getCurrentAC() const
get current AC
void refreshOverlappedInspection()
show template editor
FXButton * myCurrentIndexButton
Button for current index.
Position myClickedPosition
clicked position
std::vector< GNEAttributeCarrier * > myOverlappedACs
objects under cursor
long onCmdShowList(FXObject *, FXSelector, void *)
show list of overlapped elements
void hiderOverlappedInspection()
hide overlapped inspection
void showOverlappedInspection(GNEViewNetHelper::ViewObjectsSelector &viewObjects, const Position &clickedPosition, const bool shiftKeyPressed)
show overlapped inspection
long onCmdOverlappingHelp(FXObject *, FXSelector, void *)
Called when user press the help button.
bool overlappedInspectionShown() const
check if overlappedInspection modul is shown
long onCmdListItemSelected(FXObject *, FXSelector, void *)
called when a list item is selected
long onCmdInspectPreviousElement(FXObject *, FXSelector, void *)
Inspect previous element (from top to bot)
int myItemIndex
current index item
GNEFrame * myFrameParent
current frame parent
long onCmdInspectNextElement(FXObject *, FXSelector, void *)
Inspect next Element (from top to bot)
FXList * myOverlappedElementList
list of overlapped elements
bool myShiftKeyPressed
shift key pressed
int getNumberOfOverlappedACs() const
get number of overlapped ACs
const bool myOnlyJunctions
flag to indicate that this modul is only for junctions
class used to group all variables related with objects under cursor after a click over view
void filterAllExcept(GUIGlObjectType exception)
filter all elements except the given GLO type
const std::vector< GNEAttributeCarrier * > & getAttributeCarriers() const
get vector with ACs
void filterEdges()
filter (remove) edges
void filterBySuperMode()
filter by supermode
GNEAttributeCarrier * getAttributeCarrierFront() const
get front attribute carrier or a pointer to nullptr
GNELane * getLaneFront() const
get front lane or a pointer to nullptr
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
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:319
double distanceSquaredTo(const Position &p2) const
returns the square of the distance to another position
Definition Position.h:268