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-2024 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 // get cliked ACs
79 auto clickedACs = viewObjects.getAttributeCarriers();
80 // check if filter edges
81 if ((clickedACs.size() > 0) && (clickedACs.front()->getTagProperty().getTag() == SUMO_TAG_LANE)) {
82 // iterate over clickedAcs and remove edges
83 auto it = clickedACs.begin();
84 while (it != clickedACs.end()) {
85 if ((*it)->getTagProperty().getTag() == SUMO_TAG_EDGE) {
86 it = clickedACs.erase(it);
87 } else {
88 it++;
89 }
90 }
91 }
92 // reserve
93 myOverlappedACs.reserve(clickedACs.size());
94 // iterate over objects under cursor
95 for (const auto& AC : clickedACs) {
96 bool insert = true;
97 // check supermode demand
99 !AC->getTagProperty().isDemandElement()) {
100 insert = false;
101 }
102 // check supermode data
104 !AC->getTagProperty().isGenericData()) {
105 insert = false;
106 }
107 // check filter
108 if ((myFilteredTag != SUMO_TAG_NOTHING) && (AC->getTagProperty().getTag() != myFilteredTag)) {
109 insert = false;
110 }
111 if (insert) {
112 myOverlappedACs.push_back(AC);
113 }
114 }
115 // continue depending of number of myOverlappedACs
116 if (myOverlappedACs.size() > 1) {
117 mySavedClickedPosition = clickedPosition;
118 // by default we inspect first element
119 myItemIndex = 0;
120 // update text of current index button
121 myCurrentIndexButton->setText(("1 / " + toString(myOverlappedACs.size())).c_str());
122 // clear and fill list again
123 myOverlappedElementList->clearItems();
124 for (int i = 0; i < (int)myOverlappedACs.size(); i++) {
125 myOverlappedElementList->insertItem(i, myOverlappedACs.at(i)->getID().c_str(), myOverlappedACs.at(i)->getACIcon());
126 }
127 // set first element as selected element
128 myOverlappedElementList->getItem(0)->setSelected(TRUE);
129 // by default list hidden
131 // show GNEOverlappedInspection modul
132 show();
133 } else {
134 // hide GNEOverlappedInspection modul
135 hide();
136 }
137}
138
139
140void
142 // hide GNEOverlappedInspection modul
143 hide();
144}
145
146
147bool
149 // show GNEOverlappedInspection modul
150 return shown();
151}
152
153
154int
158
159
160bool
162 return (mySavedClickedPosition.distanceSquaredTo2D(clickedPosition) < 0.25);
163}
164
165
166bool
168 // first check if GNEOverlappedInspection is shown
169 if (shown()) {
170 // check if given position is near saved position
171 if (checkSavedPosition(clickedPosition)) {
172 // inspect next element
173 onCmdNextElement(0, 0, 0);
174 return true;
175 } else {
176 return false;
177 }
178 } else {
179 return false;
180 }
181}
182
183
184bool
186 // first check if GNEOverlappedInspection is shown
187 if (shown()) {
188 // check if given position is near saved position
189 if (checkSavedPosition(clickedPosition)) {
190 // inspect previousElement
191 onCmdPreviousElement(0, 0, 0);
192 return true;
193 } else {
194 return false;
195 }
196 } else {
197 return false;
198 }
199}
200
201
202long
204 // check if there is items
205 if (myOverlappedElementList->getNumItems() > 0) {
206 // unselect current list element
207 myOverlappedElementList->getItem((int)myItemIndex)->setSelected(FALSE);
208 // set index (it works as a ring)
209 if (myItemIndex > 0) {
210 myItemIndex--;
211 } else {
212 myItemIndex = (myOverlappedACs.size() - 1);
213 }
214 // selected current list element
215 myOverlappedElementList->getItem((int)myItemIndex)->setSelected(TRUE);
216 myOverlappedElementList->update();
217 // update current index button
218 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
219 // inspect overlapped attribute carrier
221 // show GNEOverlappedInspection again (because it's hidden in inspectSingleElement)
222 show();
223 }
224 return 1;
225}
226
227
228long
229GNEOverlappedInspection::onCmdNextElement(FXObject*, FXSelector, void*) {
230 // check if there is items
231 if (myOverlappedElementList->getNumItems() > 0) {
232 // unselect current list element
233 myOverlappedElementList->getItem((int)myItemIndex)->setSelected(FALSE);
234 // set index (it works as a ring)
235 myItemIndex = (myItemIndex + 1) % myOverlappedACs.size();
236 // selected current list element
237 myOverlappedElementList->getItem((int)myItemIndex)->setSelected(TRUE);
238 myOverlappedElementList->update();
239 // update current index button
240 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
241 // inspect overlapped attribute carrier
243 // show GNEOverlappedInspection again (because it's hidden in inspectSingleElement)
244 show();
245 }
246 return 1;
247}
248
249
250long
251GNEOverlappedInspection::onCmdShowList(FXObject*, FXSelector, void*) {
252 // show or hide element list
253 if (myOverlappedElementList->shown()) {
255 } else {
257 }
258 if (myOverlappedElementList->getNumItems() <= 10) {
259 myOverlappedElementList->setHeight(23 * myOverlappedElementList->getNumItems());
260 } else {
261 myOverlappedElementList->setHeight(230);
262 }
263 myOverlappedElementList->recalc();
264 // recalc and update frame
265 recalc();
266 return 1;
267}
268
269long
271 for (int i = 0; i < myOverlappedElementList->getNumItems(); i++) {
272 if (myOverlappedElementList->getItem(i)->isSelected()) {
273 myItemIndex = i;
274 // update current index button
275 myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());
276 // inspect overlapped attribute carrier
278 // show GNEOverlappedInspection again (because it's hidden in inspectSingleElement)
279 show();
280 return 1;
281 }
282 }
283 return 0;
284}
285
286
287long
289 FXDialogBox* helpDialog = new FXDialogBox(getCollapsableFrame(), TL("GEO attributes Help"), GUIDesignDialogBox);
290 std::ostringstream help;
291 help
292 << TL(" - Click in the same position") << "\n"
293 << TL(" for inspect next element") << "\n"
294 << TL(" - Shift + Click in the same") << "\n"
295 << TL(" position for inspect") << "\n"
296 << TL(" previous element");
297 new FXLabel(helpDialog, help.str().c_str(), nullptr, GUIDesignLabelFrameInformation);
298 // "OK"
299 GUIDesigns::buildFXButton(helpDialog, TL("OK"), "", TL("close"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), helpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
300 helpDialog->create();
301 helpDialog->show();
302 return 1;
303}
304
305
307 myFrameParent(nullptr),
308 myPreviousElement(nullptr),
309 myCurrentIndexButton(nullptr),
310 myNextElement(nullptr),
311 myOverlappedElementList(nullptr),
312 myHelpButton(nullptr),
313 myFilteredTag(SUMO_TAG_NOTHING),
314 myItemIndex(0) {
315}
316
317
318void
320 FXHorizontalFrame* frameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
321 // Create previous Item Button
323 // create current index button
325 // Create next Item Button
327 // Create list of overlapped elements (by default hidden)
329 // by default list of overlapped elements is hidden)
331 // Create help button
333}
334
335/****************************************************************************/
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:88
#define GUIDesignListFixedHeight
design for FXLists with height fixed
Definition GUIDesigns.h:692
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:405
#define GUIDesignDialogBox
Definition GUIDesigns.h:602
#define GUIDesignButtonRectangular
little rectangular button used in frames (For example, in "help" buttons)
Definition GUIDesigns.h:100
#define GUIDesignButtonOK
Definition GUIDesigns.h:159
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:285
@ BIGARROWLEFT
@ BIGARROWRIGHT
#define TL(string)
Definition MsgHandler.h:315
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ 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: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
void showOverlappedInspection(const GNEViewNetHelper::ViewObjectsSelector &viewObjects, const Position &clickedPosition)
show template editor
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
class used to group all variables related with objects under cursor after a click over view
const std::vector< GNEAttributeCarrier * > & getAttributeCarriers() const
get vector with ACs
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
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
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
Definition Position.h:281
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand
bool isCurrentSupermodeData() const
@check if current supermode is Data