diff --git a/data/assets/examples/discs.asset b/data/assets/examples/discs.asset index 5dcdbc8924..9bb583e96d 100644 --- a/data/assets/examples/discs.asset +++ b/data/assets/examples/discs.asset @@ -1,8 +1,8 @@ local assetHelper = asset.require('util/asset_helper') -- @TODO (emmbr 2020-02-03) Potential threading issue later on? This will run on the main thread -local cyanTexture = openspace.createSingeColorImage("example_disc_color1", {0.0, 1.0, 1.0}) -local purpleTexture = openspace.createSingeColorImage("example_disc_color2", {0.5, 0.0, 0.5}) +local cyanTexture = openspace.createSingleColorImage("example_disc_color1", {0.0, 1.0, 1.0}) +local purpleTexture = openspace.createSingleColorImage("example_disc_color2", {0.5, 0.0, 0.5}) local BasicDisc = { Identifier = "BasicDisc", diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 9be28c5d6f..fbf66f683c 100644 --- a/data/assets/util/webgui.asset +++ b/data/assets/util/webgui.asset @@ -3,7 +3,7 @@ asset.require('./static_server') local guiCustomization = asset.require('customization/gui') -- Select which commit hashes to use for the frontend and backend -local frontendHash = "391f8d3ed74e598a0e8a1b16016324d8f747e18d" +local frontendHash = "17b69f29a4a596d488ba8c9de953cc22fb0dce5c" local dataProvider = "data.openspaceproject.com/files/webgui" local frontend = asset.syncedResource({ diff --git a/include/openspace/documentation/documentationgenerator.h b/include/openspace/documentation/documentationgenerator.h index 103187675f..248fa4ea22 100644 --- a/include/openspace/documentation/documentationgenerator.h +++ b/include/openspace/documentation/documentationgenerator.h @@ -94,24 +94,6 @@ private: const std::vector _handlebarTemplates; }; -/** - * This function takes a \p text and escapes all necessary characters () that JSON - * does not want in its strings. - * \param text The text that is to be escaped - * \return The same text will all required characteres escaped - */ -std::string escapedJson(const std::string& text); - - -/** - * This function takes a \p list of text and escapes all necessary characters () that JSON - * does not want in its strings. - * \param text The list text that is to be escaped - * \return The same text will all required characteres escaped - */ -std::string escapedJson(const std::vector& list); - - } // namespace openspace #endif // __OPENSPACE_CORE___DOCUMENTATIONGENERATOR___H__ diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index 98fbb8518c..47d00ac21f 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -85,7 +85,7 @@ struct Configuration { bool shouldUseScreenshotDate = false; std::string onScreenTextScaling = "window"; - bool usePerSceneCache = false; + bool usePerProfileCache = false; bool isRenderingOnMasterDisabled = false; glm::dvec3 globalRotation = glm::dvec3(0.0); diff --git a/include/openspace/properties/list/doublelistproperty.h b/include/openspace/properties/list/doublelistproperty.h index b857dbc144..2d5bbdf40a 100644 --- a/include/openspace/properties/list/doublelistproperty.h +++ b/include/openspace/properties/list/doublelistproperty.h @@ -31,35 +31,21 @@ namespace openspace::properties { class DoubleListProperty : public ListProperty { public: - DoubleListProperty(Property::PropertyInfo info); - DoubleListProperty(Property::PropertyInfo info, std::vector values); + DoubleListProperty(Property::PropertyInfo info, + std::vector values = std::vector()); + + std::string className() const override; + int typeLua() const override; using TemplateProperty>::operator std::vector; using TemplateProperty>::operator=; + +protected: + std::vector fromLuaConversion(lua_State* state, bool& success) const override; + void toLuaConversion(lua_State* state) const override; + std::string toStringConversion() const override; }; -template <> -std::string PropertyDelegate>>::className(); - -template <> -template <> -std::vector -PropertyDelegate>>::fromLuaValue( - lua_State* state, bool& success); - -template <> -template <> -bool PropertyDelegate>>::toLuaValue( - lua_State* state, const std::vector& value); - -template <> -int PropertyDelegate>>::typeLua(); - -template <> -template <> -bool PropertyDelegate>>::toString( - std::string& outValue, const std::vector& inValue); - } // namespace openspace::properties #endif // __OPENSPACE_CORE___DOUBLELISTPROPERTY___H__ diff --git a/include/openspace/properties/list/intlistproperty.h b/include/openspace/properties/list/intlistproperty.h index 2213968d0d..0157b4d6af 100644 --- a/include/openspace/properties/list/intlistproperty.h +++ b/include/openspace/properties/list/intlistproperty.h @@ -31,34 +31,21 @@ namespace openspace::properties { class IntListProperty : public ListProperty { public: - IntListProperty(Property::PropertyInfo info); - IntListProperty(Property::PropertyInfo info, std::vector values); + IntListProperty(Property::PropertyInfo info, + std::vector values = std::vector()); + + std::string className() const override; + int typeLua() const override; using TemplateProperty>::operator std::vector; using TemplateProperty>::operator=; + +protected: + std::vector fromLuaConversion(lua_State* state, bool& success) const override; + void toLuaConversion(lua_State* state) const override; + std::string toStringConversion() const override; }; -template <> -std::string PropertyDelegate>>::className(); - -template <> -template <> -std::vector PropertyDelegate>>::fromLuaValue( - lua_State* state, bool& success); - -template <> -template <> -bool PropertyDelegate>>::toLuaValue( - lua_State* state, const std::vector& value); - -template <> -int PropertyDelegate>>::typeLua(); - -template <> -template <> -bool PropertyDelegate>>::toString( - std::string& outValue, const std::vector& inValue); - } // namespace openspace::properties #endif // __OPENSPACE_CORE___INTLISTPROPERTY___H__ diff --git a/include/openspace/properties/list/stringlistproperty.h b/include/openspace/properties/list/stringlistproperty.h index 8ed0259332..1d8dfc25ac 100644 --- a/include/openspace/properties/list/stringlistproperty.h +++ b/include/openspace/properties/list/stringlistproperty.h @@ -32,35 +32,22 @@ namespace openspace::properties { class StringListProperty : public ListProperty { public: - StringListProperty(Property::PropertyInfo info); - StringListProperty(Property::PropertyInfo info, std::vector values); + StringListProperty(Property::PropertyInfo info, + std::vector values = std::vector()); + + std::string className() const override; + int typeLua() const override; using TemplateProperty>::operator std::vector; using TemplateProperty>::operator=; + +protected: + std::vector fromLuaConversion(lua_State* state, + bool& success) const override; + void toLuaConversion(lua_State* state) const override; + std::string toStringConversion() const override; }; -template <> -std::string PropertyDelegate>>::className(); - -template <> -template <> -std::vector -PropertyDelegate>>::fromLuaValue( - lua_State* state, bool& success); - -template <> -template <> -bool PropertyDelegate>>::toLuaValue( - lua_State* state, const std::vector& value); - -template <> -int PropertyDelegate>>::typeLua(); - -template <> -template <> -bool PropertyDelegate>>::toString( - std::string& outValue, const std::vector& inValue); - } // namespace openspace::properties #endif // __OPENSPACE_CORE___STRINGLISTPROPERTY___H__ diff --git a/include/openspace/properties/listproperty.h b/include/openspace/properties/listproperty.h index 9d7ef0f820..2e40db8f05 100644 --- a/include/openspace/properties/listproperty.h +++ b/include/openspace/properties/listproperty.h @@ -33,7 +33,6 @@ namespace openspace::properties { template class ListProperty : public TemplateProperty> { public: - ListProperty(Property::PropertyInfo info); ListProperty(Property::PropertyInfo info, std::vector values); virtual ~ListProperty() = 0; diff --git a/include/openspace/properties/listproperty.inl b/include/openspace/properties/listproperty.inl index 6bad6b2c09..72158233bb 100644 --- a/include/openspace/properties/listproperty.inl +++ b/include/openspace/properties/listproperty.inl @@ -24,11 +24,6 @@ namespace openspace::properties { -template -ListProperty::ListProperty(Property::PropertyInfo info) - : TemplateProperty>(std::move(info)) -{} - template ListProperty::ListProperty(Property::PropertyInfo info, std::vector values) : TemplateProperty>(std::move(info), std::move(values)) diff --git a/include/openspace/properties/matrix/dmat2property.h b/include/openspace/properties/matrix/dmat2property.h index 617e56d186..659c2e98b6 100644 --- a/include/openspace/properties/matrix/dmat2property.h +++ b/include/openspace/properties/matrix/dmat2property.h @@ -28,10 +28,27 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(DMat2Property, glm::dmat2x2) +class DMat2Property : public NumericalProperty { +public: + DMat2Property(Property::PropertyInfo info, glm::dmat2x2 value = glm::dmat2x2(0.0), + glm::dmat2x2 minValue = + ghoul::createFillMat2x2(std::numeric_limits::lowest()), + glm::dmat2x2 maxValue = + ghoul::createFillMat2x2(std::numeric_limits::max()), + glm::dmat2x2 stepValue = ghoul::createFillMat2x2(0.01)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::dmat2x2 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/matrix/dmat2x3property.h b/include/openspace/properties/matrix/dmat2x3property.h deleted file mode 100644 index 825d639204..0000000000 --- a/include/openspace/properties/matrix/dmat2x3property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___DMAT2X3PROPERTY___H__ -#define __OPENSPACE_CORE___DMAT2X3PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(DMat2x3Property, glm::dmat2x3) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___DMAT2X3PROPERTY___H__ diff --git a/include/openspace/properties/matrix/dmat2x4property.h b/include/openspace/properties/matrix/dmat2x4property.h deleted file mode 100644 index ba3898edad..0000000000 --- a/include/openspace/properties/matrix/dmat2x4property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___DMAT2X4PROPERTY___H__ -#define __OPENSPACE_CORE___DMAT2X4PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(DMat2x4Property, glm::dmat2x4) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___DMAT2X4PROPERTY___H__ diff --git a/include/openspace/properties/matrix/dmat3property.h b/include/openspace/properties/matrix/dmat3property.h index 486e2ad9c3..24bb05e2c9 100644 --- a/include/openspace/properties/matrix/dmat3property.h +++ b/include/openspace/properties/matrix/dmat3property.h @@ -28,10 +28,27 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(DMat3Property, glm::dmat3x3) +class DMat3Property : public NumericalProperty { +public: + DMat3Property(Property::PropertyInfo info, glm::dmat3x3 value = glm::dmat3x3(0.0), + glm::dmat3x3 minValue = + ghoul::createFillMat3x3(std::numeric_limits::lowest()), + glm::dmat3x3 maxValue = + ghoul::createFillMat3x3(std::numeric_limits::max()), + glm::dmat3x3 stepValue = ghoul::createFillMat3x3(0.01)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::dmat3x3 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/matrix/dmat3x2property.h b/include/openspace/properties/matrix/dmat3x2property.h deleted file mode 100644 index e823466c34..0000000000 --- a/include/openspace/properties/matrix/dmat3x2property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___DMAT3X2PROPERTY___H__ -#define __OPENSPACE_CORE___DMAT3X2PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(DMat3x2Property, glm::dmat3x2) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___DMAT3X2PROPERTY___H__ diff --git a/include/openspace/properties/matrix/dmat3x4property.h b/include/openspace/properties/matrix/dmat3x4property.h deleted file mode 100644 index 87521b8724..0000000000 --- a/include/openspace/properties/matrix/dmat3x4property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___DMAT3X4PROPERTY___H__ -#define __OPENSPACE_CORE___DMAT3X4PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(DMat3x4Property, glm::dmat3x4) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___DMAT3X4PROPERTY___H__ diff --git a/include/openspace/properties/matrix/dmat4property.h b/include/openspace/properties/matrix/dmat4property.h index 3788742621..a1d1204289 100644 --- a/include/openspace/properties/matrix/dmat4property.h +++ b/include/openspace/properties/matrix/dmat4property.h @@ -28,10 +28,27 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(DMat4Property, glm::dmat4x4) +class DMat4Property : public NumericalProperty { +public: + DMat4Property(Property::PropertyInfo info, glm::dmat4x4 value = glm::dmat4x4(0.0), + glm::dmat4x4 minValue = + ghoul::createFillMat4x4(std::numeric_limits::lowest()), + glm::dmat4x4 maxValue = + ghoul::createFillMat4x4(std::numeric_limits::max()), + glm::dmat4x4 stepValue = ghoul::createFillMat4x4(0.01)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::dmat4x4 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/matrix/dmat4x2property.h b/include/openspace/properties/matrix/dmat4x2property.h deleted file mode 100644 index 7205415c08..0000000000 --- a/include/openspace/properties/matrix/dmat4x2property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___DMAT4X2PROPERTY___H__ -#define __OPENSPACE_CORE___DMAT4X2PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(DMat4x2Property, glm::dmat4x2) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___DMAT4X2PROPERTY___H__ diff --git a/include/openspace/properties/matrix/dmat4x3property.h b/include/openspace/properties/matrix/dmat4x3property.h deleted file mode 100644 index 0e028317b8..0000000000 --- a/include/openspace/properties/matrix/dmat4x3property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___DMAT4X3PROPERTY___H__ -#define __OPENSPACE_CORE___DMAT4X3PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(DMat4x3Property, glm::dmat4x3) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___DMAT4X3PROPERTY___H__ diff --git a/include/openspace/properties/matrix/mat2property.h b/include/openspace/properties/matrix/mat2property.h index 42fea778cb..1b610b2e61 100644 --- a/include/openspace/properties/matrix/mat2property.h +++ b/include/openspace/properties/matrix/mat2property.h @@ -28,10 +28,27 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(Mat2Property, glm::mat2x2) +class Mat2Property : public NumericalProperty { +public: + Mat2Property(Property::PropertyInfo info, glm::mat2x2 value = glm::mat2x2(0.f), + glm::mat2x2 minValue = + ghoul::createFillMat2x2(std::numeric_limits::lowest()), + glm::mat2x2 maxValue = + ghoul::createFillMat2x2(std::numeric_limits::max()), + glm::mat2x2 stepValue = ghoul::createFillMat2x2(0.01f)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::mat2x2 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/matrix/mat2x3property.h b/include/openspace/properties/matrix/mat2x3property.h deleted file mode 100644 index 4ad90b4c51..0000000000 --- a/include/openspace/properties/matrix/mat2x3property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___MAT2X3PROPERTY___H__ -#define __OPENSPACE_CORE___MAT2X3PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(Mat2x3Property, glm::mat2x3) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___MAT2X3PROPERTY___H__ diff --git a/include/openspace/properties/matrix/mat2x4property.h b/include/openspace/properties/matrix/mat2x4property.h deleted file mode 100644 index 54508d5535..0000000000 --- a/include/openspace/properties/matrix/mat2x4property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___MAT2X4PROPERTY___H__ -#define __OPENSPACE_CORE___MAT2X4PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(Mat2x4Property, glm::mat2x4) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___MAT2X4PROPERTY___H__ diff --git a/include/openspace/properties/matrix/mat3property.h b/include/openspace/properties/matrix/mat3property.h index fbbd272390..ee0c2357c9 100644 --- a/include/openspace/properties/matrix/mat3property.h +++ b/include/openspace/properties/matrix/mat3property.h @@ -28,10 +28,27 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(Mat3Property, glm::mat3x3) +class Mat3Property : public NumericalProperty { +public: + Mat3Property(Property::PropertyInfo info, glm::mat3x3 value = glm::mat3x3(), + glm::mat3x3 minValue = + ghoul::createFillMat3x3(std::numeric_limits::lowest()), + glm::mat3x3 maxValue = + ghoul::createFillMat3x3(std::numeric_limits::max()), + glm::mat3x3 stepValue = ghoul::createFillMat3x3(0.01f)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::mat3x3 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/matrix/mat3x2property.h b/include/openspace/properties/matrix/mat3x2property.h deleted file mode 100644 index 42290b8fbd..0000000000 --- a/include/openspace/properties/matrix/mat3x2property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___MAT3X2PROPERTY___H__ -#define __OPENSPACE_CORE___MAT3X2PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(Mat3x2Property, glm::mat3x2) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___MAT3X2PROPERTY___H__ diff --git a/include/openspace/properties/matrix/mat3x4property.h b/include/openspace/properties/matrix/mat3x4property.h deleted file mode 100644 index ee26c13adf..0000000000 --- a/include/openspace/properties/matrix/mat3x4property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___MAT3X4PROPERTY___H__ -#define __OPENSPACE_CORE___MAT3X4PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(Mat3x4Property, glm::mat3x4) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___MAT3X4PROPERTY___H__ diff --git a/include/openspace/properties/matrix/mat4property.h b/include/openspace/properties/matrix/mat4property.h index 50ddd70c40..3c64405aa7 100644 --- a/include/openspace/properties/matrix/mat4property.h +++ b/include/openspace/properties/matrix/mat4property.h @@ -28,10 +28,27 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(Mat4Property, glm::mat4x4) +class Mat4Property : public NumericalProperty { +public: + Mat4Property(Property::PropertyInfo info, glm::mat4x4 value = glm::mat4x4(), + glm::mat4x4 minValue = + ghoul::createFillMat4x4(std::numeric_limits::lowest()), + glm::mat4x4 maxValue = + ghoul::createFillMat4x4(std::numeric_limits::max()), + glm::mat4x4 stepValue = ghoul::createFillMat4x4(0.01f)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::mat4x4 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/matrix/mat4x2property.h b/include/openspace/properties/matrix/mat4x2property.h deleted file mode 100644 index a30aec4c13..0000000000 --- a/include/openspace/properties/matrix/mat4x2property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___MAT4X2PROPERTY___H__ -#define __OPENSPACE_CORE___MAT4X2PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(Mat4x2Property, glm::mat4x2) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___MAT4X2PROPERTY___H__ diff --git a/include/openspace/properties/matrix/mat4x3property.h b/include/openspace/properties/matrix/mat4x3property.h deleted file mode 100644 index fa63aa6c9e..0000000000 --- a/include/openspace/properties/matrix/mat4x3property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___MAT4X3PROPERTY___H__ -#define __OPENSPACE_CORE___MAT4X3PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(Mat4x3Property, glm::mat4x3) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___MAT4X3PROPERTY___H__ diff --git a/include/openspace/properties/numericalproperty.h b/include/openspace/properties/numericalproperty.h index 05a88a48fb..1a23ca1370 100644 --- a/include/openspace/properties/numericalproperty.h +++ b/include/openspace/properties/numericalproperty.h @@ -32,20 +32,11 @@ namespace openspace::properties { template class NumericalProperty : public TemplateProperty { public: - NumericalProperty(Property::PropertyInfo info); - NumericalProperty(Property::PropertyInfo info, T value); NumericalProperty(Property::PropertyInfo info, T value, T minimumValue, - T maximumValue); - NumericalProperty(Property::PropertyInfo info, T value, T minimumValue, - T maximumValue, T steppingValue); - NumericalProperty(Property::PropertyInfo info, T value, T minimumValue, - T maximumValue, T steppingValue, float exponent); + T maximumValue, T steppingValue, float exponent = 1.f); - bool getLuaValue(lua_State* state) const override; - bool setLuaValue(lua_State* state) override; - int typeLua() const override; - - bool getStringValue(std::string& value) const override; + virtual std::string className() const override = 0; + virtual int typeLua() const override = 0; T minValue() const; void setMinValue(T value); @@ -59,8 +50,6 @@ public: float exponent() const; void setExponent(float exponent); - virtual std::string className() const override; - std::string jsonValue() const override; using TemplateProperty::operator=; @@ -71,13 +60,16 @@ public: void interpolateValue(float t, ghoul::EasingFunc easingFunc = nullptr) override; - protected: static const std::string MinimumValueKey; static const std::string MaximumValueKey; static const std::string SteppingValueKey; static const std::string ExponentValueKey; + virtual T fromLuaConversion(lua_State* state, bool& success) const override = 0; + virtual void toLuaConversion(lua_State* state) const override; + virtual std::string toStringConversion() const override; + std::string generateAdditionalJsonDescription() const override; /** diff --git a/include/openspace/properties/numericalproperty.inl b/include/openspace/properties/numericalproperty.inl index 57913c30de..6540ddf9f3 100644 --- a/include/openspace/properties/numericalproperty.inl +++ b/include/openspace/properties/numericalproperty.inl @@ -22,175 +22,12 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include #include #include namespace openspace::properties { -#define REGISTER_NUMERICALPROPERTY_HEADER(CLASS_NAME, TYPE) \ - using CLASS_NAME = NumericalProperty; \ - \ - 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, \ - bool& success); \ - template <> \ - template <> \ - TYPE PropertyDelegate>::fromLuaValue(lua_State* state, \ - bool& success); \ - template <> \ - template <> \ - bool PropertyDelegate>::toLuaValue(lua_State* state, \ - const TYPE& value); \ - template <> \ - template <> \ - bool PropertyDelegate>::toLuaValue(lua_State* state, \ - const TYPE& value); \ - template <> \ - int PropertyDelegate>::typeLua(); \ - template <> \ - int PropertyDelegate>::typeLua(); \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toString(std::string& outValue, \ - const TYPE& inValue); \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toString(std::string& outValue, \ - const 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, \ - 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, \ - bool& success) \ - { \ - return FROM_LUA_LAMBDA_EXPRESSION(state, success); \ - } \ - \ - template <> \ - template <> \ - TYPE PropertyDelegate>::fromLuaValue(lua_State* state, \ - bool& success) \ - { \ - return PropertyDelegate>::fromLuaValue( \ - state, success); \ - } \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toLuaValue(lua_State* state, \ - const TYPE& value) \ - { \ - return TO_LUA_LAMBDA_EXPRESSION(state, value); \ - } \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toLuaValue(lua_State* state, \ - const TYPE& value) \ - { \ - return PropertyDelegate>::toLuaValue(state, value); \ - } \ - \ - template <> \ - int PropertyDelegate>::typeLua() \ - { \ - return LUA_TYPE; \ - } \ - \ - template <> \ - int PropertyDelegate>::typeLua() \ - { \ - return PropertyDelegate>::typeLua(); \ - } \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toString(std::string& outValue, \ - const TYPE& inValue) \ - { \ - return TO_STRING_LAMBDA_EXPRESSION(outValue, inValue); \ - } \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toString(std::string& outValue, \ - const TYPE& inValue) \ - { \ - return PropertyDelegate>::toString(outValue, inValue); \ - } - - template const std::string NumericalProperty::MinimumValueKey = "MinimumValue"; @@ -203,60 +40,6 @@ const std::string NumericalProperty::SteppingValueKey = "SteppingValue"; template const std::string NumericalProperty::ExponentValueKey = "Exponent"; -// Delegating constructors are necessary; automatic template deduction cannot -// deduce template argument for 'U' if 'default' methods are used as default values in -// a single constructor - -template -NumericalProperty::NumericalProperty(Property::PropertyInfo info) - : NumericalProperty( - std::move(info), - PropertyDelegate>::template defaultValue(), - PropertyDelegate>::template defaultMinimumValue(), - PropertyDelegate>::template defaultMaximumValue(), - PropertyDelegate>::template defaultSteppingValue(), - 1.f - ) -{} - -template -NumericalProperty::NumericalProperty(Property::PropertyInfo info, T value) - : NumericalProperty( - std::move(info), - std::move(value), - PropertyDelegate>::template defaultMinimumValue(), - PropertyDelegate>::template defaultMaximumValue(), - PropertyDelegate>::template defaultSteppingValue(), - 1.f - ) -{} - -template -NumericalProperty::NumericalProperty(Property::PropertyInfo info, T value, - T minimumValue, T maximumValue) - : NumericalProperty( - std::move(info), - std::move(value), - std::move(minimumValue), - std::move(maximumValue), - PropertyDelegate>::template defaultSteppingValue(), - 1.f - ) -{} - -template -NumericalProperty::NumericalProperty(Property::PropertyInfo info, T value, - T minimumValue, T maximumValue, T steppingValue) - : NumericalProperty( - std::move(info), - std::move(value), - std::move(minimumValue), - std::move(maximumValue), - std::move(steppingValue), - 1.f - ) -{} - template NumericalProperty::NumericalProperty(Property::PropertyInfo info, T value, T minimumValue, T maximumValue, T steppingValue, @@ -268,44 +51,6 @@ NumericalProperty::NumericalProperty(Property::PropertyInfo info, T value, , _exponent(exponent) {} -template -std::string NumericalProperty::className() const { - return PropertyDelegate>::className(); -} - -template -bool NumericalProperty::setLuaValue(lua_State* state) { - bool success = false; - T value = PropertyDelegate>::template fromLuaValue( - state, success - ); - if (success) { - TemplateProperty::setValue(std::move(value)); - } - return success; -} - -template -bool NumericalProperty::getLuaValue(lua_State* state) const { - bool success = PropertyDelegate>::template toLuaValue( - state, TemplateProperty::_value - ); - return success; -} - -template -int NumericalProperty::typeLua() const { - return PropertyDelegate>::typeLua(); -} - -template -bool NumericalProperty::getStringValue(std::string& value) const { - bool success = PropertyDelegate>::template toString( - value, TemplateProperty::_value - ); - return success; -} - template T NumericalProperty::minValue() const { return _minimumValue; @@ -374,8 +119,7 @@ std::string NumericalProperty::luaToJson(std::string luaValue) const { template std::string NumericalProperty::jsonValue() const { - std::string value; - getStringValue(value); + std::string value = toStringConversion(); return luaToJson(value); } @@ -390,13 +134,10 @@ void NumericalProperty::setInterpolationTarget(std::any value) { template void NumericalProperty::setLuaInterpolationTarget(lua_State* state) { bool success = false; - T thisValue = PropertyDelegate>::template fromLuaValue( - state, - success - ); + T targetValue = fromLuaConversion(state, success); if (success) { _interpolationStart = TemplateProperty::_value; - _interpolationEnd = std::move(thisValue); + _interpolationEnd = std::move(targetValue); } } @@ -412,4 +153,14 @@ void NumericalProperty::interpolateValue(float t, )); } +template +void NumericalProperty::toLuaConversion(lua_State* state) const { + ghoul::lua::push(state, TemplateProperty::_value); +} + +template +std::string NumericalProperty::toStringConversion() const { + return formatJson(TemplateProperty::_value); +} + } // namespace openspace::properties diff --git a/include/openspace/properties/propertydelegate.h b/include/openspace/properties/propertydelegate.h deleted file mode 100644 index 1a871d7b96..0000000000 --- a/include/openspace/properties/propertydelegate.h +++ /dev/null @@ -1,161 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___PROPERTYDELEGATE___H__ -#define __OPENSPACE_CORE___PROPERTYDELEGATE___H__ - -#include - -struct lua_State; - -namespace openspace::properties { - -/** - * The PropertyDelegate class is used by (among others) the TemplateProperty and the - * NumericalProperty classes to outsource the definitions of class names, default values, - * etc. Using the PropertyDelegate, it is possible to create new TemplateProperty types - * without subclassing the TemplateProperty, but rather creating a specialized instance - * of PropertyDelegate. See - * (https://github.com/OpenSpace/OpenSpace/wiki/Concepts-Properties) for more detailed - * information. - * \see TemplateProperty - * \see NumericalProperty - * \tparam T The full class for which this specialized instance of PropertyDelegate is - * responsible. For example T = TemplateProperty. - */ -template -class PropertyDelegate { -public: - /** - * This method returns the class name for the class T. The default - * implementation will lead to a compile-time error if the class method is not - * specialized. - * \return The class name for the class T - */ - static std::string className(); - - /** - * This method will return the preferred default value for the class T. - * The default implementation will lead to a compile-time error if the class method is - * not specialized. - * \return The default value that the class T should use - * \tparam U The type by which the class T is specialized. If - * T = TemplateProperty, then U = std::string - */ - template - static U defaultValue(); - - /** - * This method will return the preferred default minimum value for the class - * T. The default implementation will lead to a compile-time error if the - * class method is not specialized. This method is not used in TemplateProperty, but - * only NumericalProperty, so the TemplateProperty does not require this method to be - * specialized. - * \return The default minimum value that the class T should use - * \tparam U The type by which the class T is specialized. If - * T = NumericalProperty, then U = int - */ - template - static U defaultMinimumValue(); - - /** - * This method will return the preferred default maximum value for the class - * T. The default implementation will lead to a compile-time error if the - * class method is not specialized. This method is not used in TemplateProperty, but - * only NumericalProperty, so the TemplateProperty does not require this method to be - * specialized. - * \return The default maximum value that the class T should use - * \tparam U The type by which the class T is specialized. If - * T = NumericalProperty, then U = int - */ - template - static U defaultMaximumValue(); - - /** - * The method returns the default stepping value for the class T used in - * GUI elements. The default implementation will lead to a compile-time error if the - * class method is not specialized. This method is not used in TemplateProperty, but - * only NumericalProperty, so the TemplateProperty does not require this method to be - * specialized. - * \return The default stepping that the class T should use - * \tparam U The type by which the class T is specialized. If - * T = NumericalProperty, then U = int - */ - template - static U defaultSteppingValue(); - - /** - * This method converts the top value from the Lua stack into a value of type - * U and reports the success back to the caller. The default - * implementation will lead to a compile-time error if the class method is not - * specialized. - * \param state The Lua state from which the value is retrieved - * \param success Will be true if the conversion succeeded; - * false otherwise - * \return The value that was created by converting the top value from the stack - * \tparam U The type by which the class T is specialized. If - * T = TemplateProperty, then U = std::string - */ - template - static U fromLuaValue(lua_State* state, bool& success); - - /** - * This method converts the passed value, encodes it and places it on the - * top value of the Lua stack and returns the success back to the caller. The default - * implementation will lead to a compile-time error if the class method is not - * specialized. - * \param state The Lua state from which the value is retrieved - * \param value The value that will be converted into a Lua object - * \return true if the conversion succeeded; false otherwise - * \tparam U The type by which the class T is specialized. If - * T = TemplateProperty, then U = std::string - */ - template - static bool toLuaValue(lua_State* state, const U& value); - - /** - * Returns the Lua type that will be put onto the stack in the - * PropertyDelegate::toLuaValue method and which will be consumed by the - * PropertyDelegate::fromLuaValue 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. The default implementation will lead to a compile-time - * error if the class method is not specialized. - * \return The Lua type that will be consumed or produced by the - * PropertyDelegate::toLuaValue and PropertyDelegate::fromLuaValue methods. - */ - static int typeLua(); - - template - static bool toString(std::string& outValue, const U& inValue); -}; - -} // namespace openspace::properties - -#include - -#endif // __OPENSPACE_CORE___PROPERTYDELEGATE___H__ diff --git a/include/openspace/properties/scalar/boolproperty.h b/include/openspace/properties/scalar/boolproperty.h index 71932957a0..56f08af1d3 100644 --- a/include/openspace/properties/scalar/boolproperty.h +++ b/include/openspace/properties/scalar/boolproperty.h @@ -44,7 +44,20 @@ namespace openspace::properties { -REGISTER_TEMPLATEPROPERTY_HEADER(BoolProperty, bool) +class BoolProperty : public TemplateProperty { +public: + BoolProperty(Property::PropertyInfo info, bool value = false); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + bool fromLuaConversion(lua_State* state, bool& success) const override; + void toLuaConversion(lua_State* state) const override; + std::string toStringConversion() const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/charproperty.h b/include/openspace/properties/scalar/charproperty.h deleted file mode 100644 index bce7e2b672..0000000000 --- a/include/openspace/properties/scalar/charproperty.h +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___CHARPROPERTY___H__ -#define __OPENSPACE_CORE___CHARPROPERTY___H__ - - /** - * \file charproperty.h - * - * \addtogroup openspace - * @{ - * \addtogroup properties - * @{ - - * \class CharProperty - * This class is a concrete implementation of openspace::properties::TemplateProperty with - * the type char. - - * @} @} - */ - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(CharProperty, char) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___CHARPROPERTY___H__ diff --git a/include/openspace/properties/scalar/doubleproperty.h b/include/openspace/properties/scalar/doubleproperty.h index f0ad097207..fce130ad3d 100644 --- a/include/openspace/properties/scalar/doubleproperty.h +++ b/include/openspace/properties/scalar/doubleproperty.h @@ -41,10 +41,24 @@ */ #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(DoubleProperty, double) +class DoubleProperty : public NumericalProperty { +public: + DoubleProperty(Property::PropertyInfo info, double value = 0.0, + double minValue = std::numeric_limits::lowest(), + double maxValue = std::numeric_limits::max(), double stepValue = 0.01); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + double fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/floatproperty.h b/include/openspace/properties/scalar/floatproperty.h index 5812c05179..2b965fd3a8 100644 --- a/include/openspace/properties/scalar/floatproperty.h +++ b/include/openspace/properties/scalar/floatproperty.h @@ -41,10 +41,24 @@ */ #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(FloatProperty, float) +class FloatProperty : public NumericalProperty { +public: + FloatProperty(Property::PropertyInfo info, float value = 0.f, + float minValue = std::numeric_limits::lowest(), + float maxValue = std::numeric_limits::max(), float stepValue = 0.01f); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + float fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/intproperty.h b/include/openspace/properties/scalar/intproperty.h index 06ea74f47d..33d9a66532 100644 --- a/include/openspace/properties/scalar/intproperty.h +++ b/include/openspace/properties/scalar/intproperty.h @@ -41,10 +41,24 @@ */ #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(IntProperty, int) +class IntProperty : public NumericalProperty { +public: + IntProperty(Property::PropertyInfo info, int value = 0, + int minValue = std::numeric_limits::lowest(), + int maxValue = std::numeric_limits::max(), int stepValue = 1); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + int fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/longdoubleproperty.h b/include/openspace/properties/scalar/longdoubleproperty.h deleted file mode 100644 index 065c80aff1..0000000000 --- a/include/openspace/properties/scalar/longdoubleproperty.h +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___LONGDOUBLEPROPERTY___H__ -#define __OPENSPACE_CORE___LONGDOUBLEPROPERTY___H__ - - /** - * \file longdoubleproperty.h - * - * \addtogroup openspace - * @{ - * \addtogroup properties - * @{ - - * \class LongDoubleProperty - * This class is a concrete implementation of openspace::properties::TemplateProperty with - * the type long double. - - * @} @} - */ - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(LongDoubleProperty, long double) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___LONGDOUBLEPROPERTY___H__ diff --git a/include/openspace/properties/scalar/longlongproperty.h b/include/openspace/properties/scalar/longlongproperty.h deleted file mode 100644 index f754ee2a33..0000000000 --- a/include/openspace/properties/scalar/longlongproperty.h +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___LONGLONGPROPERTY___H__ -#define __OPENSPACE_CORE___LONGLONGPROPERTY___H__ - - /** - * \file longlongproperty.h - * - * \addtogroup openspace - * @{ - * \addtogroup properties - * @{ - - * \class LongLongProperty - * This class is a concrete implementation of openspace::properties::TemplateProperty with - * the type long long. - - * @} @} - */ - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(LongLongProperty, long long) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___LONGLONGPROPERTY___H__ diff --git a/include/openspace/properties/scalar/longproperty.h b/include/openspace/properties/scalar/longproperty.h index b77efc39ea..80d8b3cfec 100644 --- a/include/openspace/properties/scalar/longproperty.h +++ b/include/openspace/properties/scalar/longproperty.h @@ -41,10 +41,25 @@ */ #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(LongProperty, long) +class LongProperty : public NumericalProperty { +public: + LongProperty(Property::PropertyInfo info, long value = long(0), + long minValue = std::numeric_limits::lowest(), + long maxValue = std::numeric_limits::max(), + long stepValue = long(1)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + long fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/shortproperty.h b/include/openspace/properties/scalar/shortproperty.h index 3bd3c5af9b..1848ad23fe 100644 --- a/include/openspace/properties/scalar/shortproperty.h +++ b/include/openspace/properties/scalar/shortproperty.h @@ -41,10 +41,25 @@ */ #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(ShortProperty, short) +class ShortProperty : public NumericalProperty { +public: + ShortProperty(Property::PropertyInfo info, short value = short(0), + short minValue = std::numeric_limits::lowest(), + short maxValue = std::numeric_limits::max(), + short stepValue = short(1)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + short fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/signedcharproperty.h b/include/openspace/properties/scalar/signedcharproperty.h deleted file mode 100644 index 6f177f1219..0000000000 --- a/include/openspace/properties/scalar/signedcharproperty.h +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___SIGNEDCHARPROPERTY___H__ -#define __OPENSPACE_CORE___SIGNEDCHARPROPERTY___H__ - - /** - * \file signedcharproperty.h - * - * \addtogroup openspace - * @{ - * \addtogroup properties - * @{ - - * \class SignedCharProperty - * This class is a concrete implementation of openspace::properties::TemplateProperty with - * the type signed char. - - * @} @} - */ - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(SignedCharProperty, signed char) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___SIGNEDCHARPROPERTY___H__ diff --git a/include/openspace/properties/scalar/ucharproperty.h b/include/openspace/properties/scalar/ucharproperty.h deleted file mode 100644 index 0e35a5c482..0000000000 --- a/include/openspace/properties/scalar/ucharproperty.h +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___UCHARPROPERTY___H__ -#define __OPENSPACE_CORE___UCHARPROPERTY___H__ - - /** - * \file ucharproperty.h - * - * \addtogroup openspace - * @{ - * \addtogroup properties - * @{ - - * \class UCharProperty - * This class is a concrete implementation of openspace::properties::TemplateProperty with - * the type unsigned char. - - * @} @} - */ - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(UCharProperty, unsigned char) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___UCHARPROPERTY___H__ diff --git a/include/openspace/properties/scalar/uintproperty.h b/include/openspace/properties/scalar/uintproperty.h index dcbc60ee57..e3fe6fefdb 100644 --- a/include/openspace/properties/scalar/uintproperty.h +++ b/include/openspace/properties/scalar/uintproperty.h @@ -41,10 +41,25 @@ */ #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(UIntProperty, unsigned int) +class UIntProperty : public NumericalProperty { +public: + UIntProperty(Property::PropertyInfo info, unsigned int value = 0, + unsigned int minValue = std::numeric_limits::lowest(), + unsigned int maxValue = std::numeric_limits::max(), + unsigned int stepValue = 1); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + unsigned int fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/ulonglongproperty.h b/include/openspace/properties/scalar/ulonglongproperty.h deleted file mode 100644 index 2adc241bd4..0000000000 --- a/include/openspace/properties/scalar/ulonglongproperty.h +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___ULONGLONGPROPERTY___H__ -#define __OPENSPACE_CORE___ULONGLONGPROPERTY___H__ - - /** - * \file ulonglongproperty.h - * - * \addtogroup openspace - * @{ - * \addtogroup properties - * @{ - - * \class ULongLongProperty - * This class is a concrete implementation of openspace::properties::TemplateProperty with - * the type unsigned long long. - - * @} @} - */ - -#include - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_HEADER(ULongLongProperty, unsigned long long) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___ULONGLONGPROPERTY___H__ diff --git a/include/openspace/properties/scalar/ulongproperty.h b/include/openspace/properties/scalar/ulongproperty.h index 862cce3e69..8df652485c 100644 --- a/include/openspace/properties/scalar/ulongproperty.h +++ b/include/openspace/properties/scalar/ulongproperty.h @@ -41,10 +41,25 @@ */ #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(ULongProperty, unsigned long) +class ULongProperty : public NumericalProperty { +public: + ULongProperty(Property::PropertyInfo info, unsigned long value = 0ul, + unsigned long minValue = std::numeric_limits::lowest(), + unsigned long maxValue = std::numeric_limits::max(), + unsigned long stepValue = 1ul); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + unsigned long fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/ushortproperty.h b/include/openspace/properties/scalar/ushortproperty.h index 5a166ddd98..700b1be5ab 100644 --- a/include/openspace/properties/scalar/ushortproperty.h +++ b/include/openspace/properties/scalar/ushortproperty.h @@ -41,10 +41,25 @@ */ #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(UShortProperty, unsigned short) +class UShortProperty : public NumericalProperty { +public: + UShortProperty(Property::PropertyInfo info, unsigned short value = 0, + unsigned short minValue = std::numeric_limits::lowest(), + unsigned short maxValue = std::numeric_limits::max(), + unsigned short stepValue = 1); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + unsigned short fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/scalar/wcharproperty.h b/include/openspace/properties/scalar/wcharproperty.h deleted file mode 100644 index 321067bd84..0000000000 --- a/include/openspace/properties/scalar/wcharproperty.h +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___WCHARPROPERTY___H__ -#define __OPENSPACE_CORE___WCHARPROPERTY___H__ - - /** - * \file wcharproperty.h - * - * \addtogroup openspace - * @{ - * \addtogroup properties - * @{ - - * \class WCharProperty - * This class is a concrete implementation of openspace::properties::TemplateProperty with - * the type wchar_t. - - * @} @} - */ - -#include - -namespace openspace::properties { - -//REGISTER_NUMERICALPROPERTY_HEADER(WCharProperty, wchar_t) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___WCHARPROPERTY___H__ diff --git a/include/openspace/properties/selectionproperty.h b/include/openspace/properties/selectionproperty.h index 9006ecc630..b17f580a52 100644 --- a/include/openspace/properties/selectionproperty.h +++ b/include/openspace/properties/selectionproperty.h @@ -37,6 +37,9 @@ class SelectionProperty : public TemplateProperty> { public: SelectionProperty(Property::PropertyInfo info); + std::string className() const override; + int typeLua() const override; + /** * This method sets the stored value to the provided value val. * If the value is different, the listeners are notified. It also removes any @@ -110,6 +113,13 @@ public: using TemplateProperty>::operator=; +protected: + std::set fromLuaConversion(lua_State* state, bool& success) const override; + + void toLuaConversion(lua_State* state) const override; + + std::string toStringConversion() const override; + private: void sortOptions(); bool removeInvalidKeys(std::set& keys); @@ -120,28 +130,6 @@ private: std::vector _options; }; -template <> -std::string PropertyDelegate>>::className(); - -template <> -template <> -std::set -PropertyDelegate>>::fromLuaValue(lua_State* state, - bool& success); - -template <> -template <> -bool PropertyDelegate>>::toLuaValue( - lua_State* state, const std::set& value); - -template <> -int PropertyDelegate>>::typeLua(); - -template <> -template <> -bool PropertyDelegate>>::toString( - std::string& outValue, const std::set& inValue); - } // namespace openspace::properties #endif // __OPENSPACE_CORE___SELECTIONPROPERTY___H__ diff --git a/include/openspace/properties/stringproperty.h b/include/openspace/properties/stringproperty.h index e869528c5b..d1a7b8dd7b 100644 --- a/include/openspace/properties/stringproperty.h +++ b/include/openspace/properties/stringproperty.h @@ -29,7 +29,20 @@ namespace openspace::properties { -REGISTER_TEMPLATEPROPERTY_HEADER(StringProperty, std::string) +class StringProperty : public TemplateProperty { +public: + StringProperty(Property::PropertyInfo info, std::string value = ""); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + std::string fromLuaConversion(lua_State* state, bool& success) const override; + void toLuaConversion(lua_State* state) const override; + std::string toStringConversion() const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/templateproperty.h b/include/openspace/properties/templateproperty.h index 81db5f3bff..a9ccd7a8b7 100644 --- a/include/openspace/properties/templateproperty.h +++ b/include/openspace/properties/templateproperty.h @@ -27,12 +27,10 @@ #include -#include - namespace openspace::properties { /** - * This concrete subclass of Property handles a single parameter value that is of type + * This subclass of Property handles a single parameter value that is of type * T. It provides all the necessary methods to automatically access the * value. One notable instantiation of this class is StringProperty, using * T = std::string while NumericalProperty is a templated subclass dealing @@ -40,16 +38,14 @@ namespace openspace::properties { * The accessor operator and assignment operators are overloaded, so that the * TemplateProperty can be used just in the same way as a regular member variable. In the * case that these cannot not be used inline, the Property::get method will work. - * The default value for the stored value of this TemplateProperty is retrieved via a call - * to the PropertyDelegate::defaultValue method, providing the template parameter - * T as argument. When a new TemplateProperty is required, that method needs - * to be specialized for the new type or a compile-time error will occur - * (See https://github.com/OpenSpace/OpenSpace/wiki/Concepts-Properties). + * + * Each instantiation of this class should provide a constructor that deals with the + * default value for that specific type T, so that a property can be + * created from just a Property::PropertyInfo object. * * \tparam T The type of value that is stored in this TemplateProperty * \see Property * \see NumericalProperty - * \see PropertyDelegate */ template class TemplateProperty : public Property { @@ -67,19 +63,15 @@ public: * \pre \p info.identifier must not be empty * \pre \p info.guiName must not be empty */ - TemplateProperty(Property::PropertyInfo info, - T value = PropertyDelegate>::template defaultValue()); + TemplateProperty(Property::PropertyInfo info, T value); /** - * Returns the class name for this TemplateProperty. The default implementation makes - * a call to the PropertyDelegate::className method with the template parameter - * T as argument. For this to work, that method needs to be specialized - * to return the correct class name for the new template parameter T, or a - * compile-time error will occur. + * Returns the class name for this TemplateProperty. This method has to be + * specialized for each new type. * * \return The class name for the TemplateProperty */ - virtual std::string className() const override; + virtual std::string className() const override = 0; /** * Returns the stored value packed into a ghoul::any object. @@ -108,41 +100,34 @@ public: /** * This method encodes the stored value into a Lua object and pushes that object onto - * the stack. The encoding is performed by calling PropertyDelegate::toLuaValue with - * the template parameter T as an argument. This method has to be - * specialized for each new type, or a compile-time error will occur. + * the stack. * * \param state The Lua state onto which the encoded object will be pushed * \return \c true if the encoding succeeded; \c false otherwise */ - bool getLuaValue(lua_State* state) const override; + virtual bool getLuaValue(lua_State* state) const override; /** - * Sets the value of this TemplateProperty by decoding the object at the top of the Lua - * stack and, if successful, assigning it using the Property::set method. The decoding - * is performed by calling the PropertyDelegate::fromLuaValue with the template - * parameter T as argument. If the decoding is successful, the new value - * is set, otherwise it remains unchanged. + * Sets the value of this TemplateProperty by decoding the object at the top of the + * stack and, if successful, assigning it using the Property::set method. If the + * decoding is successful, the new value is set, otherwise it remains unchanged. * * \param state The Lua state from which the value will be decoded * \return \c true if the decoding succeeded; \c false otherwise */ - bool setLuaValue(lua_State* state) override; + virtual bool setLuaValue(lua_State* state) override; /// \see Property::typeLua - int typeLua() const override; + virtual int typeLua() const override = 0; /** - * This method encodes the stored value into a std::string object. The encoding is - * performed by calling PropertyDelegate::toStringValue with the template parameter - * T as an argument. This method has to be specialized for each new - * type, or a compile-time error will occur. The resulting encoding must also be a - * valid JSON representation fo the property. + * This method encodes the stored value into a std::string object. The resulting + * encoding must also be a valid JSON representation fo the property. * * \param value The string object in which to store the resulting encoding * \return \c true if the encoding succeeded; \c false otherwise */ - bool getStringValue(std::string& value) const override; + virtual bool getStringValue(std::string& value) const override; /** * Returns the description for this TemplateProperty as a Lua script that returns a @@ -199,6 +184,33 @@ public: T value() const; protected: + /** + * Decodes the object at the top of the stack to a value of the type T + * and returns it. This method has to be specialized for each new type. + * + * \param state The Lua state from which the value will be decoded + * \param success Set to true \c true if the decoding succeeded; \c false otherwise + * \return the decoded value + */ + virtual T fromLuaConversion(lua_State* state, bool& success) const = 0; + + /** + * Encodes the stored value into a Lua object and pushes that object onto + * the stack. This method has to be specialized for each new type. + * + * \param state The Lua state onto which the encoded object will be pushed + */ + virtual void toLuaConversion(lua_State* state) const = 0; + + /** + * Encodes the stored value into a std::string object, in a format that is a valid + * JSON representation of the property. This method has to be specialized for each + * new type. + * + * \return The resulting encoding + */ + virtual std::string toStringConversion() const = 0; + /// The value that this TemplateProperty currently stores T _value; }; diff --git a/include/openspace/properties/templateproperty.inl b/include/openspace/properties/templateproperty.inl index 2dc21e7b30..f4508183ea 100644 --- a/include/openspace/properties/templateproperty.inl +++ b/include/openspace/properties/templateproperty.inl @@ -24,118 +24,12 @@ namespace openspace::properties { - // The following macros can be used to quickly generate the necessary PropertyDelegate - // specializations required by the TemplateProperty class. Use the - // REGISTER_TEMPLATEPROPERTY_HEADER macro in the header file and the - // REGISTER_TEMPLATEPROPERTY_SOURCE macro in the source file of your new - // specialization of a TemplateProperty - - - // CLASS_NAME = The string that the Property::className() should return as well as the - // C++ class name for which a typedef will be created - // TYPE = The template parameter T for which the TemplateProperty is specialized -#define REGISTER_TEMPLATEPROPERTY_HEADER(CLASS_NAME, TYPE) \ - using CLASS_NAME = TemplateProperty; \ - \ - 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, \ - const TYPE& value); \ - \ - template <> \ - int PropertyDelegate>::typeLua(); \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toString(std::string& outValue, \ - const 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 -// TYPE = The template parameter T for which the TemplateProperty is specialized -// DEFAULT_VALUE = The value (as type T) which should be used as a default value -// FROM_LUA_LAMBDA_EXPRESSION = A lambda expression receiving a lua_State* as the first -// parameter, a bool& as the second parameter and returning -// a value T. It is used by the fromLua method of -// TemplateProperty. The lambda expression must extract the -// stored value from the lua_State, return the value and -// report success in the second argument -// TO_LUA_LAMBDA_EXPRESSION = A lambda expression receiving a lua_State*, a value T and -// returning a bool. The lambda expression must encode the -// value T onto the lua_State stack and return the success -// LUA_TYPE = The Lua type that will be produced/consumed by the previous -// Lambda expressions -#define REGISTER_TEMPLATEPROPERTY_SOURCE(CLASS_NAME, TYPE, DEFAULT_VALUE, \ - FROM_LUA_LAMBDA_EXPRESSION, \ - TO_LUA_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, \ - bool& success) \ - { \ - return FROM_LUA_LAMBDA_EXPRESSION(state, success); \ - } \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toLuaValue(lua_State* state, \ - const TYPE& value) \ - { \ - return TO_LUA_LAMBDA_EXPRESSION(state, value); \ - } \ - \ - template <> \ - int PropertyDelegate>::typeLua() { \ - return LUA_TYPE; \ - } \ - \ - template <> \ - template <> \ - bool PropertyDelegate>::toString(std::string& outValue, \ - const TYPE& inValue) \ - { \ - return TO_STRING_LAMBDA_EXPRESSION(outValue, inValue); \ - } \ - - template TemplateProperty::TemplateProperty(Property::PropertyInfo info, T value) : Property(std::move(info)) , _value(std::move(value)) {} -template -std::string TemplateProperty::className() const { - return PropertyDelegate>::className(); -} - template TemplateProperty::operator T() { return _value; @@ -190,20 +84,14 @@ const std::type_info& TemplateProperty::type() const { template bool TemplateProperty::getLuaValue(lua_State* state) const { - bool success = PropertyDelegate>::template toLuaValue( - state, - _value - ); - return success; + toLuaConversion(state); + return true; } template bool TemplateProperty::setLuaValue(lua_State* state) { bool success = false; - T thisValue = PropertyDelegate>::template fromLuaValue( - state, - success - ); + T thisValue = fromLuaConversion(state, success); if (success) { set(std::any(thisValue)); } @@ -211,17 +99,9 @@ bool TemplateProperty::setLuaValue(lua_State* state) { } 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; +bool TemplateProperty::getStringValue(std::string& outValue) const { + outValue = toStringConversion(); + return true; } } // namespace openspace::properties diff --git a/include/openspace/properties/vector/bvec2property.h b/include/openspace/properties/vector/bvec2property.h deleted file mode 100644 index d830934a8d..0000000000 --- a/include/openspace/properties/vector/bvec2property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___BVEC2PROPERTY___H__ -#define __OPENSPACE_CORE___BVEC2PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_TEMPLATEPROPERTY_HEADER(BVec2Property, glm::bvec2) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___BVEC2PROPERTY___H__ diff --git a/include/openspace/properties/vector/bvec3property.h b/include/openspace/properties/vector/bvec3property.h deleted file mode 100644 index e800cd040e..0000000000 --- a/include/openspace/properties/vector/bvec3property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___BVEC3PROPERTY___H__ -#define __OPENSPACE_CORE___BVEC3PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_TEMPLATEPROPERTY_HEADER(BVec3Property, glm::bvec3) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___BVEC3PROPERTY___H__ diff --git a/include/openspace/properties/vector/bvec4property.h b/include/openspace/properties/vector/bvec4property.h deleted file mode 100644 index 9c007f8f42..0000000000 --- a/include/openspace/properties/vector/bvec4property.h +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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_CORE___BVEC4PROPERTY___H__ -#define __OPENSPACE_CORE___BVEC4PROPERTY___H__ - -#include - -#include - -namespace openspace::properties { - -REGISTER_TEMPLATEPROPERTY_HEADER(BVec4Property, glm::bvec4) - -} // namespace openspace::properties - -#endif // __OPENSPACE_CORE___BVEC4PROPERTY___H__ diff --git a/include/openspace/properties/vector/dvec2property.h b/include/openspace/properties/vector/dvec2property.h index a6d72d8e48..3234fead9e 100644 --- a/include/openspace/properties/vector/dvec2property.h +++ b/include/openspace/properties/vector/dvec2property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(DVec2Property, glm::dvec2) +class DVec2Property : public NumericalProperty { +public: + DVec2Property(Property::PropertyInfo info, glm::dvec2 value = glm::dvec2(0.0), + glm::dvec2 minValue = glm::dvec2(std::numeric_limits::lowest()), + glm::dvec2 maxValue = glm::dvec2(std::numeric_limits::max()), + glm::dvec2 stepValue = glm::dvec2(0.01)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::dvec2 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/dvec3property.h b/include/openspace/properties/vector/dvec3property.h index 782f1c63d2..0def50c6e1 100644 --- a/include/openspace/properties/vector/dvec3property.h +++ b/include/openspace/properties/vector/dvec3property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(DVec3Property, glm::dvec3) +class DVec3Property : public NumericalProperty { +public: + DVec3Property(Property::PropertyInfo info, glm::dvec3 value = glm::dvec3(0.0), + glm::dvec3 minValue = glm::dvec3(std::numeric_limits::lowest()), + glm::dvec3 maxValue = glm::dvec3(std::numeric_limits::max()), + glm::dvec3 stepValue = glm::dvec3(0.01)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::dvec3 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/dvec4property.h b/include/openspace/properties/vector/dvec4property.h index e4e85dc79d..42cd570e9e 100644 --- a/include/openspace/properties/vector/dvec4property.h +++ b/include/openspace/properties/vector/dvec4property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(DVec4Property, glm::dvec4) +class DVec4Property : public NumericalProperty { +public: + DVec4Property(Property::PropertyInfo info, glm::dvec4 value = glm::dvec4(0.0), + glm::dvec4 minValue = glm::dvec4(std::numeric_limits::lowest()), + glm::dvec4 maxValue = glm::dvec4(std::numeric_limits::max()), + glm::dvec4 stepValue = glm::dvec4(0.01)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::dvec4 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/ivec2property.h b/include/openspace/properties/vector/ivec2property.h index 720afa62e8..b2060baa22 100644 --- a/include/openspace/properties/vector/ivec2property.h +++ b/include/openspace/properties/vector/ivec2property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(IVec2Property, glm::ivec2) +class IVec2Property : public NumericalProperty { +public: + IVec2Property(Property::PropertyInfo info, glm::ivec2 value = glm::ivec2(0), + glm::ivec2 minValue = glm::ivec2(std::numeric_limits::lowest()), + glm::ivec2 maxValue = glm::ivec2(std::numeric_limits::max()), + glm::ivec2 stepValue = glm::ivec2(1)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::ivec2 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/ivec3property.h b/include/openspace/properties/vector/ivec3property.h index 0a68a8e7dd..3585592ac0 100644 --- a/include/openspace/properties/vector/ivec3property.h +++ b/include/openspace/properties/vector/ivec3property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(IVec3Property, glm::ivec3) +class IVec3Property : public NumericalProperty { +public: + IVec3Property(Property::PropertyInfo info, glm::ivec3 value = glm::ivec3(0), + glm::ivec3 minValue = glm::ivec3(std::numeric_limits::lowest()), + glm::ivec3 maxValue = glm::ivec3(std::numeric_limits::max()), + glm::ivec3 stepValue = glm::ivec3(1)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::ivec3 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/ivec4property.h b/include/openspace/properties/vector/ivec4property.h index 9e076f009d..392c456032 100644 --- a/include/openspace/properties/vector/ivec4property.h +++ b/include/openspace/properties/vector/ivec4property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(IVec4Property, glm::ivec4) +class IVec4Property : public NumericalProperty { +public: + IVec4Property(Property::PropertyInfo info, glm::ivec4 value = glm::ivec4(0), + glm::ivec4 minValue = glm::ivec4(std::numeric_limits::lowest()), + glm::ivec4 maxValue = glm::ivec4(std::numeric_limits::max()), + glm::ivec4 stepValue = glm::ivec4(1)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::ivec4 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/uvec2property.h b/include/openspace/properties/vector/uvec2property.h index cd8ee273e6..abcc240a7c 100644 --- a/include/openspace/properties/vector/uvec2property.h +++ b/include/openspace/properties/vector/uvec2property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(UVec2Property, glm::uvec2) +class UVec2Property : public NumericalProperty { +public: + UVec2Property(Property::PropertyInfo info, glm::uvec2 value = glm::uvec2(0), + glm::uvec2 minValue = glm::uvec2(std::numeric_limits::lowest()), + glm::uvec2 maxValue = glm::uvec2(std::numeric_limits::max()), + glm::uvec2 stepValue = glm::uvec2(1)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::uvec2 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/uvec3property.h b/include/openspace/properties/vector/uvec3property.h index a0cae39791..3f9037d39b 100644 --- a/include/openspace/properties/vector/uvec3property.h +++ b/include/openspace/properties/vector/uvec3property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(UVec3Property, glm::uvec3) +class UVec3Property : public NumericalProperty { +public: + UVec3Property(Property::PropertyInfo info, glm::uvec3 value = glm::uvec3(0), + glm::uvec3 minValue = glm::uvec3(std::numeric_limits::lowest()), + glm::uvec3 maxValue = glm::uvec3(std::numeric_limits::max()), + glm::uvec3 stepValue = glm::uvec3(1)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::uvec3 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/uvec4property.h b/include/openspace/properties/vector/uvec4property.h index 57111530a4..a83d5e1e4e 100644 --- a/include/openspace/properties/vector/uvec4property.h +++ b/include/openspace/properties/vector/uvec4property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(UVec4Property, glm::uvec4) +class UVec4Property : public NumericalProperty { +public: + UVec4Property(Property::PropertyInfo info, glm::uvec4 value = glm::uvec4(0), + glm::uvec4 minValue = glm::uvec4(std::numeric_limits::lowest()), + glm::uvec4 maxValue = glm::uvec4(std::numeric_limits::max()), + glm::uvec4 stepValue = glm::uvec4(1)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::uvec4 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/vec2property.h b/include/openspace/properties/vector/vec2property.h index e17bf88f99..f58647c4de 100644 --- a/include/openspace/properties/vector/vec2property.h +++ b/include/openspace/properties/vector/vec2property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(Vec2Property, glm::vec2) +class Vec2Property : public NumericalProperty { +public: + Vec2Property(Property::PropertyInfo info, glm::vec2 value = glm::vec2(0.f), + glm::vec2 minValue = glm::vec2(std::numeric_limits::lowest()), + glm::vec2 maxValue = glm::vec2(std::numeric_limits::max()), + glm::vec2 stepValue = glm::vec2(0.01f)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::vec2 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/vec3property.h b/include/openspace/properties/vector/vec3property.h index 902226eed3..663f61cd86 100644 --- a/include/openspace/properties/vector/vec3property.h +++ b/include/openspace/properties/vector/vec3property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(Vec3Property, glm::vec3) +class Vec3Property : public NumericalProperty { +public: + Vec3Property(Property::PropertyInfo info, glm::vec3 value = glm::vec3(0.f), + glm::vec3 minValue = glm::vec3(std::numeric_limits::lowest()), + glm::vec3 maxValue = glm::vec3(std::numeric_limits::max()), + glm::vec3 stepValue = glm::vec3(0.01f)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::vec3 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/include/openspace/properties/vector/vec4property.h b/include/openspace/properties/vector/vec4property.h index 35b5b4c6a6..ae8e467cfd 100644 --- a/include/openspace/properties/vector/vec4property.h +++ b/include/openspace/properties/vector/vec4property.h @@ -28,10 +28,25 @@ #include #include +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_HEADER(Vec4Property, glm::vec4) +class Vec4Property : public NumericalProperty { +public: + Vec4Property(Property::PropertyInfo info, glm::vec4 value = glm::vec4(0.f), + glm::vec4 minValue = glm::vec4(std::numeric_limits::lowest()), + glm::vec4 maxValue = glm::vec4(std::numeric_limits::max()), + glm::vec4 stepValue = glm::vec4(0.01f)); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + glm::vec4 fromLuaConversion(lua_State* state, bool& success) const override; +}; } // namespace openspace::properties diff --git a/src/properties/scalar/charproperty.cpp b/include/openspace/util/json_helper.h similarity index 62% rename from src/properties/scalar/charproperty.cpp rename to include/openspace/util/json_helper.h index f6cff94313..f5dafffdbc 100644 --- a/src/properties/scalar/charproperty.cpp +++ b/include/openspace/util/json_helper.h @@ -22,51 +22,47 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#ifndef __OPENSPACE_CORE___JSON_HELPER___H__ +#define __OPENSPACE_CORE___JSON_HELPER___H__ -#include +#include -#include -#include +namespace openspace { -namespace { +/** + * This function takes a \p text and escapes all necessary characters () that JSON + * does not want in its strings. + * \param text The text that is to be escaped + * \return The same text with all required characteres escaped + */ +std::string escapedJson(const std::string& text); -char fromLuaConversion(lua_State* state, bool& success) { - success = (lua_isnumber(state, -1) == 1); - if (success) { - char val = static_cast(lua_tonumber(state, -1)); - return val; - } - else { - return char(0); - } -} +/** + * This function takes a \p list of text and escapes all necessary characters () that + * JSON does not want in its strings. + * \param text The list of text that is to be escaped + * \return The same text with all required characteres escaped + */ +std::string escapedJson(const std::vector& list); -bool toLuaConversion(lua_State* state, char value) { - lua_pushnumber(state, static_cast(value)); - return true; -} +/** + * Convert the input value to a valid JSON formatted string. Nan and Inf values + * are not vald JSON and will be represented by 'null' + * \param d The value to format + * \return The resulting JSON formatted string + */ +std::string formatJsonNumber(double d); -bool toStringConversion(std::string& outValue, char inValue) { - outValue = std::to_string(inValue); - return true; -} +/** + * Convert the input value to a valid JSON formatted string + * \param value The value to be converted + * \return The resulting JSON formatted string + */ +template +std::string formatJson(T value); -} // namespace +} // namespace openspace -namespace openspace::properties { +#include "json_helper.inl" -REGISTER_NUMERICALPROPERTY_SOURCE( - CharProperty, - char, - char(0), - std::numeric_limits::lowest(), - std::numeric_limits::max(), - char(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - -} // namespace openspace::properties +#endif // __OPENSPACE_CORE___JSON_HELPER___H__ diff --git a/include/openspace/properties/propertydelegate.inl b/include/openspace/util/json_helper.inl similarity index 50% rename from include/openspace/properties/propertydelegate.inl rename to include/openspace/util/json_helper.inl index be419421cf..ce0fafec86 100644 --- a/include/openspace/properties/propertydelegate.inl +++ b/include/openspace/util/json_helper.inl @@ -22,73 +22,75 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include +#include +#include +#include -namespace openspace::properties { +namespace openspace { + +namespace internal { + +template +struct is_any : std::disjunction...> {}; template -std::string PropertyDelegate::className() { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::className specialization"); - return ""; +constexpr bool isGlmMatrix() { + return is_any::value; } template -template -U PropertyDelegate::defaultValue() { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::defaultValue specialization"); +constexpr bool isGlmVector() { + return is_any::value; } +} // namespace internal + template -template -U PropertyDelegate::defaultMinimumValue() { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::defaultMinimumValue specialization"); +std::string formatJson(T value) { + if constexpr (std::is_same_v) { + return value ? "true" : "false"; + } + else if constexpr (std::is_arithmetic_v) { + return formatJsonNumber(static_cast(value)); + } + else if constexpr (std::is_same_v) { + return escapedJson(value); + } + else if constexpr (std::is_same_v) { + return ghoul::formatJson(value); + } + else if constexpr (internal::isGlmVector()) { + std::string values; + for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { + values += std::to_string(value[i]) + ','; + } + values.pop_back(); + return fmt::format("[{}]", values); + } + else if constexpr (internal::isGlmMatrix()) { + std::string values; + for (glm::length_t i = 0; i < T::type::row_type::length(); ++i) { + for (glm::length_t j = 0; j < T::type::col_type::length(); ++j) { + values += std::to_string(value[i][j]) + ','; + } + } + values.pop_back(); + return fmt::format("[{}]", values); + } + else { + static_assert(sizeof(T) == 0, "JSON formatting of type T not implemented"); + } } -template -template -U PropertyDelegate::defaultMaximumValue() { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::defaultMaximumValue specialization"); -} - -template -template -U PropertyDelegate::defaultSteppingValue() { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::defaultSteppingValue specialization"); -} - -template -template -U PropertyDelegate::fromLuaValue(lua_State*, bool&) { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::fromLuaValue specialization"); -} - -template -template -bool PropertyDelegate::toLuaValue(lua_State*, const U&) { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::toLuaValue specialization"); - return false; -} - -template -int PropertyDelegate::typeLua() { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::luaType specialization"); - return 0; -} - -template -template -bool PropertyDelegate::toString(std::string&, const U&) { - static_assert(sizeof(T) == 0, - "Unimplemented PropertyDelegate::toString specialization"); - return false; -} - -} // namespace openspace::properties +} // namespace openspace diff --git a/modules/globebrowsing/src/timequantizer.cpp b/modules/globebrowsing/src/timequantizer.cpp index a931db8a23..5317be039e 100644 --- a/modules/globebrowsing/src/timequantizer.cpp +++ b/modules/globebrowsing/src/timequantizer.cpp @@ -335,8 +335,8 @@ TimeQuantizer::TimeQuantizer(std::string start, std::string end, : _start(start) , _timerange(std::move(start), std::move(end)) { - verifyStartTimeRestrictions(); _resolution = parseTimeResolutionStr(resolution); + verifyStartTimeRestrictions(); } double TimeQuantizer::parseTimeResolutionStr(const std::string& resolutionStr) { @@ -366,18 +366,36 @@ void TimeQuantizer::setStartEndRange(const std::string& start, const std::string void TimeQuantizer::setResolution(const std::string& resolutionString) { _resolution = parseTimeResolutionStr(resolutionString); + verifyStartTimeRestrictions(); } void TimeQuantizer::verifyStartTimeRestrictions() { - if (_start.day() < 1 || _start.day() > 28) { + //If monthly time resolution then restrict to 28 days so every month is consistent + unsigned int dayUpperLimit; + std::string helpfulDescription = "the selected month"; + if (_resolutionUnit == 'M') { + dayUpperLimit = 28; + helpfulDescription = "monthly increment"; + } + else if (_resolutionUnit == 'y') { + //Get month sizes using a fixed non-leap year + dayUpperLimit = monthSize(_start.month(), 2001); + helpfulDescription += " on a yearly increment"; + } + else { + dayUpperLimit = 31; + } + if (_start.day() < 1 || _start.day() > dayUpperLimit) { throw ghoul::RuntimeError(fmt::format( - "Invalid start day value of {} for day of month. Valid days are 1 - 28", - _start.day() + "Invalid start day value of {} for {}, valid days are 1 - {}", + _start.day(), + helpfulDescription, + dayUpperLimit )); } if (_start.hour() != 0 || _start.minute() != 0 || _start.second() != 0) { throw ghoul::RuntimeError(fmt::format( - "Invalid start time value of {}:{}:{}. Time must be 00:00:00", + "Invalid start time value of {}:{}:{}, time must be 00:00:00", _start.hour(), _start.minute(), _start.second() )); } diff --git a/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp b/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp index 147ce0c659..c70da5bfea 100644 --- a/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp @@ -133,7 +133,7 @@ namespace { "Clear Projection Buffer", "Remove all pending projections from the buffer" }; - + struct [[codegen::Dictionary(RenderablePlanetProjection)]] Parameters { // The geometry that is used for rendering this planet ghoul::Dictionary geometry [[codegen::reference("space_geometry_planet")]]; @@ -177,7 +177,7 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& , _addColorTexturePath(AddColorTextureInfo) , _heightMapTexturePaths(HeightTexturePathsInfo) , _addHeightMapTexturePath(AddHeightTextureInfo) - , _heightExaggeration(HeightExaggerationInfo, 1.f, 0.f, 1e6f, 1.f, 3.f) + , _heightExaggeration(HeightExaggerationInfo, 1.f, 0.f, 1e6f, 1.f) , _meridianShift(MeridianShiftInfo, false) , _ambientBrightness(AmbientBrightnessInfo, 0.075f, 0.f, 1.f) , _maxProjectionsPerFrame(MaxProjectionsPerFrameInfo, 1, 1, 64) @@ -220,8 +220,6 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& }); addProperty(_addColorTexturePath); - - _heightMapTexturePaths.addOption(0, NoImageText); _heightMapTexturePaths.onChange([this]() { _heightMapTextureDirty = true; }); addProperty(_heightMapTexturePaths); @@ -266,9 +264,10 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& addPropertySubOwner(_geometry.get()); addPropertySubOwner(_projectionComponent); + _heightExaggeration.setExponent(3.f); _heightExaggeration = p.heightExaggeration.value_or(_heightExaggeration); addProperty(_heightExaggeration); - + _maxProjectionsPerFrame = p.maxProjectionsPerFrame.value_or(_maxProjectionsPerFrame); addProperty(_maxProjectionsPerFrame); diff --git a/modules/volume/transferfunction.cpp b/modules/volume/transferfunction.cpp index 0539ec516c..4ed2bc7e4f 100644 --- a/modules/volume/transferfunction.cpp +++ b/modules/volume/transferfunction.cpp @@ -90,7 +90,7 @@ bool TransferFunction::setEnvelopesFromLua(lua_State* state) { return success; } -bool TransferFunction::envelopesToLua(lua_State* state) { +void TransferFunction::envelopesToLua(lua_State* state) const { lua_newtable(state); for (auto iter = _envelopes.begin(); iter != _envelopes.end(); ++iter) { lua_newtable(state); @@ -101,7 +101,6 @@ bool TransferFunction::envelopesToLua(lua_State* state) { ("[\"" + std::to_string(iter - _envelopes.begin() + 1) + "\"]").c_str() ); } - return true; } void TransferFunction::loadEnvelopesFromFile(const std::string& path) { diff --git a/modules/volume/transferfunction.h b/modules/volume/transferfunction.h index 0d574d9e4d..a356d14893 100644 --- a/modules/volume/transferfunction.h +++ b/modules/volume/transferfunction.h @@ -38,7 +38,7 @@ public: TransferFunction() = default; TransferFunction(const std::string& string); - bool envelopesToLua(lua_State* state); + void envelopesToLua(lua_State* state) const; bool setEnvelopesFromString(const std::string& s); bool setEnvelopesFromLua(lua_State* lua); diff --git a/modules/volume/transferfunctionproperty.cpp b/modules/volume/transferfunctionproperty.cpp index 83d8a3ff97..16d1a400c3 100644 --- a/modules/volume/transferfunctionproperty.cpp +++ b/modules/volume/transferfunctionproperty.cpp @@ -23,38 +23,37 @@ ****************************************************************************************/ #include - #include -namespace { +namespace openspace::properties { -openspace::volume::TransferFunction fromLuaConversion(lua_State* state, bool& success) { +TransferFunctionProperty::TransferFunctionProperty(Property::PropertyInfo info, + volume::TransferFunction value) + : TemplateProperty(std::move(info), value) +{} + +std::string TransferFunctionProperty::className() const { + return "TransferFunctionProperty"; +} + +int TransferFunctionProperty::typeLua() const { + return LUA_TTABLE; +} + +openspace::volume::TransferFunction +TransferFunctionProperty::fromLuaConversion(lua_State* state, bool& success) const +{ openspace::volume::TransferFunction tf; success = tf.setEnvelopesFromLua(state); return tf; } -bool toLuaConversion(lua_State* state, openspace::volume::TransferFunction value) { - return value.envelopesToLua(state); +void TransferFunctionProperty::toLuaConversion(lua_State* state) const { + _value.envelopesToLua(state); } -bool toStringConversion(std::string& outValue, - openspace::volume::TransferFunction inValue) -{ - outValue = inValue.serializedToString(); - return true; +std::string TransferFunctionProperty::toStringConversion() const { + return _value.serializedToString(); } -} // namespace - -namespace openspace::properties { - -REGISTER_TEMPLATEPROPERTY_SOURCE(TransferFunctionProperty, volume::TransferFunction, - volume::TransferFunction(), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - } // namespace openspace::properties diff --git a/modules/volume/transferfunctionproperty.h b/modules/volume/transferfunctionproperty.h index 85eaab4a89..ca0a690ea5 100644 --- a/modules/volume/transferfunctionproperty.h +++ b/modules/volume/transferfunctionproperty.h @@ -30,7 +30,22 @@ namespace openspace::properties { -REGISTER_TEMPLATEPROPERTY_HEADER(TransferFunctionProperty, volume::TransferFunction) +class TransferFunctionProperty : public TemplateProperty { +public: + TransferFunctionProperty(Property::PropertyInfo info, + volume::TransferFunction value = volume::TransferFunction()); + + std::string className() const override; + int typeLua() const override; + + using TemplateProperty::operator=; + +protected: + volume::TransferFunction fromLuaConversion(lua_State* state, + bool& success) const override; + void toLuaConversion(lua_State* state) const override; + std::string toStringConversion() const override; +}; } // namespace openspace::properties diff --git a/modules/webgui/webguimodule.cpp b/modules/webgui/webguimodule.cpp index 774e8b675d..ca16560677 100644 --- a/modules/webgui/webguimodule.cpp +++ b/modules/webgui/webguimodule.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/openspace.cfg b/openspace.cfg index 7f18243690..9805780f2d 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -219,7 +219,7 @@ ScreenshotUseDate = true BypassLauncher = false -- OnScreenTextScaling = "framebuffer" --- PerSceneCache = true +-- PerProfileCache = true -- DisableRenderingOnMaster = true -- DisableInGameConsole = true diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7eebd7de61..23d6ff8de2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,42 +81,20 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/properties/list/intlistproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/list/stringlistproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat2property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat2x3property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat2x4property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat3x2property.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat3property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat3x4property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat4x2property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat4x3property.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat4property.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat2property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat2x3property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat2x4property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat3x2property.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat3property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat3x4property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat4x2property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat4x3property.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrix/mat4property.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/boolproperty.cpp - ${OPENSPACE_BASE_DIR}/src/properties/scalar/charproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/doubleproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/floatproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/intproperty.cpp - ${OPENSPACE_BASE_DIR}/src/properties/scalar/longdoubleproperty.cpp - ${OPENSPACE_BASE_DIR}/src/properties/scalar/longlongproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/longproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/shortproperty.cpp - ${OPENSPACE_BASE_DIR}/src/properties/scalar/signedcharproperty.cpp - ${OPENSPACE_BASE_DIR}/src/properties/scalar/ucharproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/uintproperty.cpp - ${OPENSPACE_BASE_DIR}/src/properties/scalar/ulonglongproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/ulongproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/scalar/ushortproperty.cpp - ${OPENSPACE_BASE_DIR}/src/properties/scalar/wcharproperty.cpp - ${OPENSPACE_BASE_DIR}/src/properties/vector/bvec2property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/vector/bvec3property.cpp - ${OPENSPACE_BASE_DIR}/src/properties/vector/bvec4property.cpp ${OPENSPACE_BASE_DIR}/src/properties/vector/dvec2property.cpp ${OPENSPACE_BASE_DIR}/src/properties/vector/dvec3property.cpp ${OPENSPACE_BASE_DIR}/src/properties/vector/dvec4property.cpp @@ -178,6 +156,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/util/distanceconversion.cpp ${OPENSPACE_BASE_DIR}/src/util/factorymanager.cpp ${OPENSPACE_BASE_DIR}/src/util/httprequest.cpp + ${OPENSPACE_BASE_DIR}/src/util/json_helper.cpp ${OPENSPACE_BASE_DIR}/src/util/keys.cpp ${OPENSPACE_BASE_DIR}/src/util/openspacemodule.cpp ${OPENSPACE_BASE_DIR}/src/util/planegeometry.cpp @@ -268,8 +247,6 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/properties/numericalproperty.inl ${OPENSPACE_BASE_DIR}/include/openspace/properties/optionproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/propertydelegate.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/propertydelegate.inl ${OPENSPACE_BASE_DIR}/include/openspace/properties/propertyowner.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/selectionproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/stringproperty.h @@ -280,42 +257,20 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/properties/list/intlistproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/list/stringlistproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat2property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat2x3property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat2x4property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat3x2property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat3property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat3x4property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat4x2property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat4x3property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat4property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat2property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat2x3property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat2x4property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat3x2property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat3property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat3x4property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat4x2property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat4x3property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat4property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/boolproperty.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/charproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/doubleproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/floatproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/intproperty.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/longdoubleproperty.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/longlongproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/longproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/shortproperty.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/signedcharproperty.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/ucharproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/uintproperty.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/ulonglongproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/ulongproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/ushortproperty.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/wcharproperty.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/bvec2property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/bvec3property.h - ${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/bvec4property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/dvec2property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/dvec3property.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/dvec4property.h @@ -382,6 +337,8 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/util/factorymanager.inl ${OPENSPACE_BASE_DIR}/include/openspace/util/httprequest.h ${OPENSPACE_BASE_DIR}/include/openspace/util/job.h + ${OPENSPACE_BASE_DIR}/include/openspace/util/json_helper.h + ${OPENSPACE_BASE_DIR}/include/openspace/util/json_helper.inl ${OPENSPACE_BASE_DIR}/include/openspace/util/keys.h ${OPENSPACE_BASE_DIR}/include/openspace/util/memorymanager.h ${OPENSPACE_BASE_DIR}/include/openspace/util/mouse.h diff --git a/src/documentation/documentationengine.cpp b/src/documentation/documentationengine.cpp index 35edf1a73e..edbba70d3f 100644 --- a/src/documentation/documentationengine.cpp +++ b/src/documentation/documentationengine.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/src/documentation/documentationgenerator.cpp b/src/documentation/documentationgenerator.cpp index 8f7880a576..91963c2a01 100644 --- a/src/documentation/documentationgenerator.cpp +++ b/src/documentation/documentationgenerator.cpp @@ -58,66 +58,4 @@ std::string DocumentationGenerator::jsonName() { return _jsonName; } -std::string escapedJson(const std::vector& list) { - std::string jsonString; - jsonString += "["; - for (const std::string& text : list) { - jsonString += "\\\""; - for (const char& c : text) { - switch (c) { - case '\t': - jsonString += "\\t"; // Replace tab with \t. - break; - case '"': - jsonString += "\\\""; // Replace " with \". - break; - case '\\': - jsonString += "\\\\"; // Replace \ with \\. - break; - case '\n': - jsonString += "\\\\n"; // Replace newline with \n. - break; - case '\r': - jsonString += "\\r"; // Replace carriage return with \r. - break; - default: - jsonString += c; - } - } - jsonString += "\\\","; - } - if (jsonString.length() > 1) { - jsonString.pop_back(); - } - jsonString += "]"; - - return jsonString; -} - -std::string escapedJson(const std::string& text) { - std::string jsonString; - for (const char& c : text) { - switch (c) { - case '\t': - jsonString += "\\t"; // Replace tab with \t. - break; - case '"': - jsonString += "\\\""; // Replace " with \". - break; - case '\\': - jsonString += "\\\\"; // Replace \ with \\. - break; - case '\n': - jsonString += "\\\\n"; // Replace newline with \n. - break; - case '\r': - jsonString += "\\r"; // Replace carriage return with \r. - break; - default: - jsonString += c; - } - } - return jsonString; -} - } // namespace openspace diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index f063bded20..cf586ec77a 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -129,11 +129,11 @@ namespace { // shutting down. If ESC is pressed again in this time, the shutdown is aborted std::optional shutdownCountdown [[codegen::greater(0.0)]]; - // If this is set to 'true', the name of the scene will be appended to the cache + // If this is set to 'true', the name of the profile will be appended to the cache // directory, thus not reusing the same directory. This is useful in cases where - // the same instance of OpenSpace is run with multiple scenes, but the caches + // the same instance of OpenSpace is run with multiple profiles, but the caches // should be retained. This value defaults to 'false' - std::optional perSceneCache; + std::optional perProfileCache; enum class Scaling { Window [[codegen::key("window")]], @@ -388,7 +388,7 @@ void parseLuaState(Configuration& configuration) { throw ghoul::MissingCaseException(); } } - c.usePerSceneCache = p.perSceneCache.value_or(c.usePerSceneCache); + c.usePerProfileCache = p.perProfileCache.value_or(c.usePerProfileCache); c.isRenderingOnMasterDisabled = p.disableRenderingOnMaster.value_or(c.isRenderingOnMasterDisabled); c.globalRotation = p.globalRotation.value_or(c.globalRotation); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index c04c60f985..dcc7785866 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -190,9 +190,14 @@ void OpenSpaceEngine::initialize() { } std::string cacheFolder = absPath("${CACHE}"); - if (global::configuration->usePerSceneCache) { - std::string scene = global::configuration->asset; - cacheFolder += "-" + ghoul::filesystem::File(scene).baseName(); + if (global::configuration->usePerProfileCache) { + std::string profile = global::configuration->profile; + if (profile.empty()) { + throw ghoul::RuntimeError( + "Unexpected error: Configuration file profile was empty" + ); + } + cacheFolder = cacheFolder + "-" + profile; LINFO(fmt::format("Old cache: {}", absPath("${CACHE}"))); LINFO(fmt::format("New cache: {}", cacheFolder)); diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index b05c8641e7..d8428ffb8e 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -195,7 +196,8 @@ std::string KeybindingManager::generateJson() const { json << R"("script": ")" << escapedJson(p.second.command) << "\","; json << R"("remoteScripting": )" << (p.second.synchronization ? "true," : "false,"); - json << R"("documentation": ")" << escapedJson(p.second.documentation) << "\","; + json << R"("documentation": ")" + << escapedJson(p.second.documentation) << "\","; json << R"("name": ")" << escapedJson(p.second.name) << "\""; json << "}"; } diff --git a/src/properties/list/doublelistproperty.cpp b/src/properties/list/doublelistproperty.cpp index 7ec47234a8..2baee602c1 100644 --- a/src/properties/list/doublelistproperty.cpp +++ b/src/properties/list/doublelistproperty.cpp @@ -27,16 +27,30 @@ #include #include #include +#include #include -namespace { +namespace openspace::properties { -constexpr const char* _loggerCat = "DoubleListProperty"; +DoubleListProperty::DoubleListProperty(Property::PropertyInfo info, + std::vector values) + : ListProperty(std::move(info), std::move(values)) +{} -std::vector fromLuaConversion(lua_State* state, bool& success) { +std::string DoubleListProperty::className() const { + return "DoubleListProperty"; +} + +int DoubleListProperty::typeLua() const { + return LUA_TTABLE; +} + +std::vector DoubleListProperty::fromLuaConversion(lua_State* state, + bool& success) const +{ if (!lua_istable(state, -1)) { success = false; - LERROR("Conversion from Lua failed. The input was not a table"); + LERRORC(className(), "Conversion from Lua failed. The input was not a table"); return {}; } @@ -48,7 +62,8 @@ std::vector fromLuaConversion(lua_State* state, bool& success) { } else { success = false; - LERROR( + LERRORC( + className(), "Conversion from Lua failed. The input table contains non-number values" ); return {}; @@ -59,46 +74,21 @@ std::vector fromLuaConversion(lua_State* state, bool& success) { return result; } -bool toLuaConversion(lua_State* state, std::vector val) { - lua_createtable(state, static_cast(val.size()), 0); +void DoubleListProperty::toLuaConversion(lua_State* state) const { + lua_createtable(state, static_cast(_value.size()), 0); int i = 1; - for (int v : val) { - lua_pushinteger(state, i); - lua_pushinteger(state, v); + for (double v : _value) { + ghoul::lua::push(state, i); + ghoul::lua::push(state, v); lua_settable(state, -3); ++i; } - - return true; } -bool toStringConversion(std::string& outValue, const std::vector& inValue) { - nlohmann::json json(inValue); - outValue = json.dump(); - return true; +std::string DoubleListProperty::toStringConversion() const { + nlohmann::json json(_value); + return json.dump(); } -} // namespace - -namespace openspace::properties { - -DoubleListProperty::DoubleListProperty(Property::PropertyInfo info) - : ListProperty(std::move(info)) -{} - -DoubleListProperty::DoubleListProperty(Property::PropertyInfo info, std::vector values) - : ListProperty(std::move(info), std::move(values)) -{} - -REGISTER_TEMPLATEPROPERTY_SOURCE( - DoubleListProperty, - std::vector, - std::vector(), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - } // namespace openspace::properties diff --git a/src/properties/list/intlistproperty.cpp b/src/properties/list/intlistproperty.cpp index 9797b0925a..8423f18ec4 100644 --- a/src/properties/list/intlistproperty.cpp +++ b/src/properties/list/intlistproperty.cpp @@ -27,16 +27,29 @@ #include #include #include +#include #include -namespace { +namespace openspace::properties { -constexpr const char* _loggerCat = "IntListProperty"; +IntListProperty::IntListProperty(Property::PropertyInfo info, std::vector values) + : ListProperty(std::move(info), std::move(values)) +{} -std::vector fromLuaConversion(lua_State* state, bool& success) { +std::string IntListProperty::className() const { + return "IntListProperty"; +} + +int IntListProperty::typeLua() const { + return LUA_TTABLE; +} + +std::vector IntListProperty::fromLuaConversion(lua_State* state, + bool& success) const +{ if (!lua_istable(state, -1)) { success = false; - LERROR("Conversion from Lua failed. The input was not a table"); + LERRORC(className(), "Conversion from Lua failed. The input was not a table"); return {}; } @@ -48,7 +61,8 @@ std::vector fromLuaConversion(lua_State* state, bool& success) { } else { success = false; - LERROR( + LERRORC( + className(), "Conversion from Lua failed. The input table contains non-number values" ); return {}; @@ -59,46 +73,21 @@ std::vector fromLuaConversion(lua_State* state, bool& success) { return result; } -bool toLuaConversion(lua_State* state, std::vector val) { - lua_createtable(state, static_cast(val.size()), 0); +void IntListProperty::toLuaConversion(lua_State* state) const { + lua_createtable(state, static_cast(_value.size()), 0); int i = 1; - for (const int& v : val) { - lua_pushinteger(state, i); - lua_pushinteger(state, v); + for (int v : _value) { + ghoul::lua::push(state, i); + ghoul::lua::push(state, v); lua_settable(state, -3); ++i; } - - return true; } -bool toStringConversion(std::string& outValue, const std::vector& inValue) { - nlohmann::json json(inValue); - outValue = json.dump(); - return true; +std::string IntListProperty::toStringConversion() const { + nlohmann::json json(_value); + return json.dump(); } -} // namespace - -namespace openspace::properties { - -IntListProperty::IntListProperty(Property::PropertyInfo info) - : ListProperty(std::move(info)) -{} - -IntListProperty::IntListProperty(Property::PropertyInfo info, std::vector values) - : ListProperty(std::move(info), std::move(values)) -{} - -REGISTER_TEMPLATEPROPERTY_SOURCE( - IntListProperty, - std::vector, - std::vector(), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - } // namespace openspace::properties diff --git a/src/properties/list/stringlistproperty.cpp b/src/properties/list/stringlistproperty.cpp index d37e96552d..8fe753ee7d 100644 --- a/src/properties/list/stringlistproperty.cpp +++ b/src/properties/list/stringlistproperty.cpp @@ -27,18 +27,30 @@ #include #include #include +#include #include -namespace { - constexpr const char* _loggerCat = "IntListProperty"; -} // namespace +namespace openspace::properties { -namespace { +StringListProperty::StringListProperty(Property::PropertyInfo info, + std::vector values) + : ListProperty(std::move(info), std::move(values)) +{} -std::vector fromLuaConversion(lua_State* state, bool& success) { +std::string StringListProperty::className() const { + return "StringListProperty"; +} + +int StringListProperty::typeLua() const { + return LUA_TTABLE; +} + +std::vector StringListProperty::fromLuaConversion(lua_State* state, + bool& success) const +{ if (!lua_istable(state, -1)) { success = false; - LERROR("Conversion from Lua failed. The input was not a table"); + LERRORC(className(), "Conversion from Lua failed. The input was not a table"); return {}; } @@ -58,47 +70,21 @@ std::vector fromLuaConversion(lua_State* state, bool& success) { return result; } -bool toLuaConversion(lua_State* state, std::vector val) { - lua_createtable(state, static_cast(val.size()), 0); +void StringListProperty::toLuaConversion(lua_State* state) const { + lua_createtable(state, static_cast(_value.size()), 0); int i = 1; - for (const std::string& v : val) { - lua_pushinteger(state, i); - lua_pushstring(state, v.c_str()); + for (const std::string& v : _value) { + ghoul::lua::push(state, i); + ghoul::lua::push(state, v.c_str()); lua_settable(state, -3); ++i; } - - return true; } -bool toStringConversion(std::string& outValue, const std::vector& inValue) { - nlohmann::json json(inValue); - outValue = json.dump(); - return true; +std::string StringListProperty::toStringConversion() const { + nlohmann::json json(_value); + return json.dump(); } -} // namespace - -namespace openspace::properties { - -StringListProperty::StringListProperty(Property::PropertyInfo info) - : ListProperty(std::move(info)) -{} - -StringListProperty::StringListProperty(Property::PropertyInfo info, - std::vector values) - : ListProperty(std::move(info), std::move(values)) -{} - -REGISTER_TEMPLATEPROPERTY_SOURCE( - StringListProperty, - std::vector, - std::vector(), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - } // namespace openspace::properties diff --git a/src/properties/matrix/dmat2property.cpp b/src/properties/matrix/dmat2property.cpp index 289b224aee..130347e582 100644 --- a/src/properties/matrix/dmat2property.cpp +++ b/src/properties/matrix/dmat2property.cpp @@ -24,84 +24,33 @@ #include -#include - -#include -#include -#include - -namespace { - -glm::dmat2x2 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat2x2 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat2x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x2::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat2x2(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat2x2(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat2x2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat2x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x2::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat2x2 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat2x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x2::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace +#include +#include namespace openspace::properties { -using nl = std::numeric_limits; +DMat2Property::DMat2Property(Property::PropertyInfo info, glm::dmat2x2 value, + glm::dmat2x2 minValue, glm::dmat2x2 maxValue, + glm::dmat2x2 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat2Property, - glm::dmat2x2, - glm::dmat2x2(0.0), - glm::dmat2x2(nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()), - glm::dmat2x2(nl::max(), nl::max(), nl::max(), nl::max()), - glm::dmat2x2(0.01, 0.01, 0.01, 0.01), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +std::string DMat2Property::className() const { + return "DMat2Property"; +} + +int DMat2Property::typeLua() const { + return LUA_TTABLE; +} + +glm::dmat2x2 DMat2Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/matrix/dmat2x3property.cpp b/src/properties/matrix/dmat2x3property.cpp deleted file mode 100644 index ee4aff65fe..0000000000 --- a/src/properties/matrix/dmat2x3property.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::dmat2x3 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat2x3 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat2x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x3::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat2x3(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat2x3(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat2x3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat2x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x3::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat2x3 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat2x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x3::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat2x3Property, - glm::dmat2x3, - glm::dmat2x3(0.0), - glm::dmat2x3( - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest() - ), - glm::dmat2x3( - nl::max(), nl::max(), - nl::max(), nl::max(), - nl::max(), nl::max() - ), - glm::dmat2x3(0.01, 0.01, 0.01, 0.01, 0.01, 0.01), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/dmat2x4property.cpp b/src/properties/matrix/dmat2x4property.cpp deleted file mode 100644 index b2d911cd4f..0000000000 --- a/src/properties/matrix/dmat2x4property.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::dmat2x4 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat2x4 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat2x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x4::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat2x4(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat2x4(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat2x4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat2x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x4::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat2x4 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat2x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x4::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat2x4Property, - glm::dmat2x4, - glm::dmat2x4(0.0), - glm::dmat2x4( - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest() - ), - glm::dmat2x4( - nl::max(), nl::max(), - nl::max(), nl::max(), - nl::max(), nl::max(), - nl::max(), nl::max() - ), - glm::dmat2x4(0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/dmat3property.cpp b/src/properties/matrix/dmat3property.cpp index bd151314fa..b09c3f31fe 100644 --- a/src/properties/matrix/dmat3property.cpp +++ b/src/properties/matrix/dmat3property.cpp @@ -24,97 +24,33 @@ #include -#include - -#include -#include -#include - -namespace { - -glm::dmat3x3 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat3x3 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat3x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x3::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat3x3(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat3x3(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat3x3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat3x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x3::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat3x3 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat3x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat2x3::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - - -} // namespace +#include +#include namespace openspace::properties { -using nl = std::numeric_limits; +DMat3Property::DMat3Property(Property::PropertyInfo info, glm::dmat3x3 value, + glm::dmat3x3 minValue, glm::dmat3x3 maxValue, + glm::dmat3x3 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat3Property, - glm::dmat3x3, - glm::dmat3x3(0.0), - glm::dmat3x3( - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::dmat3x3( - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max() - ), - glm::dmat3x3( - 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01 - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +std::string DMat3Property::className() const { + return "DMat3Property"; +} + +int DMat3Property::typeLua() const { + return LUA_TTABLE; +} + +glm::dmat3x3 DMat3Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/matrix/dmat3x2property.cpp b/src/properties/matrix/dmat3x2property.cpp deleted file mode 100644 index c9396b997f..0000000000 --- a/src/properties/matrix/dmat3x2property.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::dmat3x2 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat3x2 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat3x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat3x2::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat3x2(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat3x2(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat3x2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat3x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat3x2::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat3x2 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat3x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat3x2::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat3x2Property, - glm::dmat3x2, - glm::dmat3x2(0.0), - glm::dmat3x2( - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::dmat3x2( - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max() - ), - glm::dmat3x2( - 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01 - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/dmat3x4property.cpp b/src/properties/matrix/dmat3x4property.cpp deleted file mode 100644 index d09a9380de..0000000000 --- a/src/properties/matrix/dmat3x4property.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::dmat3x4 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat3x4 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat3x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat3x4::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat3x4(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat3x4(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat3x4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat3x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat3x4::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat3x4 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat3x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat3x4::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat3x4Property, - glm::dmat3x4, - glm::dmat3x4(0.0), - glm::dmat3x4( - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::dmat3x4( - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max() - ), - glm::dmat3x4( - 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01 - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/dmat4property.cpp b/src/properties/matrix/dmat4property.cpp index 7056ce12ea..74c9dbaa9c 100644 --- a/src/properties/matrix/dmat4property.cpp +++ b/src/properties/matrix/dmat4property.cpp @@ -24,99 +24,33 @@ #include -#include - -#include -#include -#include - -namespace { - -glm::dmat4x4 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat4x4 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat4x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x4::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat4x4(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat4x4(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat4x4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat4x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x4::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat4x4 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat4x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x4::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace +#include +#include namespace openspace::properties { -using nl = std::numeric_limits; +DMat4Property::DMat4Property(Property::PropertyInfo info, glm::dmat4x4 value, + glm::dmat4x4 minValue, glm::dmat4x4 maxValue, + glm::dmat4x4 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat4Property, - glm::dmat4x4, - glm::dmat4x4(0.0), - glm::dmat4x4( - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::dmat4x4( - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max() - ), - glm::dmat4x4( - 0.01, 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, 0.01 - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +std::string DMat4Property::className() const { + return "DMat4Property"; +} + +int DMat4Property::typeLua() const { + return LUA_TTABLE; +} + +glm::dmat4x4 DMat4Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/matrix/dmat4x2property.cpp b/src/properties/matrix/dmat4x2property.cpp deleted file mode 100644 index 6c20123cbf..0000000000 --- a/src/properties/matrix/dmat4x2property.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::dmat4x2 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat4x2 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat4x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x2::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat4x2(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat4x2(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat4x2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat4x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x2::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat4x2 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat4x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x2::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat4x2Property, - glm::dmat4x2, - glm::dmat4x2(0.0), - glm::dmat4x2( - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::dmat4x2( - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max() - ), - glm::dmat4x2( - 0.01, 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, 0.01 - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/dmat4x3property.cpp b/src/properties/matrix/dmat4x3property.cpp deleted file mode 100644 index f63b80a109..0000000000 --- a/src/properties/matrix/dmat4x3property.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::dmat4x3 fromLuaConversion(lua_State* state, bool& success) { - glm::dmat4x3 result; - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat4x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x3::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dmat4x3(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dmat4x3(0.0); - } - else { - result[i][j] = lua_tonumber(state, -1); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dmat4x3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::dmat4x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x3::col_type::length(); ++j) { - lua_pushnumber(state, value[i][j]); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dmat4x3 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::dmat4x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::dmat4x3::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - DMat4x3Property, - glm::dmat4x3, - glm::dmat4x3(0.0), - glm::dmat4x3( - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::dmat4x3( - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max() - ), - glm::dmat4x3( - 0.01, 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, 0.01 - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/mat2property.cpp b/src/properties/matrix/mat2property.cpp index c5d23ba3fd..5fe3f35ca4 100644 --- a/src/properties/matrix/mat2property.cpp +++ b/src/properties/matrix/mat2property.cpp @@ -24,95 +24,33 @@ #include -#include - -#include -#include -#include - -namespace { - -glm::mat2x2 fromLuaConversion(lua_State* state, bool& success) { - glm::mat2x2 result = glm::mat2x2(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat2x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x2::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat2x2(1.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat2x2(1.f); - } - else { - result[i][j] = static_cast( - lua_tonumber(state, -1) - ); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat2x2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat2x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x2::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat2x2 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat2x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x2::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace +#include +#include namespace openspace::properties { -using nl = std::numeric_limits; +Mat2Property::Mat2Property(Property::PropertyInfo info, glm::mat2x2 value, + glm::mat2x2 minValue, glm::mat2x2 maxValue, + glm::mat2x2 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat2Property, - glm::mat2x2, - glm::mat2x2(1.f), - glm::mat2x2( - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest() - ), - glm::mat2x2( - nl::max(), nl::max(), - nl::max(), nl::max() - ), - glm::mat2x2( - 0.01f, 0.01f, - 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +std::string Mat2Property::className() const { + return "Mat2Property"; +} + +int Mat2Property::typeLua() const { + return LUA_TTABLE; +} + +glm::mat2x2 Mat2Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/matrix/mat2x3property.cpp b/src/properties/matrix/mat2x3property.cpp deleted file mode 100644 index c5d62e1bb1..0000000000 --- a/src/properties/matrix/mat2x3property.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -using std::numeric_limits; - -namespace { - -glm::mat2x3 fromLuaConversion(lua_State* state, bool& success) { - glm::mat2x3 result = glm::mat2x3(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat2x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x3::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat2x3(1.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat2x3(1.f); - } - else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat2x3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat2x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x3::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat2x3 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat2x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x3::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat2x3Property, - glm::mat2x3, - glm::mat2x3(1.f), - glm::mat2x3( - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest() - ), - glm::mat2x3( - nl::max(), nl::max(), - nl::max(), nl::max(), - nl::max(), nl::max() - ), - glm::mat2x3( - 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/mat2x4property.cpp b/src/properties/matrix/mat2x4property.cpp deleted file mode 100644 index eb8b9822e0..0000000000 --- a/src/properties/matrix/mat2x4property.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::mat2x4 fromLuaConversion(lua_State* state, bool& success) { - glm::mat2x4 result = glm::mat2x4(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat2x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x4::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat2x4(1.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat2x4(1.f); - } - else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat2x4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat2x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x4::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat2x4 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat2x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat2x4::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat2x4Property, - glm::mat2x4, - glm::mat2x4(1.f), - glm::mat2x4( - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest() - ), - glm::mat2x4( - nl::max(), nl::max(), - nl::max(), nl::max(), - nl::max(), nl::max(), - nl::max(), nl::max() - ), - glm::mat2x4( - 0.01f, 0.01f, - 0.01f, 0.01f, - 0.01f, 0.01f, - 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/mat3property.cpp b/src/properties/matrix/mat3property.cpp index 882e984892..8abb81811a 100644 --- a/src/properties/matrix/mat3property.cpp +++ b/src/properties/matrix/mat3property.cpp @@ -24,97 +24,33 @@ #include -#include - -#include -#include -#include - -namespace { - -glm::mat3x3 fromLuaConversion(lua_State* state, bool& success) { - glm::mat3x3 result = glm::mat3x3(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat3x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x3::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat3x3(1.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat3x3(1.f); - } - else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat3x3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat3x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x3::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat3x3 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat3x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x3::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace +#include +#include namespace openspace::properties { -using nl = std::numeric_limits; +Mat3Property::Mat3Property(Property::PropertyInfo info, glm::mat3x3 value, + glm::mat3x3 minValue, glm::mat3x3 maxValue, + glm::mat3x3 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat3Property, - glm::mat3x3, - glm::mat3x3(1.f), - glm::mat3x3( - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::mat3x3( - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max() - ), - glm::mat3x3( - 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +std::string Mat3Property::className() const { + return "Mat3Property"; +} + +int Mat3Property::typeLua() const { + return LUA_TTABLE; +} + +glm::mat3x3 Mat3Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/matrix/mat3x2property.cpp b/src/properties/matrix/mat3x2property.cpp deleted file mode 100644 index 7540181d7e..0000000000 --- a/src/properties/matrix/mat3x2property.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::mat3x2 fromLuaConversion(lua_State* state, bool& success) { - glm::mat3x2 result = glm::mat3x2(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat3x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x2::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat3x2(0.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat3x2(0.f); - } - else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat3x2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat3x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x2::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat3x2 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat3x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x2::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat3x2Property, - glm::mat3x2, - glm::mat3x2(1.f), - glm::mat3x2( - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::mat3x2( - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max() - ), - glm::mat3x2( - 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/mat3x4property.cpp b/src/properties/matrix/mat3x4property.cpp deleted file mode 100644 index 5b9f7240ef..0000000000 --- a/src/properties/matrix/mat3x4property.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::mat3x4 fromLuaConversion(lua_State* state, bool& success) { - glm::mat3x4 result = glm::mat3x4(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat3x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x4::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat3x4(1.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat3x4(1.f); - } - else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat3x4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat3x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x4::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat3x4 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat3x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat3x4::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat3x4Property, - glm::mat3x4, - glm::mat3x4(1.f), - glm::mat3x4( - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::mat3x4( - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max() - ), - glm::mat3x4( - 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/mat4property.cpp b/src/properties/matrix/mat4property.cpp index b7847e93a9..a4c17513e8 100644 --- a/src/properties/matrix/mat4property.cpp +++ b/src/properties/matrix/mat4property.cpp @@ -24,102 +24,33 @@ #include -#include - -#include -#include -#include - -using std::numeric_limits; - -namespace { - -glm::mat4x4 fromLuaConversion(lua_State* state, bool& success) { - glm::mat4x4 result = glm::mat4x4(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat4x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x4::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat4x4(1.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat4x4(1.f); - } - else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat4x4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat4x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x4::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat4x4 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat4x4::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x4::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace +#include +#include namespace openspace::properties { -using nl = std::numeric_limits; +Mat4Property::Mat4Property(Property::PropertyInfo info, glm::mat4x4 value, + glm::mat4x4 minValue, glm::mat4x4 maxValue, + glm::mat4x4 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat4Property, - glm::mat4x4, - glm::mat4x4(1.f), - glm::mat4x4( - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::mat4x4( - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max() - ), - glm::mat4x4( - 0.01f, 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +std::string Mat4Property::className() const { + return "Mat4Property"; +} + +int Mat4Property::typeLua() const { + return LUA_TTABLE; +} + +glm::mat4x4 Mat4Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/matrix/mat4x2property.cpp b/src/properties/matrix/mat4x2property.cpp deleted file mode 100644 index 372ff5a307..0000000000 --- a/src/properties/matrix/mat4x2property.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::mat4x2 fromLuaConversion(lua_State* state, bool& success) { - glm::mat4x2 result = glm::mat4x2(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat4x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x2::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat4x2(1.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat4x2(1.f); - } - else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat4x2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat4x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x2::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat4x2 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat4x2::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x2::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat4x2Property, - glm::mat4x2, - glm::mat4x2(1.f), - glm::mat4x2( - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::mat4x2( - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max() - ), - glm::mat4x2( - 0.01f, 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/matrix/mat4x3property.cpp b/src/properties/matrix/mat4x3property.cpp deleted file mode 100644 index 26b2504ca6..0000000000 --- a/src/properties/matrix/mat4x3property.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::mat4x3 fromLuaConversion(lua_State* state, bool& success) { - glm::mat4x3 result = glm::mat4x3(1.f); - lua_pushnil(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat4x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x3::col_type::length(); ++j) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::mat4x3(1.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::mat4x3(1.f); - } - else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - ++number; - } - } - } - // The last accessor argument and the table are still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::mat4x3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < glm::mat4x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x3::col_type::length(); ++j) { - lua_pushnumber(state, static_cast(value[i][j])); - lua_rawseti(state, -2, number); - ++number; - } - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::mat4x3 inValue) { - outValue = "["; - for (glm::length_t i = 0; i < glm::mat4x3::row_type::length(); ++i) { - for (glm::length_t j = 0; j < glm::mat4x3::col_type::length(); ++j) { - outValue += std::to_string(inValue[i][j]) + ","; - } - } - outValue.pop_back(); - outValue += "]"; - return true; -} - -} // namespace - -namespace openspace::properties { - -using nl = std::numeric_limits; - -REGISTER_NUMERICALPROPERTY_SOURCE( - Mat4x3Property, - glm::mat4x3, - glm::mat4x3(1.f), - glm::mat4x3( - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(), - nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest() - ), - glm::mat4x3( - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max(), - nl::max(), nl::max(), nl::max(), nl::max() - ), - glm::mat4x3( - 0.01f, 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, 0.01f, - 0.01f, 0.01f, 0.01f, 0.01f - ), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/property.cpp b/src/properties/property.cpp index 5985da3dc6..1863bdd262 100644 --- a/src/properties/property.cpp +++ b/src/properties/property.cpp @@ -23,6 +23,7 @@ ****************************************************************************************/ #include + #include #include #include diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index 6864b7c0b5..94c716e826 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -36,32 +37,6 @@ namespace { constexpr const char* _loggerCat = "PropertyOwner"; - std::string escapedJson(const std::string& text) { - std::string jsonString; - for (const char& c : text) { - switch (c) { - case '\t': - jsonString += "\\t"; // Replace tab with \t. - break; - case '"': - jsonString += "\\\""; // Replace " with \". - break; - case '\\': - jsonString += "\\\\"; // Replace \ with \\. - break; - case '\n': - jsonString += "\\\\n"; // Replace newline with \n. - break; - case '\r': - jsonString += "\\r"; // Replace carriage return with \r. - break; - default: - jsonString += c; - } - } - return jsonString; - } - void createJson(openspace::properties::PropertyOwner* owner, std::vector& buf) { ZoneScoped diff --git a/src/properties/scalar/boolproperty.cpp b/src/properties/scalar/boolproperty.cpp index 439d3800f3..913a13827c 100644 --- a/src/properties/scalar/boolproperty.cpp +++ b/src/properties/scalar/boolproperty.cpp @@ -25,44 +25,33 @@ #include #include - -#include -#include - -namespace { - -bool fromLuaConversion(lua_State* state, bool& success) { - success = (lua_isboolean(state, -1) == 1); - if (success) { - return lua_toboolean(state, -1) == 1; - } - else { - return false; - } -} - -bool toLuaConversion(lua_State* state, bool value) { - lua_pushboolean(state, value); - return true; -} - -bool toStringConversion(std::string& outValue, bool inValue) { - outValue = inValue ? "true" : "false"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_TEMPLATEPROPERTY_SOURCE( - BoolProperty, - bool, - false, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TBOOLEAN -) +BoolProperty::BoolProperty(Property::PropertyInfo info, bool value) + : TemplateProperty(std::move(info), value) +{} + +std::string BoolProperty::className() const { + return "BoolProperty"; +} + +int BoolProperty::typeLua() const { + return LUA_TBOOLEAN; +} + +bool BoolProperty::fromLuaConversion(lua_State* state, bool& success) const { + success = (lua_isboolean(state, -1) == 1); + return success ? (lua_toboolean(state, -1) == 1) : false; +} + +void BoolProperty::toLuaConversion(lua_State* state) const { + ghoul::lua::push(state, _value); +} + +std::string BoolProperty::toStringConversion() const { + return _value ? "true" : "false"; +} } // namespace openspace::properties diff --git a/src/properties/scalar/doubleproperty.cpp b/src/properties/scalar/doubleproperty.cpp index 6b1019350f..ecc7c74895 100644 --- a/src/properties/scalar/doubleproperty.cpp +++ b/src/properties/scalar/doubleproperty.cpp @@ -26,12 +26,22 @@ #include -#include -#include +namespace openspace::properties { -namespace { +DoubleProperty::DoubleProperty(Property::PropertyInfo info, double value, + double minValue, double maxValue, double stepValue) + : NumericalProperty(std::move(info), value, minValue, maxValue, stepValue) +{} -double fromLuaConversion(lua_State* state, bool& success) { +std::string DoubleProperty::className() const { + return "DoubleProperty"; +} + +int DoubleProperty::typeLua() const { + return LUA_TNUMBER; +} + +double DoubleProperty::fromLuaConversion(lua_State* state, bool& success) const { success = (lua_isnumber(state, -1) == 1); if (success) { double val = lua_tonumber(state, -1); @@ -42,31 +52,4 @@ double fromLuaConversion(lua_State* state, bool& success) { } } -bool toLuaConversion(lua_State* state, double value) { - lua_pushnumber(state, value); - return true; -} - -bool toStringConversion(std::string& outValue, double inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - DoubleProperty, - double, - 0.0, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 0.01, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - } // namespace openspace::properties diff --git a/src/properties/scalar/floatproperty.cpp b/src/properties/scalar/floatproperty.cpp index a0ca445300..b7804815d3 100644 --- a/src/properties/scalar/floatproperty.cpp +++ b/src/properties/scalar/floatproperty.cpp @@ -26,12 +26,22 @@ #include -#include -#include +namespace openspace::properties { -namespace { +FloatProperty::FloatProperty(Property::PropertyInfo info, float value, + float minValue, float maxValue, float stepValue) + : NumericalProperty(std::move(info), value, minValue, maxValue, stepValue) +{} -float fromLuaConversion(lua_State* state, bool& success) { +std::string FloatProperty::className() const { + return "FloatProperty"; +} + +int FloatProperty::typeLua() const { + return LUA_TNUMBER; +} + +float FloatProperty::fromLuaConversion(lua_State* state, bool& success) const { success = (lua_isnumber(state, -1) == 1); if (success) { float val = static_cast(lua_tonumber(state, -1)); @@ -42,31 +52,4 @@ float fromLuaConversion(lua_State* state, bool& success) { } } -bool toLuaConversion(lua_State* state, float value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, float inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - FloatProperty, - float, - 0.f, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 0.01f, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - } // namespace openspace::properties diff --git a/src/properties/scalar/intproperty.cpp b/src/properties/scalar/intproperty.cpp index 0a3b134e1b..b9bb055e13 100644 --- a/src/properties/scalar/intproperty.cpp +++ b/src/properties/scalar/intproperty.cpp @@ -26,12 +26,22 @@ #include -#include -#include +namespace openspace::properties { -namespace { +IntProperty::IntProperty(Property::PropertyInfo info, int value, + int minValue, int maxValue, int stepValue) + : NumericalProperty(std::move(info), value, minValue, maxValue, stepValue) +{} -int fromLuaConversion(lua_State* state, bool& success) { +std::string IntProperty::className() const { + return "IntProperty"; +} + +int IntProperty::typeLua() const { + return LUA_TNUMBER; +} + +int IntProperty::fromLuaConversion(lua_State* state, bool& success) const { success = (lua_isnumber(state, -1) == 1); if (success) { int val = static_cast(lua_tonumber(state, -1)); @@ -42,31 +52,4 @@ int fromLuaConversion(lua_State* state, bool& success) { } } -bool toLuaConversion(lua_State* state, int value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, int inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - IntProperty, - int, - 0, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 1, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - } // namespace openspace::properties diff --git a/src/properties/scalar/longlongproperty.cpp b/src/properties/scalar/longlongproperty.cpp deleted file mode 100644 index f734194f10..0000000000 --- a/src/properties/scalar/longlongproperty.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -long long fromLuaConversion(lua_State* state, bool& success) { - success = (lua_isnumber(state, -1) == 1); - if (success) { - long long val = static_cast(lua_tonumber(state, -1)); - return val; - } - else { - return 0; - } -} - -bool toLuaConversion(lua_State* state, long long value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, long long inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - LongLongProperty, - long long, - 0, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 1, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - -} // namespace openspace::properties diff --git a/src/properties/scalar/longproperty.cpp b/src/properties/scalar/longproperty.cpp index 128b1b7cc1..e3e3a5b07a 100644 --- a/src/properties/scalar/longproperty.cpp +++ b/src/properties/scalar/longproperty.cpp @@ -26,12 +26,22 @@ #include -#include -#include +namespace openspace::properties { -namespace { +LongProperty::LongProperty(Property::PropertyInfo info, long value, + long minValue, long maxValue, long stepValue) + : NumericalProperty(std::move(info), value, minValue, maxValue, stepValue) +{} -long fromLuaConversion(lua_State* state, bool& success) { +std::string LongProperty::className() const { + return "LongProperty"; +} + +int LongProperty::typeLua() const { + return LUA_TNUMBER; +} + +long LongProperty::fromLuaConversion(lua_State* state, bool& success) const { success = (lua_isnumber(state, -1) == 1); if (success) { long val = static_cast(lua_tonumber(state, -1)); @@ -42,31 +52,4 @@ long fromLuaConversion(lua_State* state, bool& success) { } } -bool toLuaConversion(lua_State* state, long value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, long inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - LongProperty, - long, - long(0), - std::numeric_limits::lowest(), - std::numeric_limits::max(), - long(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - } // namespace openspace::properties diff --git a/src/properties/scalar/shortproperty.cpp b/src/properties/scalar/shortproperty.cpp index 721de137d3..5069a3feab 100644 --- a/src/properties/scalar/shortproperty.cpp +++ b/src/properties/scalar/shortproperty.cpp @@ -26,12 +26,22 @@ #include -#include -#include +namespace openspace::properties { -namespace { +ShortProperty::ShortProperty(Property::PropertyInfo info, short value, short minValue, + short maxValue, short stepValue) + : NumericalProperty(std::move(info), value, minValue, maxValue, stepValue) +{} -short fromLuaConversion(lua_State* state, bool& success) { +std::string ShortProperty::className() const { + return "ShortProperty"; +} + +int ShortProperty::typeLua() const { + return LUA_TNUMBER; +} + +short ShortProperty::fromLuaConversion(lua_State* state, bool& success) const { success = (lua_isnumber(state, -1) == 1); if (success) { short val = static_cast(lua_tonumber(state, -1)); @@ -42,31 +52,4 @@ short fromLuaConversion(lua_State* state, bool& success) { } } -bool toLuaConversion(lua_State* state, short value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, short inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - ShortProperty, - short, - short(0), - std::numeric_limits::lowest(), - std::numeric_limits::max(), - short(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - } // namespace openspace::properties diff --git a/src/properties/scalar/ucharproperty.cpp b/src/properties/scalar/ucharproperty.cpp deleted file mode 100644 index 81430800ac..0000000000 --- a/src/properties/scalar/ucharproperty.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -unsigned char fromLuaConversion(lua_State* state, bool& success) { - success = (lua_isnumber(state, -1) == 1); - if (success) { - unsigned char val = static_cast(lua_tonumber(state, -1)); - return val; - } - else { - return 0; - } -} - -bool toLuaConversion(lua_State* state, unsigned char value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, unsigned char inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - UCharProperty, - unsigned char, - 0, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 1, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - -} // namespace openspace::properties diff --git a/src/properties/scalar/uintproperty.cpp b/src/properties/scalar/uintproperty.cpp index 87ce4145c3..496d17de9a 100644 --- a/src/properties/scalar/uintproperty.cpp +++ b/src/properties/scalar/uintproperty.cpp @@ -26,12 +26,29 @@ #include -#include -#include +namespace openspace::properties { -namespace { +UIntProperty::UIntProperty(Property::PropertyInfo info, unsigned int value, + unsigned int minValue, unsigned int maxValue, + unsigned int stepValue) + : NumericalProperty( + std::move(info), + value, + minValue, + maxValue, + stepValue + ) +{} -unsigned int fromLuaConversion(lua_State* state, bool& success) { +std::string UIntProperty::className() const { + return "UIntProperty"; +} + +int UIntProperty::typeLua() const { + return LUA_TNUMBER; +} + +unsigned int UIntProperty::fromLuaConversion(lua_State* state, bool& success) const { success = (lua_isnumber(state, -1) == 1); if (success) { unsigned int val = static_cast(lua_tonumber(state, -1)); @@ -42,31 +59,4 @@ unsigned int fromLuaConversion(lua_State* state, bool& success) { } } -bool toLuaConversion(lua_State* state, unsigned int value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, unsigned int inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - UCharProperty, - unsigned int, - 0, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 1, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - } // namespace openspace::properties diff --git a/src/properties/scalar/ulonglongproperty.cpp b/src/properties/scalar/ulonglongproperty.cpp deleted file mode 100644 index 012a479a18..0000000000 --- a/src/properties/scalar/ulonglongproperty.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -unsigned long long fromLuaConversion(lua_State* state, bool& success) { - success = (lua_isnumber(state, -1) == 1); - if (success) { - unsigned long long val = static_cast(lua_tonumber(state, -1)); - return val; - } - else { - return 0ull; - } -} - -bool toLuaConversion(lua_State* state, unsigned long long value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, unsigned long long inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - ULongLongProperty, - unsigned long long, - 1ull, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 1ull, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - -} // namespace openspace::properties diff --git a/src/properties/scalar/ulongproperty.cpp b/src/properties/scalar/ulongproperty.cpp index 23eed4aec8..545d022aae 100644 --- a/src/properties/scalar/ulongproperty.cpp +++ b/src/properties/scalar/ulongproperty.cpp @@ -26,12 +26,29 @@ #include -#include -#include +namespace openspace::properties { -namespace { +ULongProperty::ULongProperty(Property::PropertyInfo info, unsigned long value, + unsigned long minValue, unsigned long maxValue, + unsigned long stepValue) + : NumericalProperty( + std::move(info), + value, + minValue, + maxValue, + stepValue + ) +{} -unsigned long fromLuaConversion(lua_State* state, bool& success) { +std::string ULongProperty::className() const { + return "ULongProperty"; +} + +int ULongProperty::typeLua() const { + return LUA_TNUMBER; +} + +unsigned long ULongProperty::fromLuaConversion(lua_State* state, bool& success) const { success = (lua_isnumber(state, -1) == 1); if (success) { unsigned long val = static_cast(lua_tonumber(state, -1)); @@ -42,31 +59,4 @@ unsigned long fromLuaConversion(lua_State* state, bool& success) { } } -bool toLuaConversion(lua_State* state, unsigned long value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, unsigned long inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - ULongProperty, - unsigned long, - 0ul, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 1ul, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - } // namespace openspace::properties diff --git a/src/properties/scalar/ushortproperty.cpp b/src/properties/scalar/ushortproperty.cpp index 1f4d97e183..7a54c1f0ea 100644 --- a/src/properties/scalar/ushortproperty.cpp +++ b/src/properties/scalar/ushortproperty.cpp @@ -26,12 +26,29 @@ #include -#include -#include +namespace openspace::properties { -namespace { +UShortProperty::UShortProperty(Property::PropertyInfo info, unsigned short value, + unsigned short minValue, unsigned short maxValue, + unsigned short stepValue) + : NumericalProperty( + std::move(info), + value, + minValue, + maxValue, + stepValue + ) +{} -unsigned short fromLuaConversion(lua_State* state, bool& success) { +std::string UShortProperty::className() const { + return "UShortProperty"; +} + +int UShortProperty::typeLua() const { + return LUA_TNUMBER; +} + +unsigned short UShortProperty::fromLuaConversion(lua_State* state, bool& success) const { success = (lua_isnumber(state, -1) == 1); if (success) { unsigned short val = static_cast(lua_tonumber(state, -1)); @@ -42,31 +59,4 @@ unsigned short fromLuaConversion(lua_State* state, bool& success) { } } -bool toLuaConversion(lua_State* state, unsigned short value) { - lua_pushnumber(state, static_cast(value)); - return true; -} - -bool toStringConversion(std::string& outValue, unsigned short inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - UShortProperty, - unsigned short, - 0, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 1, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - } // namespace openspace::properties diff --git a/src/properties/scalar/wcharproperty.cpp b/src/properties/scalar/wcharproperty.cpp deleted file mode 100644 index 73964f3896..0000000000 --- a/src/properties/scalar/wcharproperty.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace openspace::properties { - -int _StubToPreventLinkerWarningAboutMissingExportSymbols; - -// #define DEFAULT_FROM_LUA_LAMBDA(wchar_t, DEFAULT_VALUE) -// [](lua_State* state, bool& success) -> wchar_t { -// success = (lua_isnumber(state, -1) == 1); -// if (success) { -// return static_cast(lua_tonumber(state, -1)); -// } -// else { -// return DEFAULT_VALUE; -// } -// } - -// #define DEFAULT_TO_LUA_LAMBDA(wchar_t) -// [](lua_State* state, wchar_t value) -> bool { -// lua_pushnumber(state, static_cast(value)); -// return true; -// } - -// #define DEFAULT_FROM_STRING_LAMBDA(wchar_t, DEFAULT_VALUE) -// [](std::string val, bool& success) -> wchar_t { -// std::stringstream s(val); -// wchar_t v; -// s >> v; -// success = !s.fail(); -// if (success) { -// return v; -// } -// } - -//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); - -} // namespace openspace::properties diff --git a/src/properties/selectionproperty.cpp b/src/properties/selectionproperty.cpp index d80d48a345..1e1e37d180 100644 --- a/src/properties/selectionproperty.cpp +++ b/src/properties/selectionproperty.cpp @@ -43,6 +43,14 @@ SelectionProperty::SelectionProperty(Property::PropertyInfo info) : TemplateProperty(std::move(info), std::set()) {} +std::string SelectionProperty::className() const { + return "SelectionProperty"; +} + +int SelectionProperty::typeLua() const { + return LUA_TTABLE; +} + void SelectionProperty::setValue(std::set val) { ghoul_assert(!_options.empty(), "Cannot set selection before options have been set"); @@ -76,18 +84,18 @@ const std::vector& SelectionProperty::options() const { } void SelectionProperty::setOptions(const std::vector& keys) { - std::vector options; - options.reserve(keys.size()); + _options.clear(); + _options.reserve(keys.size()); for (const std::string& key : keys) { if (!hasOption(key)) { - options.push_back(key); + _options.push_back(key); } else { LWARNING(fmt::format("Ignoring duplicated key '{}'", key)); } } - _options = std::move(options); + _options.shrink_to_fit(); sortOptions(); // In case we have a selection, remove non-existing options @@ -121,44 +129,8 @@ void SelectionProperty::clearOptions() { clearSelection(); } -void SelectionProperty::sortOptions() { - std::sort(_options.begin(), _options.end()); -} - -bool SelectionProperty::removeInvalidKeys(std::set& keys) { - bool changed = false; - std::set::iterator it = keys.begin(); - while (it != keys.end()) { - if (!hasOption(*it)) { - LWARNING(fmt::format( - "Key '{}' is not a valid option and is removed from selection", *it - )); - keys.erase(it); - changed = true; - } - it++; - } - return changed; -} - -std::string SelectionProperty::generateAdditionalJsonDescription() const { - nlohmann::json optionsJson(_options); - std::string result = "{ "; - result += fmt::format("\"{}\": {}", OptionsKey, optionsJson.dump()); - result += " }"; - return result; -} - -template <> -std::string PropertyDelegate>>::className() { - return "SelectionProperty"; -} - -template <> -template <> -std::set -PropertyDelegate>>::fromLuaValue( - lua_State* state, bool& success) +std::set SelectionProperty::fromLuaConversion(lua_State* state, + bool& success) const { static const int KEY = -2; static const int VAL = -1; @@ -186,35 +158,50 @@ PropertyDelegate>>::fromLuaValue( return result; } -template <> -template <> -bool PropertyDelegate>>::toLuaValue( - lua_State* state, const std::set& value) -{ +void SelectionProperty::toLuaConversion(lua_State* state) const { lua_newtable(state); int i = 1; - for (const std::string& v : value) { + for (const std::string& v : _value) { lua_pushinteger(state, i); lua_pushstring(state, v.c_str()); lua_settable(state, -3); ++i; } - return true; } -template <> -int PropertyDelegate>>::typeLua() { - return LUA_TTABLE; +std::string SelectionProperty::toStringConversion() const { + nlohmann::json json(_value); + return json.dump(); } -template <> -template <> -bool PropertyDelegate>>::toString( - std::string& outValue, const std::set& inValue) -{ - nlohmann::json json(inValue); - outValue = json.dump(); - return true; +void SelectionProperty::sortOptions() { + std::sort(_options.begin(), _options.end()); +} + +bool SelectionProperty::removeInvalidKeys(std::set& keys) { + bool changed = false; + std::set::iterator it = keys.begin(); + while (it != keys.end()) { + if (!hasOption(*it)) { + LWARNING(fmt::format( + "Key '{}' is not a valid option and is removed from selection", *it + )); + it = keys.erase(it); + changed = true; + } + else { + it++; + } + } + return changed; +} + +std::string SelectionProperty::generateAdditionalJsonDescription() const { + nlohmann::json optionsJson(_options); + std::string result = "{ "; + result += fmt::format("\"{}\": {}", OptionsKey, optionsJson.dump()); + result += " }"; + return result; } } // namespace openspace::properties diff --git a/src/properties/stringproperty.cpp b/src/properties/stringproperty.cpp index c49ad3b311..53a90ce242 100644 --- a/src/properties/stringproperty.cpp +++ b/src/properties/stringproperty.cpp @@ -25,44 +25,36 @@ #include #include +#include #include -namespace { - -std::string fromLuaConversion(lua_State* state, bool& success) { - success = lua_isstring(state, -1) == 1; - if (success) { - return lua_tostring(state, -1); - } - else { - return ""; - } -} - -bool toLuaConversion(lua_State* state, const std::string& val) { - lua_pushstring(state, val.c_str()); - return true; -} - -bool toStringConversion(std::string& outValue, std::string inValue) { - nlohmann::json json; - nlohmann::to_json(json, inValue); - outValue = json.dump(); - return true; -} - -} // namespace - namespace openspace::properties { -REGISTER_TEMPLATEPROPERTY_SOURCE( - StringProperty, - std::string, - "", - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TSTRING -) +StringProperty::StringProperty(Property::PropertyInfo info, std::string value) + : TemplateProperty(info, value) +{} + +std::string StringProperty::className() const { + return "StringProperty"; +} + +int StringProperty::typeLua() const { + return LUA_TSTRING; +} + +std::string StringProperty::fromLuaConversion(lua_State* state, bool& success) const { + success = lua_isstring(state, -1) == 1; + return success ? lua_tostring(state, -1) : ""; +} + +void StringProperty::toLuaConversion(lua_State* state) const { + ghoul::lua::push(state, _value); +} + +std::string StringProperty::toStringConversion() const { + nlohmann::json json; + nlohmann::to_json(json, _value); + return json.dump(); +} } // namespace openspace::properties diff --git a/src/properties/vector/bvec2property.cpp b/src/properties/vector/bvec2property.cpp deleted file mode 100644 index 36e4d3cb97..0000000000 --- a/src/properties/vector/bvec2property.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::bvec2 fromLuaConversion(lua_State* state, bool& success) { - glm::bvec2 result = glm::bvec2(false); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::bvec2(false); - } - if (lua_isboolean(state, -1) != 1) { - success = false; - return glm::bvec2(false); - } - else { - result[i] = static_cast(lua_toboolean(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::bvec2 val) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(val[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::bvec2 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_TEMPLATEPROPERTY_SOURCE( - BVec2Property, - glm::bvec2, - glm::bvec2(false), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/vector/bvec3property.cpp b/src/properties/vector/bvec3property.cpp deleted file mode 100644 index 3f88e952ab..0000000000 --- a/src/properties/vector/bvec3property.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::bvec3 fromLuaConversion(lua_State* state, bool& success) { - glm::bvec3 result = glm::bvec3(false); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::bvec3(false); - } - if (lua_isboolean(state, -1) != 1) { - success = false; - return glm::bvec3(false); - } - else { - result[i] = static_cast(lua_toboolean(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::bvec3 val) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(val[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::bvec3 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_TEMPLATEPROPERTY_SOURCE( - BVec3Property, - glm::bvec3, - glm::bvec3(false), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/vector/bvec4property.cpp b/src/properties/vector/bvec4property.cpp deleted file mode 100644 index 757627580a..0000000000 --- a/src/properties/vector/bvec4property.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 - -namespace { - -glm::bvec4 fromLuaConversion(lua_State* state, bool& success) { - glm::bvec4 result = glm::bvec4(false); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::bvec4(false); - } - if (lua_isboolean(state, -1) != 1) { - success = false; - return glm::bvec4(false); - } - else { - result[i] = static_cast(lua_toboolean(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::bvec4 val) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(val[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::bvec4 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_TEMPLATEPROPERTY_SOURCE( - BVec4Property, - glm::bvec4, - glm::bvec4(false), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) - -} // namespace openspace::properties diff --git a/src/properties/vector/dvec2property.cpp b/src/properties/vector/dvec2property.cpp index 8425840430..132a94985f 100644 --- a/src/properties/vector/dvec2property.cpp +++ b/src/properties/vector/dvec2property.cpp @@ -25,74 +25,32 @@ #include #include -#include -#include -#include -#include - -namespace { - -glm::dvec2 fromLuaConversion(lua_State* state, bool& success) { - glm::dvec2 result = glm::dvec2(0.0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dvec2(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dvec2(0.0); - } - else { - result[i] = lua_tonumber(state, -1); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dvec2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, value[i]); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dvec2 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - DVec2Property, - glm::dvec2, - glm::dvec2(0.0), - glm::dvec2(std::numeric_limits::lowest()), - glm::dvec2(std::numeric_limits::max()), - glm::dvec2(0.01), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +DVec2Property::DVec2Property(Property::PropertyInfo info, glm::dvec2 value, + glm::dvec2 minValue, glm::dvec2 maxValue, + glm::dvec2 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string DVec2Property::className() const { + return "DVec2Property"; +} + +int DVec2Property::typeLua() const { + return LUA_TTABLE; +} + +glm::dvec2 DVec2Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/dvec3property.cpp b/src/properties/vector/dvec3property.cpp index e97b87a7a4..4937c8d39e 100644 --- a/src/properties/vector/dvec3property.cpp +++ b/src/properties/vector/dvec3property.cpp @@ -24,75 +24,33 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::dvec3 fromLuaConversion(lua_State* state, bool& success) { - glm::dvec3 result = glm::dvec3(0.0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dvec3(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dvec3(0.0); - } - else { - result[i] = lua_tonumber(state, -1); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dvec3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, value[i]); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dvec3 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - DVec3Property, - glm::dvec3, - glm::dvec3(0.0), - glm::dvec3(std::numeric_limits::lowest()), - glm::dvec3(std::numeric_limits::max()), - glm::dvec3(0.01), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +DVec3Property::DVec3Property(Property::PropertyInfo info, glm::dvec3 value, + glm::dvec3 minValue, glm::dvec3 maxValue, + glm::dvec3 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string DVec3Property::className() const { + return "DVec3Property"; +} + +int DVec3Property::typeLua() const { + return LUA_TTABLE; +} + +glm::dvec3 DVec3Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/dvec4property.cpp b/src/properties/vector/dvec4property.cpp index 0fdbe9f3e3..31119da29d 100644 --- a/src/properties/vector/dvec4property.cpp +++ b/src/properties/vector/dvec4property.cpp @@ -24,75 +24,33 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::dvec4 fromLuaConversion(lua_State* state, bool& success) { - glm::dvec4 result = glm::dvec4(0.0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::dvec4(0.0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::dvec4(0.0); - } - else { - result[i] = lua_tonumber(state, -1); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::dvec4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, value[i]); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::dvec4 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - DVec4Property, - glm::dvec4, - glm::dvec4(0.0), - glm::dvec4(std::numeric_limits::lowest()), - glm::dvec4(std::numeric_limits::max()), - glm::dvec4(0.01), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +DVec4Property::DVec4Property(Property::PropertyInfo info, glm::dvec4 value, + glm::dvec4 minValue, glm::dvec4 maxValue, + glm::dvec4 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string DVec4Property::className() const { + return "DVec4Property"; +} + +int DVec4Property::typeLua() const { + return LUA_TTABLE; +} + +glm::dvec4 DVec4Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/ivec2property.cpp b/src/properties/vector/ivec2property.cpp index 42296a1d9f..851f2fb8d0 100644 --- a/src/properties/vector/ivec2property.cpp +++ b/src/properties/vector/ivec2property.cpp @@ -24,75 +24,33 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::ivec2 fromLuaConversion(lua_State* state, bool& success) { - glm::ivec2 result = glm::ivec2(0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::ivec2(0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::ivec2(0); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::ivec2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::ivec2 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - IVec2Property, - glm::ivec2, - glm::ivec2(0), - glm::ivec2(std::numeric_limits::lowest()), - glm::ivec2(std::numeric_limits::max()), - glm::ivec2(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +IVec2Property::IVec2Property(Property::PropertyInfo info, glm::ivec2 value, + glm::ivec2 minValue, glm::ivec2 maxValue, + glm::ivec2 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string IVec2Property::className() const { + return "IVec2Property"; +} + +int IVec2Property::typeLua() const { + return LUA_TTABLE; +} + +glm::ivec2 IVec2Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/ivec3property.cpp b/src/properties/vector/ivec3property.cpp index 96b12bec64..211f250a6b 100644 --- a/src/properties/vector/ivec3property.cpp +++ b/src/properties/vector/ivec3property.cpp @@ -24,75 +24,33 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::ivec3 fromLuaConversion(lua_State* state, bool& success) { - glm::ivec3 result = glm::ivec3(0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::ivec3(0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::ivec3(0); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::ivec3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::ivec3 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - IVec3Property, - glm::ivec3, - glm::ivec3(0), - glm::ivec3(std::numeric_limits::lowest()), - glm::ivec3(std::numeric_limits::max()), - glm::ivec3(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +IVec3Property::IVec3Property(Property::PropertyInfo info, glm::ivec3 value, + glm::ivec3 minValue, glm::ivec3 maxValue, + glm::ivec3 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string IVec3Property::className() const { + return "IVec3Property"; +} + +int IVec3Property::typeLua() const { + return LUA_TTABLE; +} + +glm::ivec3 IVec3Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/ivec4property.cpp b/src/properties/vector/ivec4property.cpp index 416bd76e94..3646c49768 100644 --- a/src/properties/vector/ivec4property.cpp +++ b/src/properties/vector/ivec4property.cpp @@ -24,75 +24,33 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::ivec4 fromLuaConversion(lua_State* state, bool& success) { - glm::ivec4 result = glm::ivec4(0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::ivec4(0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::ivec4(0); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::ivec4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::ivec4 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - IVec4Property, - glm::ivec4, - glm::ivec4(0), - glm::ivec4(std::numeric_limits::lowest()), - glm::ivec4(std::numeric_limits::max()), - glm::ivec4(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +IVec4Property::IVec4Property(Property::PropertyInfo info, glm::ivec4 value, + glm::ivec4 minValue, glm::ivec4 maxValue, + glm::ivec4 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string IVec4Property::className() const { + return "IVec4Property"; +} + +int IVec4Property::typeLua() const { + return LUA_TTABLE; +} + +glm::ivec4 IVec4Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/uvec2property.cpp b/src/properties/vector/uvec2property.cpp index 7a98c9feea..94591b4ae6 100644 --- a/src/properties/vector/uvec2property.cpp +++ b/src/properties/vector/uvec2property.cpp @@ -24,75 +24,33 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::uvec2 fromLuaConversion(lua_State* state, bool& success) { - glm::uvec2 result = glm::uvec2(0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::uvec2(0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::uvec2(0); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::uvec2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::uvec2 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - UVec2Property, - glm::uvec2, - glm::uvec2(0), - glm::uvec2(std::numeric_limits::lowest()), - glm::uvec2(std::numeric_limits::max()), - glm::uvec2(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +UVec2Property::UVec2Property(Property::PropertyInfo info, glm::uvec2 value, + glm::uvec2 minValue, glm::uvec2 maxValue, + glm::uvec2 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string UVec2Property::className() const { + return "UVec2Property"; +} + +int UVec2Property::typeLua() const { + return LUA_TTABLE; +} + +glm::uvec2 UVec2Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/uvec3property.cpp b/src/properties/vector/uvec3property.cpp index b387254a99..31000d5200 100644 --- a/src/properties/vector/uvec3property.cpp +++ b/src/properties/vector/uvec3property.cpp @@ -24,75 +24,33 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::uvec3 fromLuaConversion(lua_State* state, bool& success) { - glm::uvec3 result = glm::uvec3(0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::uvec3(0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::uvec3(0); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::uvec3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::uvec3 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - UVec3Property, - glm::uvec3, - glm::uvec3(0), - glm::uvec3(std::numeric_limits::lowest()), - glm::uvec3(std::numeric_limits::max()), - glm::uvec3(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +UVec3Property::UVec3Property(Property::PropertyInfo info, glm::uvec3 value, + glm::uvec3 minValue, glm::uvec3 maxValue, + glm::uvec3 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string UVec3Property::className() const { + return "UVec3Property"; +} + +int UVec3Property::typeLua() const { + return LUA_TTABLE; +} + +glm::uvec3 UVec3Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/uvec4property.cpp b/src/properties/vector/uvec4property.cpp index c42868a2bc..71f5cdbbb7 100644 --- a/src/properties/vector/uvec4property.cpp +++ b/src/properties/vector/uvec4property.cpp @@ -24,75 +24,33 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::uvec4 fromLuaConversion(lua_State* state, bool& success) { - glm::uvec4 result = glm::uvec4(0); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::uvec4(0); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::uvec4(0); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::uvec4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::uvec4 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - UVec4Property, - glm::uvec4, - glm::uvec4(0), - glm::uvec4(std::numeric_limits::lowest()), - glm::uvec4(std::numeric_limits::max()), - glm::uvec4(1), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +UVec4Property::UVec4Property(Property::PropertyInfo info, glm::uvec4 value, + glm::uvec4 minValue, glm::uvec4 maxValue, + glm::uvec4 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string UVec4Property::className() const { + return "UVec4Property"; +} + +int UVec4Property::typeLua() const { + return LUA_TTABLE; +} + +glm::uvec4 UVec4Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/vec2property.cpp b/src/properties/vector/vec2property.cpp index 61bca8403e..c3c0f9e75b 100644 --- a/src/properties/vector/vec2property.cpp +++ b/src/properties/vector/vec2property.cpp @@ -24,75 +24,32 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::vec2 fromLuaConversion(lua_State* state, bool& success) { - glm::vec2 result = glm::vec2(0.f); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::vec2(0.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::vec2(0.f); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::vec2 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::vec2 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - Vec2Property, - glm::vec2, - glm::vec2(0.f), - glm::vec2(std::numeric_limits::lowest()), - glm::vec2(std::numeric_limits::max()), - glm::vec2(0.01f), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +Vec2Property::Vec2Property(Property::PropertyInfo info, glm::vec2 value, + glm::vec2 minValue, glm::vec2 maxValue, glm::vec2 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string Vec2Property::className() const { + return "Vec2Property"; +} + +int Vec2Property::typeLua() const { + return LUA_TTABLE; +} + +glm::vec2 Vec2Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/vec3property.cpp b/src/properties/vector/vec3property.cpp index d77093ed90..a9e0fd9471 100644 --- a/src/properties/vector/vec3property.cpp +++ b/src/properties/vector/vec3property.cpp @@ -24,74 +24,32 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::vec3 fromLuaConversion(lua_State* state, bool& success) { - glm::vec3 result = glm::vec3(0.f); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::vec3(0.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::vec3(0.f); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::vec3 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::vec3 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - Vec3Property, - glm::vec3, - glm::vec3(0.f), - glm::vec3(std::numeric_limits::lowest()), - glm::vec3(std::numeric_limits::max()), - glm::vec3(0.01f), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +Vec3Property::Vec3Property(Property::PropertyInfo info, glm::vec3 value, + glm::vec3 minValue, glm::vec3 maxValue, glm::vec3 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string Vec3Property::className() const { + return "Vec3Property"; +} + +int Vec3Property::typeLua() const { + return LUA_TTABLE; +} + +glm::vec3 Vec3Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/properties/vector/vec4property.cpp b/src/properties/vector/vec4property.cpp index 538e9270ea..374d5ef3f9 100644 --- a/src/properties/vector/vec4property.cpp +++ b/src/properties/vector/vec4property.cpp @@ -24,75 +24,32 @@ #include -#include #include -#include -#include -#include - -namespace { - -glm::vec4 fromLuaConversion(lua_State* state, bool& success) { - glm::vec4 result = glm::vec4(0.f); - lua_pushnil(state); - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - int hasNext = lua_next(state, -2); - if (hasNext != 1) { - success = false; - return glm::vec4(0.f); - } - if (lua_isnumber(state, -1) != 1) { - success = false; - return glm::vec4(0.f); - } - else { - result[i] = static_cast(lua_tonumber(state, -1)); - lua_pop(state, 1); - } - } - - // The last accessor argument is still on the stack - lua_pop(state, 1); - success = true; - return result; -} - -bool toLuaConversion(lua_State* state, glm::vec4 value) { - lua_newtable(state); - int number = 1; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - lua_pushnumber(state, static_cast(value[i])); - lua_rawseti(state, -2, number); - ++number; - } - return true; -} - -bool toStringConversion(std::string& outValue, glm::vec4 inValue) { - outValue = "{"; - for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { - outValue += std::to_string(inValue[i]) + ","; - } - outValue.pop_back(); - outValue += "}"; - return true; -} - -} // namespace +#include namespace openspace::properties { -REGISTER_NUMERICALPROPERTY_SOURCE( - Vec4Property, - glm::vec4, - glm::vec4(0.f), - glm::vec4(std::numeric_limits::lowest()), - glm::vec4(std::numeric_limits::max()), - glm::vec4(0.01f), - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TTABLE -) +Vec4Property::Vec4Property(Property::PropertyInfo info, glm::vec4 value, + glm::vec4 minValue, glm::vec4 maxValue, glm::vec4 stepValue) + : NumericalProperty( + std::move(info), + std::move(value), + std::move(minValue), + std::move(maxValue), + std::move(stepValue) + ) +{} + +std::string Vec4Property::className() const { + return "Vec4Property"; +} + +int Vec4Property::typeLua() const { + return LUA_TTABLE; +} + +glm::vec4 Vec4Property::fromLuaConversion(lua_State* state, bool& success) const { + return ghoul::lua::tryGetValue(state, success); +} } // namespace openspace::properties diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 2a44f4a5bd..caac1536e3 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -425,7 +425,7 @@ SceneGraphNode::SceneGraphNode() ) } , _boundingSphere(BoundingSphereInfo, -1.0, -1.0, 1e12) - , _interactionSphere(InteractionSphereInfo, -1.0, -1.0, -1.0, 1e12) + , _interactionSphere(InteractionSphereInfo, -1.0, -1.0, 1e12) , _computeScreenSpaceValues(ComputeScreenSpaceInfo, false) , _screenSpacePosition(ScreenSpacePositionInfo, glm::ivec2(-1, -1)) , _screenVisibility(ScreenVisibilityInfo, false) diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index e93946ae41..ef7f4841b9 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 7ea69ac42d..0693847c5c 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/src/properties/scalar/longdoubleproperty.cpp b/src/util/json_helper.cpp similarity index 58% rename from src/properties/scalar/longdoubleproperty.cpp rename to src/util/json_helper.cpp index 5f74b6d550..6466c7a525 100644 --- a/src/properties/scalar/longdoubleproperty.cpp +++ b/src/util/json_helper.cpp @@ -22,51 +22,58 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +namespace openspace { -#include - -#include -#include - -namespace { - -long double fromLuaConversion(lua_State* state, bool& success) { - success = (lua_isnumber(state, -1) == 1); - if (success) { - long double val = static_cast(lua_tonumber(state, -1)); - return val; +std::string escapedJson(const std::string& text) { + std::string jsonString; + jsonString.reserve(text.size()); + for (const char& c : text) { + switch (c) { + case '\t': + jsonString += "\\t"; // Replace tab with \t. + break; + case '"': + jsonString += "\\\""; // Replace " with \". + break; + case '\\': + jsonString += "\\\\"; // Replace \ with \\. + break; + case '\n': + jsonString += "\\\\n"; // Replace newline with \n. + break; + case '\r': + jsonString += "\\r"; // Replace carriage return with \r. + break; + default: + jsonString += c; + } } - else { - return 0l; + return jsonString; +} + +std::string escapedJson(const std::vector& list) { + std::string jsonString; + jsonString += "["; + for (const std::string& text : list) { + jsonString += "\\\""; + jsonString += escapedJson(text); + jsonString += "\\\","; } + if (jsonString.length() > 1) { + jsonString.pop_back(); + } + jsonString += "]"; + + return jsonString; } -bool toLuaConversion(lua_State* state, long double value) { - lua_pushnumber(state, static_cast(value)); - return true; +std::string formatJsonNumber(double d) { + // to_string will represent infinite values with 'inf' and NaNs with 'nan'. + // These are not valid in JSON, so use 'null' instead + if (!std::isfinite(d)) { + return "null"; + } + return std::to_string(d); } -bool toStringConversion(std::string& outValue, long double inValue) { - outValue = std::to_string(inValue); - return true; -} - -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - LongDoubleProperty, - long double, - 0l, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 0.01l, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - -} // namespace openspace::properties +} // namespace openspace diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c68874247c..cae023372f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,9 +32,9 @@ add_executable( test_configuration.cpp test_documentation.cpp test_iswamanager.cpp + test_jsonformatting.cpp test_latlonpatch.cpp test_lrucache.cpp - test_luaconversions.cpp test_lua_createsinglecolorimage.cpp test_profile.cpp test_rawvolumeio.cpp diff --git a/tests/property/test_property_selectionproperty.cpp b/tests/property/test_property_selectionproperty.cpp index 8b5225f837..5d903d91f2 100644 --- a/tests/property/test_property_selectionproperty.cpp +++ b/tests/property/test_property_selectionproperty.cpp @@ -119,7 +119,7 @@ TEST_CASE("SelectionProperty: Add Options", "[selectionproperty]") { const int nOptions = static_cast(p.options().size()); REQUIRE(nOptions == 2); - REQUIRE((p.hasOption("a") && p.hasOption("b"))); + REQUIRE(p.options() == std::vector{ "a", "b" }); } TEST_CASE("SelectionProperty: Get String Value", "[selectionproperty]") { @@ -168,7 +168,7 @@ TEST_CASE("SelectionProperty: Set Lua Value - Invalid Key", "[selectionproperty] p.setOptions({ "a", "b", "c" }); ghoul::lua::LuaState L; - ghoul::lua::push(L, std::vector{ "a", "d" }); // + ghoul::lua::push(L, std::vector{ "a", "d" }); p.setLuaValue(L); @@ -218,8 +218,19 @@ TEST_CASE("SelectionProperty: Value From Copying Variable", "[selectionproperty] openspace::properties::SelectionProperty p({ "id", "gui", "desc" }); p.setOptions({ "a", "b", "c" }); - const std::set list{ "a", "b" }; - p = list; + p = { "a", "b" }; - REQUIRE(p.value() == list); + REQUIRE(p.value() == std::set{ "a", "b" }); +} + +TEST_CASE("SelectionProperty: Re-set Options After Selection", "[selectionproperty]") { + openspace::properties::SelectionProperty p({ "id", "gui", "desc" }); + p.setOptions({ "a", "b", "c" }); + + p = { "a", "b" }; + + p.setOptions({ "a", "c", "d" }); // b no longer included + // => should be removed from selection + + REQUIRE(p.value() == std::set{ "a" }); } diff --git a/tests/test_configuration.cpp b/tests/test_configuration.cpp index f7c031d251..25aa84be4f 100644 --- a/tests/test_configuration.cpp +++ b/tests/test_configuration.cpp @@ -300,10 +300,10 @@ TEST_CASE("Configuration: onScreenTextScaling", "[configuration]") { CHECK(c.onScreenTextScaling == "framebuffer"); } -TEST_CASE("Configuration: usePerSceneCache", "[configuration]") { - constexpr const char Extra[] = R"(PerSceneCache = true)"; - const Configuration c = loadConfiguration("usePerSceneCache", Extra); - CHECK(c.usePerSceneCache == true); +TEST_CASE("Configuration: usePerProfileCache", "[configuration]") { + constexpr const char Extra[] = R"(PerProfileCache = true)"; + const Configuration c = loadConfiguration("usePerProfileCache", Extra); + CHECK(c.usePerProfileCache == true); } TEST_CASE("Configuration: isRenderingOnMasterDisabled", "[configuration]") { diff --git a/src/properties/scalar/signedcharproperty.cpp b/tests/test_jsonformatting.cpp similarity index 57% rename from src/properties/scalar/signedcharproperty.cpp rename to tests/test_jsonformatting.cpp index a89fa006a3..59d791a81f 100644 --- a/src/properties/scalar/signedcharproperty.cpp +++ b/tests/test_jsonformatting.cpp @@ -22,51 +22,47 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include "catch2/catch.hpp" -#include +#include +#include +#include -#include -#include +// Note: Dictionary formatting is tested in Ghoul -namespace { +TEMPLATE_TEST_CASE("FormatJson", "[formatjson]", glm::vec2, glm::vec3, + glm::vec4, glm::dvec2, glm::dvec3, glm::dvec4, glm::ivec2, glm::ivec3, glm::ivec4, + glm::uvec2, glm::uvec3, glm::uvec4, glm::mat2x2, glm::mat2x3, glm::mat2x4, + glm::mat3x2, glm::mat3x3, glm::mat3x4, glm::mat4x2, glm::mat4x3, glm::mat4x4, + glm::dmat2x2, glm::dmat2x3, glm::dmat2x4, glm::dmat3x2, glm::dmat3x3, glm::dmat3x4, + glm::dmat4x2, glm::dmat4x3, glm::dmat4x4) +{ + using T = TestType; -signed char fromLuaConversion(lua_State* state, bool& success) { - success = (lua_isnumber(state, -1) == 1); - if (success) { - signed char val = static_cast(lua_tonumber(state, -1)); - return val; - } - else { - return 0; - } + const T val(1); + + std::string json = openspace::formatJson(val); + + // Compare with Ghoul's Lua conversions. Note that Lua uses '{' for arrays, + // while we here expect '[' for all glm types + std::string luaValue = ghoul::to_string(val); + luaValue.replace(0, 1, "["); + luaValue.replace(luaValue.size() - 1, 1, "]"); + + REQUIRE(json == luaValue); } -bool toLuaConversion(lua_State* state, signed char value) { - lua_pushnumber(state, static_cast(value)); - return true; +TEST_CASE("FormatJson - Bool", "[formatjson]") { + bool trueVal = true; + bool falseVal = false; + + REQUIRE(openspace::formatJson(trueVal) == "true"); + REQUIRE(openspace::formatJson(falseVal) == "false"); } -bool toStringConversion(std::string& outValue, signed char inValue) { - outValue = std::to_string(inValue); - return true; +TEST_CASE("FormatJson - Infinity & Nan", "[formatjson]") { + REQUIRE(openspace::formatJson(std::numeric_limits::infinity()) == "null"); + REQUIRE(openspace::formatJson(std::numeric_limits::quiet_NaN()) == "null"); } -} // namespace - -namespace openspace::properties { - -REGISTER_NUMERICALPROPERTY_SOURCE( - SignedCharProperty, - signed char, - 0, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - 0, - fromLuaConversion, - toLuaConversion, - toStringConversion, - LUA_TNUMBER -) - -} // namespace openspace::properties +// @TODO(emmbr 2021-04-29) Add more tests at some point, if we find it necessary diff --git a/tests/test_luaconversions.cpp b/tests/test_luaconversions.cpp deleted file mode 100644 index 958b73db65..0000000000 --- a/tests/test_luaconversions.cpp +++ /dev/null @@ -1,882 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2021 * - * * - * 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 "catch2/catch.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - constexpr const int NumberFuzzTests = 10000; -} // namespace - -TEST_CASE("LuaConversion: LuaExecution", "[luaconversion]") { - lua_State* state = luaL_newstate(); - luaL_openlibs(state); - - const int status = luaL_loadstring(state, ""); - REQUIRE(status == LUA_OK); - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion", "[luaconversion]", bool, char, signed char, - unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, - long long, unsigned long long, float, double, long double, glm::vec2, glm::vec3, - glm::vec4, glm::dvec2, glm::dvec3, glm::dvec4, glm::ivec2, glm::ivec3, glm::ivec4, - glm::uvec2, glm::uvec3, glm::uvec4, glm::mat2x2, glm::mat2x3, glm::mat2x4, - glm::mat3x2, glm::mat3x3, glm::mat3x4, glm::mat4x2, glm::mat4x3, glm::mat4x4, - glm::dmat2x2, glm::dmat2x3, glm::dmat2x4, glm::dmat3x2, glm::dmat3x3, glm::dmat3x4, - glm::dmat4x2, glm::dmat4x3, glm::dmat4x4) -{ - using T = TestType; - - lua_State* state = luaL_newstate(); - luaL_openlibs(state); - - const T val(1); - - using namespace openspace::properties; - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion Fuzz dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - - const T val = T(dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion Fuzz >short", "[luaconversion]", short, unsigned short, - int, unsigned int) -{ - using T = TestType; - using namespace openspace::properties; - - lua_State* state = luaL_newstate(); - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - - const T val = T(dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - - -TEMPLATE_TEST_CASE("LuaConversion Fuzz Limited Signed", "[luaconversion]", long, - long long) -{ - using T = TestType; - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - - std::mt19937 gen(1337); - std::uniform_int_distribution<> dis( - // We need to limit the range of values as Lua uses 'doubles' to store, and some - // values will not be representable - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion Fuzz Limited Unsigned", "[luaconversion]", - unsigned long, unsigned long long) -{ - using T = TestType; - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - // We need to limit the range of values as Lua uses 'doubles' to store, and some - // values will not be representable - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion Float Fuzz", "[luaconversion]", float, double, - long double) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - 0.f, - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - - if (typeid(T) == typeid(long double)) { - if (value != std::numeric_limits::infinity()) { - REQUIRE(value == val); - } - } - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Vec2 Float Fuzz", "[luaconversion]", glm::vec2, - glm::dvec2) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} -TEMPLATE_TEST_CASE("LuaConversion: Vec2 Fuzz", "[luaconversion]", glm::ivec2, glm::uvec2) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Vec3 Float Fuzz", "[luaconversion]", glm::vec3, - glm::dvec3) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Vec3 Fuzz", "[luaconversion]", glm::ivec3, glm::uvec3) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Vec4 Float Fuzz", "[luaconversion]", glm::vec4, - glm::dvec4) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Vec4 Fuzz", "[luaconversion]", glm::ivec4, glm::uvec4) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat2x2 Fuzz", "[luaconversion]", glm::mat2x2, - glm::dmat2x2) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat2x3 Fuzz", "[luaconversion]", glm::mat2x3, - glm::dmat2x3) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat2x4 Fuzz", "[luaconversion]", glm::mat2x4, - glm::dmat2x4) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat3x2 Fuzz", "[luaconversion]", glm::mat3x2, - glm::dmat3x2) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat3x3 Fuzz", "[luaconversion]", glm::mat3x3, - glm::dmat3x3) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat3x4 Fuzz", "[luaconversion]", glm::mat3x4, - glm::dmat3x4) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat4x2 Fuzz", "[luaconversion]", glm::mat4x2, - glm::dmat4x2) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat4x3 Fuzz", "[luaconversion]", glm::mat4x3, - glm::dmat4x3) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - -TEMPLATE_TEST_CASE("LuaConversion: Mat4x4 Fuzz", "[luaconversion]", glm::mat4x4, - glm::dmat4x4) -{ - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - using T = TestType; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - std::numeric_limits::min(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen)); - - const bool success = PropertyDelegate>::template toLuaValue( - state, - val - ); - REQUIRE(success); - bool success2; - const T value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == val); - - lua_pop(state, 1); - } - - lua_close(state); -} - - -TEST_CASE("LuaConversion: String", "[luaconversion]") { - lua_State* state = luaL_newstate(); - - using namespace openspace::properties; - bool success - = PropertyDelegate>::template toLuaValue( - state, "value"); - REQUIRE(success); - std::string value; - bool success2; - value = PropertyDelegate>::template fromLuaValue( - state, - success2 - ); - REQUIRE(success2); - REQUIRE(value == "value"); - - lua_close(state); -} diff --git a/tests/test_timequantizer.cpp b/tests/test_timequantizer.cpp index cb7506a4f4..aaa7dc38d1 100644 --- a/tests/test_timequantizer.cpp +++ b/tests/test_timequantizer.cpp @@ -148,6 +148,15 @@ TEST_CASE("TimeQuantizer: Test years resolution", "[timequantizer]") { singleTimeTest(testT, t1, true, "2028-12-08T23:59:59", "2025-12-09T00:00:00.000"); singleTimeTest(testT, t1, true, "2028-12-09T00:00:01", "2028-12-09T00:00:00.000"); + try { + t1.setStartEndRange("2020-02-29T00:00:00", "2030-02-29T00:00:00"); + } + catch (const ghoul::RuntimeError& e) { + REQUIRE(e.message.find("Invalid start day value of 29 for the selected month " + "on a yearly increment, valid days are 1 - 28") != std::string::npos); + } + t1.setStartEndRange("2020-02-28T00:00:00", "2030-02-28T00:00:00"); + SpiceManager::deinitialize(); } @@ -191,6 +200,11 @@ TEST_CASE("TimeQuantizer: Test days resolution", "[timequantizer]") { singleTimeTest(testT, t1, true, "2020-03-01T00:30:00", "2020-03-01T00:00:00.000"); singleTimeTest(testT, t1, true, "2019-03-04T00:00:02", "2019-03-04T00:00:00.000"); + t1.setStartEndRange("2020-01-31T00:00:00", "2020-07-31T00:00:00"); + t1.setResolution("1d"); + + singleTimeTest(testT, t1, true, "2020-03-01T00:30:00", "2020-03-01T00:00:00.000"); + SpiceManager::deinitialize(); } @@ -207,6 +221,14 @@ TEST_CASE("TimeQuantizer: Test months resolution", "[timequantizer]") { singleTimeTest(testT, t1, true, "2017-03-03T05:15:45", "2017-02-28T00:00:00.000"); singleTimeTest(testT, t1, true, "2017-03-29T00:15:45", "2017-03-28T00:00:00.000"); + try { + t1.setStartEndRange("2017-01-30T00:00:00", "2020-09-01T00:00:00"); + } + catch (const ghoul::RuntimeError& e) { + REQUIRE(e.message.find("Invalid start day value of 30 for monthly increment, " + "valid days are 1 - 28") != std::string::npos); + } + t1.setStartEndRange("2016-01-17T00:00:00", "2020-09-01T00:00:00"); t1.setResolution("2M"); @@ -333,7 +355,7 @@ TEST_CASE("TimeQuantizer: Test start time pre-existing object", "[timequantizer] globebrowsing::TimeQuantizer t1; singleStartTimeTest(t1, "2017-01-20T00:00:00", "Invalid start", false); - singleStartTimeTest(t1, "2017-01-29T00:00:00", "Invalid start day value", true); + singleStartTimeTest(t1, "2017-01-29T00:00:00", "Invalid start day value", false); singleStartTimeTest(t1, "2017-01-28T12:00:00", "Invalid start time value", true); singleStartTimeTest(t1, "2017-01-28T00:01:00", "Invalid start time value", true); singleStartTimeTest(t1, "2017-01-28T00:00:01", "Invalid start time value", true); @@ -347,7 +369,7 @@ TEST_CASE("TimeQuantizer: Test start time using constructor", "[timequantizer]") loadLSKKernel(); singleStartTimeTest("2017-01-20T00:00:00", "Invalid start", false); - singleStartTimeTest("2017-01-29T00:00:00", "Invalid start day value", true); + singleStartTimeTest("2017-01-32T00:00:00", "For January the day must be at least 1.0D0 and less than 3.2E+01", true); singleStartTimeTest("2017-01-28T12:00:00", "Invalid start time value", true); singleStartTimeTest("2017-01-28T00:01:00", "Invalid start time value", true); singleStartTimeTest("2017-01-28T00:00:01", "Invalid start time value", true);