From d0f97901d467bef2f18b6daabeffde43797a260e Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 18 Jun 2018 12:49:03 +0200 Subject: [PATCH] Add DashboardItem that can display a property value Fix documentation of most other dashboard items --- data/assets/examples/dashboarditems.asset | 33 ++-- data/assets/util/default_dashboard.asset | 20 +- ext/ghoul | 2 +- modules/base/CMakeLists.txt | 2 + modules/base/basemodule.cpp | 4 + .../base/dashboard/dashboarditemframerate.cpp | 2 +- .../base/dashboard/dashboarditemmission.cpp | 2 +- .../dashboarditemparallelconnection.cpp | 2 +- .../dashboard/dashboarditempropertyvalue.cpp | 182 ++++++++++++++++++ .../dashboard/dashboarditempropertyvalue.h | 69 +++++++ .../dashboarditemsimulationincrement.cpp | 2 +- 11 files changed, 292 insertions(+), 28 deletions(-) create mode 100644 modules/base/dashboard/dashboarditempropertyvalue.cpp create mode 100644 modules/base/dashboard/dashboarditempropertyvalue.h diff --git a/data/assets/examples/dashboarditems.asset b/data/assets/examples/dashboarditems.asset index bfb0590e6b..3d3f04d29e 100644 --- a/data/assets/examples/dashboarditems.asset +++ b/data/assets/examples/dashboarditems.asset @@ -2,42 +2,49 @@ local assetHelper = asset.require('util/asset_helper') assetHelper.registerDashboardItems(asset, { { + Type = "DashboardItemAngle", Identifier = "Angle", GuiName = "Angle", - Type = "DashboardItemAngle", ReferenceType = "Node", ReferenceNodeName = "Earth", DestinationType = "Node", DestinationNodeName = "Moon" }, { + Type = "DashboardItemDate", Identifier = "Date", - GuiName = "Date", - Type = "DashboardItemDate" + GuiName = "Date" }, { + Type = "DashboardItemSimulationIncrement", Identifier = "SimulationIncrement", - GuiName = "Simulation Increment", - Type = "DashboardItemSimulationIncrement" + GuiName = "Simulation Increment" }, { + Type = "DashboardItemDistance", Identifier = "Distance", - GuiName = "Distance", - Type = "DashboardItemDistance" + GuiName = "Distance" }, { + Type = "DashboardItemFramerate", Identifier = "Framerate", - GuiName = "Framerate", - Type = "DashboardItemFramerate" + GuiName = "Framerate" }, { + Type = "DashboardItemParallelConnection", Identifier = "ParallelConnection", - GuiName = "Parallel Connection", - Type = "DashboardItemParallelConnection" + GuiName = "Parallel Connection" }, { + Type = "DashboardItemMission", Identifier = "Mission", - GuiName = "Mission", - Type = "DashboardItemMission" + GuiName = "Mission" + }, + { + Type = "DashboardItemPropertyValue", + Identifier = "asd", + GuiName = "adasd", + URI = "Scene.Earth.RenderableGlobe.Enabled", + DisplayString = "Earth is enabled: {}" } }) diff --git a/data/assets/util/default_dashboard.asset b/data/assets/util/default_dashboard.asset index f4e01457f8..dcc4191c70 100644 --- a/data/assets/util/default_dashboard.asset +++ b/data/assets/util/default_dashboard.asset @@ -2,28 +2,28 @@ local assetHelper = asset.require('util/asset_helper') assetHelper.registerDashboardItems(asset, { { + Type = "DashboardItemDate", Identifier = "Date", - GuiName = "Date", - Type = "DashboardItemDate" + GuiName = "Date" }, { + Type = "DashboardItemSimulationIncrement", Identifier = "SimulationIncrement", - GuiName = "Simulation Increment", - Type = "DashboardItemSimulationIncrement" + GuiName = "Simulation Increment" }, { + Type = "DashboardItemDistance", Identifier = "Distance", - GuiName = "Distance", - Type = "DashboardItemDistance" + GuiName = "Distance" }, { + Type = "DashboardItemFramerate", Identifier = "Framerate", - GuiName = "Framerate", - Type = "DashboardItemFramerate" + GuiName = "Framerate" }, { + Type = "DashboardItemParallelConnection", Identifier = "ParallelConnection", - GuiName = "Parallel Connection", - Type = "DashboardItemParallelConnection" + GuiName = "Parallel Connection" } }) diff --git a/ext/ghoul b/ext/ghoul index debf58989c..c3385dd94b 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit debf58989c5ba0c36341d4bb64b945fb90db4dcd +Subproject commit c3385dd94b6ff9ce0153722303356802eb8819a2 diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index 1c92306bdb..8b5a977773 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -31,6 +31,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemframerate.h ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemmission.h ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemparallelconnection.h + ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditempropertyvalue.h ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemsimulationincrement.h ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemspacing.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.h @@ -65,6 +66,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemframerate.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemmission.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemparallelconnection.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditempropertyvalue.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemsimulationincrement.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemspacing.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.cpp diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index 695bf27557..e5a08a3f31 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,9 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) { fDashboard->registerClass( "DashboardItemParallelConnection" ); + fDashboard->registerClass( + "DashboardItemPropertyValue" + ); fDashboard->registerClass( "DashboardItemSimulationIncrement" ); diff --git a/modules/base/dashboard/dashboarditemframerate.cpp b/modules/base/dashboard/dashboarditemframerate.cpp index 9d6741f320..fab7e7cb29 100644 --- a/modules/base/dashboard/dashboarditemframerate.cpp +++ b/modules/base/dashboard/dashboarditemframerate.cpp @@ -104,7 +104,7 @@ DashboardItemFramerate::DashboardItemFramerate(const ghoul::Dictionary& dictiona documentation::testSpecificationAndThrow( Documentation(), dictionary, - "DashboardItemDate" + "DashboardItemFramerate" ); if (dictionary.hasKey(FontNameInfo.identifier)) { diff --git a/modules/base/dashboard/dashboarditemmission.cpp b/modules/base/dashboard/dashboarditemmission.cpp index fd3574eacd..021e541714 100644 --- a/modules/base/dashboard/dashboarditemmission.cpp +++ b/modules/base/dashboard/dashboarditemmission.cpp @@ -106,7 +106,7 @@ DashboardItemMission::DashboardItemMission(const ghoul::Dictionary& dictionary) documentation::testSpecificationAndThrow( Documentation(), dictionary, - "DashboardItemDate" + "DashboardItemMission" ); if (dictionary.hasKey(FontNameInfo.identifier)) { diff --git a/modules/base/dashboard/dashboarditemparallelconnection.cpp b/modules/base/dashboard/dashboarditemparallelconnection.cpp index 28b7d4edc7..0fc2a479dc 100644 --- a/modules/base/dashboard/dashboarditemparallelconnection.cpp +++ b/modules/base/dashboard/dashboarditemparallelconnection.cpp @@ -91,7 +91,7 @@ DashboardItemParallelConnection::DashboardItemParallelConnection( documentation::testSpecificationAndThrow( Documentation(), dictionary, - "DashboardItemDate" + "DashboardItemParallelConnection" ); if (dictionary.hasKey(FontNameInfo.identifier)) { diff --git a/modules/base/dashboard/dashboarditempropertyvalue.cpp b/modules/base/dashboard/dashboarditempropertyvalue.cpp new file mode 100644 index 0000000000..8a39d2e856 --- /dev/null +++ b/modules/base/dashboard/dashboarditempropertyvalue.cpp @@ -0,0 +1,182 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + constexpr const char* KeyFontMono = "Mono"; + constexpr const float DefaultFontSize = 10.f; + + const openspace::properties::Property::PropertyInfo FontNameInfo = { + "FontName", + "Font Name", + "This value is the name of the font that is used. It can either refer to an " + "internal name registered previously, or it can refer to a path that is used." + }; + + const openspace::properties::Property::PropertyInfo FontSizeInfo = { + "FontSize", + "Font Size", + "This value determines the size of the font that is used to render the date." + }; + + const openspace::properties::Property::PropertyInfo PropertyUriInfo = { + "URI", + "Property URI", + "The URI of the property that is displayed in this dashboarditem" + }; + + const openspace::properties::Property::PropertyInfo DisplayStringInfo = { + "DisplayString", + "Display String", + "The String that is being displayed. It must either be empty (in which case only " + "the value itself will be displayed), or it must contain extact one instance of " + "{}, which will be replaced with the value of the property during rendering." + }; +} // namespace + +namespace openspace { + +documentation::Documentation DashboardItemPropertyValue::Documentation() { + using namespace documentation; + return { + "DashboardItem PropertyValue", + "base_dashboarditem_propertyvalue", + { + { + "Type", + new StringEqualVerifier("DashboardItemPropertyValue"), + Optional::No + }, + { + FontNameInfo.identifier, + new StringVerifier, + Optional::Yes, + FontNameInfo.description + }, + { + FontSizeInfo.identifier, + new IntVerifier, + Optional::Yes, + FontSizeInfo.description + }, + { + PropertyUriInfo.identifier, + new StringVerifier, + Optional::Yes, + PropertyUriInfo.description + }, + { + DisplayStringInfo.identifier, + new StringVerifier, + Optional::Yes, + DisplayStringInfo.description + } + } + }; +} + +DashboardItemPropertyValue::DashboardItemPropertyValue(const ghoul::Dictionary& dictionary) + : DashboardItem(dictionary) + , _fontName(FontNameInfo, KeyFontMono) + , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) + , _propertyUri(PropertyUriInfo) + , _displayString(DisplayStringInfo) +{ + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "DashboardItemPropertyValue" + ); + + if (dictionary.hasKey(FontNameInfo.identifier)) { + _fontName = dictionary.value(FontNameInfo.identifier); + } + _fontName.onChange([this](){ + _font = OsEng.fontManager().font(_fontName, _fontSize); + }); + addProperty(_fontName); + + if (dictionary.hasKey(FontSizeInfo.identifier)) { + _fontSize = static_cast( + dictionary.value(FontSizeInfo.identifier) + ); + } + _fontSize.onChange([this](){ + _font = OsEng.fontManager().font(_fontName, _fontSize); + }); + addProperty(_fontSize); + + if (dictionary.hasKey(PropertyUriInfo.identifier)) { + _propertyUri = dictionary.value(PropertyUriInfo.identifier); + } + _propertyUri.onChange([this]() { + _propertyIsDirty = true; + }); + addProperty(_propertyUri); + + if (dictionary.hasKey(DisplayStringInfo.identifier)) { + _displayString = dictionary.value(DisplayStringInfo.identifier); + } + addProperty(_displayString); + + _font = OsEng.fontManager().font(_fontName, _fontSize); +} + +void DashboardItemPropertyValue::render(glm::vec2& penPosition) { + if (_propertyIsDirty) { + _property = openspace::property(_propertyUri); + _propertyIsDirty = false; + } + + if (_property) { + std::string value; + _property->getStringValue(value); + + penPosition.y -= _font->height(); + RenderFont( + *_font, + penPosition, + fmt::format(_displayString.value(), value) + ); + } +} + +glm::vec2 DashboardItemPropertyValue::size() const { + return ghoul::fontrendering::FontRenderer::defaultRenderer().boundingBox( + *_font, + _displayString.value() + ).boundingBox; +} + +} // namespace openspace diff --git a/modules/base/dashboard/dashboarditempropertyvalue.h b/modules/base/dashboard/dashboarditempropertyvalue.h new file mode 100644 index 0000000000..1c853ce40a --- /dev/null +++ b/modules/base/dashboard/dashboarditempropertyvalue.h @@ -0,0 +1,69 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMPROPERTYVALUE___H__ +#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMPROPERTYVALUE___H__ + +#include + +#include +#include + +namespace ghoul::fontrendering { class Font; } + +namespace openspace { + +namespace properties { class Property; } + +namespace documentation { struct Documentation; } + +class DashboardItemPropertyValue : public DashboardItem { +public: + DashboardItemPropertyValue(const ghoul::Dictionary& dictionary); + ~DashboardItemPropertyValue() = default; + + void render(glm::vec2& penPosition) override; + + glm::vec2 size() const override; + + static documentation::Documentation Documentation(); + +private: + properties::StringProperty _fontName; + properties::FloatProperty _fontSize; + + properties::Property* _property = nullptr; + bool _propertyIsDirty = true; + + properties::StringProperty _propertyUri; + properties::StringProperty _displayString; + + + + std::shared_ptr _font; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___DASHBOARDITEMPROPERTYVALUE___H__ diff --git a/modules/base/dashboard/dashboarditemsimulationincrement.cpp b/modules/base/dashboard/dashboarditemsimulationincrement.cpp index 41a7d92cb5..e431a5ae6a 100644 --- a/modules/base/dashboard/dashboarditemsimulationincrement.cpp +++ b/modules/base/dashboard/dashboarditemsimulationincrement.cpp @@ -129,7 +129,7 @@ DashboardItemSimulationIncrement::DashboardItemSimulationIncrement( documentation::testSpecificationAndThrow( Documentation(), dictionary, - "DashboardItemDate" + "DashboardItemSimulationIncrement" ); if (dictionary.hasKey(FontNameInfo.identifier)) {