From 180cddfaa3d99e6c878b21713ab5a3e507160f83 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Wed, 16 Sep 2020 21:06:46 -0600 Subject: [PATCH] Fixed parse exceptions and improved assets with path and variable name --- apps/OpenSpace/ext/launcher/include/assets.h | 7 +- .../ext/launcher/include/assettreeitem.h | 1 + .../ext/launcher/include/assettreemodel.h | 15 ++- .../ext/launcher/include/launcherwindow.h | 4 +- .../ext/launcher/include/profileedit.h | 10 +- .../ext/launcher/include/ui_assets.h | 28 +++++- apps/OpenSpace/ext/launcher/src/assets.cpp | 70 ++++++++------ apps/OpenSpace/ext/launcher/src/assets.ui | 55 ++++++++++- .../ext/launcher/src/assettreeitem.cpp | 4 + .../ext/launcher/src/assettreemodel.cpp | 30 ++++-- .../ext/launcher/src/launcherwindow.cpp | 76 ++++++++++++++- .../ext/launcher/src/profileedit.cpp | 94 ++++--------------- data/profiles/insight.profile | 2 +- data/profiles/rosetta.profile | 2 +- data/profiles/touch.profile | 2 +- include/openspace/scene/profile.h | 2 +- src/scene/profile.cpp | 28 ++++-- 17 files changed, 274 insertions(+), 156 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/include/assets.h b/apps/OpenSpace/ext/launcher/include/assets.h index 11c0fafc0e..690c9934ff 100644 --- a/apps/OpenSpace/ext/launcher/include/assets.h +++ b/apps/OpenSpace/ext/launcher/include/assets.h @@ -21,6 +21,8 @@ class assets : public QDialog public slots: void cancel(); void parseSelections(); + void selected(const QModelIndex&); + void setVarName(); public: explicit assets(openspace::Profile* imported, const std::string reportAssets, @@ -34,13 +36,14 @@ protected: private: void compareFilesystemWithProfileAssets(); bool traverseToExpandSelectedItems(int nRows, QModelIndex parent); - void findPathMatch(std::string& path, std::string& filename); + void findPathMatch(std::string& path, std::string& varName); void traverseToFindFilesystemMatch(QModelIndex parent, int nRows, - std::string dirname, std::string filename); + std::string dirname, std::string varName); Ui::assets *ui; QWidget* _parent; openspace::Profile* _imported; assetTreeModel _assetTreeModel; + QModelIndex _selectedIdx; }; #endif // ASSETS_H diff --git a/apps/OpenSpace/ext/launcher/include/assettreeitem.h b/apps/OpenSpace/ext/launcher/include/assettreeitem.h index 78fb014465..da0db8c8ac 100644 --- a/apps/OpenSpace/ext/launcher/include/assettreeitem.h +++ b/apps/OpenSpace/ext/launcher/include/assettreeitem.h @@ -52,6 +52,7 @@ public: void setExistsInFilesystem(bool fileExists); bool doesExistInFilesystem() const; QString name() const; + QString varName() const; static const int checkboxColumn = 1; private: diff --git a/apps/OpenSpace/ext/launcher/include/assettreemodel.h b/apps/OpenSpace/ext/launcher/include/assettreemodel.h index 6aad41824c..a860ccd725 100644 --- a/apps/OpenSpace/ext/launcher/include/assettreemodel.h +++ b/apps/OpenSpace/ext/launcher/include/assettreemodel.h @@ -27,15 +27,17 @@ #include #include "assettreeitem.h" +#include "openspace/scene/profile.h" struct importElement { - importElement(std::string l, int lev, bool chk) - : line(l), level(lev), checked(chk) {} + importElement(std::string l, int lev, bool chk, std::string vname) + : line(l), level(lev), checked(chk), varname(vname) {} std::string line; int level = -1; bool checked = false; bool existsInFilesystem = true; + std::string varname; }; class assetTreeModel : public QAbstractItemModel @@ -43,7 +45,8 @@ class assetTreeModel : public QAbstractItemModel Q_OBJECT public: - explicit assetTreeModel(QString header1, QString header2, QObject* parent = nullptr); + explicit assetTreeModel(QString header1, QString header2, QString header3, + QObject* parent = nullptr); ~assetTreeModel(); QVariant data(const QModelIndex &index, int role) const override; @@ -60,7 +63,7 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; - std::vector selectedAssets(); + std::vector selectedAssets(); void importModelData(const std::string contents); bool isChecked(QModelIndex& index) const; bool isAsset(QModelIndex& index) const; @@ -71,12 +74,14 @@ public: void setName(QModelIndex& index, QString name); void setChecked(QModelIndex& index, bool checked); void setExistenceInFilesystem(QModelIndex& index, bool fileExists); + QString varName(const QModelIndex& index) const; + void setVarName(QModelIndex& index, QString varName); private: std::string headerTitle; assetTreeItem *getItem(const QModelIndex &index) const; assetTreeItem *rootItem; - void parseChildrenForSelected(assetTreeItem* item, std::vector& output, + void parseChildrenForSelected(assetTreeItem* item, std::vector& output, std::string pathPrefix); void importInsertItem(std::istringstream& iss, assetTreeItem* parent, importElement& elem, int level); diff --git a/apps/OpenSpace/ext/launcher/include/launcherwindow.h b/apps/OpenSpace/ext/launcher/include/launcherwindow.h index ceed90dba7..066d320956 100644 --- a/apps/OpenSpace/ext/launcher/include/launcherwindow.h +++ b/apps/OpenSpace/ext/launcher/include/launcherwindow.h @@ -28,6 +28,8 @@ public: 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(); @@ -42,9 +44,9 @@ private: Ui::LauncherWindow *ui; ProfileEdit* myEditorWindow; + errordialog* _myDialog; filesystemAccess _fileAccess_profiles; filesystemAccess _fileAccess_winConfigs; - openspace::Profile::Meta _metaData; std::vector _moduleData; std::vector _assetData; diff --git a/apps/OpenSpace/ext/launcher/include/profileedit.h b/apps/OpenSpace/ext/launcher/include/profileedit.h index ff29780d8a..027da4ddce 100644 --- a/apps/OpenSpace/ext/launcher/include/profileedit.h +++ b/apps/OpenSpace/ext/launcher/include/profileedit.h @@ -42,13 +42,11 @@ public slots: void approved(); public: - explicit ProfileEdit(std::string filename, const std::string reportedAssets, QWidget *parent = nullptr); + explicit ProfileEdit(openspace::Profile* profile, const std::string reportedAssets, QWidget *parent = nullptr); ~ProfileEdit(); void setProfileName(QString profileToSet); private: - bool loadProfileFromFile(std::string filename); - void displayProfileParseErrorDialogThenQuit(std::string msg); void initSummaryTextForEachCategory(); QString summarizeText_meta(); QString summarizeText_modules(); @@ -63,7 +61,6 @@ private: Ui::ProfileEdit *ui; QWidget* _parent; - errordialog* _myDialog; meta* _meta; properties* _properties; osmodules* _modules; @@ -74,10 +71,7 @@ private: deltaTimes* _deltaTimes; camera* _camera; markNodes* _markNodes; - - //ProfileBlock _pData; - openspace::Profile* _pData = nullptr; - std::vector _content; + openspace::Profile* _pData; const std::string _reportedAssets; }; diff --git a/apps/OpenSpace/ext/launcher/include/ui_assets.h b/apps/OpenSpace/ext/launcher/include/ui_assets.h index 4324310c3e..e8d8d83096 100644 --- a/apps/OpenSpace/ext/launcher/include/ui_assets.h +++ b/apps/OpenSpace/ext/launcher/include/ui_assets.h @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #include QT_BEGIN_NAMESPACE @@ -23,26 +26,43 @@ class Ui_assets public: QDialogButtonBox *buttonBox; QTreeView *treeView; + QPushButton *varName; + QLineEdit *lineEdit; + QLabel *label; void setupUi(QDialog *assets) { if (assets->objectName().isEmpty()) assets->setObjectName(QString::fromUtf8("assets")); - assets->resize(470, 442); + assets->resize(610, 479); buttonBox = new QDialogButtonBox(assets); buttonBox->setObjectName(QString::fromUtf8("buttonBox")); - buttonBox->setGeometry(QRect(110, 400, 341, 32)); + buttonBox->setGeometry(QRect(240, 430, 341, 32)); buttonBox->setOrientation(Qt::Horizontal); buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); treeView = new QTreeView(assets); treeView->setObjectName(QString::fromUtf8("treeView")); - treeView->setGeometry(QRect(20, 20, 431, 351)); + treeView->setGeometry(QRect(20, 20, 571, 351)); QFont font; font.setFamily(QString::fromUtf8("Arial")); treeView->setFont(font); treeView->setStyleSheet(QString::fromUtf8("background-color: rgb(85, 87, 83);")); treeView->setAlternatingRowColors(false); treeView->setAnimated(false); + varName = new QPushButton(assets); + varName->setObjectName(QString::fromUtf8("varName")); + varName->setGeometry(QRect(130, 430, 121, 25)); + lineEdit = new QLineEdit(assets); + lineEdit->setObjectName(QString::fromUtf8("lineEdit")); + lineEdit->setGeometry(QRect(130, 390, 261, 25)); + label = new QLabel(assets); + label->setObjectName(QString::fromUtf8("label")); + label->setGeometry(QRect(30, 390, 71, 61)); + QFont font1; + font1.setFamily(QString::fromUtf8("Arial")); + font1.setPointSize(12); + label->setFont(font1); + label->setWordWrap(true); retranslateUi(assets); //QObject::connect(buttonBox, SIGNAL(accepted()), assets, SLOT(accept())); @@ -57,6 +77,8 @@ public: #if QT_CONFIG(tooltip) treeView->setToolTip(QCoreApplication::translate("assets", "

Expand arrow entries to browse assets in this OpenSpace installation. Enable checkbox to include an asset. Those assets highlighted in red are present in the profile but do not exist in this OpenSpace installation.

", nullptr)); #endif // QT_CONFIG(tooltip) + varName->setText(QCoreApplication::translate("assets", "Modify Name", nullptr)); + label->setText(QCoreApplication::translate("assets", "Optional variable name", nullptr)); } // retranslateUi }; diff --git a/apps/OpenSpace/ext/launcher/src/assets.cpp b/apps/OpenSpace/ext/launcher/src/assets.cpp index 6a0f3761d6..ef43c630d1 100644 --- a/apps/OpenSpace/ext/launcher/src/assets.cpp +++ b/apps/OpenSpace/ext/launcher/src/assets.cpp @@ -11,7 +11,7 @@ assets::assets(openspace::Profile* imported, const std::string reportAssets, QWi : QDialog(parent) , ui(new Ui::assets) , _imported(imported) - , _assetTreeModel(tr("Asset"), tr("Enabled")) + , _assetTreeModel(tr("Asset"), tr("Enabled"), tr("Var Name")) { ui->setupUi(this); @@ -19,15 +19,24 @@ assets::assets(openspace::Profile* imported, const std::string reportAssets, QWi ui->treeView->setModel(&_assetTreeModel); ui->treeView->setRootIndex(_assetTreeModel.index(-1, 0)); - ui->treeView->setColumnWidth(0, ui->treeView->width() * 0.8); + ui->treeView->setColumnWidth(0, ui->treeView->width() * 0.63); + ui->treeView->setColumnWidth(1, ui->treeView->width() * 0.12); + ui->treeView->setColumnWidth(2, ui->treeView->width() * 0.25); ui->treeView->setAnimated(true); ui->treeView->setSortingEnabled(false); + ui->treeView->setSelectionMode(QAbstractItemView::SingleSelection); compareFilesystemWithProfileAssets(); int nRows = _assetTreeModel.rowCount(_assetTreeModel.index(-1, 0)); traverseToExpandSelectedItems(nRows, _assetTreeModel.index(-1, 0)); + connect(ui->treeView, + SIGNAL(clicked(const QModelIndex&)), + this, + SLOT(selected(const QModelIndex&)) + ); + connect(ui->varName, SIGNAL(clicked()), this, SLOT(setVarName())); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel())); } @@ -38,21 +47,21 @@ void assets::compareFilesystemWithProfileAssets() { } } -void assets::findPathMatch(std::string& path, std::string& filename) { +void assets::findPathMatch(std::string& path, std::string& varName) { QModelIndex parent = _assetTreeModel.index(-1, 0); int nRows = _assetTreeModel.rowCount(parent); - traverseToFindFilesystemMatch(parent, nRows, path, filename); + traverseToFindFilesystemMatch(parent, nRows, path, varName); } void assets::traverseToFindFilesystemMatch(QModelIndex parent, int nRows, - std::string path, std::string filename) + std::string path, std::string varName) { - bool endOfPath = (path.length() == 0); size_t slash = path.find_first_of('/', 0); - std::string firstDir = endOfPath ? path : path.substr(0, slash); + bool endOfPath = (slash == std::string::npos); + std::string firstDir = endOfPath ? "" : path.substr(0, slash); if (!endOfPath) { - std::string nextPath = (slash == std::string::npos) ? "" : + std::string nextPath = (slash == std::string::npos) ? path : path.substr(slash + 1); bool foundDirMatch = false; for (int r = 0; r < nRows; r++) { @@ -62,7 +71,7 @@ void assets::traverseToFindFilesystemMatch(QModelIndex parent, int nRows, if (firstDir.compare(assetName) == 0) { int nChildRows = _assetTreeModel.childCount(idx); foundDirMatch = true; - traverseToFindFilesystemMatch(idx, nChildRows, nextPath, filename); + traverseToFindFilesystemMatch(idx, nChildRows, nextPath, varName); break; } } @@ -72,11 +81,11 @@ void assets::traverseToFindFilesystemMatch(QModelIndex parent, int nRows, } if (!foundDirMatch) { //Insert missing directory here with name and exists=false condition - _assetTreeModel.assetItem(parent)->insertChildren(nRows, 1, 2); + _assetTreeModel.assetItem(parent)->insertChildren(nRows, 1, 3); QModelIndex idx = _assetTreeModel.index(nRows, 0, parent); _assetTreeModel.setName(idx, QString(firstDir.c_str())); _assetTreeModel.setExistenceInFilesystem(idx, false); - traverseToFindFilesystemMatch(idx, 0, nextPath, filename); + traverseToFindFilesystemMatch(idx, 0, nextPath, varName); } } else { @@ -85,18 +94,20 @@ void assets::traverseToFindFilesystemMatch(QModelIndex parent, int nRows, QModelIndex idx = _assetTreeModel.index(r, 0, parent); std::string assetName = _assetTreeModel.name(idx).toUtf8().constData(); - if (filename.compare(assetName) == 0) { + if (path.compare(assetName) == 0) { foundFileMatch = true; _assetTreeModel.setChecked(idx, true); + _assetTreeModel.setVarName(idx, QString(varName.c_str())); break; } } if (!foundFileMatch) { //Insert missing file here with name and exists=false condition - _assetTreeModel.assetItem(parent)->insertChildren(nRows, 1, 2); + _assetTreeModel.assetItem(parent)->insertChildren(nRows, 1, 3); QModelIndex idx = _assetTreeModel.index(nRows, 0, parent); - _assetTreeModel.setName(idx, QString(filename.c_str())); + _assetTreeModel.setName(idx, QString(path.c_str())); _assetTreeModel.setChecked(idx, true); + _assetTreeModel.setVarName(idx, QString(varName.c_str())); _assetTreeModel.setExistenceInFilesystem(idx, false); } } @@ -124,30 +135,33 @@ bool assets::traverseToExpandSelectedItems(int nRows, QModelIndex parent) { std::string assets::createTextSummary() { std::string summary; - for (std::string line : _assetTreeModel.selectedAssets()) { - summary += line + "\n"; + for (openspace::Profile::Asset sel : _assetTreeModel.selectedAssets()) { + summary += sel.path + " " + sel.name + "\n"; } return summary; } void assets::parseSelections() { _imported->clearAssets(); - for (std::string selected : _assetTreeModel.selectedAssets()) { - openspace::Profile::Asset a; - size_t slash = selected.find_last_of('/'); - if (slash == std::string::npos) { - a.path = ""; - a.name = selected; - } - else { - a.path = selected.substr(0, slash); - a.name = selected.substr(slash + 1); - } - _imported->addAsset(a.path + "/" + a.name); + for (openspace::Profile::Asset sel : _assetTreeModel.selectedAssets()) { + _imported->addAsset(sel.path, sel.name); } accept(); } +void assets::selected(const QModelIndex& sel) { + _selectedIdx = sel; + QString existingVarName = _assetTreeModel.varName(_selectedIdx); + ui->lineEdit->setText(existingVarName); +} + +void assets::setVarName() { + _assetTreeModel.setVarName(_selectedIdx, ui->lineEdit->text()); + ui->treeView->reset(); + int nRows = _assetTreeModel.rowCount(_assetTreeModel.index(-1, 0)); + traverseToExpandSelectedItems(nRows, _assetTreeModel.index(-1, 0)); +} + assets::~assets() { delete ui; } diff --git a/apps/OpenSpace/ext/launcher/src/assets.ui b/apps/OpenSpace/ext/launcher/src/assets.ui index 4fbab4c4e7..d9b5cdbc2a 100644 --- a/apps/OpenSpace/ext/launcher/src/assets.ui +++ b/apps/OpenSpace/ext/launcher/src/assets.ui @@ -6,8 +6,8 @@ 0 0 - 470 - 442 + 610 + 479 @@ -16,8 +16,8 @@ - 110 - 400 + 240 + 430 341 32 @@ -34,7 +34,7 @@ 20 20 - 431 + 571 351 @@ -56,6 +56,51 @@ false + + + + 130 + 430 + 121 + 25 + + + + Modify Name + + + + + + 130 + 390 + 261 + 25 + + + + + + + 30 + 390 + 71 + 61 + + + + + Arial + 12 + + + + Optional variable name + + + true + + diff --git a/apps/OpenSpace/ext/launcher/src/assettreeitem.cpp b/apps/OpenSpace/ext/launcher/src/assettreeitem.cpp index 13ac3862e2..6f9156a654 100644 --- a/apps/OpenSpace/ext/launcher/src/assettreeitem.cpp +++ b/apps/OpenSpace/ext/launcher/src/assettreeitem.cpp @@ -105,6 +105,10 @@ QString assetTreeItem::name() const { return QString(data(0).toString()); } +QString assetTreeItem::varName() const { + return QString(data(2).toString()); +} + bool assetTreeItem::insertChildren(int position, int count, int columns) { if (position < 0 || position > _childItems.size()) diff --git a/apps/OpenSpace/ext/launcher/src/assettreemodel.cpp b/apps/OpenSpace/ext/launcher/src/assettreemodel.cpp index 27ccebdb57..f55ec54c46 100644 --- a/apps/OpenSpace/ext/launcher/src/assettreemodel.cpp +++ b/apps/OpenSpace/ext/launcher/src/assettreemodel.cpp @@ -27,22 +27,22 @@ #include #include -assetTreeModel::assetTreeModel(QString header1, QString header2, QObject* parent) +assetTreeModel::assetTreeModel(QString header1, QString header2, QString header3, + QObject* parent) : QAbstractItemModel(parent), headerTitle(header1.toUtf8().constData()) { QVector rootData; - rootItem = new assetTreeItem({header1, header2}); + rootItem = new assetTreeItem({header1, header2, header3}); } - assetTreeModel::~assetTreeModel() { delete rootItem; } void assetTreeModel::importModelData(const std::string contents) { std::istringstream iss(contents.c_str()); - importElement rootElem = {"", 0, false}; + importElement rootElem = {"", 0, false, ""}; if (importGetNextLine(rootElem, iss)) { importInsertItem(iss, rootItem, rootElem, 0); @@ -59,11 +59,12 @@ void assetTreeModel::importInsertItem(std::istringstream& iss, assetTreeItem* pa int levelChange = elem.level - level; if (levelChange == 0) { - parent->insertChildren(++nChildInsert, 1, 2); + parent->insertChildren(++nChildInsert, 1, 3); parent->child(nChildInsert)->setData(0, QString::fromUtf8(elem.line.c_str())); bool shouldMakeElemChecked = (elem.checked || !elem.existsInFilesystem); Qt::CheckState check = (shouldMakeElemChecked) ? Qt::Checked : Qt::Unchecked; parent->child(nChildInsert)->setData(1, check); + parent->child(nChildInsert)->setData(2, ""); parent->child(nChildInsert)->setExistsInFilesystem(elem.existsInFilesystem); continueToNextLine = importGetNextLine(elem, iss); } @@ -145,6 +146,14 @@ QString assetTreeModel::name(QModelIndex& index) const { return getItem(index)->name(); } +QString assetTreeModel::varName(const QModelIndex& index) const { + return getItem(index)->varName(); +} + +void assetTreeModel::setVarName(QModelIndex& index, QString varName) { + getItem(index)->setData(2, varName); +} + void assetTreeModel::setName(QModelIndex& index, QString name) { getItem(index)->setData(0, name); } @@ -166,7 +175,6 @@ assetTreeItem* assetTreeModel::child(int row) const { return nullptr; } - QModelIndex assetTreeModel::index(int row, int column, const QModelIndex& parent) const { if (parent.isValid() && parent.column() != 0) return QModelIndex(); @@ -287,22 +295,24 @@ QVariant assetTreeModel::headerData(int section, Qt::Orientation orientation, return QVariant(); } -std::vector assetTreeModel::selectedAssets() { - std::vector output; +std::vector assetTreeModel::selectedAssets() { + std::vector output; parseChildrenForSelected(rootItem, output, ""); return output; } void assetTreeModel::parseChildrenForSelected(assetTreeItem* item, - std::vector& output, + std::vector& output, std::string pathPrefix) { std::string itemName = item->data(0).toString().toUtf8().constData(); + std::string varName = item->data(2).toString().toUtf8().constData(); bool isPathPrefix = ((pathPrefix.length()) == 0 && (itemName == headerTitle)); if (item->isAsset()) { if (item->isChecked()) { - output.push_back(pathPrefix + itemName); + std::string path = pathPrefix + itemName; + output.push_back(openspace::Profile::Asset({path, varName})); } } else { diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index 5c1d91a7c0..0df117390b 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -55,8 +55,12 @@ void LauncherWindow::populateWindowConfigsList() { void LauncherWindow::openWindow_new() { clearData(); - myEditorWindow = new ProfileEdit("", _reportAssetsInFilesystem); - myEditorWindow->exec(); + openspace::Profile* pData = new openspace::Profile(); + if (pData != nullptr) { + myEditorWindow = new ProfileEdit(pData, _reportAssetsInFilesystem); + myEditorWindow->exec(); + } + delete pData; } void LauncherWindow::openWindow_edit() { @@ -66,9 +70,71 @@ void LauncherWindow::openWindow_edit() { QString profileToSet = ui->comboBoxProfiles->itemText(selectedProfileIdx); editProfilePath += profileToSet.toUtf8().constData(); editProfilePath += ".profile"; - myEditorWindow = new ProfileEdit(editProfilePath, _reportAssetsInFilesystem); - myEditorWindow->setProfileName(profileToSet); - myEditorWindow->exec(); + openspace::Profile* pData; + loadProfileFromFile(pData, editProfilePath); + if (pData != nullptr) { + myEditorWindow = new ProfileEdit(pData, _reportAssetsInFilesystem); + myEditorWindow->setProfileName(profileToSet); + myEditorWindow->exec(); + } + delete pData; +} + +bool LauncherWindow::loadProfileFromFile(openspace::Profile*& p, std::string filename) { + std::vector content; + if (filename.length() > 0) { + std::ifstream inFile; + try { + inFile.open(filename, std::ifstream::in); + } + catch (const std::ifstream::failure& e) { + throw ghoul::RuntimeError(fmt::format( + "Exception opening {} profile for read: ({})", + filename, + e.what() + )); + } + std::string line; + while (std::getline(inFile, line)) { + content.push_back(std::move(line)); + } + } + try { + p = new openspace::Profile(content); + } + catch (const ghoul::MissingCaseException& e) { + displayProfileParseErrorDialogThenQuit(fmt::format( + "Missing case exception in {}: {}", + filename, + e.what() + )); + return false; + } + catch (const openspace::Profile::ParsingError& e) { + displayProfileParseErrorDialogThenQuit(fmt::format( + "ParsingError exception in {}: {}, {}", + filename, + e.component, + e.message + )); + return false; + } + catch (const ghoul::RuntimeError& e) { + displayProfileParseErrorDialogThenQuit(fmt::format( + "RuntimeError exception in {}, component {}: {}", + filename, + e.component, + e.message + )); + return false; + } + return true; +} + +void LauncherWindow::displayProfileParseErrorDialogThenQuit(std::string msg) { + //New instance of info dialog window + _myDialog = new errordialog(QString(msg.c_str())); + _myDialog->exec(); } void LauncherWindow::receiveAssets(std::vector results) { diff --git a/apps/OpenSpace/ext/launcher/src/profileedit.cpp b/apps/OpenSpace/ext/launcher/src/profileedit.cpp index 7e002cd12d..9710ca23b5 100644 --- a/apps/OpenSpace/ext/launcher/src/profileedit.cpp +++ b/apps/OpenSpace/ext/launcher/src/profileedit.cpp @@ -6,89 +6,32 @@ template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; -ProfileEdit::ProfileEdit(std::string filename, const std::string reportedAssets, QWidget *parent) +ProfileEdit::ProfileEdit(openspace::Profile* profile, const std::string reportedAssets, QWidget *parent) : QDialog(parent) , ui(new Ui::ProfileEdit) , _reportedAssets(reportedAssets) + , _pData(profile) { ui->setupUi(this); - loadProfileFromFile(filename); - - initSummaryTextForEachCategory(); - connect(ui->edit_meta, SIGNAL(clicked()), this, SLOT(openMeta())); - connect(ui->edit_properties, SIGNAL(clicked()), this, SLOT(openProperties())); - connect(ui->edit_modules, SIGNAL(clicked()), this, SLOT(openModules())); - connect(ui->edit_keybindings, SIGNAL(clicked()), this, SLOT(openKeybindings())); - connect(ui->edit_assets, SIGNAL(clicked()), this, SLOT(openAssets())); - connect(ui->edit_time, SIGNAL(clicked()), this, SLOT(openTime())); - connect(ui->edit_additionalscripts, SIGNAL(clicked()), this, SLOT(openAddedScripts())); - connect(ui->edit_deltatimes, SIGNAL(clicked()), this, SLOT(openDeltaTimes())); - connect(ui->edit_camera, SIGNAL(clicked()), this, SLOT(openCamera())); - connect(ui->edit_marknodes, SIGNAL(clicked()), this, SLOT(openMarkNodes())); - connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(approved())); - connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel())); + if (_pData != nullptr) { + initSummaryTextForEachCategory(); + connect(ui->edit_meta, SIGNAL(clicked()), this, SLOT(openMeta())); + connect(ui->edit_properties, SIGNAL(clicked()), this, SLOT(openProperties())); + connect(ui->edit_modules, SIGNAL(clicked()), this, SLOT(openModules())); + connect(ui->edit_keybindings, SIGNAL(clicked()), this, SLOT(openKeybindings())); + connect(ui->edit_assets, SIGNAL(clicked()), this, SLOT(openAssets())); + connect(ui->edit_time, SIGNAL(clicked()), this, SLOT(openTime())); + connect(ui->edit_additionalscripts, SIGNAL(clicked()), this, SLOT(openAddedScripts())); + connect(ui->edit_deltatimes, SIGNAL(clicked()), this, SLOT(openDeltaTimes())); + connect(ui->edit_camera, SIGNAL(clicked()), this, SLOT(openCamera())); + connect(ui->edit_marknodes, SIGNAL(clicked()), this, SLOT(openMarkNodes())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(approved())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel())); + } } ProfileEdit::~ProfileEdit() { delete ui; - delete _pData; -} - -bool ProfileEdit::loadProfileFromFile(std::string filename) { - if (filename.length() > 0) { - std::ifstream inFile; - try { - inFile.open(filename, std::ifstream::in); - } - catch (const std::ifstream::failure& e) { - throw ghoul::RuntimeError(fmt::format( - "Exception opening {} profile for read: ({})", - filename, - e.what() - )); - } - std::string line; - while (std::getline(inFile, line)) { - _content.push_back(std::move(line)); - } - } - try { - _pData = new openspace::Profile(_content); - } - catch (const ghoul::MissingCaseException& e) { - displayProfileParseErrorDialogThenQuit(fmt::format( - "Missing case exception in {}: {}", - filename, - e.what() - )); - return false; - } - catch (const openspace::Profile::ParsingError& e) { - displayProfileParseErrorDialogThenQuit(fmt::format( - "ParsingError exception in {}: {}, {}", - filename, - e.component, - e.message - )); - return false; - } - catch (const ghoul::RuntimeError& e) { - displayProfileParseErrorDialogThenQuit(fmt::format( - "RuntimeError exception in {}, component {}: {}", - filename, - e.component, - e.message - )); - return false; - } - return true; -} - -void ProfileEdit::displayProfileParseErrorDialogThenQuit(std::string msg) { - //New instance of info dialog window - _myDialog = new errordialog(QString(msg.c_str())); - _myDialog->exec(); - cancel(); } void ProfileEdit::initSummaryTextForEachCategory() { @@ -281,7 +224,7 @@ QString ProfileEdit::summarizeText_assets() { } QString results = QString("\n").arg(_pData->assets().size()); for (openspace::Profile::Asset a : _pData->assets()) { - results += " " + QString(a.path.c_str()) + "/"; + results += " " + QString(a.path.c_str()) + " "; results += QString(a.name.c_str()) + "\n"; } return results; @@ -384,7 +327,6 @@ QString ProfileEdit::summarizeText_markNodes() { void ProfileEdit::cancel() { reject(); - rejected(); } void ProfileEdit::approved() { diff --git a/data/profiles/insight.profile b/data/profiles/insight.profile index 8367730f5e..389f8b1951 100644 --- a/data/profiles/insight.profile +++ b/data/profiles/insight.profile @@ -24,7 +24,7 @@ SHIFT+i Undo Insight landing layers setup Unset Insight layers /Missions/Insight absolute 2018 NOV 26 19:39:03.68 #Camera -setNavigationState insightAsset.Insight.Identifier "Root" 8.430115E0, -1.791710E1, 2.813660E0 0.494659E0,0.357162E0,0.792306E0 +setNavigationState insightAsset.Insight.Identifier "Root" 8.430115E0, -1.791710E1, 2.813660E0 0.494659E0, 0.357162E0, 0.792306E0 #MarkNodes Insight diff --git a/data/profiles/rosetta.profile b/data/profiles/rosetta.profile index dd27b61191..dace12a1e3 100644 --- a/data/profiles/rosetta.profile +++ b/data/profiles/rosetta.profile @@ -31,7 +31,7 @@ p Enables or disables the image projection on 67P. Toggle 67P projection /Missio absolute 2014-08-01T03:05:00.000 #Camera -setNavigationState Comet67PAsset.Comet67P.Identifier "Root" -7.294781E5 , -6.657894E5, 2.509047E6 0.146529E0, 0.944727E0, 0.293290E0 +setNavigationState Comet67PAsset.Comet67P.Identifier "Root" -7.294781E5, -6.657894E5, 2.509047E6 0.146529E0, 0.944727E0, 0.293290E0 #MarkNodes 67P diff --git a/data/profiles/touch.profile b/data/profiles/touch.profile index 8fe818c78b..47d38d2de6 100644 --- a/data/profiles/touch.profile +++ b/data/profiles/touch.profile @@ -18,7 +18,7 @@ setPropertyValueSingle Scene.PlutoBarycenterTrail.Renderable.Enabled false relative -1d #Camera -setNavigationState earthAsset.Earth.Identifier 58.5877,16.1924,20000000 +setNavigationState earthAsset.Earth.Identifier 58.5877, 16.1924, 20000000 #MarkNodes Earth diff --git a/include/openspace/scene/profile.h b/include/openspace/scene/profile.h index fb65ef038e..07b30db866 100644 --- a/include/openspace/scene/profile.h +++ b/include/openspace/scene/profile.h @@ -141,7 +141,7 @@ public: void setIgnoreUpdates(bool ignoreUpdates); /// Adds a new asset and checks for duplicates - void addAsset(const std::string& path); + void addAsset(const std::string& path, const std::string& varName = ""); /// Removes an asset void removeAsset(const std::string& path); diff --git a/src/scene/profile.cpp b/src/scene/profile.cpp index 6ce39e8d81..f5ed01196b 100644 --- a/src/scene/profile.cpp +++ b/src/scene/profile.cpp @@ -364,15 +364,24 @@ namespace { ); } - std::vector up = ghoul::tokenizeString(fields[5], ' '); + std::vector up = ghoul::tokenizeString(fields[5], ','); if (up.size() != 0 && up.size() != 3) { - throw Profile::ParsingError( - lineNumber, - fmt::format( - "Expected 0 or 3 fields for the camera's up vector, got {}", - up.size() - ) - ); + //Fix for tokenizeString returns incorrect up.size() with blank entry + bool emptyFields = true; + for (auto u : up) { + if (u.length() > 0) { + emptyFields = false; + } + } + if (!emptyFields) { + throw Profile::ParsingError( + lineNumber, + fmt::format( + "Expected 0 or 3 fields for camera up vector, got {}", + up.size() + ) + ); + } } if (up.size() == 3) { try { @@ -503,7 +512,7 @@ void Profile::setIgnoreUpdates(bool ignoreUpdates) { _ignoreUpdates = ignoreUpdates; } -void Profile::addAsset(const std::string& path) { +void Profile::addAsset(const std::string& path, const std::string& varName) { ZoneScoped if (_ignoreUpdates) { @@ -523,6 +532,7 @@ void Profile::addAsset(const std::string& path) { Asset a; a.path = path; + a.name = varName; _assets.push_back(std::move(a)); }