Only update the piece info for a model after its project is set active.

This commit is contained in:
leo 2015-01-17 18:29:10 +00:00
parent a9fb816839
commit 6ad512d012
5 changed files with 60 additions and 36 deletions

View file

@ -157,7 +157,8 @@ lcModel::~lcModel()
{
if (mPieceInfo)
{
mPieceInfo->SetPlaceholder();
if (mPieceInfo->GetModel() == this)
mPieceInfo->SetPlaceholder();
mPieceInfo->Release();
}
@ -211,9 +212,48 @@ void lcModel::DeleteModel()
void lcModel::CreatePieceInfo()
{
QString PartID = mProperties.mName.toUpper();
mPieceInfo = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), true);
mPieceInfo = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), false);
if (!mPieceInfo)
{
mPieceInfo = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), true);
mPieceInfo->SetModel(this);
}
mPieceInfo->AddRef();
}
void lcModel::UpdatePieceInfo(lcArray<lcModel*>& UpdatedModels)
{
if (UpdatedModels.FindIndex(this) != -1)
return;
mPieceInfo->SetModel(this);
UpdatedModels.Add(this);
if (mPieces.IsEmpty())
{
memset(mPieceInfo->m_fDimensions, 0, sizeof(mPieceInfo->m_fDimensions));
return;
}
float BoundingBox[6] = { FLT_MAX, FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX };
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->GetStepHide() == LC_STEP_MAX)
{
Piece->mPieceInfo->UpdateBoundingBox(UpdatedModels);
Piece->CompareBoundingBox(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];
}
void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
@ -2560,35 +2600,6 @@ bool lcModel::GetSelectionCenter(lcVector3& Center) const
return Selected;
}
void lcModel::SubModelUpdateBoundingBox()
{
if (mPieces.IsEmpty())
{
memset(mPieceInfo->m_fDimensions, 0, sizeof(mPieceInfo->m_fDimensions));
return;
}
float BoundingBox[6] = { FLT_MAX, FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX };
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->GetStepHide() == LC_STEP_MAX)
{
Piece->mPieceInfo->UpdateBoundingBox();
Piece->CompareBoundingBox(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];
}
bool lcModel::GetPiecesBoundingBox(float BoundingBox[6]) const
{
BoundingBox[0] = FLT_MAX;

View file

@ -127,6 +127,7 @@ public:
bool IncludesModel(const lcModel* Model) const;
void CreatePieceInfo();
void UpdatePieceInfo(lcArray<lcModel*>& UpdatedModels);
PieceInfo* GetPieceInfo() const
{
@ -234,7 +235,6 @@ public:
bool GetFocusPosition(lcVector3& Position) const;
lcObject* GetFocusObject() const;
bool GetSelectionCenter(lcVector3& Center) const;
void SubModelUpdateBoundingBox();
bool GetPiecesBoundingBox(float BoundingBox[6]) const;
void GetPartsList(int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;

View file

@ -56,6 +56,11 @@ void PieceInfo::SetModel(lcModel* Model)
mFlags = LC_PIECE_MODEL;
mModel = Model;
strncpy(m_strName, Model->GetProperties().mName.toLatin1().data(), sizeof(m_strName));
m_strName[sizeof(m_strName)-1] = 0;
strncpy(m_strDescription, Model->GetProperties().mName.toLatin1().data(), sizeof(m_strDescription));
m_strDescription[sizeof(m_strDescription)-1] = 0;
delete mMesh;
mMesh = NULL;
}
@ -325,8 +330,8 @@ void PieceInfo::GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorInd
ModelPartsEntry.Info = const_cast<PieceInfo*>(this);
}
void PieceInfo::UpdateBoundingBox()
void PieceInfo::UpdateBoundingBox(lcArray<lcModel*>& UpdatedModels)
{
if (mFlags & LC_PIECE_MODEL)
mModel->SubModelUpdateBoundingBox();
mModel->UpdatePieceInfo(UpdatedModels);
}

View file

@ -29,6 +29,11 @@ public:
return mMesh;
}
lcModel* GetModel() const
{
return mModel;
}
void SetMesh(lcMesh* Mesh)
{
mMesh = Mesh;
@ -113,7 +118,7 @@ public:
bool BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 Planes[6]) const;
void GetPartsList(int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcArray<lcModelPartsEntry>& ModelParts) const;
void UpdateBoundingBox();
void UpdateBoundingBox(lcArray<lcModel*>& UpdatedModels);
public:
// Attributes

View file

@ -58,8 +58,11 @@ void Project::SetActiveModel(int ModelIndex)
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
mModels[ModelIdx]->SetActive(ModelIdx == ModelIndex);
lcArray<lcModel*> UpdatedModels;
UpdatedModels.AllocGrow(mModels.GetSize());
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
mModels[ModelIdx]->SubModelUpdateBoundingBox();
mModels[ModelIdx]->UpdatePieceInfo(UpdatedModels);
mActiveModel = mModels[ModelIndex];
mActiveModel->UpdateInterface();