property - first attempt

This commit is contained in:
AndreaRigoni
2026-03-23 12:55:09 +00:00
parent b52ae808b8
commit 94843de711
16 changed files with 482 additions and 63 deletions

View File

@@ -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 &copy)
: 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;
};

View File

@@ -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
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////