separate display properties from properties
This commit is contained in:
@@ -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<T>::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<T>::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<std::string> m_Labels;
|
||||
@@ -352,12 +350,6 @@ protected:
|
||||
std::set<const void*> m_Visited;
|
||||
};
|
||||
|
||||
class display_properties_archive : public property_register_archive {
|
||||
public:
|
||||
friend class boost::archive::detail::interface_oarchive<display_properties_archive>;
|
||||
display_properties_archive(Object* obj) : property_register_archive(obj, true) {}
|
||||
};
|
||||
|
||||
} // namespace Archive
|
||||
} // namespace uLib
|
||||
|
||||
@@ -368,19 +360,10 @@ inline void Property<T>::serialize(Archive::property_register_archive & ar, cons
|
||||
ar.register_property(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void Property<T>::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<T> 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<type> name{this, #name, (type)(defaultVal)};
|
||||
|
||||
// Common property type aliases
|
||||
typedef Property<bool> BoolProperty;
|
||||
typedef Property<int> IntProperty;
|
||||
typedef Property<float> FloatProperty;
|
||||
typedef Property<double> DoubleProperty;
|
||||
typedef Property<std::string> StringProperty;
|
||||
|
||||
template <class ArchiveT>
|
||||
void serialize_properties_helper(ArchiveT &ar, const std::vector<PropertyBase*> &props, unsigned int version) {
|
||||
for (auto* prop : props) prop->serialize(ar, version);
|
||||
|
||||
@@ -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<T>::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<std::string> m_GroupStack;
|
||||
|
||||
Reference in New Issue
Block a user