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.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/****************************************************************************/
22// A single child window which contains a view of the simulation area
23/****************************************************************************/
24
32#include <guisim/GUIPerson.h>
33#include <guisim/GUIEdge.h>
34#include <guisim/GUILane.h>
35#include <guisim/GUINet.h>
38
39#include "GUIViewTraffic.h"
41#include "GUISUMOViewParent.h"
42
44
45#include <osgview/GUIOSGView.h>
46
47#define SPEEDFACTOR_SCALE 100.0
48
49// ===========================================================================
50// FOX callback mapping
51// ===========================================================================
52FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
54 // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
64
67 FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
68
69};
70
71// Object implementation
72FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
73
74
75// ===========================================================================
76// member method definitions
77// ===========================================================================
78GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
79 const FXString& name,
80 GUIMainWindow* parentWindow,
81 FXIcon* ic, FXuint opts,
82 FXint x, FXint y, FXint w, FXint h) :
83 GUIGlChildWindow(p, parentWindow, mdimenu, name, nullptr, ic, opts, x, y, w, h) {
84 buildSpeedControlToolbar();
85 myGUIMainWindowParent->addGLChild(this);
86}
87
88
91 switch (type) {
92 default:
93 case VIEW_2D_OPENGL:
95 break;
96#ifdef HAVE_OSG
97 case VIEW_3D_OSG:
99 break;
100#endif
101 }
105 }
106 return myView;
107}
108
109
112}
113
114
115void
117 if (value) {
119 } else {
121 }
122}
123
124
125void
127 myGLObjChooser[GLObjChooser->getMessageId()] = nullptr;
128}
129
130
131long
132GUISUMOViewParent::onCmdMakeSnapshot(FXObject* sender, FXSelector, void*) {
133 MFXCheckableButton* button = dynamic_cast<MFXCheckableButton*>(sender);
134 // check if cast was successfully
135 if (button) {
136 if (button->amChecked()) {
138 button->setChecked(false);
139 return 1;
140 }
141 // get the new file name
142 FXFileDialog opendialog(this, TL("Save Snapshot"));
143 opendialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::CAMERA));
144 opendialog.setSelectMode(SELECTFILE_ANY);
145#ifdef HAVE_FFMPEG
146 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"
147 "All Video Files (*.h264,*.hevc,*.mp4)\n"
148#else
149 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"
150#endif
151 "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
152 "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
153 "JPEG Image (*.jpg,*.jpeg)\nTIFF Image (*.tif,*.tiff)\n"
154 "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
155 "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
156 "All Files (*)");
157 if (gCurrentFolder.length() != 0) {
158 opendialog.setDirectory(gCurrentFolder);
159 }
160 if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
161 return 1;
162 }
163 gCurrentFolder = opendialog.getDirectory();
164 std::string file = opendialog.getFilename().text();
165 if (file.find(".") == std::string::npos) {
166 file.append(".png");
167 WRITE_MESSAGE(TL("No file extension was specified - saving Snapshot as PNG."));
168 }
169 std::string error = myView->makeSnapshot(file);
170 if (error == "video") {
171 button->setChecked(!button->amChecked());
172 } else if (error != "") {
173 FXMessageBox::error(this, MBOX_OK, TL("Saving failed."), "%s", error.c_str());
174 } else {
175 WRITE_MESSAGE(TL("Snapshot successfully saved!"));
176 }
177 }
178 return 1;
179}
180
181
182std::vector<GUIGlID>
184 switch (messageId) {
186 return static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myGUIMainWindowParent->listInternal());
190 std::vector<GUIGlID> vehicles;
192 static_cast<GUIMEVehicleControl*>(static_cast<GUINet*>(MSNet::getInstance())->getGUIMEVehicleControl())->insertVehicleIDs(vehicles);
193 } else {
194 static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(
196 }
197 return vehicles;
198 }
200 std::vector<GUIGlID> persons;
201 static_cast<GUITransportableControl&>(MSNet::getInstance()->getPersonControl()).insertIDs(persons);
202 return persons;
203 }
205 // get containers
206 std::vector<GUIGlID> containers;
207 static_cast<GUITransportableControl&>(MSNet::getInstance()->getContainerControl()).insertIDs(containers);
208 return containers;
209 }
211 return static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
215 return static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
217 return static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
218 default:
219 throw ProcessError(TL("Unknown Message ID in onCmdLocate"));
220 }
221}
222
223
224long
225GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
226 int messageId = FXSELID(sel);
227 if (myGLObjChooser.count(messageId) == 0 || myGLObjChooser[messageId] == nullptr) {
228 FXIcon* icon = nullptr;
229 std::string titleString = "";
230 switch (messageId) {
233 titleString = TL("Junction Chooser");
234 break;
237 titleString = TL("Edge Chooser");
238 break;
241 titleString = TL("Vehicle Chooser");
242 break;
245 titleString = TL("Person Chooser");
246 break;
249 titleString = TL("Container Chooser");
250 break;
253 titleString = TL("Traffic Lights Chooser");
254 break;
257 titleString = TL("Additional Objects Chooser");
258 break;
261 titleString = TL("POI Chooser");
262 break;
265 titleString = TL("Polygon Chooser");
266 break;
267 default:
268 throw ProcessError(TL("Unknown Message ID in onCmdLocate"));
269 }
270
271 myGLObjChooser[messageId] = new GUIDialog_GLObjChooser(this, messageId, icon, titleString.c_str(), getObjectIDs(messageId), GUIGlObjectStorage::gIDStorage);
272
273 } else {
274 myGLObjChooser[messageId]->restore();
275 myGLObjChooser[messageId]->setFocus();
276 myGLObjChooser[messageId]->raise();
277 }
278 myLocatorPopup->popdown();
279 myLocatorButton->killFocus();
280 myLocatorPopup->update();
281 return 1;
282}
283
284
285long
286GUISUMOViewParent::onSimStep(FXObject*, FXSelector, void*) {
287 myView->update();
289 return 1;
290}
291
292
293bool
295 GUIGlObjectType type = o->getType();
296 if (gSelected.isSelected(type, o->getGlID())) {
297 return true;
298 } else if (type == GLO_EDGE) {
299 GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
300 if (edge == nullptr) {
301 // hmph, just some security stuff
302 return false;
303 }
304 const std::vector<MSLane*>& lanes = edge->getLanes();
305 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
306 GUILane* l = dynamic_cast<GUILane*>(*j);
307 if (l != nullptr && gSelected.isSelected(GLO_LANE, l->getGlID())) {
308 return true;
309 }
310 }
311 return false;
312 } else {
313 return false;
314 }
315}
316
317
318long
319GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* ptr) {
320 myView->onKeyPress(o, sel, ptr);
321 return 0;
322}
323
324
325long
326GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* ptr) {
327 myView->onKeyRelease(o, sel, ptr);
328 return 0;
329}
330
331
332void
335 new FXVerticalSeparator(toolbar, GUIDesignVerticalSeparator);
336
337 //myToolBarDragSpeed = new FXToolBarShell(this, GUIDesignToolBar);
338 //myToolBarSpeed = new FXToolBar(toolbar, myToolBarDragSpeed, GUIDesignToolBarRaisedSameTop);
339 //mySpeedFactorSlider = new FXSlider(myToolBarSpeed, this, MID_SPEEDFACTOR, LAYOUT_FIX_WIDTH | SLIDER_ARROW_UP | SLIDER_TICKS_TOP, 0, 0, 300, 10, 0, 0, 5, 0);
340 mySpeedFactorSlider = new FXSlider(toolbar, this, MID_SPEEDFACTOR, LAYOUT_FIX_WIDTH | SLIDER_ARROW_UP | SLIDER_TICKS_TOP, 0, 0, 200, 10, 0, 0, 5, 0);
341 mySpeedFactorSlider->setRange(0, 200);
342 mySpeedFactorSlider->setHeadSize(10);
343 mySpeedFactorSlider->setIncrement(1);
344 mySpeedFactorSlider->setTickDelta(100);
345 mySpeedFactorSlider->setValue(100);
346 mySpeedFactorSlider->setHelpText("Control speedFactor of tracked object");
347 //mySpeedFactorSlider->hide();
348}
349
350long
351GUISUMOViewParent::onCmdSpeedFactor(FXObject*, FXSelector, void*) {
352 if (myView != nullptr && myView->getTrackedID() != GUIGlObject::INVALID_ID) {
354 if (o != nullptr) {
355 const double speedFactor = mySpeedFactorSlider->getValue() / SPEEDFACTOR_SCALE;
356 if (o->getType() == GLO_VEHICLE) {
357 MSBaseVehicle* veh = dynamic_cast<MSBaseVehicle*>(o);
358 veh->setChosenSpeedFactor(speedFactor);
359 } else if (o->getType() == GLO_PERSON) {
360 //MSPerson* person = dynamic_cast<MSPerson*>(o);
361 //person->setChosenSpeedFactor(speedFactor);
362 }
363 mySpeedFactorSlider->setTipText(toString(speedFactor).c_str());
364 }
365
366 }
367 return 1;
368}
369
370long
371GUISUMOViewParent::onUpdSpeedFactor(FXObject* sender, FXSelector, void* ptr) {
372 bool disable = myView == nullptr || myView->getTrackedID() == GUIGlObject::INVALID_ID;
373 sender->handle(this, FXSEL(SEL_COMMAND, disable ? ID_DISABLE : ID_ENABLE), ptr);
374 if (disable) {
375 mySpeedFactorSlider->hide();
376 } else {
378 if (o != nullptr) {
379 if (o->getType() == GLO_VEHICLE) {
380 MSBaseVehicle* veh = dynamic_cast<MSBaseVehicle*>(o);
382 } else if (o->getType() == GLO_PERSON) {
383 MSPerson* person = dynamic_cast<MSPerson*>(o);
384 mySpeedFactorSlider->setValue((int)(person->getChosenSpeedFactor() * SPEEDFACTOR_SCALE));
385 }
386 mySpeedFactorSlider->show();
387 } else {
388 myView->stopTrack();
389 mySpeedFactorSlider->hide();
390 }
391 }
392 return 1;
393}
394
395
396/****************************************************************************/
@ MID_MAKESNAPSHOT
Make snapshot - button.
Definition: GUIAppEnum.h:384
@ MID_SPEEDFACTOR
scale vehicle speed
Definition: GUIAppEnum.h:398
@ MID_HOTKEY_SHIFT_O_LOCATEPOI
Locate poi - button.
Definition: GUIAppEnum.h:179
@ MID_HOTKEY_SHIFT_A_LOCATEADDITIONAL
Locate additional structure - button.
Definition: GUIAppEnum.h:169
@ MID_HOTKEY_SHIFT_C_LOCATECONTAINER
Locate container - button.
Definition: GUIAppEnum.h:171
@ MID_HOTKEY_SHIFT_V_LOCATEVEHICLE
Locate vehicle - button.
Definition: GUIAppEnum.h:189
@ MID_SIMSTEP
A Simulation step was performed.
Definition: GUIAppEnum.h:534
@ MID_HOTKEY_SHIFT_L_LOCATEPOLY
Locate polygons - button.
Definition: GUIAppEnum.h:177
@ MID_HOTKEY_SHIFT_E_LOCATEEDGE
Locate edge - button.
Definition: GUIAppEnum.h:173
@ MID_HOTKEY_SHIFT_P_LOCATEPERSON
Locate person - button.
Definition: GUIAppEnum.h:181
@ MID_HOTKEY_SHIFT_J_LOCATEJUNCTION
Locate junction - button.
Definition: GUIAppEnum.h:175
@ MID_HOTKEY_SHIFT_T_LOCATETLS
Locate TLS - button.
Definition: GUIAppEnum.h:187
#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:272
#define TL(string)
Definition: MsgHandler.h:287
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:51
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition: GUIEdge.cpp:103
GUIMainWindow * myGUIMainWindowParent
FOX needs this.
GUISUMOAbstractView * myView
The view.
FXPopup * myLocatorPopup
The locator menu.
MFXMenuButtonTooltip * myLocatorButton
The locator button.
FXVerticalFrame * myChildWindowContentFrame
The contents frame.
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, const bool inform=false)
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:1181
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:503
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:380
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1172
double getChosenSpeedFactor() const
the current speed factor of the transportable (where applicable)
Definition: MSPerson.h:267