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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // The popup menu of a globject
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <iostream>
33 #include <cassert>
41 #include <utils/common/ToString.h>
42 #include "GUIGLObjectPopupMenu.h"
43 
44 // ===========================================================================
45 // FOX callback mapping
46 // ===========================================================================
47 FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[] = {
48  FXMAPFUNC(SEL_COMMAND, MID_CENTER, GUIGLObjectPopupMenu::onCmdCenter),
49  FXMAPFUNC(SEL_COMMAND, MID_COPY_NAME, GUIGLObjectPopupMenu::onCmdCopyName),
54  FXMAPFUNC(SEL_COMMAND, MID_SHOWPARS, GUIGLObjectPopupMenu::onCmdShowPars),
58 };
59 
60 // Object implementation
61 FXIMPLEMENT(GUIGLObjectPopupMenu, FXMenuPane, GUIGLObjectPopupMenuMap, ARRAYNUMBER(GUIGLObjectPopupMenuMap))
62 
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
67 
69  FXMenuPane(&parent),
70  myParent(&parent),
71  myObject(&o),
72  myApplication(&app),
73  myNetworkPosition(parent.getPositionInformation()) {
74 }
75 
76 
78  // Delete MenuPaneChilds
79  for (auto i : myMenuPanes) {
80  delete i;
81  }
82 }
83 
84 
85 void
87  // Check that MenuPaneChild isn't NULL
88  if (child == NULL) {
89  throw ProcessError("MenuPaneChild cannot be NULL");
90  }
91  // Check that MenuPaneChild wasn't already inserted
92  for (auto i : myMenuPanes) {
93  if (i == child) {
94  throw ProcessError("MenuPaneChild already inserted");
95  }
96  }
97  // Insert MenuPaneChild
98  myMenuPanes.push_back(child);
99 }
100 
101 
102 long
103 GUIGLObjectPopupMenu::onCmdCenter(FXObject*, FXSelector, void*) {
104  // we already know where the object is since we clicked on it -> zoom on Boundary
105  myParent->centerTo(myObject->getGlID(), true, -1);
106  return 1;
107 }
108 
109 
110 long
111 GUIGLObjectPopupMenu::onCmdCopyName(FXObject*, FXSelector, void*) {
113  return 1;
114 }
115 
116 
117 long
118 GUIGLObjectPopupMenu::onCmdCopyTypedName(FXObject*, FXSelector, void*) {
120  return 1;
121 }
122 
123 
124 long
125 GUIGLObjectPopupMenu::onCmdCopyEdgeName(FXObject*, FXSelector, void*) {
126  assert(myObject->getType() == GLO_LANE);
128  return 1;
129 }
130 
131 
132 long
133 GUIGLObjectPopupMenu::onCmdCopyCursorPosition(FXObject*, FXSelector, void*) {
135  return 1;
136 }
137 
138 
139 long
143  // formated for pasting into google maps
144  const std::string posString = toString(pos.y(), gPrecisionGeo) + ", " + toString(pos.x(), gPrecisionGeo);
145  GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
146  return 1;
147 }
148 
149 
150 long
151 GUIGLObjectPopupMenu::onCmdShowPars(FXObject*, FXSelector, void*) {
153  return 1;
154 }
155 
156 
157 
158 long
159 GUIGLObjectPopupMenu::onCmdShowTypePars(FXObject*, FXSelector, void*) {
161  return 1;
162 }
163 
164 
165 long
166 GUIGLObjectPopupMenu::onCmdAddSelected(FXObject*, FXSelector, void*) {
168  myParent->update();
169  return 1;
170 }
171 
172 
173 long
174 GUIGLObjectPopupMenu::onCmdRemoveSelected(FXObject*, FXSelector, void*) {
176  myParent->update();
177  return 1;
178 }
179 
180 /****************************************************************************/
181 
Show object parameter - popup entry.
Definition: GUIAppEnum.h:240
long onCmdCenter(FXObject *, FXSelector, void *)
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.
static void copyToClipboard(const FXApp &app, const std::string &text)
Copies the given text to clipboard.
Definition: GUIUserIO.cpp:44
Copy edge name (for lanes only)
Definition: GUIAppEnum.h:232
long onCmdAddSelected(FXObject *, FXSelector, void *)
Called if the object shall be added to the list of selected objects.
long onCmdCopyCursorPosition(FXObject *, FXSelector, void *)
Called if the cursor position shall be copied to clipboard.
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
double y() const
Returns the y-position.
Definition: Position.h:67
double x() const
Returns the x-position.
Definition: Position.h:62
long onCmdCopyCursorGeoPosition(FXObject *, FXSelector, void *)
Called if the cursor geo-position shall be copied to clipboard.
Center view to object - popup entry.
Definition: GUIAppEnum.h:226
GUISUMOAbstractView * myParent
The parent window.
long onCmdShowTypePars(FXObject *, FXSelector, void *)
Called if the type parameter of this object shall be shown.
Remove from selected items - Menu Etry.
Definition: GUIAppEnum.h:252
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
long onCmdCopyEdgeName(FXObject *, FXSelector, void *)
Called if the edge name shall be copied to clipboard (for lanes only)
virtual ~GUIGLObjectPopupMenu()
Destructor.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
virtual GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window (optional)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
int gPrecisionGeo
Definition: StdDefs.cpp:30
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
virtual GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)=0
Returns an own parameter window.
std::vector< FXMenuPane * > myMenuPanes
vector mit Sub-MenuPanes
Copy object name - popup entry.
Definition: GUIAppEnum.h:228
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:236
long onCmdCopyTypedName(FXObject *, FXSelector, void *)
Called if the typed name shall be copied to clipboard.
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:242
void deselect(GUIGlID id)
Deselects the object with the given id.
long onCmdRemoveSelected(FXObject *, FXSelector, void *)
Called if the object shall be removed from the list of selected objects.
The popup menu of a globject.
long onCmdShowPars(FXObject *, FXSelector, void *)
Called if the parameter of this object shall be shown.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
virtual const std::string & getParentName() const
Returns the name of the parent object (if any)
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:234
GUIGlID getGlID() const
Returns the numerical id of the object.
void insertMenuPaneChild(FXMenuPane *child)
Insert a sub-menu pane in this GUIGLObjectPopupMenu.
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:230
GUIMainWindow * myApplication
The main application.
const std::string & getFullName() const
GUIGlObject * myObject
The object that belongs to this popup-menu.
GUISelectedStorage gSelected
A global holder of selected objects.
FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[]
Add to selected items - menu entry.
Definition: GUIAppEnum.h:250