From 2cfa0e06c3fc5fd443e389cd62fcdda8cf8d1fff Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Thu, 17 Sep 2020 19:35:54 -0600 Subject: [PATCH] Various bug fixes and removal of simulated test data --- .../ext/launcher/include/addedscripts.h | 1 + apps/OpenSpace/ext/launcher/include/assets.h | 1 + apps/OpenSpace/ext/launcher/include/camera.h | 1 + .../ext/launcher/include/deltatimes.h | 50 +-- .../ext/launcher/include/keybindings.h | 1 + .../ext/launcher/include/launcherwindow.h | 27 +- .../ext/launcher/include/marknodes.h | 1 + apps/OpenSpace/ext/launcher/include/meta.h | 1 + .../ext/launcher/include/osmodules.h | 1 + apps/OpenSpace/ext/launcher/include/ostime.h | 1 + .../ext/launcher/include/profileedit.h | 4 + .../ext/launcher/include/properties.h | 1 + .../ext/launcher/include/ui_assets.h | 2 +- .../ext/launcher/include/ui_deltatimes.h | 7 +- .../ext/launcher/include/ui_launcherwindow.h | 5 - .../ext/launcher/include/ui_profileedit.h | 2 +- .../ext/launcher/src/addedscripts.cpp | 8 + apps/OpenSpace/ext/launcher/src/assets.cpp | 8 + apps/OpenSpace/ext/launcher/src/camera.cpp | 9 + .../OpenSpace/ext/launcher/src/deltatimes.cpp | 103 ++++--- .../ext/launcher/src/keybindings.cpp | 9 + .../ext/launcher/src/launcherwindow.cpp | 289 ++++-------------- apps/OpenSpace/ext/launcher/src/marknodes.cpp | 9 + apps/OpenSpace/ext/launcher/src/meta.cpp | 13 +- apps/OpenSpace/ext/launcher/src/osmodules.cpp | 9 + apps/OpenSpace/ext/launcher/src/ostime.cpp | 24 +- .../ext/launcher/src/profileedit.cpp | 28 ++ .../OpenSpace/ext/launcher/src/properties.cpp | 9 + 28 files changed, 278 insertions(+), 346 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/include/addedscripts.h b/apps/OpenSpace/ext/launcher/include/addedscripts.h index 265e2b386e..c070121603 100644 --- a/apps/OpenSpace/ext/launcher/include/addedscripts.h +++ b/apps/OpenSpace/ext/launcher/include/addedscripts.h @@ -23,6 +23,7 @@ public: explicit addedScripts(openspace::Profile* imported, QWidget *parent = nullptr); ~addedScripts(); void setScriptText(std::string s); + void keyPressEvent(QKeyEvent *evt); private: Ui::addedScripts *ui; diff --git a/apps/OpenSpace/ext/launcher/include/assets.h b/apps/OpenSpace/ext/launcher/include/assets.h index 690c9934ff..2a6098c627 100644 --- a/apps/OpenSpace/ext/launcher/include/assets.h +++ b/apps/OpenSpace/ext/launcher/include/assets.h @@ -29,6 +29,7 @@ public: QWidget *parent = nullptr); ~assets(); std::string createTextSummary(); + void keyPressEvent(QKeyEvent *evt); protected: //void resizeEvent(QResizeEvent* event); diff --git a/apps/OpenSpace/ext/launcher/include/camera.h b/apps/OpenSpace/ext/launcher/include/camera.h index 5e40c1e944..7534606233 100644 --- a/apps/OpenSpace/ext/launcher/include/camera.h +++ b/apps/OpenSpace/ext/launcher/include/camera.h @@ -39,6 +39,7 @@ public: Nav = 0, Geo }; + void keyPressEvent(QKeyEvent *evt); private: bool isNumericalValue(QLineEdit* le); diff --git a/apps/OpenSpace/ext/launcher/include/deltatimes.h b/apps/OpenSpace/ext/launcher/include/deltatimes.h index 53127f30fd..5fc37c61ea 100644 --- a/apps/OpenSpace/ext/launcher/include/deltatimes.h +++ b/apps/OpenSpace/ext/launcher/include/deltatimes.h @@ -12,7 +12,7 @@ class deltaTimes; } QT_END_NAMESPACE -static const double _defaultDeltaTimes[30] = { +static const int _defaultDeltaTimes[30] = { 1, 2, 5, 10, 30, 60, 120, 300, 600, 1800, 3600, 7200, 10800, 21600, 43200, @@ -21,36 +21,6 @@ static const double _defaultDeltaTimes[30] = { 63072000, 157680000, 315360000, 630720000, 1576800000 }; -struct DeltaTimes { - std::vector _times; - DeltaTimes() { - _times.resize(sizeof(_defaultDeltaTimes)/sizeof(double)); - zeroValues(); - }; - DeltaTimes(std::vector dt) { - _times.resize(sizeof(_defaultDeltaTimes)/sizeof(double)); - zeroValues(); - _times = dt; - }; - void loadValues(std::vector& dt) { - for (size_t i = 0; i < dt.size(); ++i) { - _times[i] = dt[i]; - } - } - size_t size() { - auto it = find(_times.begin(), _times.end(), 0); - return std::distance(_times.begin(), it); - }; - size_t totalSize() { - return (sizeof(_defaultDeltaTimes) / sizeof(double)); - } - void zeroValues() { - for (size_t i = 0; i < _times.size(); ++i) { - _times[i] = 0.0; - } - } -}; - class deltaTimes : public QDialog { Q_OBJECT @@ -58,20 +28,22 @@ class deltaTimes : public QDialog public slots: void listItemSelected(); void saveDeltaTimeValue(); - void clearDeltaTimeValue(); + void addDeltaTimeValue(); + void removeDeltaTimeValue(); void parseSelections(); public: explicit deltaTimes(openspace::Profile* _imported, QWidget *parent = nullptr); ~deltaTimes(); void setDeltaTimes(std::vector& dt); - QString createSummaryForDeltaTime(size_t idx, double dt, bool forListView); + QString createSummaryForDeltaTime(size_t idx, int dt, bool forListView); + void keyPressEvent(QKeyEvent *evt); struct timeIntervals { int index; - double secondsPerInterval; + int secondsPerInterval; QString intervalName; }; - + int _maxSize = sizeof(_defaultDeltaTimes) / sizeof(int); const int secondsPerYear = 31536000; const int secondsPerMonth = 18144000; const int secondsPerWeek = 604800; @@ -80,10 +52,10 @@ public: const int secondsPerMinute = 60; private: - QString timeDescription(double value); + QString timeDescription(int value); bool checkForTimeDescription(QString& description, QString unit, - int interval, double value); - QString checkForTimeDescription(int intervalIndex, double value); + int interval, int value); + QString checkForTimeDescription(int intervalIndex, int value); int lastSelectableItem(); bool isNumericalValue(QLineEdit* le); @@ -91,7 +63,7 @@ private: QWidget* _parent; openspace::Profile* _imported; - DeltaTimes _data; + std::vector _data; std::vector _deltaTimeStrings; std::vector _deltaListItems; diff --git a/apps/OpenSpace/ext/launcher/include/keybindings.h b/apps/OpenSpace/ext/launcher/include/keybindings.h index 033f023f6b..4f570dfd17 100644 --- a/apps/OpenSpace/ext/launcher/include/keybindings.h +++ b/apps/OpenSpace/ext/launcher/include/keybindings.h @@ -27,6 +27,7 @@ public slots: public: explicit keybindings(openspace::Profile* imported, QWidget *parent = nullptr); ~keybindings(); + void keyPressEvent(QKeyEvent *evt); protected: //void resizeEvent(QResizeEvent* event); diff --git a/apps/OpenSpace/ext/launcher/include/launcherwindow.h b/apps/OpenSpace/ext/launcher/include/launcherwindow.h index 066d320956..93a79fdb5b 100644 --- a/apps/OpenSpace/ext/launcher/include/launcherwindow.h +++ b/apps/OpenSpace/ext/launcher/include/launcherwindow.h @@ -18,48 +18,25 @@ class LauncherWindow : public QMainWindow public slots: void openWindow_edit(); void openWindow_new(); - void simulateData(); public: LauncherWindow(std::string basePath, QWidget *parent = nullptr); ~LauncherWindow(); - void receiveAssets(std::vector results); private: void populateProfilesList(); void populateWindowConfigsList(); bool loadProfileFromFile(openspace::Profile*& p, std::string filename); - void displayProfileParseErrorDialogThenQuit(std::string msg); - void clearData(); - void initialize_meta(); - void initialize_modules(); - void initialize_assets(); - void initialize_properties(); - void initialize_keybindings(); - void initialize_deltaTimes(); - void initialize_time(); - void initialize_camera(); - void initialize_markNodes(); - void initialize_addedScripts(); + void saveProfileToFile(const std::string& path, openspace::Profile* p); + void displayErrorDialog(std::string msg); Ui::LauncherWindow *ui; ProfileEdit* myEditorWindow; errordialog* _myDialog; filesystemAccess _fileAccess_profiles; filesystemAccess _fileAccess_winConfigs; - openspace::Profile::Meta _metaData; - std::vector _moduleData; - std::vector _assetData; filesystemAccess _filesystemAccess; std::string _reportAssetsInFilesystem; - std::vector _propsData; - std::vector _keybindingsData; - DeltaTimes _deltaTimesData; - openspace::Profile::Time _timeData; - openspace::Profile::CameraType _cameraData; - std::vector _markNodesData; - std::string _addedScriptsData; - //ProfileBlock _pData; QString _basePath; }; #endif // LAUNCHERWINDOW_H diff --git a/apps/OpenSpace/ext/launcher/include/marknodes.h b/apps/OpenSpace/ext/launcher/include/marknodes.h index 8ce9e51ad5..75a53c834e 100644 --- a/apps/OpenSpace/ext/launcher/include/marknodes.h +++ b/apps/OpenSpace/ext/launcher/include/marknodes.h @@ -25,6 +25,7 @@ public slots: public: explicit markNodes(openspace::Profile* imported, QWidget *parent = nullptr); ~markNodes(); + void keyPressEvent(QKeyEvent *evt); private: Ui::markNodes *ui; diff --git a/apps/OpenSpace/ext/launcher/include/meta.h b/apps/OpenSpace/ext/launcher/include/meta.h index 1717110d35..ae60f76c0a 100644 --- a/apps/OpenSpace/ext/launcher/include/meta.h +++ b/apps/OpenSpace/ext/launcher/include/meta.h @@ -23,6 +23,7 @@ public: explicit meta(openspace::Profile* imported, QWidget *parent = nullptr); ~meta(); bool areAllEntriesBlank(); + void keyPressEvent(QKeyEvent *evt); private: Ui::meta *ui; diff --git a/apps/OpenSpace/ext/launcher/include/osmodules.h b/apps/OpenSpace/ext/launcher/include/osmodules.h index 925f6ce4ca..d300a344d8 100644 --- a/apps/OpenSpace/ext/launcher/include/osmodules.h +++ b/apps/OpenSpace/ext/launcher/include/osmodules.h @@ -27,6 +27,7 @@ public slots: public: explicit osmodules(openspace::Profile* imported, QWidget *parent = nullptr); ~osmodules(); + void keyPressEvent(QKeyEvent *evt); protected: //void resizeEvent(QResizeEvent* event); diff --git a/apps/OpenSpace/ext/launcher/include/ostime.h b/apps/OpenSpace/ext/launcher/include/ostime.h index dc619cb64a..756cf819e2 100644 --- a/apps/OpenSpace/ext/launcher/include/ostime.h +++ b/apps/OpenSpace/ext/launcher/include/ostime.h @@ -19,6 +19,7 @@ public slots: void enableAccordingToType(int); void cancel(); void approved(); + void keyPressEvent(QKeyEvent *evt); public: explicit ostime(openspace::Profile* imported, QWidget *parent = nullptr); diff --git a/apps/OpenSpace/ext/launcher/include/profileedit.h b/apps/OpenSpace/ext/launcher/include/profileedit.h index 027da4ddce..740cdbcd34 100644 --- a/apps/OpenSpace/ext/launcher/include/profileedit.h +++ b/apps/OpenSpace/ext/launcher/include/profileedit.h @@ -45,6 +45,9 @@ public: explicit ProfileEdit(openspace::Profile* profile, const std::string reportedAssets, QWidget *parent = nullptr); ~ProfileEdit(); void setProfileName(QString profileToSet); + bool wasSaved(); + std::string specifiedFilename(); + void keyPressEvent(QKeyEvent *evt); private: void initSummaryTextForEachCategory(); @@ -73,6 +76,7 @@ private: markNodes* _markNodes; openspace::Profile* _pData; const std::string _reportedAssets; + bool _saveSelected = false; }; #endif // PROFILEEDIT_H diff --git a/apps/OpenSpace/ext/launcher/include/properties.h b/apps/OpenSpace/ext/launcher/include/properties.h index a67460df3f..05248ed0d0 100644 --- a/apps/OpenSpace/ext/launcher/include/properties.h +++ b/apps/OpenSpace/ext/launcher/include/properties.h @@ -27,6 +27,7 @@ public slots: public: explicit properties(openspace::Profile* imported, QWidget *parent = nullptr); ~properties(); + void keyPressEvent(QKeyEvent *evt); protected: //void resizeEvent(QResizeEvent* event); diff --git a/apps/OpenSpace/ext/launcher/include/ui_assets.h b/apps/OpenSpace/ext/launcher/include/ui_assets.h index e8d8d83096..0e11fa64d5 100644 --- a/apps/OpenSpace/ext/launcher/include/ui_assets.h +++ b/apps/OpenSpace/ext/launcher/include/ui_assets.h @@ -46,7 +46,7 @@ public: QFont font; font.setFamily(QString::fromUtf8("Arial")); treeView->setFont(font); - treeView->setStyleSheet(QString::fromUtf8("background-color: rgb(85, 87, 83);")); + //treeView->setStyleSheet(QString::fromUtf8("background-color: rgb(85, 87, 83);")); treeView->setAlternatingRowColors(false); treeView->setAnimated(false); varName = new QPushButton(assets); diff --git a/apps/OpenSpace/ext/launcher/include/ui_deltatimes.h b/apps/OpenSpace/ext/launcher/include/ui_deltatimes.h index e98058d3d0..42d95dc625 100644 --- a/apps/OpenSpace/ext/launcher/include/ui_deltatimes.h +++ b/apps/OpenSpace/ext/launcher/include/ui_deltatimes.h @@ -28,6 +28,7 @@ public: QListWidget *listWidget; QLabel *label_adjust; QPushButton *button_save; + QPushButton *button_add; QPushButton *button_remove; QLineEdit *line_seconds; @@ -60,9 +61,12 @@ public: button_save = new QPushButton(deltaTimes); button_save->setObjectName(QString::fromUtf8("button_save")); button_save->setGeometry(QRect(20, 354, 71, 25)); + button_add = new QPushButton(deltaTimes); + button_add->setObjectName(QString::fromUtf8("button_add")); + button_add->setGeometry(QRect(20, 230, 151, 25)); button_remove = new QPushButton(deltaTimes); button_remove->setObjectName(QString::fromUtf8("button_remove")); - button_remove->setGeometry(QRect(20, 230, 151, 25)); + button_remove->setGeometry(QRect(190, 230, 151, 25)); line_seconds = new QLineEdit(deltaTimes); line_seconds->setObjectName(QString::fromUtf8("line_seconds")); line_seconds->setGeometry(QRect(20, 310, 191, 31)); @@ -81,6 +85,7 @@ public: label_module->setText(QCoreApplication::translate("deltaTimes", "Delta Times", nullptr)); label_adjust->setText(QCoreApplication::translate("deltaTimes", "Set Delta Time for key", nullptr)); button_save->setText(QCoreApplication::translate("deltaTimes", "Save", nullptr)); + button_add->setText(QCoreApplication::translate("deltaTimes", "Add New Entry", nullptr)); button_remove->setText(QCoreApplication::translate("deltaTimes", "Remove Last Entry", nullptr)); } // retranslateUi diff --git a/apps/OpenSpace/ext/launcher/include/ui_launcherwindow.h b/apps/OpenSpace/ext/launcher/include/ui_launcherwindow.h index a95dfe70a1..3320b2e599 100644 --- a/apps/OpenSpace/ext/launcher/include/ui_launcherwindow.h +++ b/apps/OpenSpace/ext/launcher/include/ui_launcherwindow.h @@ -35,7 +35,6 @@ public: QComboBox *comboBoxWindowConfigs; QLabel *labelChoose; QLabel *labelOptions; - QPushButton *buttonSim; QMenuBar *menubar; QMenu *menuOpenSpace_Launcher; QStatusBar *statusbar; @@ -89,9 +88,6 @@ public: labelOptions->setGeometry(QRect(130, 250, 151, 17)); labelOptions->setFont(font); labelOptions->setTextFormat(Qt::RichText); - buttonSim = new QPushButton(centralwidget); - buttonSim->setObjectName(QString::fromUtf8("buttonSim")); - buttonSim->setGeometry(QRect(210, 500, 89, 25)); LauncherWindow->setCentralWidget(centralwidget); menubar = new QMenuBar(LauncherWindow); menubar->setObjectName(QString::fromUtf8("menubar")); @@ -121,7 +117,6 @@ public: logolabel->setText(QString()); labelChoose->setText(QCoreApplication::translate("LauncherWindow", "

Choose Profile

", nullptr)); labelOptions->setText(QCoreApplication::translate("LauncherWindow", "

Window Options

", nullptr)); - buttonSim->setText(QCoreApplication::translate("LauncherWindow", "simData", nullptr)); menuOpenSpace_Launcher->setTitle(QCoreApplication::translate("LauncherWindow", "OpenSpace Launcher", nullptr)); } // retranslateUi diff --git a/apps/OpenSpace/ext/launcher/include/ui_profileedit.h b/apps/OpenSpace/ext/launcher/include/ui_profileedit.h index 25b956a7be..7a1c893542 100644 --- a/apps/OpenSpace/ext/launcher/include/ui_profileedit.h +++ b/apps/OpenSpace/ext/launcher/include/ui_profileedit.h @@ -329,7 +329,7 @@ public: line_profile->setFont(font3); retranslateUi(ProfileEdit); - QObject::connect(buttonBox, SIGNAL(accepted()), ProfileEdit, SLOT(accept())); + //QObject::connect(buttonBox, SIGNAL(accepted()), ProfileEdit, SLOT(accept())); QObject::connect(buttonBox, SIGNAL(rejected()), ProfileEdit, SLOT(reject())); QMetaObject::connectSlotsByName(ProfileEdit); diff --git a/apps/OpenSpace/ext/launcher/src/addedscripts.cpp b/apps/OpenSpace/ext/launcher/src/addedscripts.cpp index 8bc9b9bf12..4bdb828191 100644 --- a/apps/OpenSpace/ext/launcher/src/addedscripts.cpp +++ b/apps/OpenSpace/ext/launcher/src/addedscripts.cpp @@ -3,6 +3,7 @@ #include #include #include +#include addedScripts::addedScripts(openspace::Profile* imported, QWidget *parent) : QDialog(parent) @@ -35,4 +36,11 @@ void addedScripts::parseScript() { accept(); } +void addedScripts::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} + addedScripts::~addedScripts() { } diff --git a/apps/OpenSpace/ext/launcher/src/assets.cpp b/apps/OpenSpace/ext/launcher/src/assets.cpp index ef43c630d1..d96d57a223 100644 --- a/apps/OpenSpace/ext/launcher/src/assets.cpp +++ b/apps/OpenSpace/ext/launcher/src/assets.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -168,3 +169,10 @@ assets::~assets() { void assets::cancel() { } + +void assets::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} diff --git a/apps/OpenSpace/ext/launcher/src/camera.cpp b/apps/OpenSpace/ext/launcher/src/camera.cpp index 1efcfe95dd..035d4b2cc2 100644 --- a/apps/OpenSpace/ext/launcher/src/camera.cpp +++ b/apps/OpenSpace/ext/launcher/src/camera.cpp @@ -1,6 +1,7 @@ #include #include "camera.h" #include "./ui_camera.h" +#include template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; @@ -252,3 +253,11 @@ bool camera::isUpVectorValid() { && isNumericalValue(ui->line_upY) && isNumericalValue(ui->line_upZ)); } + +void camera::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} + diff --git a/apps/OpenSpace/ext/launcher/src/deltatimes.cpp b/apps/OpenSpace/ext/launcher/src/deltatimes.cpp index 4d0e423f85..caab96bd01 100644 --- a/apps/OpenSpace/ext/launcher/src/deltatimes.cpp +++ b/apps/OpenSpace/ext/launcher/src/deltatimes.cpp @@ -2,27 +2,33 @@ #include "./ui_deltatimes.h" #include #include +#include deltaTimes::deltaTimes(openspace::Profile* imported, QWidget *parent) : QDialog(parent) , ui(new Ui::deltaTimes) , _imported(imported) - , _data(imported->deltaTimes()) { ui->setupUi(this); + _data.clear(); + for (double dt : imported->deltaTimes()) { + _data.push_back(static_cast(dt)); + } + for (size_t d = 0; d < _data.size(); ++d) { - QString summary = createSummaryForDeltaTime(d, _data._times.at(d), true); + QString summary = createSummaryForDeltaTime(d, _data.at(d), true); _deltaListItems.push_back(new QListWidgetItem(summary)); ui->listWidget->addItem(_deltaListItems[d]); } connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(listItemSelected())); connect(ui->button_save, SIGNAL(clicked()), this, SLOT(saveDeltaTimeValue())); - connect(ui->button_remove, SIGNAL(clicked()), this, SLOT(clearDeltaTimeValue())); + connect(ui->button_add, SIGNAL(clicked()), this, SLOT(addDeltaTimeValue())); + connect(ui->button_remove, SIGNAL(clicked()), this, SLOT(removeDeltaTimeValue())); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections())); } -QString deltaTimes::createSummaryForDeltaTime(size_t idx, double dt, bool forListView) { +QString deltaTimes::createSummaryForDeltaTime(size_t idx, int dt, bool forListView) { std::string s; int k = (idx%10 == 9) ? 0 : idx%10 + 1; k = (idx == 0) ? 1 : k; @@ -40,7 +46,7 @@ QString deltaTimes::createSummaryForDeltaTime(size_t idx, double dt, bool forLis } if (dt != 0) { - s += (forListView) ? "\t" + std::to_string(static_cast(dt)) : ""; + s += (forListView) ? "\t" + std::to_string(dt) : ""; } if (forListView) { @@ -54,22 +60,22 @@ void deltaTimes::listItemSelected() { QListWidgetItem *item = ui->listWidget->currentItem(); int index = ui->listWidget->row(item); - if (index < (static_cast(_data.totalSize()) - 1)) { - if (index > lastSelectableItem() + 1) { - index = lastSelectableItem() + 1; - ui->listWidget->setCurrentRow(index); - } + if (index < (static_cast(_data.size()) - 1)) { + //if (index > lastSelectableItem() + 1) { + // index = lastSelectableItem() + 1; + ui->listWidget->setCurrentRow(index); + //} } QString labelS = "Set Delta Time for key "; - labelS += createSummaryForDeltaTime(index, _data._times.at(index), false); + labelS += createSummaryForDeltaTime(index, _data.at(index), false); labelS += " :\t"; ui->label_adjust->setText(labelS); - ui->line_seconds->setText(QString::number(_data._times.at(index))); + ui->line_seconds->setText(QString::number(_data.at(index))); } -int deltaTimes::lastSelectableItem() { +/*int deltaTimes::lastSelectableItem() { if (_data.size() == 0) { return 0; } @@ -89,9 +95,9 @@ int deltaTimes::lastSelectableItem() { else { return i + 1; } -} +}*/ -QString deltaTimes::timeDescription(double value) { +QString deltaTimes::timeDescription(int value) { QString description; if (value == 0) { @@ -107,29 +113,36 @@ QString deltaTimes::timeDescription(double value) { return checkForTimeDescription(i, value); } -QString deltaTimes::checkForTimeDescription(int intervalIndex, double value) { - double amount = static_cast(value) / - static_cast(_timeIntervals[intervalIndex].secondsPerInterval); +QString deltaTimes::checkForTimeDescription(int intervalIndex, int value) { +// double amount = static_cast(value) / +// static_cast(_timeIntervals[intervalIndex].secondsPerInterval); + int amount = value /_timeIntervals[intervalIndex].secondsPerInterval; QString description = QString::number(amount, 'g', 2); return description += " " + _timeIntervals[intervalIndex].intervalName + "/sec"; } +void deltaTimes::addDeltaTimeValue() { + if (_data.size() < _maxSize) { + if (_data.size() != 0 && _data.back() == 0) { + return; + } + _data.push_back(0); + QString summary = createSummaryForDeltaTime(_data.size() - 1, 0, true); + _deltaListItems.push_back(new QListWidgetItem(summary)); + ui->listWidget->addItem(_deltaListItems.back()); + } +} + void deltaTimes::saveDeltaTimeValue() { QListWidgetItem *item = ui->listWidget->currentItem(); if (item != nullptr) { int index = ui->listWidget->row(item); - if (isNumericalValue(ui->line_seconds) && index <= lastSelectableItem() + 1) { - _data._times.at(index) = ui->line_seconds->text().toDouble(); - QString summary = createSummaryForDeltaTime(index, _data._times.at(index), true); + if (isNumericalValue(ui->line_seconds) /*&& index <= lastSelectableItem() + 1*/) { + _data.at(index) = ui->line_seconds->text().toInt(); + QString summary = createSummaryForDeltaTime(index, _data.at(index), true); _deltaListItems.at(index)->setText(summary); } } - else if (_data.size() == 0) { - _data._times.at(0) = ui->line_seconds->text().toDouble(); - QString summary = createSummaryForDeltaTime(0, _data._times.at(0), true); - _deltaListItems.push_back(new QListWidgetItem(summary)); - ui->listWidget->addItem(_deltaListItems[0]); - } } bool deltaTimes::isNumericalValue(QLineEdit* le) { @@ -139,23 +152,24 @@ bool deltaTimes::isNumericalValue(QLineEdit* le) { return validConversion; } -void deltaTimes::clearDeltaTimeValue() { - int i; - for (i = _data.size() - 1; i >= 0; --i) { - if (_data._times.at(i) != 0) { - break; - } - } - if (i >= 0) { - _data._times.at(i) = 0; - QString summary = createSummaryForDeltaTime(i, _data._times.at(i), true); - _deltaListItems.at(i)->setText(summary); - ui->listWidget->setCurrentRow(i); - } +void deltaTimes::removeDeltaTimeValue() { + ui->listWidget->takeItem(_deltaListItems.size() - 1); + _data.pop_back(); + _deltaListItems.pop_back(); } void deltaTimes::parseSelections() { - _imported->setDeltaTimes(_data._times); + int finalNonzeroIndex = _data.size() - 1; + for (; finalNonzeroIndex >= 0; --finalNonzeroIndex) { + if (_data.at(finalNonzeroIndex) != 0) { + break; + } + } + std::vector tempDt; + for (size_t i = 0; i < (finalNonzeroIndex + 1); ++i) { + tempDt.push_back(static_cast(_data[i])); + } + _imported->setDeltaTimes(tempDt); accept(); } @@ -165,3 +179,10 @@ deltaTimes::~deltaTimes() { } delete ui; } + +void deltaTimes::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} diff --git a/apps/OpenSpace/ext/launcher/src/keybindings.cpp b/apps/OpenSpace/ext/launcher/src/keybindings.cpp index 614a1508bc..fcb3b8ff81 100644 --- a/apps/OpenSpace/ext/launcher/src/keybindings.cpp +++ b/apps/OpenSpace/ext/launcher/src/keybindings.cpp @@ -4,6 +4,7 @@ #include "./ui_keybindings.h" #include #include +#include keybindings::keybindings(openspace::Profile* imported, QWidget *parent) : QDialog(parent) @@ -270,3 +271,11 @@ keybindings::~keybindings() { } delete ui; } + +void keybindings::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} + diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index 0df117390b..bf1e87acc2 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -3,6 +3,7 @@ #include "profileedit.h" #include "./ui_launcherwindow.h" #include +#include #include "filesystemaccess.h" #include #include @@ -22,7 +23,6 @@ LauncherWindow::LauncherWindow(std::string basePath, QWidget *parent) ui->logolabel->setPixmap(pix.scaled(400, 120, Qt::KeepAspectRatio)); connect(ui->newButton, SIGNAL(released()), this, SLOT(openWindow_new())); connect(ui->editButton, SIGNAL(released()), this, SLOT(openWindow_edit())); - connect(ui->buttonSim, SIGNAL(released()), this, SLOT(simulateData())); _reportAssetsInFilesystem = _filesystemAccess.useQtFileSystemModelToTraverseDir( QString(basePath.c_str()) + "/data/assets"); populateProfilesList(); @@ -30,15 +30,19 @@ LauncherWindow::LauncherWindow(std::string basePath, QWidget *parent) } void LauncherWindow::populateProfilesList() { + for (int i = 0; i < ui->comboBoxProfiles->count(); ++i) { + ui->comboBoxProfiles->removeItem(i); + } std::string reportProfiles = _fileAccess_profiles.useQtFileSystemModelToTraverseDir( _basePath + "/data/profiles"); std::stringstream instream(reportProfiles); std::string iline; QStringList profilesListLine; while (std::getline(instream, iline)) { - profilesListLine << iline.c_str(); + if (ui->comboBoxProfiles->findText(QString(iline.c_str())) == -1) { + ui->comboBoxProfiles->addItem(iline.c_str()); + } } - ui->comboBoxProfiles->addItems(profilesListLine); } void LauncherWindow::populateWindowConfigsList() { @@ -54,33 +58,72 @@ void LauncherWindow::populateWindowConfigsList() { } void LauncherWindow::openWindow_new() { - clearData(); openspace::Profile* pData = new openspace::Profile(); if (pData != nullptr) { myEditorWindow = new ProfileEdit(pData, _reportAssetsInFilesystem); myEditorWindow->exec(); + if (myEditorWindow->wasSaved()) { + std::string saveProfilePath = _basePath.toUtf8().constData(); + saveProfilePath += "/data/profiles/"; + saveProfilePath += myEditorWindow->specifiedFilename() + ".profile"; + saveProfileToFile(saveProfilePath, pData); + } + delete pData; + populateProfilesList(); } - delete pData; } void LauncherWindow::openWindow_edit() { - std::string editProfilePath = _basePath.toUtf8().constData(); - editProfilePath += "/data/profiles/"; + std::string profilePath = _basePath.toUtf8().constData(); + profilePath += "/data/profiles/"; int selectedProfileIdx = ui->comboBoxProfiles->currentIndex(); QString profileToSet = ui->comboBoxProfiles->itemText(selectedProfileIdx); - editProfilePath += profileToSet.toUtf8().constData(); + std::string editProfilePath = profilePath + profileToSet.toUtf8().constData(); editProfilePath += ".profile"; openspace::Profile* pData; - loadProfileFromFile(pData, editProfilePath); - if (pData != nullptr) { + bool validFile = loadProfileFromFile(pData, editProfilePath); + if (pData != nullptr && validFile) { myEditorWindow = new ProfileEdit(pData, _reportAssetsInFilesystem); myEditorWindow->setProfileName(profileToSet); myEditorWindow->exec(); + if (myEditorWindow->wasSaved()) { + profilePath += myEditorWindow->specifiedFilename() + ".profile"; + saveProfileToFile(profilePath, pData); + } + delete pData; + populateProfilesList(); } - delete pData; +} + +void LauncherWindow::saveProfileToFile(const std::string& path, openspace::Profile* p) { + std::ofstream outFile; + try { + outFile.open(path, std::ofstream::out); + } + catch (const std::ofstream::failure& e) { + displayErrorDialog(fmt::format( + "Exception opening profile file {} for write: ({})", + path, + e.what() + )); + } + + try { + outFile << p->serialize(); + } + catch (const std::ofstream::failure& e) { + displayErrorDialog(fmt::format( + "Data write error to file: {} ({})", + path, + e.what() + )); + } + + outFile.close(); } bool LauncherWindow::loadProfileFromFile(openspace::Profile*& p, std::string filename) { + bool successfulLoad = true; std::vector content; if (filename.length() > 0) { std::ifstream inFile; @@ -103,249 +146,41 @@ bool LauncherWindow::loadProfileFromFile(openspace::Profile*& p, std::string fil p = new openspace::Profile(content); } catch (const ghoul::MissingCaseException& e) { - displayProfileParseErrorDialogThenQuit(fmt::format( + displayErrorDialog(fmt::format( "Missing case exception in {}: {}", filename, e.what() )); - return false; + successfulLoad = false; } catch (const openspace::Profile::ParsingError& e) { - displayProfileParseErrorDialogThenQuit(fmt::format( + displayErrorDialog(fmt::format( "ParsingError exception in {}: {}, {}", filename, e.component, e.message )); - return false; + successfulLoad = false; } catch (const ghoul::RuntimeError& e) { - displayProfileParseErrorDialogThenQuit(fmt::format( + displayErrorDialog(fmt::format( "RuntimeError exception in {}, component {}: {}", filename, e.component, e.message )); - return false; + successfulLoad = false; } - return true; + return successfulLoad; } -void LauncherWindow::displayProfileParseErrorDialogThenQuit(std::string msg) { +void LauncherWindow::displayErrorDialog(std::string msg) { //New instance of info dialog window _myDialog = new errordialog(QString(msg.c_str())); _myDialog->exec(); } -void LauncherWindow::receiveAssets(std::vector results) { - std::string windowText; - for (std::string line : results) { - windowText += line + "\n"; - } -} - LauncherWindow::~LauncherWindow() { delete ui; delete myEditorWindow; } - -void LauncherWindow::simulateData() { - initialize_meta(); - initialize_modules(); - initialize_assets(); - initialize_properties(); - initialize_keybindings(); - initialize_deltaTimes(); - initialize_time(); - initialize_camera(); - initialize_markNodes(); - initialize_addedScripts(); -} - -void LauncherWindow::clearData() { - _metaData = {"", "", "", "", "", ""}; - _moduleData.clear(); - _assetData.clear(); - _propsData.clear(); - _keybindingsData.clear(); - _deltaTimesData._times.clear(); - _timeData.time = ""; - openspace::Profile::CameraNavState c = {"", "", "", {0.0, 0.0, 0.0}, std::nullopt, std::nullopt, std::nullopt}; - _cameraData = c; - _markNodesData.clear(); - _addedScriptsData = ""; -} - -void LauncherWindow::initialize_meta() { - _metaData.name = "The meta name"; - _metaData.version = "0.15.2"; - _metaData.description = "Description here"; - _metaData.author = "Author"; - _metaData.url = "http://openspaceproject.com"; - _metaData.license = "MIT"; -} - -void LauncherWindow::initialize_modules() { - _moduleData = { - { - "base", - "Do stuff for base if it's loaded", - "" - }, - { - "globebrowsing", - "", - "" - }, - { - "gaia", - "", - "Command if gaia not loaded" - }, - { - "kameleon", - "script {\n line1\n line2\n}", - "Command if gaia not loaded" - }, - }; - -} - -void LauncherWindow::initialize_assets() { - - - _assetData = { - {"", "base"}, - {"examples", "spheres"}, - {"examples", "slidedeck"}, - {"scene/milkyway/gaia", "galah"}, - {"scene/solarsystem/missions/pioneer", "pioneer10"}, - {"scene/solarsystem/missions/spacex", "roadster"}, - {"scene/solarsystem/sun", "glare"}, - {"scene/solarsystem/sun", "marker"}, - {"util", "layer_helper"}, - {"customization", "gui"} - }; -} - -void LauncherWindow::initialize_properties() { - _propsData = { - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "NavigationHandler.OrbitalNavigator.FollowAnchorNodeRotationDistance", - "20.0" - }, - { - openspace::Profile::Property::SetType::SetPropertyValue, - "Scene.Pluto.Renderable.Enabled", - "false" - }, - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "Scene.Charon.Renderable.Enabled", - "false" - }, - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "Scene.PlutoBarycenterTrail.Renderable.Enabled", - "false" - }, - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "NavigationHandler.OrbitalNavigator.FollowAnchorNodeRotationDistance", - "20.0" - }, - { - openspace::Profile::Property::SetType::SetPropertyValue, - "Scene.Pluto.Renderable.Enabled", - "false" - }, - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "Scene.Styx.Renderable.Enabled", - "false" - }, - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "Scene.PlutoBarycenterTrail.Renderable.Enabled", - "false" - }, - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "NavigationHandler.OrbitalNavigator.FollowAnchorNodeRotationDistance", - "20.0" - }, - { - openspace::Profile::Property::SetType::SetPropertyValue, - "Scene.Pluto.Renderable.Enabled", - "false" - }, - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "Scene.StyxRenderableTrail.Renderable.Enabled", - "false" - }, - { - openspace::Profile::Property::SetType::SetPropertyValueSingle, - "Scene.PlutoBarycenterTrail.Renderable.Enabled", - "false" - }, - }; -} - -void LauncherWindow::initialize_keybindings() { - _keybindingsData = { - { - {openspace::Key::Equal, openspace::KeyModifier::Control}, - "Documentation for ctrl+=", - "Name for the keybinding", - "/Path/to/keys", - true, - "openspace.keybindings.local.variable.1" - }, - { - {openspace::Key::KeypadAdd, openspace::KeyModifier::Shift}, - "Documentation for shift++", - "Name for the keybinding", - "/Path/to/keys", - true, - "openspace.keybindings.local.variable.2" - }, - { - {openspace::Key::Keypad3, openspace::KeyModifier::NoModifier}, - "Documentation for '3'", - "Name for the keybinding", - "/Path/to/keys", - false, - "openspace.keybindings.local.variable.3" - }, - }; -} - -void LauncherWindow::initialize_deltaTimes() { - std::vector dt = {1, 2, 5, 10, 30, - 60, 120, 300, 600, 1800, - 3600, 7200, 10800, 21600, 43200, - 86400, 172800, 345600, 604800}; - _deltaTimesData.loadValues(dt); -} - -void LauncherWindow::initialize_time() { - _timeData.type = openspace::Profile::Time::Type::Absolute; - _timeData.time = "2011-04-17T21:23:59"; -} - -void LauncherWindow::initialize_camera() { - glm::dvec3 p = {1.0, 2.0, 3.0}; - glm::dvec3 u = {4.0, 5.0, 6.0}; - openspace::Profile::CameraNavState c = {"Earth", "Moon", "SUNREF", p, u, 180.0, 359.9}; - _cameraData = c; -} - -void LauncherWindow::initialize_markNodes() { - _markNodesData = {"Earth", "Moon", "Mars", "Jupiter", "Sun"}; -} - -void LauncherWindow::initialize_addedScripts() { - _addedScriptsData = "line1\nline2\nline3\nline4\nline5"; -} diff --git a/apps/OpenSpace/ext/launcher/src/marknodes.cpp b/apps/OpenSpace/ext/launcher/src/marknodes.cpp index ba2b0bb261..4bba573698 100644 --- a/apps/OpenSpace/ext/launcher/src/marknodes.cpp +++ b/apps/OpenSpace/ext/launcher/src/marknodes.cpp @@ -2,6 +2,7 @@ #include "./ui_marknodes.h" #include #include +#include markNodes::markNodes(openspace::Profile* imported, QWidget *parent) : QDialog(parent) @@ -77,3 +78,11 @@ markNodes::~markNodes() { } delete ui; } + +void markNodes::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} + diff --git a/apps/OpenSpace/ext/launcher/src/meta.cpp b/apps/OpenSpace/ext/launcher/src/meta.cpp index 0396e831c3..1ff1d81ee8 100644 --- a/apps/OpenSpace/ext/launcher/src/meta.cpp +++ b/apps/OpenSpace/ext/launcher/src/meta.cpp @@ -1,6 +1,8 @@ #include #include "meta.h" #include "./ui_meta.h" +#include +#include meta::meta(openspace::Profile* imported, QWidget *parent) : QDialog(parent) @@ -29,12 +31,21 @@ meta::meta(openspace::Profile* imported, QWidget *parent) connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save())); } +void meta::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} + void meta::save() { if (!areAllEntriesBlank()) { openspace::Profile::Meta m; m.name = ui->line_name->text().toUtf8().constData(); m.version = ui->line_version->text().toUtf8().constData(); - m.description = ui->text_description->toPlainText().toUtf8().constData(); + std::string desc = ui->text_description->toPlainText().toUtf8().constData(); + std::replace(desc.begin(), desc.end(), '\n', ' '); + m.description = desc; m.author = ui->line_author->text().toUtf8().constData(); m.url = ui->line_url->text().toUtf8().constData(); m.license = ui->line_license->text().toUtf8().constData(); diff --git a/apps/OpenSpace/ext/launcher/src/osmodules.cpp b/apps/OpenSpace/ext/launcher/src/osmodules.cpp index 3e964c11ef..a321e69cfe 100644 --- a/apps/OpenSpace/ext/launcher/src/osmodules.cpp +++ b/apps/OpenSpace/ext/launcher/src/osmodules.cpp @@ -2,6 +2,7 @@ #include "osmodules.h" #include "./ui_osmodules.h" #include +#include osmodules::osmodules(openspace::Profile* imported, QWidget *parent) : QDialog(parent) @@ -151,3 +152,11 @@ osmodules::~osmodules() { } delete ui; } + +void osmodules::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} + diff --git a/apps/OpenSpace/ext/launcher/src/ostime.cpp b/apps/OpenSpace/ext/launcher/src/ostime.cpp index 199c4d006d..34e59a8511 100644 --- a/apps/OpenSpace/ext/launcher/src/ostime.cpp +++ b/apps/OpenSpace/ext/launcher/src/ostime.cpp @@ -2,6 +2,7 @@ #include "ostime.h" #include "./ui_ostime.h" #include +#include ostime::ostime(openspace::Profile* imported, QWidget *parent) : QDialog(parent) @@ -10,14 +11,19 @@ ostime::ostime(openspace::Profile* imported, QWidget *parent) { ui->setupUi(this); + QStringList types { "Absolute", "Relative" }; + ui->combo_type->addItems(types); if (_imported->time().has_value()) { - QStringList types { "Absolute", "Relative" }; - ui->combo_type->addItems(types); - _data = _imported->time().value(); + _data = _imported->time().value(); + if (_data.type == openspace::Profile::Time::Type::Relative) { + if (_data.time == "") { + _data.time = "now"; + } + } } else { _data.type = openspace::Profile::Time::Type::Relative; - _data.time = ""; + _data.time = "now"; } _initializedAsAbsolute = (_data.type == openspace::Profile::Time::Type::Absolute); enableAccordingToType(static_cast(_data.type)); @@ -36,7 +42,7 @@ void ostime::enableAccordingToType(int idx) { if (comboIdx == openspace::Profile::Time::Type::Relative) { ui->label_relative->setText("Relative Time:"); if (_initializedAsAbsolute) { - ui->line_relative->setText(""); + ui->line_relative->setText("now"); } else { ui->line_relative->setText(QString(_data.time.c_str())); @@ -92,3 +98,11 @@ void ostime::approved() { } accept(); } + +void ostime::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} + diff --git a/apps/OpenSpace/ext/launcher/src/profileedit.cpp b/apps/OpenSpace/ext/launcher/src/profileedit.cpp index 9710ca23b5..c6795d2d65 100644 --- a/apps/OpenSpace/ext/launcher/src/profileedit.cpp +++ b/apps/OpenSpace/ext/launcher/src/profileedit.cpp @@ -2,6 +2,7 @@ #include "profileedit.h" #include "./ui_profileedit.h" #include "filesystemaccess.h" +#include template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; @@ -325,9 +326,36 @@ QString ProfileEdit::summarizeText_markNodes() { return results; } +bool ProfileEdit::wasSaved() { + return _saveSelected; +} + +std::string ProfileEdit::specifiedFilename() { + return ui->line_profile->text().toUtf8().constData(); +} + void ProfileEdit::cancel() { + _saveSelected = false; reject(); } void ProfileEdit::approved() { + if (ui->line_profile->text().length() > 0) { + _saveSelected = true; + accept(); + } + else { + QString formatText = ""; + formatText += ui->label_profile->text(); + formatText += ""; + ui->label_profile->setText(formatText); + } } + +void ProfileEdit::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} + diff --git a/apps/OpenSpace/ext/launcher/src/properties.cpp b/apps/OpenSpace/ext/launcher/src/properties.cpp index f3be1407c0..712c76914e 100644 --- a/apps/OpenSpace/ext/launcher/src/properties.cpp +++ b/apps/OpenSpace/ext/launcher/src/properties.cpp @@ -2,6 +2,7 @@ #include "properties.h" #include "./ui_properties.h" #include +#include properties::properties(openspace::Profile* imported, QWidget *parent) : QDialog(parent) @@ -203,3 +204,11 @@ properties::~properties() { } delete ui; } + +void properties::keyPressEvent(QKeyEvent *evt) +{ + if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) + return; + QDialog::keyPressEvent(evt); +} +