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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The popup menu of a globject
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <iostream>
27 #include <cassert>
35 #include <utils/common/ToString.h>
36 #include "GUIGLObjectPopupMenu.h"
37 
38 // ===========================================================================
39 // FOX callback mapping
40 // ===========================================================================
41 FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[] = {
42  FXMAPFUNC(SEL_COMMAND, MID_CENTER, GUIGLObjectPopupMenu::onCmdCenter),
43  FXMAPFUNC(SEL_COMMAND, MID_COPY_NAME, GUIGLObjectPopupMenu::onCmdCopyName),
48  FXMAPFUNC(SEL_COMMAND, MID_SHOWPARS, GUIGLObjectPopupMenu::onCmdShowPars),
52 };
53 
54 // Object implementation
55 FXIMPLEMENT(GUIGLObjectPopupMenu, FXMenuPane, GUIGLObjectPopupMenuMap, ARRAYNUMBER(GUIGLObjectPopupMenuMap))
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 
63  FXMenuPane(&parent),
64  myParent(&parent),
65  myObject(&o),
66  myApplication(&app),
67  myNetworkPosition(parent.getPositionInformation()) {
68 }
69 
70 
72  // Delete MenuPaneChilds
73  for (auto i : myMenuPanes) {
74  delete i;
75  }
76 }
77 
78 
79 void
81  // Check that MenuPaneChild isn't NULL
82  if (child == nullptr) {
83  throw ProcessError("MenuPaneChild cannot be NULL");
84  }
85  // Check that MenuPaneChild wasn't already inserted
86  for (auto i : myMenuPanes) {
87  if (i == child) {
88  throw ProcessError("MenuPaneChild already inserted");
89  }
90  }
91  // Insert MenuPaneChild
92  myMenuPanes.push_back(child);
93 }
94 
95 
96 long
97 GUIGLObjectPopupMenu::onCmdCenter(FXObject*, FXSelector, void*) {
98  // we already know where the object is since we clicked on it -> zoom on Boundary
99  myParent->centerTo(myObject->getGlID(), true, -1);
100  return 1;
101 }
102 
103 
104 long
105 GUIGLObjectPopupMenu::onCmdCopyName(FXObject*, FXSelector, void*) {
107  return 1;
108 }
109 
110 
111 long
112 GUIGLObjectPopupMenu::onCmdCopyTypedName(FXObject*, FXSelector, void*) {
114  return 1;
115 }
116 
117 
118 long
119 GUIGLObjectPopupMenu::onCmdCopyEdgeName(FXObject*, FXSelector, void*) {
120  assert(myObject->getType() == GLO_LANE);
122  return 1;
123 }
124 
125 
126 long
127 GUIGLObjectPopupMenu::onCmdCopyCursorPosition(FXObject*, FXSelector, void*) {
129  return 1;
130 }
131 
132 
133 long
137  // formated for pasting into google maps
138  const std::string posString = toString(pos.y(), gPrecisionGeo) + ", " + toString(pos.x(), gPrecisionGeo);
139  GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
140  return 1;
141 }
142 
143 
144 long
145 GUIGLObjectPopupMenu::onCmdShowPars(FXObject*, FXSelector, void*) {
147  return 1;
148 }
149 
150 
151 
152 long
153 GUIGLObjectPopupMenu::onCmdShowTypePars(FXObject*, FXSelector, void*) {
155  return 1;
156 }
157 
158 
159 long
160 GUIGLObjectPopupMenu::onCmdAddSelected(FXObject*, FXSelector, void*) {
162  myParent->update();
163  return 1;
164 }
165 
166 
167 long
168 GUIGLObjectPopupMenu::onCmdRemoveSelected(FXObject*, FXSelector, void*) {
170  myParent->update();
171  return 1;
172 }
173 
174 /****************************************************************************/
175 
Copy object name - popup entry.
Definition: GUIAppEnum.h:230
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:38
Center view to object - popup entry.
Definition: GUIAppEnum.h:228
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:62
double x() const
Returns the x-position.
Definition: Position.h:57
long onCmdCopyCursorGeoPosition(FXObject *, FXSelector, void *)
Called if the cursor geo-position shall be copied to clipboard.
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:256
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.
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:238
Show object parameter - popup entry.
Definition: GUIAppEnum.h:242
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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
virtual GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window (optional)
Copy edge name (for lanes only)
Definition: GUIAppEnum.h:234
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
int gPrecisionGeo
Definition: StdDefs.cpp:28
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:236
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
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
long onCmdCopyTypedName(FXObject *, FXSelector, void *)
Called if the typed name shall be copied to clipboard.
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...
GUIGlID getGlID() const
Returns the numerical id of the object.
void insertMenuPaneChild(FXMenuPane *child)
Insert a sub-menu pane in this GUIGLObjectPopupMenu.
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:244
GUIMainWindow * myApplication
The main application.
const std::string & getFullName() const
Add to selected items - menu entry.
Definition: GUIAppEnum.h:254
GUIGlObject * myObject
The object that belongs to this popup-menu.
GUISelectedStorage gSelected
A global holder of selected objects.
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:232
FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[]