Eclipse SUMO - Simulation of Urban MObility
GUIGLObjectPopupMenu.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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// ===========================================================================
43FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[] = {
44 FXMAPFUNC(SEL_COMMAND, MID_CENTER, GUIGLObjectPopupMenu::onCmdCenter),
55};
56
57// Object implementation
58FXIMPLEMENT(GUIGLObjectPopupMenu, FXMenuPane, GUIGLObjectPopupMenuMap, ARRAYNUMBER(GUIGLObjectPopupMenuMap))
59
60
61// ===========================================================================
62// method definitions
63// ===========================================================================
64
66 FXMenuPane(&parent),
67 myParent(&parent),
68 myObject(&o),
69 myApplication(&app),
70 myPopupType(PopupType::ATTRIBUTES),
71 myNetworkPosition(parent.getPositionInformation()) {
72}
73
74
76 FXMenuPane(parent),
77 myParent(parent),
78 myObject(nullptr),
79 myApplication(app),
80 myPopupType(popupType),
81 myNetworkPosition(parent->getPositionInformation()) {
82}
83
84
86 // Delete MenuPane children
87 for (const auto& pane : myMenuPanes) {
88 delete pane;
89 }
90 // remove popup menu from object
91 if (myObject) {
93 }
94}
95
96
97void
99 // Check that MenuPaneChild isn't NULL
100 if (child == nullptr) {
101 throw ProcessError("MenuPaneChild cannot be NULL");
102 }
103 // Check that MenuPaneChild wasn't already inserted
104 for (const auto& pane : myMenuPanes) {
105 if (pane == child) {
106 throw ProcessError("MenuPaneChild already inserted");
107 }
108 }
109 // Insert MenuPaneChild
110 myMenuPanes.push_back(child);
111}
112
113
116 return myParent;
117}
118
119
122 return myPopupType;
123}
124
125
126long
127GUIGLObjectPopupMenu::onCmdCenter(FXObject*, FXSelector, void*) {
128 // we already know where the object is since we clicked on it -> zoom on Boundary
129 if (myObject) {
130 myParent->centerTo(myObject->getGlID(), true, -1);
131 } else {
132 throw ProcessError("Object is NULL");
133 }
134 return 1;
135}
136
137
138long
139GUIGLObjectPopupMenu::onCmdCopyName(FXObject*, FXSelector, void*) {
140 if (myObject) {
142 } else {
143 throw ProcessError("Object is NULL");
144 }
145 return 1;
146}
147
148
149long
150GUIGLObjectPopupMenu::onCmdCopyTypedName(FXObject*, FXSelector, void*) {
151 if (myObject) {
153 } else {
154 throw ProcessError("Object is NULL");
155 }
156 return 1;
157}
158
159
160long
161GUIGLObjectPopupMenu::onCmdCopyEdgeName(FXObject*, FXSelector, void*) {
162 if (myObject == nullptr) {
163 throw ProcessError("Object is NULL");
164 } else if (myObject->getType() != GLO_LANE) {
165 throw ProcessError("Object must be a lane");
166 } else {
168 }
169 return 1;
170}
171
172
173long
176 return 1;
177}
178
179
180long
184 // formated for pasting into google maps
185 const std::string posString = toString(pos.y(), gPrecisionGeo) + ", " + toString(pos.x(), gPrecisionGeo);
186 GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
187 return 1;
188}
189
190
191long
193 FXMenuCommand* const mc = dynamic_cast<FXMenuCommand*>(item);
196 std::string url = myApplication->getOnlineMaps().find(mc->getText().rafter(' ').text())->second;
197 url = StringUtils::replace(StringUtils::replace(url, "%lat", toString(pos.y(), gPrecisionGeo)), "%lon", toString(pos.x(), gPrecisionGeo));
198 MFXLinkLabel::fxexecute(url.c_str());
199 return 1;
200}
201
202
203long
204GUIGLObjectPopupMenu::onCmdShowPars(FXObject*, FXSelector, void*) {
205 if (myObject) {
207 } else {
208 throw ProcessError("Object is NULL");
209 }
210 return 1;
211}
212
213
214
215long
216GUIGLObjectPopupMenu::onCmdShowTypePars(FXObject*, FXSelector, void*) {
217 if (myObject) {
219 } else {
220 throw ProcessError("Object is NULL");
221 }
222 return 1;
223}
224
225
226long
227GUIGLObjectPopupMenu::onCmdAddSelected(FXObject*, FXSelector, void*) {
228 if (myObject) {
230 myParent->update();
231 } else {
232 throw ProcessError("Object is NULL");
233 }
234 return 1;
235}
236
237
238long
239GUIGLObjectPopupMenu::onCmdRemoveSelected(FXObject*, FXSelector, void*) {
240 if (myObject) {
242 myParent->update();
243 } else {
244 throw ProcessError("Object is NULL");
245 }
246 return 1;
247}
248
249
251 FXMenuPane(),
252 myParent(nullptr),
253 myObject(nullptr),
254 myApplication(nullptr),
255 myPopupType(PopupType::PROPERTIES) {
256}
257
258/****************************************************************************/
@ MID_ADDSELECT
Add to selected items - menu entry.
Definition: GUIAppEnum.h:476
@ MID_COPY_CURSOR_GEOPOSITION
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:456
@ MID_CENTER
Center view to object - popup entry.
Definition: GUIAppEnum.h:446
@ MID_SHOW_GEOPOSITION_ONLINE
Show the cursor geo-coordinate position online in GeoHack - popup entry.
Definition: GUIAppEnum.h:458
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:450
@ MID_COPY_EDGE_NAME
Copy edge name (for lanes only)
Definition: GUIAppEnum.h:452
@ MID_COPY_CURSOR_POSITION
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:454
@ MID_SHOWPARS
Show object parameter - popup entry.
Definition: GUIAppEnum.h:462
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:448
@ MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:464
@ MID_REMOVESELECT
Remove from selected items - Menu Entry.
Definition: GUIAppEnum.h:478
FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[]
@ GLO_LANE
a lane
GUISelectedStorage gSelected
A global holder of selected objects.
int gPrecisionGeo
Definition: StdDefs.cpp:26
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
The popup menu of a globject.
GUIGlObject * myObject
The object that belongs to this popup-menu.
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.
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.
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.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
virtual GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window (optional)
const std::string & getFullName() const
Definition: GUIGlObject.h:92
virtual std::string getParentName() const
Returns the name of the parent object (if any)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
virtual void removedPopupMenu()
notify object about popup menu removal
Definition: GUIGlObject.h:122
virtual GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)=0
Returns an own parameter window.
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
const std::map< std::string, std::string > & getOnlineMaps() const
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:55
double y() const
Returns the y-position.
Definition: Position.h:60
static std::string replace(std::string str, const std::string &what, const std::string &by)