diff --git a/apps/Launcher/ext/libtorrent/CMakeLists.txt b/apps/Launcher/ext/libtorrent/CMakeLists.txt index 18b052bc1b..1cbdeb7355 100644 --- a/apps/Launcher/ext/libtorrent/CMakeLists.txt +++ b/apps/Launcher/ext/libtorrent/CMakeLists.txt @@ -1,7 +1,7 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.0) project(libtorrent) -set (SOVERSION "8") -set (VERSION "1.0.5") +set(SOVERSION "8") +set(VERSION "1.0.5") set(sources web_connection_base diff --git a/apps/Launcher/infowidget.cpp b/apps/Launcher/infowidget.cpp index 11ea196638..a10d9430e6 100644 --- a/apps/Launcher/infowidget.cpp +++ b/apps/Launcher/infowidget.cpp @@ -43,26 +43,34 @@ InfoWidget::InfoWidget(QString name, int totalBytes) setFixedHeight(100); QGridLayout* layout = new QGridLayout; - layout->setVerticalSpacing(0); layout->setHorizontalSpacing(10); - layout->setContentsMargins(0, 0, 0, 0); _name = new QLabel(name); - layout->addWidget(_name, 0, 0); + _name->setObjectName("Name"); + //_name->setMaximumWidth(300); + _name->setFixedWidth(450); + layout->addWidget(_name, 0, 0, 1, 2); + layout->setRowStretch(1, 10); _bytes = new QLabel(""); - layout->addWidget(_bytes, 1, 0); + _bytes->setObjectName("Bytes"); + layout->addWidget(_bytes, 2, 0); _progress = new QProgressBar; - layout->addWidget(_progress, 1, 1); + _progress->setTextVisible(false); + _progress->setFixedWidth(285); + layout->addWidget(_progress, 2, 1); _messagesLeft = new QLabel(""); + _messagesLeft->setObjectName("MessageLeft"); _messagesCenter = new QLabel(""); + _messagesCenter->setObjectName("MessageCenter"); _messagesRight = new QLabel(""); - - layout->addWidget(_messagesLeft, 2, 0, 1, 2); - layout->addWidget(_messagesCenter, 2, 0, 1, 2, Qt::AlignCenter); - layout->addWidget(_messagesRight, 2, 0, 1, 2, Qt::AlignRight); + _messagesRight->setObjectName("MessageRight"); + + layout->addWidget(_messagesLeft, 3, 0, 1, 2); + layout->addWidget(_messagesCenter, 3, 0, 1, 2, Qt::AlignCenter); + layout->addWidget(_messagesRight, 3, 0, 1, 2, Qt::AlignRight); setLayout(layout); } @@ -99,13 +107,13 @@ void InfoWidget::update(libtorrent::torrent_status s) { if (bytesPerSecond > 0 && remainingBytes > 0) { float seconds = static_cast(remainingBytes) / bytesPerSecond; - QString left = "Time remaining %1 s"; + QString left = "Remaining: %1 s"; _messagesLeft->setText(left.arg(static_cast(seconds))); QString center = "Peers: %1 (%2) | Seeds: %3 (%4)"; _messagesCenter->setText(center.arg(s.num_peers).arg(s.list_peers).arg(s.num_seeds).arg(s.list_seeds)); - QString right = "Download Rate: %1 KiB/s"; + QString right = "%1 KiB/s"; _messagesRight->setText(right.arg(bytesPerSecond / 1024)); } else diff --git a/apps/Launcher/main.cpp b/apps/Launcher/main.cpp index b4c17f6d04..63a90a620e 100644 --- a/apps/Launcher/main.cpp +++ b/apps/Launcher/main.cpp @@ -24,130 +24,151 @@ #include +#include + #include "mainwindow.h" -//static const QString style = R"style( -//QWidget { -// background-color: rgb(80, 80, 80); -// font-family: Helvetica; -//} -// -//QGroupBox { -// background-color: qlineargradient( -// x1: 0, y1: 0, x2: 0, y2: 1, -// stop: 0 #858585, -// stop: 1 #959595); -// border: 2px solid gray; -// border-radius: 5px; -// margin-top: 4ex; -// font-size: bold 12px; -//} -// -//QGroupBox::title { -// background-color: #E0E0E0; -// border: 2px solid gray; -// border-radius: 5px; -// subcontrol-origin: margin; -// subcontrol-position: top center; -// padding: 0 10px; -//} -// -//QLineEdit { -// color: lightgray; -//} -// -//QSlider::groove:horizontal { -// border: 1px solid #999999; -// height: 8px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */ -// background: qlineargradient( -// x1:0, y1:0, x2:1, y2:0, -// stop:0 #c4c4c4, -// stop:0.5 #555555, -// stop:1 #c4c4c4 -// ); -// margin: 2px 0; -//} -// -//QSlider::handle:horizontal { -// background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f); -// border: 1px solid #5c5c5c; -// width: 18px; -// margin: -2px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */ -// border-radius: 3px; -//} -// -//QPushButton { -// background-color: lightgray; -// border-style: outset; -// border-width: 0.5px; -// border-radius: 5px; -// border-color: black; -// font: bold 12px; -// min-width: 10em; -//} -// -//QPushButton#connection { -// background-color: lightgreen; -//} -// -//QPushButton#connection:pressed { -// background-color: green; -//} -// -// -//QPushButton#pause, QPushButton#play { -// padding: 5px; -//} -// -//QPushButton#pause:pressed, QPushButton#play:pressed, QPushButton:pressed { -// background-color: darkgray; -// border-style: inset; -//} -// -//QCombobox { -// border: 1px solid gray; -// border-radius: 3px; -// padding: 1px 18px 1px 3px; -// min-width: 6em; -//} -// -//QComboBox:editable { -// background: lightgrey; -//} -// -//QComboBox QAbstractItemView { -// border: 2px solid darkgray; -// border-radius: 5px; -// background-color: #a8a8a8; -// selection-background-color: #a8a8a8; -//} -// -//QLabel#label { -// font-size: 13px; -// background-color: transparent; -// font-variant: small-caps; -//} -// -//QLabel#value { -// font-family: monospace; -// font-weight: bold; -// font-size: 14px; -// background-color: transparent; -//} -// -//QWidget#background { -// background-color: transparent; -//} -// -//QTextEdit { -// font-family: monospace; -//} -//)style"; +#include + +static const QString style = R"style( +QWidget { + /*font-family: "Helvetica";*/ +} +QWidget#MainWindow, QTextEdit, QWidget#SyncWidget, QWidget#DownloadArea { + background-color: rgb(40, 40, 40); +} +QTextEdit, QLabel, QComboBox, QCheckBox { + color: #EDEDED; + font-size: 12px; +} +QLabel { + font-size: 13px; +} +QLabel#Image { + margin: -10px 0px -5px 0px; +} +QTextEdit { + border-width: 2px 2px 0px 0px; + border-style: solid; + background-color: rgb(60, 60, 60); +} +QPushButton { + color:#202020; + background-color: + qlineargradient( + x1: 0, y1: 0, x2: 0, y2: 1, + stop: 0 white, + stop: 1 #555555 + ); + border: 1px solid black; + font-size: 11px; + min-height: 20px; +} +QComboBox { + background-color: rgb(60, 60, 60); + min-height: 20px; +} +QComboBox:focus, QComboBox:focus QAbstractItemView { + color: white; + background-color: rgb(60, 60, 60); + selection-background-color: rgb(75, 75, 75); +} +QCheckBox { + border: none; +} +QCheckBox::indicator { + width: 12px; + height: 12px; +} +QCheckBox::indicator::unchecked { + border: 1px solid #5A5A5A; + background: transparent; +} +QCheckBox::indicator:unchecked:hover { + border: 1px solid #DDDDDD; +} +QCheckBox::indicator::checked { + border: 1px solid #AAAAAA; + background: #666666; +} +QCheckBox::indicator:checked:hover { + border: 1px solid #DDDDDD; + background: #555555; +} +QGroupBox, QScrollArea { + border: 0px; +} +InfoWidget { + border-width: 1px; + border-style: solid; + border-color: #BBBBBB; + margin: 2px 1px 2px 1px; + padding: 7.5px; +} +InfoWidget QLabel#Name { + font-size: 17px; +} +InfoWidget QLabel#Bytes { + font-size: 13px; + font-family: "Lucida Console"; +} +InfoWidget QLabel#MessageLeft, QLabel#MessageCenter, QLabel#MessageRight { + font-size: 11.5px; + margin-top: -2px; +} +InfoWidget QProgressBar { + border: 2px solid #BBBBBB; + border-radius: 5px; + background: white; + height: 15px; +} +InfoWidget QProgressBar::chunk { + background: qlineargradient( + x1: 0, y1: 0.5, x2: 1, y2: 0.5, + stop: 0 #444444, + stop: 1 #600000 + ); +} +QScrollBar { + border: 1px solid #000000; + background: #282828; + width: 15px; + margin: 16px 0px 16px 0px; +} +QScrollBar::handle { + background: #B0B0B0; + border: 1px solid #000000; + border-width: 1px 0px 1px 0px; + min-height: 20px; +} +QScrollBar::add-line, QScrollBar::sub-line { + background:#B0B0B0; + border: 1px solid #5A5A5A; + subcontrol-origin: margin; +} +QScrollBar::add-line { + top: 15px; + height: 15px; +} +QScrollBar::sub-line { + height: 15px; + subcontrol-position: top; +} +QScrollBar::up-arrow, QScrollBar::down-arrow { + border: 1px solid #5A5A5A; + width: 3px; + height: 3px; + background-color: #353535; +} +QScrollBar::add-page, QScrollBar::sub-page { + background: none; +} +)style"; int main(int argc, char** argv) { QApplication app(argc, argv); + app.setStyleSheet(style); -// app.setStyleSheet(style); MainWindow window; window.show(); diff --git a/apps/Launcher/mainwindow.cpp b/apps/Launcher/mainwindow.cpp index 53f08c04f3..9d97a0ffe3 100644 --- a/apps/Launcher/mainwindow.cpp +++ b/apps/Launcher/mainwindow.cpp @@ -79,19 +79,28 @@ MainWindow::MainWindow() , _shortcutWidget(nullptr) , _syncWidget(nullptr) { + setObjectName("MainWindow"); setFixedSize(WindowSize); + //setContentsMargins(0, 0, 0, 0); QGridLayout* layout = new QGridLayout; + layout->setContentsMargins(0, 0, 0, 0); QLabel* image = new QLabel; + //image->setContentsMargins(0, 0, 0, 0); + image->setObjectName("Image"); QPixmap p = QPixmap(":/images/header.png"); image->setPixmap(p.scaledToWidth(WindowSize.width())); layout->addWidget(image, 0, 0, 1, 2); + _informationWidget = new QTextEdit(this); _informationWidget->setReadOnly(true); _informationWidget->setEnabled(false); layout->addWidget(_informationWidget, 1, 0, 2, 1); + layout->setRowStretch(1, 10); + layout->setColumnStretch(0, 4); + layout->setColumnStretch(1, 5); QWidget* container = new QWidget; { @@ -104,11 +113,18 @@ MainWindow::MainWindow() this, SLOT(shortcutButtonPressed()) ); layout->addWidget(shortcutButton, 0, 1); + + layout->setRowStretch(1, 10); + + QLabel* configurationSelectionLabel = new QLabel("Configuration:"); + layout->addWidget(configurationSelectionLabel, 2, 0); + _configurations = new QComboBox; + layout->addWidget(_configurations, 2, 1); QLabel* sceneSelectionLabel = new QLabel("Scenes:"); - layout->addWidget(sceneSelectionLabel, 1, 0); + layout->addWidget(sceneSelectionLabel, 3, 0); _scenes = new QComboBox; - layout->addWidget(_scenes); + layout->addWidget(_scenes, 3, 1); container->setLayout(layout); } @@ -181,27 +197,40 @@ void MainWindow::initialize() { std::string configurationFile = _configurationFile; bool found = openspace::OpenSpaceEngine::findConfiguration(configurationFile); if (!found) { + LERRORC("MainWindow", "Could not find configuration file"); } _configuration = new openspace::ConfigurationManager; _configuration->loadFromFile(configurationFile); - - QString modulesDirectory = QString::fromStdString( - absPath("${SCENE}") - ); + // Load all available scenes + QString modulesDirectory = QString::fromStdString(absPath("${SCENE}")); QDir d(modulesDirectory); d.setFilter(QDir::Files); - QFileInfoList list = d.entryInfoList(); + _scenes->addItem("Use Default"); for (const QFileInfo& i : list) { - _sceneFiles.insert(i.fileName(), i.absoluteFilePath()); - _scenes->addItem(i.fileName()); + QString file = i.fileName(); + file = file.replace(".scene", ""); + _sceneFiles.insert(file, i.absoluteFilePath()); + _scenes->addItem(file); } - - _scenes->setCurrentText("default.scene"); - + _scenes->setCurrentText("Use Default"); _syncWidget->setSceneFiles(_sceneFiles); + + // Load all available configuration files + QString configurationDirectory = QString::fromStdString(absPath("${SGCT}")); + d = QDir(configurationDirectory); + d.setFilter(QDir::Files); + list = d.entryInfoList(); + _configurations->addItem("Use Default"); + for (const QFileInfo& i : list) { + QString file = i.fileName(); + file = file.replace(".xml", ""); + _configurationFiles.insert(file, i.absoluteFilePath()); + _configurations->addItem(file); + } + _configurations->setCurrentText("Use Default"); } void MainWindow::shortcutButtonPressed() { @@ -213,7 +242,15 @@ void MainWindow::syncButtonPressed() { } void MainWindow::startButtonPressed() { - QProcess::startDetached(OpenSpaceExecutable); + QString exec = OpenSpaceExecutable; + if (_sceneFiles.contains(_scenes->currentText())) + exec += " -scene \"" + _sceneFiles[_scenes->currentText()] + "\""; + + if (_configurationFiles.contains(_configurations->currentText())) + exec += " -sgct \"" + _configurationFiles[_configurations->currentText()] + "\""; + + LINFOC("MainWindow", "Executing: " << exec.toStdString()); + QProcess::startDetached(exec); } void MainWindow::newsNetworkError() { diff --git a/apps/Launcher/mainwindow.h b/apps/Launcher/mainwindow.h index f131a8aa25..62859548b0 100644 --- a/apps/Launcher/mainwindow.h +++ b/apps/Launcher/mainwindow.h @@ -63,9 +63,12 @@ private: QTextEdit* _informationWidget; + QComboBox* _configurations; + QMap _configurationFiles; + QComboBox* _scenes; QMap _sceneFiles; - + ShortcutWidget* _shortcutWidget; SyncWidget* _syncWidget; diff --git a/apps/Launcher/syncwidget.cpp b/apps/Launcher/syncwidget.cpp index d2abd0d983..69a127156c 100644 --- a/apps/Launcher/syncwidget.cpp +++ b/apps/Launcher/syncwidget.cpp @@ -82,9 +82,11 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) , _sceneLayout(nullptr) , _session(new libtorrent::session) { + setObjectName("SyncWidget"); setFixedSize(500, 500); QBoxLayout* layout = new QVBoxLayout; + layout->setContentsMargins(0, 0, 0, 0); { QGroupBox* sceneBox = new QGroupBox; _sceneLayout = new QGridLayout; @@ -92,7 +94,8 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) layout->addWidget(sceneBox); } { - QPushButton* syncButton = new QPushButton("Synchronize Scenes"); + QPushButton* syncButton = new QPushButton("Synchronize Data"); + syncButton->setObjectName("SyncButton"); QObject::connect( syncButton, SIGNAL(clicked(bool)), this, SLOT(syncButtonPressed()) @@ -106,6 +109,7 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) area->setWidgetResizable(true); QWidget* w = new QWidget; + w->setObjectName("DownloadArea"); area->setWidget(w); _downloadLayout = new QVBoxLayout(w); @@ -115,6 +119,12 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) layout->addWidget(area); } + QPushButton* close = new QPushButton("Close"); + layout->addWidget(close, Qt::AlignRight); + QObject::connect( + close, SIGNAL(clicked(bool)), + this, SLOT(close()) + ); setLayout(layout); @@ -213,7 +223,6 @@ void SyncWidget::setSceneFiles(QMap sceneFiles) { const QString& sceneName = keys[i]; QCheckBox* checkbox = new QCheckBox(sceneName); - checkbox->setChecked(true); _sceneLayout->addWidget(checkbox, i / nColumns, i % nColumns); @@ -326,7 +335,13 @@ void SyncWidget::handleTorrentFiles() { } if (_torrentInfoWidgetMap.find(h) == _torrentInfoWidgetMap.end()) { - InfoWidget* w = new InfoWidget(f.file, h.status().total_wanted); + QString fileString = f.file; + QString t = QString(".torrent"); + fileString.replace(fileString.indexOf(t), t.size(), ""); + + fileString = f.module + "/" + fileString; + + InfoWidget* w = new InfoWidget(fileString, h.status().total_wanted); _downloadLayout->insertWidget(_downloadLayout->count() - 1, w); _torrentInfoWidgetMap[h] = w; } diff --git a/ext/ghoul b/ext/ghoul index 5a6d99432b..f87ad95260 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 5a6d99432b394ea98e9c5d50c8a99c990c504f8c +Subproject commit f87ad95260996a56105fb4543e734e86d187413a diff --git a/include/openspace/properties/numericalproperty.h b/include/openspace/properties/numericalproperty.h index 36edef62aa..80fce6e9f4 100644 --- a/include/openspace/properties/numericalproperty.h +++ b/include/openspace/properties/numericalproperty.h @@ -40,10 +40,13 @@ public: NumericalProperty(std::string identifier, std::string guiName, T value, T minimumValue, T maximumValue, T steppingValue); - bool getLua(lua_State* state) const override; - bool setLua(lua_State* state) override; + bool getLuaValue(lua_State* state) const override; + bool setLuaValue(lua_State* state) override; int typeLua() const override; + bool getStringValue(std::string& value) const override; + bool setStringValue(std::string value) override; + T minValue() const; T maxValue() const; diff --git a/include/openspace/properties/numericalproperty.inl b/include/openspace/properties/numericalproperty.inl index e1bd5b77e1..cf4a0ec5f9 100644 --- a/include/openspace/properties/numericalproperty.inl +++ b/include/openspace/properties/numericalproperty.inl @@ -29,22 +29,29 @@ namespace properties { #define REGISTER_NUMERICALPROPERTY_HEADER(CLASS_NAME, TYPE) \ typedef NumericalProperty CLASS_NAME; \ + \ template <> \ std::string PropertyDelegate>::className(); \ + \ template <> \ std::string PropertyDelegate>::className(); \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultValue(); \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultMinimumValue(); \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultMaximumValue(); \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultSteppingValue(); \ + \ template <> \ template <> \ TYPE PropertyDelegate>::fromLuaValue(lua_State* state, \ @@ -64,61 +71,92 @@ namespace properties { template <> \ int PropertyDelegate>::typeLua(); \ template <> \ - int PropertyDelegate>::typeLua(); + int PropertyDelegate>::typeLua(); \ + \ + template <> \ + template <> \ + TYPE PropertyDelegate>::fromString(std::string value, \ + bool& success); \ + \ + template <> \ + template <> \ + TYPE PropertyDelegate>::fromString(std::string value, \ + bool& success); \ + \ + template <> \ + template <> \ + bool PropertyDelegate>::toString(std::string& outValue, \ + TYPE inValue); \ + \ + template <> \ + template <> \ + bool PropertyDelegate>::toString(std::string& outValue, \ + TYPE inValue); + #define REGISTER_NUMERICALPROPERTY_SOURCE(CLASS_NAME, TYPE, DEFAULT_VALUE, \ DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, \ DEFAULT_STEPPING, FROM_LUA_LAMBDA_EXPRESSION, \ - TO_LUA_LAMBDA_EXPRESSION, LUA_TYPE) \ + TO_LUA_LAMBDA_EXPRESSION, \ + FROM_STRING_LAMBDA_EXPRESSION, \ + TO_STRING_LAMBDA_EXPRESSION, LUA_TYPE) \ template <> \ std::string PropertyDelegate>::className() \ { \ return #CLASS_NAME; \ } \ + \ template <> \ std::string PropertyDelegate>::className() \ { \ return PropertyDelegate>::className(); \ } \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultValue() \ { \ return DEFAULT_VALUE; \ } \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultMinimumValue() \ { \ return DEFAULT_MIN_VALUE; \ } \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultMaximumValue() \ { \ return DEFAULT_MAX_VALUE; \ } \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultSteppingValue() \ { \ return DEFAULT_STEPPING; \ } \ + \ template <> \ template <> \ - TYPE PropertyDelegate>::fromLuaValue(lua_State * state, \ + TYPE PropertyDelegate>::fromLuaValue(lua_State* state, \ bool& success) \ { \ return FROM_LUA_LAMBDA_EXPRESSION(state, success); \ } \ + \ template <> \ template <> \ TYPE PropertyDelegate>::fromLuaValue( \ - lua_State * state, bool& success) \ + lua_State* state, bool& success) \ { \ return PropertyDelegate>::fromLuaValue(state, \ success); \ } \ + \ template <> \ template <> \ bool PropertyDelegate>::toLuaValue(lua_State * state, \ @@ -126,6 +164,7 @@ namespace properties { { \ return TO_LUA_LAMBDA_EXPRESSION(state, value); \ } \ + \ template <> \ template <> \ bool PropertyDelegate>::toLuaValue(lua_State * state, \ @@ -133,15 +172,50 @@ namespace properties { { \ return PropertyDelegate>::toLuaValue(state, value); \ } \ + \ template <> \ int PropertyDelegate>::typeLua() \ { \ return LUA_TYPE; \ } \ + \ template <> \ int PropertyDelegate>::typeLua() \ { \ return PropertyDelegate>::typeLua(); \ + } \ + \ + template <> \ + template <> \ + TYPE PropertyDelegate>::fromString(std::string value, \ + bool& success) \ + { \ + return FROM_STRING_LAMBDA_EXPRESSION(value, success); \ + } \ + \ + template <> \ + template <> \ + TYPE PropertyDelegate>::fromString(std::string value, \ + bool& success) \ + { \ + return PropertyDelegate>::fromString(value, \ + success); \ + } \ + \ + template <> \ + template <> \ + bool PropertyDelegate>::toString(std::string& outValue, \ + TYPE inValue) \ + { \ + return TO_STRING_LAMBDA_EXPRESSION(outValue, inValue); \ + } \ + \ + template <> \ + template <> \ + bool PropertyDelegate>::toString(std::string& outValue, \ + TYPE inValue) \ + { \ + return PropertyDelegate>::toString(outValue, inValue); \ } @@ -206,7 +280,7 @@ std::string NumericalProperty::className() const { } template -bool NumericalProperty::setLua(lua_State* state) +bool NumericalProperty::setLuaValue(lua_State* state) { bool success = false; T value = PropertyDelegate>::template fromLuaValue(state, success); @@ -216,7 +290,7 @@ bool NumericalProperty::setLua(lua_State* state) } template -bool NumericalProperty::getLua(lua_State* state) const +bool NumericalProperty::getLuaValue(lua_State* state) const { bool success = PropertyDelegate>::template toLuaValue(state, TemplateProperty::_value); return success; @@ -227,6 +301,21 @@ int NumericalProperty::typeLua() const { return PropertyDelegate>::typeLua(); } +template +bool NumericalProperty::getStringValue(std::string& value) const { + bool success = PropertyDelegate>::template toString(value, _value); + return success; +} + +template +bool NumericalProperty::setStringValue(std::string value) { + bool success = false; + T thisValue = PropertyDelegate>::template fromString(value, success); + if (success) + set(boost::any(thisValue)); + return success; +} + template T NumericalProperty::minValue() const { return _minimumValue; diff --git a/include/openspace/properties/property.h b/include/openspace/properties/property.h index 471ed0579a..9770fa426e 100644 --- a/include/openspace/properties/property.h +++ b/include/openspace/properties/property.h @@ -45,8 +45,9 @@ class PropertyOwner; * Property. Per PropertyOwner, the identifier needs to be unique and can be * used as a URI. This class is an abstract base class and each subclass (most notable * TemplateProperty) needs to implement the methods Property::className, Property::get, - * Property::set, Property::type(), Property::getLua, Property::setLua, and - * Property::typeLua to make full use of the infrastructure. + * Property::set, Property::type(), Property::getLuaValue, Property::setLuaValue, + * Property::getStringValue, Property::setStringValue and Property::typeLua to make full + * use of the infrastructure. * The most common types can be implemented by creating a specialized instantiation of * TemplateProperty, which provides default implementations for these methods. * @@ -118,47 +119,69 @@ public: * This method encodes the encapsulated value of this Property at the top of the Lua * stack. The specific details of this serialization is up to the property developer * as long as the rest of the stack is unchanged. The implementation has to be - * synchronized with the Property::setLua method. The default implementation is a + * synchronized with the Property::setLuaValue method. The default implementation is a * no-op. * \param state The Lua state to which the value will be encoded * \return true if the encoding succeeded, false otherwise */ - virtual bool getLua(lua_State* state) const; + virtual bool getLuaValue(lua_State* state) const; /** * This method sets the value encapsulated by this Property by deserializing the value * on top of the passed Lua stack. The specific details of the deserialization are up * to the Property developer, but they must only depend on the top element of the * stack and must leave all other elements unchanged. The implementation has to be - * synchronized with the Property::getLua method. The default implementation is a + * synchronized with the Property::getLuaValue method. The default implementation is a * no-op. * \param state The Lua state from which the value will be decoded * \return true if the decoding and setting of the value succeeded, * false otherwise */ - virtual bool setLua(lua_State* state); + virtual bool setLuaValue(lua_State* state); /** * Returns the Lua type that will be put onto the stack in the Property::getLua method - * and which will be consumed by the Property::setLua method. The returned value + * and which will be consumed by the Property::setLuaValue method. The returned value * can belong to the set of Lua types: LUA_TNONE, LUA_TNIL, * LUA_TBOOLEAN, LUA_TLIGHTUSERDATA, * LUA_TNUMBER, LUA_TSTRING, LUA_TTABLE, * LUA_TFUNCTION, LUA_TUSERDATA, or * LUA_TTHREAD. The default implementation will return * LUA_TNONE. - * \return The Lua type that will be consumed or produced by the Property::getLua and - * Property::setLua methods. + * \return The Lua type that will be consumed or produced by the Property::getLuaValue + * and Property::setLuaValue methods. */ virtual int typeLua() const; + /** + * This method encodes the encapsulated value of this Property as a + * std::string. The specific details of this serialization is up to the + * property developer. The implementation has to be synchronized with the + Property::setStringValue method. The default implementation is a no-op. + * \param value The value to which the Property will be encoded + * \return true if the encoding succeeded, false otherwise + */ + virtual bool getStringValue(std::string& value) const; + + /** + * This method sets the value encapsulated by this Property by deserializing the + * passed std::string. The specific details of the deserialization are up + * to the Property developer. The implementation has to be synchronized with the + * Property::getLuaValue method. The default implementation is a no-op. + * \param value The value from which the Property will be decoded + * \return true if the decoding and setting of the value succeeded, + * false otherwise + */ + virtual bool setStringValue(std::string value); + /** * This method registers a callback function that will be called every - * time if either Property:set or Property::setLua was called with a value that is - * different from the previously stored value. The callback can be removed my passing - * an empty std::function object. + * time if either Property:set or Property::setLuaValue was called with a value that + * is different from the previously stored value. The callback can be removed by + * passing an empty std::function object. * \param callback The callback function that is called when the encapsulated type has - * been successfully changed by either the Property::set or Property::setLua methods. + * been successfully changed by either the Property::set or Property::setLuaValue + * methods. */ virtual void onChange(std::function callback); @@ -243,9 +266,10 @@ public: /** * This method determines if this Property should be read-only in external * applications. This setting is only a hint and does not need to be followed by GUI - * applications and does not have any effect on the Property::set or Property::setLua - * methods. The value is stored in the metaData Dictionary with the key: - * isReadOnly. The default value is false. + * applications and does not have any effect on the Property::set, + * Property::setLuaValue, or Property::setStringValue methods. The value is stored in + * the metaData Dictionary with the key: isReadOnly. The default value is + * false. * \param state true if the Property should be read only, * false otherwise */ diff --git a/include/openspace/properties/propertydelegate.h b/include/openspace/properties/propertydelegate.h index f09ca43686..b9bf9f218f 100644 --- a/include/openspace/properties/propertydelegate.h +++ b/include/openspace/properties/propertydelegate.h @@ -149,6 +149,12 @@ public: * PropertyDelegate::toLuaValue and PropertyDelegate::fromLuaValue methods. */ static int typeLua(); + + template + static U fromString(std::string value, bool& success); + + template + static bool toString(std::string& outValue, U inValue); }; } // namespace properties diff --git a/include/openspace/properties/propertydelegate.inl b/include/openspace/properties/propertydelegate.inl index 60cedb8a9a..21fa253e1d 100644 --- a/include/openspace/properties/propertydelegate.inl +++ b/include/openspace/properties/propertydelegate.inl @@ -81,5 +81,19 @@ int PropertyDelegate::typeLua() { "Unimplemented PropertyDelegate::luaType specialization"); } +template +template +bool PropertyDelegate::toString(std::string& outValue, U inValue) { + static_assert(sizeof(T) == 0, + "Unimplemented PropertyDelegate::toString specialization"); +} + +template +template +U PropertyDelegate::fromString(std::string value, bool& success) { + static_assert(sizeof(T) == 0, + "Unimplemented PropertyDelegate::fromString specialization"); +} + } // namespace properties } // namespace openspace diff --git a/include/openspace/properties/selectionproperty.h b/include/openspace/properties/selectionproperty.h index b7a2277f25..1e793354cc 100644 --- a/include/openspace/properties/selectionproperty.h +++ b/include/openspace/properties/selectionproperty.h @@ -67,6 +67,14 @@ bool PropertyDelegate>>::toLuaValue(lua_State* template <> int PropertyDelegate>>::typeLua(); +template <> +template <> +std::vector PropertyDelegate>>::fromString(std::string value, bool& success); + +template <> +template <> +bool PropertyDelegate>>::toString(std::string& outValue, std::vector inValue); + } // namespace properties } // namespace openspace diff --git a/include/openspace/properties/templateproperty.h b/include/openspace/properties/templateproperty.h index 000754e4d3..08dfedcc43 100644 --- a/include/openspace/properties/templateproperty.h +++ b/include/openspace/properties/templateproperty.h @@ -111,7 +111,7 @@ public: * \param state The Lua state onto which the encoded object will be pushed * \return true if the encoding succeeded; false otherwise */ - bool getLua(lua_State* state) const override; + bool getLuaValue(lua_State* state) const override; /** * Sets the value of this TemplateProprty by decoding the object at the top of the Lua @@ -122,11 +122,15 @@ public: * \param state The Lua state from which the value will be decoded * \return true if the decoding succeeded; false otherwise */ - bool setLua(lua_State* state) override; + bool setLuaValue(lua_State* state) override; /// \see Property::typeLua int typeLua() const override; + bool getStringValue(std::string& value) const override; + + bool setStringValue(std::string value) override; + /** * Returns the description for this TemplateProperty as a Lua script that returns a * table on execution diff --git a/include/openspace/properties/templateproperty.inl b/include/openspace/properties/templateproperty.inl index 2b68100a91..396c05613f 100644 --- a/include/openspace/properties/templateproperty.inl +++ b/include/openspace/properties/templateproperty.inl @@ -37,21 +37,37 @@ namespace properties { // TYPE = The template parameter T for which the TemplateProperty is specialized #define REGISTER_TEMPLATEPROPERTY_HEADER(CLASS_NAME, TYPE) \ typedef TemplateProperty CLASS_NAME; \ + \ template <> \ std::string PropertyDelegate>::className(); \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultValue(); \ + \ template <> \ template <> \ TYPE PropertyDelegate>::fromLuaValue(lua_State* state, \ bool& success); \ + \ template <> \ template <> \ bool PropertyDelegate>::toLuaValue(lua_State* state, \ TYPE value); \ + \ template <> \ - int PropertyDelegate>::typeLua(); + int PropertyDelegate>::typeLua(); \ + \ + template <> \ + template <> \ + TYPE PropertyDelegate>::fromString(std::string value, \ + bool& success); \ + \ + template <> \ + template <> \ + bool PropertyDelegate>::toString(std::string& outValue, \ + TYPE inValue); + // CLASS_NAME = The string that the Property::className() should return as well as the // C++ class name for which a typedef will be created @@ -70,18 +86,22 @@ namespace properties { // Lambda expressions #define REGISTER_TEMPLATEPROPERTY_SOURCE(CLASS_NAME, TYPE, DEFAULT_VALUE, \ FROM_LUA_LAMBDA_EXPRESSION, \ - TO_LUA_LAMBDA_EXPRESSION, LUA_TYPE) \ + TO_LUA_LAMBDA_EXPRESSION, \ + FROM_STRING_LAMBDA_EXPRESSION, \ + TO_STRING_LAMBDA_EXPRESSION, LUA_TYPE) \ template <> \ std::string PropertyDelegate>::className() \ { \ return #CLASS_NAME; \ } \ + \ template <> \ template <> \ TYPE PropertyDelegate>::defaultValue() \ { \ return DEFAULT_VALUE; \ } \ + \ template <> \ template <> \ TYPE PropertyDelegate>::fromLuaValue(lua_State * state, \ @@ -89,6 +109,7 @@ namespace properties { { \ return FROM_LUA_LAMBDA_EXPRESSION(state, success); \ } \ + \ template <> \ template <> \ bool PropertyDelegate>::toLuaValue(lua_State * state, \ @@ -96,11 +117,30 @@ namespace properties { { \ return TO_LUA_LAMBDA_EXPRESSION(state, value); \ } \ + \ template <> \ int PropertyDelegate>::typeLua() \ { \ return LUA_TYPE; \ - } + } \ + \ + template <> \ + template <> \ + TYPE PropertyDelegate>::fromString(std::string value, \ + bool& success) \ + { \ + return FROM_STRING_LAMBDA_EXPRESSION(value, success); \ + } \ + \ + template <> \ + template <> \ + bool PropertyDelegate>::toString(std::string& outValue, \ + TYPE inValue) \ + { \ + return TO_STRING_LAMBDA_EXPRESSION(outValue, inValue); \ + } \ + + // Delegating constructors are necessary; automatic template deduction cannot // deduce template argument for 'U' if 'default' methods are used as default values in @@ -195,8 +235,13 @@ const std::type_info& TemplateProperty::type() const { } template -bool TemplateProperty::setLua(lua_State* state) -{ +bool TemplateProperty::getLuaValue(lua_State* state) const { + bool success = PropertyDelegate>::template toLuaValue(state, _value); + return success; +} + +template +bool TemplateProperty::setLuaValue(lua_State* state) { bool success = false; T thisValue = PropertyDelegate>::template fromLuaValue(state, success); if (success) @@ -204,17 +249,25 @@ bool TemplateProperty::setLua(lua_State* state) return success; } -template -bool TemplateProperty::getLua(lua_State* state) const -{ - bool success = PropertyDelegate>::template toLuaValue(state, _value); - return success; -} - template int TemplateProperty::typeLua() const { return PropertyDelegate>::typeLua(); } +template +bool TemplateProperty::getStringValue(std::string& value) const { + bool success = PropertyDelegate>::template toString(value, _value); + return success; +} + +template +bool TemplateProperty::setStringValue(std::string value) { + bool success = false; + T thisValue = PropertyDelegate>::template fromString(value, success); + if (success) + set(boost::any(thisValue)); + return success; +} + } // namespace properties } // namespace openspace diff --git a/include/openspace/properties/triggerproperty.h b/include/openspace/properties/triggerproperty.h index c4a0cc8f50..33c48f0377 100644 --- a/include/openspace/properties/triggerproperty.h +++ b/include/openspace/properties/triggerproperty.h @@ -56,7 +56,7 @@ public: * \param state The unused Lua state * \return Returns always true */ - bool setLua(lua_State* state); + bool setLuaValue(lua_State* state); /** * Silently ignores any value that is passed into this function and will trigger the diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index 715279cd5c..499839e4b3 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -40,13 +40,15 @@ #include #endif +#define USE_MULTITHREADED_DOWNLOAD + namespace { const std::string _loggerCat = "DownloadManager"; const std::string RequestIdentifier = "identifier"; const std::string RequestFileVersion = "file_version"; const std::string RequestApplicationVersion = "application_version"; - + struct ProgressInformation { openspace::DownloadManager::FileFuture* future; std::chrono::system_clock::time_point startTime; @@ -145,7 +147,10 @@ DownloadManager::FileFuture* DownloadManager::downloadFile( LDEBUG("Starting download for file: '" << url << "' into file '" << file.path() << "'"); + +#ifdef USE_MULTITHREADED_DOWNLOAD std::thread t = std::thread([url, finishedCallback, progressCallback, future, fp]() { +#endif CURL* curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); @@ -174,6 +179,7 @@ DownloadManager::FileFuture* DownloadManager::downloadFile( if (finishedCallback) finishedCallback(*future); } +#ifdef USE_MULTITHREADED_DOWNLOAD }); #ifdef WIN32 @@ -185,6 +191,7 @@ DownloadManager::FileFuture* DownloadManager::downloadFile( #endif t.detach(); +#endif // USE_MULTITHREADED_DOWNLOAD return future; } @@ -253,7 +260,9 @@ void DownloadManager::downloadRequestFilesAsync( bool overrideFiles, AsyncDownloadFinishedCallback callback) { +#ifdef USE_MULTITHREADED_DOWNLOAD std::thread t = std::thread([this, identifier, destination, version, overrideFiles, callback](){ +#endif std::vector f = downloadRequestFiles( identifier, destination, @@ -262,6 +271,7 @@ void DownloadManager::downloadRequestFilesAsync( ); callback(f); +#ifdef USE_MULTITHREADED_DOWNLOAD }); #ifdef WIN32 @@ -273,6 +283,7 @@ void DownloadManager::downloadRequestFilesAsync( #endif t.detach(); +#endif // USE_MULTITHREADED_DOWNLOAD } } // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 96d361787e..2c2abf44c1 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -92,6 +92,7 @@ namespace { struct { std::string configurationName; std::string sgctConfigurationName; + std::string sceneName; } commandlineArgumentPlaceholders; } @@ -358,11 +359,14 @@ bool OpenSpaceEngine::initialize() { _renderEngine->initialize(); sceneGraph->initialize(); - std::string sceneDescriptionPath; - success = configurationManager()->getValue( - ConfigurationManager::KeyConfigScene, sceneDescriptionPath); - if (success) - sceneGraph->scheduleLoadSceneFile(sceneDescriptionPath); + std::string sceneDescriptionPath = ""; + if (commandlineArgumentPlaceholders.sceneName.empty()) { + success = configurationManager()->getValue( + ConfigurationManager::KeyConfigScene, sceneDescriptionPath); + } + else + sceneDescriptionPath = commandlineArgumentPlaceholders.sceneName; + sceneGraph->scheduleLoadSceneFile(sceneDescriptionPath); _interactionHandler->setKeyboardController(new interaction::KeyboardControllerFixed); _interactionHandler->setMouseController(new interaction::OrbitalMouseController); @@ -413,6 +417,13 @@ bool OpenSpaceEngine::gatherCommandlineArguments() { "the OpenSpace configuration file"); _commandlineParser->addCommand(sgctConfigFileCommand); + commandlineArgumentPlaceholders.sceneName = ""; + CommandlineCommand* sceneFileCommand = new SingleCommand( + &commandlineArgumentPlaceholders.sceneName, "-scene", "", + "Provides the path to the scene file, overriding the value set in the OpenSpace" + " configuration file"); + _commandlineParser->addCommand(sceneFileCommand); + return true; } diff --git a/src/properties/matrixproperty.cpp b/src/properties/matrixproperty.cpp index 11f67f0c7d..37eeb75787 100644 --- a/src/properties/matrixproperty.cpp +++ b/src/properties/matrixproperty.cpp @@ -24,7 +24,11 @@ #include +#include + #include +#include +#include using std::numeric_limits; @@ -32,7 +36,7 @@ namespace openspace { namespace properties { #define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \ - [](lua_State * state, bool& success) -> __TYPE__ { \ + [](lua_State* state, bool& success) -> __TYPE__ { \ __TYPE__ result; \ int number = 1; \ for (__TYPE__::size_type i = 0; i < __TYPE__::row_size(); ++i) { \ @@ -54,7 +58,7 @@ namespace properties { } #define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \ - [](lua_State * state, __TYPE__ value) -> bool { \ + [](lua_State* state, __TYPE__ value) -> bool { \ lua_newtable(state); \ int number = 1; \ for (__TYPE__::size_type i = 0; i < __TYPE__::row_size(); ++i) { \ @@ -67,6 +71,45 @@ namespace properties { return true; \ } +#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \ + [](std::string value, bool& success) -> __TYPE__ { \ + __TYPE__ result; \ + std::vector tokens = ghoul::tokenizeString(value, ','); \ + if (tokens.size() != (__TYPE__::row_size() * __TYPE__::col_size())) { \ + success = false; \ + return result; \ + } \ + int number = 0; \ + for (__TYPE__::size_type i = 0; i < __TYPE__::row_size(); ++i) { \ + for (__TYPE__::size_type j = 0; j < __TYPE__::col_size(); ++j) { \ + std::stringstream s(tokens[number]); \ + __TYPE__::value_type v; \ + s >> v; \ + if (s.fail()) { \ + success = false; \ + return result; \ + } \ + else { \ + result[i][j] = v; \ + ++number; \ + } \ + } \ + } \ + success = true; \ + return result; \ + } + +#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \ + [](std::string& outValue, __TYPE__ inValue) -> bool { \ + outValue = ""; \ + for (__TYPE__::size_type i = 0; i < __TYPE__::row_size(); ++i) { \ + for (__TYPE__::size_type j = 0; j < __TYPE__::col_size(); ++j) { \ + outValue += std::to_string(inValue[i][j]) + ","; \ + } \ + } \ + return true; \ + } + REGISTER_NUMERICALPROPERTY_SOURCE(Mat2Property, glm::mat2x2, glm::mat2x2(0), glm::mat2x2( numeric_limits::lowest(), @@ -85,7 +128,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat2Property, glm::mat2x2, glm::mat2x2(0), 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat2x2), - DEFAULT_TO_LUA_LAMBDA(glm::mat2x2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat2x2), + DEFAULT_FROM_STRING_LAMBDA(glm::mat2x2), + DEFAULT_TO_STRING_LAMBDA(glm::mat2x2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x3Property, glm::mat2x3, glm::mat2x3(0), glm::mat2x3( @@ -109,7 +155,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x3Property, glm::mat2x3, glm::mat2x3(0), 0.01f, 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat2x3), - DEFAULT_TO_LUA_LAMBDA(glm::mat2x3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat2x3), + DEFAULT_FROM_STRING_LAMBDA(glm::mat2x3), + DEFAULT_TO_STRING_LAMBDA(glm::mat2x3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x4Property, glm::mat2x4, glm::mat2x4(0), glm::mat2x4( @@ -137,7 +186,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x4Property, glm::mat2x4, glm::mat2x4(0), 0.01f, 0.01f, 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat2x4), - DEFAULT_TO_LUA_LAMBDA(glm::mat2x4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat2x4), + DEFAULT_FROM_STRING_LAMBDA(glm::mat2x4), + DEFAULT_TO_STRING_LAMBDA(glm::mat2x4), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x2Property, glm::mat3x2, glm::mat3x2(0), glm::mat3x2( @@ -161,7 +213,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x2Property, glm::mat3x2, glm::mat3x2(0), 0.01f, 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat3x2), - DEFAULT_TO_LUA_LAMBDA(glm::mat3x2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat3x2), + DEFAULT_FROM_STRING_LAMBDA(glm::mat3x2), + DEFAULT_TO_STRING_LAMBDA(glm::mat3x2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(Mat3Property, glm::mat3x3, glm::mat3x3(0), glm::mat3x3( @@ -192,7 +247,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat3Property, glm::mat3x3, glm::mat3x3(0), 0.01f, 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat3x3), - DEFAULT_TO_LUA_LAMBDA(glm::mat3x3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat3x3), + DEFAULT_FROM_STRING_LAMBDA(glm::mat3x3), + DEFAULT_TO_STRING_LAMBDA(glm::mat3x3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x4Property, glm::mat3x4, glm::mat3x4(0), glm::mat3x4( @@ -229,7 +287,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x4Property, glm::mat3x4, glm::mat3x4(0), 0.01f, 0.01f, 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat3x4), - DEFAULT_TO_LUA_LAMBDA(glm::mat3x4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat3x4), + DEFAULT_FROM_STRING_LAMBDA(glm::mat3x4), + DEFAULT_TO_STRING_LAMBDA(glm::mat3x4), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x2Property, glm::mat4x2, glm::mat4x2(0), glm::mat4x2( @@ -257,7 +318,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x2Property, glm::mat4x2, glm::mat4x2(0), 0.01f, 0.01f, 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat4x2), - DEFAULT_TO_LUA_LAMBDA(glm::mat4x2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat4x2), + DEFAULT_FROM_STRING_LAMBDA(glm::mat4x2), + DEFAULT_TO_STRING_LAMBDA(glm::mat4x2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x3Property, glm::mat4x3, glm::mat4x3(0), glm::mat4x3( @@ -294,7 +358,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x3Property, glm::mat4x3, glm::mat4x3(0), 0.01f, 0.01f, 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat4x3), - DEFAULT_TO_LUA_LAMBDA(glm::mat4x3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat4x3), + DEFAULT_FROM_STRING_LAMBDA(glm::mat4x3), + DEFAULT_TO_STRING_LAMBDA(glm::mat4x3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(Mat4Property, glm::mat4x4, glm::mat4x4(0), glm::mat4x4( @@ -340,7 +407,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat4Property, glm::mat4x4, glm::mat4x4(0), 0.01f, 0.01f, 0.01f, 0.01f ), DEFAULT_FROM_LUA_LAMBDA(glm::mat4x4), - DEFAULT_TO_LUA_LAMBDA(glm::mat4x4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::mat4x4), + DEFAULT_FROM_STRING_LAMBDA(glm::mat4x4), + DEFAULT_TO_STRING_LAMBDA(glm::mat4x4), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat2Property, glm::dmat2x2, glm::dmat2x2(0), glm::dmat2x2( @@ -360,7 +430,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat2Property, glm::dmat2x2, glm::dmat2x2(0), 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x2), - DEFAULT_TO_LUA_LAMBDA(glm::dmat2x2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat2x2), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x2), + DEFAULT_TO_STRING_LAMBDA(glm::dmat2x2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x3Property, glm::dmat2x3, glm::dmat2x3(0), glm::dmat2x3( @@ -384,7 +457,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x3Property, glm::dmat2x3, glm::dmat2x3(0) 0.01, 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x3), - DEFAULT_TO_LUA_LAMBDA(glm::dmat2x3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat2x3), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x3), + DEFAULT_TO_STRING_LAMBDA(glm::dmat2x3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x4Property, glm::dmat2x4, glm::dmat2x4(0), glm::dmat2x4( @@ -412,7 +488,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x4Property, glm::dmat2x4, glm::dmat2x4(0) 0.01, 0.01, 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x4), - DEFAULT_TO_LUA_LAMBDA(glm::dmat2x4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat2x4), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x4), + DEFAULT_TO_STRING_LAMBDA(glm::dmat2x4), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x2Property, glm::dmat3x2, glm::dmat3x2(0), glm::dmat3x2( @@ -436,7 +515,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x2Property, glm::dmat3x2, glm::dmat3x2(0) 0.01, 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x2), - DEFAULT_TO_LUA_LAMBDA(glm::dmat3x2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat3x2), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x2), + DEFAULT_TO_STRING_LAMBDA(glm::dmat3x2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat3Property, glm::dmat3x3, glm::dmat3x3(0), glm::dmat3x3( @@ -467,7 +549,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat3Property, glm::dmat3x3, glm::dmat3x3(0), 0.01, 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x3), - DEFAULT_TO_LUA_LAMBDA(glm::dmat3x3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat3x3), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x3), + DEFAULT_TO_STRING_LAMBDA(glm::dmat3x3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x4Property, glm::dmat3x4, glm::dmat3x4(0), glm::dmat3x4( @@ -504,7 +589,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x4Property, glm::dmat3x4, glm::dmat3x4(0) 0.01, 0.01, 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x4), - DEFAULT_TO_LUA_LAMBDA(glm::dmat3x4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat3x4), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x4), + DEFAULT_TO_STRING_LAMBDA(glm::dmat3x4), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x2Property, glm::dmat4x2, glm::dmat4x2(0), glm::dmat4x2( @@ -532,7 +620,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x2Property, glm::dmat4x2, glm::dmat4x2(0) 0.01, 0.01, 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x2), - DEFAULT_TO_LUA_LAMBDA(glm::dmat4x2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat4x2), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x2), + DEFAULT_TO_STRING_LAMBDA(glm::dmat4x2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x3Property, glm::dmat4x3, glm::dmat4x3(0), glm::dmat4x3( @@ -569,7 +660,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x3Property, glm::dmat4x3, glm::dmat4x3(0) 0.01, 0.01, 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x3), - DEFAULT_TO_LUA_LAMBDA(glm::dmat4x3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat4x3), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x3), + DEFAULT_TO_STRING_LAMBDA(glm::dmat4x3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DMat4Property, glm::dmat4x4, glm::dmat4x4(0), glm::dmat4x4( @@ -615,7 +709,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat4Property, glm::dmat4x4, glm::dmat4x4(0), 0.01, 0.01, 0.01, 0.01 ), DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x4), - DEFAULT_TO_LUA_LAMBDA(glm::dmat4x4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dmat4x4), + DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x4), + DEFAULT_TO_STRING_LAMBDA(glm::dmat4x4), + LUA_TTABLE); } // namespace properties } // namespace openspace diff --git a/src/properties/property.cpp b/src/properties/property.cpp index fda0a6cc17..621191ef93 100644 --- a/src/properties/property.cpp +++ b/src/properties/property.cpp @@ -85,14 +85,13 @@ boost::any Property::get() const { return boost::any(); } -bool Property::getLua(lua_State* state) const { - return true; +bool Property::getLuaValue(lua_State* state) const { + return false; } -void Property::set(boost::any value) { -} +void Property::set(boost::any value) {} -bool Property::setLua(lua_State* state) { +bool Property::setLuaValue(lua_State* state) { return false; } @@ -104,6 +103,14 @@ int Property::typeLua() const { return LUA_TNIL; } +bool Property::getStringValue(std::string& value) const { + return false; +} + +bool Property::setStringValue(std::string value) { + return false; +} + std::string Property::guiName() const { std::string result; _metaData.getValue(_metaDataKeyGuiName, result); diff --git a/src/properties/scalarproperty.cpp b/src/properties/scalarproperty.cpp index e46b266308..fe817b7f78 100644 --- a/src/properties/scalarproperty.cpp +++ b/src/properties/scalarproperty.cpp @@ -27,27 +27,44 @@ #include #include +#include using std::numeric_limits; namespace openspace { namespace properties { -#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \ - [](lua_State* state, bool& success) -> TYPE { \ - success = (lua_isnumber(state, -1) == 1); \ - if (success) \ - return static_cast(lua_tonumber(state, -1)); \ - else \ - return DEFAULT_VALUE; \ +#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \ + [](lua_State* state, bool& success) -> TYPE { \ + success = (lua_isnumber(state, -1) == 1); \ + if (success) \ + return static_cast(lua_tonumber(state, -1)); \ + else \ + return DEFAULT_VALUE; \ } -#define DEFAULT_TO_LUA_LAMBDA(TYPE) \ - [](lua_State* state, TYPE value) -> bool { \ - lua_pushnumber(state, static_cast(value)); \ - return true; \ +#define DEFAULT_TO_LUA_LAMBDA(TYPE) \ + [](lua_State* state, TYPE value) -> bool { \ + lua_pushnumber(state, static_cast(value)); \ + return true; \ } +#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \ + [](std::string value, bool& success) -> TYPE { \ + std::stringstream s(value); \ + TYPE v; \ + s >> v; \ + success = !s.fail(); \ + if (success) \ + return v; \ + } + +#define DEFAULT_TO_STRING_LAMBDA(TYPE) \ + [](std::string& outValue, TYPE inValue) -> bool { \ + outValue = std::to_string(inValue); \ + return true; \ + } + // char16_t and char32_t are not supported on Visual Studio 2013 and are defined to // be equal to unsigned short and unsigned int which causes a compile error @@ -63,6 +80,8 @@ REGISTER_TEMPLATEPROPERTY_SOURCE(BoolProperty, bool, false, lua_pushboolean(state, value); return true; }, + DEFAULT_FROM_STRING_LAMBDA(bool, false), + DEFAULT_TO_STRING_LAMBDA(bool), LUA_TBOOLEAN ); @@ -70,7 +89,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(CharProperty, char, char(0), numeric_limits::lowest(), numeric_limits::max(), char(1), DEFAULT_FROM_LUA_LAMBDA(char, char(0)), - DEFAULT_TO_LUA_LAMBDA(char), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(char), + DEFAULT_FROM_STRING_LAMBDA(char, char(0)), + DEFAULT_TO_STRING_LAMBDA(char), + LUA_TNUMBER); // REGISTER_NUMERICALPROPERTY_SOURCE(Char16Property, char16_t, char16_t(0), // numeric_limits::lowest(), numeric_limits::max(), char16_t(1)); @@ -78,92 +100,145 @@ REGISTER_NUMERICALPROPERTY_SOURCE(CharProperty, char, char(0), // REGISTER_NUMERICALPROPERTY_SOURCE(Char32Property, char32_t, char32_t(0), // numeric_limits::lowest(), numeric_limits::max(), char32_t(1)); -REGISTER_NUMERICALPROPERTY_SOURCE(WCharProperty, wchar_t, wchar_t(0), - numeric_limits::lowest(), - numeric_limits::max(), wchar_t(1), - DEFAULT_FROM_LUA_LAMBDA(wchar_t, wchar_t(0)), - DEFAULT_TO_LUA_LAMBDA(wchar_t), LUA_TNUMBER); +//REGISTER_NUMERICALPROPERTY_SOURCE(WCharProperty, wchar_t, wchar_t(0), +// numeric_limits::lowest(), +// numeric_limits::max(), wchar_t(1), +// DEFAULT_FROM_LUA_LAMBDA(wchar_t, wchar_t(0)), +// DEFAULT_TO_LUA_LAMBDA(wchar_t), +// DEFAULT_FROM_STRING_LAMBDA(wchar_t, wchar_t(0)), +// DEFAULT_TO_STRING_LAMBDA(wchar_t), +// LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(SignedCharProperty, signed char, (signed char)(0), numeric_limits::lowest(), numeric_limits::max(), (signed char)0, DEFAULT_FROM_LUA_LAMBDA(signed char, (signed char)(0)), - DEFAULT_TO_LUA_LAMBDA(signed char), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(signed char), + DEFAULT_FROM_STRING_LAMBDA(signed char, (signed char)(0)), + DEFAULT_TO_STRING_LAMBDA(signed char), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(UCharProperty, unsigned char, (unsigned char)0, numeric_limits::lowest(), numeric_limits::max(), (unsigned char)1, DEFAULT_FROM_LUA_LAMBDA(unsigned char, (unsigned char)(0)), - DEFAULT_TO_LUA_LAMBDA(unsigned char), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(unsigned char), + DEFAULT_FROM_STRING_LAMBDA(unsigned char, + (unsigned char)(0)), + DEFAULT_TO_STRING_LAMBDA(unsigned char), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(ShortProperty, short, short(0), numeric_limits::lowest(), numeric_limits::max(), short(1), DEFAULT_FROM_LUA_LAMBDA(short, short(0)), - DEFAULT_TO_LUA_LAMBDA(short), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(short), + DEFAULT_FROM_STRING_LAMBDA(short, short(0)), + DEFAULT_TO_STRING_LAMBDA(short), + LUA_TNUMBER); -REGISTER_NUMERICALPROPERTY_SOURCE( - UShortProperty, unsigned short, (unsigned short)(0), - numeric_limits::lowest(), numeric_limits::max(), - (unsigned short)1, DEFAULT_FROM_LUA_LAMBDA(unsigned short, (unsigned short)(0)), - DEFAULT_TO_LUA_LAMBDA(unsigned short), LUA_TNUMBER); +REGISTER_NUMERICALPROPERTY_SOURCE(UShortProperty, unsigned short, (unsigned short)(0), + numeric_limits::lowest(), + numeric_limits::max(), + (unsigned short)1, + DEFAULT_FROM_LUA_LAMBDA(unsigned short, + (unsigned short)(0)), + DEFAULT_TO_LUA_LAMBDA(unsigned short), + DEFAULT_FROM_STRING_LAMBDA(unsigned short, + (unsigned short)(0)), + DEFAULT_TO_STRING_LAMBDA(unsigned short), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(IntProperty, int, int(0), numeric_limits::lowest(), numeric_limits::max(), int(1), DEFAULT_FROM_LUA_LAMBDA(int, int(0)), - DEFAULT_TO_LUA_LAMBDA(int), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(int), + DEFAULT_FROM_STRING_LAMBDA(int, int(0)), + DEFAULT_TO_STRING_LAMBDA(int), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(UIntProperty, unsigned int, (unsigned int)0, numeric_limits::lowest(), numeric_limits::max(), (unsigned int)1, DEFAULT_FROM_LUA_LAMBDA(unsigned int, (unsigned int)(0)), - DEFAULT_TO_LUA_LAMBDA(unsigned int), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(unsigned int), + DEFAULT_FROM_STRING_LAMBDA(unsigned int, + (unsigned int)(0)), + DEFAULT_TO_STRING_LAMBDA(unsigned int), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(LongProperty, long, long(0), numeric_limits::lowest(), numeric_limits::max(), long(1), DEFAULT_FROM_LUA_LAMBDA(long, long(0)), - DEFAULT_TO_LUA_LAMBDA(long), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(long), + DEFAULT_FROM_STRING_LAMBDA(long, long(0)), + DEFAULT_TO_STRING_LAMBDA(long), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(ULongProperty, unsigned long, (unsigned long)0, numeric_limits::lowest(), numeric_limits::max(), (unsigned long)1, DEFAULT_FROM_LUA_LAMBDA(unsigned long, (unsigned long)(0)), - DEFAULT_TO_LUA_LAMBDA(unsigned long), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(unsigned long), + DEFAULT_FROM_STRING_LAMBDA(unsigned long, + (unsigned long)(0)), + DEFAULT_TO_STRING_LAMBDA(unsigned long), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(LongLongProperty, long long, (long long)0, numeric_limits::lowest(), numeric_limits::max(), (long long)1, DEFAULT_FROM_LUA_LAMBDA(long long, (long long)(0)), - DEFAULT_TO_LUA_LAMBDA(long long), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(long long), + DEFAULT_FROM_STRING_LAMBDA(long long, + (long long)(0)), + DEFAULT_TO_STRING_LAMBDA(long long), + LUA_TNUMBER); -REGISTER_NUMERICALPROPERTY_SOURCE( - ULongLongProperty, unsigned long long, (unsigned long long)1, - numeric_limits::lowest(), - numeric_limits::max(), (unsigned long long)1, - DEFAULT_FROM_LUA_LAMBDA(unsigned long long, (unsigned long long)(0)), - DEFAULT_TO_LUA_LAMBDA(unsigned long long), LUA_TNUMBER); +REGISTER_NUMERICALPROPERTY_SOURCE(ULongLongProperty, unsigned long long, + (unsigned long long)1, + numeric_limits::lowest(), + numeric_limits::max(), + (unsigned long long)1, + DEFAULT_FROM_LUA_LAMBDA(unsigned long long, + (unsigned long long)(0)), + DEFAULT_TO_LUA_LAMBDA(unsigned long long), + DEFAULT_FROM_STRING_LAMBDA(unsigned long long, + (unsigned long long)(0)), + DEFAULT_TO_STRING_LAMBDA(unsigned long long), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(FloatProperty, float, 0.f, numeric_limits::lowest(), numeric_limits::max(), 0.01f, DEFAULT_FROM_LUA_LAMBDA(float, float(0)), - DEFAULT_TO_LUA_LAMBDA(float), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(float), + DEFAULT_FROM_STRING_LAMBDA(float, float(0)), + DEFAULT_TO_STRING_LAMBDA(float), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(DoubleProperty, double, 0.0, numeric_limits::lowest(), numeric_limits::max(), 0.01, DEFAULT_FROM_LUA_LAMBDA(double, double(0)), - DEFAULT_TO_LUA_LAMBDA(double), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(double), + DEFAULT_FROM_STRING_LAMBDA(double, double(0)), + DEFAULT_TO_STRING_LAMBDA(double), + LUA_TNUMBER); REGISTER_NUMERICALPROPERTY_SOURCE(LongDoubleProperty, long double, (long double)0, numeric_limits::lowest(), numeric_limits::max(), (long double)0.01f, DEFAULT_FROM_LUA_LAMBDA(long double, (long double)(0)), - DEFAULT_TO_LUA_LAMBDA(long double), LUA_TNUMBER); + DEFAULT_TO_LUA_LAMBDA(long double), + DEFAULT_FROM_STRING_LAMBDA(long double, + (long double)(0)), + DEFAULT_TO_STRING_LAMBDA(long double), + LUA_TNUMBER); } // namespace properties } // namespace openspace diff --git a/src/properties/selectionproperty.cpp b/src/properties/selectionproperty.cpp index 56bcf2abd0..cb4b5ce461 100644 --- a/src/properties/selectionproperty.cpp +++ b/src/properties/selectionproperty.cpp @@ -26,6 +26,8 @@ namespace { const std::string _loggerCat = "SelectionProperty"; + + const std::string Delimiter = ","; } namespace openspace { @@ -109,6 +111,29 @@ int PropertyDelegate>>::typeLua() { return LUA_TTABLE; } +template <> +template <> +std::vector PropertyDelegate>>::fromString(std::string value, bool& success) { + std::vector result; + size_t pos = 0; + while ((pos = value.find(Delimiter)) != std::string::npos) { + std::string token = value.substr(0, pos); + result.push_back(std::stoi(token)); + value.erase(0, pos + Delimiter.length()); + } + return result; +} + +template <> +template <> +bool PropertyDelegate>>::toString(std::string& outValue, std::vector inValue) { + outValue = "["; + for (int i : inValue) + outValue += std::to_string(i) + Delimiter; + outValue += "]"; + return true; +} + std::string SelectionProperty::generateAdditionalDescription() const { std::string result; result += OptionsKey + " = {"; diff --git a/src/properties/stringproperty.cpp b/src/properties/stringproperty.cpp index 1192acb36f..0eeffd7a3b 100644 --- a/src/properties/stringproperty.cpp +++ b/src/properties/stringproperty.cpp @@ -41,6 +41,14 @@ REGISTER_TEMPLATEPROPERTY_SOURCE(StringProperty, std::string, "", lua_pushstring(state, value.c_str()); return true; }, +[](std::string value, bool& success) -> std::string { + success = true; + return value; +}, +[](std::string& outValue, std::string inValue) -> bool { + outValue = inValue; + return true; +}, LUA_TSTRING ); diff --git a/src/properties/triggerproperty.cpp b/src/properties/triggerproperty.cpp index 41b114711a..f9450afd65 100644 --- a/src/properties/triggerproperty.cpp +++ b/src/properties/triggerproperty.cpp @@ -35,7 +35,7 @@ std::string TriggerProperty::className() const { return "TriggerProperty"; } -bool TriggerProperty::setLua(lua_State* state) { +bool TriggerProperty::setLuaValue(lua_State* state) { notifyListener(); return true; } diff --git a/src/properties/vectorproperty.cpp b/src/properties/vectorproperty.cpp index 9fcc7cdf57..98b9c40a29 100644 --- a/src/properties/vectorproperty.cpp +++ b/src/properties/vectorproperty.cpp @@ -26,6 +26,7 @@ #include #include +#include #include @@ -68,6 +69,37 @@ namespace properties { return true; \ } +#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \ + [](std::string value, bool& success) -> __TYPE__ { \ + __TYPE__ result; \ + std::vector tokens = ghoul::tokenizeString(value, ','); \ + if (tokens.size() != result.length()) { \ + success = false; \ + return result; \ + } \ + for (__TYPE__::size_type i = 0; i < result.length(); ++i) { \ + std::stringstream s(tokens[i]); \ + __TYPE__::value_type v; \ + s >> v; \ + if (s.fail()) { \ + success = false; \ + return result; \ + } \ + else \ + result[i] = v; \ + } \ + success = true; \ + return result; \ + } + +#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \ + [](std::string& outValue, __TYPE__ inValue) -> bool { \ + outValue = ""; \ + for (__TYPE__::size_type i = 0; i < inValue.length(); ++i) \ + outValue += std::to_string(inValue[i]) + ","; \ + return true; \ + } + // Forcing value from int to bool is acceptable here (line 48) #ifdef WIN32 @@ -78,40 +110,64 @@ namespace properties { REGISTER_TEMPLATEPROPERTY_SOURCE(BVec2Property, glm::bvec2, glm::bvec2(false), DEFAULT_FROM_LUA_LAMBDA(glm::bvec2, lua_toboolean, lua_isboolean), - DEFAULT_TO_LUA_LAMBDA(glm::bvec2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::bvec2), + DEFAULT_FROM_STRING_LAMBDA(glm::bvec2), + DEFAULT_TO_STRING_LAMBDA(glm::bvec2), + LUA_TTABLE); REGISTER_TEMPLATEPROPERTY_SOURCE(BVec3Property, glm::bvec3, glm::bvec3(false), DEFAULT_FROM_LUA_LAMBDA(glm::bvec3, lua_toboolean, lua_isboolean), - DEFAULT_TO_LUA_LAMBDA(glm::bvec3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::bvec3), + DEFAULT_FROM_STRING_LAMBDA(glm::bvec3), + DEFAULT_TO_STRING_LAMBDA(glm::bvec3), + LUA_TTABLE); REGISTER_TEMPLATEPROPERTY_SOURCE(BVec4Property, glm::bvec4, glm::bvec4(false), DEFAULT_FROM_LUA_LAMBDA(glm::bvec4, lua_toboolean, lua_isboolean), - DEFAULT_TO_LUA_LAMBDA(glm::bvec4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::bvec4), + DEFAULT_FROM_STRING_LAMBDA(glm::bvec4), + DEFAULT_TO_STRING_LAMBDA(glm::bvec4), + LUA_TTABLE); #ifdef WIN32 #pragma warning(default : 4800) #endif -REGISTER_NUMERICALPROPERTY_SOURCE( - Vec2Property, glm::vec2, glm::vec2(0), glm::vec2(numeric_limits::lowest()), - glm::vec2(numeric_limits::max()), glm::vec2(0.01f), - DEFAULT_FROM_LUA_LAMBDA(glm::vec2, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::vec2), LUA_TTABLE); +REGISTER_NUMERICALPROPERTY_SOURCE(Vec2Property, glm::vec2, glm::vec2(0), + glm::vec2(numeric_limits::lowest()), + glm::vec2(numeric_limits::max()), + glm::vec2(0.01f), + DEFAULT_FROM_LUA_LAMBDA(glm::vec2, lua_tonumber, + lua_isnumber), + DEFAULT_TO_LUA_LAMBDA(glm::vec2), + DEFAULT_FROM_STRING_LAMBDA(glm::vec2), + DEFAULT_TO_STRING_LAMBDA(glm::vec2), + LUA_TTABLE); -REGISTER_NUMERICALPROPERTY_SOURCE( - Vec3Property, glm::vec3, glm::vec3(0), glm::vec3(numeric_limits::lowest()), - glm::vec3(numeric_limits::max()), glm::vec3(0.01f), - DEFAULT_FROM_LUA_LAMBDA(glm::vec3, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::vec3), LUA_TTABLE); +REGISTER_NUMERICALPROPERTY_SOURCE(Vec3Property, glm::vec3, glm::vec3(0), + glm::vec3(numeric_limits::lowest()), + glm::vec3(numeric_limits::max()), + glm::vec3(0.01f), + DEFAULT_FROM_LUA_LAMBDA(glm::vec3, lua_tonumber, + lua_isnumber), + DEFAULT_TO_LUA_LAMBDA(glm::vec3), + DEFAULT_FROM_STRING_LAMBDA(glm::vec3), + DEFAULT_TO_STRING_LAMBDA(glm::vec3), + LUA_TTABLE); -REGISTER_NUMERICALPROPERTY_SOURCE( - Vec4Property, glm::vec4, glm::vec4(0), glm::vec4(numeric_limits::lowest()), - glm::vec4(numeric_limits::max()), glm::vec4(0.01f), - DEFAULT_FROM_LUA_LAMBDA(glm::vec4, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::vec4), LUA_TTABLE); +REGISTER_NUMERICALPROPERTY_SOURCE(Vec4Property, glm::vec4, glm::vec4(0), + glm::vec4(numeric_limits::lowest()), + glm::vec4(numeric_limits::max()), + glm::vec4(0.01f), + DEFAULT_FROM_LUA_LAMBDA(glm::vec4, lua_tonumber, + lua_isnumber), + DEFAULT_TO_LUA_LAMBDA(glm::vec4), + DEFAULT_FROM_STRING_LAMBDA(glm::vec4), + DEFAULT_TO_STRING_LAMBDA(glm::vec4), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DVec2Property, glm::dvec2, glm::dvec2(0), glm::dvec2(numeric_limits::lowest()), @@ -119,7 +175,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DVec2Property, glm::dvec2, glm::dvec2(0), glm::dvec2(0.01), DEFAULT_FROM_LUA_LAMBDA(glm::dvec2, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::dvec2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dvec2), + DEFAULT_FROM_STRING_LAMBDA(glm::dvec2), + DEFAULT_TO_STRING_LAMBDA(glm::dvec2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DVec3Property, glm::dvec3, glm::dvec3(0), glm::dvec3(numeric_limits::lowest()), @@ -127,7 +186,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DVec3Property, glm::dvec3, glm::dvec3(0), glm::dvec3(0.01), DEFAULT_FROM_LUA_LAMBDA(glm::dvec3, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::dvec3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dvec3), + DEFAULT_FROM_STRING_LAMBDA(glm::dvec3), + DEFAULT_TO_STRING_LAMBDA(glm::dvec3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(DVec4Property, glm::dvec4, glm::dvec4(0), glm::dvec4(numeric_limits::lowest()), @@ -135,28 +197,40 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DVec4Property, glm::dvec4, glm::dvec4(0), glm::dvec4(0.01), DEFAULT_FROM_LUA_LAMBDA(glm::dvec4, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::dvec4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::dvec4), + DEFAULT_FROM_STRING_LAMBDA(glm::dvec4), + DEFAULT_TO_STRING_LAMBDA(glm::dvec4), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(IVec2Property, glm::ivec2, glm::ivec2(0), glm::ivec2(numeric_limits::lowest()), glm::ivec2(numeric_limits::max()), glm::ivec2(1), DEFAULT_FROM_LUA_LAMBDA(glm::ivec2, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::ivec2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::ivec2), + DEFAULT_FROM_STRING_LAMBDA(glm::ivec2), + DEFAULT_TO_STRING_LAMBDA(glm::ivec2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(IVec3Property, glm::ivec3, glm::ivec3(0), glm::ivec3(numeric_limits::lowest()), glm::ivec3(numeric_limits::max()), glm::ivec3(1), DEFAULT_FROM_LUA_LAMBDA(glm::ivec3, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::ivec3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::ivec3), + DEFAULT_FROM_STRING_LAMBDA(glm::ivec3), + DEFAULT_TO_STRING_LAMBDA(glm::ivec3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(IVec4Property, glm::ivec4, glm::ivec4(0), glm::ivec4(numeric_limits::lowest()), glm::ivec4(numeric_limits::max()), glm::ivec4(1), DEFAULT_FROM_LUA_LAMBDA(glm::ivec4, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::ivec4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::ivec4), + DEFAULT_FROM_STRING_LAMBDA(glm::ivec4), + DEFAULT_TO_STRING_LAMBDA(glm::ivec4), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(UVec2Property, glm::uvec2, glm::uvec2(0), glm::uvec2(numeric_limits::lowest()), @@ -164,7 +238,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(UVec2Property, glm::uvec2, glm::uvec2(0), glm::uvec2(1), DEFAULT_FROM_LUA_LAMBDA(glm::uvec2, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::uvec2), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::uvec2), + DEFAULT_FROM_STRING_LAMBDA(glm::uvec2), + DEFAULT_TO_STRING_LAMBDA(glm::uvec2), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(UVec3Property, glm::uvec3, glm::uvec3(0), glm::uvec3(numeric_limits::lowest()), @@ -172,7 +249,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(UVec3Property, glm::uvec3, glm::uvec3(0), glm::uvec3(1), DEFAULT_FROM_LUA_LAMBDA(glm::uvec3, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::uvec3), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::uvec3), + DEFAULT_FROM_STRING_LAMBDA(glm::uvec3), + DEFAULT_TO_STRING_LAMBDA(glm::uvec3), + LUA_TTABLE); REGISTER_NUMERICALPROPERTY_SOURCE(UVec4Property, glm::uvec4, glm::uvec4(0), glm::uvec4(numeric_limits::lowest()), @@ -180,7 +260,10 @@ REGISTER_NUMERICALPROPERTY_SOURCE(UVec4Property, glm::uvec4, glm::uvec4(0), glm::uvec4(1), DEFAULT_FROM_LUA_LAMBDA(glm::uvec4, lua_tonumber, lua_isnumber), - DEFAULT_TO_LUA_LAMBDA(glm::uvec4), LUA_TTABLE); + DEFAULT_TO_LUA_LAMBDA(glm::uvec4), + DEFAULT_FROM_STRING_LAMBDA(glm::uvec4), + DEFAULT_TO_STRING_LAMBDA(glm::uvec4), + LUA_TTABLE); } // namespace properties } // namespace openspace diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index c08347e1d5..6c43277031 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -58,7 +58,7 @@ int property_setValue(lua_State* L) { return 0; } else - prop->setLua(L); + prop->setLuaValue(L); return 0; } @@ -84,7 +84,7 @@ int property_getValue(lua_State* L) { return 0; } else - prop->getLua(L); + prop->getLuaValue(L); return 1; } diff --git a/support/cmake/handle_external_library.cmake b/support/cmake/handle_external_library.cmake index 27cd7af07f..da53da1ea4 100644 --- a/support/cmake/handle_external_library.cmake +++ b/support/cmake/handle_external_library.cmake @@ -33,12 +33,15 @@ function (include_external_library target_name library_name path) target_link_libraries(${target_name} ${library_name}) target_include_directories(${target_name} PUBLIC SYSTEM ${INCLUDE_DIR}) set_property(TARGET ${library_name} PROPERTY FOLDER "External") + if (MSVC) + target_compile_options(${library_name} PUBLIC "/MP") + endif () if (OPENSPACE_DISABLE_EXTERNAL_WARNINGS) if (MSVC) - target_compile_options(${library_name} PUBLIC "/W0" "/MP") + target_compile_options(${library_name} PUBLIC "/W0") else () target_compile_options(${library_name} PUBLIC "-w") endif () endif () endif () -endfunction () \ No newline at end of file +endfunction () diff --git a/support/cmake/support_macros.cmake b/support/cmake/support_macros.cmake index 1f90d5e24f..9ed1a86d9b 100644 --- a/support/cmake/support_macros.cmake +++ b/support/cmake/support_macros.cmake @@ -178,6 +178,13 @@ function (add_external_dependencies) target_compile_definitions(libOpenSpace PUBLIC "OPENSPACE_CURL_ENABLED") endif () endif() + + # Qt + # Unfortunately, we have to set this value manually; sigh + # In the future, if the Qt version is updated, just add to this variable ---abock + if (APPLE) + set(CMAKE_PREFIX_PATH "~/Qt/5.5/clang_64/lib/cmake" PARENT_SCOPE) + endif () endfunction ()