leocad/common/object.h

153 lines
3.7 KiB
C
Raw Normal View History

#pragma once
2011-09-07 21:06:51 +00:00
2012-08-16 23:50:40 +00:00
#include "lc_math.h"
#include "lc_array.h"
2012-08-16 23:50:40 +00:00
2020-04-18 19:45:21 -07:00
enum class lcObjectType
2011-09-07 21:06:51 +00:00
{
2020-04-18 19:45:21 -07:00
Piece,
Camera,
Light
2012-08-16 23:50:40 +00:00
};
2011-09-07 21:06:51 +00:00
2014-08-31 00:53:12 +00:00
template<typename T>
struct lcObjectKey
2011-09-07 21:06:51 +00:00
{
2014-07-06 06:04:09 +00:00
lcStep Step;
2014-08-31 00:53:12 +00:00
T Value;
2012-08-16 23:50:40 +00:00
};
2011-09-07 21:06:51 +00:00
template<typename T>
class lcObjectKeyArray
{
public:
int GetSize() const
{
2021-01-05 12:27:45 -08:00
return static_cast<int>(mKeys.size());
}
bool IsEmpty() const
{
2021-01-05 12:27:45 -08:00
return mKeys.empty();
}
void RemoveAll()
{
2021-01-05 12:27:45 -08:00
mKeys.clear();
}
2023-10-01 16:24:42 -07:00
void SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const;
void LoadKeysLDraw(QTextStream& Stream);
const T& CalculateKey(lcStep Step) const;
void ChangeKey(const T& Value, lcStep Step, bool AddKey);
void InsertTime(lcStep Start, lcStep Time);
void RemoveTime(lcStep Start, lcStep Time);
protected:
2021-01-05 12:27:45 -08:00
std::vector<lcObjectKey<T>> mKeys;
};
struct lcObjectSection
{
lcObject* Object = nullptr;
quint32 Section = 0;
};
struct lcPieceInfoRayTest
{
2022-01-09 12:54:45 -08:00
const PieceInfo* Info = nullptr;
lcMatrix44 Transform;
lcVector3 Plane;
};
struct lcObjectRayTest
2011-09-07 21:06:51 +00:00
{
2014-05-03 16:59:57 +00:00
lcCamera* ViewCamera;
bool PiecesOnly;
2017-11-12 19:38:07 -08:00
bool IgnoreSelected;
2012-08-16 23:50:40 +00:00
lcVector3 Start;
lcVector3 End;
float Distance = FLT_MAX;
lcObjectSection ObjectSection;
lcPieceInfoRayTest PieceInfoRayTest;
};
struct lcObjectBoxTest
{
2014-05-03 16:59:57 +00:00
lcCamera* ViewCamera;
lcVector4 Planes[6];
2014-11-29 02:55:58 +00:00
lcArray<lcObject*> Objects;
};
2023-09-04 10:59:16 -07:00
#define LC_OBJECT_TRANSFORM_MOVE_X 0x001
#define LC_OBJECT_TRANSFORM_MOVE_Y 0x002
#define LC_OBJECT_TRANSFORM_MOVE_Z 0x004
#define LC_OBJECT_TRANSFORM_MOVE_XYZ (LC_OBJECT_TRANSFORM_MOVE_X | LC_OBJECT_TRANSFORM_MOVE_Y | LC_OBJECT_TRANSFORM_MOVE_Z)
#define LC_OBJECT_TRANSFORM_ROTATE_X 0x010
#define LC_OBJECT_TRANSFORM_ROTATE_Y 0x020
#define LC_OBJECT_TRANSFORM_ROTATE_Z 0x040
#define LC_OBJECT_TRANSFORM_ROTATE_XYZ (LC_OBJECT_TRANSFORM_ROTATE_X | LC_OBJECT_TRANSFORM_ROTATE_Y | LC_OBJECT_TRANSFORM_ROTATE_Z)
#define LC_OBJECT_TRANSFORM_SCALE_X 0x100
#define LC_OBJECT_TRANSFORM_SCALE_Y 0x200
#define LC_OBJECT_TRANSFORM_SCALE_Z 0x400
#define LC_OBJECT_TRANSFORM_SCALE_XYZ (LC_OBJECT_TRANSFORM_SCALE_X | LC_OBJECT_TRANSFORM_SCALE_Y | LC_OBJECT_TRANSFORM_SCALE_Z)
2014-05-01 18:42:11 +00:00
class lcObject
2011-09-07 21:06:51 +00:00
{
public:
2014-05-01 18:42:11 +00:00
lcObject(lcObjectType ObjectType);
virtual ~lcObject();
2011-09-07 21:06:51 +00:00
2020-05-03 15:39:39 -07:00
lcObject(const lcObject&) = delete;
2021-11-14 18:34:24 -08:00
lcObject(lcObject&&) = delete;
2020-05-03 15:39:39 -07:00
lcObject& operator=(const lcObject&) = delete;
2021-11-14 18:34:24 -08:00
lcObject& operator=(lcObject&&) = delete;
2020-05-03 15:39:39 -07:00
2011-09-07 21:06:51 +00:00
public:
2014-01-30 23:26:55 +00:00
bool IsPiece() const
{
2020-04-18 19:45:21 -07:00
return mObjectType == lcObjectType::Piece;
2014-01-30 23:26:55 +00:00
}
2011-09-07 21:06:51 +00:00
2014-01-30 23:26:55 +00:00
bool IsCamera() const
{
2020-04-18 19:45:21 -07:00
return mObjectType == lcObjectType::Camera;
2014-01-30 23:26:55 +00:00
}
2011-09-07 21:06:51 +00:00
2014-01-30 23:26:55 +00:00
bool IsLight() const
{
2020-04-18 19:45:21 -07:00
return mObjectType == lcObjectType::Light;
2014-01-30 23:26:55 +00:00
}
2011-09-07 21:06:51 +00:00
lcObjectType GetType() const
2014-01-30 23:26:55 +00:00
{
return mObjectType;
2014-01-30 23:26:55 +00:00
}
2011-09-07 21:06:51 +00:00
virtual bool IsSelected() const = 0;
2017-12-02 12:22:04 -08:00
virtual bool IsSelected(quint32 Section) const = 0;
virtual void SetSelected(bool Selected) = 0;
2017-12-02 12:22:04 -08:00
virtual void SetSelected(quint32 Section, bool Selected) = 0;
virtual bool IsFocused() const = 0;
2017-12-02 12:22:04 -08:00
virtual bool IsFocused(quint32 Section) const = 0;
virtual void SetFocused(quint32 Section, bool Focused) = 0;
virtual quint32 GetFocusSection() const = 0;
2017-12-02 12:22:04 -08:00
virtual quint32 GetAllowedTransforms() const = 0;
virtual lcVector3 GetSectionPosition(quint32 Section) const = 0;
virtual void RayTest(lcObjectRayTest& ObjectRayTest) const = 0;
virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const = 0;
virtual void DrawInterface(lcContext* Context, const lcScene& Scene) const = 0;
virtual void RemoveKeyFrames() = 0;
2020-12-13 16:27:21 -08:00
virtual QString GetName() const = 0;
2011-09-07 21:06:51 +00:00
2023-10-01 16:24:42 -07:00
protected:
template<typename T>
void SaveAttribute(QTextStream& Stream, const T& Variable, const lcObjectKeyArray<T>& Keys, const char* ObjectName, const char* VariableName) const;
template<typename T>
bool LoadAttribute(QTextStream& Stream, const QString& Token, T& Variable, lcObjectKeyArray<T>& Keys, const char* VariableName);
2012-08-16 23:50:40 +00:00
private:
lcObjectType mObjectType;
2011-09-07 21:06:51 +00:00
};