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.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 /****************************************************************************/
20 // The popup menu of a globject
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <iostream>
25 #include <cassert>
36 #include <utils/common/ToString.h>
37 #include "GUIGLObjectPopupMenu.h"
39 
40 // ===========================================================================
41 // FOX callback mapping
42 // ===========================================================================
43 FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[] = {
44  FXMAPFUNC(SEL_COMMAND, MID_CENTER, GUIGLObjectPopupMenu::onCmdCenter),
45  FXMAPFUNC(SEL_COMMAND, MID_COPY_NAME, GUIGLObjectPopupMenu::onCmdCopyName),
53  FXMAPFUNC(SEL_COMMAND, MID_SHOWPARS, GUIGLObjectPopupMenu::onCmdShowPars),
57 };
58 
59 // Object implementation
60 FXIMPLEMENT(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 
96 void
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 
113 void
115  // remove popup menu from object
116  if (myObject) {
118  }
119 }
120 
123  return myParent;
124 }
125 
126 
129  return myPopupType;
130 }
131 
132 
133 long
134 GUIGLObjectPopupMenu::onCmdCenter(FXObject*, FXSelector, void*) {
135  // we already know where the object is since we clicked on it -> zoom on Boundary
136  if (myObject) {
137  myParent->centerTo(myObject->getGlID(), true, -1);
138  } else {
139  throw ProcessError("Object is NULL");
140  }
141  return 1;
142 }
143 
144 
145 long
146 GUIGLObjectPopupMenu::onCmdCopyName(FXObject*, FXSelector, void*) {
147  if (myObject) {
149  } else {
150  throw ProcessError("Object is NULL");
151  }
152  return 1;
153 }
154 
155 
156 long
157 GUIGLObjectPopupMenu::onCmdCopyTypedName(FXObject*, FXSelector, void*) {
158  if (myObject) {
160  } else {
161  throw ProcessError("Object is NULL");
162  }
163  return 1;
164 }
165 
166 
167 long
168 GUIGLObjectPopupMenu::onCmdCopyEdgeName(FXObject*, FXSelector, void*) {
169  if (myObject == nullptr) {
170  throw ProcessError("Object is NULL");
171  } else if (myObject->getType() != GLO_LANE) {
172  throw ProcessError(TL("Object must be a lane"));
173  } else {
175  }
176  return 1;
177 }
178 
179 
180 long
181 GUIGLObjectPopupMenu::onCmdCopyTestCoordinates(FXObject*, FXSelector, void*) {
182  if (myObject) {
184  } else {
185  throw ProcessError("Object is NULL");
186  }
187  return 1;
188 }
189 
190 
191 long
192 GUIGLObjectPopupMenu::onCmdCopyCursorPosition(FXObject*, FXSelector, void*) {
194  return 1;
195 }
196 
197 
198 long
202  // formatted for pasting into google maps
203  const std::string posString = toString(pos.y(), gPrecisionGeo) + ", " + toString(pos.x(), gPrecisionGeo);
204  GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
205  return 1;
206 }
207 
208 
209 long
210 GUIGLObjectPopupMenu::onCmdCopyViewGeoBoundary(FXObject*, FXSelector, void*) {
211  const Boundary b = myParent->getVisibleBoundary();
212  Position lowLeft(b.xmin(), b.ymin());
214  Position upRight(b.xmax(), b.ymax());
216  // formatted for usage with osmconvert
217  const std::string posString = toString(lowLeft.x(), gPrecisionGeo) + "," + toString(lowLeft.y(), gPrecisionGeo) + "," +
218  toString(upRight.x(), gPrecisionGeo) + "," + toString(upRight.y(), gPrecisionGeo);
219  GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
220  return 1;
221 }
222 
223 
224 long
225 GUIGLObjectPopupMenu::onCmdShowCursorGeoPositionOnline(FXObject* item, FXSelector, void*) {
226  FXMenuCommand* const mc = dynamic_cast<FXMenuCommand*>(item);
229  std::string url = myApplication->getOnlineMaps().find(mc->getText().text())->second;
230  url = StringUtils::replace(StringUtils::replace(url, "%lat", toString(pos.y(), gPrecisionGeo)), "%lon", toString(pos.x(), gPrecisionGeo));
231  MFXLinkLabel::fxexecute(url.c_str());
232  return 1;
233 }
234 
235 
236 long
237 GUIGLObjectPopupMenu::onCmdShowPars(FXObject*, FXSelector, void*) {
238  if (myObject) {
240  } else {
241  throw ProcessError("Object is NULL");
242  }
243  return 1;
244 }
245 
246 
247 
248 long
249 GUIGLObjectPopupMenu::onCmdShowTypePars(FXObject*, FXSelector, void*) {
250  if (myObject) {
252  } else {
253  throw ProcessError("Object is NULL");
254  }
255  return 1;
256 }
257 
258 
259 long
260 GUIGLObjectPopupMenu::onCmdAddSelected(FXObject*, FXSelector, void*) {
261  if (myObject) {
263  myParent->update();
264  } else {
265  throw ProcessError("Object is NULL");
266  }
267  return 1;
268 }
269 
270 
271 long
272 GUIGLObjectPopupMenu::onCmdRemoveSelected(FXObject*, FXSelector, void*) {
273  if (myObject) {
275  myParent->update();
276  } else {
277  throw ProcessError("Object is NULL");
278  }
279  return 1;
280 }
281 
282 
284  FXMenuPane(),
285  myParent(nullptr),
286  myObject(nullptr),
287  myApplication(nullptr),
288  myPopupType(PopupType::PROPERTIES) {
289 }
290 
291 /****************************************************************************/
@ MID_ADDSELECT
Add to selected items - menu entry.
Definition: GUIAppEnum.h:485
@ MID_COPY_CURSOR_GEOPOSITION
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:463
@ MID_CENTER
Center view to object - popup entry.
Definition: GUIAppEnum.h:451
@ MID_COPY_TEST_COORDINATES
Copy test coordinates.
Definition: GUIAppEnum.h:457
@ MID_SHOW_GEOPOSITION_ONLINE
Show the cursor geo-coordinate position online in GeoHack - popup entry.
Definition: GUIAppEnum.h:467
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:455
@ MID_COPY_EDGE_NAME
Copy edge name (for lanes only)
Definition: GUIAppEnum.h:459
@ MID_COPY_CURSOR_POSITION
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:461
@ MID_SHOWPARS
Show object parameter - popup entry.
Definition: GUIAppEnum.h:471
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:453
@ MID_COPY_VIEW_GEOBOUNDARY
Copy view geo-coordinate boundary - popup entry.
Definition: GUIAppEnum.h:465
@ MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:473
@ MID_REMOVESELECT
Remove from selected items - Menu Entry.
Definition: GUIAppEnum.h:487
FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[]
@ GLO_LANE
a lane
GUISelectedStorage gSelected
A global holder of selected objects.
#define TL(string)
Definition: MsgHandler.h:315
int gPrecisionGeo
Definition: StdDefs.cpp:27
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
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:130
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:118
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:136
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:124
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.
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.
const std::string & getFullName() const
Definition: GUIGlObject.h:94
virtual GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window (optional)
virtual GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)=0
Returns an own parameter window.
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:156
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
virtual void removedPopupMenu()
notify object about popup menu removal
Definition: GUIGlObject.h:124
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:104
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
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
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)
Replaces all occurrences of the second string by the third string within the first string.