Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2025 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
113
114
115void
117 if (value) {
119 } else {
121 }
122}
123
124
125void
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(SUMOXMLDefinitions::ImageVideoFileExtensions.getMultilineString().c_str());
147#else
148 opendialog.setPatternList(SUMOXMLDefinitions::ImageFileExtensions.getMultilineString().c_str());
149#endif
150 if (gCurrentFolder.length() != 0) {
151 opendialog.setDirectory(gCurrentFolder);
152 }
153 if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
154 return 1;
155 }
156 gCurrentFolder = opendialog.getDirectory();
157 std::string file = opendialog.getFilename().text();
158 if (file.find(".") == std::string::npos) {
159 file.append(".png");
160 WRITE_MESSAGE(TL("No file extension was specified - saving Snapshot as PNG."));
161 }
162 std::string error = myView->makeSnapshot(file);
163 if (error == "video") {
164 button->setChecked(!button->amChecked());
165 } else if (error != "") {
166 FXMessageBox::error(this, MBOX_OK, TL("Saving failed."), "%s", error.c_str());
167 } else {
168 WRITE_MESSAGE(TL("Snapshot successfully saved!"));
169 }
170 }
171 return 1;
172}
173
174
175std::vector<GUIGlID>
177 switch (messageId) {
179 return static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myGUIMainWindowParent->listInternal());
183 std::vector<GUIGlID> vehicles;
185 static_cast<GUIMEVehicleControl*>(static_cast<GUINet*>(MSNet::getInstance())->getGUIMEVehicleControl())->insertVehicleIDs(vehicles);
186 } else {
187 static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(
189 }
190 return vehicles;
191 }
193 std::vector<GUIGlID> persons;
194 static_cast<GUITransportableControl&>(MSNet::getInstance()->getPersonControl()).insertIDs(persons);
195 return persons;
196 }
198 // get containers
199 std::vector<GUIGlID> containers;
200 static_cast<GUITransportableControl&>(MSNet::getInstance()->getContainerControl()).insertIDs(containers);
201 return containers;
202 }
204 return static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
208 return static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
210 return static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
211 default:
212 throw ProcessError(TL("Unknown Message ID in onCmdLocate"));
213 }
214}
215
216
217long
218GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
219 int messageId = FXSELID(sel);
220 if (myGLObjChooser.count(messageId) == 0 || myGLObjChooser[messageId] == nullptr) {
221 FXIcon* icon = nullptr;
222 std::string titleString = "";
223 switch (messageId) {
226 titleString = TL("Junction Chooser");
227 break;
230 titleString = TL("Edge Chooser");
231 break;
234 titleString = TL("Vehicle Chooser");
235 break;
238 titleString = TL("Person Chooser");
239 break;
242 titleString = TL("Container Chooser");
243 break;
246 titleString = TL("Traffic Lights Chooser");
247 break;
250 titleString = TL("Additional Objects Chooser");
251 break;
254 titleString = TL("POI Chooser");
255 break;
258 titleString = TL("Polygon Chooser");
259 break;
260 default:
261 throw ProcessError(TL("Unknown Message ID in onCmdLocate"));
262 }
263
264 myGLObjChooser[messageId] = new GUIDialog_GLObjChooser(this, messageId, icon, titleString.c_str(), getObjectIDs(messageId), GUIGlObjectStorage::gIDStorage);
265
266 } else {
267 myGLObjChooser[messageId]->restore();
268 myGLObjChooser[messageId]->setFocus();
269 myGLObjChooser[messageId]->raise();
270 }
271 myLocatorPopup->popdown();
272 myLocatorButton->killFocus();
273 myLocatorPopup->update();
274 return 1;
275}
276
277
278long
279GUISUMOViewParent::onSimStep(FXObject*, FXSelector, void*) {
280 myView->update();
282 return 1;
283}
284
285
286bool
288 GUIGlObjectType type = o->getType();
289 if (gSelected.isSelected(type, o->getGlID())) {
290 return true;
291 } else if (type == GLO_EDGE) {
292 GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
293 if (edge == nullptr) {
294 // hmph, just some security stuff
295 return false;
296 }
297 const std::vector<MSLane*>& lanes = edge->getLanes();
298 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
299 GUILane* l = dynamic_cast<GUILane*>(*j);
300 if (l != nullptr && gSelected.isSelected(GLO_LANE, l->getGlID())) {
301 return true;
302 }
303 }
304 return false;
305 } else {
306 return false;
307 }
308}
309
310
311long
312GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* ptr) {
313 myView->onKeyPress(o, sel, ptr);
314 return 0;
315}
316
317
318long
319GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* ptr) {
320 myView->onKeyRelease(o, sel, ptr);
321 return 0;
322}
323
324
325void
328 new FXVerticalSeparator(toolbar, GUIDesignVerticalSeparator);
329
330 //myToolBarDragSpeed = new FXToolBarShell(this, GUIDesignToolBar);
331 //myToolBarSpeed = new FXToolBar(toolbar, myToolBarDragSpeed, GUIDesignToolBarRaisedSameTop);
332 //mySpeedFactorSlider = new FXSlider(myToolBarSpeed, this, MID_SPEEDFACTOR, LAYOUT_FIX_WIDTH | SLIDER_ARROW_UP | SLIDER_TICKS_TOP, 0, 0, 300, 10, 0, 0, 5, 0);
333 mySpeedFactorSlider = new FXSlider(toolbar, this, MID_SPEEDFACTOR, LAYOUT_FIX_WIDTH | SLIDER_ARROW_UP | SLIDER_TICKS_TOP, 0, 0, 200, 10, 0, 0, 5, 0);
334 mySpeedFactorSlider->setRange(0, 200);
335 mySpeedFactorSlider->setHeadSize(10);
336 mySpeedFactorSlider->setIncrement(1);
337 mySpeedFactorSlider->setTickDelta(100);
338 mySpeedFactorSlider->setValue(100);
339 mySpeedFactorSlider->setHelpText("Control speedFactor of tracked object");
340 //mySpeedFactorSlider->hide();
341}
342
343long
344GUISUMOViewParent::onCmdSpeedFactor(FXObject*, FXSelector, void*) {
345 if (myView != nullptr && myView->getTrackedID() != GUIGlObject::INVALID_ID) {
347 if (o != nullptr) {
348 const double speedFactor = mySpeedFactorSlider->getValue() / SPEEDFACTOR_SCALE;
349 if (o->getType() == GLO_VEHICLE) {
350 MSBaseVehicle* veh = dynamic_cast<MSBaseVehicle*>(o);
351 veh->setChosenSpeedFactor(speedFactor);
352 } else if (o->getType() == GLO_PERSON) {
353 //MSPerson* person = dynamic_cast<MSPerson*>(o);
354 //person->setChosenSpeedFactor(speedFactor);
355 }
356 mySpeedFactorSlider->setTipText(toString(speedFactor).c_str());
357 }
358
359 }
360 return 1;
361}
362
363long
364GUISUMOViewParent::onUpdSpeedFactor(FXObject* sender, FXSelector, void* ptr) {
365 bool disable = myView == nullptr || myView->getTrackedID() == GUIGlObject::INVALID_ID;
366 sender->handle(this, FXSEL(SEL_COMMAND, disable ? ID_DISABLE : ID_ENABLE), ptr);
367 if (disable) {
368 mySpeedFactorSlider->hide();
369 } else {
371 if (o != nullptr) {
372 if (o->getType() == GLO_VEHICLE) {
373 MSBaseVehicle* veh = dynamic_cast<MSBaseVehicle*>(o);
375 } else if (o->getType() == GLO_PERSON) {
376 MSPerson* person = dynamic_cast<MSPerson*>(o);
377 mySpeedFactorSlider->setValue((int)(person->getChosenSpeedFactor() * SPEEDFACTOR_SCALE));
378 }
379 mySpeedFactorSlider->show();
380 } else {
381 myView->stopTrack();
382 mySpeedFactorSlider->hide();
383 }
384 }
385 return 1;
386}
387
388
389/****************************************************************************/
@ MID_MAKESNAPSHOT
Make snapshot - button.
Definition GUIAppEnum.h:391
@ MID_SPEEDFACTOR
scale vehicle speed
Definition GUIAppEnum.h:405
@ MID_HOTKEY_SHIFT_O_LOCATEPOI
Locate poi - button.
Definition GUIAppEnum.h:182
@ MID_HOTKEY_SHIFT_A_LOCATEADDITIONAL
Locate additional structure - button.
Definition GUIAppEnum.h:172
@ MID_HOTKEY_SHIFT_C_LOCATECONTAINER
Locate container - button.
Definition GUIAppEnum.h:174
@ MID_HOTKEY_SHIFT_V_LOCATEVEHICLE
Locate vehicle - button.
Definition GUIAppEnum.h:192
@ MID_SIMSTEP
A Simulation step was performed.
Definition GUIAppEnum.h:543
@ MID_HOTKEY_SHIFT_L_LOCATEPOLY
Locate polygons - button.
Definition GUIAppEnum.h:180
@ MID_HOTKEY_SHIFT_E_LOCATEEDGE
Locate edge - button.
Definition GUIAppEnum.h:176
@ MID_HOTKEY_SHIFT_P_LOCATEPERSON
Locate person - button.
Definition GUIAppEnum.h:184
@ MID_HOTKEY_SHIFT_J_LOCATEJUNCTION
Locate junction - button.
Definition GUIAppEnum.h:178
@ MID_HOTKEY_SHIFT_T_LOCATETLS
Locate TLS - button.
Definition GUIAppEnum.h:190
#define GUIDesignVerticalSeparator
vertical separator
Definition GUIDesigns.h:497
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:288
#define TL(string)
Definition MsgHandler.h:304
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:106
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:73
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
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:40
The base class for microscopic and mesoscopic vehicles.
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:106
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1265
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition MSNet.h:515
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:392
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1256
double getChosenSpeedFactor() const
the current speed factor of the transportable (where applicable)
Definition MSPerson.h:154
static StringBijection< ImageVideoFileExtension > ImageVideoFileExtensions
image and videofile extensions
static StringBijection< ImageFileExtension > ImageFileExtensions
image file extensions