mirror of
https://github.com/leozide/leocad
synced 2025-02-06 08:46:06 +01:00
Only update the piece info for a model after its project is set active.
This commit is contained in:
parent
a9fb816839
commit
6ad512d012
5 changed files with 60 additions and 36 deletions
|
@ -157,6 +157,7 @@ lcModel::~lcModel()
|
||||||
{
|
{
|
||||||
if (mPieceInfo)
|
if (mPieceInfo)
|
||||||
{
|
{
|
||||||
|
if (mPieceInfo->GetModel() == this)
|
||||||
mPieceInfo->SetPlaceholder();
|
mPieceInfo->SetPlaceholder();
|
||||||
mPieceInfo->Release();
|
mPieceInfo->Release();
|
||||||
}
|
}
|
||||||
|
@ -211,10 +212,49 @@ void lcModel::DeleteModel()
|
||||||
void lcModel::CreatePieceInfo()
|
void lcModel::CreatePieceInfo()
|
||||||
{
|
{
|
||||||
QString PartID = mProperties.mName.toUpper();
|
QString PartID = mProperties.mName.toUpper();
|
||||||
|
mPieceInfo = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), false);
|
||||||
|
if (!mPieceInfo)
|
||||||
|
{
|
||||||
mPieceInfo = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), true);
|
mPieceInfo = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), true);
|
||||||
mPieceInfo->AddRef();
|
|
||||||
mPieceInfo->SetModel(this);
|
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
|
void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
|
||||||
{
|
{
|
||||||
|
@ -2560,35 +2600,6 @@ bool lcModel::GetSelectionCenter(lcVector3& Center) const
|
||||||
return Selected;
|
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
|
bool lcModel::GetPiecesBoundingBox(float BoundingBox[6]) const
|
||||||
{
|
{
|
||||||
BoundingBox[0] = FLT_MAX;
|
BoundingBox[0] = FLT_MAX;
|
||||||
|
|
|
@ -127,6 +127,7 @@ public:
|
||||||
|
|
||||||
bool IncludesModel(const lcModel* Model) const;
|
bool IncludesModel(const lcModel* Model) const;
|
||||||
void CreatePieceInfo();
|
void CreatePieceInfo();
|
||||||
|
void UpdatePieceInfo(lcArray<lcModel*>& UpdatedModels);
|
||||||
|
|
||||||
PieceInfo* GetPieceInfo() const
|
PieceInfo* GetPieceInfo() const
|
||||||
{
|
{
|
||||||
|
@ -234,7 +235,6 @@ public:
|
||||||
bool GetFocusPosition(lcVector3& Position) const;
|
bool GetFocusPosition(lcVector3& Position) const;
|
||||||
lcObject* GetFocusObject() const;
|
lcObject* GetFocusObject() const;
|
||||||
bool GetSelectionCenter(lcVector3& Center) const;
|
bool GetSelectionCenter(lcVector3& Center) const;
|
||||||
void SubModelUpdateBoundingBox();
|
|
||||||
bool GetPiecesBoundingBox(float BoundingBox[6]) const;
|
bool GetPiecesBoundingBox(float BoundingBox[6]) const;
|
||||||
void GetPartsList(int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
|
void GetPartsList(int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
|
||||||
void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
|
void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
|
||||||
|
|
|
@ -56,6 +56,11 @@ void PieceInfo::SetModel(lcModel* Model)
|
||||||
mFlags = LC_PIECE_MODEL;
|
mFlags = LC_PIECE_MODEL;
|
||||||
mModel = 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;
|
delete mMesh;
|
||||||
mMesh = NULL;
|
mMesh = NULL;
|
||||||
}
|
}
|
||||||
|
@ -325,8 +330,8 @@ void PieceInfo::GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorInd
|
||||||
ModelPartsEntry.Info = const_cast<PieceInfo*>(this);
|
ModelPartsEntry.Info = const_cast<PieceInfo*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PieceInfo::UpdateBoundingBox()
|
void PieceInfo::UpdateBoundingBox(lcArray<lcModel*>& UpdatedModels)
|
||||||
{
|
{
|
||||||
if (mFlags & LC_PIECE_MODEL)
|
if (mFlags & LC_PIECE_MODEL)
|
||||||
mModel->SubModelUpdateBoundingBox();
|
mModel->UpdatePieceInfo(UpdatedModels);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,11 @@ public:
|
||||||
return mMesh;
|
return mMesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lcModel* GetModel() const
|
||||||
|
{
|
||||||
|
return mModel;
|
||||||
|
}
|
||||||
|
|
||||||
void SetMesh(lcMesh* Mesh)
|
void SetMesh(lcMesh* Mesh)
|
||||||
{
|
{
|
||||||
mMesh = Mesh;
|
mMesh = Mesh;
|
||||||
|
@ -113,7 +118,7 @@ public:
|
||||||
bool BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 Planes[6]) const;
|
bool BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 Planes[6]) const;
|
||||||
void GetPartsList(int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
|
void GetPartsList(int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
|
||||||
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcArray<lcModelPartsEntry>& ModelParts) const;
|
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcArray<lcModelPartsEntry>& ModelParts) const;
|
||||||
void UpdateBoundingBox();
|
void UpdateBoundingBox(lcArray<lcModel*>& UpdatedModels);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Attributes
|
// Attributes
|
||||||
|
|
|
@ -58,8 +58,11 @@ void Project::SetActiveModel(int ModelIndex)
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
||||||
mModels[ModelIdx]->SetActive(ModelIdx == ModelIndex);
|
mModels[ModelIdx]->SetActive(ModelIdx == ModelIndex);
|
||||||
|
|
||||||
|
lcArray<lcModel*> UpdatedModels;
|
||||||
|
UpdatedModels.AllocGrow(mModels.GetSize());
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
||||||
mModels[ModelIdx]->SubModelUpdateBoundingBox();
|
mModels[ModelIdx]->UpdatePieceInfo(UpdatedModels);
|
||||||
|
|
||||||
mActiveModel = mModels[ModelIndex];
|
mActiveModel = mModels[ModelIndex];
|
||||||
mActiveModel->UpdateInterface();
|
mActiveModel->UpdateInterface();
|
||||||
|
|
Loading…
Add table
Reference in a new issue