mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Reuse piece bounding box function to avoid duplication.
This commit is contained in:
parent
6684abf96a
commit
a6a69b7661
6 changed files with 85 additions and 86 deletions
|
@ -1080,6 +1080,29 @@ bool lcModel::GetSelectionCenter(lcVector3& Center) const
|
||||||
return Selected;
|
return Selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool lcModel::GetPiecesBoundingBox(float BoundingBox[6]) const
|
||||||
|
{
|
||||||
|
if (mPieces.IsEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
BoundingBox[0] = FLT_MAX;
|
||||||
|
BoundingBox[1] = FLT_MAX;
|
||||||
|
BoundingBox[2] = FLT_MAX;
|
||||||
|
BoundingBox[3] = -FLT_MAX;
|
||||||
|
BoundingBox[4] = -FLT_MAX;
|
||||||
|
BoundingBox[5] = -FLT_MAX;
|
||||||
|
|
||||||
|
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||||
|
{
|
||||||
|
lcPiece* Piece = mPieces[PieceIdx];
|
||||||
|
|
||||||
|
if (Piece->IsVisible(mCurrentStep))
|
||||||
|
Piece->CompareBoundingBox(BoundingBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void lcModel::UpdateSelection() const
|
void lcModel::UpdateSelection() const
|
||||||
{
|
{
|
||||||
int Flags = 0;
|
int Flags = 0;
|
||||||
|
|
|
@ -152,6 +152,8 @@ 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;
|
||||||
|
bool GetPiecesBoundingBox(float BoundingBox[6]) const;
|
||||||
|
|
||||||
void FocusOrDeselectObject(const lcObjectSection& ObjectSection);
|
void FocusOrDeselectObject(const lcObjectSection& ObjectSection);
|
||||||
void ClearSelectionAndSetFocus(lcObject* Object, lcuint32 Section);
|
void ClearSelectionAndSetFocus(lcObject* Object, lcuint32 Section);
|
||||||
void ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection);
|
void ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection);
|
||||||
|
|
|
@ -1257,91 +1257,25 @@ void Project::RenderSceneObjects(View* view)
|
||||||
Context->SetLineWidth(Preferences.mLineWidth); // context remove
|
Context->SetLineWidth(Preferences.mLineWidth); // context remove
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Project::GetPiecesBoundingBox(View* view, float BoundingBox[6])
|
|
||||||
{
|
|
||||||
if (mPieces.IsEmpty() && view->mTrackTool != LC_TRACKTOOL_INSERT)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BoundingBox[0] = FLT_MAX;
|
|
||||||
BoundingBox[1] = FLT_MAX;
|
|
||||||
BoundingBox[2] = FLT_MAX;
|
|
||||||
BoundingBox[3] = -FLT_MAX;
|
|
||||||
BoundingBox[4] = -FLT_MAX;
|
|
||||||
BoundingBox[5] = -FLT_MAX;
|
|
||||||
|
|
||||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
|
||||||
{
|
|
||||||
lcPiece* Piece = mPieces[PieceIdx];
|
|
||||||
|
|
||||||
if (Piece->IsVisible(mCurrentStep))
|
|
||||||
Piece->CompareBoundingBox(BoundingBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (view->mTrackTool == LC_TRACKTOOL_INSERT)
|
|
||||||
{
|
|
||||||
lcVector3 Position;
|
|
||||||
lcVector4 Rotation;
|
|
||||||
GetPieceInsertPosition(view, Position, Rotation);
|
|
||||||
PieceInfo* CurPiece = gMainWindow->mPreviewWidget->GetCurrentPiece();
|
|
||||||
|
|
||||||
lcVector3 Points[8] =
|
|
||||||
{
|
|
||||||
lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[5]),
|
|
||||||
lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[5]),
|
|
||||||
lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[2]),
|
|
||||||
lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[5]),
|
|
||||||
lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[2]),
|
|
||||||
lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[2]),
|
|
||||||
lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[5]),
|
|
||||||
lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[2])
|
|
||||||
};
|
|
||||||
|
|
||||||
lcMatrix44 ModelWorld = lcMatrix44FromAxisAngle(lcVector3(Rotation[0], Rotation[1], Rotation[2]), Rotation[3] * LC_DTOR);
|
|
||||||
ModelWorld.SetTranslation(Position);
|
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
lcVector3 Point = lcMul31(Points[i], ModelWorld);
|
|
||||||
|
|
||||||
if (Point[0] < BoundingBox[0]) BoundingBox[0] = Point[0];
|
|
||||||
if (Point[1] < BoundingBox[1]) BoundingBox[1] = Point[1];
|
|
||||||
if (Point[2] < BoundingBox[2]) BoundingBox[2] = Point[2];
|
|
||||||
if (Point[0] > BoundingBox[3]) BoundingBox[3] = Point[0];
|
|
||||||
if (Point[1] > BoundingBox[4]) BoundingBox[4] = Point[1];
|
|
||||||
if (Point[2] > BoundingBox[5]) BoundingBox[5] = Point[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Project::ZoomExtents(int FirstView, int LastView)
|
void Project::ZoomExtents(int FirstView, int LastView)
|
||||||
{
|
{
|
||||||
if (mPieces.IsEmpty())
|
float BoundingBox[6];
|
||||||
|
|
||||||
|
if (!GetPiecesBoundingBox(BoundingBox))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
|
lcVector3 Center((BoundingBox[0] + BoundingBox[3]) / 2, (BoundingBox[1] + BoundingBox[4]) / 2, (BoundingBox[2] + BoundingBox[5]) / 2);
|
||||||
|
|
||||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
|
||||||
{
|
|
||||||
lcPiece* Piece = mPieces[PieceIdx];
|
|
||||||
|
|
||||||
if (Piece->IsVisible(mCurrentStep))
|
|
||||||
Piece->CompareBoundingBox(bs);
|
|
||||||
}
|
|
||||||
|
|
||||||
lcVector3 Center((bs[0] + bs[3]) / 2, (bs[1] + bs[4]) / 2, (bs[2] + bs[5]) / 2);
|
|
||||||
|
|
||||||
lcVector3 Points[8] =
|
lcVector3 Points[8] =
|
||||||
{
|
{
|
||||||
lcVector3(bs[0], bs[1], bs[5]),
|
lcVector3(BoundingBox[0], BoundingBox[1], BoundingBox[5]),
|
||||||
lcVector3(bs[3], bs[1], bs[5]),
|
lcVector3(BoundingBox[3], BoundingBox[1], BoundingBox[5]),
|
||||||
lcVector3(bs[0], bs[1], bs[2]),
|
lcVector3(BoundingBox[0], BoundingBox[1], BoundingBox[2]),
|
||||||
lcVector3(bs[3], bs[4], bs[5]),
|
lcVector3(BoundingBox[3], BoundingBox[4], BoundingBox[5]),
|
||||||
lcVector3(bs[3], bs[4], bs[2]),
|
lcVector3(BoundingBox[3], BoundingBox[4], BoundingBox[2]),
|
||||||
lcVector3(bs[0], bs[4], bs[2]),
|
lcVector3(BoundingBox[0], BoundingBox[4], BoundingBox[2]),
|
||||||
lcVector3(bs[0], bs[4], bs[5]),
|
lcVector3(BoundingBox[0], BoundingBox[4], BoundingBox[5]),
|
||||||
lcVector3(bs[3], bs[1], bs[2])
|
lcVector3(BoundingBox[3], BoundingBox[1], BoundingBox[2])
|
||||||
};
|
};
|
||||||
|
|
||||||
const lcArray<View*> Views = gMainWindow->GetViews();
|
const lcArray<View*> Views = gMainWindow->GetViews();
|
||||||
|
@ -4031,12 +3965,12 @@ void Project::HandleCommand(LC_COMMANDS id)
|
||||||
|
|
||||||
if (!GetSelectionCenter(Center))
|
if (!GetSelectionCenter(Center))
|
||||||
{
|
{
|
||||||
float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
|
float BoundingBox[6];
|
||||||
|
|
||||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
if (GetPiecesBoundingBox(BoundingBox))
|
||||||
mPieces[PieceIdx]->CompareBoundingBox(bs);
|
Center = lcVector3((BoundingBox[0] + BoundingBox[3]) / 2, (BoundingBox[1] + BoundingBox[4]) / 2, (BoundingBox[2] + BoundingBox[5]) / 2);
|
||||||
|
else
|
||||||
Center = lcVector3((bs[0] + bs[3]) * 0.5f, (bs[1] + bs[4]) * 0.5f, (bs[2] + bs[5]) * 0.5f);
|
Center = lcVector3(0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
gMainWindow->GetActiveView()->mCamera->Center(Center, mCurrentStep, gMainWindow->GetAddKeys());
|
gMainWindow->GetActiveView()->mCamera->Center(Center, mCurrentStep, gMainWindow->GetAddKeys());
|
||||||
|
|
|
@ -96,7 +96,6 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void LoadDefaults();
|
void LoadDefaults();
|
||||||
bool GetPiecesBoundingBox(View* view, float BoundingBox[6]);
|
|
||||||
void GetPiecesUsed(lcArray<lcPiecesUsedEntry>& PiecesUsed) const;
|
void GetPiecesUsed(lcArray<lcPiecesUsedEntry>& PiecesUsed) const;
|
||||||
void CreateImages(Image* images, int width, int height, lcStep from, lcStep to, bool hilite);
|
void CreateImages(Image* images, int width, int height, lcStep from, lcStep to, bool hilite);
|
||||||
void Render(View* view, bool bToMemory);
|
void Render(View* view, bool bToMemory);
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "tr.h"
|
#include "tr.h"
|
||||||
#include "texfont.h"
|
#include "texfont.h"
|
||||||
#include "lc_texture.h"
|
#include "lc_texture.h"
|
||||||
|
#include "preview.h"
|
||||||
|
#include "pieceinf.h"
|
||||||
|
|
||||||
View::View(Project *project)
|
View::View(Project *project)
|
||||||
{
|
{
|
||||||
|
@ -879,7 +881,46 @@ void View::DrawGrid()
|
||||||
int MinX, MaxX, MinY, MaxY;
|
int MinX, MaxX, MinY, MaxY;
|
||||||
float BoundingBox[6];
|
float BoundingBox[6];
|
||||||
|
|
||||||
if (mProject->GetPiecesBoundingBox(this, BoundingBox))
|
bool GridSizeValid = mProject->GetPiecesBoundingBox(BoundingBox);
|
||||||
|
|
||||||
|
if (mTrackTool == LC_TRACKTOOL_INSERT)
|
||||||
|
{
|
||||||
|
lcVector3 Position;
|
||||||
|
lcVector4 Rotation;
|
||||||
|
mProject->GetPieceInsertPosition(this, Position, Rotation);
|
||||||
|
PieceInfo* CurPiece = gMainWindow->mPreviewWidget->GetCurrentPiece();
|
||||||
|
|
||||||
|
lcVector3 Points[8] =
|
||||||
|
{
|
||||||
|
lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[5]),
|
||||||
|
lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[5]),
|
||||||
|
lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[2]),
|
||||||
|
lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[5]),
|
||||||
|
lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[2]),
|
||||||
|
lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[2]),
|
||||||
|
lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[5]),
|
||||||
|
lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[2])
|
||||||
|
};
|
||||||
|
|
||||||
|
lcMatrix44 ModelWorld = lcMatrix44FromAxisAngle(lcVector3(Rotation[0], Rotation[1], Rotation[2]), Rotation[3] * LC_DTOR);
|
||||||
|
ModelWorld.SetTranslation(Position);
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
lcVector3 Point = lcMul31(Points[i], ModelWorld);
|
||||||
|
|
||||||
|
if (Point[0] < BoundingBox[0]) BoundingBox[0] = Point[0];
|
||||||
|
if (Point[1] < BoundingBox[1]) BoundingBox[1] = Point[1];
|
||||||
|
if (Point[2] < BoundingBox[2]) BoundingBox[2] = Point[2];
|
||||||
|
if (Point[0] > BoundingBox[3]) BoundingBox[3] = Point[0];
|
||||||
|
if (Point[1] > BoundingBox[4]) BoundingBox[4] = Point[1];
|
||||||
|
if (Point[2] > BoundingBox[5]) BoundingBox[5] = Point[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
GridSizeValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GridSizeValid)
|
||||||
{
|
{
|
||||||
MinX = (int)(floorf(BoundingBox[0] / (20.0f * Spacing))) - 1;
|
MinX = (int)(floorf(BoundingBox[0] / (20.0f * Spacing))) - 1;
|
||||||
MinY = (int)(floorf(BoundingBox[1] / (20.0f * Spacing))) - 1;
|
MinY = (int)(floorf(BoundingBox[1] / (20.0f * Spacing))) - 1;
|
||||||
|
|
|
@ -373,7 +373,7 @@ void lcQMainWindow::createToolBars()
|
||||||
QAction* angleAction = new QAction(tr("Snap Rotate"), this);
|
QAction* angleAction = new QAction(tr("Snap Rotate"), this);
|
||||||
angleAction->setStatusTip(tr("Snap rotations to fixed intervals"));
|
angleAction->setStatusTip(tr("Snap rotations to fixed intervals"));
|
||||||
angleAction->setIcon(QIcon(":/resources/edit_snap_angle.png"));
|
angleAction->setIcon(QIcon(":/resources/edit_snap_angle.png"));
|
||||||
angleAction->setMenu(snapMenu);
|
angleAction->setMenu(snapAngleMenu);
|
||||||
|
|
||||||
standardToolBar = addToolBar(tr("Standard"));
|
standardToolBar = addToolBar(tr("Standard"));
|
||||||
standardToolBar->setObjectName("StandardToolbar");
|
standardToolBar->setObjectName("StandardToolbar");
|
||||||
|
|
Loading…
Add table
Reference in a new issue