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>
30
32
33// ===========================================================================
34// FOX callback mapping
35// ===========================================================================
36
44
45// Object implementation
46FXIMPLEMENT(GNEOverlappedInspection, MFXGroupBoxModule, OverlappedInspectionMap, ARRAYNUMBER(OverlappedInspectionMap))
47
48// ===========================================================================
49// method definitions
50// ===========================================================================
51
52GNEOverlappedInspection::GNEOverlappedInspection(GNEFrame* frameParent, const bool onlyJunctions) :
53 MFXGroupBoxModule(frameParent, onlyJunctions ? TL("Overlapped junctions") : TL("Overlapped elements")),
54 myFrameParent(frameParent),
55 myOnlyJunctions(onlyJunctions) {
56 FXHorizontalFrame* frameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
57 // Create previous Item Button
59 // create current index button
60 myCurrentIndexButton = GUIDesigns::buildFXButton(frameButtons, "", "", "", nullptr, this, MID_GNE_OVERLAPPED_SHOWLIST, GUIDesignButton);
61 // Create next Item Button
63 // Create list of overlapped elements (by default hidden)
64 myOverlappedElementList = new FXList(getCollapsableFrame(), this, MID_GNE_OVERLAPPED_ITEMSELECTED, GUIDesignListFixedHeight);
65 // by default list of overlapped elements is hidden)
66 myOverlappedElementList->hide();
67 // Create help button
68 myHelpButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Help"), "", "", nullptr, this, MID_HELP, GUIDesignButtonRectangular);
69 // by default hidden
70 hide();
71}
72
73
75
76
77void
78GNEOverlappedInspection::showOverlappedInspection(GNEViewNetHelper::ViewObjectsSelector& viewObjects, const Position& clickedPosition, const bool shiftKeyPressed) {
79 // check if filter all except junctions
80 if (myOnlyJunctions) {
81 viewObjects.filterAllExcept(GLO_JUNCTION);
82 } else {
83 // filter by supermode
84 viewObjects.filterBySuperMode();
85 // filtger edges if we clicked over a lane
86 if (viewObjects.getAttributeCarrierFront() && viewObjects.getAttributeCarrierFront() == viewObjects.getLaneFront()) {
87 viewObjects.filterEdges();
88 }
89 }
90 // check if previously we clicked an edge and now we want to inspect their lane
91 bool toogleInspectEdgeLane = false;
92 if (!myOnlyJunctions && (myOverlappedACs.size() > 0) && (myOverlappedACs.front()->getTagProperty()->getTag() == SUMO_TAG_EDGE) && shiftKeyPressed) {
93 toogleInspectEdgeLane = true;
94 }
95 // in this point, check if we want to iterate over existent overlapped inspection, or we want to inspet a new set of elements
96 if (!toogleInspectEdgeLane && (myOverlappedACs.size() > 0) && (myClickedPosition != Position::INVALID) && (myClickedPosition.distanceSquaredTo(clickedPosition) < 0.05) && (myShiftKeyPressed == shiftKeyPressed)) {
97 onCmdInspectNextElement(nullptr, 0, nullptr);
98 } else {
100 myItemIndex = 0;
102 }
103 // update clicked position and refresh overlapped inspection
104 myClickedPosition = clickedPosition;
105 myShiftKeyPressed = shiftKeyPressed;
107}
108
109
110void
117
118
119void
123
124void
126 // show modul depending of number of overlapped elements
127 if (myOverlappedACs.size() > 1) {
128 // update text of current index button
129 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
130 // clear and fill list again
131 myOverlappedElementList->clearItems();
132 for (int i = 0; i < (int)myOverlappedACs.size(); i++) {
133 myOverlappedElementList->insertItem(i, myOverlappedACs.at(i)->getID().c_str(), myOverlappedACs.at(i)->getACIcon());
134 }
135 // select current item
136 myOverlappedElementList->getItem(myItemIndex)->setSelected(TRUE);
137 // show modul
138 show();
139 // call selectedOverlappedElement
141 } else {
142 if (myOverlappedACs.size() > 0) {
144 } else {
146 }
147 hide();
148 }
149}
150
151
152bool
154 // show GNEOverlappedInspection modul
155 return shown();
156}
157
158
159int
163
164
167 if (myOverlappedACs.size() > 0) {
168 return myOverlappedACs.at(myItemIndex);
169 } else {
170 return nullptr;
171 }
172}
173
174long
176 // check if there is items
177 if (myOverlappedElementList->getNumItems() > 0) {
178 // set index (it works as a ring)
179 if (myItemIndex > 0) {
180 myItemIndex--;
181 } else {
182 myItemIndex = ((int)myOverlappedACs.size() - 1);
183 }
185 }
186 return 1;
187}
188
189
190long
192 // check if there is items
193 if (myOverlappedElementList->getNumItems() > 0) {
194 // set index (it works as a ring)
195 myItemIndex = (myItemIndex + 1) % myOverlappedACs.size();
197 }
198 return 1;
199}
200
201
202long
203GNEOverlappedInspection::onCmdShowList(FXObject*, FXSelector, void*) {
204 // show or hide element list
205 if (myOverlappedElementList->shown()) {
207 } else {
209 }
210 if (myOverlappedElementList->getNumItems() <= 10) {
211 myOverlappedElementList->setHeight(23 * myOverlappedElementList->getNumItems());
212 } else {
213 myOverlappedElementList->setHeight(230);
214 }
215 myOverlappedElementList->recalc();
216 // recalc and update frame
217 recalc();
218 return 1;
219}
220
221long
223 for (int i = 0; i < myOverlappedElementList->getNumItems(); i++) {
224 if (myOverlappedElementList->getItem(i)->isSelected()) {
225 myItemIndex = i;
227 return 1;
228 }
229 }
230 return 0;
231}
232
233
234long
236 // create text for help dialog
237 std::ostringstream help;
238 help
239 << TL(" - Click in the same position") << "\n"
240 << TL(" to inspect next element") << "\n"
241 << TL(" - Shift + Click in the same") << "\n"
242 << TL(" position to inspect") << "\n"
243 << TL(" previous element");
244 // create help dialog
246 TL("GEO attributes Help"), help);
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:655
@ MID_GNE_OVERLAPPED_SHOWLIST
show list of overlapped elements
@ MID_GNE_OVERLAPPED_NEXT
inspect next element in overlapped module
#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 GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:430
#define GUIDesignButtonRectangular
little rectangular button used in frames (For example, in "help" buttons)
Definition GUIDesigns.h:112
@ GLO_JUNCTION
a junction
@ BIGARROWLEFT
@ BIGARROWRIGHT
#define TL(string)
Definition MsgHandler.h:304
@ 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
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:152
virtual void selectedOverlappedElement(GNEAttributeCarrier *AC)
open GNEAttributesCreator extended dialog
Definition GNEFrame.cpp:233
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
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
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)
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:323
double distanceSquaredTo(const Position &p2) const
returns the square of the distance to another position
Definition Position.h:268