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-2023 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#include <config.h>
21
22#include <netedit/GNEViewNet.h>
26
28
29
30// ===========================================================================
31// FOX callback mapping
32// ===========================================================================
33
41
42
43// Object implementation
44FXIMPLEMENT(GNEOverlappedInspection, MFXGroupBoxModule, OverlappedInspectionMap, ARRAYNUMBER(OverlappedInspectionMap))
45
46
47// ===========================================================================
48// method definitions
49// ===========================================================================
50
52 MFXGroupBoxModule(frameParent, TL("Overlapped elements")),
53 myFrameParent(frameParent),
54 myFilteredTag(SUMO_TAG_NOTHING),
55 myItemIndex(0) {
56 // build elements
57 buildFXElements();
58}
59
60
62 MFXGroupBoxModule(frameParent, (TL("Overlapped ") + toString(filteredTag) + "s").c_str()),
63 myFrameParent(frameParent),
64 myFilteredTag(filteredTag),
65 myItemIndex(0) {
66 // build elements
68}
69
70
72
73
74void
76 // first clear myOverlappedACs
77 myOverlappedACs.clear();
78 // reserve
79 myOverlappedACs.reserve(objectsUnderCursor.getClickedAttributeCarriers().size());
80 // iterate over objects under cursor
81 for (const auto& AC : objectsUnderCursor.getClickedAttributeCarriers()) {
82 bool insert = true;
83 // check supermode demand
85 !AC->getTagProperty().isDemandElement()) {
86 insert = false;
87 }
88 // check supermode data
90 !AC->getTagProperty().isGenericData()) {
91 insert = false;
92 }
93 // check filter
94 if ((myFilteredTag != SUMO_TAG_NOTHING) && (AC->getTagProperty().getTag() != myFilteredTag)) {
95 insert = false;
96 }
97 if (insert) {
98 myOverlappedACs.push_back(AC);
99 }
100 }
101 // continue depending of number of myOverlappedACs
102 if (myOverlappedACs.size() > 1) {
103 mySavedClickedPosition = clickedPosition;
104 // by default we inspect first element
105 myItemIndex = 0;
106 // update text of current index button
107 myCurrentIndexButton->setText(("1 / " + toString(myOverlappedACs.size())).c_str());
108 // clear and fill list again
109 myOverlappedElementList->clearItems();
110 for (int i = 0; i < (int)myOverlappedACs.size(); i++) {
111 myOverlappedElementList->insertItem(i, myOverlappedACs.at(i)->getID().c_str(), myOverlappedACs.at(i)->getACIcon());
112 }
113 // set first element as selected element
114 myOverlappedElementList->getItem(0)->setSelected(TRUE);
115 // by default list hidden
117 // show GNEOverlappedInspection modul
118 show();
119 } else {
120 // hide GNEOverlappedInspection modul
121 hide();
122 }
123}
124
125
126void
128 // hide GNEOverlappedInspection modul
129 hide();
130}
131
132
133bool
135 // show GNEOverlappedInspection modul
136 return shown();
137}
138
139
140int
144
145
146bool
148 return (mySavedClickedPosition.distanceSquaredTo2D(clickedPosition) < 0.25);
149}
150
151
152bool
154 // first check if GNEOverlappedInspection is shown
155 if (shown()) {
156 // check if given position is near saved position
157 if (checkSavedPosition(clickedPosition)) {
158 // inspect next element
159 onCmdNextElement(0, 0, 0);
160 return true;
161 } else {
162 return false;
163 }
164 } else {
165 return false;
166 }
167}
168
169
170bool
172 // first check if GNEOverlappedInspection is shown
173 if (shown()) {
174 // check if given position is near saved position
175 if (checkSavedPosition(clickedPosition)) {
176 // inspect previousElement
177 onCmdPreviousElement(0, 0, 0);
178 return true;
179 } else {
180 return false;
181 }
182 } else {
183 return false;
184 }
185}
186
187
188long
190 // check if there is items
191 if (myOverlappedElementList->getNumItems() > 0) {
192 // unselect current list element
193 myOverlappedElementList->getItem((int)myItemIndex)->setSelected(FALSE);
194 // set index (it works as a ring)
195 if (myItemIndex > 0) {
196 myItemIndex--;
197 } else {
198 myItemIndex = (myOverlappedACs.size() - 1);
199 }
200 // selected current list element
201 myOverlappedElementList->getItem((int)myItemIndex)->setSelected(TRUE);
202 myOverlappedElementList->update();
203 // update current index button
204 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
205 // inspect overlapped attribute carrier
207 // show GNEOverlappedInspection again (because it's hidden in inspectSingleElement)
208 show();
209 }
210 return 1;
211}
212
213
214long
215GNEOverlappedInspection::onCmdNextElement(FXObject*, FXSelector, void*) {
216 // check if there is items
217 if (myOverlappedElementList->getNumItems() > 0) {
218 // unselect current list element
219 myOverlappedElementList->getItem((int)myItemIndex)->setSelected(FALSE);
220 // set index (it works as a ring)
221 myItemIndex = (myItemIndex + 1) % myOverlappedACs.size();
222 // selected current list element
223 myOverlappedElementList->getItem((int)myItemIndex)->setSelected(TRUE);
224 myOverlappedElementList->update();
225 // update current index button
226 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
227 // inspect overlapped attribute carrier
229 // show GNEOverlappedInspection again (because it's hidden in inspectSingleElement)
230 show();
231 }
232 return 1;
233}
234
235
236long
237GNEOverlappedInspection::onCmdShowList(FXObject*, FXSelector, void*) {
238 // show or hide element list
239 if (myOverlappedElementList->shown()) {
241 } else {
243 }
244 if (myOverlappedElementList->getNumItems() <= 10) {
245 myOverlappedElementList->setHeight(23 * myOverlappedElementList->getNumItems());
246 } else {
247 myOverlappedElementList->setHeight(230);
248 }
249 myOverlappedElementList->recalc();
250 // recalc and update frame
251 recalc();
252 return 1;
253}
254
255long
257 for (int i = 0; i < myOverlappedElementList->getNumItems(); i++) {
258 if (myOverlappedElementList->getItem(i)->isSelected()) {
259 myItemIndex = i;
260 // update current index button
261 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
262 // inspect overlapped attribute carrier
264 // show GNEOverlappedInspection again (because it's hidden in inspectSingleElement)
265 show();
266 return 1;
267 }
268 }
269 return 0;
270}
271
272
273long
275 FXDialogBox* helpDialog = new FXDialogBox(getCollapsableFrame(), TL("GEO attributes Help"), GUIDesignDialogBox);
276 std::ostringstream help;
277 help
278 << TL(" - Click in the same position") << "\n"
279 << TL(" for inspect next element") << "\n"
280 << TL(" - Shift + Click in the same") << "\n"
281 << TL(" position for inspect") << "\n"
282 << TL(" previous element");
283 new FXLabel(helpDialog, help.str().c_str(), nullptr, GUIDesignLabelFrameInformation);
284 // "OK"
285 new FXButton(helpDialog, (TL("OK") + std::string("\t\t") + TL("close")).c_str(), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), helpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
286 helpDialog->create();
287 helpDialog->show();
288 return 1;
289}
290
291
293 myFrameParent(nullptr),
294 myPreviousElement(nullptr),
295 myCurrentIndexButton(nullptr),
296 myNextElement(nullptr),
297 myOverlappedElementList(nullptr),
298 myHelpButton(nullptr),
299 myFilteredTag(SUMO_TAG_NOTHING),
300 myItemIndex(0) {
301}
302
303
304void
306 FXHorizontalFrame* frameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
307 // Create previous Item Button
309 // create current index button
310 myCurrentIndexButton = new FXButton(frameButtons, "", nullptr, this, MID_GNE_OVERLAPPED_SHOWLIST, GUIDesignButton);
311 // Create next Item Button
313 // Create list of overlapped elements (by default hidden)
315 // by default list of overlapped elements is hidden)
317 // Create help button
318 myHelpButton = new FXButton(getCollapsableFrame(), TL("Help"), nullptr, this, MID_HELP, GUIDesignButtonRectangular);
319}
320
321/****************************************************************************/
FXDEFMAP(GNEOverlappedInspection) OverlappedInspectionMap[]
@ MID_GNE_OVERLAPPED_PREVIOUS
inspect previous element in overlapped module
Definition GUIAppEnum.h:983
@ MID_GNE_OVERLAPPED_ITEMSELECTED
list item selected in overlapped module
Definition GUIAppEnum.h:987
@ MID_HELP
help button
Definition GUIAppEnum.h:645
@ MID_GNE_OVERLAPPED_SHOWLIST
show list of overlapped elements
Definition GUIAppEnum.h:985
@ MID_GNE_OVERLAPPED_NEXT
inspect next element in overlapped module
Definition GUIAppEnum.h:981
#define GUIDesignButton
Definition GUIDesigns.h:74
#define GUIDesignListFixedHeight
design for FXLists with height fixed
Definition GUIDesigns.h:678
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:394
#define GUIDesignDialogBox
Definition GUIDesigns.h:588
#define GUIDesignButtonRectangular
little rectangular button used in frames (For example, in "help" buttons)
Definition GUIDesigns.h:80
#define GUIDesignButtonIconRectangular
button only with icon
Definition GUIDesigns.h:86
#define GUIDesignButtonOK
Definition GUIDesigns.h:148
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:274
@ BIGARROWLEFT
@ BIGARROWRIGHT
#define TL(string)
Definition MsgHandler.h:287
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_NOTHING
invalid tag
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
virtual void selectedOverlappedElement(GNEAttributeCarrier *AC)
open GNEAttributesCreator extended dialog
Definition GNEFrame.cpp:298
long onCmdNextElement(FXObject *, FXSelector, void *)
Inspect next Element (from top to bot)
long onCmdPreviousElement(FXObject *, FXSelector, void *)
Inspect previous element (from top to bot)
FXButton * myCurrentIndexButton
Button for current index.
FXButton * myPreviousElement
Previous element button.
Position mySavedClickedPosition
saved clicked position
std::vector< GNEAttributeCarrier * > myOverlappedACs
objects under cursor
long onCmdShowList(FXObject *, FXSelector, void *)
show list of overlapped elements
long onCmdOverlappingHelp(FXObject *, FXSelector, void *)
Called when user press the help button.
void hideOverlappedInspection()
hide template editor
bool overlappedInspectionShown() const
check if overlappedInspection modul is shown
long onCmdListItemSelected(FXObject *, FXSelector, void *)
called when a list item is selected
GNEFrame * myFrameParent
current frame parent
void buildFXElements()
build Fox Toolkit elemements
FXButton * myHelpButton
button for help
const SumoXMLTag myFilteredTag
filtered tag
FXButton * myNextElement
Next element button.
bool checkSavedPosition(const Position &clickedPosition) const
check if given position is near to saved position
size_t myItemIndex
current index item
FXList * myOverlappedElementList
list of overlapped elements
int getNumberOfOverlappedACs() const
get number of overlapped ACSs
bool nextElement(const Position &clickedPosition)
try to go to next element if clicked position is near to saved position
bool previousElement(const Position &clickedPosition)
try to go to previous element if clicked position is near to saved position
void showOverlappedInspection(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const Position &clickedPosition)
show template editor
class used to group all variables related with objects under cursor after a click over view
const std::vector< GNEAttributeCarrier * > & getClickedAttributeCarriers() const
get vector with clicked ACs
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
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
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
Definition Position.h:259
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand
bool isCurrentSupermodeData() const
@check if current supermode is Data