From caee77881cbcc0391585bac16e9f5cf623744640 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Thu, 24 Sep 2020 15:07:53 -0600 Subject: [PATCH] Launcher works with all types of SGCT/Profile settings plus commandline --- .../ext/launcher/include/launcherwindow.h | 11 +- .../ext/launcher/src/launcherwindow.cpp | 33 ++++- apps/OpenSpace/main.cpp | 117 ++++++++++++++++-- include/openspace/engine/configuration.h | 1 + scripts/configuration_helper.lua | 9 ++ src/engine/configuration.cpp | 4 + src/engine/configuration_doc.inl | 2 +- 7 files changed, 161 insertions(+), 16 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/include/launcherwindow.h b/apps/OpenSpace/ext/launcher/include/launcherwindow.h index 4e04847241..fd4e9baf6f 100644 --- a/apps/OpenSpace/ext/launcher/include/launcherwindow.h +++ b/apps/OpenSpace/ext/launcher/include/launcherwindow.h @@ -21,15 +21,17 @@ public slots: void startOpenSpace(); public: - LauncherWindow(std::string basePath, std::string profileName, - QWidget *parent = nullptr); + LauncherWindow(std::string basePath, bool profileEnabled, std::string profileName, + bool sgctConfigEnabled, std::string sgctConfigName, QWidget *parent = nullptr); ~LauncherWindow(); bool wasLaunchSelected(); + bool isFullyConfiguredFromCliArgs(); std::string selectedProfile(); + std::string selectedWindowConfig(); private: void populateProfilesList(QString preset); - void populateWindowConfigsList(); + void populateWindowConfigsList(QString preset); bool loadProfileFromFile(openspace::Profile*& p, std::string filename); void saveProfileToFile(const std::string& path, openspace::Profile* p); void displayErrorDialog(std::string msg); @@ -43,5 +45,8 @@ private: std::string _reportAssetsInFilesystem; QString _basePath; bool _launch = false; + bool _fullyConfiguredViaCliArgs = false; + bool _profileChangeAllowed = true; + bool _sgctConfigChangeAllowed = true; }; #endif // LAUNCHERWINDOW_H diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index 1025881585..14ea71b282 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -8,8 +8,9 @@ #include #include -LauncherWindow::LauncherWindow(std::string basePath, std::string profileName, - QWidget *parent) +LauncherWindow::LauncherWindow(std::string basePath, bool profileEnabled, + std::string profileName, bool sgctConfigEnabled, + std::string sgctConfigName, QWidget *parent) : QMainWindow(parent) , ui(new Ui::LauncherWindow) , _fileAccess_profiles(".profile", {"./"}, true, false) @@ -17,6 +18,8 @@ LauncherWindow::LauncherWindow(std::string basePath, std::string profileName, , _filesystemAccess(".asset", {"scene", "global", "customization", "examples"}, true, true) , _basePath(QString::fromUtf8(basePath.c_str())) + , _profileChangeAllowed(profileEnabled) + , _sgctConfigChangeAllowed(sgctConfigEnabled) { ui->setupUi(this); QString logoPath = _basePath + "/data/openspace-horiz-logo.png"; @@ -28,7 +31,10 @@ LauncherWindow::LauncherWindow(std::string basePath, std::string profileName, _reportAssetsInFilesystem = _filesystemAccess.useQtFileSystemModelToTraverseDir( QString(basePath.c_str()) + "/data/assets"); populateProfilesList(QString(profileName.c_str())); - populateWindowConfigsList(); + ui->comboBoxProfiles->setDisabled(!_profileChangeAllowed); + populateWindowConfigsList(QString(sgctConfigName.c_str())); + ui->comboBoxWindowConfigs->setDisabled(!_sgctConfigChangeAllowed); + _fullyConfiguredViaCliArgs = (!profileEnabled && !sgctConfigEnabled); } void LauncherWindow::populateProfilesList(QString preset) { @@ -53,7 +59,7 @@ void LauncherWindow::populateProfilesList(QString preset) { } } -void LauncherWindow::populateWindowConfigsList() { +void LauncherWindow::populateWindowConfigsList(QString preset) { std::string reportConfigs = _fileAccess_winConfigs.useQtFileSystemModelToTraverseDir( _basePath + "/config"); std::stringstream instream(reportConfigs); @@ -63,6 +69,17 @@ void LauncherWindow::populateWindowConfigsList() { windowConfigsListLine << iline.c_str(); } ui->comboBoxWindowConfigs->addItems(windowConfigsListLine); + if (preset.length() > 0) { + int presetMatchIdx = ui->comboBoxWindowConfigs->findText(preset); + if (presetMatchIdx != -1) { + ui->comboBoxWindowConfigs->setCurrentIndex(presetMatchIdx); + } + else { + ui->comboBoxWindowConfigs->addItem(preset); + ui->comboBoxWindowConfigs->setCurrentIndex( + ui->comboBoxWindowConfigs->count() - 1); + } + } } void LauncherWindow::openWindow_new() { @@ -205,10 +222,18 @@ bool LauncherWindow::wasLaunchSelected() { return _launch; } +bool LauncherWindow::isFullyConfiguredFromCliArgs() { + return _fullyConfiguredViaCliArgs; +} + std::string LauncherWindow::selectedProfile() { return ui->comboBoxProfiles->currentText().toUtf8().constData(); } +std::string LauncherWindow::selectedWindowConfig() { + return ui->comboBoxWindowConfigs->currentText().toUtf8().constData(); +} + void LauncherWindow::startOpenSpace() { _launch = true; close(); diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 0e73c9fef3..9eed663ce2 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -926,6 +926,78 @@ void setSgctDelegateFunctions() { }; } +void analyzeCommandLineArgsForSettings(int& argc, char** argv, bool& sgct, bool& profile) { + bool haveCliConfigFlag = false; + for (int i = 1; i < argc; ++i) { + std::string a = argv[i]; + if (a.compare("-c") == 0 || a.compare("--config") == 0) { + haveCliConfigFlag = true; + } + else if (haveCliConfigFlag) { + a.erase(remove_if(a.begin(), a.end(), isspace), a.end()); + if (a.find("SGCTConfig=") != std::string::npos) { + sgct = true; + } + if (a.find("Profile=") != std::string::npos) { + profile = true; + } + } + } +} + +std::string setWindowConfigPresetForGui(const std::string labelFromCfgFile, + const std::string xmlExt, bool haveCliSGCTConfig) +{ + const std::string labelFromCli = " (from CLI)"; + std::string preset; + bool sgctConfigFileSpecifiedByLuaFunction = (global::configuration.sgctConfigNameInitialized.length() > 0); + if (haveCliSGCTConfig) { + preset = global::configuration.windowConfiguration; + preset += labelFromCli; + } + else if (sgctConfigFileSpecifiedByLuaFunction) { + preset = global::configuration.sgctConfigNameInitialized; + preset += labelFromCfgFile; + } + else { + preset = global::configuration.windowConfiguration; + if (preset.find("/") != std::string::npos) { + preset.erase(0, preset.find_last_of("/") + 1); + } + if (preset.length() >= xmlExt.length()) { + if (preset.substr(preset.length() - xmlExt.length()) + .compare(xmlExt) == 0) + { + preset = preset.substr(0, preset.length() + - xmlExt.length()); + } + } + } + return preset; +} + +std::string getSelectedSgctProfileFromLauncher(LauncherWindow* lw, bool haveCliSGCTConfig, + std::string windowConfiguration, + const std::string& labelFromCfgFile, + const std::string& xmlExt) +{ + std::string config = windowConfiguration; + if (!haveCliSGCTConfig) { + if (lw != nullptr) { + config = lw->selectedWindowConfig(); + } + if (config.find(labelFromCfgFile) != std::string::npos) { + config = config.substr(0, + config.length() - labelFromCfgFile.length()); + } + else { + config = "${CONFIG}/" + config + xmlExt; + } + global::configuration.windowConfiguration = config; + } + return config; +} + int main(int argc, char** argv) { #ifdef WIN32 SetUnhandledExceptionFilter(generateMiniDump); @@ -1065,16 +1137,42 @@ int main(int argc, char** argv) { global::openSpaceEngine.registerPathTokens(); + bool haveCliSGCTConfig = false; + bool haveCliProfile = false; + analyzeCommandLineArgsForSettings(argc, argv, haveCliSGCTConfig, haveCliProfile); + //Call profile GUI - int ac = 0; - QApplication a(ac, nullptr); - LauncherWindow w(absPath("${BASE}"), global::configuration.profile); - w.show(); - a.exec(); - if (!w.wasLaunchSelected()) { - exit(EXIT_FAILURE); + const std::string labelFromCfgFile = " (from .cfg)"; + const std::string xmlExt = ".xml"; + std::string windowCfgPreset = setWindowConfigPresetForGui(labelFromCfgFile, xmlExt, + haveCliSGCTConfig); + + QApplication* qaobj = nullptr; + LauncherWindow* launchwin = nullptr; + bool skipLauncherSinceProfileAndWindowAreConfiguredInCli = + (haveCliProfile && haveCliSGCTConfig); + + if (!skipLauncherSinceProfileAndWindowAreConfiguredInCli) { + int qac = 0; + qaobj = new QApplication(qac, nullptr); + launchwin = new LauncherWindow(absPath("${BASE}"), !haveCliProfile, + global::configuration.profile, !haveCliSGCTConfig, windowCfgPreset); + launchwin->show(); + qaobj->exec(); + + if (!launchwin->wasLaunchSelected()) { + exit(EXIT_FAILURE); + } + + global::configuration.profile = launchwin->selectedProfile(); + windowConfiguration = getSelectedSgctProfileFromLauncher( + launchwin, + haveCliSGCTConfig, + windowConfiguration, + labelFromCfgFile, + xmlExt + ); } - global::configuration.profile = w.selectedProfile(); // Prepend the outgoing sgctArguments with the program name // as well as the configuration file that sgct is supposed to use @@ -1190,6 +1288,9 @@ int main(int argc, char** argv) { } #endif // OPENSPACE_HAS_SPOUT + delete qaobj; + delete launchwin; + ghoul::deinitialize(); exit(EXIT_SUCCESS); } diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index 41643b3041..86a5fab814 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -43,6 +43,7 @@ struct Configuration { Configuration& operator=(Configuration&&) = default; std::string windowConfiguration = "${CONFIG}/single.xml"; + std::string sgctConfigNameInitialized; std::string asset; std::string profile; std::vector globalCustomizationScripts; diff --git a/scripts/configuration_helper.lua b/scripts/configuration_helper.lua index 300d4c8ebf..2fc3bf4c67 100644 --- a/scripts/configuration_helper.lua +++ b/scripts/configuration_helper.lua @@ -88,6 +88,8 @@ function sgct.config.fisheye(arg) end function sgct.config.cube(arg) end +-- Global variable storing the name of the config function called at initialization +sgctconfiginitializeString = "" --[[ ########################################################################################## @@ -699,6 +701,8 @@ function sgct.config.single(arg) type(arg["tracked"]) == "boolean" or type(arg["tracked"]) == "nil", "tracked must be a boolean or nil" ) + sgctconfiginitializeString = "sgct.config.single" + trackedSpecifier = "tracked=\"true\"" if (arg["tracked"] ~= nil and arg["tracked"] == false) then @@ -718,6 +722,7 @@ end function sgct.config.fisheye(arg) + arg = normalizeArg(arg) assert( @@ -775,6 +780,8 @@ function sgct.config.fisheye(arg) assert(type(arg["offset"]["z"]) == "number", "offset['z'] must be a number") end + sgctconfiginitializeString = "sgct.config.fisheye" + if arg["fov"] == nil then arg["fov"] = 180 end @@ -869,6 +876,7 @@ function sgct.config.cube(arg) return generateWindow(arg) end + sgctconfiginitializeString = "sgct.config.cube" res = 1024 size = { 640, 360 } @@ -894,3 +902,4 @@ function sgct.config.cube(arg) return sgct.makeConfig(generateCluster(arg)) end + diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index c226d65a42..50ac9cc555 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -90,6 +90,8 @@ namespace { constexpr const char* KeyShowProgressbar = "ShowProgressbar"; constexpr const char* KeyModuleConfigurations = "ModuleConfigurations"; + constexpr const char* KeySgctConfigNameInitialized = "sgctconfiginitializeString"; + template void getValue(ghoul::lua::LuaState& L, const char* name, T& value) { using namespace openspace::configuration; @@ -304,6 +306,8 @@ void parseLuaState(Configuration& configuration) { getValue(s, KeyModuleConfigurations, c.moduleConfigurations); getValue(s, KeyOpenGLDebugContext, c.openGLDebugContext); getValue(s, KeyHttpProxy, c.httpProxy); + + getValue(s, KeySgctConfigNameInitialized, c.sgctConfigNameInitialized); } std::string findConfiguration(const std::string& filename) { diff --git a/src/engine/configuration_doc.inl b/src/engine/configuration_doc.inl index 0e7059fc02..fd05a74149 100644 --- a/src/engine/configuration_doc.inl +++ b/src/engine/configuration_doc.inl @@ -35,7 +35,7 @@ documentation::Documentation Configuration::Documentation = { { KeySGCTConfig, new StringAnnotationVerifier("A valid SGCT configuration file"), - Optional::No, + Optional::Yes, "The SGCT configuration file that determines the window and view frustum " "settings that are being used when OpenSpace is started." },