From 98aa121dec1de82e776909d6478d3a9bb3f9d2fa Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 30 Dec 2014 16:56:13 +0000 Subject: [PATCH] Correctly draw selection box outline of submodels. --- common/lc_application.cpp | 1 + common/lc_model.cpp | 32 +++++++++++++++++++++++++++----- common/lc_model.h | 1 + common/project.cpp | 6 ++---- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index f101ba9b..78ad82f3 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -77,6 +77,7 @@ void lcApplication::SetProject(Project* Project) for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++) Views[ViewIdx]->SetModel(lcGetActiveModel()); + gMainWindow->UpdateAllViews(); gMainWindow->UpdateModels(); gMainWindow->UpdateTitle(); } diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 11711de9..f0336218 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -449,7 +449,6 @@ void lcModel::LoadLDraw(QTextStream& Stream) continue; } - // todo: mpd // todo: load from disk Info = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), true); @@ -954,10 +953,6 @@ void lcModel::SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMat PieceInfo* Info = Piece->mPieceInfo; Info->AddRenderMeshes(Scene, lcMul(Piece->mModelWorld, WorldMatrix), ColorIndex, Focused, Selected); } - - // todo: add model bounding box -// if (Selected) -// Scene.InterfaceObjects.Add(Piece); } void lcModel::DrawBackground(lcContext* Context) @@ -1172,6 +1167,33 @@ void lcModel::LoadCheckPoint(lcModelHistoryEntry* CheckPoint) gMainWindow->UpdateAllViews(); } +void lcModel::SetActive(bool Active) +{ + if (Active) + { + CalculateStep(mCurrentStep); + } + else + { + CalculateStep(LC_STEP_MAX); + + float BoundingBox[6]; + GetPiecesBoundingBox(BoundingBox); + + mPieceInfo->m_fDimensions[0] = BoundingBox[3]; + mPieceInfo->m_fDimensions[1] = BoundingBox[4]; + mPieceInfo->m_fDimensions[2] = BoundingBox[5]; + mPieceInfo->m_fDimensions[3] = BoundingBox[0]; + mPieceInfo->m_fDimensions[4] = BoundingBox[1]; + mPieceInfo->m_fDimensions[5] = BoundingBox[2]; + + strncpy(mPieceInfo->m_strName, mProperties.mName.toLatin1().constData(), sizeof(mPieceInfo->m_strName)); + mPieceInfo->m_strName[sizeof(mPieceInfo->m_strName) - 1] = 0; + strncpy(mPieceInfo->m_strDescription, mProperties.mName.toLatin1().constData(), sizeof(mPieceInfo->m_strDescription)); + mPieceInfo->m_strDescription[sizeof(mPieceInfo->m_strDescription) - 1] = 0; + } +} + void lcModel::CalculateStep(lcStep Step) { for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) diff --git a/common/lc_model.h b/common/lc_model.h index 5074d76a..b11cd1be 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -170,6 +170,7 @@ public: return mCurrentStep; } + void SetActive(bool Active); void CalculateStep(lcStep Step); void SetCurrentStep(lcStep Step) { diff --git a/common/project.cpp b/common/project.cpp index 714ffcad..e028b265 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -55,11 +55,9 @@ void Project::SetActiveModel(int ModelIndex) return; for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++) - if (ModelIdx != ModelIndex) - mModels[ModelIdx]->CalculateStep(LC_STEP_MAX); + mModels[ModelIdx]->SetActive(ModelIdx == ModelIndex); mActiveModel = mModels[ModelIndex]; - mActiveModel->CalculateStep(mActiveModel->GetCurrentStep()); mActiveModel->UpdateInterface(); gMainWindow->UpdateModels(); @@ -242,7 +240,7 @@ bool Project::Load(const QString& FileName) Model->CreatePieceInfo(); } - mActiveModel = mModels[0]; + SetActiveModel(0); /*