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-2026 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>
38
40
41// ===========================================================================
42// FOX callback mapping
43// ===========================================================================
61
62// Object implementation
63FXIMPLEMENT(GUIGLObjectPopupMenu, FXMenuPane, GUIGLObjectPopupMenuMap, ARRAYNUMBER(GUIGLObjectPopupMenuMap))
64
65
66// ===========================================================================
67// method definitions
68// ===========================================================================
69
71 FXMenuPane(&parent),
72 myParent(&parent),
73 myObject(o),
74 myApplication(&app),
75 myPopupType(PopupType::ATTRIBUTES),
76 myNetworkPosition(parent.getPositionInformation()),
77 myTestCoordinates((toString(parent.getWindowCursorPosition().x() - 24.0) + " " + toString(parent.getWindowCursorPosition().y() - 25.0))) {
78}
79
80
82 FXMenuPane(parent),
83 myParent(parent),
84 myObject(nullptr),
85 myApplication(app),
86 myPopupType(popupType),
87 myNetworkPosition(parent->getPositionInformation()) {
88}
89
90
92 // Delete MenuPane children
93 for (const auto& pane : myMenuPanes) {
94 delete pane;
95 }
96}
97
98
99void
101 // Check that MenuPaneChild isn't NULL
102 if (child == nullptr) {
103 throw ProcessError("MenuPaneChild cannot be NULL");
104 }
105 // Check that MenuPaneChild wasn't already inserted
106 for (const auto& pane : myMenuPanes) {
107 if (pane == child) {
108 throw ProcessError("MenuPaneChild already inserted");
109 }
110 }
111 // Insert MenuPaneChild
112 myMenuPanes.push_back(child);
113}
114
115
116void
118 // remove popup menu from object
119 if (myObject) {
121 }
122}
123
128
129
134
135
140
141
142long
143GUIGLObjectPopupMenu::onCmdCenter(FXObject*, FXSelector, void*) {
144 // we already know where the object is since we clicked on it -> zoom on Boundary
145 if (myObject) {
146 myParent->centerTo(myObject->getGlID(), true, -1);
147 } else {
148 throw ProcessError("Object is NULL");
149 }
150 return 1;
151}
152
153
154long
155GUIGLObjectPopupMenu::onCmdCopyName(FXObject*, FXSelector, void*) {
156 if (myObject) {
158 } else {
159 throw ProcessError("Object is NULL");
160 }
161 return 1;
162}
163
164
165long
166GUIGLObjectPopupMenu::onCmdCopyTypedName(FXObject*, FXSelector, void*) {
167 if (myObject) {
169 } else {
170 throw ProcessError("Object is NULL");
171 }
172 return 1;
173}
174
175
176long
177GUIGLObjectPopupMenu::onCmdCopyEdgeName(FXObject*, FXSelector, void*) {
178 if (myObject == nullptr) {
179 throw ProcessError("Object is NULL");
180 } else if (myObject->getType() != GLO_LANE) {
181 throw ProcessError(TL("Object must be a lane"));
182 } else {
184 }
185 return 1;
186}
187
188
189long
191 if (myObject) {
193 } else {
194 throw ProcessError("Object is NULL");
195 }
196 return 1;
197}
198
199
200long
203 return 1;
204}
205
206
207long
211 // formatted for pasting into google maps
212 const std::string posString = toString(pos.y(), gPrecisionGeo) + ", " + toString(pos.x(), gPrecisionGeo);
213 GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
214 return 1;
215}
216
217
218long
221 Position lowLeft(b.xmin(), b.ymin());
223 Position upRight(b.xmax(), b.ymax());
225 // formatted for usage with osmconvert
226 const std::string posString = toString(lowLeft.x(), gPrecisionGeo) + "," + toString(lowLeft.y(), gPrecisionGeo) + "," +
227 toString(upRight.x(), gPrecisionGeo) + "," + toString(upRight.y(), gPrecisionGeo);
228 GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
229 return 1;
230}
231
232
233long
235 FXMenuCommand* const mc = dynamic_cast<FXMenuCommand*>(item);
238 std::string url = myApplication->getOnlineMaps().find(mc->getText().text())->second;
239 url = StringUtils::replace(StringUtils::replace(url, "%lat", toString(pos.y(), gPrecisionGeo)), "%lon", toString(pos.x(), gPrecisionGeo));
240 MFXLinkLabel::fxexecute(url.c_str());
241 return 1;
242}
243
244
245long
246GUIGLObjectPopupMenu::onCmdShowPars(FXObject*, FXSelector, void*) {
247 if (myObject) {
249 } else {
250 throw ProcessError("Object is NULL");
251 }
252 return 1;
253}
254
255
256long
257GUIGLObjectPopupMenu::onCmdShowParsParent(FXObject*, FXSelector, void*) {
260 } else {
261 throw ProcessError("Object is NULL");
262 }
263 return 1;
264}
265
266
267long
268GUIGLObjectPopupMenu::onCmdShowTypePars(FXObject*, FXSelector, void*) {
269 if (myObject) {
271 } else {
272 throw ProcessError("Object is NULL");
273 }
274 return 1;
275}
276
277
278long
279GUIGLObjectPopupMenu::onCmdAddSelected(FXObject*, FXSelector, void*) {
280 if (myObject) {
282 myParent->update();
283 } else {
284 throw ProcessError("Object is NULL");
285 }
286 return 1;
287}
288
289
290long
291GUIGLObjectPopupMenu::onCmdRemoveSelected(FXObject*, FXSelector, void*) {
292 if (myObject) {
294 myParent->update();
295 } else {
296 throw ProcessError("Object is NULL");
297 }
298 return 1;
299}
300
301
302long
303GUIGLObjectPopupMenu::onCmdDelete(FXObject*, FXSelector, void*) {
304 if (myObject) {
306 } else {
307 throw ProcessError("Object is NULL");
308 }
309 return 1;
310}
311
312
314 FXMenuPane(),
315 myParent(nullptr),
316 myObject(nullptr),
317 myApplication(nullptr),
318 myPopupType(PopupType::PROPERTIES) {
319}
320
321/****************************************************************************/
@ MID_ADDSELECT
Add to selected items - menu entry.
Definition GUIAppEnum.h:489
@ 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_SHOWPARS_PARENT
Show object parent parameter - popup entry.
Definition GUIAppEnum.h:475
@ 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_DELETE
delete item - menu entry
Definition GUIAppEnum.h:493
@ MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition GUIAppEnum.h:477
@ MID_REMOVESELECT
Remove from selected items - Menu Entry.
Definition GUIAppEnum.h:491
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:49
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:127
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:115
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:133
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:121
The popup menu of a globject.
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.
long onCmdShowParsParent(FXObject *, FXSelector, void *)
Called if the parameter of this object parent 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)
long onCmdDelete(FXObject *, FXSelector, void *)
Called if the object can be removed.
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.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void deleteGLObject()
delete GLObject (Currently used only in netedit)
virtual GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window (optional)
const std::string & getFullName() const
Definition GUIGlObject.h:95
virtual std::string getParentName() const
Returns the name of the parent object (if any)
GUIGlObject * getGLObjectParent()
notify object about popup menu removal
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual void removedPopupMenu()
notify object about popup menu removal
virtual GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)=0
Returns an own parameter window.
GUIGlID getGlID() const
Returns the numerical id of the object.
const std::map< std::string, std::string > & getOnlineMaps() const
Boundary getVisibleBoundary() const
get visible boundary
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
void deselect(GUIGlID id)
Deselects the object with the given id.
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.