Eclipse SUMO - Simulation of Urban MObility
GUISUMOViewParent.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-2022 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/****************************************************************************/
22// A single child window which contains a view of the simulation area
23/****************************************************************************/
24#include <config.h>
25
26#include <string>
27#include <vector>
28#include <fxkeys.h>
30#include <utils/geom/Position.h>
31#include <utils/geom/Boundary.h>
46#include <guisim/GUIVehicle.h>
47#include <guisim/GUIPerson.h>
48#include <guisim/GUIEdge.h>
49#include <guisim/GUILane.h>
50#include <guisim/GUINet.h>
53#include <microsim/MSJunction.h>
54#include <microsim/MSGlobals.h>
55
56#include "GUIGlobals.h"
57#include "GUIViewTraffic.h"
59#include "GUISUMOViewParent.h"
60
62
63#include <osgview/GUIOSGView.h>
64
65#define SPEEDFACTOR_SCALE 100.0
66
67// ===========================================================================
68// FOX callback mapping
69// ===========================================================================
70FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
72 // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
74 FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
76 FXMAPFUNC(SEL_COMMAND, MID_LOCATEPERSON, GUISUMOViewParent::onCmdLocate),
78 FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
79 FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
80 FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
81 FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
84 FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
85
86};
87
88// Object implementation
89FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
90
91
92// ===========================================================================
93// member method definitions
94// ===========================================================================
95GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
96 const FXString& name,
97 GUIMainWindow* parentWindow,
98 FXIcon* ic, FXuint opts,
99 FXint x, FXint y, FXint w, FXint h) :
100 GUIGlChildWindow(p, parentWindow, mdimenu, name, nullptr, ic, opts, x, y, w, h) {
101 buildSpeedControlToolbar();
102 myParent->addGLChild(this);
103}
104
105
108 switch (type) {
109 default:
110 case VIEW_2D_OPENGL:
112 break;
113#ifdef HAVE_OSG
114 case VIEW_3D_OSG:
115 myView = new GUIOSGView(myChildWindowContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
116 break;
117#endif
118 }
120 if (myParent->isGaming()) {
122 }
123 return myView;
124}
125
126
128 myParent->removeGLChild(this);
129}
130
131
132void
134 if (value) {
136 } else {
138 }
139}
140
141
142void
144 myGLObjChooser[GLObjChooser->getMessageId()] = nullptr;
145}
146
147
148long
149GUISUMOViewParent::onCmdMakeSnapshot(FXObject* sender, FXSelector, void*) {
150 MFXCheckableButton* button = dynamic_cast<MFXCheckableButton*>(sender);
151 // check if cast was successfully
152 if (button) {
153 if (button->amChecked()) {
155 button->setChecked(false);
156 return 1;
157 }
158 // get the new file name
159 FXFileDialog opendialog(this, TL("Save Snapshot"));
160 opendialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::CAMERA));
161 opendialog.setSelectMode(SELECTFILE_ANY);
162#ifdef HAVE_FFMPEG
163 opendialog.setPatternList("All Image and Video Files (*.gif,*.bmp,*.xpm,*.pcx,*.ico,*.rgb,*.xbm,*.tga,*.png,*.jpg,*.jpeg,*.tif,*.tiff,*.ps,*.eps,*.pdf,*.svg,*.tex,*.pgf,*.h264,*.hevc,*.mp4)\n"
164 "All Video Files (*.h264,*.hevc,*.mp4)\n"
165#else
166 opendialog.setPatternList("All Image Files (*.gif,*.bmp,*.xpm,*.pcx,*.ico,*.rgb,*.xbm,*.tga,*.png,*.jpg,*.jpeg,*.tif,*.tiff,*.ps,*.eps,*.pdf,*.svg,*.tex,*.pgf)\n"
167#endif
168 "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
169 "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
170 "JPEG Image (*.jpg,*.jpeg)\nTIFF Image (*.tif,*.tiff)\n"
171 "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
172 "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
173 "All Files (*)");
174 if (gCurrentFolder.length() != 0) {
175 opendialog.setDirectory(gCurrentFolder);
176 }
177 if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
178 return 1;
179 }
180 gCurrentFolder = opendialog.getDirectory();
181 std::string file = opendialog.getFilename().text();
182 if (file.find(".") == std::string::npos) {
183 file.append(".png");
184 WRITE_MESSAGE(TL("No file extension was specified - saving Snapshot as PNG."));
185 }
186 std::string error = myView->makeSnapshot(file);
187 if (error == "video") {
188 button->setChecked(!button->amChecked());
189 } else if (error != "") {
190 FXMessageBox::error(this, MBOX_OK, TL("Saving failed."), "%s", error.c_str());
191 } else {
192 WRITE_MESSAGE(TL("Snapshot successfully saved!"));
193 }
194 }
195 return 1;
196}
197
198
199std::vector<GUIGlID>
201 switch (messageId) {
203 return static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
204 case MID_LOCATEEDGE:
206 case MID_LOCATEVEHICLE: {
207 std::vector<GUIGlID> vehicles;
209 static_cast<GUIMEVehicleControl*>(static_cast<GUINet*>(MSNet::getInstance())->getGUIMEVehicleControl())->insertVehicleIDs(vehicles);
210 } else {
211 static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(
213 }
214 return vehicles;
215 }
216 case MID_LOCATEPERSON: {
217 std::vector<GUIGlID> persons;
218 static_cast<GUITransportableControl&>(MSNet::getInstance()->getPersonControl()).insertIDs(persons);
219 return persons;
220 }
221 case MID_LOCATECONTAINER: {
222 // get containers
223 std::vector<GUIGlID> containers;
224 static_cast<GUITransportableControl&>(MSNet::getInstance()->getContainerControl()).insertIDs(containers);
225 return containers;
226 }
227 case MID_LOCATETLS:
228 return static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
229 case MID_LOCATEADD:
231 case MID_LOCATEPOI:
232 return static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
233 case MID_LOCATEPOLY:
234 return static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
235 default:
236 throw ProcessError("Unknown Message ID in onCmdLocate");
237 }
238}
239
240
241long
242GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
243 int messageId = FXSELID(sel);
244 if (myGLObjChooser.count(messageId) == 0 || myGLObjChooser[messageId] == nullptr) {
245 FXIcon* icon = nullptr;
246 std::string titleString = "";
247 switch (messageId) {
250 titleString = "Junction Chooser";
251 break;
252 case MID_LOCATEEDGE:
254 titleString = "Edge Chooser";
255 break;
258 titleString = "Vehicle Chooser";
259 break;
260 case MID_LOCATEPERSON:
262 titleString = "Person Chooser";
263 break;
266 titleString = "Container Chooser";
267 break;
268 case MID_LOCATETLS:
270 titleString = "Traffic Lights Chooser";
271 break;
272 case MID_LOCATEADD:
274 titleString = "Additional Objects Chooser";
275 break;
276 case MID_LOCATEPOI:
278 titleString = "POI Chooser";
279 break;
280 case MID_LOCATEPOLY:
282 titleString = "Polygon Chooser";
283 break;
284 default:
285 throw ProcessError("Unknown Message ID in onCmdLocate");
286 }
287
288 myGLObjChooser[messageId] = new GUIDialog_GLObjChooser(this, messageId, icon, titleString.c_str(), getObjectIDs(messageId), GUIGlObjectStorage::gIDStorage);
289
290 } else {
291 myGLObjChooser[messageId]->restore();
292 myGLObjChooser[messageId]->setFocus();
293 myGLObjChooser[messageId]->raise();
294 }
295 myLocatorPopup->popdown();
296 myLocatorButton->killFocus();
297 myLocatorPopup->update();
298 return 1;
299}
300
301
302long
303GUISUMOViewParent::onSimStep(FXObject*, FXSelector, void*) {
304 myView->update();
306 return 1;
307}
308
309
310bool
312 GUIGlObjectType type = o->getType();
313 if (gSelected.isSelected(type, o->getGlID())) {
314 return true;
315 } else if (type == GLO_EDGE) {
316 GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
317 if (edge == nullptr) {
318 // hmph, just some security stuff
319 return false;
320 }
321 const std::vector<MSLane*>& lanes = edge->getLanes();
322 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
323 GUILane* l = dynamic_cast<GUILane*>(*j);
324 if (l != nullptr && gSelected.isSelected(GLO_LANE, l->getGlID())) {
325 return true;
326 }
327 }
328 return false;
329 } else {
330 return false;
331 }
332}
333
334
335long
336GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* ptr) {
337 myView->onKeyPress(o, sel, ptr);
338 return 0;
339}
340
341
342long
343GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* ptr) {
344 myView->onKeyRelease(o, sel, ptr);
345 return 0;
346}
347
348
349void
352 new FXVerticalSeparator(toolbar, GUIDesignVerticalSeparator);
353
354 //myToolBarDragSpeed = new FXToolBarShell(this, GUIDesignToolBar);
355 //myToolBarSpeed = new FXToolBar(toolbar, myToolBarDragSpeed, GUIDesignToolBarRaisedSameTop);
356 //mySpeedFactorSlider = new FXSlider(myToolBarSpeed, this, MID_SPEEDFACTOR, LAYOUT_FIX_WIDTH | SLIDER_ARROW_UP | SLIDER_TICKS_TOP, 0, 0, 300, 10, 0, 0, 5, 0);
357 mySpeedFactorSlider = new FXSlider(toolbar, this, MID_SPEEDFACTOR, LAYOUT_FIX_WIDTH | SLIDER_ARROW_UP | SLIDER_TICKS_TOP, 0, 0, 200, 10, 0, 0, 5, 0);
358 mySpeedFactorSlider->setRange(0, 200);
359 mySpeedFactorSlider->setHeadSize(10);
360 mySpeedFactorSlider->setIncrement(1);
361 mySpeedFactorSlider->setTickDelta(100);
362 mySpeedFactorSlider->setValue(100);
363 mySpeedFactorSlider->setHelpText("Control speedFactor of tracked object");
364 //mySpeedFactorSlider->hide();
365}
366
367long
368GUISUMOViewParent::onCmdSpeedFactor(FXObject*, FXSelector, void*) {
369 if (myView != nullptr && myView->getTrackedID() != GUIGlObject::INVALID_ID) {
371 if (o != nullptr) {
372 const double speedFactor = mySpeedFactorSlider->getValue() / SPEEDFACTOR_SCALE;
373 if (o->getType() == GLO_VEHICLE) {
374 MSBaseVehicle* veh = dynamic_cast<MSBaseVehicle*>(o);
375 veh->setChosenSpeedFactor(speedFactor);
376 } else if (o->getType() == GLO_PERSON) {
377 //MSPerson* person = dynamic_cast<MSPerson*>(o);
378 //person->setChosenSpeedFactor(speedFactor);
379 }
380 mySpeedFactorSlider->setTipText(toString(speedFactor).c_str());
381 }
382
383 }
384 return 1;
385}
386
387long
388GUISUMOViewParent::onUpdSpeedFactor(FXObject* sender, FXSelector, void* ptr) {
389 bool disable = myView == nullptr || myView->getTrackedID() == GUIGlObject::INVALID_ID;
390 sender->handle(this, FXSEL(SEL_COMMAND, disable ? ID_DISABLE : ID_ENABLE), ptr);
391 if (disable) {
392 mySpeedFactorSlider->hide();
393 } else {
395 if (o != nullptr) {
396 if (o->getType() == GLO_VEHICLE) {
397 MSBaseVehicle* veh = dynamic_cast<MSBaseVehicle*>(o);
399 } else if (o->getType() == GLO_PERSON) {
400 MSPerson* person = dynamic_cast<MSPerson*>(o);
401 mySpeedFactorSlider->setValue((int)(person->getChosenSpeedFactor() * SPEEDFACTOR_SCALE));
402 }
403 mySpeedFactorSlider->show();
404 } else {
405 myView->stopTrack();
406 mySpeedFactorSlider->hide();
407 }
408 }
409 return 1;
410}
411
412
413/****************************************************************************/
@ MID_MAKESNAPSHOT
Make snapshot - button.
Definition: GUIAppEnum.h:385
@ MID_LOCATEPERSON
Locate person - button.
Definition: GUIAppEnum.h:369
@ MID_LOCATEJUNCTION
Locate junction - button.
Definition: GUIAppEnum.h:357
@ MID_LOCATEPOLY
Locate polygons - button.
Definition: GUIAppEnum.h:379
@ MID_SPEEDFACTOR
scale vehicle speed
Definition: GUIAppEnum.h:399
@ MID_LOCATEADD
Locate additional structure - button.
Definition: GUIAppEnum.h:375
@ MID_LOCATEPOI
Locate poi - button.
Definition: GUIAppEnum.h:377
@ MID_SIMSTEP
A Simulation step was performed.
Definition: GUIAppEnum.h:532
@ MID_LOCATEEDGE
Locate edge - button.
Definition: GUIAppEnum.h:359
@ MID_LOCATEVEHICLE
Locate vehicle - button.
Definition: GUIAppEnum.h:363
@ MID_LOCATETLS
Locate TLS - button.
Definition: GUIAppEnum.h:373
@ MID_LOCATECONTAINER
Locate container - button.
Definition: GUIAppEnum.h:371
#define GUIDesignVerticalSeparator
vertical separator
Definition: GUIDesigns.h:455
GUIGlObjectType
@ GLO_LANE
a lane
@ GLO_ADDITIONALELEMENT
reserved GLO type for packing all additionals elements
@ GLO_EDGE
an edge
@ GLO_VEHICLE
a vehicle
@ GLO_PERSON
a person
GUISelectedStorage gSelected
A global holder of selected objects.
FXString gCurrentFolder
The folder used as last.
@ LOCATEVEHICLE
@ LOCATEPERSON
@ LOCATECONTAINER
@ LOCATEJUNCTION
#define SPEEDFACTOR_SCALE
FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[]
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:267
#define TL(string)
Definition: MsgHandler.h:282
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:50
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition: GUIEdge.cpp:103
GUISUMOAbstractView * myView
The view.
FXPopup * myLocatorPopup
The locator menu.
MFXMenuButtonTooltip * myLocatorButton
The locator button.
FXVerticalFrame * myChildWindowContentFrame
The contents frame.
GUIMainWindow * myParent
FOX needs this.
FXToolBar * myStaticNavigationToolBar
The static navigation tool bar.
FXMenuBar * myGripNavigationToolbar
The grip navigation tool bar.
static std::vector< GUIGlID > getIDList(GUIGlObjectType typeFilter)
Returns the list of gl-ids of all additional objects that match the given type.
static const GUIGlID INVALID_ID
Definition: GUIGlObject.h:71
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
GUIGlObject * getObjectBlocking(GUIGlID id) const
Returns the object from the container locking it.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:60
The class responsible for building and deletion of vehicles (gui-version)
bool isGaming() const
return whether the gui is in gaming mode
bool listTeleporting() const
return whether to list teleporting vehicles
bool listParking() const
return whether to list parking vehicles
bool listInternal() const
return whether to list internal structures
FXGLVisual * getGLVisual() const
get GL Visual
void removeGLChild(GUIGlChildWindow *child)
removes the given child window from the list (GUIGlChildWindow)
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:82
std::string makeSnapshot(const std::string &destFile, const int w=-1, const int h=-1)
Takes a snapshots and writes it into the given file.
virtual void checkSnapshots()
Checks whether it is time for a snapshot.
virtual void endSnapshot()
Ends a video snapshot.
virtual void buildViewToolBars(GUIGlChildWindow *)
builds the view toolbars
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
keyboard functions
virtual void stopTrack()
stop track
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
virtual GUIGlID getTrackedID() const
get tracked id
A single child window which contains a view of the simulation area.
std::map< int, GUIDialog_ChooserAbstract * > myGLObjChooser
map for existing dialogs
bool isSelected(GUIGlObject *o) const
true if the object is selected (may include extra logic besides calling gSelected)
ViewType
Available view types.
@ VIEW_3D_OSG
plain 3D OSG view (
@ VIEW_2D_OPENGL
plain 2D openGL view (
long onCmdSpeedFactor(FXObject *, FXSelector, void *)
speedFactor-callback
void eraseGLObjChooser(GUIDialog_GLObjChooser *GLObjChooser)
erase GLObjChooser
virtual GUISUMOAbstractView * init(FXGLCanvas *share, GUINet &net, ViewType type)
"Initialises" this window by building the contents
long onCmdLocate(FXObject *, FXSelector, void *)
locator-callback
void buildSpeedControlToolbar()
fox need this
long onUpdSpeedFactor(FXObject *, FXSelector, void *)
long onKeyRelease(FXObject *o, FXSelector sel, void *data)
long onCmdMakeSnapshot(FXObject *sender, FXSelector, void *)
Called if the user wants to make a snapshot (screenshot)
long onSimStep(FXObject *sender, FXSelector, void *)
Called on a simulation step.
FXSlider * mySpeedFactorSlider
slider for speedfactor
void setToolBarVisibility(const bool value)
about toggled gaming status
long onKeyPress(FXObject *o, FXSelector sel, void *data)
handle keys
~GUISUMOViewParent()
Destructor.
std::vector< GUIGlID > getObjectIDs(int messageId) const
get all objects of the given type
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
Storage for geometrical objects extended by mutexes.
GUI-version of the transportable control for building gui persons and containers.
The class responsible for building and deletion of vehicles (gui-version)
bool amChecked() const
check if this MFXCheckableButton is checked
void setChecked(bool val)
check or uncheck this MFXCheckableButton
static FXbool userPermitsOverwritingWhenFileExists(FXWindow *const parent, const FXString &file)
Returns true if either the file given by its name does not exist or the user allows overwriting it.
Definition: MFXUtils.cpp:39
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:55
void setChosenSpeedFactor(const double factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
static bool gUseMesoSim
Definition: MSGlobals.h:103
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1105
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:502
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:379
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1096
double getChosenSpeedFactor() const
the current speed factor of the transportable (where applicable)
Definition: MSPerson.h:262