finish merge + manual time offset property

This commit is contained in:
ElonOlsson
2021-05-12 15:37:22 -04:00
965 changed files with 69303 additions and 52573 deletions

View File

@@ -94,24 +94,6 @@ private:
const std::vector<HandlebarTemplate> _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<std::string>& list);
} // namespace openspace
#endif // __OPENSPACE_CORE___DOCUMENTATIONGENERATOR___H__

View File

@@ -29,6 +29,7 @@
#include <ghoul/glm.h>
#include <functional>
#include <type_traits>
#include <variant>
namespace openspace::documentation {
@@ -155,7 +156,17 @@ struct IntVerifier : public TemplateVerifier<int> {
* <code>std::string</code>. No implicit conversion is considered in this testing.
*/
struct StringVerifier : public TemplateVerifier<std::string> {
StringVerifier(bool mustBeNotEmpty = false);
TestResult operator()(const ghoul::Dictionary& dictionary,
const std::string& key) const override;
std::string type() const override;
bool mustBeNotEmpty() const;
private:
bool _mustBeNotEmpty = false;
};
/**
@@ -180,6 +191,17 @@ struct DirectoryVerifier : public StringVerifier {
std::string type() const override;
};
/**
* A Verifier that checks whether a given key inside a ghoul::Dictionary is a string and
* a valid date time
*/
struct DateTimeVerifier : public StringVerifier {
TestResult operator()(const ghoul::Dictionary& dict,
const std::string& key) const override;
std::string type() const override;
};
/**
* A Verifier that checks whether a given key inside a ghoul::Dictionary is another
* ghoul::Dictionary. The constructor takes a list of DocumentationEntry%s, which are used
@@ -994,8 +1016,15 @@ struct OrVerifier : public Verifier {
* \param values The list of Verifiers that are to be tested
*
* \pre values must contain at least two values
*
* \todo: The use of the variant to use both raw pointers and shared pointers is
* definitely undesired. At the momement we are not handling the ownership of
* the verifiers very well and this must be cleaned up when doing a pass over
* the entire ownership model of the documentation/verifiers. For now it was
* necessary to make the codegen work in all cases without complications there
*/
OrVerifier(const std::vector<Verifier*> values);
OrVerifier(const std::vector<std::variant<Verifier*,
std::shared_ptr<Verifier>>> values);
/**
* Checks whether the \p dictionary contains the \p key and whether this key passes

View File

@@ -45,17 +45,27 @@ template <typename T>
TestResult TemplateVerifier<T>::operator()(const ghoul::Dictionary& dict,
const std::string& key) const
{
TestResult res;
if (dict.hasValue<Type>(key)) {
return { true, {}, {} };
res.success = true;
}
else {
res.success = false;
if (dict.hasKey(key)) {
return { false, { { key, TestResult::Offense::Reason::WrongType } }, {} };
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::WrongType;
res.offenses.push_back(o);
}
else {
return { false, { { key, TestResult::Offense::Reason::MissingKey } }, {} };
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::MissingKey;
res.offenses.push_back(o);
}
}
return res;
}
template <typename T>
@@ -143,7 +153,13 @@ TestResult OperatorVerifier<T, Operator>::operator()(const ghoul::Dictionary& di
val = static_cast<int>(d);
}
else {
return { false, { { key, TestResult::Offense::Reason::WrongType } }, {} };
TestResult r;
r.success = false;
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::WrongType;
r.offenses.push_back(o);
return r;
}
}
else {
@@ -153,7 +169,13 @@ TestResult OperatorVerifier<T, Operator>::operator()(const ghoul::Dictionary& di
return { true, {}, {} };
}
else {
return { false, { { key, TestResult::Offense::Reason::Verification } }, {} };
TestResult r;
r.success = false;
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::Verification;
r.offenses.push_back(o);
return r;
}
}
else {
@@ -210,7 +232,13 @@ TestResult InListVerifier<T>::operator()(const ghoul::Dictionary& dict,
return { true, {}, {} };
}
else {
return { false, { { key, TestResult::Offense::Reason::Verification } }, {} };
TestResult r;
r.success = false;
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::Verification;
r.offenses.push_back(o);
return r;
}
}
else {
@@ -256,7 +284,13 @@ TestResult NotInListVerifier<T>::operator()(const ghoul::Dictionary& dict,
return { true, {}, {} };
}
else {
return { false, { { key, TestResult::Offense::Reason::Verification } }, {} };
TestResult r;
r.success = false;
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::Verification;
r.offenses.push_back(o);
return r;
}
}
else {
@@ -306,7 +340,13 @@ TestResult InRangeVerifier<T>::operator()(const ghoul::Dictionary& dict,
val = static_cast<int>(d);
}
else {
return { false, { { key, TestResult::Offense::Reason::WrongType } }, {} };
TestResult r;
r.success = false;
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::WrongType;
r.offenses.push_back(o);
return r;
}
}
else {
@@ -317,7 +357,13 @@ TestResult InRangeVerifier<T>::operator()(const ghoul::Dictionary& dict,
return { true, {}, {} };
}
else {
return { false, { { key, TestResult::Offense::Reason::Verification } }, {} };
TestResult r;
r.success = false;
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::Verification;
r.offenses.push_back(o);
return r;
}
}
else {
@@ -353,7 +399,13 @@ TestResult NotInRangeVerifier<T>::operator()(const ghoul::Dictionary& dict,
val = static_cast<int>(d);
}
else {
return { false, { { key, TestResult::Offense::Reason::WrongType } }, {} };
TestResult r;
r.success = false;
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::WrongType;
r.offenses.push_back(o);
return r;
}
}
else {
@@ -361,7 +413,13 @@ TestResult NotInRangeVerifier<T>::operator()(const ghoul::Dictionary& dict,
}
if (val >= lower && val <= upper) {
return { false, { { key, TestResult::Offense::Reason::Verification } }, {} };
TestResult r;
r.success = false;
TestResult::Offense o;
o.offender = key;
o.reason = TestResult::Offense::Reason::Verification;
r.offenses.push_back(o);
return r;
}
else {
return { true, {}, {} };
@@ -396,9 +454,10 @@ TestResult DeprecatedVerifier<T>::operator()(const ghoul::Dictionary& dict,
const std::string& key) const
{
TestResult res = T::operator()(dict, key);
res.warnings.push_back(
TestResult::Warning{ key, TestResult::Warning::Reason::Deprecated }
);
TestResult::Warning w;
w.offender = key;
w.reason = TestResult::Warning::Reason::Deprecated;
res.warnings.push_back(w);
return res;
}

View File

@@ -43,7 +43,6 @@ struct Configuration {
Configuration& operator=(Configuration&&) = default;
std::string windowConfiguration = "${CONFIG}/single.xml";
std::string sgctConfigNameInitialized;
std::string asset;
std::string profile;
std::vector<std::string> readOnlyProfiles;
@@ -93,7 +92,6 @@ struct Configuration {
glm::dvec3 screenSpaceRotation = glm::dvec3(0.0);
glm::dvec3 masterRotation = glm::dvec3(0.0);
bool isConsoleDisabled = false;
bool usingProfile = false;
bool bypassLauncher = false;
std::map<std::string, ghoul::Dictionary> moduleConfigurations;
@@ -123,6 +121,9 @@ struct Configuration {
};
HTTPProxy httpProxy;
// Values not read from the openspace.cfg file
bool usingProfile = false;
std::string sgctConfigNameInitialized;
static documentation::Documentation Documentation;
ghoul::lua::LuaState state;
@@ -130,9 +131,8 @@ struct Configuration {
std::string findConfiguration(const std::string& filename = "openspace.cfg");
Configuration loadConfigurationFromFile(const std::string& filename);
void parseLuaState(Configuration& configuration);
Configuration loadConfigurationFromFile(const std::string& filename,
const std::string& overrideScript);
} // namespace openspace::configuration

View File

@@ -99,6 +99,7 @@ public:
void writeSceneDocumentation();
void writeStaticDocumentation();
void createUserDirectoriesIfNecessary();
/**
* Returns the Lua library that contains all Lua functions available to affect the
@@ -143,7 +144,7 @@ private:
// Lua functions - exposed for testing
namespace openspace::luascriptfunctions {
int createSingeColorImage(lua_State* L);
int createSingleColorImage(lua_State* L);
} // openspace::luascriptfunctions

View File

@@ -22,30 +22,30 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___LONGDOUBLEPROPERTY___H__
#define __OPENSPACE_CORE___LONGDOUBLEPROPERTY___H__
#ifndef __OPENSPACE_CORE___DOUBLELISTPROPERTY___H__
#define __OPENSPACE_CORE___DOUBLELISTPROPERTY___H__
/**
* \file longdoubleproperty.h
*
* \addtogroup openspace
* @{
* \addtogroup properties
* @{
* \class LongDoubleProperty
* This class is a concrete implementation of openspace::properties::TemplateProperty with
* the type <code>long double</code>.
* @} @}
*/
#include <openspace/properties/numericalproperty.h>
#include <openspace/properties/listproperty.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(LongDoubleProperty, long double)
class DoubleListProperty : public ListProperty<double> {
public:
DoubleListProperty(Property::PropertyInfo info,
std::vector<double> values = std::vector<double>());
std::string className() const override;
int typeLua() const override;
using TemplateProperty<std::vector<double>>::operator std::vector<double>;
using TemplateProperty<std::vector<double>>::operator=;
protected:
std::vector<double> fromLuaConversion(lua_State* state, bool& success) const override;
void toLuaConversion(lua_State* state) const override;
std::string toStringConversion() const override;
};
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___LONGDOUBLEPROPERTY___H__
#endif // __OPENSPACE_CORE___DOUBLELISTPROPERTY___H__

View File

@@ -22,30 +22,30 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___CHARPROPERTY___H__
#define __OPENSPACE_CORE___CHARPROPERTY___H__
#ifndef __OPENSPACE_CORE___INTLISTPROPERTY___H__
#define __OPENSPACE_CORE___INTLISTPROPERTY___H__
/**
* \file charproperty.h
*
* \addtogroup openspace
* @{
* \addtogroup properties
* @{
* \class CharProperty
* This class is a concrete implementation of openspace::properties::TemplateProperty with
* the type <code>char</code>.
* @} @}
*/
#include <openspace/properties/numericalproperty.h>
#include <openspace/properties/listproperty.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(CharProperty, char)
class IntListProperty : public ListProperty<int> {
public:
IntListProperty(Property::PropertyInfo info,
std::vector<int> values = std::vector<int>());
std::string className() const override;
int typeLua() const override;
using TemplateProperty<std::vector<int>>::operator std::vector<int>;
using TemplateProperty<std::vector<int>>::operator=;
protected:
std::vector<int> fromLuaConversion(lua_State* state, bool& success) const override;
void toLuaConversion(lua_State* state) const override;
std::string toStringConversion() const override;
};
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___CHARPROPERTY___H__
#endif // __OPENSPACE_CORE___INTLISTPROPERTY___H__

View File

@@ -25,14 +25,28 @@
#ifndef __OPENSPACE_CORE___STRINGLISTPROPERTY___H__
#define __OPENSPACE_CORE___STRINGLISTPROPERTY___H__
#include <openspace/properties/templateproperty.h>
#include <openspace/properties/listproperty.h>
#include <string>
#include <vector>
namespace openspace::properties {
REGISTER_TEMPLATEPROPERTY_HEADER(StringListProperty, std::vector<std::string>)
class StringListProperty : public ListProperty<std::string> {
public:
StringListProperty(Property::PropertyInfo info,
std::vector<std::string> values = std::vector<std::string>());
std::string className() const override;
int typeLua() const override;
using TemplateProperty<std::vector<std::string>>::operator std::vector<std::string>;
using TemplateProperty<std::vector<std::string>>::operator=;
protected:
std::vector<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

View File

@@ -22,17 +22,24 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___DMAT2X3PROPERTY___H__
#define __OPENSPACE_CORE___DMAT2X3PROPERTY___H__
#ifndef __OPENSPACE_CORE___LISTPROPERTY___H__
#define __OPENSPACE_CORE___LISTPROPERTY___H__
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <openspace/properties/templateproperty.h>
#include <vector>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat2x3Property, glm::dmat2x3)
template <typename T>
class ListProperty : public TemplateProperty<std::vector<T>> {
public:
ListProperty(Property::PropertyInfo info, std::vector<T> values);
virtual ~ListProperty() = 0;
};
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___DMAT2X3PROPERTY___H__
#include "openspace/properties/listproperty.inl"
#endif // __OPENSPACE_CORE___LISTPROPERTY___H__

View File

@@ -22,17 +22,15 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___BVEC2PROPERTY___H__
#define __OPENSPACE_CORE___BVEC2PROPERTY___H__
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_TEMPLATEPROPERTY_HEADER(BVec2Property, glm::bvec2)
template <typename T>
ListProperty<T>::ListProperty(Property::PropertyInfo info, std::vector<T> values)
: TemplateProperty<std::vector<T>>(std::move(info), std::move(values))
{}
template <typename T>
ListProperty<T>::~ListProperty() {}
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___BVEC2PROPERTY___H__

View File

@@ -28,10 +28,27 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat2Property, glm::dmat2x2)
class DMat2Property : public NumericalProperty<glm::dmat2x2> {
public:
DMat2Property(Property::PropertyInfo info, glm::dmat2x2 value = glm::dmat2x2(0.0),
glm::dmat2x2 minValue =
ghoul::createFillMat2x2<double>(std::numeric_limits<double>::lowest()),
glm::dmat2x2 maxValue =
ghoul::createFillMat2x2<double>(std::numeric_limits<double>::max()),
glm::dmat2x2 stepValue = ghoul::createFillMat2x2<double>(0.01));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::dmat2x2>::operator=;
protected:
glm::dmat2x2 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat2x4Property, glm::dmat2x4)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___DMAT2X4PROPERTY___H__

View File

@@ -28,10 +28,27 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat3Property, glm::dmat3x3)
class DMat3Property : public NumericalProperty<glm::dmat3x3> {
public:
DMat3Property(Property::PropertyInfo info, glm::dmat3x3 value = glm::dmat3x3(0.0),
glm::dmat3x3 minValue =
ghoul::createFillMat3x3<double>(std::numeric_limits<double>::lowest()),
glm::dmat3x3 maxValue =
ghoul::createFillMat3x3<double>(std::numeric_limits<double>::max()),
glm::dmat3x3 stepValue = ghoul::createFillMat3x3<double>(0.01));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::dmat3x3>::operator=;
protected:
glm::dmat3x3 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat3x2Property, glm::dmat3x2)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___DMAT3X2PROPERTY___H__

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat3x4Property, glm::dmat3x4)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___DMAT3X4PROPERTY___H__

View File

@@ -28,10 +28,27 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat4Property, glm::dmat4x4)
class DMat4Property : public NumericalProperty<glm::dmat4x4> {
public:
DMat4Property(Property::PropertyInfo info, glm::dmat4x4 value = glm::dmat4x4(0.0),
glm::dmat4x4 minValue =
ghoul::createFillMat4x4<double>(std::numeric_limits<double>::lowest()),
glm::dmat4x4 maxValue =
ghoul::createFillMat4x4<double>(std::numeric_limits<double>::max()),
glm::dmat4x4 stepValue = ghoul::createFillMat4x4<double>(0.01));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::dmat4x4>::operator=;
protected:
glm::dmat4x4 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat4x2Property, glm::dmat4x2)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___DMAT4X2PROPERTY___H__

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DMat4x3Property, glm::dmat4x3)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___DMAT4X3PROPERTY___H__

View File

@@ -28,10 +28,27 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat2Property, glm::mat2x2)
class Mat2Property : public NumericalProperty<glm::mat2x2> {
public:
Mat2Property(Property::PropertyInfo info, glm::mat2x2 value = glm::mat2x2(0.f),
glm::mat2x2 minValue =
ghoul::createFillMat2x2<float>(std::numeric_limits<float>::lowest()),
glm::mat2x2 maxValue =
ghoul::createFillMat2x2<float>(std::numeric_limits<float>::max()),
glm::mat2x2 stepValue = ghoul::createFillMat2x2<float>(0.01f));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::mat2x2>::operator=;
protected:
glm::mat2x2 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat2x3Property, glm::mat2x3)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___MAT2X3PROPERTY___H__

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat2x4Property, glm::mat2x4)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___MAT2X4PROPERTY___H__

View File

@@ -28,10 +28,27 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat3Property, glm::mat3x3)
class Mat3Property : public NumericalProperty<glm::mat3x3> {
public:
Mat3Property(Property::PropertyInfo info, glm::mat3x3 value = glm::mat3x3(),
glm::mat3x3 minValue =
ghoul::createFillMat3x3<float>(std::numeric_limits<float>::lowest()),
glm::mat3x3 maxValue =
ghoul::createFillMat3x3<float>(std::numeric_limits<float>::max()),
glm::mat3x3 stepValue = ghoul::createFillMat3x3<float>(0.01f));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::mat3x3>::operator=;
protected:
glm::mat3x3 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat3x2Property, glm::mat3x2)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___MAT3X2PROPERTY___H__

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat3x4Property, glm::mat3x4)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___MAT3X4PROPERTY___H__

View File

@@ -28,10 +28,27 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat4Property, glm::mat4x4)
class Mat4Property : public NumericalProperty<glm::mat4x4> {
public:
Mat4Property(Property::PropertyInfo info, glm::mat4x4 value = glm::mat4x4(),
glm::mat4x4 minValue =
ghoul::createFillMat4x4<float>(std::numeric_limits<float>::lowest()),
glm::mat4x4 maxValue =
ghoul::createFillMat4x4<float>(std::numeric_limits<float>::max()),
glm::mat4x4 stepValue = ghoul::createFillMat4x4<float>(0.01f));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::mat4x4>::operator=;
protected:
glm::mat4x4 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat4x2Property, glm::mat4x2)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___MAT4X2PROPERTY___H__

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Mat4x3Property, glm::mat4x3)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___MAT4X3PROPERTY___H__

View File

@@ -32,21 +32,11 @@ namespace openspace::properties {
template <typename T>
class NumericalProperty : public TemplateProperty<T> {
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;
bool setStringValue(std::string value) override;
virtual std::string className() const override = 0;
virtual int typeLua() const override = 0;
T minValue() const;
void setMinValue(T value);
@@ -60,27 +50,26 @@ public:
float exponent() const;
void setExponent(float exponent);
virtual std::string className() const override;
std::string jsonValue() const override;
using TemplateProperty<T>::operator=;
void setInterpolationTarget(std::any value) override;
void setLuaInterpolationTarget(lua_State* state) override;
void setStringInterpolationTarget(std::string value) override;
void interpolateValue(float t,
ghoul::EasingFunc<float> 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;
/**

View File

@@ -22,205 +22,12 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/json_helper.h>
#include <ghoul/lua/ghoul_lua.h>
#include <glm/ext/matrix_common.hpp>
namespace openspace::properties {
#define REGISTER_NUMERICALPROPERTY_HEADER(CLASS_NAME, TYPE) \
using CLASS_NAME = NumericalProperty<TYPE>; \
\
template <> \
std::string PropertyDelegate<NumericalProperty<TYPE>>::className(); \
\
template <> \
std::string PropertyDelegate<TemplateProperty<TYPE>>::className(); \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultValue<TYPE>(); \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMinimumValue<TYPE>(); \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMaximumValue<TYPE>(); \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultSteppingValue<TYPE>(); \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue(lua_State* state, \
bool& success); \
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::fromLuaValue(lua_State* state, \
bool& success); \
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue(lua_State* state, \
const TYPE& value); \
template <> \
template <> \
bool PropertyDelegate<NumericalProperty<TYPE>>::toLuaValue(lua_State* state, \
const TYPE& value); \
template <> \
int PropertyDelegate<TemplateProperty<TYPE>>::typeLua(); \
template <> \
int PropertyDelegate<NumericalProperty<TYPE>>::typeLua(); \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromString(const std::string& value, \
bool& success); \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::fromString(const std::string& value, \
bool& success); \
\
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toString(std::string& outValue, \
const TYPE& inValue); \
\
template <> \
template <> \
bool PropertyDelegate<NumericalProperty<TYPE>>::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, \
FROM_STRING_LAMBDA_EXPRESSION, \
TO_STRING_LAMBDA_EXPRESSION, LUA_TYPE) \
template <> \
std::string PropertyDelegate<TemplateProperty<TYPE>>::className() \
{ \
return #CLASS_NAME; \
} \
\
template <> \
std::string PropertyDelegate<NumericalProperty<TYPE>>::className() \
{ \
return PropertyDelegate<TemplateProperty<TYPE>>::className(); \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultValue<TYPE>() \
{ \
return DEFAULT_VALUE; \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMinimumValue<TYPE>() \
{ \
return DEFAULT_MIN_VALUE; \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMaximumValue<TYPE>() \
{ \
return DEFAULT_MAX_VALUE; \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultSteppingValue<TYPE>() \
{ \
return DEFAULT_STEPPING; \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue<TYPE>(lua_State* state, \
bool& success) \
{ \
return FROM_LUA_LAMBDA_EXPRESSION(state, success); \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::fromLuaValue<TYPE>(lua_State* state, \
bool& success) \
{ \
return PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue<TYPE>( \
state, success); \
} \
\
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(lua_State* state, \
const TYPE& value) \
{ \
return TO_LUA_LAMBDA_EXPRESSION(state, value); \
} \
\
template <> \
template <> \
bool PropertyDelegate<NumericalProperty<TYPE>>::toLuaValue<TYPE>(lua_State* state, \
const TYPE& value) \
{ \
return PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(state, value); \
} \
\
template <> \
int PropertyDelegate<TemplateProperty<TYPE>>::typeLua() \
{ \
return LUA_TYPE; \
} \
\
template <> \
int PropertyDelegate<NumericalProperty<TYPE>>::typeLua() \
{ \
return PropertyDelegate<TemplateProperty<TYPE>>::typeLua(); \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromString(const std::string& value, \
bool& success) \
{ \
return FROM_STRING_LAMBDA_EXPRESSION(value, success); \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::fromString(const std::string& value, \
bool& success) \
{ \
return PropertyDelegate<TemplateProperty<TYPE>>::fromString<TYPE>( \
value, \
success \
); \
} \
\
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toString(std::string& outValue, \
const TYPE& inValue) \
{ \
return TO_STRING_LAMBDA_EXPRESSION(outValue, inValue); \
} \
\
template <> \
template <> \
bool PropertyDelegate<NumericalProperty<TYPE>>::toString(std::string& outValue, \
const TYPE& inValue) \
{ \
return PropertyDelegate<TemplateProperty<TYPE>>::toString(outValue, inValue); \
}
template <typename T>
const std::string NumericalProperty<T>::MinimumValueKey = "MinimumValue";
@@ -233,60 +40,6 @@ const std::string NumericalProperty<T>::SteppingValueKey = "SteppingValue";
template <typename T>
const std::string NumericalProperty<T>::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 <typename T>
NumericalProperty<T>::NumericalProperty(Property::PropertyInfo info)
: NumericalProperty<T>(
std::move(info),
PropertyDelegate<NumericalProperty<T>>::template defaultValue<T>(),
PropertyDelegate<NumericalProperty<T>>::template defaultMinimumValue<T>(),
PropertyDelegate<NumericalProperty<T>>::template defaultMaximumValue<T>(),
PropertyDelegate<NumericalProperty<T>>::template defaultSteppingValue<T>(),
1.f
)
{}
template <typename T>
NumericalProperty<T>::NumericalProperty(Property::PropertyInfo info, T value)
: NumericalProperty<T>(
std::move(info),
std::move(value),
PropertyDelegate<NumericalProperty<T>>::template defaultMinimumValue<T>(),
PropertyDelegate<NumericalProperty<T>>::template defaultMaximumValue<T>(),
PropertyDelegate<NumericalProperty<T>>::template defaultSteppingValue<T>(),
1.f
)
{}
template <typename T>
NumericalProperty<T>::NumericalProperty(Property::PropertyInfo info, T value,
T minimumValue, T maximumValue)
: NumericalProperty<T>(
std::move(info),
std::move(value),
std::move(minimumValue),
std::move(maximumValue),
PropertyDelegate<NumericalProperty<T>>::template defaultSteppingValue<T>(),
1.f
)
{}
template <typename T>
NumericalProperty<T>::NumericalProperty(Property::PropertyInfo info, T value,
T minimumValue, T maximumValue, T steppingValue)
: NumericalProperty<T>(
std::move(info),
std::move(value),
std::move(minimumValue),
std::move(maximumValue),
std::move(steppingValue),
1.f
)
{}
template <typename T>
NumericalProperty<T>::NumericalProperty(Property::PropertyInfo info, T value,
T minimumValue, T maximumValue, T steppingValue,
@@ -298,56 +51,6 @@ NumericalProperty<T>::NumericalProperty(Property::PropertyInfo info, T value,
, _exponent(exponent)
{}
template <typename T>
std::string NumericalProperty<T>::className() const {
return PropertyDelegate<NumericalProperty<T>>::className();
}
template <typename T>
bool NumericalProperty<T>::setLuaValue(lua_State* state) {
bool success = false;
T value = PropertyDelegate<NumericalProperty<T>>::template fromLuaValue<T>(
state, success
);
if (success) {
TemplateProperty<T>::setValue(std::move(value));
}
return success;
}
template <typename T>
bool NumericalProperty<T>::getLuaValue(lua_State* state) const {
bool success = PropertyDelegate<NumericalProperty<T>>::template toLuaValue<T>(
state, TemplateProperty<T>::_value
);
return success;
}
template <typename T>
int NumericalProperty<T>::typeLua() const {
return PropertyDelegate<NumericalProperty<T>>::typeLua();
}
template <typename T>
bool NumericalProperty<T>::getStringValue(std::string& value) const {
bool success = PropertyDelegate<NumericalProperty<T>>::template toString<T>(
value, TemplateProperty<T>::_value
);
return success;
}
template <typename T>
bool NumericalProperty<T>::setStringValue(std::string value) {
bool success = false;
T thisValue = PropertyDelegate<NumericalProperty<T>>::template fromString<T>(
value, success
);
if (success) {
TemplateProperty<T>::set(std::any(std::move(thisValue)));
}
return success;
}
template <typename T>
T NumericalProperty<T>::minValue() const {
return _minimumValue;
@@ -416,8 +119,7 @@ std::string NumericalProperty<T>::luaToJson(std::string luaValue) const {
template <typename T>
std::string NumericalProperty<T>::jsonValue() const {
std::string value;
getStringValue(value);
std::string value = toStringConversion();
return luaToJson(value);
}
@@ -432,26 +134,10 @@ void NumericalProperty<T>::setInterpolationTarget(std::any value) {
template <typename T>
void NumericalProperty<T>::setLuaInterpolationTarget(lua_State* state) {
bool success = false;
T thisValue = PropertyDelegate<NumericalProperty<T>>::template fromLuaValue<T>(
state,
success
);
T targetValue = fromLuaConversion(state, success);
if (success) {
_interpolationStart = TemplateProperty<T>::_value;
_interpolationEnd = std::move(thisValue);
}
}
template <typename T>
void NumericalProperty<T>::setStringInterpolationTarget(std::string value) {
bool success = false;
T thisValue = PropertyDelegate<NumericalProperty<T>>::template fromString<T>(
value,
success
);
if (success) {
_interpolationStart = TemplateProperty<T>::_value;
_interpolationEnd = std::move(thisValue);
_interpolationEnd = std::move(targetValue);
}
}
@@ -467,4 +153,14 @@ void NumericalProperty<T>::interpolateValue(float t,
));
}
template <typename T>
void NumericalProperty<T>::toLuaConversion(lua_State* state) const {
ghoul::lua::push(state, TemplateProperty<T>::_value);
}
template <typename T>
std::string NumericalProperty<T>::toStringConversion() const {
return formatJson(TemplateProperty<T>::_value);
}
} // namespace openspace::properties

View File

@@ -44,8 +44,7 @@ class PropertyOwner;
* used as a URI. This class is an abstract base class and each subclass (most notable
* TemplateProperty) needs to implement the methods Property::className, Property::get,
* Property::set, Property::type(), Property::getLuaValue, Property::setLuaValue,
* Property::getStringValue, Property::setStringValue and Property::typeLua to make full
* use of the infrastructure.
* Property::getStringValue, and Property::typeLua to make full use of the infrastructure.
* The most common types can be implemented by creating a specialized instantiation of
* TemplateProperty, which provides default implementations for these methods.
*
@@ -217,8 +216,7 @@ public:
/**
* This method encodes the encapsulated \p value of this Property as a
* <code>std::string</code>. The specific details of this serialization is up to the
* property developer. The implementation has to be synchronized with the
* Property::setStringValue method. The default implementation is a no-op.
* property developer. The default implementation is a no-op.
*
* \param value The value to which the Property will be encoded
* \return \p true if the encoding succeeded, \p false otherwise
@@ -235,18 +233,6 @@ public:
*/
std::string getStringValue() const;
/**
* This method sets the value encapsulated by this Property by deserializing the
* passed <code>std::string</code>. The specific details of the deserialization are up
* to the Property developer. The implementation has to be synchronized with the
* Property::getLuaValue method. The default implementation is a no-op.
*
* \param value The value from which the Property will be decoded
* \return \c true if the decoding and setting of the value succeeded, \c false
* otherwise
*/
virtual bool setStringValue(std::string value);
/**
* This method registers a \p callback function that will be called every time if
* either Property:set or Property::setLuaValue was called with a value that is
@@ -385,9 +371,9 @@ public:
/**
* This method determines if this Property should be read-only in external
* applications. This setting is only a hint and does not need to be followed by GUI
* applications and does not have any effect on the Property::set,
* Property::setLuaValue, or Property::setStringValue methods. The value is stored in
* the metaData Dictionary with the key: \c isReadOnly. The default value is \c false.
* applications and does not have any effect on the Property::set or
* Property::setLuaValue methods. The value is stored in the metaData Dictionary
* with the key: \c isReadOnly. The default value is \c false.
*
* \param state \c true if the Property should be read only, \c false otherwise
*/
@@ -395,22 +381,21 @@ public:
/**
* Default view options that can be used in the Property::setViewOption method. The
* values are: Property::ViewOptions::Color = \c color,
* Property::ViewOptions::LightPosition = \c lightPosition
* values are: Property::ViewOptions::Color = \c Color,
* Property::ViewOptions::Logarithmic = \c Logarithmic
*/
struct ViewOptions {
static const char* Color;
static const char* LightPosition;
static const char* Logarithmic;
};
/**
* This method allows the developer to give hints to the GUI about different
* representations for the GUI. The same Property (for example Vec4Property) can be
* used in different ways, each requiring a different input method. These values are
* stored in the metaData object using the <code>views.</code> prefix in front of the
* <code>option</code> parameter. See Property::ViewOptions for a default list of
* possible options. As these are only hints, the GUI is free to ignore any suggestion
* by the developer.
* stored in the metaData object under <code>ViewOptions</code>.
* See Property::ViewOptions for a default list of possible options. As these are
* only hints, the GUI is free to ignore any suggestion by the developer.
* \param option The view option that should be modified
* \param value Determines if the view option should be active (<code>true</code>) or
* deactivated (<code>false</code>)
@@ -456,7 +441,6 @@ public:
/// Interpolation methods
virtual void setInterpolationTarget(std::any value);
virtual void setLuaInterpolationTarget(lua_State* state);
virtual void setStringInterpolationTarget(std::string value);
virtual void interpolateValue(float t,
ghoul::EasingFunc<float> easingFunction = nullptr);

View File

@@ -1,164 +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 <string>
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 <code>T = TemplateProperty<std::string></code>.
*/
template <typename T>
class PropertyDelegate {
public:
/**
* This method returns the class name for the class <code>T</code>. The default
* implementation will lead to a compile-time error if the class method is not
* specialized.
* \return The class name for the class <code>T</code>
*/
static std::string className();
/**
* This method will return the preferred default value for the class <code>T</code>.
* The default implementation will lead to a compile-time error if the class method is
* not specialized.
* \return The default value that the class <code>T</code> should use
* \tparam U The type by which the class T is specialized. If
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
*/
template <typename U>
static U defaultValue();
/**
* This method will return the preferred default minimum value for the class
* <code>T</code>. 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 <code>T</code> should use
* \tparam U The type by which the class T is specialized. If
* <code>T = NumericalProperty<int></code>, then <code>U = int</code>
*/
template <typename U>
static U defaultMinimumValue();
/**
* This method will return the preferred default maximum value for the class
* <code>T</code>. 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 <code>T</code> should use
* \tparam U The type by which the class T is specialized. If
* <code>T = NumericalProperty<int></code>, then <code>U = int</code>
*/
template <typename U>
static U defaultMaximumValue();
/**
* The method returns the default stepping value for the class <code>T</code> 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 <code>T</code> should use
* \tparam U The type by which the class T is specialized. If
* <code>T = NumericalProperty<int></code>, then <code>U = int</code>
*/
template <typename U>
static U defaultSteppingValue();
/**
* This method converts the top value from the Lua stack into a value of type
* <code>U</code> and reports the <code>success</code> 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 <code>true</code> if the conversion succeeded;
* <code>false</code> 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
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
*/
template <typename U>
static U fromLuaValue(lua_State* state, bool& success);
/**
* This method converts the passed <code>value</code>, 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 <code>true</code> if the conversion succeeded; <code>false</code> otherwise
* \tparam U The type by which the class T is specialized. If
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
*/
template <typename U>
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: <code>LUA_TNONE</code>, <code>LUA_TNIL</code>,
* <code>LUA_TBOOLEAN</code>, <code>LUA_TLIGHTUSERDATA</code>,
* <code>LUA_TNUMBER</code>, <code>LUA_TSTRING</code>, <code>LUA_TTABLE</code>,
* <code>LUA_TFUNCTION</code>, <code>LUA_TUSERDATA</code>, or
* <code>LUA_TTHREAD</code>. The default implementation will return
* <code>LUA_TNONE</code>. 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 <typename U>
static U fromString(const std::string& value, bool& success);
template <typename U>
static bool toString(std::string& outValue, const U& inValue);
};
} // namespace openspace::properties
#include <openspace/properties/propertydelegate.inl>
#endif // __OPENSPACE_CORE___PROPERTYDELEGATE___H__

View File

@@ -44,7 +44,20 @@
namespace openspace::properties {
REGISTER_TEMPLATEPROPERTY_HEADER(BoolProperty, bool)
class BoolProperty : public TemplateProperty<bool> {
public:
BoolProperty(Property::PropertyInfo info, bool value = false);
std::string className() const override;
int typeLua() const override;
using TemplateProperty<bool>::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

View File

@@ -41,10 +41,24 @@
*/
#include <openspace/properties/numericalproperty.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DoubleProperty, double)
class DoubleProperty : public NumericalProperty<double> {
public:
DoubleProperty(Property::PropertyInfo info, double value = 0.0,
double minValue = std::numeric_limits<double>::lowest(),
double maxValue = std::numeric_limits<double>::max(), double stepValue = 0.01);
std::string className() const override;
int typeLua() const override;
using TemplateProperty<double>::operator=;
protected:
double fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -41,10 +41,24 @@
*/
#include <openspace/properties/numericalproperty.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(FloatProperty, float)
class FloatProperty : public NumericalProperty<float> {
public:
FloatProperty(Property::PropertyInfo info, float value = 0.f,
float minValue = std::numeric_limits<float>::lowest(),
float maxValue = std::numeric_limits<float>::max(), float stepValue = 0.01f);
std::string className() const override;
int typeLua() const override;
using TemplateProperty<float>::operator=;
protected:
float fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -41,10 +41,24 @@
*/
#include <openspace/properties/numericalproperty.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(IntProperty, int)
class IntProperty : public NumericalProperty<int> {
public:
IntProperty(Property::PropertyInfo info, int value = 0,
int minValue = std::numeric_limits<int>::lowest(),
int maxValue = std::numeric_limits<int>::max(), int stepValue = 1);
std::string className() const override;
int typeLua() const override;
using TemplateProperty<int>::operator=;
protected:
int fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -41,10 +41,25 @@
*/
#include <openspace/properties/numericalproperty.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(LongProperty, long)
class LongProperty : public NumericalProperty<long> {
public:
LongProperty(Property::PropertyInfo info, long value = long(0),
long minValue = std::numeric_limits<long>::lowest(),
long maxValue = std::numeric_limits<long>::max(),
long stepValue = long(1));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<long>::operator=;
protected:
long fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -41,10 +41,25 @@
*/
#include <openspace/properties/numericalproperty.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(ShortProperty, short)
class ShortProperty : public NumericalProperty<short> {
public:
ShortProperty(Property::PropertyInfo info, short value = short(0),
short minValue = std::numeric_limits<short>::lowest(),
short maxValue = std::numeric_limits<short>::max(),
short stepValue = short(1));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<short>::operator=;
protected:
short fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <code>unsigned char</code>.
* @} @}
*/
#include <openspace/properties/numericalproperty.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(UCharProperty, unsigned char)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___UCHARPROPERTY___H__

View File

@@ -41,10 +41,25 @@
*/
#include <openspace/properties/numericalproperty.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(UIntProperty, unsigned int)
class UIntProperty : public NumericalProperty<unsigned int> {
public:
UIntProperty(Property::PropertyInfo info, unsigned int value = 0,
unsigned int minValue = std::numeric_limits<unsigned int>::lowest(),
unsigned int maxValue = std::numeric_limits<unsigned int>::max(),
unsigned int stepValue = 1);
std::string className() const override;
int typeLua() const override;
using TemplateProperty<unsigned int>::operator=;
protected:
unsigned int fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <code>unsigned long long</code>.
* @} @}
*/
#include <openspace/properties/numericalproperty.h>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(ULongLongProperty, unsigned long long)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___ULONGLONGPROPERTY___H__

View File

@@ -41,10 +41,25 @@
*/
#include <openspace/properties/numericalproperty.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(ULongProperty, unsigned long)
class ULongProperty : public NumericalProperty<unsigned long> {
public:
ULongProperty(Property::PropertyInfo info, unsigned long value = 0ul,
unsigned long minValue = std::numeric_limits<unsigned long>::lowest(),
unsigned long maxValue = std::numeric_limits<unsigned long>::max(),
unsigned long stepValue = 1ul);
std::string className() const override;
int typeLua() const override;
using TemplateProperty<unsigned long>::operator=;
protected:
unsigned long fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -41,10 +41,25 @@
*/
#include <openspace/properties/numericalproperty.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(UShortProperty, unsigned short)
class UShortProperty : public NumericalProperty<unsigned short> {
public:
UShortProperty(Property::PropertyInfo info, unsigned short value = 0,
unsigned short minValue = std::numeric_limits<unsigned short>::lowest(),
unsigned short maxValue = std::numeric_limits<unsigned short>::max(),
unsigned short stepValue = 1);
std::string className() const override;
int typeLua() const override;
using TemplateProperty<unsigned short>::operator=;
protected:
unsigned short fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -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 <code>wchar_t</code>.
* @} @}
*/
#include <openspace/properties/numericalproperty.h>
namespace openspace::properties {
//REGISTER_NUMERICALPROPERTY_HEADER(WCharProperty, wchar_t)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___WCHARPROPERTY___H__

View File

@@ -27,63 +27,109 @@
#include <openspace/properties/templateproperty.h>
#include <set>
#include <vector>
namespace openspace::properties {
class SelectionProperty : public TemplateProperty<std::vector<int>> {
public:
struct Option {
int value;
std::string description;
};
class SelectionProperty : public TemplateProperty<std::set<std::string>> {
public:
SelectionProperty(Property::PropertyInfo info);
void addOption(Option option);
void removeOptions();
const std::vector<Option>& options() const;
std::string className() const override;
int typeLua() const override;
using TemplateProperty<std::vector<int>>::operator std::vector<int>;
/**
* This method sets the stored value to the provided value <code>val</code>.
* If the value is different, the listeners are notified. It also removes any
* invalid keys in the input set. A key is invalid if it does not correspond to
* an existing option in the SelectionProperty
*
* \param val The new value for this SelectionProperty
*/
void setValue(std::set<std::string> val) override;
using TemplateProperty<std::vector<int>>::operator=;
/**
* Checks if an option given by the provided <code>key</code> exists.
*
* \param key The key that should be checked for existence
* \return \c if the option exists; \c false otherwise
*/
bool hasOption(const std::string& key) const;
/**
* Checks if an option given by the provided <code>key</code> is selected.
*
* \param key The key that should be checked
* \return \c true if the option is selected; \c false otherwise
*/
bool isSelected(const std::string& key) const;
/**
* Checks if the SelectionProperty has any selected values, that is, if its
* value is empty.
*
* \return \c true if there are selected options; \c false otherwise
*/
bool hasSelected() const;
/**
* Returns all available options for this SelectionProperty. Should be
* sorted alphabetically.
*
* \return A list of all available options
*/
const std::vector<std::string>& options() const;
/**
* This method sets all available options at once, removing any potential duplicates.
* If a selection exists, it is updated to that any selected option that does not
* match the new set of options is removed.
*
* \param keys The keys for the options to be set
*/
void setOptions(const std::vector<std::string>& keys);
/**
* Adds an individual option, if it did not already exist.
*
* \param key The key for the option to be added
*/
void addOption(const std::string& key);
/**
* This method clears the selection list, that is the value of this SelectionProperty
*/
void clearSelection();
/**
* This method clears the options list. As the selection must match the available
* options, the selection list is cleared as well.
*/
void clearOptions();
using TemplateProperty<std::set<std::string>>::operator std::set<std::string>;
using TemplateProperty<std::set<std::string>>::operator=;
protected:
std::set<std::string> fromLuaConversion(lua_State* state, bool& success) const override;
void toLuaConversion(lua_State* state) const override;
std::string toStringConversion() const override;
private:
static const std::string OptionsKey;
void sortOptions();
bool removeInvalidKeys(std::set<std::string>& keys);
std::string generateAdditionalJsonDescription() const override;
/// The list of options which have been registered with this OptionProperty
std::vector<Option> _options;
std::vector<int> _values;
// A list of all available options that can be selected
std::vector<std::string> _options;
};
template <>
std::string PropertyDelegate<TemplateProperty<std::vector<int>>>::className();
template <>
template <>
std::vector<int> PropertyDelegate<TemplateProperty<std::vector<int>>>::fromLuaValue(
lua_State* state, bool& success);
template <>
template <>
bool PropertyDelegate<TemplateProperty<std::vector<int>>>::toLuaValue(lua_State* state,
const std::vector<int>& value);
template <>
int PropertyDelegate<TemplateProperty<std::vector<int>>>::typeLua();
template <>
template <>
std::vector<int> PropertyDelegate<TemplateProperty<std::vector<int>>>::fromString(
const std::string& value, bool& success);
template <>
template <>
bool PropertyDelegate<TemplateProperty<std::vector<int>>>::toString(
std::string& outValue, const std::vector<int>& inValue);
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___SELECTIONPROPERTY___H__

View File

@@ -29,7 +29,20 @@
namespace openspace::properties {
REGISTER_TEMPLATEPROPERTY_HEADER(StringProperty, std::string)
class StringProperty : public TemplateProperty<std::string> {
public:
StringProperty(Property::PropertyInfo info, std::string value = "");
std::string className() const override;
int typeLua() const override;
using TemplateProperty<std::string>::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

View File

@@ -27,12 +27,10 @@
#include <openspace/properties/property.h>
#include <openspace/properties/propertydelegate.h>
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
* <code>T</code>. It provides all the necessary methods to automatically access the
* value. One notable instantiation of this class is StringProperty, using
* <code>T = std::string</code> 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
* <code>T</code> 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 <code>T</code>, 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 <typename T>
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<TemplateProperty<T>>::template defaultValue<T>());
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
* <code>T</code> 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,33 +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 <code>T</code> 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 TemplateProprty 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 <code>T</code> 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;
bool getStringValue(std::string& value) const override;
bool setStringValue(std::string value) override;
/**
* 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
*/
virtual bool getStringValue(std::string& value) const override;
/**
* Returns the description for this TemplateProperty as a Lua script that returns a
@@ -169,15 +162,15 @@ public:
* the TemplateProperty::set method. It will be done internally by this method and it
* allows assignments such as <code>prop = T(1)</code>.
*
* \param val The value that should be set.
* \param val The value that should be set
*/
TemplateProperty<T>& operator=(T val);
/**
* These method sets the stored value to the provided value <code>val</code>,
* moving it into place. This move only happens if the provided value <code>val</code>
* This method sets the stored value to the provided value <code>val</code>,
* moving it into place. The move only happens if the provided value <code>val</code>
* is different from the stored value, which needs an operator== to exist for the type
* <code>T</code>. If the value are different, the listeners are notified.
* <code>T</code>. If the value is different, the listeners are notified.
*
* \param val The new value for this TemplateProperty
*/
@@ -191,6 +184,33 @@ public:
T value() const;
protected:
/**
* Decodes the object at the top of the stack to a value of the type <code>T</code>
* 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;
};

View File

@@ -24,132 +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<TYPE>; \
\
template <> \
std::string PropertyDelegate<TemplateProperty<TYPE>>::className(); \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::defaultValue<TYPE>(); \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue(lua_State* state, \
bool& success); \
\
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue(lua_State* state, \
const TYPE& value); \
\
template <> \
int PropertyDelegate<TemplateProperty<TYPE>>::typeLua(); \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromString(const std::string& value, \
bool& success); \
\
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::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, \
FROM_STRING_LAMBDA_EXPRESSION, \
TO_STRING_LAMBDA_EXPRESSION, LUA_TYPE) \
template <> \
std::string PropertyDelegate<TemplateProperty<TYPE>>::className() \
{ \
return #CLASS_NAME; \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::defaultValue<TYPE>() \
{ \
return DEFAULT_VALUE; \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue<TYPE>(lua_State* state, \
bool& success) \
{ \
return FROM_LUA_LAMBDA_EXPRESSION(state, success); \
} \
\
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(lua_State* state, \
const TYPE& value) \
{ \
return TO_LUA_LAMBDA_EXPRESSION(state, value); \
} \
\
template <> \
int PropertyDelegate<TemplateProperty<TYPE>>::typeLua() { \
return LUA_TYPE; \
} \
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromString(const std::string& value, \
bool& success) \
{ \
return FROM_STRING_LAMBDA_EXPRESSION(value, success); \
} \
\
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toString(std::string& outValue, \
const TYPE& inValue) \
{ \
return TO_STRING_LAMBDA_EXPRESSION(outValue, inValue); \
} \
template <typename T>
TemplateProperty<T>::TemplateProperty(Property::PropertyInfo info, T value)
: Property(std::move(info))
, _value(std::move(value))
{}
template <typename T>
std::string TemplateProperty<T>::className() const {
return PropertyDelegate<TemplateProperty<T>>::className();
}
template <typename T>
TemplateProperty<T>::operator T() {
return _value;
@@ -194,11 +74,7 @@ std::any TemplateProperty<T>::get() const {
template <typename T>
void TemplateProperty<T>::set(std::any value) {
T v = std::any_cast<T>(std::move(value));
if (v != _value) {
_value = std::move(v);
notifyChangeListeners();
_isValueDirty = true;
}
setValue(v);
}
template <typename T>
@@ -208,20 +84,14 @@ const std::type_info& TemplateProperty<T>::type() const {
template <typename T>
bool TemplateProperty<T>::getLuaValue(lua_State* state) const {
bool success = PropertyDelegate<TemplateProperty<T>>::template toLuaValue<T>(
state,
_value
);
return success;
toLuaConversion(state);
return true;
}
template <typename T>
bool TemplateProperty<T>::setLuaValue(lua_State* state) {
bool success = false;
T thisValue = PropertyDelegate<TemplateProperty<T>>::template fromLuaValue<T>(
state,
success
);
T thisValue = fromLuaConversion(state, success);
if (success) {
set(std::any(thisValue));
}
@@ -229,30 +99,9 @@ bool TemplateProperty<T>::setLuaValue(lua_State* state) {
}
template <typename T>
int TemplateProperty<T>::typeLua() const {
return PropertyDelegate<TemplateProperty<T>>::typeLua();
}
template <typename T>
bool TemplateProperty<T>::getStringValue(std::string& value) const {
bool success = PropertyDelegate<TemplateProperty<T>>::template toString<T>(
value,
_value
);
return success;
}
template <typename T>
bool TemplateProperty<T>::setStringValue(std::string value) {
bool success = false;
T thisValue = PropertyDelegate<TemplateProperty<T>>::template fromString<T>(
value,
success
);
if (success) {
set(std::any(thisValue));
}
return success;
bool TemplateProperty<T>::getStringValue(std::string& outValue) const {
outValue = toStringConversion();
return true;
}
} // namespace openspace::properties

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_TEMPLATEPROPERTY_HEADER(BVec3Property, glm::bvec3)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___BVEC3PROPERTY___H__

View File

@@ -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 <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
namespace openspace::properties {
REGISTER_TEMPLATEPROPERTY_HEADER(BVec4Property, glm::bvec4)
} // namespace openspace::properties
#endif // __OPENSPACE_CORE___BVEC4PROPERTY___H__

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DVec2Property, glm::dvec2)
class DVec2Property : public NumericalProperty<glm::dvec2> {
public:
DVec2Property(Property::PropertyInfo info, glm::dvec2 value = glm::dvec2(0.0),
glm::dvec2 minValue = glm::dvec2(std::numeric_limits<double>::lowest()),
glm::dvec2 maxValue = glm::dvec2(std::numeric_limits<double>::max()),
glm::dvec2 stepValue = glm::dvec2(0.01));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::dvec2>::operator=;
protected:
glm::dvec2 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DVec3Property, glm::dvec3)
class DVec3Property : public NumericalProperty<glm::dvec3> {
public:
DVec3Property(Property::PropertyInfo info, glm::dvec3 value = glm::dvec3(0.0),
glm::dvec3 minValue = glm::dvec3(std::numeric_limits<double>::lowest()),
glm::dvec3 maxValue = glm::dvec3(std::numeric_limits<double>::max()),
glm::dvec3 stepValue = glm::dvec3(0.01));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::dvec3>::operator=;
protected:
glm::dvec3 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(DVec4Property, glm::dvec4)
class DVec4Property : public NumericalProperty<glm::dvec4> {
public:
DVec4Property(Property::PropertyInfo info, glm::dvec4 value = glm::dvec4(0.0),
glm::dvec4 minValue = glm::dvec4(std::numeric_limits<double>::lowest()),
glm::dvec4 maxValue = glm::dvec4(std::numeric_limits<double>::max()),
glm::dvec4 stepValue = glm::dvec4(0.01));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::dvec4>::operator=;
protected:
glm::dvec4 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(IVec2Property, glm::ivec2)
class IVec2Property : public NumericalProperty<glm::ivec2> {
public:
IVec2Property(Property::PropertyInfo info, glm::ivec2 value = glm::ivec2(0),
glm::ivec2 minValue = glm::ivec2(std::numeric_limits<int>::lowest()),
glm::ivec2 maxValue = glm::ivec2(std::numeric_limits<int>::max()),
glm::ivec2 stepValue = glm::ivec2(1));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::ivec2>::operator=;
protected:
glm::ivec2 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(IVec3Property, glm::ivec3)
class IVec3Property : public NumericalProperty<glm::ivec3> {
public:
IVec3Property(Property::PropertyInfo info, glm::ivec3 value = glm::ivec3(0),
glm::ivec3 minValue = glm::ivec3(std::numeric_limits<int>::lowest()),
glm::ivec3 maxValue = glm::ivec3(std::numeric_limits<int>::max()),
glm::ivec3 stepValue = glm::ivec3(1));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::ivec3>::operator=;
protected:
glm::ivec3 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(IVec4Property, glm::ivec4)
class IVec4Property : public NumericalProperty<glm::ivec4> {
public:
IVec4Property(Property::PropertyInfo info, glm::ivec4 value = glm::ivec4(0),
glm::ivec4 minValue = glm::ivec4(std::numeric_limits<int>::lowest()),
glm::ivec4 maxValue = glm::ivec4(std::numeric_limits<int>::max()),
glm::ivec4 stepValue = glm::ivec4(1));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::ivec4>::operator=;
protected:
glm::ivec4 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(UVec2Property, glm::uvec2)
class UVec2Property : public NumericalProperty<glm::uvec2> {
public:
UVec2Property(Property::PropertyInfo info, glm::uvec2 value = glm::uvec2(0),
glm::uvec2 minValue = glm::uvec2(std::numeric_limits<unsigned int>::lowest()),
glm::uvec2 maxValue = glm::uvec2(std::numeric_limits<unsigned int>::max()),
glm::uvec2 stepValue = glm::uvec2(1));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::uvec2>::operator=;
protected:
glm::uvec2 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(UVec3Property, glm::uvec3)
class UVec3Property : public NumericalProperty<glm::uvec3> {
public:
UVec3Property(Property::PropertyInfo info, glm::uvec3 value = glm::uvec3(0),
glm::uvec3 minValue = glm::uvec3(std::numeric_limits<unsigned int>::lowest()),
glm::uvec3 maxValue = glm::uvec3(std::numeric_limits<unsigned int>::max()),
glm::uvec3 stepValue = glm::uvec3(1));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::uvec3>::operator=;
protected:
glm::uvec3 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(UVec4Property, glm::uvec4)
class UVec4Property : public NumericalProperty<glm::uvec4> {
public:
UVec4Property(Property::PropertyInfo info, glm::uvec4 value = glm::uvec4(0),
glm::uvec4 minValue = glm::uvec4(std::numeric_limits<unsigned int>::lowest()),
glm::uvec4 maxValue = glm::uvec4(std::numeric_limits<unsigned int>::max()),
glm::uvec4 stepValue = glm::uvec4(1));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::uvec4>::operator=;
protected:
glm::uvec4 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Vec2Property, glm::vec2)
class Vec2Property : public NumericalProperty<glm::vec2> {
public:
Vec2Property(Property::PropertyInfo info, glm::vec2 value = glm::vec2(0.f),
glm::vec2 minValue = glm::vec2(std::numeric_limits<float>::lowest()),
glm::vec2 maxValue = glm::vec2(std::numeric_limits<float>::max()),
glm::vec2 stepValue = glm::vec2(0.01f));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::vec2>::operator=;
protected:
glm::vec2 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Vec3Property, glm::vec3)
class Vec3Property : public NumericalProperty<glm::vec3> {
public:
Vec3Property(Property::PropertyInfo info, glm::vec3 value = glm::vec3(0.f),
glm::vec3 minValue = glm::vec3(std::numeric_limits<float>::lowest()),
glm::vec3 maxValue = glm::vec3(std::numeric_limits<float>::max()),
glm::vec3 stepValue = glm::vec3(0.01f));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::vec3>::operator=;
protected:
glm::vec3 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,10 +28,25 @@
#include <openspace/properties/numericalproperty.h>
#include <ghoul/glm.h>
#include <limits>
namespace openspace::properties {
REGISTER_NUMERICALPROPERTY_HEADER(Vec4Property, glm::vec4)
class Vec4Property : public NumericalProperty<glm::vec4> {
public:
Vec4Property(Property::PropertyInfo info, glm::vec4 value = glm::vec4(0.f),
glm::vec4 minValue = glm::vec4(std::numeric_limits<float>::lowest()),
glm::vec4 maxValue = glm::vec4(std::numeric_limits<float>::max()),
glm::vec4 stepValue = glm::vec4(0.01f));
std::string className() const override;
int typeLua() const override;
using TemplateProperty<glm::vec4>::operator=;
protected:
glm::vec4 fromLuaConversion(lua_State* state, bool& success) const override;
};
} // namespace openspace::properties

View File

@@ -28,12 +28,9 @@
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/stringproperty.h>
#include <ghoul/glm.h>
namespace ghoul { class Dictionary; }
namespace ghoul::fontrendering { class Font; }
namespace openspace {
@@ -58,22 +55,6 @@ protected:
properties::BoolProperty _isEnabled;
};
class DashboardTextItem : public DashboardItem {
public:
static documentation::Documentation Documentation();
DashboardTextItem(const ghoul::Dictionary& dictionary, float fontSize = 10.f,
const std::string& fontName = "Mono");
protected:
properties::StringProperty _fontName;
properties::FloatProperty _fontSize;
std::shared_ptr<ghoul::fontrendering::Font> _font;
};
} // openspace
#endif // __OPENSPACE_CORE___DASHBOARDITEM___H__

View File

@@ -22,30 +22,35 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___LONGLONGPROPERTY___H__
#define __OPENSPACE_CORE___LONGLONGPROPERTY___H__
#ifndef __OPENSPACE_CORE___DASHBOARDTEXTITEM___H__
#define __OPENSPACE_CORE___DASHBOARDTEXTITEM___H__
/**
* \file longlongproperty.h
*
* \addtogroup openspace
* @{
* \addtogroup properties
* @{
#include <openspace/rendering/dashboarditem.h>
* \class LongLongProperty
* This class is a concrete implementation of openspace::properties::TemplateProperty with
* the type <code>long long</code>.
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/stringproperty.h>
* @} @}
*/
namespace ghoul { class Dictionary; }
namespace ghoul::fontrendering { class Font; }
#include <openspace/properties/numericalproperty.h>
namespace openspace {
namespace openspace::properties {
namespace documentation { struct Documentation; }
REGISTER_NUMERICALPROPERTY_HEADER(LongLongProperty, long long)
class DashboardTextItem : public DashboardItem {
public:
static documentation::Documentation Documentation();
} // namespace openspace::properties
DashboardTextItem(const ghoul::Dictionary& dictionary, float fontSize = 10.f,
const std::string& fontName = "Mono");
#endif // __OPENSPACE_CORE___LONGLONGPROPERTY___H__
protected:
properties::StringProperty _fontName;
properties::FloatProperty _fontSize;
std::shared_ptr<ghoul::fontrendering::Font> _font;
};
} // openspace
#endif // __OPENSPACE_CORE___DASHBOARDTEXTITEM___H__

View File

@@ -61,12 +61,12 @@ void renderBox(const glm::vec2& position, const glm::vec2& size, const glm::vec4
struct Shaders {
struct {
std::unique_ptr<ghoul::opengl::ProgramObject> program;
UniformCache(tex, hasTexture, shouldFlipTexture, ortho, color) cache;
UniformCache(tex, hasTexture, shouldFlipTexture, proj, color) cache;
} xyuvrgba;
struct {
std::unique_ptr<ghoul::opengl::ProgramObject> program;
UniformCache(tex, hasTexture, shouldFlipTexture, ortho, color) cache;
UniformCache(tex, hasTexture, shouldFlipTexture, proj, color) cache;
} screenfilling;
};
@@ -76,6 +76,14 @@ struct VertexObjects {
GLuint vbo;
} square;
struct {
GLuint vao;
GLuint vbo;
GLuint ibo;
int nElements = 64;
} sphere;
struct {
GLuint vao;
} empty;
@@ -108,6 +116,9 @@ std::vector<VertexXYZ> convert(std::vector<Vertex> v);
std::vector<Vertex> createRing(int nSegments, float radius,
glm::vec4 colors = glm::vec4(1.f));
std::pair<std::vector<Vertex>, std::vector<GLushort>>
createSphere(int nSegments, glm::vec3 radii, glm::vec4 colors = glm::vec4(1.f));
} // namespace openspace::rendering::helper
#endif // __OPENSPACE_CORE___HELPER___H__

View File

@@ -31,6 +31,7 @@
#include <openspace/properties/scalar/doubleproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/scene/scenegraphnode.h>
#include <ghoul/misc/managedmemoryuniqueptr.h>
namespace ghoul { class Dictionary; }
@@ -75,11 +76,17 @@ public:
bool isEnabled() const;
bool shouldUpdateIfDisabled() const;
void setBoundingSphere(double boundingSphere);
double boundingSphere() const;
double interactionSphere() const;
virtual void render(const RenderData& data, RendererTasks& rendererTask);
virtual void update(const UpdateData& data);
// The 'surface' in this case is the interaction sphere of this renderable. In some
// cases (i.e., planets) this corresponds directly to the physical surface, but in
// many cases, models, volumetric data, this will not. Regardless of what the physical
// representation is, the 'surface' is always the sphere around which interaction is
// handled
virtual SurfacePositionHandle calculateSurfacePositionHandle(
const glm::dvec3& targetModelSpace) const;
@@ -98,15 +105,26 @@ public:
protected:
properties::BoolProperty _enabled;
properties::FloatProperty _opacity;
properties::DoubleProperty _boundingSphere;
properties::StringProperty _renderableType;
bool _shouldUpdateIfDisabled = false;
void setBoundingSphere(double boundingSphere);
void setInteractionSphere(double interactionSphere);
void setRenderBinFromOpacity();
void registerUpdateRenderBinFromOpacity();
double _boundingSphere = 0.0;
double _interactionSphere = 0.0;
SceneGraphNode* _parent = nullptr;
bool _shouldUpdateIfDisabled = false;
private:
// We only want the SceneGraphNode to be able manipulate the parent, so we don't want
// to provide a set method for this. Otherwise, anyone might mess around with our
// parentage and that's no bueno
friend ghoul::mm_unique_ptr<SceneGraphNode> SceneGraphNode::createFromDictionary(
const ghoul::Dictionary&);
RenderBin _renderBin = RenderBin::Opaque;
};

View File

@@ -201,6 +201,7 @@ private:
properties::BoolProperty _showCameraInfo;
properties::BoolProperty _applyWarping;
properties::BoolProperty _screenshotUseDate;
properties::BoolProperty _showFrameInformation;
properties::BoolProperty _disableMasterRendering;

View File

@@ -36,14 +36,16 @@
#include <ghoul/misc/boolean.h>
#include <ghoul/misc/managedmemoryuniqueptr.h>
#include <atomic>
#include <chrono>
#include <functional>
#include <memory>
#include <optional>
#include <vector>
#include <chrono>
//#define Debugging_Core_SceneGraphNode_Indices
namespace ghoul { class Dictionary; }
namespace ghoul::opengl { class ProgramObject; }
namespace openspace {
@@ -127,6 +129,7 @@ public:
std::vector<SceneGraphNode*> children() const;
double boundingSphere() const;
double interactionSphere() const;
SceneGraphNode* childNode(const std::string& identifier);
@@ -143,6 +146,7 @@ private:
glm::dmat3 calculateWorldRotation() const;
glm::dvec3 calculateWorldScale() const;
void computeScreenSpaceData(RenderData& newData);
void renderDebugSphere(const Camera& camera, double size, glm::vec4 color);
std::atomic<State> _state = State::Loaded;
std::vector<ghoul::mm_unique_ptr<SceneGraphNode>> _children;
@@ -178,6 +182,7 @@ private:
glm::dmat4 _modelTransformCached = glm::dmat4(1.0);
properties::DoubleProperty _boundingSphere;
properties::DoubleProperty _interactionSphere;
properties::BoolProperty _computeScreenSpaceValues;
properties::IVec2Property _screenSpacePosition;
properties::BoolProperty _screenVisibility;
@@ -189,6 +194,12 @@ private:
// are calculated when _computeScreenSpaceValues is true)
std::chrono::high_resolution_clock::time_point _lastScreenSpaceUpdateTime;
properties::BoolProperty _showDebugSphere;
static ghoul::opengl::ProgramObject* _debugSphereProgram;
std::optional<double> _overrideBoundingSphere;
std::optional<double> _overrideInteractionSphere;
#ifdef Debugging_Core_SceneGraphNode_Indices
int index = 0;
static int nextIndex;

View File

@@ -47,6 +47,8 @@ struct LuaLibrary;
class ScriptScheduler {
public:
struct ScheduledScript {
ScheduledScript() = default;
ScheduledScript(const ghoul::Dictionary& dict);
double time = -std::numeric_limits<double>::max();
std::string forwardScript;

View File

@@ -36,6 +36,12 @@ namespace openspace::distanceconstants {
constexpr double LightSecond = 299792458.0;
constexpr double AstronomicalUnit = 1.495978707E11;
constexpr double Parsec = 3.0856776E16;
constexpr double Inch = 0.0254;
constexpr double Foot = 0.3048;
constexpr double Yard = 0.9144;
constexpr double Chain = 20.1168;
constexpr double Mile = 1609.344;
} // openspace::distanceconstants
#endif // __OPENSPACE_CORE___DISTANCECONSTANTS___H__

View File

@@ -39,6 +39,8 @@ enum class DistanceUnit {
Nanometer = 0,
Micrometer,
Millimeter,
Centimeter,
Decimeter,
Meter,
Kilometer,
AU,
@@ -66,6 +68,8 @@ enum class DistanceUnit {
constexpr const char* DistanceUnitNanometer = "nanometer";
constexpr const char* DistanceUnitMicrometer = "micrometer";
constexpr const char* DistanceUnitMillimeter = "millimeter";
constexpr const char* DistanceUnitCentimeter = "centimeter";
constexpr const char* DistanceUnitDecimeter = "decimeter";
constexpr const char* DistanceUnitMeter = "meter";
constexpr const char* DistanceUnitKilometer = "km";
constexpr const char* DistanceUnitAU = "AU";
@@ -91,6 +95,8 @@ constexpr const char* DistanceUnitLeague = "league";
constexpr const char* DistanceUnitNanometers = "nanometers";
constexpr const char* DistanceUnitMicrometers = "micrometers";
constexpr const char* DistanceUnitMillimeters = "millimeters";
constexpr const char* DistanceUnitCentimeters = "centimeters";
constexpr const char* DistanceUnitDecimeters = "decimeters";
constexpr const char* DistanceUnitMeters = "meters";
constexpr const char* DistanceUnitKilometers = "km";
constexpr const char* DistanceUnitAUs = "AU";
@@ -114,18 +120,20 @@ constexpr const char* DistanceUnitLeagues = "leagues";
constexpr const std::array<DistanceUnit, static_cast<int>(DistanceUnit::League) + 1>
DistanceUnits = {
DistanceUnit::Nanometer, DistanceUnit::Micrometer, DistanceUnit::Millimeter,
DistanceUnit::Meter, DistanceUnit::Kilometer, DistanceUnit::AU,
DistanceUnit::Lighthour, DistanceUnit::Lightday, DistanceUnit::Lightmonth,
DistanceUnit::Lightyear, DistanceUnit::Parsec, DistanceUnit::Kiloparsec,
DistanceUnit::Megaparsec, DistanceUnit::Gigaparsec, DistanceUnit::Thou,
DistanceUnit::Inch, DistanceUnit::Foot, DistanceUnit::Yard, DistanceUnit::Chain,
DistanceUnit::Furlong, DistanceUnit::Mile, DistanceUnit::League
DistanceUnit::Centimeter, DistanceUnit::Decimeter, DistanceUnit::Meter,
DistanceUnit::Kilometer, DistanceUnit::AU, DistanceUnit::Lighthour,
DistanceUnit::Lightday, DistanceUnit::Lightmonth, DistanceUnit::Lightyear,
DistanceUnit::Parsec, DistanceUnit::Kiloparsec, DistanceUnit::Megaparsec,
DistanceUnit::Gigaparsec, DistanceUnit::Thou, DistanceUnit::Inch,
DistanceUnit::Foot, DistanceUnit::Yard, DistanceUnit::Chain, DistanceUnit::Furlong,
DistanceUnit::Mile, DistanceUnit::League
};
constexpr const std::array<const char*, static_cast<int>(DistanceUnit::League) + 1>
DistanceUnitNamesSingular = {
DistanceUnitNanometer, DistanceUnitMicrometer, DistanceUnitMillimeter,
DistanceUnitMeter, DistanceUnitKilometer, DistanceUnitAU, DistanceUnitLighthour,
DistanceUnitCentimeter, DistanceUnitDecimeter, DistanceUnitMeter,
DistanceUnitKilometer, DistanceUnitAU, DistanceUnitLighthour,
DistanceUnitLightday, DistanceUnitLightmonth, DistanceUnitLightyear,
DistanceUnitParsec, DistanceUnitKiloparsec, DistanceUnitMegaparsec,
DistanceUnitGigaparsec, DistanceUnitThou, DistanceUnitInch, DistanceUnitFoot,
@@ -136,7 +144,8 @@ DistanceUnitNamesSingular = {
constexpr const std::array<const char*, static_cast<int>(DistanceUnit::League) + 1>
DistanceUnitNamesPlural = {
DistanceUnitNanometers, DistanceUnitMicrometers, DistanceUnitMillimeters,
DistanceUnitMeters, DistanceUnitKilometers, DistanceUnitAUs, DistanceUnitLighthours,
DistanceUnitCentimeters, DistanceUnitDecimeters, DistanceUnitMeters,
DistanceUnitKilometers, DistanceUnitAUs, DistanceUnitLighthours,
DistanceUnitLightdays, DistanceUnitLightmonths, DistanceUnitLightyears,
DistanceUnitParsecs, DistanceUnitKiloparsecs, DistanceUnitMegaparsecs,
DistanceUnitGigaparsecs, DistanceUnitThous, DistanceUnitInches, DistanceUnitFeet,
@@ -168,6 +177,8 @@ constexpr const char* nameForDistanceUnit(DistanceUnit unit, bool pluralForm = f
case DistanceUnit::Nanometer:
case DistanceUnit::Micrometer:
case DistanceUnit::Millimeter:
case DistanceUnit::Centimeter:
case DistanceUnit::Decimeter:
case DistanceUnit::Meter:
case DistanceUnit::Kilometer:
case DistanceUnit::AU:
@@ -232,7 +243,7 @@ constexpr DistanceUnit distanceUnitFromString(const char* unitName) {
std::pair<double, std::string> simplifyDistance(double meters,
bool forceSingularForm = false);
constexpr double convertDistance(double meters, DistanceUnit requestedUnit) {
constexpr double convertMeters(double meters, DistanceUnit requestedUnit) {
switch (requestedUnit) {
case DistanceUnit::Nanometer:
return meters / 1e-9;
@@ -240,6 +251,10 @@ constexpr double convertDistance(double meters, DistanceUnit requestedUnit) {
return meters / 1e-6;
case DistanceUnit::Millimeter:
return meters / 1e-3;
case DistanceUnit::Centimeter:
return meters / 1e-2;
case DistanceUnit::Decimeter:
return meters / 1e-1;
case DistanceUnit::Meter:
return meters;
case DistanceUnit::Kilometer:
@@ -262,33 +277,90 @@ constexpr double convertDistance(double meters, DistanceUnit requestedUnit) {
return meters / (1e6 * distanceconstants::Parsec);
case DistanceUnit::Gigaparsec:
return meters / (1e9 * distanceconstants::Parsec);
// Such wow, such coefficients
case DistanceUnit::Thou:
return (meters * 1000.0 / 25.4) * 1000.0; // m -> mm -> inch -> thou
return meters / (1e-3 * distanceconstants::Inch);
case DistanceUnit::Inch:
return (meters * 1000.0 / 25.4); // m -> mm -> inch
return meters / distanceconstants::Inch;
case DistanceUnit::Foot:
return (meters * 1000.0 / 25.4) / 12.0; // m -> mm -> inch -> feet
return meters / distanceconstants::Foot;
case DistanceUnit::Yard:
// m -> mm -> inch -> feet -> yard
return (meters * 1000.0 / 25.4) / 12.0 / 3.0;
return meters / distanceconstants::Yard;
case DistanceUnit::Chain:
// m -> mm -> inch -> feet -> yard -> chain
return (meters * 1000.0 / 25.4) / 12.0 / 3.0 / 22.0;
return meters / distanceconstants::Chain;
case DistanceUnit::Furlong:
// m -> mm -> inch -> feet -> yard -> chain -> furlong
return (meters * 1000.0 / 25.4) / 12.0 / 3.0 / 22.0 / 10.0;
return meters / (10.0 * distanceconstants::Chain);
case DistanceUnit::Mile:
// m -> mm -> inch -> feet -> yard -> chain -> furlong -> mile
return (meters * 1000.0 / 25.4) / 12.0 / 3.0 / 22.0 / 10.0 / 8.0;
return meters / distanceconstants::Mile;
case DistanceUnit::League:
// m -> mm -> inch -> feet -> yard -> chain -> furlong -> mile -> league
return (meters * 1000.0 / 25.4) / 12.0 / 3.0 / 22.0 / 10.0 / 8.0 / 3.0;
return meters / (3.0 * distanceconstants::Mile);
default:
throw ghoul::MissingCaseException();
}
}
constexpr double toMeter(DistanceUnit unit) {
switch (unit) {
case DistanceUnit::Nanometer:
return 1e-9;
case DistanceUnit::Micrometer:
return 1e-6;
case DistanceUnit::Millimeter:
return 1e-3;
case DistanceUnit::Centimeter:
return 1e-2;
case DistanceUnit::Decimeter:
return 1e-1;
case DistanceUnit::Meter:
return 1.0;
case DistanceUnit::Kilometer:
return 1000.0;
case DistanceUnit::AU:
return distanceconstants::AstronomicalUnit;
case DistanceUnit::Lighthour:
return distanceconstants::LightHour;
case DistanceUnit::Lightday:
return distanceconstants::LightDay;
case DistanceUnit::Lightmonth:
return distanceconstants::LightMonth;
case DistanceUnit::Lightyear:
return distanceconstants::LightYear;
case DistanceUnit::Parsec:
return distanceconstants::Parsec;
case DistanceUnit::Kiloparsec:
return 1e3 * distanceconstants::Parsec;
case DistanceUnit::Megaparsec:
return 1e6 * distanceconstants::Parsec;
case DistanceUnit::Gigaparsec:
return 1e9 * distanceconstants::Parsec;
case DistanceUnit::Thou:
return 1e-3 * distanceconstants::Inch;
case DistanceUnit::Inch:
return distanceconstants::Inch;
case DistanceUnit::Foot:
return distanceconstants::Foot;
case DistanceUnit::Yard:
return distanceconstants::Yard;
case DistanceUnit::Chain:
return distanceconstants::Chain;
case DistanceUnit::Furlong:
return 10.0 * distanceconstants::Chain;
case DistanceUnit::Mile:
return distanceconstants::Mile;
case DistanceUnit::League:
return 3.0 * distanceconstants::Mile;
default:
throw ghoul::MissingCaseException();
}
}
constexpr double convertUnit(DistanceUnit fromUnit, DistanceUnit toUnit) {
return convertMeters(toMeter(fromUnit), toUnit);
}
constexpr double convertDistance(double distance, DistanceUnit fromUnit, DistanceUnit toUnit) {
return distance * convertUnit(fromUnit, toUnit);
}
float convertMasPerYearToMeterPerSecond(float masPerYear, float parallax);
} // namespace openspace

View File

@@ -22,30 +22,47 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___SIGNEDCHARPROPERTY___H__
#define __OPENSPACE_CORE___SIGNEDCHARPROPERTY___H__
#ifndef __OPENSPACE_CORE___JSON_HELPER___H__
#define __OPENSPACE_CORE___JSON_HELPER___H__
/**
* \file signedcharproperty.h
*
* \addtogroup openspace
* @{
* \addtogroup properties
* @{
#include <string>
* \class SignedCharProperty
* This class is a concrete implementation of openspace::properties::TemplateProperty with
* the type <code>signed char</code>.
namespace openspace {
* @} @}
/**
* 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);
#include <openspace/properties/numericalproperty.h>
/**
* 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<std::string>& list);
namespace openspace::properties {
/**
* 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);
REGISTER_NUMERICALPROPERTY_HEADER(SignedCharProperty, signed char)
/**
* Convert the input value to a valid JSON formatted string
* \param value The value to be converted
* \return The resulting JSON formatted string
*/
template <typename T>
std::string formatJson(T value);
} // namespace openspace::properties
} // namespace openspace
#endif // __OPENSPACE_CORE___SIGNEDCHARPROPERTY___H__
#include "json_helper.inl"
#endif // __OPENSPACE_CORE___JSON_HELPER___H__

View File

@@ -22,80 +22,75 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <typeinfo>
#include <ghoul/fmt.h>
#include <ghoul/glm.h>
#include <ghoul/misc/dictionaryjsonformatter.h>
#include <type_traits>
namespace openspace::properties {
namespace openspace {
namespace internal {
template <class T, class... Ts>
struct is_any : std::disjunction<std::is_same<T, Ts>...> {};
template <typename T>
std::string PropertyDelegate<T>::className() {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::className specialization");
return "";
constexpr bool isGlmMatrix() {
return is_any<T,
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>::value;
}
template <typename T>
template <typename U>
U PropertyDelegate<T>::defaultValue() {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::defaultValue specialization");
constexpr bool isGlmVector() {
return is_any<T,
glm::vec2, glm::vec3, glm::vec4,
glm::ivec2, glm::ivec3, glm::ivec4,
glm::dvec2, glm::dvec3, glm::dvec4,
glm::uvec2, glm::uvec3, glm::uvec4>::value;
}
} // namespace internal
template <typename T>
template <typename U>
U PropertyDelegate<T>::defaultMinimumValue() {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::defaultMinimumValue specialization");
std::string formatJson(T value) {
if constexpr (std::is_same_v<T, bool>) {
return value ? "true" : "false";
}
else if constexpr (std::is_arithmetic_v<T>) {
return formatJsonNumber(static_cast<double>(value));
}
else if constexpr (std::is_same_v<T, std::string>) {
return escapedJson(value);
}
else if constexpr (std::is_same_v<T, ghoul::Dictionary>) {
return ghoul::formatJson(value);
}
else if constexpr (internal::isGlmVector<T>()) {
std::string values;
for (glm::length_t i = 0; i < ghoul::glm_components<T>::value; ++i) {
values += std::to_string(value[i]) + ',';
}
values.pop_back();
return fmt::format("[{}]", values);
}
else if constexpr (internal::isGlmMatrix<T>()) {
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 <typename T>
template <typename U>
U PropertyDelegate<T>::defaultMaximumValue() {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::defaultMaximumValue specialization");
}
template <typename T>
template <typename U>
U PropertyDelegate<T>::defaultSteppingValue() {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::defaultSteppingValue specialization");
}
template <typename T>
template <typename U>
U PropertyDelegate<T>::fromLuaValue(lua_State*, bool&) {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::fromLuaValue specialization");
}
template <typename T>
template <typename U>
bool PropertyDelegate<T>::toLuaValue(lua_State*, const U&) {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::toLuaValue specialization");
return false;
}
template <typename T>
int PropertyDelegate<T>::typeLua() {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::luaType specialization");
return 0;
}
template <typename T>
template <typename U>
bool PropertyDelegate<T>::toString(std::string&, const U&) {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::toString specialization");
return false;
}
template <typename T>
template <typename U>
U PropertyDelegate<T>::fromString(const std::string&, bool&) {
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::fromString specialization");
}
} // namespace openspace::properties
} // namespace openspace

View File

@@ -50,7 +50,7 @@ struct UpdateData {
struct RenderData {
const Camera& camera;
const Time time;
int renderBinMask = -1;
int8_t renderBinMask = -1;
TransformData modelTransform;
};