diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 20757cc4..6e44b495 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -995,11 +995,48 @@ bool lcModel::LoadInventory(const QByteArray& Inventory) } } - CalculateStep(mCurrentStep); + if (mPieces.IsEmpty()) + return false; + Library->WaitForLoadQueue(); Library->mBuffersDirty = true; Library->UnloadUnusedParts(); + auto RoundBounds = [](float& Value) + { + Value = ((Value < 0.0f) ? floor((Value - 5.0f) / 10.0f) : ceil((Value + 5.0f) / 10.0f)) * 10.0f; + }; + + const float TargetHeight = 800.0f; + float CurrentX = 0.0f; + float CurrentY = 0.0f; + float ColumnWidth = 0.0f; + + for (lcPiece* Piece : mPieces) + { + lcBoundingBox BoundingBox = Piece->mPieceInfo->GetBoundingBox(); + RoundBounds(BoundingBox.Min.x); + RoundBounds(BoundingBox.Min.y); + RoundBounds(BoundingBox.Max.x); + RoundBounds(BoundingBox.Max.y); + + float PieceWidth = BoundingBox.Max.x - BoundingBox.Min.x; + float PieceHeight = BoundingBox.Max.y - BoundingBox.Min.y; + + if (CurrentY + PieceHeight > TargetHeight) + { + CurrentY = 0.0f; + CurrentX += ColumnWidth; + ColumnWidth = 0.0f; + } + + Piece->SetPosition(lcVector3(CurrentX + PieceWidth / 2.0f, CurrentY + PieceHeight / 2.0f, 0.0f), 1, false); + CurrentY += PieceHeight; + ColumnWidth = qMax(ColumnWidth, PieceWidth); + } + + CalculateStep(mCurrentStep); + return true; #else return false; diff --git a/common/project.cpp b/common/project.cpp index 66eeb8f9..f56d270f 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -1489,7 +1489,7 @@ QImage Project::CreatePartsListImage(lcModel* Model, lcStep Step) for (lcPartsListImage& Image : Images) { CurrentHeight = qMax(Image.Bounds.height() + Ascent, CurrentHeight); - MaxWidth = qMax(MaxWidth, Image.Bounds.height()); + MaxWidth = qMax(MaxWidth, Image.Bounds.width()); } for (;;)