37#include <simgear/compiler.h>
46#include <simgear/debug/logstream.hxx>
47#include <simgear/misc/sg_path.hxx>
48#include <simgear/screen/screen-dump.hxx>
49#include <simgear/structure/commands.hxx>
50#include <simgear/structure/event_mgr.hxx>
51#include <simgear/props/props_io.hxx>
100 const int maxdialogs = 5;
102 SGPropertyNode *msg =
fgGetNode(
"/sim/gui/dialogs",
true);
104 for (
i = 0;
i < maxdialogs;
i++) {
105 std::ostringstream s;
106 s <<
"message-" <<
i;
109 if (!msg->getNode(
name.c_str(),
false))
112 if (!strcmp(txt, msg->getNode(
name.c_str())->getStringValue(
"message").c_str())) {
113 SG_LOG(SG_GENERAL, SG_WARN,
"mkDialog(): duplicate of message " << txt);
119 msg = msg->getNode(
name.c_str(),
true);
120 msg->setStringValue(
"message", txt);
121 msg = msg->getNode(
"dialog",
true);
122 copyProperties(master, msg);
123 msg->setStringValue(
"name",
name.c_str());
125 gui->showDialog(
name.c_str());
131 SG_LOG(SG_GENERAL, SG_ALERT, txt);
140 msg += throwable.getFormattedMessage();
141 if (std::strlen(throwable.getOrigin()) != 0) {
142 msg +=
"\n (reported by ";
143 msg += throwable.getOrigin();
146 SG_LOG(SG_GENERAL, SG_ALERT, msg);
164 string address(aAddress);
167 if (address.find(
"://")==string::npos)
170 SGPath path(address);
171 path =
globals->resolve_maybe_aircraft_path(address);
172 if (!path.isNull()) {
173 address =
"file://" + path.local8BitStr();
175 mkDialog (
"Sorry, file not found!");
176 SG_LOG(SG_GENERAL, SG_ALERT,
"openBrowser: Cannot find requested file '"
187 char win32_name[1024];
189 cygwin32_conv_to_full_win32_path(address.c_str(),win32_name);
191 strncpy(win32_name,address.c_str(), 1024);
193 ShellExecuteA(NULL,
"open", win32_name, NULL, NULL,
198 string::size_type pos;
199 if ((pos =
command.find(
"%u", 0)) != string::npos)
200 command.replace(pos, 2, address);
202 command +=
" \"" + address +
"\"";
205 ok = (system(
command.c_str() ) == 0);
208 if(
fgGetBool(
"/sim/gui/show-browser-open-hint",
true) )
209 mkDialog(
"The file is shown in your web browser window.");
222 SGPath nextScreenshotPath(
const SGPath& screenshotDir)
226 while (count < 100) {
228 time_t calendar_time = time(NULL);
230 tmUTC = gmtime(&calendar_time);
231 strftime(time_str,
sizeof(time_str),
"%Y%m%d%H%M%S", tmUTC);
234 snprintf(filename, 32,
"fgfs-%s-%d.png", time_str, count++);
236 snprintf(filename, 32,
"fgfs-%s.png", time_str);
238 SGPath
p = screenshotDir / filename;
247 class GUISnapShotOperation :
256 if (_snapShotOp.valid())
258 _snapShotOp =
new GUISnapShotOperation();
263 osg::GraphicsContext* gc = 0;
265 gc = guiCamera->getGraphicsContext();
267 gc->add(_snapShotOp.get());
269 wsa->
windows[0]->gc->add(_snapShotOp.get());
276 _snapShotOp =
nullptr;
281 GUISnapShotOperation() :
282 flightgear::GraphicsContextOperation(std::string(
"GUI snap shot")),
283 _master_freeze(
fgGetNode(
"/sim/freeze/master", true)),
289 _master_freeze->setBoolValue(
true);
293 SGPath dir = SGPath::fromUtf8(
fgGetString(
"/sim/paths/screenshot-dir"));
295 dir = SGPath::desktop();
297 if (!dir.exists() && dir.create_dir( 0755 )) {
298 SG_LOG(SG_GENERAL, SG_ALERT,
"Cannot create screenshot directory '"
299 << dir <<
"'. Trying home directory.");
303 _path = nextScreenshotPath(dir);
304 _xsize =
fgGetInt(
"/sim/startup/xsize");
305 _ysize =
fgGetInt(
"/sim/startup/ysize");
308 renderer->
resize(_xsize, _ysize);
310 [
this](){ this->timerExpired(); },
315 void run(osg::GraphicsContext* gc)
317 std::string ps = _path.local8BitStr();
318 _result = sg_glDumpWindow(ps.c_str(),
324 virtual void timerExpired()
330 fgSetString(
"/sim/paths/screenshot-last", _path.utf8Str());
331 fgSetBool(
"/sim/signals/screenshot", _result);
336 _master_freeze->setBoolValue(
false);
342 static osg::ref_ptr<GUISnapShotOperation> _snapShotOp;
343 SGPropertyNode_ptr _master_freeze;
353osg::ref_ptr<GUISnapShotOperation> GUISnapShotOperation::_snapShotOp;
360 return GUISnapShotOperation::start();
365 GUISnapShotOperation::cancel();
371 char *filename =
new char [24];
373 static unsigned short count = 1;
375 SGPropertyNode *master_freeze =
fgGetNode(
"/sim/freeze/master");
377 bool freeze = master_freeze->getBoolValue();
379 master_freeze->setBoolValue(
true);
382 while (count < 1000) {
384 snprintf(filename, 24,
"fgfs-graph-%03d.osg", count++);
385 if ( (fp = fopen(filename,
"r")) == NULL )
391 message =
"Entire scene graph saved to \"";
395 message =
"Failed to save to \"";
405 master_freeze->setBoolValue(
false);
413 char *filename =
new char [24];
415 static unsigned short count = 1;
417 SGPropertyNode *master_freeze =
fgGetNode(
"/sim/freeze/master");
419 bool freeze = master_freeze->getBoolValue();
421 master_freeze->setBoolValue(
true);
424 while (count < 1000) {
426 snprintf(filename, 24,
"fgfs-graph-%03d.osg", count++);
427 if ( (fp = fopen(filename,
"r")) == NULL )
433 message =
"Terrain graph saved to \"";
437 message =
"Failed to save to \"";
447 master_freeze->setBoolValue(
false);
453 SGPropertyNode *master_freeze =
fgGetNode(
"/sim/freeze/master");
455 bool freeze = master_freeze->getBoolValue();
457 master_freeze->setBoolValue(
true);
463 master_freeze->setBoolValue(
false);
469 bool paused =
fgGetBool(
"/sim/freeze/master",
true) ||
fgGetBool(
"/sim/freeze/clock",
true);
470 SGPropertyNode_ptr args(
new SGPropertyNode);
471 args->setStringValue(
"id",
"sim-pause");
472 if (paused &&
fgGetBool(
"/sim/view-name-popup")) {
473 args->setStringValue(
"label",
"Simulation is paused");
474 globals->get_commands()->execute(
"show-message", args,
nullptr);
476 globals->get_commands()->execute(
"clear-message", args,
nullptr);
void cocoaOpenUrl(const std::string &url)
open a URL using the system's web-browser
virtual FGRenderer * get_renderer() const
SGEventMgr * get_event_mgr() const
const SGPath & get_fg_home() const
void resize(int width, int height)
Handle a window resize event.
XML-configured GUI subsystem.
virtual SGPropertyNode_ptr getDialogProperties(const std::string &name)
Get dialog property tree's root node.
static CameraGroup * getDefault()
Get the default CameraGroup.
An operation that is run once with a particular GraphicsContext current.
WindowVector windows
Vector of all the registered windows.
static WindowSystemAdapter * getWSA()
Get the global WindowSystemAdapter.
SGCommandMgr::command_t command
void fgSetMouseCursor(FGMouseCursor::Cursor cursor)
FGMouseCursor::Cursor fgGetMouseCursor()
int fgGetInt(const char *name, int defaultValue)
Get an int value for a property.
std::string fgGetString(const char *name, const char *defaultValue)
Get a string value for a property.
void fgDumpSnapShotWrapper()
const __fg_gui_fn_t __fg_gui_fn[]
void syncPausePopupState()
synchronize /sim/freeze properties with visiblity of the popup-dialog which informs the user
void fgDumpTerrainBranch()
void mkDialog(const char *txt)
void guiErrorMessage(const char *txt)
void fgPrintVisibleSceneInfoCommand()
bool openBrowser(const std::string &aAddress)
void fgDumpSnapShotWrapper()
bool getBoolValue(const char *spec, bool default_)
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
osg::Camera * getGUICamera(CameraGroup *cgroup)
Get the osg::Camera that draws the GUI, if any, from a camera group.
bool fgGetBool(char const *name, bool def)
Get a bool value for a property.
bool fgSetBool(char const *name, bool val)
Set a bool value for a property.
bool fgSetString(char const *name, char const *str)
Set a string value for a property.
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
bool fgPrintVisibleSceneInfo(FGRenderer *renderer)
bool fgDumpTerrainBranchToFile(const char *filename)
bool fgDumpSceneGraphToFile(const char *filename)