mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Move parts after importing inventory.
This commit is contained in:
parent
81c70f9daa
commit
8486295a02
2 changed files with 39 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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 (;;)
|
||||
|
|
Loading…
Reference in a new issue