From c627e1608ef051217f59a723acf5b4875cf8f2e7 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 25 Jan 2026 23:01:47 -0800 Subject: [PATCH] Merged selection/focus code in the lcObject class. --- common/camera.cpp | 2 +- common/camera.h | 95 ++--------------------------------------------- common/light.h | 43 +-------------------- common/object.h | 54 +++++++++++++++++++++++---- common/piece.cpp | 2 +- common/piece.h | 43 +-------------------- 6 files changed, 54 insertions(+), 185 deletions(-) diff --git a/common/camera.cpp b/common/camera.cpp index 0f90296a..813a78c4 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -909,7 +909,7 @@ void lcCamera::RemoveKeyFrames() bool lcCamera::SaveUndoData(QDataStream& Stream, const lcModel* Model) const { - static_assert(sizeof(lcCamera) == 240); + static_assert(sizeof(lcCamera) == 248); Q_UNUSED(Model); Stream << m_fovy; diff --git a/common/camera.h b/common/camera.h index c99192e6..6b54da3a 100644 --- a/common/camera.h +++ b/common/camera.h @@ -3,18 +3,9 @@ #include "object.h" #include "lc_math.h" -#define LC_CAMERA_HIDDEN 0x0001 -#define LC_CAMERA_SIMPLE 0x0002 -#define LC_CAMERA_ORTHO 0x0004 -#define LC_CAMERA_POSITION_SELECTED 0x0010 -#define LC_CAMERA_POSITION_FOCUSED 0x0020 -#define LC_CAMERA_TARGET_SELECTED 0x0040 -#define LC_CAMERA_TARGET_FOCUSED 0x0080 -#define LC_CAMERA_UPVECTOR_SELECTED 0x0100 -#define LC_CAMERA_UPVECTOR_FOCUSED 0x0200 - -#define LC_CAMERA_SELECTION_MASK (LC_CAMERA_POSITION_SELECTED | LC_CAMERA_TARGET_SELECTED | LC_CAMERA_UPVECTOR_SELECTED) -#define LC_CAMERA_FOCUS_MASK (LC_CAMERA_POSITION_FOCUSED | LC_CAMERA_TARGET_FOCUSED | LC_CAMERA_UPVECTOR_FOCUSED) +#define LC_CAMERA_HIDDEN 0x01 +#define LC_CAMERA_SIMPLE 0x02 +#define LC_CAMERA_ORTHO 0x04 enum class lcViewpoint { @@ -37,7 +28,7 @@ enum class lcCameraType enum lcCameraSection : quint32 { - LC_CAMERA_SECTION_INVALID = ~0U, + LC_CAMERA_SECTION_INVALID = LC_OBJECT_SECTION_INVALID, LC_CAMERA_SECTION_POSITION = 0, LC_CAMERA_SECTION_TARGET, LC_CAMERA_SECTION_UPVECTOR @@ -94,84 +85,6 @@ public: mState &= ~LC_CAMERA_ORTHO; } - bool IsSelected() const override - { - return (mState & LC_CAMERA_SELECTION_MASK) != 0; - } - - void SetSelected(bool Selected) override - { - if (Selected) - mState |= LC_CAMERA_SELECTION_MASK; - else - mState &= ~(LC_CAMERA_SELECTION_MASK | LC_CAMERA_FOCUS_MASK); - } - - bool IsFocused() const override - { - return (mState & LC_CAMERA_FOCUS_MASK) != 0; - } - - bool IsFocused(quint32 Section) const override - { - switch (Section) - { - case LC_CAMERA_SECTION_POSITION: - return (mState & LC_CAMERA_POSITION_FOCUSED) != 0; - break; - - case LC_CAMERA_SECTION_TARGET: - return (mState & LC_CAMERA_TARGET_FOCUSED) != 0; - break; - - case LC_CAMERA_SECTION_UPVECTOR: - return (mState & LC_CAMERA_UPVECTOR_FOCUSED) != 0; - break; - } - return false; - } - - void SetFocused(quint32 Section, bool Focus) override - { - switch (Section) - { - case LC_CAMERA_SECTION_POSITION: - if (Focus) - mState |= LC_CAMERA_SELECTION_MASK | LC_CAMERA_POSITION_FOCUSED; - else - mState &= ~LC_CAMERA_POSITION_FOCUSED; - break; - - case LC_CAMERA_SECTION_TARGET: - if (Focus) - mState |= LC_CAMERA_SELECTION_MASK | LC_CAMERA_TARGET_FOCUSED; - else - mState &= ~LC_CAMERA_TARGET_FOCUSED; - break; - - case LC_CAMERA_SECTION_UPVECTOR: - if (Focus) - mState |= LC_CAMERA_SELECTION_MASK | LC_CAMERA_UPVECTOR_FOCUSED; - else - mState &= ~LC_CAMERA_UPVECTOR_FOCUSED; - break; - } - } - - quint32 GetFocusSection() const override - { - if (mState & LC_CAMERA_POSITION_FOCUSED) - return LC_CAMERA_SECTION_POSITION; - - if (mState & LC_CAMERA_TARGET_FOCUSED) - return LC_CAMERA_SECTION_TARGET; - - if (mState & LC_CAMERA_UPVECTOR_FOCUSED) - return LC_CAMERA_SECTION_UPVECTOR; - - return LC_CAMERA_SECTION_INVALID; - } - quint32 GetAllowedTransforms() const override { return LC_OBJECT_TRANSFORM_MOVE_XYZ; diff --git a/common/light.h b/common/light.h index 9db0056c..8a935c0f 100644 --- a/common/light.h +++ b/common/light.h @@ -8,7 +8,7 @@ enum lcLightSection : quint32 { - LC_LIGHT_SECTION_INVALID = ~0U, + LC_LIGHT_SECTION_INVALID = LC_OBJECT_SECTION_INVALID, LC_LIGHT_SECTION_POSITION = 0, LC_LIGHT_SECTION_TARGET }; @@ -76,45 +76,6 @@ public: bool SetLightType(lcLightType LightType); - bool IsSelected() const override - { - return mSelected; - } - - void SetSelected(bool Selected) override - { - mSelected = Selected; - - if (!Selected) - mFocusedSection = LC_LIGHT_SECTION_INVALID; - } - - bool IsFocused() const override - { - return mFocusedSection != LC_LIGHT_SECTION_INVALID; - } - - bool IsFocused(quint32 Section) const override - { - return mFocusedSection == Section; - } - - void SetFocused(quint32 Section, bool Focused) override - { - if (Focused) - { - mFocusedSection = Section; - mSelected = true; - } - else - mFocusedSection = LC_LIGHT_SECTION_INVALID; - } - - quint32 GetFocusSection() const override - { - return mFocusedSection; - } - quint32 GetAllowedTransforms() const override { if (IsPointLight()) @@ -373,8 +334,6 @@ protected: lcObjectProperty mPOVRayAreaGridY = lcObjectProperty(2); quint32 mState = 0; - bool mSelected = false; - quint32 mFocusedSection = LC_LIGHT_SECTION_INVALID; lcVector3 mTargetMovePosition = lcVector3(0.0f, 0.0f, 0.0f); lcMatrix44 mWorldMatrix; diff --git a/common/object.h b/common/object.h index 652c9640..c69330f7 100644 --- a/common/object.h +++ b/common/object.h @@ -55,6 +55,8 @@ struct lcObjectBoxTest #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) +#define LC_OBJECT_SECTION_INVALID 0xffffffff + class lcObject { public: @@ -86,14 +88,46 @@ public: { return mObjectType; } - - virtual bool IsSelected() const = 0; - virtual void SetSelected(bool Selected) = 0; - virtual bool IsFocused() const = 0; - virtual bool IsFocused(quint32 Section) const = 0; - virtual void SetFocused(quint32 Section, bool Focused) = 0; - virtual quint32 GetFocusSection() const = 0; - + + bool IsSelected() const + { + return mSelected; + } + + void SetSelected(bool Selected) + { + mSelected = Selected; + + if (!Selected) + mFocusedSection = LC_OBJECT_SECTION_INVALID; + } + + bool IsFocused() const + { + return mFocusedSection != LC_OBJECT_SECTION_INVALID; + } + + bool IsFocused(quint32 Section) const + { + return mFocusedSection == Section; + } + + void SetFocused(quint32 Section, bool Focused) + { + if (Focused) + { + mFocusedSection = Section; + mSelected = true; + } + else + mFocusedSection = LC_OBJECT_SECTION_INVALID; + } + + quint32 GetFocusSection() const + { + return mFocusedSection; + } + virtual void UpdatePosition(lcStep Step) = 0; virtual quint32 GetAllowedTransforms() const = 0; virtual lcVector3 GetSectionPosition(quint32 Section) const = 0; @@ -112,4 +146,8 @@ public: private: lcObjectType mObjectType; + +protected: + bool mSelected = false; + quint32 mFocusedSection = LC_OBJECT_SECTION_INVALID; }; diff --git a/common/piece.cpp b/common/piece.cpp index 4ad10d5a..d4d378a6 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -937,7 +937,7 @@ void lcPiece::RemoveKeyFrames() bool lcPiece::SaveUndoData(QDataStream& Stream, const lcModel* Model) const { - static_assert(sizeof(lcPiece) == 376); + static_assert(sizeof(lcPiece) == 384); Stream << mFileLine; Stream << mID; diff --git a/common/piece.h b/common/piece.h index 1db62daf..6241f029 100644 --- a/common/piece.h +++ b/common/piece.h @@ -10,7 +10,7 @@ class PieceInfo; enum lcPieceSection : quint32 { - LC_PIECE_SECTION_INVALID = ~0U, + LC_PIECE_SECTION_INVALID = LC_OBJECT_SECTION_INVALID, LC_PIECE_SECTION_POSITION = 0, LC_PIECE_SECTION_CONTROL_POINT_FIRST, LC_PIECE_SECTION_CONTROL_POINT_LAST = LC_PIECE_SECTION_CONTROL_POINT_FIRST + LC_MAX_CONTROL_POINTS - 1, @@ -36,45 +36,6 @@ public: void CopyProperties(const lcPiece& Other); - bool IsSelected() const override - { - return mSelected; - } - - void SetSelected(bool Selected) override - { - mSelected = Selected; - - if (!Selected) - mFocusedSection = LC_PIECE_SECTION_INVALID; - } - - bool IsFocused() const override - { - return mFocusedSection != LC_PIECE_SECTION_INVALID; - } - - bool IsFocused(quint32 Section) const override - { - return mFocusedSection == Section; - } - - void SetFocused(quint32 Section, bool Focused) override - { - if (Focused) - { - mFocusedSection = Section; - mSelected = true; - } - else - mFocusedSection = LC_PIECE_SECTION_INVALID; - } - - quint32 GetFocusSection() const override - { - return mFocusedSection; - } - quint32 GetAllowedTransforms() const override; lcVector3 GetSectionPosition(quint32 Section) const override; @@ -315,8 +276,6 @@ protected: bool mPivotPointValid = false; bool mHidden = false; - bool mSelected = false; - quint32 mFocusedSection = LC_PIECE_SECTION_INVALID; std::vector mControlPoints; std::vector mTrainTrackConnections; lcMesh* mMesh = nullptr;