mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-12 22:39:09 -05:00
Launcher works with all types of SGCT/Profile settings plus commandline
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
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();
|
||||
|
||||
+109
-8
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<std::string> globalCustomizationScripts;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -90,6 +90,8 @@ namespace {
|
||||
constexpr const char* KeyShowProgressbar = "ShowProgressbar";
|
||||
constexpr const char* KeyModuleConfigurations = "ModuleConfigurations";
|
||||
|
||||
constexpr const char* KeySgctConfigNameInitialized = "sgctconfiginitializeString";
|
||||
|
||||
template <typename T>
|
||||
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) {
|
||||
|
||||
@@ -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."
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user