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-2019 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 /****************************************************************************/
16 // The popup menu of a globject
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <iostream>
26 #include <cassert>
34 #include <utils/common/ToString.h>
35 #include "GUIGLObjectPopupMenu.h"
36 
37 // ===========================================================================
38 // FOX callback mapping
39 // ===========================================================================
40 FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[] = {
41  FXMAPFUNC(SEL_COMMAND, MID_CENTER, GUIGLObjectPopupMenu::onCmdCenter),
42  FXMAPFUNC(SEL_COMMAND, MID_COPY_NAME, GUIGLObjectPopupMenu::onCmdCopyName),
47  FXMAPFUNC(SEL_COMMAND, MID_SHOWPARS, GUIGLObjectPopupMenu::onCmdShowPars),
51 };
52 
53 // Object implementation
54 FXIMPLEMENT(GUIGLObjectPopupMenu, FXMenuPane, GUIGLObjectPopupMenuMap, ARRAYNUMBER(GUIGLObjectPopupMenuMap))
55 
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 
62  FXMenuPane(&parent),
63  myParent(&parent),
64  myObject(&o),
65  myApplication(&app),
66  myNetworkPosition(parent.getPositionInformation()) {
67 }
68 
69 
71  // Delete MenuPane children
72  for (auto i : myMenuPanes) {
73  delete i;
74  }
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 
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:180
GUIGLObjectPopupMenu::onCmdRemoveSelected
long onCmdRemoveSelected(FXObject *, FXSelector, void *)
Called if the object shall be removed from the list of selected objects.
Definition: GUIGLObjectPopupMenu.cpp:168
GUIGlObject.h
ToString.h
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:72
GUIGLObjectPopupMenu::onCmdCopyName
long onCmdCopyName(FXObject *, FXSelector, void *)
Called if the name shall be copied to clipboard.
Definition: GUIGLObjectPopupMenu.cpp:105
GUIGlObject::getTypeParameterWindow
virtual GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window (optional)
Definition: GUIGlObject.cpp:155
GUIGLObjectPopupMenu::insertMenuPaneChild
void insertMenuPaneChild(FXMenuPane *child)
Insert a sub-menu pane in this GUIGLObjectPopupMenu.
Definition: GUIGLObjectPopupMenu.cpp:80
GUIParameterTableWindow.h
MID_COPY_CURSOR_GEOPOSITION
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:390
GUIUserIO::copyToClipboard
static void copyToClipboard(const FXApp &app, const std::string &text)
Copies the given text to clipboard.
Definition: GUIUserIO.cpp:37
GUIGLObjectPopupMenu::onCmdCopyEdgeName
long onCmdCopyEdgeName(FXObject *, FXSelector, void *)
Called if the edge name shall be copied to clipboard (for lanes only)
Definition: GUIGLObjectPopupMenu.cpp:119
GUIGlObject::getParameterWindow
virtual GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)=0
Returns an own parameter window.
GUIGLObjectPopupMenu::~GUIGLObjectPopupMenu
virtual ~GUIGLObjectPopupMenu()
Destructor.
Definition: GUIGLObjectPopupMenu.cpp:70
GUIGlObject::removedPopupMenu
virtual void removedPopupMenu()
notify object about popup menu removal
Definition: GUIGlObject.h:111
GUIGLObjectPopupMenu.h
GUIGlobalSelection.h
GUISUMOAbstractView::centerTo
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
Definition: GUISUMOAbstractView.cpp:789
GUIGLObjectPopupMenu::myNetworkPosition
Position myNetworkPosition
The position within the network the cursor was above when instanting the popup.
Definition: GUIGLObjectPopupMenu.h:117
GeoConvHelper.h
GUIGLObjectPopupMenu::myParent
GUISUMOAbstractView * myParent
The parent window.
Definition: GUIGLObjectPopupMenu.h:108
GUIGlObject::getFullName
const std::string & getFullName() const
Definition: GUIGlObject.cpp:137
MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:382
GUIGLObjectPopupMenu::onCmdCopyCursorPosition
long onCmdCopyCursorPosition(FXObject *, FXSelector, void *)
Called if the cursor position shall be copied to clipboard.
Definition: GUIGLObjectPopupMenu.cpp:127
GUIGLObjectPopupMenu
The popup menu of a globject.
Definition: GUIGLObjectPopupMenu.h:47
GUIGLObjectPopupMenu::onCmdCopyCursorGeoPosition
long onCmdCopyCursorGeoPosition(FXObject *, FXSelector, void *)
Called if the cursor geo-position shall be copied to clipboard.
Definition: GUIGLObjectPopupMenu.cpp:134
gPrecisionGeo
int gPrecisionGeo
Definition: StdDefs.cpp:27
MID_ADDSELECT
Add to selected items - menu entry.
Definition: GUIAppEnum.h:408
GUIAppEnum.h
MID_COPY_CURSOR_POSITION
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:388
GUISUMOAbstractView.h
MID_CENTER
Center view to object - popup entry.
Definition: GUIAppEnum.h:380
GUISelectedStorage::select
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
Definition: GUISelectedStorage.cpp:113
GeoConvHelper::getFinal
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: GeoConvHelper.h:105
MID_COPY_EDGE_NAME
Copy edge name (for lanes only)
Definition: GUIAppEnum.h:386
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:149
ProcessError
Definition: UtilExceptions.h:39
GeoConvHelper::cartesian2geo
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Definition: GeoConvHelper.cpp:293
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
GUIGLObjectPopupMenu::onCmdShowPars
long onCmdShowPars(FXObject *, FXSelector, void *)
Called if the parameter of this object shall be shown.
Definition: GUIGLObjectPopupMenu.cpp:145
GUIGLObjectPopupMenu::onCmdShowTypePars
long onCmdShowTypePars(FXObject *, FXSelector, void *)
Called if the type parameter of this object shall be shown.
Definition: GUIGLObjectPopupMenu.cpp:153
GLO_LANE
a lane
Definition: GUIGlObjectTypes.h:48
GUIGlObject
Definition: GUIGlObject.h:65
GUIGLObjectPopupMenu::onCmdCopyTypedName
long onCmdCopyTypedName(FXObject *, FXSelector, void *)
Called if the typed name shall be copied to clipboard.
Definition: GUIGLObjectPopupMenu.cpp:112
GUIGLObjectPopupMenu::myMenuPanes
std::vector< FXMenuPane * > myMenuPanes
vector mit Sub-MenuPanes
Definition: GUIGLObjectPopupMenu.h:120
GUIGLObjectPopupMenu::myObject
GUIGlObject * myObject
The object that belongs to this popup-menu.
Definition: GUIGLObjectPopupMenu.h:111
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
MID_SHOWPARS
Show object parameter - popup entry.
Definition: GUIAppEnum.h:394
GUIMainWindow
Definition: GUIMainWindow.h:46
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
GUIUserIO.h
gSelected
GUISelectedStorage gSelected
A global holder of selected objects.
Definition: GUIGlobalSelection.cpp:33
GUIGLObjectPopupMenu::myApplication
GUIMainWindow * myApplication
The main application.
Definition: GUIGLObjectPopupMenu.h:114
GUIGLObjectPopupMenu::onCmdAddSelected
long onCmdAddSelected(FXObject *, FXSelector, void *)
Called if the object shall be added to the list of selected objects.
Definition: GUIGLObjectPopupMenu.cpp:160
config.h
MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:384
FXDEFMAP
FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[]
GUIGlObject::getMicrosimID
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.cpp:163
MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:396
GUISelectedStorage::deselect
void deselect(GUIGlID id)
Deselects the object with the given id.
Definition: GUISelectedStorage.cpp:130
GUIGlObject::getParentName
virtual std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GUIGlObject.cpp:143
MID_REMOVESELECT
Remove from selected items - Menu Etry.
Definition: GUIAppEnum.h:410
GUIGLObjectPopupMenu::onCmdCenter
long onCmdCenter(FXObject *, FXSelector, void *)
Definition: GUIGLObjectPopupMenu.cpp:97