Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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>
28
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
42
43// Object implementation
44FXIMPLEMENT(GNEOverlappedInspection, MFXGroupBoxModule, OverlappedInspectionMap, ARRAYNUMBER(OverlappedInspectionMap))
45
46// ===========================================================================
47// method definitions
48// ===========================================================================
49
50GNEOverlappedInspection::GNEOverlappedInspection(GNEFrame* frameParent, const bool onlyJunctions) :
51 MFXGroupBoxModule(frameParent, onlyJunctions ? TL("Overlapped junctions") : TL("Overlapped elements")),
52 myFrameParent(frameParent),
53 myOnlyJunctions(onlyJunctions) {
54 FXHorizontalFrame* frameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
55 // Create previous Item Button
57 // create current index button
58 myCurrentIndexButton = GUIDesigns::buildFXButton(frameButtons, "", "", "", nullptr, this, MID_GNE_OVERLAPPED_SHOWLIST, GUIDesignButton);
59 // Create next Item Button
61 // Create list of overlapped elements (by default hidden)
62 myOverlappedElementList = new FXList(getCollapsableFrame(), this, MID_GNE_OVERLAPPED_ITEMSELECTED, GUIDesignListFixedHeight);
63 // by default list of overlapped elements is hidden)
64 myOverlappedElementList->hide();
65 // Create help button
66 myHelpButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Help"), "", "", nullptr, this, MID_HELP, GUIDesignButtonRectangular);
67 // by default hidden
68 hide();
69}
70
71
73
74
75void
76GNEOverlappedInspection::showOverlappedInspection(GNEViewNetHelper::ViewObjectsSelector& viewObjects, const Position& clickedPosition, const bool shiftKeyPressed) {
77 // check if filter all except junctions
78 if (myOnlyJunctions) {
79 viewObjects.filterAllExcept(GLO_JUNCTION);
80 } else {
81 // filter by supermode
82 viewObjects.filterBySuperMode();
83 // filtger edges if we clicked over a lane
84 if (viewObjects.getAttributeCarrierFront() && viewObjects.getAttributeCarrierFront() == viewObjects.getLaneFront()) {
85 viewObjects.filterEdges();
86 }
87 }
88 // check if previously we clicked an edge and now we want to inspect their lane
89 bool toogleInspectEdgeLane = false;
90 if (!myOnlyJunctions && (myOverlappedACs.size() > 0) && (myOverlappedACs.front()->getTagProperty()->getTag() == SUMO_TAG_EDGE) && shiftKeyPressed) {
91 toogleInspectEdgeLane = true;
92 }
93 // in this point, check if we want to iterate over existent overlapped inspection, or we want to inspet a new set of elements
94 if (!toogleInspectEdgeLane && (myOverlappedACs.size() > 0) && (myClickedPosition != Position::INVALID) && (myClickedPosition.distanceSquaredTo(clickedPosition) < 0.05) && (myShiftKeyPressed == shiftKeyPressed)) {
95 onCmdInspectNextElement(nullptr, 0, nullptr);
96 } else {
98 myItemIndex = 0;
100 }
101 // update clicked position and refresh overlapped inspection
102 myClickedPosition = clickedPosition;
103 myShiftKeyPressed = shiftKeyPressed;
105}
106
107
108void
115
116
117void
121
122void
124 // show modul depending of number of overlapped elements
125 if (myOverlappedACs.size() > 1) {
126 // update text of current index button
127 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
128 // clear and fill list again
129 myOverlappedElementList->clearItems();
130 for (int i = 0; i < (int)myOverlappedACs.size(); i++) {
131 myOverlappedElementList->insertItem(i, myOverlappedACs.at(i)->getID().c_str(), myOverlappedACs.at(i)->getACIcon());
132 }
133 // select current item
134 myOverlappedElementList->getItem(myItemIndex)->setSelected(TRUE);
135 // show modul
136 show();
137 // call selectedOverlappedElement
139 } else {
140 if (myOverlappedACs.size() > 0) {
142 } else {
144 }
145 hide();
146 }
147}
148
149
150bool
152 // show GNEOverlappedInspection modul
153 return shown();
154}
155
156
157int
161
162
165 if (myOverlappedACs.size() > 0) {
166 return myOverlappedACs.at(myItemIndex);
167 } else {
168 return nullptr;
169 }
170}
171
172long
174 // check if there is items
175 if (myOverlappedElementList->getNumItems() > 0) {
176 // set index (it works as a ring)
177 if (myItemIndex > 0) {
178 myItemIndex--;
179 } else {
180 myItemIndex = ((int)myOverlappedACs.size() - 1);
181 }
183 }
184 return 1;
185}
186
187
188long
190 // check if there is items
191 if (myOverlappedElementList->getNumItems() > 0) {
192 // set index (it works as a ring)
193 myItemIndex = (myItemIndex + 1) % myOverlappedACs.size();
195 }
196 return 1;
197}
198
199
200long
201GNEOverlappedInspection::onCmdShowList(FXObject*, FXSelector, void*) {
202 // show or hide element list
203 if (myOverlappedElementList->shown()) {
205 } else {
207 }
208 if (myOverlappedElementList->getNumItems() <= 10) {
209 myOverlappedElementList->setHeight(23 * myOverlappedElementList->getNumItems());
210 } else {
211 myOverlappedElementList->setHeight(230);
212 }
213 myOverlappedElementList->recalc();
214 // recalc and update frame
215 recalc();
216 return 1;
217}
218
219long
221 for (int i = 0; i < myOverlappedElementList->getNumItems(); i++) {
222 if (myOverlappedElementList->getItem(i)->isSelected()) {
223 myItemIndex = i;
225 return 1;
226 }
227 }
228 return 0;
229}
230
231
232long
234 MFXDialogBox* helpDialog = new MFXDialogBox(getCollapsableFrame(), TL("GEO attributes Help"), GUIDesignDialogBox);
235 std::ostringstream help;
236 help
237 << TL(" - Click in the same position") << "\n"
238 << TL(" to inspect next element") << "\n"
239 << TL(" - Shift + Click in the same") << "\n"
240 << TL(" position to inspect") << "\n"
241 << TL(" previous element");
242 new FXLabel(helpDialog, help.str().c_str(), nullptr, GUIDesignLabelFrameInformation);
243 // "OK"
244 GUIDesigns::buildFXButton(helpDialog, TL("OK"), "", TL("close"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), helpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
245 helpDialog->create();
246 helpDialog->show(PLACEMENT_SCREEN);
247 return 1;
248}
249
250
252
253/****************************************************************************/
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:302
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