mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-22 12:59:07 -06:00
Update codegen repository and make use of it
This commit is contained in:
Submodule ext/ghoul updated: 80f08aead8...e11e97d203
@@ -22,6 +22,8 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
|
||||
namespace {
|
||||
|
||||
// Checks if the passed identifier corresponds to an action.
|
||||
@@ -69,6 +71,27 @@ namespace {
|
||||
global::actionManager->removeAction(identifier);
|
||||
}
|
||||
|
||||
struct [[codegen::Dictionary(Action)]] Action {
|
||||
// The identifier under which the action is registered
|
||||
std::string identifier;
|
||||
|
||||
// The Lua script that is to be executed when the action is triggered
|
||||
std::string command;
|
||||
|
||||
// The user-facing name of the action
|
||||
std::optional<std::string> name;
|
||||
|
||||
// A documentation that explains what the action does
|
||||
std::optional<std::string> documentation;
|
||||
|
||||
// The path in the GUI under which the action is shown to the user. If the value is
|
||||
// not provided, the default value is /
|
||||
std::optional<std::string> guiPath;
|
||||
|
||||
// Determines whether the provided command will be executed locally or will be sent to
|
||||
// connected computers in a cluster or parallel connection environment
|
||||
std::optional<bool> isLocal;
|
||||
};
|
||||
/**
|
||||
* Registers a new action. The first argument is the identifier which cannot have been
|
||||
* used to register a previous action before, the second argument is the Lua command that
|
||||
@@ -78,50 +101,26 @@ namespace {
|
||||
* whether the action should be executed locally (= false) or remotely (= true, the
|
||||
* default).
|
||||
*/
|
||||
[[codegen::luawrap]] void registerAction(ghoul::Dictionary action) {
|
||||
[[codegen::luawrap]] void registerAction(Action action) {
|
||||
using namespace openspace;
|
||||
|
||||
if (!action.hasValue<std::string>("Identifier")) {
|
||||
throw ghoul::lua::LuaError("Identifier must to provided to register action");
|
||||
}
|
||||
std::string identifier = action.value<std::string>("Identifier");
|
||||
if (global::actionManager->hasAction(identifier)) {
|
||||
throw ghoul::lua::LuaError(
|
||||
fmt::format("Action for identifier '{}' already existed", identifier)
|
||||
);
|
||||
}
|
||||
if (global::actionManager->hasAction(identifier)) {
|
||||
throw ghoul::lua::LuaError(
|
||||
fmt::format("Identifier '{}' for action already registered", identifier)
|
||||
);
|
||||
}
|
||||
|
||||
if (!action.hasValue<std::string>("Command")) {
|
||||
throw ghoul::lua::LuaError(
|
||||
fmt::format(
|
||||
"Identifier '{}' does not provide a Lua command to execute", identifier
|
||||
)
|
||||
);
|
||||
if (global::actionManager->hasAction(action.identifier)) {
|
||||
throw ghoul::lua::LuaError(fmt::format(
|
||||
"Identifier '{}' for action already registered", action.identifier
|
||||
));
|
||||
}
|
||||
|
||||
interaction::Action a;
|
||||
a.identifier = std::move(identifier);
|
||||
a.command = action.value<std::string>("Command");
|
||||
if (action.hasValue<std::string>("Name")) {
|
||||
a.name = action.value<std::string>("Name");
|
||||
a.identifier = std::move(action.identifier);
|
||||
a.command = std::move(action.command);
|
||||
a.name = action.name.value_or(a.name);
|
||||
a.documentation = action.documentation.value_or(a.documentation);
|
||||
a.guiPath = action.guiPath.value_or(a.guiPath);
|
||||
if (!a.guiPath.starts_with('/')) {
|
||||
throw ghoul::RuntimeError("Action's GuiPath must start with /");
|
||||
}
|
||||
if (action.hasValue<std::string>("Documentation")) {
|
||||
a.documentation = action.value<std::string>("Documentation");
|
||||
}
|
||||
if (action.hasValue<std::string>("GuiPath")) {
|
||||
a.guiPath = action.value<std::string>("GuiPath");
|
||||
if (!a.guiPath.starts_with('/')) {
|
||||
throw ghoul::RuntimeError("Action's GuiPath must start with /");
|
||||
}
|
||||
}
|
||||
if (action.hasValue<bool>("IsLocal")) {
|
||||
bool value = action.value<bool>("IsLocal");
|
||||
a.synchronization = interaction::Action::IsSynchronized(value);
|
||||
if (action.isLocal.has_value()) {
|
||||
a.synchronization = interaction::Action::IsSynchronized(*action.isLocal);
|
||||
}
|
||||
global::actionManager->registerAction(std::move(a));
|
||||
}
|
||||
|
||||
@@ -70,17 +70,6 @@ namespace {
|
||||
[[codegen::luawrap]] void setNavigationState(ghoul::Dictionary navigationState) {
|
||||
using namespace openspace;
|
||||
|
||||
documentation::TestResult r = documentation::testSpecification(
|
||||
interaction::NavigationState::Documentation(),
|
||||
navigationState
|
||||
);
|
||||
|
||||
if (!r.success) {
|
||||
throw ghoul::lua::LuaError(
|
||||
fmt::format("Could not set camera state: {}", ghoul::to_string(r))
|
||||
);
|
||||
}
|
||||
|
||||
global::navigationHandler->setNavigationStateNextFrame(
|
||||
interaction::NavigationState(navigationState)
|
||||
);
|
||||
|
||||
@@ -967,6 +967,38 @@ void createCustomProperty(openspace::properties::Property::PropertyInfo info,
|
||||
openspace::global::userPropertyOwner->addProperty(p);
|
||||
}
|
||||
|
||||
enum class [[codegen::enum]] CustomPropertyType {
|
||||
DMat2Property,
|
||||
DMat3Property,
|
||||
DMat4Property,
|
||||
Mat2Property,
|
||||
Mat3Property,
|
||||
Mat4Property,
|
||||
BoolProperty,
|
||||
DoubleProperty,
|
||||
FloatProperty,
|
||||
IntProperty,
|
||||
StringProperty,
|
||||
StringListProperty,
|
||||
LongProperty,
|
||||
ShortProperty,
|
||||
UShortProperty,
|
||||
UIntProperty,
|
||||
ULongProperty,
|
||||
DVec2Property,
|
||||
DVec3Property,
|
||||
DVec4Property,
|
||||
IVec2Property,
|
||||
IVec3Property,
|
||||
IVec4Property,
|
||||
UVec2Property,
|
||||
UVec3Property,
|
||||
UVec4Property,
|
||||
Vec2Property,
|
||||
Vec3Property,
|
||||
Vec4Property
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new property that lives in the `UserProperty` group.
|
||||
*
|
||||
@@ -984,12 +1016,14 @@ void createCustomProperty(openspace::properties::Property::PropertyInfo info,
|
||||
* \param description A description what the property is used for
|
||||
* \param onChange A Lua script that will be executed whenever the property changes
|
||||
*/
|
||||
[[codegen::luawrap]] void addCustomProperty(std::string identifier, std::string type,
|
||||
[[codegen::luawrap]] void addCustomProperty(std::string identifier,
|
||||
CustomPropertyType type,
|
||||
std::optional<std::string> guiName,
|
||||
std::optional<std::string> description,
|
||||
std::optional<std::string> onChange)
|
||||
{
|
||||
using namespace openspace;
|
||||
using namespace openspace::properties;
|
||||
|
||||
if (identifier.empty()) {
|
||||
throw ghoul::lua::LuaError("Identifier must not empty");
|
||||
@@ -1013,101 +1047,101 @@ void createCustomProperty(openspace::properties::Property::PropertyInfo info,
|
||||
guiName->c_str() :
|
||||
identifier.c_str();
|
||||
|
||||
properties::Property::PropertyInfo info = {
|
||||
Property::PropertyInfo info = {
|
||||
identifier.c_str(),
|
||||
gui,
|
||||
description.has_value() ? description->c_str() : ""
|
||||
};
|
||||
if (type == "DMat2Property") {
|
||||
createCustomProperty<properties::DMat2Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "DMat3Property") {
|
||||
createCustomProperty<properties::DMat3Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "DMat4Property") {
|
||||
createCustomProperty<properties::DMat4Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "Mat2Property") {
|
||||
createCustomProperty<properties::Mat2Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "Mat3Property") {
|
||||
createCustomProperty<properties::Mat3Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "Mat4Property") {
|
||||
createCustomProperty<properties::Mat4Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "BoolProperty") {
|
||||
createCustomProperty<properties::BoolProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "DoubleProperty") {
|
||||
createCustomProperty<properties::DoubleProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "FloatProperty") {
|
||||
createCustomProperty<properties::FloatProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "IntProperty") {
|
||||
createCustomProperty<properties::IntProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "StringProperty") {
|
||||
createCustomProperty<properties::StringProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "StringListProperty") {
|
||||
createCustomProperty<properties::StringListProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "LongProperty") {
|
||||
createCustomProperty<properties::LongProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "ShortProperty") {
|
||||
createCustomProperty<properties::ShortProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "UIntProperty") {
|
||||
createCustomProperty<properties::UIntProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "ULongProperty") {
|
||||
createCustomProperty<properties::ULongProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "UShortProperty") {
|
||||
createCustomProperty<properties::UShortProperty>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "DVec2Property") {
|
||||
createCustomProperty<properties::DVec2Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "DVec3Property") {
|
||||
createCustomProperty<properties::DVec3Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "DVec4Property") {
|
||||
createCustomProperty<properties::DVec4Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "IVec2Property") {
|
||||
createCustomProperty<properties::IVec2Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "IVec3Property") {
|
||||
createCustomProperty<properties::IVec3Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "IVec4Property") {
|
||||
createCustomProperty<properties::IVec4Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "UVec2Property") {
|
||||
createCustomProperty<properties::UVec2Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "UVec3Property") {
|
||||
createCustomProperty<properties::UVec3Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "UVec4Property") {
|
||||
createCustomProperty<properties::UVec4Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "Vec2Property") {
|
||||
createCustomProperty<properties::Vec2Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "Vec3Property") {
|
||||
createCustomProperty<properties::Vec3Property>(info, std::move(onChange));
|
||||
}
|
||||
else if (type == "Vec4Property") {
|
||||
createCustomProperty<properties::Vec4Property>(info, std::move(onChange));
|
||||
}
|
||||
else {
|
||||
throw ghoul::lua::LuaError(fmt::format("Unsupported type {}", type));
|
||||
switch (type) {
|
||||
case CustomPropertyType::DMat2Property:
|
||||
createCustomProperty<DMat2Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::DMat3Property:
|
||||
createCustomProperty<DMat3Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::DMat4Property:
|
||||
createCustomProperty<DMat4Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::Mat2Property:
|
||||
createCustomProperty<Mat2Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::Mat3Property:
|
||||
createCustomProperty<Mat3Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::Mat4Property:
|
||||
createCustomProperty<Mat4Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::BoolProperty:
|
||||
createCustomProperty<BoolProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::DoubleProperty:
|
||||
createCustomProperty<DoubleProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::FloatProperty:
|
||||
createCustomProperty<FloatProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::IntProperty:
|
||||
createCustomProperty<IntProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::StringProperty:
|
||||
createCustomProperty<StringProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::StringListProperty:
|
||||
createCustomProperty<StringListProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::LongProperty:
|
||||
createCustomProperty<LongProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::ShortProperty:
|
||||
createCustomProperty<ShortProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::UIntProperty:
|
||||
createCustomProperty<UIntProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::ULongProperty:
|
||||
createCustomProperty<ULongProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::UShortProperty:
|
||||
createCustomProperty<UShortProperty>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::DVec2Property:
|
||||
createCustomProperty<DVec2Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::DVec3Property:
|
||||
createCustomProperty<DVec3Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::DVec4Property:
|
||||
createCustomProperty<DVec4Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::IVec2Property:
|
||||
createCustomProperty<IVec2Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::IVec3Property:
|
||||
createCustomProperty<IVec3Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::IVec4Property:
|
||||
createCustomProperty<IVec4Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::UVec2Property:
|
||||
createCustomProperty<UVec2Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::UVec3Property:
|
||||
createCustomProperty<UVec3Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::UVec4Property:
|
||||
createCustomProperty<UVec4Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::Vec2Property:
|
||||
createCustomProperty<Vec2Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::Vec3Property:
|
||||
createCustomProperty<Vec3Property>(info, std::move(onChange));
|
||||
return;
|
||||
case CustomPropertyType::Vec4Property:
|
||||
createCustomProperty<Vec4Property>(info, std::move(onChange));
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error("Missing case label");
|
||||
}
|
||||
|
||||
[[codegen::luawrap]] void removeCustomProperty(std::string identifier) {
|
||||
|
||||
Submodule support/coding/codegen updated: 63d7ae2731...be55036b25
Reference in New Issue
Block a user