Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUICursorDialog.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// Dialog for edit element under cursor
19/****************************************************************************/
20#include <config.h>
21
26
27#include <netedit/GNEUndoList.h>
28
29#include "GUICursorDialog.h"
30
31
32#define NUM_VISIBLE_ITEMS 10
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
48
49// Object implementation
50FXIMPLEMENT(GUICursorDialog, GUIGLObjectPopupMenu, GUICursorDialogMap, ARRAYNUMBER(GUICursorDialogMap))
51
52// ===========================================================================
53// member method definitions
54// ===========================================================================
55
57 GUIGLObjectPopupMenu(view->getMainWindow(), view, type),
58 myType(type),
59 myView(view) {
60 // continue depending of properties
62 buildDialogElements(view, TL("Overlapped objects"), GUIIcon::MODEINSPECT, MID_CURSORDIALOG_PROPERTIES, objects);
64 buildDialogElements(view, TL("Delete element"), GUIIcon::MODEDELETE, MID_CURSORDIALOG_DELETEELEMENT, objects);
66 buildDialogElements(view, TL("Select element"), GUIIcon::MODESELECT, MID_CURSORDIALOG_SELECTELEMENT, objects);
68 buildDialogElements(view, TL("Mark front element"), GUIIcon::FRONTELEMENT, MID_CURSORDIALOG_SETFRONTELEMENT, objects);
69 }
70}
71
72
74 // delete all menu commands
75 for (const auto& GLObject : myMenuCommandGLObjects) {
76 delete GLObject.first;
77 }
78}
79
80
81long
82GUICursorDialog::onCmdSetFrontElement(FXObject* obj, FXSelector, void*) {
83 // search element in myGLObjects
84 for (const auto& GLObject : myMenuCommandGLObjects) {
85 if (GLObject.first == obj) {
86 GLObject.second->markAsFrontElement();
87 }
88 }
89 // destroy popup
91 return 1;
92}
93
94
95long
96GUICursorDialog::onCmdDeleteElement(FXObject* obj, FXSelector, void*) {
97 // search element in myGLObjects
98 for (const auto& GLObject : myMenuCommandGLObjects) {
99 if (GLObject.first == obj) {
100 GLObject.second->deleteGLObject();
101 }
102 }
103 // destroy popup
105 return 1;
106}
107
108
109long
110GUICursorDialog::onCmdSelectElement(FXObject* obj, FXSelector, void*) {
111 // search element in myGLObjects
112 for (const auto& GLObject : myMenuCommandGLObjects) {
113 if (GLObject.first == obj) {
114 GLObject.second->selectGLObject();
115 }
116 }
117 // destroy popup
119 return 1;
120}
121
122
123long
124GUICursorDialog::onCmdOpenPropertiesPopUp(FXObject* obj, FXSelector, void*) {
125 // search element in myGLObjects
126 for (const auto& GLObject : myMenuCommandGLObjects) {
127 if (GLObject.first == obj) {
128 myView->replacePopup(GLObject.second->getPopUpMenu(*myView->getMainWindow(), *myView));
129 return 1;
130 }
131 }
132 return 0;
133}
134
135
136long
137GUICursorDialog::onCmdMoveListUp(FXObject*, FXSelector, void*) {
139 updateList();
140 show();
141 return 0;
142}
143
144
145long
146GUICursorDialog::onCmdMoveListDown(FXObject*, FXSelector, void*) {
148 updateList();
149 show();
150 return 0;
151}
152
153
154long
155GUICursorDialog::onCmdProcessFront(FXObject*, FXSelector, void*) {
156 if (myMenuCommandGLObjects.size() > 0) {
157 // continue depending of properties
159 myMenuCommandGLObjects.front().second->deleteGLObject();
161 myMenuCommandGLObjects.front().second->selectGLObject();
163 myMenuCommandGLObjects.front().second->markAsFrontElement();
164 }
165 }
166 return 0;
167}
168
169
170long
171GUICursorDialog::onCmdUnpost(FXObject* obj, FXSelector, void* ptr) {
172 // ignore move up, down and header
173 if ((obj == myMoveUpMenuCommand) || (obj == myMoveDownMenuCommand) || (obj == myMenuHeader)) {
174 return 1;
175 }
176 if (grabowner) {
177 grabowner->handle(this, FXSEL(SEL_COMMAND, ID_UNPOST), ptr);
178 } else {
179 popdown();
180 if (grabbed()) {
181 ungrab();
182 }
183 }
184 return 1;
185}
186
187
188void
190 // first hide all menu commands
191 for (const auto& GLObject : myMenuCommandGLObjects) {
192 GLObject.first->hide();
193 }
194 // check if disable menu command up
195 if (myListIndex == 0) {
196 myMoveUpMenuCommand->disable();
197 } else {
198 myMoveUpMenuCommand->enable();
199 }
200 // show menu commands depending of myListIndex
202 for (int i = (int)myMenuCommandGLObjects.size() - NUM_VISIBLE_ITEMS; i < (int)myMenuCommandGLObjects.size(); i++) {
203 myMenuCommandGLObjects.at(i).first->show();
204 }
205 myMoveDownMenuCommand->disable();
206 } else {
207 for (int i = myListIndex; i < (myListIndex + NUM_VISIBLE_ITEMS); i++) {
208 myMenuCommandGLObjects.at(i).first->show();
209 }
210 myMoveDownMenuCommand->enable();
211 }
212 // recalc popup
213 recalc();
214}
215
216
217void
218GUICursorDialog::buildDialogElements(GUISUMOAbstractView* view, const FXString text, GUIIcon icon, FXSelector sel, const std::vector<GUIGlObject*>& objects) {
219 // create header
220 myMenuHeader = new MFXMenuHeader(this, view->getMainWindow()->getBoldFont(), text, GUIIconSubSys::getIcon(icon), nullptr, 0);
221 new FXMenuSeparator(this);
222 // check if create move up menu command
223 if (objects.size() > NUM_VISIBLE_ITEMS) {
225 new FXMenuSeparator(this);
226 }
227 // create a menu command for every object
228 for (const auto& GLObject : objects) {
229 myMenuCommandGLObjects.push_back(std::make_pair(GUIDesigns::buildFXMenuCommand(this, GLObject->getMicrosimID(), GLObject->getGLIcon(), this, sel), GLObject));
230 }
231 // check if create move down menu command
232 if (objects.size() > NUM_VISIBLE_ITEMS) {
233 new FXMenuSeparator(this);
235 updateList();
236 }
237}
238
239/****************************************************************************/
@ MID_CURSORDIALOG_SETFRONTELEMENT
Definition GUIAppEnum.h:430
@ MID_CURSORDIALOG_MOVEDOWN
move list down
Definition GUIAppEnum.h:440
@ MID_CURSORDIALOG_PROPERTIES
open properties popup
Definition GUIAppEnum.h:436
@ MID_CURSORDIALOG_FRONT
remove/select/mark front element
Definition GUIAppEnum.h:442
@ MID_CURSORDIALOG_MOVEUP
move list up
Definition GUIAppEnum.h:438
@ MID_CURSORDIALOG_DELETEELEMENT
delete element
Definition GUIAppEnum.h:432
@ MID_CURSORDIALOG_SELECTELEMENT
select element
Definition GUIAppEnum.h:434
FXDEFMAP(GUICursorDialog) GUICursorDialogMap[]
#define NUM_VISIBLE_ITEMS
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ FRONTELEMENT
#define TL(string)
Definition MsgHandler.h:315
Dialog for edit rerouter intervals.
void updateList()
update list
long onCmdMoveListDown(FXObject *, FXSelector, void *)
move list down
FXMenuCommand * myMoveUpMenuCommand
menu command for move up list
~GUICursorDialog()
destructor
long onCmdMoveListUp(FXObject *, FXSelector, void *)
move list up
long onCmdSelectElement(FXObject *, FXSelector, void *)
select element
long onCmdProcessFront(FXObject *, FXSelector, void *)
move list down
long onCmdUnpost(FXObject *, FXSelector, void *ptr)
unpost
std::vector< std::pair< FXMenuCommand *, GUIGlObject * > > myMenuCommandGLObjects
container for menu commands and GLObjects
int myListIndex
list index
long onCmdDeleteElement(FXObject *, FXSelector, void *)
delete element
GUIGLObjectPopupMenu::PopupType myType
FOX need this.
GUISUMOAbstractView * myView
pointer to view
void buildDialogElements(GUISUMOAbstractView *view, const FXString text, GUIIcon icon, FXSelector sel, const std::vector< GUIGlObject * > &objects)
build dialog elements
FXMenuCommand * myMoveDownMenuCommand
menu command for move down list
MFXMenuHeader * myMenuHeader
header
long onCmdOpenPropertiesPopUp(FXObject *, FXSelector, void *)
open properties popUp
long onCmdSetFrontElement(FXObject *, FXSelector, void *)
set front element
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel, const bool disable=false)
build menu command
The popup menu of a globject.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
FXFont * getBoldFont()
get bold front
void replacePopup(GUIGLObjectPopupMenu *popUp)
replace PopUp
GUIMainWindow * getMainWindow() const
get main window
void destroyPopup()
destroys the popup
Definition json.hpp:4471