From ce0d7c7be3770731d31607399fc296f13c8b188a Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 14 Feb 2026 12:34:29 -0800 Subject: [PATCH] Removed group action. --- common/camera.cpp | 4 +- common/group.cpp | 4 +- common/lc_model.cpp | 156 ++++++++++++++------------------------ common/lc_model.h | 8 -- common/lc_modelaction.cpp | 5 -- common/lc_modelaction.h | 27 ------- common/light.cpp | 4 +- common/piece.cpp | 14 ++-- 8 files changed, 69 insertions(+), 153 deletions(-) diff --git a/common/camera.cpp b/common/camera.cpp index fe4cb618..27fde10e 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -898,7 +898,7 @@ void lcCamera::RemoveKeyFrames() mUpVector.RemoveAllKeys(); } -lcCameraHistoryState lcCamera::GetHistoryState(const lcModel* Model) const +lcCameraHistoryState lcCamera::GetHistoryState([[maybe_unused]] const lcModel* Model) const { lcCameraHistoryState State; @@ -917,7 +917,7 @@ lcCameraHistoryState lcCamera::GetHistoryState(const lcModel* Model) const return State; } -void lcCamera::SetHistoryState(const lcCameraHistoryState& State, const lcModel* Model) +void lcCamera::SetHistoryState(const lcCameraHistoryState& State, [[maybe_unused]] const lcModel* Model) { mId = State.Id; mHidden = State.Hidden; diff --git a/common/group.cpp b/common/group.cpp index 5f52a21a..a1df761e 100644 --- a/common/group.cpp +++ b/common/group.cpp @@ -68,7 +68,7 @@ lcGroupHistoryState lcGroup::GetHistoryState(const lcModel* Model) const lcGroupHistoryState State; State.Id = mId; - State.ParentIndex = ~0; + State.ParentIndex = ~0U; State.Name = mName; if (mGroup) @@ -79,7 +79,7 @@ lcGroupHistoryState lcGroup::GetHistoryState(const lcModel* Model) const { if (Groups[GroupIndex].get() == mGroup) { - State.ParentIndex = GroupIndex; + State.ParentIndex = static_cast(GroupIndex); break; } } diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 30755b93..8d0e3863 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -329,15 +329,6 @@ void lcModel::UpdatePieceInfo(std::vector& UpdatedModels) mPieceInfo->SetBoundingBox(Min, Max); } -lcCamera* lcModel::GetCamera(const QString& Name) const -{ - for (const std::unique_ptr& Camera : mCameras) - if (Camera->GetName() == Name) - return Camera.get(); - - return nullptr; -} - void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly, lcStep LastStep) const { const QLatin1String LineEnding("\r\n"); @@ -1873,7 +1864,7 @@ void lcModel::EndObjectEditAction() ModelActionObjectEdit->SaveEndState(this); - if (ModelActionObjectEdit->StateChanged()) + if (!ModelActionObjectEdit->StateChanged()) mActionSequence.pop_back(); } @@ -1890,87 +1881,6 @@ void lcModel::RunObjectEditAction(const lcModelActionObjectEdit* ModelActionObje SetCurrentStep(mCurrentStep); } -void lcModel::RecordGroupPiecesAction(lcModelActionGroupPiecesMode Mode, const QString& GroupName) -{ - std::unique_ptr ModelActionGroupPieces = std::make_unique(Mode, GroupName); - - RunGroupPiecesAction(ModelActionGroupPieces.get(), true); - - mActionSequence.emplace_back(std::move(ModelActionGroupPieces)); -} - -void lcModel::RunGroupPiecesAction(const lcModelActionGroupPieces* ModelActionGroupPieces, bool Apply) -{ - if (!ModelActionGroupPieces) - return; - - if (Apply == (ModelActionGroupPieces->GetMode() == lcModelActionGroupPiecesMode::Group)) - { - lcGroup* NewGroup = new lcGroup(); - mGroups.emplace_back(NewGroup); - - NewGroup->mName = ModelActionGroupPieces->GetGroupName(); - NewGroup->mGroup = nullptr; - - for (const std::unique_ptr& Piece : mPieces) - { - if (Piece->IsSelected()) - { - lcGroup* TopGroup = Piece->GetTopGroup(); - - if (!TopGroup) - Piece->SetGroup(NewGroup); - else if (TopGroup != NewGroup) - TopGroup->mGroup = NewGroup; - } - } - } - else - { - std::set SelectedGroups; - - for (const std::unique_ptr& Piece : mPieces) - { - if (Piece->IsSelected()) - { - lcGroup* Group = Piece->GetTopGroup(); - - if (SelectedGroups.insert(Group).second) - { - for (std::vector>::iterator GroupIt = mGroups.begin(); GroupIt != mGroups.end(); GroupIt++) - { - if (GroupIt->get() == Group) - { - GroupIt->release(); - mGroups.erase(GroupIt); - break; - } - } - } - } - } - - for (const std::unique_ptr& Piece : mPieces) - { - lcGroup* Group = Piece->GetGroup(); - - if (SelectedGroups.find(Group) != SelectedGroups.end()) - Piece->SetGroup(nullptr); - } - - for (const std::unique_ptr& Group : mGroups) - if (SelectedGroups.find(Group->mGroup) != SelectedGroups.end()) - Group->mGroup = nullptr; - - for (lcGroup* Group : SelectedGroups) - delete Group; - - RemoveEmptyGroups(); - } - - gMainWindow->UpdateSelectedObjects(true); -} - void lcModel::RunActionSequence(const std::vector>& ActionSequence, bool Apply) { bool SelectionChanged = false; @@ -1985,8 +1895,6 @@ void lcModel::RunActionSequence(const std::vector } else if (const lcModelActionObjectEdit* ModelActionObjectEdit = dynamic_cast(ModelAction)) RunObjectEditAction(ModelActionObjectEdit, Apply); - else if (const lcModelActionGroupPieces* ModelActionGroupPieces = dynamic_cast(ModelAction)) - RunGroupPiecesAction(ModelActionGroupPieces, Apply); }; if (Apply) @@ -2306,10 +2214,27 @@ void lcModel::GroupSelection() return; BeginActionSequence(); + BeginObjectEditAction(); - RecordGroupPiecesAction(lcModelActionGroupPiecesMode::Group, Dialog.mName); + lcGroup* NewGroup = GetGroup(Dialog.mName, true); + for (const std::unique_ptr& Piece : mPieces) + { + if (Piece->IsSelected()) + { + lcGroup* Group = Piece->GetTopGroup(); + + if (!Group) + Piece->SetGroup(NewGroup); + else if (Group != NewGroup) + Group->mGroup = NewGroup; + } + } + + EndObjectEditAction(); EndActionSequence(tr("Group")); + + gMainWindow->UpdateSelectedObjects(true); } void lcModel::UngroupSelection() @@ -2320,28 +2245,59 @@ void lcModel::UngroupSelection() return; } - bool FoundGroup = false; + std::set SelectedGroups; for (const std::unique_ptr& Piece : mPieces) { - if (Piece->IsSelected() && Piece->GetGroup()) + if (Piece->IsSelected()) { - FoundGroup = true; - break; + lcGroup* Group = Piece->GetTopGroup(); + + if (SelectedGroups.insert(Group).second) + { + for (std::vector>::iterator GroupIt = mGroups.begin(); GroupIt != mGroups.end(); GroupIt++) + { + if (GroupIt->get() == Group) + { + GroupIt->release(); + mGroups.erase(GroupIt); + break; + } + } + } } } - if (!FoundGroup) + if (!SelectedGroups.empty()) { QMessageBox::information(gMainWindow, tr("Ungroup Selection"), tr("No groups selected.")); return; } BeginActionSequence(); + BeginObjectEditAction(); - RecordGroupPiecesAction(lcModelActionGroupPiecesMode::Ungroup, QString()); + for (const std::unique_ptr& Piece : mPieces) + { + lcGroup* Group = Piece->GetGroup(); + if (SelectedGroups.find(Group) != SelectedGroups.end()) + Piece->SetGroup(nullptr); + } + + for (const std::unique_ptr& Group : mGroups) + if (SelectedGroups.find(Group->mGroup) != SelectedGroups.end()) + Group->mGroup = nullptr; + + for (lcGroup* Group : SelectedGroups) + delete Group; + + RemoveEmptyGroups(); + + EndObjectEditAction(); EndActionSequence(tr("Ungroup")); + + gMainWindow->UpdateSelectedObjects(true); } void lcModel::AddSelectedPiecesToGroup() diff --git a/common/lc_model.h b/common/lc_model.h index 906a1576..ea392eaa 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -9,10 +9,6 @@ struct lcModelHistoryState; class lcModelAction; class lcModelActionSelection; class lcModelActionObjectEdit; -class lcModelActionGroupPieces; -enum class lcModelActionSelectionMode; -enum class lcModelActionObjectEditMode; -enum class lcModelActionGroupPiecesMode; #define LC_SEL_NO_PIECES 0x0001 // No pieces in model #define LC_SEL_PIECE 0x0002 // At least 1 piece selected @@ -164,8 +160,6 @@ public: return mCameras; } - lcCamera* GetCamera(const QString& Name) const; - const std::vector>& GetLights() const { return mLights; @@ -421,8 +415,6 @@ protected: void BeginObjectEditAction(); void EndObjectEditAction(); void RunObjectEditAction(const lcModelActionObjectEdit* ModelActionObjectEdit, bool Apply); - void RecordGroupPiecesAction(lcModelActionGroupPiecesMode Mode, const QString& GroupName); - void RunGroupPiecesAction(const lcModelActionGroupPieces* ModelActionGroupPieces, bool Apply); void RunActionSequence(const std::vector>& ActionSequence, bool Apply); void BeginActionSequence(); diff --git a/common/lc_modelaction.cpp b/common/lc_modelaction.cpp index 69d113eb..b176c066 100644 --- a/common/lc_modelaction.cpp +++ b/common/lc_modelaction.cpp @@ -194,8 +194,3 @@ bool lcModelActionObjectEdit::StateChanged() const { return mStartState != mEndState; } - -lcModelActionGroupPieces::lcModelActionGroupPieces(lcModelActionGroupPiecesMode Mode, const QString& GroupName) - : mMode(Mode), mGroupName(GroupName) -{ -} diff --git a/common/lc_modelaction.h b/common/lc_modelaction.h index 9c9b8c4b..a865133d 100644 --- a/common/lc_modelaction.h +++ b/common/lc_modelaction.h @@ -85,30 +85,3 @@ protected: lcModelHistoryState mStartState; lcModelHistoryState mEndState; }; - -enum class lcModelActionGroupPiecesMode -{ - Group, - Ungroup -}; - -class lcModelActionGroupPieces : public lcModelAction -{ -public: - lcModelActionGroupPieces(lcModelActionGroupPiecesMode Mode, const QString& GroupName); - virtual ~lcModelActionGroupPieces() = default; - - lcModelActionGroupPiecesMode GetMode() const - { - return mMode; - } - - const QString& GetGroupName() const - { - return mGroupName; - } - -protected: - lcModelActionGroupPiecesMode mMode; - QString mGroupName; -}; diff --git a/common/light.cpp b/common/light.cpp index 4ab16282..498e9442 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -1534,7 +1534,7 @@ void lcLight::RemoveKeyFrames() mPOVRayFadePower.RemoveAllKeys(); } -lcLightHistoryState lcLight::GetHistoryState(const lcModel* Model) const +lcLightHistoryState lcLight::GetHistoryState([[maybe_unused]] const lcModel* Model) const { lcLightHistoryState State; @@ -1564,7 +1564,7 @@ lcLightHistoryState lcLight::GetHistoryState(const lcModel* Model) const return State; } -void lcLight::SetHistoryState(const lcLightHistoryState& State, const lcModel* Model) +void lcLight::SetHistoryState(const lcLightHistoryState& State, [[maybe_unused]] const lcModel* Model) { mId = State.Id; mHidden = State.Hidden; diff --git a/common/piece.cpp b/common/piece.cpp index 6bed4239..19534c7c 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -104,13 +104,13 @@ void lcPiece::SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait, bool U else mID.clear(); - mControlPoints.clear(); - - delete mMesh; - mMesh = nullptr; - if (UpdateSynthInfo) { + mControlPoints.clear(); + + delete mMesh; + mMesh = nullptr; + const lcSynthInfo* SynthInfo = mPieceInfo ? mPieceInfo->GetSynthInfo() : nullptr; if (SynthInfo) @@ -945,7 +945,7 @@ lcPieceHistoryState lcPiece::GetHistoryState(const lcModel* Model) const State.Hidden = mHidden; State.FileLine = mFileLine; State.PieceId = mID; - State.GroupIndex = ~0; + State.GroupIndex = ~0U; State.ColorIndex = mColorIndex; State.ColorCode = mColorCode; State.StepShow = mStepShow; @@ -964,7 +964,7 @@ lcPieceHistoryState lcPiece::GetHistoryState(const lcModel* Model) const { if (mGroup == Groups[GroupIndex].get()) { - State.GroupIndex = GroupIndex; + State.GroupIndex = static_cast(GroupIndex); break; } }