Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/GNEOverlappedInspection.cpp
169678 views
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
/****************************************************************************/
14
/// @file GNEOverlappedInspection.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Mar 2022
17
///
18
// Frame for overlapped elements
19
/****************************************************************************/
20
21
#include <netedit/GNEViewNet.h>
22
#include <netedit/GNEViewParent.h>
23
#include <netedit/GNEApplicationWindow.h>
24
#include <netedit/GNETagProperties.h>
25
#include <netedit/dialogs/basic/GNEHelpBasicDialog.h>
26
#include <netedit/elements/network/GNELane.h>
27
#include <netedit/frames/common/GNEInspectorFrame.h>
28
#include <utils/gui/div/GUIDesigns.h>
29
#include <utils/gui/windows/GUIAppEnum.h>
30
31
#include "GNEOverlappedInspection.h"
32
33
// ===========================================================================
34
// FOX callback mapping
35
// ===========================================================================
36
37
FXDEFMAP(GNEOverlappedInspection) OverlappedInspectionMap[] = {
38
FXMAPFUNC(SEL_COMMAND, MID_GNE_OVERLAPPED_NEXT, GNEOverlappedInspection::onCmdInspectNextElement),
39
FXMAPFUNC(SEL_COMMAND, MID_GNE_OVERLAPPED_PREVIOUS, GNEOverlappedInspection::onCmdInspectPreviousElement),
40
FXMAPFUNC(SEL_COMMAND, MID_GNE_OVERLAPPED_SHOWLIST, GNEOverlappedInspection::onCmdShowList),
41
FXMAPFUNC(SEL_COMMAND, MID_GNE_OVERLAPPED_ITEMSELECTED, GNEOverlappedInspection::onCmdListItemSelected),
42
FXMAPFUNC(SEL_COMMAND, MID_HELP, GNEOverlappedInspection::onCmdOverlappingHelp)
43
};
44
45
// Object implementation
46
FXIMPLEMENT(GNEOverlappedInspection, MFXGroupBoxModule, OverlappedInspectionMap, ARRAYNUMBER(OverlappedInspectionMap))
47
48
// ===========================================================================
49
// method definitions
50
// ===========================================================================
51
52
GNEOverlappedInspection::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
58
myPreviousElement = GUIDesigns::buildFXButton(frameButtons, "", "", "", GUIIconSubSys::getIcon(GUIIcon::BIGARROWLEFT), this, MID_GNE_OVERLAPPED_PREVIOUS, GUIDesignButtonRectangular);
59
// create current index button
60
myCurrentIndexButton = GUIDesigns::buildFXButton(frameButtons, "", "", "", nullptr, this, MID_GNE_OVERLAPPED_SHOWLIST, GUIDesignButton);
61
// Create next Item Button
62
myNextElement = GUIDesigns::buildFXButton(frameButtons, "", "", "", GUIIconSubSys::getIcon(GUIIcon::BIGARROWRIGHT), this, MID_GNE_OVERLAPPED_NEXT, GUIDesignButtonRectangular);
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
74
GNEOverlappedInspection::~GNEOverlappedInspection() {}
75
76
77
void
78
GNEOverlappedInspection::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 {
99
myOverlappedACs = viewObjects.getAttributeCarriers();
100
myItemIndex = 0;
101
myOverlappedElementList->hide();
102
}
103
// update clicked position and refresh overlapped inspection
104
myClickedPosition = clickedPosition;
105
myShiftKeyPressed = shiftKeyPressed;
106
refreshOverlappedInspection();
107
}
108
109
110
void
111
GNEOverlappedInspection::clearOverlappedInspection() {
112
myOverlappedACs.clear();
113
myItemIndex = 0;
114
myOverlappedElementList->hide();
115
refreshOverlappedInspection();
116
}
117
118
119
void
120
GNEOverlappedInspection::hiderOverlappedInspection() {
121
hide();
122
}
123
124
void
125
GNEOverlappedInspection::refreshOverlappedInspection() {
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
140
myFrameParent->selectedOverlappedElement(myOverlappedACs.at(myItemIndex));
141
} else {
142
if (myOverlappedACs.size() > 0) {
143
myFrameParent->selectedOverlappedElement(myOverlappedACs.front());
144
} else {
145
myFrameParent->selectedOverlappedElement(nullptr);
146
}
147
hide();
148
}
149
}
150
151
152
bool
153
GNEOverlappedInspection::overlappedInspectionShown() const {
154
// show GNEOverlappedInspection modul
155
return shown();
156
}
157
158
159
int
160
GNEOverlappedInspection::getNumberOfOverlappedACs() const {
161
return (int)myOverlappedACs.size();
162
}
163
164
165
GNEAttributeCarrier*
166
GNEOverlappedInspection::getCurrentAC() const {
167
if (myOverlappedACs.size() > 0) {
168
return myOverlappedACs.at(myItemIndex);
169
} else {
170
return nullptr;
171
}
172
}
173
174
long
175
GNEOverlappedInspection::onCmdInspectPreviousElement(FXObject*, FXSelector, void*) {
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
}
184
refreshOverlappedInspection();
185
}
186
return 1;
187
}
188
189
190
long
191
GNEOverlappedInspection::onCmdInspectNextElement(FXObject*, FXSelector, void*) {
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();
196
refreshOverlappedInspection();
197
}
198
return 1;
199
}
200
201
202
long
203
GNEOverlappedInspection::onCmdShowList(FXObject*, FXSelector, void*) {
204
// show or hide element list
205
if (myOverlappedElementList->shown()) {
206
myOverlappedElementList->hide();
207
} else {
208
myOverlappedElementList->show();
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
221
long
222
GNEOverlappedInspection::onCmdListItemSelected(FXObject*, FXSelector, void*) {
223
for (int i = 0; i < myOverlappedElementList->getNumItems(); i++) {
224
if (myOverlappedElementList->getItem(i)->isSelected()) {
225
myItemIndex = i;
226
refreshOverlappedInspection();
227
return 1;
228
}
229
}
230
return 0;
231
}
232
233
234
long
235
GNEOverlappedInspection::onCmdOverlappingHelp(FXObject*, FXSelector, void*) {
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
245
GNEHelpBasicDialog(myFrameParent->getViewNet()->getViewParent()->getGNEAppWindows(),
246
TL("GEO attributes Help"), help);
247
return 1;
248
}
249
250
251
GNEOverlappedInspection::GNEOverlappedInspection() {}
252
253
/****************************************************************************/
254
255