Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIGLObjectPopupMenu.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/****************************************************************************/
20// The popup menu of a globject
21/****************************************************************************/
22#include <config.h>
23
24#include <iostream>
25#include <cassert>
39
40// ===========================================================================
41// FOX callback mapping
42// ===========================================================================
58
59// Object implementation
60FXIMPLEMENT(GUIGLObjectPopupMenu, FXMenuPane, GUIGLObjectPopupMenuMap, ARRAYNUMBER(GUIGLObjectPopupMenuMap))
61
62
63// ===========================================================================
64// method definitions
65// ===========================================================================
66
68 FXMenuPane(&parent),
69 myParent(&parent),
70 myObject(o),
71 myApplication(&app),
72 myPopupType(PopupType::ATTRIBUTES),
73 myNetworkPosition(parent.getPositionInformation()),
74 myTestCoordinates((toString(parent.getWindowCursorPosition().x() - 24.0) + " " + toString(parent.getWindowCursorPosition().y() - 25.0))) {
75}
76
77
79 FXMenuPane(parent),
80 myParent(parent),
81 myObject(nullptr),
82 myApplication(app),
83 myPopupType(popupType),
84 myNetworkPosition(parent->getPositionInformation()) {
85}
86
87
89 // Delete MenuPane children
90 for (const auto& pane : myMenuPanes) {
91 delete pane;
92 }
93}
94
95
96void
98 // Check that MenuPaneChild isn't NULL
99 if (child == nullptr) {
100 throw ProcessError("MenuPaneChild cannot be NULL");
101 }
102 // Check that MenuPaneChild wasn't already inserted
103 for (const auto& pane : myMenuPanes) {
104 if (pane == child) {
105 throw ProcessError("MenuPaneChild already inserted");
106 }
107 }
108 // Insert MenuPaneChild
109 myMenuPanes.push_back(child);
110}
111
112
113void
115 // remove popup menu from object
116 if (myObject) {
117 myObject->removedPopupMenu();
118 }
119}
120
125
126
131
132
137
138
139long
140GUIGLObjectPopupMenu::onCmdCenter(FXObject*, FXSelector, void*) {
141 // we already know where the object is since we clicked on it -> zoom on Boundary
142 if (myObject) {
143 myParent->centerTo(myObject->getGlID(), true, -1);
144 } else {
145 throw ProcessError("Object is NULL");
146 }
147 return 1;
148}
149
150
151long
152GUIGLObjectPopupMenu::onCmdCopyName(FXObject*, FXSelector, void*) {
153 if (myObject) {
154 GUIUserIO::copyToClipboard(*myParent->getApp(), myObject->getMicrosimID());
155 } else {
156 throw ProcessError("Object is NULL");
157 }
158 return 1;
159}
160
161
162long
163GUIGLObjectPopupMenu::onCmdCopyTypedName(FXObject*, FXSelector, void*) {
164 if (myObject) {
165 GUIUserIO::copyToClipboard(*myParent->getApp(), myObject->getFullName());
166 } else {
167 throw ProcessError("Object is NULL");
168 }
169 return 1;
170}
171
172
173long
174GUIGLObjectPopupMenu::onCmdCopyEdgeName(FXObject*, FXSelector, void*) {
175 if (myObject == nullptr) {
176 throw ProcessError("Object is NULL");
177 } else if (myObject->getType() != GLO_LANE) {
178 throw ProcessError(TL("Object must be a lane"));
179 } else {
180 GUIUserIO::copyToClipboard(*myParent->getApp(), myObject->getParentName());
181 }
182 return 1;
183}
184
185
186long
188 if (myObject) {
190 } else {
191 throw ProcessError("Object is NULL");
192 }
193 return 1;
194}
195
196
197long
200 return 1;
201}
202
203
204long
208 // formatted for pasting into google maps
209 const std::string posString = toString(pos.y(), gPrecisionGeo) + ", " + toString(pos.x(), gPrecisionGeo);
210 GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
211 return 1;
212}
213
214
215long
217 const Boundary b = myParent->getVisibleBoundary();
218 Position lowLeft(b.xmin(), b.ymin());
220 Position upRight(b.xmax(), b.ymax());
222 // formatted for usage with osmconvert
223 const std::string posString = toString(lowLeft.x(), gPrecisionGeo) + "," + toString(lowLeft.y(), gPrecisionGeo) + "," +
224 toString(upRight.x(), gPrecisionGeo) + "," + toString(upRight.y(), gPrecisionGeo);
225 GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
226 return 1;
227}
228
229
230long
232 FXMenuCommand* const mc = dynamic_cast<FXMenuCommand*>(item);
235 std::string url = myApplication->getOnlineMaps().find(mc->getText().text())->second;
236 url = StringUtils::replace(StringUtils::replace(url, "%lat", toString(pos.y(), gPrecisionGeo)), "%lon", toString(pos.x(), gPrecisionGeo));
237 MFXLinkLabel::fxexecute(url.c_str());
238 return 1;
239}
240
241
242long
243GUIGLObjectPopupMenu::onCmdShowPars(FXObject*, FXSelector, void*) {
244 if (myObject) {
245 myObject->getParameterWindow(*myApplication, *myParent);
246 } else {
247 throw ProcessError("Object is NULL");
248 }
249 return 1;
250}
251
252
253
254long
255GUIGLObjectPopupMenu::onCmdShowTypePars(FXObject*, FXSelector, void*) {
256 if (myObject) {
257 myObject->getTypeParameterWindow(*myApplication, *myParent);
258 } else {
259 throw ProcessError("Object is NULL");
260 }
261 return 1;
262}
263
264
265long
266GUIGLObjectPopupMenu::onCmdAddSelected(FXObject*, FXSelector, void*) {
267 if (myObject) {
268 gSelected.select(myObject->getGlID());
269 myParent->update();
270 } else {
271 throw ProcessError("Object is NULL");
272 }
273 return 1;
274}
275
276
277long
278GUIGLObjectPopupMenu::onCmdRemoveSelected(FXObject*, FXSelector, void*) {
279 if (myObject) {
280 gSelected.deselect(myObject->getGlID());
281 myParent->update();
282 } else {
283 throw ProcessError("Object is NULL");
284 }
285 return 1;
286}
287
288
290 FXMenuPane(),
291 myParent(nullptr),
292 myObject(nullptr),
293 myApplication(nullptr),
294 myPopupType(PopupType::PROPERTIES) {
295}
296
297/****************************************************************************/
@ MID_ADDSELECT
Add to selected items - menu entry.
Definition GUIAppEnum.h:487
@ MID_COPY_CURSOR_GEOPOSITION
Copy cursor geo-coordinate position - popup entry.
Definition GUIAppEnum.h:465
@ MID_CENTER
Center view to object - popup entry.
Definition GUIAppEnum.h:453
@ MID_COPY_TEST_COORDINATES
Copy test coordinates.
Definition GUIAppEnum.h:459
@ MID_SHOW_GEOPOSITION_ONLINE
Show the cursor geo-coordinate position online in GeoHack - popup entry.
Definition GUIAppEnum.h:469
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition GUIAppEnum.h:457
@ MID_COPY_EDGE_NAME
Copy edge name (for lanes only).
Definition GUIAppEnum.h:461
@ MID_COPY_CURSOR_POSITION
Copy cursor position - popup entry.
Definition GUIAppEnum.h:463
@ MID_SHOWPARS
Show object parameter - popup entry.
Definition GUIAppEnum.h:473
@ MID_COPY_NAME
Copy object name - popup entry.
Definition GUIAppEnum.h:455
@ MID_COPY_VIEW_GEOBOUNDARY
Copy view geo-coordinate boundary - popup entry.
Definition GUIAppEnum.h:467
@ MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition GUIAppEnum.h:475
@ MID_REMOVESELECT
Remove from selected items - Menu Entry.
Definition GUIAppEnum.h:489
FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[]
@ GLO_LANE
a lane
GUISelectedStorage gSelected
A global holder of selected objects.
#define TL(string)
Definition MsgHandler.h:304
int gPrecisionGeo
Definition StdDefs.cpp:29
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
The popup menu of a globject.
GUIGLObjectPopupMenu(GUIMainWindow &app, GUISUMOAbstractView &parent, GUIGlObject *o)
Constructor.
GUIGlObject * myObject
The object that belongs to this popup-menu.
long onCmdCopyViewGeoBoundary(FXObject *, FXSelector, void *)
Called if the current geo-boundary shall be copied to clipboard.
const Position myNetworkPosition
The position within the network the cursor was above when instanting the popup.
long onCmdCopyName(FXObject *, FXSelector, void *)
Called if the name shall be copied to clipboard.
GUISUMOAbstractView * myParent
The parent window.
long onCmdCopyCursorPosition(FXObject *, FXSelector, void *)
Called if the cursor position shall be copied to clipboard.
const std::string myTestCoordinates
The test coordinates position when instanting the popup.
GUISUMOAbstractView * getParentView()
return the real owner of this popup
long onCmdCopyCursorGeoPosition(FXObject *, FXSelector, void *)
Called if the cursor geo-position shall be copied to clipboard.
long onCmdAddSelected(FXObject *, FXSelector, void *)
Called if the object shall be added to the list of selected objects.
long onCmdShowTypePars(FXObject *, FXSelector, void *)
Called if the type parameter of this object shall be shown.
long onCmdShowPars(FXObject *, FXSelector, void *)
Called if the parameter of this object shall be shown.
GUIMainWindow * myApplication
The main application.
long onCmdCopyEdgeName(FXObject *, FXSelector, void *)
Called if the edge name shall be copied to clipboard (for lanes only).
PopupType getPopupType() const
popup type;
const PopupType myPopupType
popup type;
long onCmdShowCursorGeoPositionOnline(FXObject *, FXSelector, void *)
Called if the cursor geo-position shall be shown online.
long onCmdCenter(FXObject *, FXSelector, void *)
void insertMenuPaneChild(FXMenuPane *child)
Insert a sub-menu pane in this GUIGLObjectPopupMenu.
long onCmdRemoveSelected(FXObject *, FXSelector, void *)
Called if the object shall be removed from the list of selected objects.
GUIGLObjectPopupMenu()
FOX needs this.
long onCmdCopyTestCoordinates(FXObject *, FXSelector, void *)
Called if the test coordinates shall be copied to clipboard (only if gui-testing option is enabled).
std::vector< FXMenuPane * > myMenuPanes
vector mit Sub-MenuPanes
virtual ~GUIGLObjectPopupMenu()
Destructor.
long onCmdCopyTypedName(FXObject *, FXSelector, void *)
Called if the typed name shall be copied to clipboard.
GUIGlObject * getGLObject() const
The object that belongs to this popup-menu.
static void copyToClipboard(const FXApp &app, const std::string &text)
Copies the given text to clipboard.
Definition GUIUserIO.cpp:36
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:52
double y() const
Returns the y-position.
Definition Position.h:57
static std::string replace(std::string str, const std::string &what, const std::string &by)
Replaces all occurrences of the second string by the third string within the first string.