Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2023 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>
39
40// ===========================================================================
41// FOX callback mapping
42// ===========================================================================
57
58// Object implementation
59FXIMPLEMENT(GUIGLObjectPopupMenu, FXMenuPane, GUIGLObjectPopupMenuMap, ARRAYNUMBER(GUIGLObjectPopupMenuMap))
60
61
62// ===========================================================================
63// method definitions
64// ===========================================================================
65
67 FXMenuPane(&parent),
68 myParent(&parent),
69 myObject(&o),
70 myApplication(&app),
71 myPopupType(PopupType::ATTRIBUTES),
72 myNetworkPosition(parent.getPositionInformation()) {
73}
74
75
77 FXMenuPane(parent),
78 myParent(parent),
79 myObject(nullptr),
80 myApplication(app),
81 myPopupType(popupType),
82 myNetworkPosition(parent->getPositionInformation()) {
83}
84
85
87 // Delete MenuPane children
88 for (const auto& pane : myMenuPanes) {
89 delete pane;
90 }
91}
92
93
94void
96 // Check that MenuPaneChild isn't NULL
97 if (child == nullptr) {
98 throw ProcessError("MenuPaneChild cannot be NULL");
99 }
100 // Check that MenuPaneChild wasn't already inserted
101 for (const auto& pane : myMenuPanes) {
102 if (pane == child) {
103 throw ProcessError("MenuPaneChild already inserted");
104 }
105 }
106 // Insert MenuPaneChild
107 myMenuPanes.push_back(child);
108}
109
110
111void
113 // remove popup menu from object
114 if (myObject) {
116 }
117}
118
123
124
129
130
131long
132GUIGLObjectPopupMenu::onCmdCenter(FXObject*, FXSelector, void*) {
133 // we already know where the object is since we clicked on it -> zoom on Boundary
134 if (myObject) {
135 myParent->centerTo(myObject->getGlID(), true, -1);
136 } else {
137 throw ProcessError("Object is NULL");
138 }
139 return 1;
140}
141
142
143long
144GUIGLObjectPopupMenu::onCmdCopyName(FXObject*, FXSelector, void*) {
145 if (myObject) {
147 } else {
148 throw ProcessError("Object is NULL");
149 }
150 return 1;
151}
152
153
154long
155GUIGLObjectPopupMenu::onCmdCopyTypedName(FXObject*, FXSelector, void*) {
156 if (myObject) {
158 } else {
159 throw ProcessError("Object is NULL");
160 }
161 return 1;
162}
163
164
165long
166GUIGLObjectPopupMenu::onCmdCopyEdgeName(FXObject*, FXSelector, void*) {
167 if (myObject == nullptr) {
168 throw ProcessError("Object is NULL");
169 } else if (myObject->getType() != GLO_LANE) {
170 throw ProcessError(TL("Object must be a lane"));
171 } else {
173 }
174 return 1;
175}
176
177
178long
181 return 1;
182}
183
184
185long
189 // formatted for pasting into google maps
190 const std::string posString = toString(pos.y(), gPrecisionGeo) + ", " + toString(pos.x(), gPrecisionGeo);
191 GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
192 return 1;
193}
194
195
196long
199 Position lowLeft(b.xmin(), b.ymin());
201 Position upRight(b.xmax(), b.ymax());
203 // formatted for usage with osmconvert
204 const std::string posString = toString(lowLeft.x(), gPrecisionGeo) + "," + toString(lowLeft.y(), gPrecisionGeo) + "," +
205 toString(upRight.x(), gPrecisionGeo) + "," + toString(upRight.y(), gPrecisionGeo);
206 GUIUserIO::copyToClipboard(*myParent->getApp(), posString);
207 return 1;
208}
209
210
211long
213 FXMenuCommand* const mc = dynamic_cast<FXMenuCommand*>(item);
216 std::string url = myApplication->getOnlineMaps().find(mc->getText().rafter(' ').text())->second;
217 url = StringUtils::replace(StringUtils::replace(url, "%lat", toString(pos.y(), gPrecisionGeo)), "%lon", toString(pos.x(), gPrecisionGeo));
218 MFXLinkLabel::fxexecute(url.c_str());
219 return 1;
220}
221
222
223long
224GUIGLObjectPopupMenu::onCmdShowPars(FXObject*, FXSelector, void*) {
225 if (myObject) {
227 } else {
228 throw ProcessError("Object is NULL");
229 }
230 return 1;
231}
232
233
234
235long
236GUIGLObjectPopupMenu::onCmdShowTypePars(FXObject*, FXSelector, void*) {
237 if (myObject) {
239 } else {
240 throw ProcessError("Object is NULL");
241 }
242 return 1;
243}
244
245
246long
247GUIGLObjectPopupMenu::onCmdAddSelected(FXObject*, FXSelector, void*) {
248 if (myObject) {
250 myParent->update();
251 } else {
252 throw ProcessError("Object is NULL");
253 }
254 return 1;
255}
256
257
258long
259GUIGLObjectPopupMenu::onCmdRemoveSelected(FXObject*, FXSelector, void*) {
260 if (myObject) {
262 myParent->update();
263 } else {
264 throw ProcessError("Object is NULL");
265 }
266 return 1;
267}
268
269
271 FXMenuPane(),
272 myParent(nullptr),
273 myObject(nullptr),
274 myApplication(nullptr),
275 myPopupType(PopupType::PROPERTIES) {
276}
277
278/****************************************************************************/
@ MID_ADDSELECT
Add to selected items - menu entry.
Definition GUIAppEnum.h:478
@ MID_COPY_CURSOR_GEOPOSITION
Copy cursor geo-coordinate position - popup entry.
Definition GUIAppEnum.h:456
@ MID_CENTER
Center view to object - popup entry.
Definition GUIAppEnum.h:446
@ MID_SHOW_GEOPOSITION_ONLINE
Show the cursor geo-coordinate position online in GeoHack - popup entry.
Definition GUIAppEnum.h:460
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition GUIAppEnum.h:450
@ MID_COPY_EDGE_NAME
Copy edge name (for lanes only)
Definition GUIAppEnum.h:452
@ MID_COPY_CURSOR_POSITION
Copy cursor position - popup entry.
Definition GUIAppEnum.h:454
@ MID_SHOWPARS
Show object parameter - popup entry.
Definition GUIAppEnum.h:464
@ MID_COPY_NAME
Copy object name - popup entry.
Definition GUIAppEnum.h:448
@ MID_COPY_VIEW_GEOBOUNDARY
Copy view geo-coordinate boundary - popup entry.
Definition GUIAppEnum.h:458
@ MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition GUIAppEnum.h:466
@ MID_REMOVESELECT
Remove from selected items - Menu Entry.
Definition GUIAppEnum.h:480
FXDEFMAP(GUIGLObjectPopupMenu) GUIGLObjectPopupMenuMap[]
@ GLO_LANE
a lane
GUISelectedStorage gSelected
A global holder of selected objects.
#define TL(string)
Definition MsgHandler.h:287
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.
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.
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 & 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)
const std::string & getFullName() const
Definition GUIGlObject.h:92
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
virtual GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)=0
Returns an own parameter window.
GUIGlID getGlID() const
Returns the numerical id of the object.
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
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
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.