Compare commits
2 Commits
b52ae808b8
...
5d0efb3078
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d0efb3078 | ||
|
|
94843de711 |
@@ -140,7 +140,7 @@ QVariant ContextModel::data(const QModelIndex& index, int role) const {
|
||||
|
||||
QVariant ContextModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) {
|
||||
return "Object Type";
|
||||
return "Object Context";
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ class QTreeView;
|
||||
class QVBoxLayout;
|
||||
class QLabel;
|
||||
class ContextModel;
|
||||
class QSplitter;
|
||||
|
||||
|
||||
namespace uLib {
|
||||
class Object;
|
||||
@@ -18,8 +20,6 @@ namespace uLib {
|
||||
}
|
||||
}
|
||||
|
||||
class QSplitter;
|
||||
|
||||
class ContextPanel : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -41,6 +41,7 @@ private:
|
||||
QTreeView* m_treeView;
|
||||
ContextModel* m_model;
|
||||
QSplitter* m_splitter;
|
||||
|
||||
uLib::Vtk::QViewport* m_vtkView;
|
||||
uLib::Vtk::vtkObjectsContext* m_vtkContext;
|
||||
uLib::ObjectsContext* m_context;
|
||||
|
||||
@@ -198,20 +198,16 @@ public:
|
||||
return &bpos;
|
||||
}
|
||||
|
||||
template <class T> Archive &operator<<(T &t) {
|
||||
template <class T> Archive &operator<<(const T &t) {
|
||||
// to get access you must redefine save_override by typing
|
||||
// "using save_override" in archive impl
|
||||
this->This()->save_override(t);
|
||||
return *this->This();
|
||||
}
|
||||
|
||||
|
||||
// the & operator
|
||||
template <class T> Archive &operator&(T &t) {
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
return *this->This() << const_cast<const T &>(t);
|
||||
#else
|
||||
template <class T> Archive &operator&(const T &t) {
|
||||
return *this->This() << t;
|
||||
#endif
|
||||
}
|
||||
|
||||
// the == operator
|
||||
@@ -364,7 +360,6 @@ public:
|
||||
boost::serialization::hrp<T> &t) {
|
||||
this->This()->load_start(t.name());
|
||||
this->detail_common_iarchive::load_override(t.value());
|
||||
// t.stov();
|
||||
this->This()->load_end(t.name());
|
||||
}
|
||||
|
||||
@@ -432,8 +427,7 @@ public:
|
||||
#endif
|
||||
::boost::serialization::hrp<T> &t) {
|
||||
this->This()->save_start(t.name());
|
||||
// t.vtos();
|
||||
// this->detail_common_oarchive::save_override(t.const_value());
|
||||
this->detail_common_oarchive::save_override(t.const_value());
|
||||
this->This()->save_end(t.name());
|
||||
}
|
||||
|
||||
@@ -467,14 +461,10 @@ public:
|
||||
text_iarchive(std::istream &is, unsigned int flags = 0)
|
||||
: text_iarchive_impl<Archive>(is, flags) {}
|
||||
|
||||
using basic_text_iarchive::load_override;
|
||||
using base::load_override;
|
||||
|
||||
void load_override(boost::archive::object_id_type &t) {}
|
||||
|
||||
// class_name_type can't be handled here as it depends upon the
|
||||
// char type used by the stream. So require the derived implementation.
|
||||
// derived in this case is xml_iarchive_impl or base ..
|
||||
using base::load_override;
|
||||
|
||||
void load_override(const char *str) {
|
||||
StringReader sr(basic_text_iprimitive::is);
|
||||
@@ -532,7 +522,7 @@ public:
|
||||
hrt_iarchive(std::istream &is, unsigned int flags = 0)
|
||||
: base(is, flags | boost::archive::no_header) {}
|
||||
|
||||
using basic_text_iarchive::load_override;
|
||||
using base::load_override;
|
||||
|
||||
// hide all archive props //
|
||||
void load_override(boost::archive::object_id_type &t) {}
|
||||
@@ -544,10 +534,6 @@ public:
|
||||
void load_override(boost::archive::class_name_type &t) {}
|
||||
void load_override(boost::archive::tracking_type &t) {}
|
||||
|
||||
// class_name_type can't be handled here as it depends upon the
|
||||
// char type used by the stream. So require the derived implementation.
|
||||
// derived in this case is xml_iarchive_impl or base ..
|
||||
using base::load_override;
|
||||
|
||||
void load_override(const char *str) {
|
||||
StringReader sr(basic_text_iprimitive::is);
|
||||
@@ -583,6 +569,13 @@ public:
|
||||
|
||||
void save_override(const char *str) { basic_text_oprimitive::save(str); }
|
||||
|
||||
template <class T>
|
||||
void save_override(const boost::serialization::hrp<T> &t) {
|
||||
*this << t.name() << ": ";
|
||||
*this << t.const_value();
|
||||
*this << "\n";
|
||||
}
|
||||
|
||||
~hrt_oarchive() {}
|
||||
};
|
||||
|
||||
@@ -611,7 +604,7 @@ public:
|
||||
// basic_text_oprimitive::save(str);
|
||||
}
|
||||
|
||||
template <class T> void save_override(T &t) {
|
||||
template <class T> void save_override(const T &t) {
|
||||
base::save_override(boost::serialization::make_nvp(NULL, t));
|
||||
}
|
||||
|
||||
@@ -627,6 +620,10 @@ public:
|
||||
base::save_override(t);
|
||||
}
|
||||
|
||||
template <class T> void save_override(const boost::serialization::hrp<T> &t) {
|
||||
base::save_override(boost::serialization::make_nvp(t.name(), t.const_value()));
|
||||
}
|
||||
|
||||
// specific overrides for attributes - not name value pairs so we
|
||||
// want to trap them before the above "fall through"
|
||||
// since we don't want to see these in the output - make them no-ops.
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "SmartPointer.h"
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <TObject.h>
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
#include "boost/archive/polymorphic_xml_iarchive.hpp"
|
||||
#include "boost/archive/polymorphic_xml_oarchive.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include "Property.h"
|
||||
|
||||
namespace uLib {
|
||||
|
||||
const char *Version::PackageName = PACKAGE_NAME;
|
||||
@@ -60,8 +63,51 @@ public:
|
||||
std::string m_InstanceName;
|
||||
Vector<Signal> sigv;
|
||||
Vector<Slot> slov;
|
||||
std::vector<PropertyBase*> m_Properties;
|
||||
std::vector<PropertyBase*> m_DynamicProperties;
|
||||
};
|
||||
|
||||
// Implementations of Property methods
|
||||
void Object::RegisterProperty(PropertyBase* prop) {
|
||||
if (prop) d->m_Properties.push_back(prop);
|
||||
}
|
||||
|
||||
void Object::RegisterDynamicProperty(PropertyBase* prop) {
|
||||
if (prop) {
|
||||
d->m_DynamicProperties.push_back(prop);
|
||||
d->m_Properties.push_back(prop);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<PropertyBase*>& Object::GetProperties() const {
|
||||
return d->m_Properties;
|
||||
}
|
||||
|
||||
// In Object.h, the template serialize needs to be updated to call property serialization.
|
||||
// However, since Object::serialize is a template in the header, we might need a helper here.
|
||||
|
||||
template <class ArchiveT>
|
||||
void Object::serialize(ArchiveT &ar, const unsigned int version) {
|
||||
ar & boost::serialization::make_nvp("InstanceName", d->m_InstanceName);
|
||||
for (auto* prop : d->m_Properties) {
|
||||
prop->serialize(ar, version);
|
||||
}
|
||||
}
|
||||
|
||||
void Object::Updated() { ULIB_SIGNAL_EMIT(Object::Updated); }
|
||||
|
||||
template <class ArchiveT>
|
||||
void Object::save_override(ArchiveT &ar, const unsigned int version) {}
|
||||
|
||||
// Explicitly instantiate for all uLib archives
|
||||
template void Object::serialize(Archive::xml_oarchive &, const unsigned int);
|
||||
template void Object::serialize(Archive::xml_iarchive &, const unsigned int);
|
||||
template void Object::serialize(Archive::text_oarchive &, const unsigned int);
|
||||
template void Object::serialize(Archive::text_iarchive &, const unsigned int);
|
||||
template void Object::serialize(Archive::hrt_oarchive &, const unsigned int);
|
||||
template void Object::serialize(Archive::hrt_iarchive &, const unsigned int);
|
||||
template void Object::serialize(Archive::log_archive &, const unsigned int);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -71,7 +117,12 @@ Object::Object() : d(new ObjectPrivate) {}
|
||||
|
||||
Object::Object(const Object ©) : d(new ObjectPrivate(*copy.d)) {}
|
||||
|
||||
Object::~Object() { delete d; }
|
||||
Object::~Object() {
|
||||
for (auto* p : d->m_DynamicProperties) {
|
||||
delete p;
|
||||
}
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Object::DeepCopy(const Object ©) {
|
||||
// should lock to be tread safe //
|
||||
@@ -146,8 +197,6 @@ GenericMFPtr *Object::findSlotImpl(const char *name) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Object::Updated() { ULIB_SIGNAL_EMIT(Object::Updated); }
|
||||
|
||||
const std::string& Object::GetInstanceName() const {
|
||||
return d->m_InstanceName;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ class polymorphic_oarchive;
|
||||
|
||||
namespace uLib {
|
||||
|
||||
class PropertyBase;
|
||||
|
||||
class Version {
|
||||
public:
|
||||
static const char *PackageName;
|
||||
@@ -79,6 +81,13 @@ public:
|
||||
|
||||
const std::string& GetInstanceName() const;
|
||||
void SetInstanceName(const std::string& name);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// PROPERTIES //
|
||||
void RegisterProperty(PropertyBase* prop);
|
||||
void RegisterDynamicProperty(PropertyBase* prop);
|
||||
const std::vector<PropertyBase*>& GetProperties() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// PARAMETERS //
|
||||
|
||||
@@ -89,9 +98,9 @@ public:
|
||||
// SERIALIZATION //
|
||||
|
||||
template <class ArchiveT>
|
||||
void serialize(ArchiveT &ar, const unsigned int version) {}
|
||||
void serialize(ArchiveT &ar, const unsigned int version);
|
||||
template <class ArchiveT>
|
||||
void save_override(ArchiveT &ar, const unsigned int version) {}
|
||||
void save_override(ArchiveT &ar, const unsigned int version);
|
||||
|
||||
void SaveConfig(std::ostream &os, int version = 0);
|
||||
void LoadConfig(std::istream &is, int version = 0);
|
||||
|
||||
221
src/Core/Property.h
Normal file
221
src/Core/Property.h
Normal file
@@ -0,0 +1,221 @@
|
||||
#ifndef U_CORE_PROPERTY_H
|
||||
#define U_CORE_PROPERTY_H
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <typeinfo>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "Core/Archives.h"
|
||||
#include "Core/Signal.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
namespace uLib {
|
||||
|
||||
/**
|
||||
* @brief Base class for properties to allow runtime listing and identification.
|
||||
*/
|
||||
class PropertyBase : public Object {
|
||||
public:
|
||||
virtual ~PropertyBase() {}
|
||||
virtual const std::string& GetName() const = 0;
|
||||
virtual const char* GetTypeName() const = 0;
|
||||
virtual std::string GetValueAsString() const = 0;
|
||||
|
||||
// Signal support
|
||||
signals:
|
||||
virtual void Updated() override { ULIB_SIGNAL_EMIT(PropertyBase::Updated); }
|
||||
|
||||
// Serialization support for different uLib archives
|
||||
virtual void serialize(Archive::xml_oarchive & ar, const unsigned int version) = 0;
|
||||
virtual void serialize(Archive::xml_iarchive & ar, const unsigned int version) = 0;
|
||||
virtual void serialize(Archive::text_oarchive & ar, const unsigned int version) = 0;
|
||||
virtual void serialize(Archive::text_iarchive & ar, const unsigned int version) = 0;
|
||||
virtual void serialize(Archive::hrt_oarchive & ar, const unsigned int version) = 0;
|
||||
virtual void serialize(Archive::hrt_iarchive & ar, const unsigned int version) = 0;
|
||||
virtual void serialize(Archive::log_archive & ar, const unsigned int version) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Template class for typed properties.
|
||||
*/
|
||||
template <typename T>
|
||||
class Property : public PropertyBase {
|
||||
public:
|
||||
// PROXY: Use an existing variable as back-end storage
|
||||
Property(Object* owner, const std::string& name, T* valuePtr)
|
||||
: m_owner(owner), m_name(name), m_value(valuePtr), m_own(false) {
|
||||
if (m_owner) {
|
||||
m_owner->RegisterProperty(this);
|
||||
}
|
||||
}
|
||||
|
||||
// MANAGED: Create and own internal storage
|
||||
Property(Object* owner, const std::string& name, const T& defaultValue = T())
|
||||
: m_owner(owner), m_name(name), m_value(new T(defaultValue)), m_own(true) {
|
||||
if (m_owner) {
|
||||
m_owner->RegisterProperty(this);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~Property() {
|
||||
if (m_own) delete m_value;
|
||||
}
|
||||
|
||||
const std::string& GetName() const override { return m_name; }
|
||||
const char* GetTypeName() const override { return typeid(T).name(); }
|
||||
|
||||
std::string GetValueAsString() const override {
|
||||
try {
|
||||
return boost::lexical_cast<std::string>(*m_value);
|
||||
} catch (const boost::bad_lexical_cast&) {
|
||||
std::stringstream ss;
|
||||
ss << *m_value;
|
||||
return ss.str();
|
||||
}
|
||||
}
|
||||
|
||||
// Accessors
|
||||
const T& Get() const { return *m_value; }
|
||||
void Set(const T& value) {
|
||||
if (*m_value != value) {
|
||||
*m_value = value;
|
||||
ULIB_SIGNAL_EMIT(Property<T>::PropertyChanged);
|
||||
}
|
||||
}
|
||||
|
||||
// Operators for seamless usage
|
||||
operator const T&() const { return *m_value; }
|
||||
Property& operator=(const T& value) {
|
||||
Set(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Signals
|
||||
signals:
|
||||
virtual void PropertyChanged() { ULIB_SIGNAL_EMIT(Property<T>::PropertyChanged); }
|
||||
|
||||
// Serialization
|
||||
template <class ArchiveT>
|
||||
void serialize_impl(ArchiveT & ar, const unsigned int version) {
|
||||
ar & boost::serialization::make_nvp(m_name.c_str(), *m_value);
|
||||
}
|
||||
|
||||
void serialize(Archive::xml_oarchive & ar, const unsigned int v) override { serialize_impl(ar, v); }
|
||||
void serialize(Archive::xml_iarchive & ar, const unsigned int v) override { serialize_impl(ar, v); }
|
||||
void serialize(Archive::text_oarchive & ar, const unsigned int v) override { serialize_impl(ar, v); }
|
||||
void serialize(Archive::text_iarchive & ar, const unsigned int v) override { serialize_impl(ar, v); }
|
||||
void serialize(Archive::hrt_oarchive & ar, const unsigned int v) override { serialize_impl(ar, v); }
|
||||
void serialize(Archive::hrt_iarchive & ar, const unsigned int v) override { serialize_impl(ar, v); }
|
||||
void serialize(Archive::log_archive & ar, const unsigned int v) override { serialize_impl(ar, v); }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
T* m_value;
|
||||
bool m_own;
|
||||
Object* m_owner;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Conveninent typedefs for common property types.
|
||||
*/
|
||||
typedef Property<std::string> StringProperty;
|
||||
typedef Property<int> IntProperty;
|
||||
typedef Property<unsigned int> UIntProperty;
|
||||
typedef Property<long> LongProperty;
|
||||
typedef Property<unsigned long> ULongProperty;
|
||||
typedef Property<float> FloatProperty;
|
||||
typedef Property<double> DoubleProperty;
|
||||
typedef Property<Bool_t> BoolProperty;
|
||||
|
||||
/**
|
||||
* @brief Macro to simplify property declaration within a class.
|
||||
* Usage: ULIB_PROPERTY(float, Width, 1.0f)
|
||||
* It creates a raw member m_Width and a Property proxy Width.
|
||||
*/
|
||||
#define ULIB_PROPERTY(type, name, defaultValue) \
|
||||
type m_##name = defaultValue; \
|
||||
Property<type> name = Property<type>(this, #name, &m_##name);
|
||||
|
||||
|
||||
} // namespace uLib
|
||||
|
||||
namespace uLib {
|
||||
namespace Archive {
|
||||
class property_register_archive;
|
||||
} // namespace Archive
|
||||
} // namespace uLib
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
namespace detail {
|
||||
template <>
|
||||
class interface_oarchive<uLib::Archive::property_register_archive>
|
||||
: public uLib_interface_oarchive<uLib::Archive::property_register_archive> {};
|
||||
} // namespace detail
|
||||
} // namespace archive
|
||||
} // namespace boost
|
||||
|
||||
namespace uLib {
|
||||
namespace Archive {
|
||||
|
||||
/**
|
||||
* @brief A special archive that creates and registers Property proxies
|
||||
* for any member it encounters wrapped in HRP().
|
||||
*/
|
||||
class property_register_archive :
|
||||
public boost::archive::detail::common_oarchive<property_register_archive>
|
||||
{
|
||||
Object* m_Object;
|
||||
public:
|
||||
friend class boost::archive::detail::interface_oarchive<property_register_archive>;
|
||||
friend class boost::archive::save_access;
|
||||
|
||||
typedef boost::archive::detail::common_oarchive<property_register_archive> detail_common_oarchive;
|
||||
|
||||
property_register_archive(Object* obj) :
|
||||
boost::archive::detail::common_oarchive<property_register_archive>(boost::archive::no_header),
|
||||
m_Object(obj) {}
|
||||
|
||||
// Core logic: encounter HRP -> Create Dynamic Property
|
||||
template<class T>
|
||||
void save_override(const boost::serialization::hrp<T> &t) {
|
||||
if (m_Object) {
|
||||
// We use const_cast because we are just creating a proxy to the member
|
||||
m_Object->RegisterDynamicProperty(
|
||||
new Property<T>(m_Object, t.name(), &const_cast<boost::serialization::hrp<T>&>(t).value())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle standard NVPs by recursing (important for base classes)
|
||||
template<class T>
|
||||
void save_override(const boost::serialization::nvp<T> &t) {
|
||||
this->detail_common_oarchive::save_override(t.const_value());
|
||||
}
|
||||
|
||||
// Ignore everything else
|
||||
template<class T> void save_override(const T &t) {}
|
||||
|
||||
// Required attribute overrides for common_oarchive
|
||||
void save_override(const boost::archive::object_id_type & t) {}
|
||||
void save_override(const boost::archive::object_reference_type & t) {}
|
||||
void save_override(const boost::archive::version_type & t) {}
|
||||
void save_override(const boost::archive::class_id_type & t) {}
|
||||
void save_override(const boost::archive::class_id_optional_type & t) {}
|
||||
void save_override(const boost::archive::class_id_reference_type & t) {}
|
||||
void save_override(const boost::archive::class_name_type & t) {}
|
||||
void save_override(const boost::archive::tracking_type & t) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Convenience macro to automatically activate and register all HRP members
|
||||
* as uLib properties. Usage: ULIB_ACTIVATE_PROPERTIES(obj)
|
||||
*/
|
||||
#define ULIB_ACTIVATE_PROPERTIES(obj) \
|
||||
{ uLib::Archive::property_register_archive _ar_tmp(&(obj)); (obj).serialize(_ar_tmp, 0); }
|
||||
|
||||
} // namespace Archive
|
||||
} // namespace uLib
|
||||
|
||||
#endif // U_CORE_PROPERTY_H
|
||||
@@ -72,39 +72,33 @@ namespace serialization {
|
||||
template <class T> struct access2 {};
|
||||
|
||||
// NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------
|
||||
template <class T> class hrp : public wrapper_traits<const hrp<T>> {
|
||||
template <class T>
|
||||
class hrp : public boost::serialization::wrapper_traits<hrp<T>> {
|
||||
const char *m_name;
|
||||
T *m_value;
|
||||
std::string *m_str;
|
||||
T &m_value;
|
||||
|
||||
public:
|
||||
explicit hrp(const char *name_, T &t)
|
||||
: m_str(new std::string), m_name(name_), m_value(&t) {}
|
||||
explicit hrp(const char *name_, T &t) : m_name(name_), m_value(t) {}
|
||||
|
||||
const char *name() const { return this->m_name; }
|
||||
T &value() { return this->m_value; }
|
||||
const T &const_value() const { return this->m_value; }
|
||||
|
||||
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
||||
|
||||
template <class Archivex>
|
||||
void save(Archivex &ar, const unsigned int /* file_version */) const {
|
||||
//// ar.operator<<(const_value());
|
||||
// std::stringstream ss;
|
||||
// uLib::Archive::hrt_oarchive har(ss);
|
||||
// har << make_nvp(m_name,*m_value);
|
||||
// // (*m_str) = ss.str();
|
||||
//// ar.operator << (make_nvp(m_name, ss.str());
|
||||
void save(Archivex &ar, const unsigned int /* version */) const {
|
||||
ar << boost::serialization::make_nvp(m_name, m_value);
|
||||
}
|
||||
|
||||
template <class Archivex>
|
||||
void load(Archivex &ar, const unsigned int /* file_version */) {
|
||||
// ar.operator>>(value());
|
||||
void load(Archivex &ar, const unsigned int /* version */) {
|
||||
ar >> boost::serialization::make_nvp(m_name, m_value);
|
||||
}
|
||||
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
const
|
||||
#endif
|
||||
hrp<T> make_hrp(const char *name, T &t) {
|
||||
inline hrp<T> make_hrp(const char *name, T &t) {
|
||||
return hrp<T>(name, t);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ typedef id_t Id_t;
|
||||
typedef void *Pointer_t;
|
||||
typedef bool Bool_t; // Boolean (0=false, 1=true) (bool)
|
||||
|
||||
|
||||
//--- bit manipulation ---------------------------------------------------------
|
||||
#ifndef BIT
|
||||
#define BIT(n) (1ULL << (n))
|
||||
|
||||
@@ -21,6 +21,8 @@ set( TESTS
|
||||
OptionsTest
|
||||
PingPongTest
|
||||
VectorMetaAllocatorTest
|
||||
PropertyTypesTest
|
||||
HRPTest
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
|
||||
83
src/Core/testing/HRPTest.cpp
Normal file
83
src/Core/testing/HRPTest.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Property.h"
|
||||
#include "Core/Serializable.h"
|
||||
#include "Core/Archives.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
struct SimpleObject {
|
||||
int value;
|
||||
std::string name;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version) {
|
||||
ar & HRP(value);
|
||||
ar & HRP(name);
|
||||
}
|
||||
};
|
||||
|
||||
struct DynamicObject : public Object {
|
||||
float width;
|
||||
int height;
|
||||
|
||||
DynamicObject() : width(10.0f), height(20) {
|
||||
// Automatic registration of properties based on serialize/HRP
|
||||
ULIB_ACTIVATE_PROPERTIES(*this);
|
||||
}
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version) {
|
||||
ar & HRP(width);
|
||||
ar & HRP(height);
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
SimpleObject obj;
|
||||
obj.value = 42;
|
||||
obj.name = "TestObject";
|
||||
|
||||
std::cout << "Testing HRP Serialization to Log..." << std::endl;
|
||||
std::stringstream ss;
|
||||
{
|
||||
uLib::Archive::log_archive ar(ss);
|
||||
ar << boost::serialization::make_nvp("Object", obj);
|
||||
}
|
||||
std::cout << ss.str() << std::endl;
|
||||
|
||||
std::cout << "Testing HRP Serialization to HRT..." << std::endl;
|
||||
ss.str("");
|
||||
{
|
||||
uLib::Archive::hrt_oarchive ar(ss);
|
||||
ar << obj;
|
||||
}
|
||||
std::cout << ss.str() << std::endl;
|
||||
|
||||
std::cout << "Testing HRP Serialization to XML..." << std::endl;
|
||||
ss.str("");
|
||||
{
|
||||
uLib::Archive::xml_oarchive ar(ss);
|
||||
ar << boost::serialization::make_nvp("Object", obj);
|
||||
}
|
||||
std::cout << ss.str() << std::endl;
|
||||
|
||||
std::cout << "Testing Dynamic Property Creation via ULIB_ACTIVATE_PROPERTIES macro..." << std::endl;
|
||||
DynamicObject dynObj;
|
||||
// (properties were already created in DynamicObject constructor via macro)
|
||||
|
||||
std::cout << "Registered Properties in dynObj:" << std::endl;
|
||||
const auto& props = dynObj.GetProperties();
|
||||
for (auto* p : props) {
|
||||
std::cout << " - [" << p->GetTypeName() << "] " << p->GetName() << " = " << p->GetValueAsString() << std::endl;
|
||||
}
|
||||
|
||||
if (props.size() == 2) {
|
||||
std::cout << "Dynamic Property Creation SUCCESS!" << std::endl;
|
||||
} else {
|
||||
std::cout << "Dynamic Property Creation FAILED (Expected 2, got " << props.size() << ")" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
64
src/Core/testing/PropertySystemTest.cpp
Normal file
64
src/Core/testing/PropertySystemTest.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Property.h"
|
||||
#include <cassert>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
class TestObject : public Object {
|
||||
public:
|
||||
TestObject() : Object(),
|
||||
IntProp(this, "IntProp", 10),
|
||||
StringProp(this, "StringProp", "Initial")
|
||||
{}
|
||||
|
||||
virtual const char* GetClassName() const override { return "TestObject"; }
|
||||
|
||||
Property<int> IntProp;
|
||||
Property<std::string> StringProp;
|
||||
};
|
||||
|
||||
int main() {
|
||||
TestObject obj;
|
||||
|
||||
std::cout << "Testing Properties..." << std::endl;
|
||||
|
||||
// 1. Check registration
|
||||
const auto& props = obj.GetProperties();
|
||||
assert(props.size() == 2);
|
||||
assert(props[0]->GetName() == "IntProp");
|
||||
assert(props[1]->GetName() == "StringProp");
|
||||
|
||||
// 2. Check value access and signals
|
||||
bool signalCalled = false;
|
||||
uLib::Object::connect(&obj.IntProp, &Property<int>::PropertyChanged, [&signalCalled]() {
|
||||
signalCalled = true;
|
||||
});
|
||||
|
||||
assert(obj.IntProp.Get() == 10);
|
||||
obj.IntProp = 20;
|
||||
assert(obj.IntProp.Get() == 20);
|
||||
assert(signalCalled == true);
|
||||
|
||||
// 3. Check serialization
|
||||
std::stringstream ss;
|
||||
Object::SaveXml(ss, obj);
|
||||
std::string xml = ss.str();
|
||||
std::cout << "Serialized XML: \n" << xml << std::endl;
|
||||
|
||||
assert(xml.find("<IntProp>20</IntProp>") != std::string::npos);
|
||||
assert(xml.find("<StringProp>Initial</StringProp>") != std::string::npos);
|
||||
|
||||
// 4. Check deserialization
|
||||
TestObject obj2;
|
||||
std::stringstream ss2(xml);
|
||||
Object::LoadXml(ss2, obj2);
|
||||
|
||||
assert(obj2.IntProp.Get() == 20);
|
||||
assert(obj2.StringProp.Get() == "Initial");
|
||||
|
||||
std::cout << "All Property Tests PASSED!" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
68
src/Core/testing/PropertyTypesTest.cpp
Normal file
68
src/Core/testing/PropertyTypesTest.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Property.h"
|
||||
#include "Math/Dense.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
class TestObject : public Object {
|
||||
public:
|
||||
TestObject() : Object() {}
|
||||
|
||||
virtual const char* GetClassName() const override { return "TestObject"; }
|
||||
|
||||
// Use new typedefs
|
||||
StringProperty StringProp = StringProperty(this, "StringProp", "Initial");
|
||||
IntProperty IntProp = IntProperty(this, "IntProp", 42);
|
||||
FloatProperty FloatProp = FloatProperty(this, "FloatProp", 3.14f);
|
||||
BoolProperty BoolProp = BoolProperty(this, "BoolProp", true);
|
||||
|
||||
// Use new macro
|
||||
ULIB_PROPERTY(Matrix3f, MatrixProp, Matrix3f::Identity())
|
||||
|
||||
// Use new Dense typedefs
|
||||
Vector3fProperty Vector3fProp = Vector3fProperty(this, "Vector3fProp", Vector3f(1.1f, 2.2f, 3.3f));
|
||||
Matrix4fProperty Matrix4fProp = Matrix4fProperty(this, "Matrix4fProp", Matrix4f::Identity());
|
||||
};
|
||||
|
||||
int main() {
|
||||
TestObject obj;
|
||||
|
||||
std::cout << "Testing Property Types..." << std::endl;
|
||||
|
||||
// 1. Verify string representation
|
||||
std::cout << "StringProp: " << obj.StringProp.GetValueAsString() << std::endl;
|
||||
assert(obj.StringProp.GetValueAsString() == "Initial");
|
||||
|
||||
std::cout << "IntProp: " << obj.IntProp.GetValueAsString() << std::endl;
|
||||
assert(obj.IntProp.GetValueAsString() == "42");
|
||||
|
||||
std::cout << "FloatProp: " << obj.FloatProp.GetValueAsString() << std::endl;
|
||||
// boost::lexical_cast might have different precision, but for 3.14 it should be okay or we check find
|
||||
assert(obj.FloatProp.GetValueAsString().find("3.14") != std::string::npos);
|
||||
|
||||
std::cout << "BoolProp: " << obj.BoolProp.GetValueAsString() << std::endl;
|
||||
// Bool might be "1" or "true" depending on lexical_cast/stringstream
|
||||
assert(obj.BoolProp.GetValueAsString() == "1" || obj.BoolProp.GetValueAsString() == "true");
|
||||
|
||||
// 2. Verify Matrix/Vector string representation (uses operator<<)
|
||||
std::cout << "MatrixProp: \n" << obj.MatrixProp.GetValueAsString() << std::endl;
|
||||
assert(obj.MatrixProp.GetValueAsString().find("1 0 0") != std::string::npos);
|
||||
|
||||
std::cout << "Vector3fProp: " << obj.Vector3fProp.GetValueAsString() << std::endl;
|
||||
assert(obj.Vector3fProp.GetValueAsString().find("1.1 2.2 3.3") != std::string::npos);
|
||||
|
||||
std::cout << "Matrix4fProp: \n" << obj.Matrix4fProp.GetValueAsString() << std::endl;
|
||||
assert(obj.Matrix4fProp.GetValueAsString().find("1 0 0 0") != std::string::npos);
|
||||
|
||||
// 3. Verify updates and signals
|
||||
obj.IntProp = 100;
|
||||
assert(obj.IntProp.Get() == 100);
|
||||
assert(obj.IntProp.GetValueAsString() == "100");
|
||||
|
||||
std::cout << "All Property Type Tests PASSED!" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "Geometry.h"
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Property.h"
|
||||
#include "Math/Dense.h"
|
||||
#include "Math/Transform.h"
|
||||
#include <utility>
|
||||
@@ -48,6 +49,11 @@ class ContainerBox : public AffineTransform, public Object {
|
||||
typedef AffineTransform BaseClass;
|
||||
|
||||
public:
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// PROPERTIES //
|
||||
Property<float> Width;
|
||||
Property<float> Height;
|
||||
Property<float> Depth;
|
||||
|
||||
virtual const char * GetClassName() const { return "ContainerBox"; }
|
||||
|
||||
@@ -56,14 +62,28 @@ public:
|
||||
* Initializes the local transformation with this instance as its parent.
|
||||
*/
|
||||
ContainerBox()
|
||||
: m_LocalT(this) // BaseClass is Parent of m_LocalTransform
|
||||
{}
|
||||
: m_LocalT(this), // BaseClass is Parent of m_LocalTransform
|
||||
Width(this, "Width", 1.0f),
|
||||
Height(this, "Height", 1.0f),
|
||||
Depth(this, "Depth", 1.0f) {
|
||||
Object::connect(&Width, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Height, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Depth, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Constructor with size.
|
||||
* @param size The size vector.
|
||||
*/
|
||||
ContainerBox(const Vector3f &size) : m_LocalT(this) { this->SetSize(size); }
|
||||
ContainerBox(const Vector3f &size)
|
||||
: m_LocalT(this),
|
||||
Width(this, "Width", size(0)),
|
||||
Height(this, "Height", size(1)),
|
||||
Depth(this, "Depth", size(2)) {
|
||||
Object::connect(&Width, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Height, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Depth, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
@@ -71,9 +91,14 @@ public:
|
||||
*/
|
||||
ContainerBox(const ContainerBox ©)
|
||||
: m_LocalT(this), // BaseClass is Parent of m_LocalTransform
|
||||
AffineTransform(copy) {
|
||||
AffineTransform(copy),
|
||||
Width(this, "Width", copy.Width),
|
||||
Height(this, "Height", copy.Height),
|
||||
Depth(this, "Depth", copy.Depth) {
|
||||
Object::connect(&Width, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Height, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Depth, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
this->SetOrigin(copy.GetOrigin());
|
||||
this->SetSize(copy.GetSize());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,6 +119,9 @@ public:
|
||||
* @param v The size vector (width, height, depth).
|
||||
*/
|
||||
void SetSize(const Vector3f &v) {
|
||||
Width = v(0);
|
||||
Height = v(1);
|
||||
Depth = v(2);
|
||||
Vector3f pos = this->GetOrigin();
|
||||
m_LocalT = AffineTransform(this); // regenerate local transform
|
||||
m_LocalT.Scale(v);
|
||||
@@ -186,6 +214,10 @@ signals:
|
||||
virtual void Updated() override { ULIB_SIGNAL_EMIT(ContainerBox::Updated); }
|
||||
|
||||
private:
|
||||
void SyncSize() {
|
||||
this->SetSize(Vector3f(Width, Height, Depth));
|
||||
}
|
||||
|
||||
AffineTransform m_LocalT;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Eigen/Dense>
|
||||
#include "Core/Types.h"
|
||||
#include "Core/Property.h"
|
||||
|
||||
//// BOOST SERIALIZATION ///////////////////////////////////////////////////////
|
||||
|
||||
@@ -107,7 +109,6 @@ std::ostream &operator<<(std::ostream &os,
|
||||
namespace uLib {
|
||||
|
||||
typedef id_t Id_t;
|
||||
|
||||
typedef int Scalari;
|
||||
typedef unsigned int Scalarui;
|
||||
typedef long Scalarl;
|
||||
@@ -249,15 +250,53 @@ struct _HError3f {
|
||||
HVector3f position_error;
|
||||
HVector3f direction_error;
|
||||
};
|
||||
typedef struct _HError3f HError3f;
|
||||
typedef struct _HError3f HError3f;
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &stream, const HError3f &err) {
|
||||
stream << "HError3f(" << "ept[" << err.position_error.transpose()
|
||||
<< "] , edr[" << err.direction_error.transpose() << "]) ";
|
||||
return stream;
|
||||
}
|
||||
|
||||
typedef Property<Scalari> ScalariProperty;
|
||||
typedef Property<Scalarui> ScalaruiProperty;
|
||||
typedef Property<Scalarl> ScalarlProperty;
|
||||
typedef Property<Scalarul> ScalarulProperty;
|
||||
typedef Property<Scalarf> ScalarfProperty;
|
||||
typedef Property<Scalard> ScalardProperty;
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &stream, const HError3f &err) {
|
||||
stream << "HError3f(" << "ept[" << err.position_error.transpose()
|
||||
<< "] , edr[" << err.direction_error.transpose() << "]) ";
|
||||
return stream;
|
||||
}
|
||||
typedef Property<Vector1i> Vector1iProperty;
|
||||
typedef Property<Vector1f> Vector1fProperty;
|
||||
typedef Property<Vector1d> Vector1dProperty;
|
||||
|
||||
} // namespace uLib
|
||||
typedef Property<Vector2i> Vector2iProperty;
|
||||
typedef Property<Vector3i> Vector3iProperty;
|
||||
typedef Property<Vector4i> Vector4iProperty;
|
||||
|
||||
typedef Property<Vector2f> Vector2fProperty;
|
||||
typedef Property<Vector3f> Vector3fProperty;
|
||||
typedef Property<Vector4f> Vector4fProperty;
|
||||
|
||||
typedef Property<Vector2d> Vector2dProperty;
|
||||
typedef Property<Vector3d> Vector3dProperty;
|
||||
typedef Property<Vector4d> Vector4dProperty;
|
||||
|
||||
typedef Property<Matrix2i> Matrix2iProperty;
|
||||
typedef Property<Matrix3i> Matrix3iProperty;
|
||||
typedef Property<Matrix4i> Matrix4iProperty;
|
||||
|
||||
typedef Property<Matrix2f> Matrix2fProperty;
|
||||
typedef Property<Matrix3f> Matrix3fProperty;
|
||||
typedef Property<Matrix4f> Matrix4fProperty;
|
||||
|
||||
typedef Property<Matrix2d> Matrix2dProperty;
|
||||
typedef Property<Matrix3d> Matrix3dProperty;
|
||||
typedef Property<Matrix4d> Matrix4dProperty;
|
||||
|
||||
typedef Property<HVector3f> HVector3fProperty;
|
||||
typedef Property<HPoint3f> HPoint3fProperty;
|
||||
|
||||
} // namespace uLib
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -3,6 +3,7 @@ set( TESTS
|
||||
vtkViewerTest
|
||||
vtkContainerBoxTest
|
||||
vtkHandlerWidget
|
||||
PuppetPropertyTest
|
||||
# vtkVoxImageTest
|
||||
# vtkTriangleMeshTest
|
||||
)
|
||||
|
||||
68
src/Vtk/testing/PuppetPropertyTest.cpp
Normal file
68
src/Vtk/testing/PuppetPropertyTest.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
#include "Core/Property.h"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
using namespace Vtk;
|
||||
|
||||
int main() {
|
||||
BEGIN_TESTING(Puppet Property Registration Test);
|
||||
|
||||
std::cout << "Creating Puppet object..." << std::endl;
|
||||
Puppet p;
|
||||
|
||||
// At this point, the Puppet constructor has called ULIB_ACTIVATE_PROPERTIES.
|
||||
// This should have discovered the members used in Puppet::serialize()
|
||||
// and registered them as uLib properties.
|
||||
|
||||
const auto& props = p.GetProperties();
|
||||
std::cout << "Total registered properties: " << props.size() << std::endl;
|
||||
|
||||
// Verify specific properties exist
|
||||
Property<double>* opacityProp = nullptr;
|
||||
Property<double>* colorRProp = nullptr;
|
||||
|
||||
for (auto* prop : props) {
|
||||
std::cout << " - [" << prop->GetTypeName() << "] " << prop->GetName()
|
||||
<< " = " << prop->GetValueAsString() << std::endl;
|
||||
|
||||
if (prop->GetName() == "Opacity") {
|
||||
opacityProp = dynamic_cast<Property<double>*>(prop);
|
||||
}
|
||||
if (prop->GetName() == "ColorR") {
|
||||
colorRProp = dynamic_cast<Property<double>*>(prop);
|
||||
}
|
||||
}
|
||||
|
||||
assert(opacityProp != nullptr && "Opacity property not registered!");
|
||||
assert(colorRProp != nullptr && "ColorR property not registered!");
|
||||
|
||||
// Test modification via uLib Property interface
|
||||
std::cout << "Modifying Opacity via property proxy (0.25)..." << std::endl;
|
||||
*opacityProp = 0.25;
|
||||
|
||||
// Verify the proxy correctly updated the underlying data
|
||||
assert(opacityProp->Get() == 0.25);
|
||||
assert(opacityProp->GetValueAsString().find("0.25") != std::string::npos);
|
||||
|
||||
std::cout << "Modifying ColorR via property proxy (0.9)..." << std::endl;
|
||||
*colorRProp = 0.9;
|
||||
assert(colorRProp->Get() == 0.9);
|
||||
|
||||
std::cout << "All Puppet Property Registration Tests PASSED!" << std::endl;
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
@@ -60,6 +60,7 @@
|
||||
|
||||
#include "uLibVtkInterface.h"
|
||||
#include "vtkHandlerWidget.h"
|
||||
#include "Core/Property.h"
|
||||
|
||||
|
||||
|
||||
@@ -197,7 +198,12 @@ public:
|
||||
|
||||
|
||||
|
||||
Puppet::Puppet() : d(new PuppetData) { }
|
||||
Puppet::Puppet() : Object(), d(new PuppetData) {
|
||||
ULIB_ACTIVATE_PROPERTIES(*this);
|
||||
for (auto* p : this->GetProperties()) {
|
||||
uLib::Object::connect(p, &uLib::PropertyBase::Updated, this, &Puppet::Update);
|
||||
}
|
||||
}
|
||||
|
||||
Puppet::~Puppet()
|
||||
{
|
||||
@@ -442,6 +448,12 @@ bool Puppet::IsSelected() const
|
||||
|
||||
void Puppet::Update()
|
||||
{
|
||||
vtkProp3DCollection *props = d->m_Assembly->GetParts();
|
||||
props->InitTraversal();
|
||||
for (int i = 0; i < props->GetNumberOfItems(); ++i) {
|
||||
d->ApplyAppearance(props->GetNextProp3D());
|
||||
}
|
||||
|
||||
if (d->m_Selected) {
|
||||
d->UpdateHighlight();
|
||||
}
|
||||
@@ -462,5 +474,19 @@ void Puppet::ConnectInteractor(vtkRenderWindowInteractor *interactor)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void Puppet::serialize(Archive & ar, const unsigned int version) {
|
||||
ar & boost::serialization::make_hrp("ColorR", d->m_Color[0]);
|
||||
ar & boost::serialization::make_hrp("ColorG", d->m_Color[1]);
|
||||
ar & boost::serialization::make_hrp("ColorB", d->m_Color[2]);
|
||||
ar & boost::serialization::make_hrp("Opacity", d->m_Opacity);
|
||||
ar & boost::serialization::make_hrp("Representation", d->m_Representation);
|
||||
}
|
||||
|
||||
void Puppet::save_override(Archive::xml_oarchive & ar, const unsigned int v) { serialize(ar, v); }
|
||||
void Puppet::save_override(Archive::hrt_oarchive & ar, const unsigned int v) { serialize(ar, v); }
|
||||
void Puppet::save_override(Archive::log_archive & ar, const unsigned int v) { serialize(ar, v); }
|
||||
void Puppet::save_override(Archive::text_oarchive & ar, const unsigned int v) { serialize(ar, v); }
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <iomanip>
|
||||
#include <ostream>
|
||||
#include "Core/Object.h"
|
||||
|
||||
// vtk classes forward declaration //
|
||||
class vtkProp;
|
||||
@@ -41,7 +42,8 @@ class vtkRenderWindowInteractor;
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
class Puppet {
|
||||
class Puppet : public uLib::Object {
|
||||
uLibTypeMacro(Puppet, uLib::Object)
|
||||
public:
|
||||
Puppet();
|
||||
~Puppet();
|
||||
@@ -90,6 +92,14 @@ public:
|
||||
|
||||
virtual void ConnectInteractor(class vtkRenderWindowInteractor *interactor);
|
||||
|
||||
// Serialization and Reflection
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version);
|
||||
void save_override(Archive::xml_oarchive & ar, const unsigned int version);
|
||||
void save_override(Archive::hrt_oarchive & ar, const unsigned int version);
|
||||
void save_override(Archive::log_archive & ar, const unsigned int version);
|
||||
void save_override(Archive::text_oarchive & ar, const unsigned int version);
|
||||
|
||||
protected:
|
||||
void SetProp(vtkProp *prop);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Vtk {
|
||||
/**
|
||||
* @brief vtkObjectsContext manages VTK representations (Puppets) for a collection of uLib::Objects.
|
||||
*/
|
||||
class vtkObjectsContext : public uLib::Object, public Puppet {
|
||||
class vtkObjectsContext : public Puppet {
|
||||
public:
|
||||
virtual const char* GetClassName() const override { return "vtkObjectsContext"; }
|
||||
vtkObjectsContext(uLib::ObjectsContext *context);
|
||||
|
||||
@@ -55,7 +55,7 @@ void Viewport::SetupPipeline(vtkRenderWindowInteractor* iren)
|
||||
m_Annotation->GetTextProperty()->SetFontFamilyToArial();
|
||||
m_Annotation->GetTextProperty()->SetOpacity(0.5);
|
||||
m_Annotation->SetMaximumFontSize(10);
|
||||
m_Annotation->SetText(0, "uLib VTK Viewer - OpenCMT viewer.");
|
||||
m_Annotation->SetText(0, "uLib VTK viewer.");
|
||||
m_Renderer->AddViewProp(m_Annotation);
|
||||
|
||||
// right corner annotation
|
||||
|
||||
Reference in New Issue
Block a user