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-2020 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>
33 #include <utils/common/ToString.h>
34 #include "GUIGLObjectPopupMenu.h"
35 
36 // ===========================================================================
37 // FOX callback mapping
38 // ===========================================================================
39 FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[] = {
40  FXMAPFUNC(SEL_COMMAND, MID_CENTER, GUIGLObjectPopupMenu::onCmdCenter),
41  FXMAPFUNC(SEL_COMMAND, MID_COPY_NAME, GUIGLObjectPopupMenu::onCmdCopyName),
46  FXMAPFUNC(SEL_COMMAND, MID_SHOWPARS, GUIGLObjectPopupMenu::onCmdShowPars),
50 };
51 
52 // Object implementation
53 FXIMPLEMENT(GUIGLObjectPopupMenu, FXMenuPane, GUIGLObjectPopupMenuMap, ARRAYNUMBER(GUIGLObjectPopupMenuMap))
54 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 
61  FXMenuPane(&parent),
62  myParent(&parent),
63  myObject(&o),
64  myApplication(&app),
65  myNetworkPosition(parent.getPositionInformation()) {
66 }
67 
68 
70  // Delete MenuPane children
71  for (auto i : myMenuPanes) {
72  delete i;
73  }
75 }
76 
77 
78 void
80  // Check that MenuPaneChild isn't NULL
81  if (child == nullptr) {
82  throw ProcessError("MenuPaneChild cannot be NULL");
83  }
84  // Check that MenuPaneChild wasn't already inserted
85  for (auto i : myMenuPanes) {
86  if (i == child) {
87  throw ProcessError("MenuPaneChild already inserted");
88  }
89  }
90  // Insert MenuPaneChild
91  myMenuPanes.push_back(child);
92 }
93 
94 
95 long
96 GUIGLObjectPopupMenu::onCmdCenter(FXObject*, FXSelector, void*) {
97  // we already know where the object is since we clicked on it -> zoom on Boundary
98  myParent->centerTo(myObject->getGlID(), true, -1);
99  return 1;
100 }
101 
102 
103 long
104 GUIGLObjectPopupMenu::onCmdCopyName(FXObject*, FXSelector, void*) {
106  return 1;
107 }
108 
109 
110 long
111 GUIGLObjectPopupMenu::onCmdCopyTypedName(FXObject*, FXSelector, void*) {
113  return 1;
114 }
115 
116 
117 long
118 GUIGLObjectPopupMenu::onCmdCopyEdgeName(FXObject*, FXSelector, void*) {
119  assert(myObject->getType() == GLO_LANE);
121  return 1;
122 }
123 
124 
125 long
126 GUIGLObjectPopupMenu::onCmdCopyCursorPosition(FXObject*, FXSelector, void*) {
128  return 1;
129 }
130 
131 
132 long
136  // formated for pasting into google maps
137  const std::string posString = toString(pos.y(), gPrecisionGeo) + ", " + toString(pos.x(), gPrecisionGeo);
138  GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
139  return 1;
140 }
141 
142 
143 long
144 GUIGLObjectPopupMenu::onCmdShowPars(FXObject*, FXSelector, void*) {
146  return 1;
147 }
148 
149 
150 
151 long
152 GUIGLObjectPopupMenu::onCmdShowTypePars(FXObject*, FXSelector, void*) {
154  return 1;
155 }
156 
157 
158 long
159 GUIGLObjectPopupMenu::onCmdAddSelected(FXObject*, FXSelector, void*) {
161  myParent->update();
162  return 1;
163 }
164 
165 
166 long
167 GUIGLObjectPopupMenu::onCmdRemoveSelected(FXObject*, FXSelector, void*) {
169  myParent->update();
170  return 1;
171 }
172 
173 
174 /****************************************************************************/
@ MID_ADDSELECT
Add to selected items - menu entry.
Definition: GUIAppEnum.h:427
@ MID_COPY_CURSOR_GEOPOSITION
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:409
@ MID_CENTER
Center view to object - popup entry.
Definition: GUIAppEnum.h:399
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:403
@ MID_COPY_EDGE_NAME
Copy edge name (for lanes only)
Definition: GUIAppEnum.h:405
@ MID_COPY_CURSOR_POSITION
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:407
@ MID_SHOWPARS
Show object parameter - popup entry.
Definition: GUIAppEnum.h:413
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:401
@ MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:415
@ MID_REMOVESELECT
Remove from selected items - Menu Etry.
Definition: GUIAppEnum.h:429
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:44
The popup menu of a globject.
GUIGlObject * myObject
The object that belongs to this popup-menu.
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.
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)
long onCmdCenter(FXObject *, FXSelector, void *)
Position myNetworkPosition
The position within the network the cursor was above when instanting the popup.
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.
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.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
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.
const std::string & getFullName() const
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.
virtual void removedPopupMenu()
notify object about popup menu removal
Definition: GUIGlObject.h:109
GUIGlID getGlID() const
Returns the numerical id of the object.
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:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59