From 9d6301319b76d10b6adcd8deddd75e16e973025d Mon Sep 17 00:00:00 2001 From: AndreaRigoni Date: Fri, 3 Apr 2026 10:15:16 +0000 Subject: [PATCH] separate display properties from properties --- src/Core/Property.h | 36 ++++++++++++++++-------------------- src/Vtk/uLibVtkInterface.h | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/Core/Property.h b/src/Core/Property.h index 1d86bab..0501646 100644 --- a/src/Core/Property.h +++ b/src/Core/Property.h @@ -20,7 +20,6 @@ namespace uLib { namespace Archive { class property_register_archive; -class display_properties_archive; } /** @@ -68,7 +67,6 @@ public: virtual void serialize(Archive::log_archive & ar, const unsigned int version) override = 0; virtual void serialize(Archive::property_register_archive & ar, const unsigned int v) = 0; - virtual void serialize(Archive::display_properties_archive & ar, const unsigned int v) = 0; }; /** @@ -109,7 +107,9 @@ public: const T& Get() const { return *m_value; } void Set(const T& value) { T val = value; - if (m_HasRange) { if (val < m_Min) val = m_Min; if (val > m_Max) val = m_Max; } + if constexpr (std::is_arithmetic::value) { + if (m_HasRange) { if (val < m_Min) val = m_Min; if (val > m_Max) val = m_Max; } + } if (*m_value != val) { *m_value = val; ULIB_SIGNAL_EMIT(Property::PropertyChanged); @@ -168,7 +168,6 @@ public: virtual void serialize(Archive::log_archive & ar, const unsigned int v) override { serialize_helper(ar, v); } virtual void serialize(Archive::property_register_archive & ar, const unsigned int v) override; - virtual void serialize(Archive::display_properties_archive & ar, const unsigned int v) override; virtual void Updated() override { PropertyBase::Updated(); this->PropertyChanged(); } @@ -213,7 +212,6 @@ public: virtual void serialize(Archive::log_archive & ar, const unsigned int v) override { serialize_enum_helper(ar, v); } virtual void serialize(Archive::property_register_archive & ar, const unsigned int v) override; - virtual void serialize(Archive::display_properties_archive & ar, const unsigned int v) override; private: std::vector m_Labels; @@ -352,12 +350,6 @@ protected: std::set m_Visited; }; -class display_properties_archive : public property_register_archive { -public: - friend class boost::archive::detail::interface_oarchive; - display_properties_archive(Object* obj) : property_register_archive(obj, true) {} -}; - } // namespace Archive } // namespace uLib @@ -368,19 +360,10 @@ inline void Property::serialize(Archive::property_register_archive & ar, cons ar.register_property(*this); } -template -inline void Property::serialize(Archive::display_properties_archive & ar, const unsigned int v) { - ar.register_property(*this); -} - inline void EnumProperty::serialize(Archive::property_register_archive & ar, const unsigned int v) { ar.register_enum_property(*this); } -inline void EnumProperty::serialize(Archive::display_properties_archive & ar, const unsigned int v) { - ar.register_enum_property(*this); -} - namespace Archive { #define ULIB_ACTIVATE_PROPERTIES(obj) \ @@ -397,6 +380,19 @@ private: \ } // namespace Archive +// Convenience macro: declares a named Property member with a default value. +// Usage inside a class body (requires 'this' to be available, so use in-class initializer): +// ULIB_PROPERTY(int, MyProp, 42) +#define ULIB_PROPERTY(type, name, defaultVal) \ + ::uLib::Property name{this, #name, (type)(defaultVal)}; + +// Common property type aliases +typedef Property BoolProperty; +typedef Property IntProperty; +typedef Property FloatProperty; +typedef Property DoubleProperty; +typedef Property StringProperty; + template void serialize_properties_helper(ArchiveT &ar, const std::vector &props, unsigned int version) { for (auto* prop : props) prop->serialize(ar, version); diff --git a/src/Vtk/uLibVtkInterface.h b/src/Vtk/uLibVtkInterface.h index d797f84..42ef572 100644 --- a/src/Vtk/uLibVtkInterface.h +++ b/src/Vtk/uLibVtkInterface.h @@ -284,6 +284,21 @@ public: void save_override(const boost::archive::class_name_type &t) {} void save_override(const boost::archive::tracking_type &t) {} + // Called by Property::serialize() and EnumProperty::serialize() to + // directly register an existing property object as a display property. + void register_property(uLib::PropertyBase &p) { + if (m_Puppet) { + m_Puppet->RegisterDisplayProperty(&p); + Vtk::Puppet *puppet = m_Puppet; + uLib::Object::connect(&p, &uLib::PropertyBase::Updated, + [puppet]() { puppet->Update(); }); + } + } + + void register_enum_property(uLib::EnumProperty &p) { + register_property(p); + } + private: Vtk::Puppet *m_Puppet; std::vector m_GroupStack;