mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Use a regular View for the Minifig Wizard.
This commit is contained in:
parent
fd24accea7
commit
b77210db22
15 changed files with 113 additions and 253 deletions
|
@ -13,8 +13,8 @@
|
||||||
lcGLWidget* lcGLWidget::mLastFocusedView;
|
lcGLWidget* lcGLWidget::mLastFocusedView;
|
||||||
std::vector<lcGLWidget*> lcGLWidget::mViews;
|
std::vector<lcGLWidget*> lcGLWidget::mViews;
|
||||||
|
|
||||||
lcGLWidget::lcGLWidget(lcModel* Model)
|
lcGLWidget::lcGLWidget(lcViewType ViewType, lcModel* Model)
|
||||||
: mScene(new lcScene()), mModel(Model)
|
: mScene(new lcScene()), mModel(Model), mViewType(ViewType)
|
||||||
{
|
{
|
||||||
mContext = new lcContext();
|
mContext = new lcContext();
|
||||||
mViews.push_back(this);
|
mViews.push_back(this);
|
||||||
|
|
|
@ -80,12 +80,20 @@ enum class lcTrackTool
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class lcViewType
|
||||||
|
{
|
||||||
|
View,
|
||||||
|
Preview,
|
||||||
|
Minifig,
|
||||||
|
Count
|
||||||
|
};
|
||||||
|
|
||||||
class lcGLWidget : public QObject
|
class lcGLWidget : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
lcGLWidget(lcModel* Model);
|
lcGLWidget(lcViewType ViewType, lcModel* Model);
|
||||||
virtual ~lcGLWidget();
|
virtual ~lcGLWidget();
|
||||||
|
|
||||||
lcGLWidget(const lcGLWidget&) = delete;
|
lcGLWidget(const lcGLWidget&) = delete;
|
||||||
|
@ -96,6 +104,11 @@ public:
|
||||||
|
|
||||||
lcModel* GetActiveModel() const;
|
lcModel* GetActiveModel() const;
|
||||||
|
|
||||||
|
lcViewType GetViewType() const
|
||||||
|
{
|
||||||
|
return mViewType;
|
||||||
|
}
|
||||||
|
|
||||||
lcCamera* GetCamera() const
|
lcCamera* GetCamera() const
|
||||||
{
|
{
|
||||||
return mCamera;
|
return mCamera;
|
||||||
|
@ -230,6 +243,7 @@ protected:
|
||||||
int mWidth = 1;
|
int mWidth = 1;
|
||||||
int mHeight = 1;
|
int mHeight = 1;
|
||||||
bool mDeleteContext = true;
|
bool mDeleteContext = true;
|
||||||
|
lcViewType mViewType;
|
||||||
|
|
||||||
static lcGLWidget* mLastFocusedView;
|
static lcGLWidget* mLastFocusedView;
|
||||||
static std::vector<lcGLWidget*> mViews;
|
static std::vector<lcGLWidget*> mViews;
|
||||||
|
|
|
@ -770,7 +770,7 @@ void lcMainWindow::CreateToolBars()
|
||||||
|
|
||||||
View* lcMainWindow::CreateView(lcModel* Model)
|
View* lcMainWindow::CreateView(lcModel* Model)
|
||||||
{
|
{
|
||||||
View* NewView = new View(Model);
|
View* NewView = new View(lcViewType::View, Model);
|
||||||
|
|
||||||
connect(NewView, SIGNAL(CameraChanged()), this, SLOT(ViewCameraChanged()));
|
connect(NewView, SIGNAL(CameraChanged()), this, SLOT(ViewCameraChanged()));
|
||||||
connect(NewView, SIGNAL(FocusReceived()), this, SLOT(ViewFocusReceived()));
|
connect(NewView, SIGNAL(FocusReceived()), this, SLOT(ViewFocusReceived()));
|
||||||
|
|
|
@ -1275,7 +1275,7 @@ QImage lcModel::GetStepImage(bool Zoom, int Width, int Height, lcStep Step)
|
||||||
if (Zoom)
|
if (Zoom)
|
||||||
ZoomExtents(Camera, (float)Width / (float)Height);
|
ZoomExtents(Camera, (float)Width / (float)Height);
|
||||||
|
|
||||||
View View(this);
|
View View(lcViewType::View, this);
|
||||||
View.SetCamera(Camera, false);
|
View.SetCamera(Camera, false);
|
||||||
View.SetContext(Context);
|
View.SetContext(Context);
|
||||||
|
|
||||||
|
@ -4418,7 +4418,7 @@ void lcModel::ShowMinifigDialog()
|
||||||
|
|
||||||
lcGroup* Group = AddGroup(tr("Minifig #"), nullptr);
|
lcGroup* Group = AddGroup(tr("Minifig #"), nullptr);
|
||||||
lcArray<lcObject*> Pieces(LC_MFW_NUMITEMS);
|
lcArray<lcObject*> Pieces(LC_MFW_NUMITEMS);
|
||||||
lcMinifig& Minifig = Dialog.mMinifigWidget->mMinifig;
|
lcMinifig& Minifig = Dialog.mMinifigWizard->mMinifig;
|
||||||
|
|
||||||
for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++)
|
for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,7 +80,7 @@ void lcPreviewDockWidget::SetPreviewLock()
|
||||||
}
|
}
|
||||||
|
|
||||||
lcPreviewWidget::lcPreviewWidget()
|
lcPreviewWidget::lcPreviewWidget()
|
||||||
: lcGLWidget(nullptr), mLoader(new Project(true))
|
: lcGLWidget(lcViewType::Preview, nullptr), mLoader(new Project(true))
|
||||||
{
|
{
|
||||||
mViewSphere = std::unique_ptr<lcViewSphere>(new lcViewSphere(this));
|
mViewSphere = std::unique_ptr<lcViewSphere>(new lcViewSphere(this));
|
||||||
mLoader->SetActiveModel(0);
|
mLoader->SetActiveModel(0);
|
||||||
|
|
|
@ -32,17 +32,23 @@ void lcViewSphere::UpdateSettings()
|
||||||
{
|
{
|
||||||
const lcPreferences& Preferences = lcGetPreferences();
|
const lcPreferences& Preferences = lcGetPreferences();
|
||||||
|
|
||||||
if (!mIsPreview)
|
switch (mWidget->GetViewType())
|
||||||
{
|
{
|
||||||
|
case lcViewType::View:
|
||||||
mSize = Preferences.mViewSphereSize;
|
mSize = Preferences.mViewSphereSize;
|
||||||
mEnabled = Preferences.mViewSphereEnabled;
|
mEnabled = Preferences.mViewSphereEnabled;
|
||||||
mLocation = Preferences.mViewSphereLocation;
|
mLocation = Preferences.mViewSphereLocation;
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
case lcViewType::Preview:
|
||||||
mSize = Preferences.mPreviewViewSphereSize;
|
mSize = Preferences.mPreviewViewSphereSize;
|
||||||
mEnabled = Preferences.mPreviewViewSphereEnabled;
|
mEnabled = Preferences.mPreviewViewSphereEnabled;
|
||||||
mLocation = Preferences.mPreviewViewSphereLocation;
|
mLocation = Preferences.mPreviewViewSphereLocation;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case lcViewType::Minifig:
|
||||||
|
case lcViewType::Count:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ protected:
|
||||||
bool mIsPreview = false;
|
bool mIsPreview = false;
|
||||||
|
|
||||||
int mSize = 1;
|
int mSize = 1;
|
||||||
bool mEnabled = true;
|
bool mEnabled = false;
|
||||||
lcViewSphereLocation mLocation = lcViewSphereLocation::TopRight;
|
lcViewSphereLocation mLocation = lcViewSphereLocation::TopRight;
|
||||||
|
|
||||||
int mMouseDownX = 0;
|
int mMouseDownX = 0;
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
|
|
||||||
static QList<lcViewWidget*> gWidgetList;
|
static QList<lcViewWidget*> gWidgetList;
|
||||||
|
|
||||||
lcViewWidget::lcViewWidget(QWidget* Parent, lcGLWidget* Owner)
|
lcViewWidget::lcViewWidget(QWidget* Parent, lcGLWidget* View)
|
||||||
: QGLWidget(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first())
|
: QGLWidget(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first())
|
||||||
{
|
{
|
||||||
mWheelAccumulator = 0;
|
mWheelAccumulator = 0;
|
||||||
mView = Owner;
|
mView = View;
|
||||||
mView->SetWidget(this);
|
mView->SetWidget(this);
|
||||||
|
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
|
@ -55,7 +55,7 @@ lcViewWidget::lcViewWidget(QWidget* Parent, lcGLWidget* Owner)
|
||||||
|
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
if (dynamic_cast<View*>(Owner))
|
if (View->GetViewType() == lcViewType::View)
|
||||||
{
|
{
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
|
@ -36,19 +36,10 @@ const char* MinifigWizard::mSectionNames[LC_MFW_NUMITEMS] =
|
||||||
};
|
};
|
||||||
|
|
||||||
MinifigWizard::MinifigWizard()
|
MinifigWizard::MinifigWizard()
|
||||||
: lcGLWidget(nullptr)
|
: mModel(new lcModel(QString(), nullptr, false))
|
||||||
{
|
{
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
LoadTemplates();
|
LoadTemplates();
|
||||||
|
|
||||||
mModel = new lcModel(QString(), nullptr, false);
|
|
||||||
mCamera = new lcCamera(true);
|
|
||||||
|
|
||||||
mRotateX = 75.0f;
|
|
||||||
mRotateZ = 180.0f;
|
|
||||||
mDistance = 10.0f;
|
|
||||||
mAutoZoom = true;
|
|
||||||
mTracking = LC_TRACK_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MinifigWizard::~MinifigWizard()
|
MinifigWizard::~MinifigWizard()
|
||||||
|
@ -59,9 +50,6 @@ MinifigWizard::~MinifigWizard()
|
||||||
if (mMinifig.Parts[i])
|
if (mMinifig.Parts[i])
|
||||||
Library->ReleasePieceInfo(mMinifig.Parts[i]); // todo: don't call ReleasePieceInfo here because it may release textures and they need a GL context current
|
Library->ReleasePieceInfo(mMinifig.Parts[i]); // todo: don't call ReleasePieceInfo here because it may release textures and they need a GL context current
|
||||||
|
|
||||||
delete mModel;
|
|
||||||
delete mCamera;
|
|
||||||
|
|
||||||
SaveTemplates();
|
SaveTemplates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,11 +74,8 @@ void MinifigWizard::LoadSettings()
|
||||||
ParseSettings(MinifigFile);
|
ParseSettings(MinifigFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinifigWizard::OnInitialUpdate()
|
void MinifigWizard::LoadDefault()
|
||||||
{
|
{
|
||||||
MakeCurrent();
|
|
||||||
mContext->SetDefaultState();
|
|
||||||
|
|
||||||
LC_ARRAY_SIZE_CHECK(MinifigWizard::mSectionNames, LC_MFW_NUMITEMS);
|
LC_ARRAY_SIZE_CHECK(MinifigWizard::mSectionNames, LC_MFW_NUMITEMS);
|
||||||
|
|
||||||
const int ColorCodes[LC_MFW_NUMITEMS] = { 4, 7, 14, 7, 1, 0, 7, 4, 4, 14, 14, 7, 7, 0, 0, 7, 7 };
|
const int ColorCodes[LC_MFW_NUMITEMS] = { 4, 7, 14, 7, 1, 0, 7, 4, 4, 14, 14, 7, 7, 0, 0, 7, 7 };
|
||||||
|
@ -315,156 +300,6 @@ void MinifigWizard::SaveTemplates()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinifigWizard::OnDraw()
|
|
||||||
{
|
|
||||||
mContext->SetDefaultState();
|
|
||||||
|
|
||||||
mContext->SetViewport(0, 0, mWidth, mHeight);
|
|
||||||
|
|
||||||
DrawBackground();
|
|
||||||
|
|
||||||
DrawViewport();
|
|
||||||
|
|
||||||
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
|
|
||||||
|
|
||||||
for (int InfoIdx = 0; InfoIdx < LC_MFW_NUMITEMS; InfoIdx++)
|
|
||||||
{
|
|
||||||
const PieceInfo* const Info = mMinifig.Parts[InfoIdx];
|
|
||||||
|
|
||||||
if (!Info)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
lcVector3 Points[8];
|
|
||||||
lcGetBoxCorners(Info->GetBoundingBox(), Points);
|
|
||||||
|
|
||||||
for (int PointIdx = 0; PointIdx < 8; PointIdx++)
|
|
||||||
{
|
|
||||||
const lcVector3 Point = lcMul31(Points[PointIdx], mMinifig.Matrices[InfoIdx]);
|
|
||||||
|
|
||||||
Min = lcMin(Point, Min);
|
|
||||||
Max = lcMax(Point, Max);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const lcVector3 Center = (Min + Max) / 2.0f;
|
|
||||||
|
|
||||||
lcVector3 Eye(0.0f, 0.0f, 1.0f);
|
|
||||||
|
|
||||||
Eye = lcMul30(Eye, lcMatrix44RotationX(-mRotateX * LC_DTOR));
|
|
||||||
Eye = lcMul30(Eye, lcMatrix44RotationZ(-mRotateZ * LC_DTOR));
|
|
||||||
|
|
||||||
const float Aspect = (float)mWidth / (float)mHeight;
|
|
||||||
const lcMatrix44 Projection = lcMatrix44Perspective(30.0f, Aspect, 1.0f, 2500.0f);
|
|
||||||
mContext->SetProjectionMatrix(Projection);
|
|
||||||
|
|
||||||
lcMatrix44& ViewMatrix = mCamera->mWorldView;
|
|
||||||
|
|
||||||
if (mAutoZoom)
|
|
||||||
{
|
|
||||||
lcVector3 Points[8];
|
|
||||||
lcGetBoxCorners(Min, Max, Points);
|
|
||||||
|
|
||||||
Eye += Center;
|
|
||||||
|
|
||||||
const lcMatrix44 ModelView = lcMatrix44LookAt(Eye, Center, lcVector3(0, 0, 1));
|
|
||||||
std::tie(Eye, std::ignore) = lcZoomExtents(Eye, ModelView, Projection, Points, 8);
|
|
||||||
|
|
||||||
ViewMatrix = lcMatrix44LookAt(Eye, Center, lcVector3(0, 0, 1));
|
|
||||||
|
|
||||||
const lcVector3 d = Eye - Center;
|
|
||||||
mDistance = d.Length();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ViewMatrix = lcMatrix44LookAt(Eye * mDistance, Center, lcVector3(0, 0, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
Calculate();
|
|
||||||
|
|
||||||
mScene->Begin(ViewMatrix);
|
|
||||||
mScene->SetAllowLOD(false);
|
|
||||||
|
|
||||||
mModel->GetScene(mScene.get(), mCamera, false, false);
|
|
||||||
|
|
||||||
mScene->End();
|
|
||||||
|
|
||||||
mScene->Draw(mContext);
|
|
||||||
|
|
||||||
mContext->ClearResources();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinifigWizard::OnLeftButtonDown()
|
|
||||||
{
|
|
||||||
if (mTracking == LC_TRACK_NONE)
|
|
||||||
{
|
|
||||||
mDownX = mMouseX;
|
|
||||||
mDownY = mMouseY;
|
|
||||||
mTracking = LC_TRACK_LEFT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinifigWizard::OnLeftButtonUp()
|
|
||||||
{
|
|
||||||
if (mTracking == LC_TRACK_LEFT)
|
|
||||||
mTracking = LC_TRACK_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinifigWizard::OnLeftButtonDoubleClick()
|
|
||||||
{
|
|
||||||
mAutoZoom = true;
|
|
||||||
Redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinifigWizard::OnRightButtonDown()
|
|
||||||
{
|
|
||||||
if (mTracking == LC_TRACK_NONE)
|
|
||||||
{
|
|
||||||
mDownX = mMouseX;
|
|
||||||
mDownY = mMouseY;
|
|
||||||
mTracking = LC_TRACK_RIGHT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinifigWizard::OnRightButtonUp()
|
|
||||||
{
|
|
||||||
if (mTracking == LC_TRACK_RIGHT)
|
|
||||||
mTracking = LC_TRACK_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinifigWizard::OnMouseMove()
|
|
||||||
{
|
|
||||||
if (mTracking == LC_TRACK_LEFT)
|
|
||||||
{
|
|
||||||
// Rotate.
|
|
||||||
mRotateZ += mMouseX - mDownX;
|
|
||||||
mRotateX += mMouseY - mDownY;
|
|
||||||
|
|
||||||
if (mRotateX > 179.5f)
|
|
||||||
mRotateX = 179.5f;
|
|
||||||
else if (mRotateX < 0.5f)
|
|
||||||
mRotateX = 0.5f;
|
|
||||||
|
|
||||||
mDownX = mMouseX;
|
|
||||||
mDownY = mMouseY;
|
|
||||||
|
|
||||||
Redraw();
|
|
||||||
}
|
|
||||||
else if (mTracking == LC_TRACK_RIGHT)
|
|
||||||
{
|
|
||||||
// Zoom.
|
|
||||||
mDistance += (float)(mDownY - mMouseY) * 0.2f;
|
|
||||||
mAutoZoom = false;
|
|
||||||
|
|
||||||
if (mDistance < 0.5f)
|
|
||||||
mDistance = 0.5f;
|
|
||||||
|
|
||||||
mDownX = mMouseX;
|
|
||||||
mDownY = mMouseY;
|
|
||||||
|
|
||||||
Redraw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinifigWizard::Calculate()
|
void MinifigWizard::Calculate()
|
||||||
{
|
{
|
||||||
float HeadOffset = 0.0f;
|
float HeadOffset = 0.0f;
|
||||||
|
@ -650,7 +485,6 @@ int MinifigWizard::GetSelectionIndex(int Type) const
|
||||||
void MinifigWizard::SetSelectionIndex(int Type, int Index)
|
void MinifigWizard::SetSelectionIndex(int Type, int Index)
|
||||||
{
|
{
|
||||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||||
MakeCurrent();
|
|
||||||
|
|
||||||
if (mMinifig.Parts[Type])
|
if (mMinifig.Parts[Type])
|
||||||
Library->ReleasePieceInfo(mMinifig.Parts[Type]);
|
Library->ReleasePieceInfo(mMinifig.Parts[Type]);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "lc_glwidget.h"
|
|
||||||
#include "lc_math.h"
|
#include "lc_math.h"
|
||||||
|
|
||||||
enum LC_MFW_TYPES
|
enum LC_MFW_TYPES
|
||||||
|
@ -47,16 +46,19 @@ struct lcMinifigTemplate
|
||||||
float Angles[LC_MFW_NUMITEMS];
|
float Angles[LC_MFW_NUMITEMS];
|
||||||
};
|
};
|
||||||
|
|
||||||
class MinifigWizard : public lcGLWidget
|
class MinifigWizard
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MinifigWizard();
|
MinifigWizard();
|
||||||
~MinifigWizard();
|
~MinifigWizard();
|
||||||
|
|
||||||
MinifigWizard(const MinifigWizard&) = delete;
|
MinifigWizard(const MinifigWizard&) = delete;
|
||||||
MinifigWizard(MinifigWizard&&) = delete;
|
|
||||||
MinifigWizard& operator=(const MinifigWizard&) = delete;
|
MinifigWizard& operator=(const MinifigWizard&) = delete;
|
||||||
MinifigWizard& operator=(MinifigWizard&&) = delete;
|
|
||||||
|
lcModel* GetModel() const
|
||||||
|
{
|
||||||
|
return mModel.get();
|
||||||
|
}
|
||||||
|
|
||||||
const std::map<QString, lcMinifigTemplate>& GetTemplates() const
|
const std::map<QString, lcMinifigTemplate>& GetTemplates() const
|
||||||
{
|
{
|
||||||
|
@ -68,14 +70,7 @@ public:
|
||||||
void AddTemplatesJson(const QByteArray& TemplateData);
|
void AddTemplatesJson(const QByteArray& TemplateData);
|
||||||
QByteArray GetTemplatesJson() const;
|
QByteArray GetTemplatesJson() const;
|
||||||
|
|
||||||
void OnDraw() override;
|
void LoadDefault();
|
||||||
void OnLeftButtonDown() override;
|
|
||||||
void OnLeftButtonUp() override;
|
|
||||||
void OnLeftButtonDoubleClick() override;
|
|
||||||
void OnRightButtonDown() override;
|
|
||||||
void OnRightButtonUp() override;
|
|
||||||
void OnMouseMove() override;
|
|
||||||
void OnInitialUpdate() override;
|
|
||||||
|
|
||||||
void Calculate();
|
void Calculate();
|
||||||
int GetSelectionIndex(int Type) const;
|
int GetSelectionIndex(int Type) const;
|
||||||
|
@ -83,26 +78,18 @@ public:
|
||||||
void SetColor(int Type, int Color);
|
void SetColor(int Type, int Color);
|
||||||
void SetAngle(int Type, float Angle);
|
void SetAngle(int Type, float Angle);
|
||||||
|
|
||||||
void ParseSettings(lcFile& Settings);
|
|
||||||
|
|
||||||
std::vector<lcMinifigPieceInfo> mSettings[LC_MFW_NUMITEMS];
|
std::vector<lcMinifigPieceInfo> mSettings[LC_MFW_NUMITEMS];
|
||||||
|
|
||||||
lcMinifig mMinifig;
|
lcMinifig mMinifig;
|
||||||
|
|
||||||
int mTracking;
|
|
||||||
int mDownX;
|
|
||||||
int mDownY;
|
|
||||||
|
|
||||||
float mDistance;
|
|
||||||
float mRotateX;
|
|
||||||
float mRotateZ;
|
|
||||||
bool mAutoZoom;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void LoadSettings();
|
void LoadSettings();
|
||||||
|
void ParseSettings(lcFile& Settings);
|
||||||
|
|
||||||
void LoadTemplates();
|
void LoadTemplates();
|
||||||
void SaveTemplates();
|
void SaveTemplates();
|
||||||
|
|
||||||
|
std::unique_ptr<lcModel> mModel;
|
||||||
std::map<QString, lcMinifigTemplate> mTemplates;
|
std::map<QString, lcMinifigTemplate> mTemplates;
|
||||||
static const char* mSectionNames[LC_MFW_NUMITEMS];
|
static const char* mSectionNames[LC_MFW_NUMITEMS];
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,13 +29,6 @@ public:
|
||||||
bool PartsListEnd;
|
bool PartsListEnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum LC_MOUSE_TRACK
|
|
||||||
{
|
|
||||||
LC_TRACK_NONE,
|
|
||||||
LC_TRACK_LEFT,
|
|
||||||
LC_TRACK_RIGHT
|
|
||||||
};
|
|
||||||
|
|
||||||
struct lcInstructionsPageLayout;
|
struct lcInstructionsPageLayout;
|
||||||
|
|
||||||
class Project
|
class Project
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
lcVertexBuffer View::mRotateMoveVertexBuffer;
|
lcVertexBuffer View::mRotateMoveVertexBuffer;
|
||||||
lcIndexBuffer View::mRotateMoveIndexBuffer;
|
lcIndexBuffer View::mRotateMoveIndexBuffer;
|
||||||
|
|
||||||
View::View(lcModel* Model)
|
View::View(lcViewType ViewType, lcModel* Model)
|
||||||
: lcGLWidget(Model)
|
: lcGLWidget(ViewType, Model)
|
||||||
{
|
{
|
||||||
mViewSphere = std::unique_ptr<lcViewSphere>(new lcViewSphere(this));
|
mViewSphere = std::unique_ptr<lcViewSphere>(new lcViewSphere(this));
|
||||||
memset(mGridSettings, 0, sizeof(mGridSettings));
|
memset(mGridSettings, 0, sizeof(mGridSettings));
|
||||||
|
@ -638,7 +638,7 @@ void View::OnDraw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DrawInterface)
|
if (DrawInterface && mViewType == lcViewType::View)
|
||||||
mScene->SetPreTranslucentCallback([this]() { DrawGrid(); });
|
mScene->SetPreTranslucentCallback([this]() { DrawGrid(); });
|
||||||
|
|
||||||
mScene->End();
|
mScene->End();
|
||||||
|
@ -730,6 +730,8 @@ void View::OnDraw()
|
||||||
|
|
||||||
mContext->SetLineWidth(1.0f);
|
mContext->SetLineWidth(1.0f);
|
||||||
|
|
||||||
|
if (mViewType == lcViewType::View)
|
||||||
|
{
|
||||||
if (Preferences.mDrawAxes)
|
if (Preferences.mDrawAxes)
|
||||||
DrawAxes();
|
DrawAxes();
|
||||||
|
|
||||||
|
@ -748,6 +750,8 @@ void View::OnDraw()
|
||||||
DrawRotateViewOverlay();
|
DrawRotateViewOverlay();
|
||||||
|
|
||||||
mViewSphere->Draw();
|
mViewSphere->Draw();
|
||||||
|
}
|
||||||
|
|
||||||
DrawViewport();
|
DrawViewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1693,6 +1697,13 @@ void View::Zoom(float Amount)
|
||||||
|
|
||||||
void View::UpdateTrackTool()
|
void View::UpdateTrackTool()
|
||||||
{
|
{
|
||||||
|
if (mViewType != lcViewType::View)
|
||||||
|
{
|
||||||
|
mTrackTool = lcTrackTool::None;
|
||||||
|
UpdateCursor();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lcTool CurrentTool = gMainWindow->GetTool();
|
lcTool CurrentTool = gMainWindow->GetTool();
|
||||||
lcTrackTool NewTrackTool = mTrackTool;
|
lcTrackTool NewTrackTool = mTrackTool;
|
||||||
int x = mMouseX;
|
int x = mMouseX;
|
||||||
|
|
|
@ -8,7 +8,7 @@ class View : public lcGLWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
View(lcModel* Model);
|
View(lcViewType ViewType, lcModel* Model);
|
||||||
~View();
|
~View();
|
||||||
|
|
||||||
View(const View&) = delete;
|
View(const View&) = delete;
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "lc_application.h"
|
#include "lc_application.h"
|
||||||
#include "pieceinf.h"
|
#include "pieceinf.h"
|
||||||
#include "lc_library.h"
|
#include "lc_library.h"
|
||||||
|
#include "view.h"
|
||||||
|
#include "camera.h"
|
||||||
|
|
||||||
lcQMinifigDialog::lcQMinifigDialog(QWidget* Parent)
|
lcQMinifigDialog::lcQMinifigDialog(QWidget* Parent)
|
||||||
: QDialog(Parent), ui(new Ui::lcQMinifigDialog)
|
: QDialog(Parent), ui(new Ui::lcQMinifigDialog)
|
||||||
|
@ -44,15 +46,19 @@ lcQMinifigDialog::lcQMinifigDialog(QWidget* Parent)
|
||||||
QGridLayout* PreviewLayout = new QGridLayout(ui->minifigFrame);
|
QGridLayout* PreviewLayout = new QGridLayout(ui->minifigFrame);
|
||||||
PreviewLayout->setContentsMargins(0, 0, 0, 0);
|
PreviewLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
mMinifigWidget = new MinifigWizard();
|
mMinifigWizard = new MinifigWizard();
|
||||||
|
mView = new View(lcViewType::Minifig, mMinifigWizard->GetModel());
|
||||||
|
|
||||||
lcViewWidget* ViewWidget = new lcViewWidget(nullptr, mMinifigWidget);
|
lcViewWidget* ViewWidget = new lcViewWidget(nullptr, mView);
|
||||||
ViewWidget->setMinimumWidth(100);
|
ViewWidget->setMinimumWidth(100);
|
||||||
PreviewLayout->addWidget(ViewWidget);
|
PreviewLayout->addWidget(ViewWidget);
|
||||||
|
|
||||||
|
mView->MakeCurrent();
|
||||||
|
mMinifigWizard->LoadDefault();
|
||||||
|
|
||||||
for (int ItemIndex = 0; ItemIndex < LC_MFW_NUMITEMS; ItemIndex++)
|
for (int ItemIndex = 0; ItemIndex < LC_MFW_NUMITEMS; ItemIndex++)
|
||||||
{
|
{
|
||||||
std::vector<lcMinifigPieceInfo>& PartList = mMinifigWidget->mSettings[ItemIndex];
|
std::vector<lcMinifigPieceInfo>& PartList = mMinifigWizard->mSettings[ItemIndex];
|
||||||
QStringList ItemStrings;
|
QStringList ItemStrings;
|
||||||
QVector<int> Separators;
|
QVector<int> Separators;
|
||||||
|
|
||||||
|
@ -72,12 +78,12 @@ lcQMinifigDialog::lcQMinifigDialog(QWidget* Parent)
|
||||||
ItemCombo->addItems(ItemStrings);
|
ItemCombo->addItems(ItemStrings);
|
||||||
for (int SeparatorIndex = Separators.size() - 1; SeparatorIndex >= 0; SeparatorIndex--)
|
for (int SeparatorIndex = Separators.size() - 1; SeparatorIndex >= 0; SeparatorIndex--)
|
||||||
ItemCombo->insertSeparator(Separators[SeparatorIndex]);
|
ItemCombo->insertSeparator(Separators[SeparatorIndex]);
|
||||||
ItemCombo->setCurrentIndex(mMinifigWidget->GetSelectionIndex(ItemIndex));
|
ItemCombo->setCurrentIndex(mMinifigWizard->GetSelectionIndex(ItemIndex));
|
||||||
ItemCombo->blockSignals(false);
|
ItemCombo->blockSignals(false);
|
||||||
|
|
||||||
lcQColorPicker *colorPicker = mColorPickers[ItemIndex];
|
lcQColorPicker *colorPicker = mColorPickers[ItemIndex];
|
||||||
colorPicker->blockSignals(true);
|
colorPicker->blockSignals(true);
|
||||||
colorPicker->setCurrentColor(mMinifigWidget->mMinifig.Colors[ItemIndex]);
|
colorPicker->setCurrentColor(mMinifigWizard->mMinifig.Colors[ItemIndex]);
|
||||||
colorPicker->blockSignals(false);
|
colorPicker->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,12 +91,16 @@ lcQMinifigDialog::lcQMinifigDialog(QWidget* Parent)
|
||||||
ui->TemplateGroup->hide();
|
ui->TemplateGroup->hide();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mMinifigWidget->OnInitialUpdate();
|
|
||||||
UpdateTemplateCombo();
|
UpdateTemplateCombo();
|
||||||
|
|
||||||
|
mMinifigWizard->Calculate();
|
||||||
|
mView->GetCamera()->SetViewpoint(lcVector3(0.0f, -270.0f, 90.0f));
|
||||||
|
mView->ZoomExtents();
|
||||||
}
|
}
|
||||||
|
|
||||||
lcQMinifigDialog::~lcQMinifigDialog()
|
lcQMinifigDialog::~lcQMinifigDialog()
|
||||||
{
|
{
|
||||||
|
delete mMinifigWizard;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +108,7 @@ void lcQMinifigDialog::UpdateTemplateCombo()
|
||||||
{
|
{
|
||||||
ui->TemplateComboBox->clear();
|
ui->TemplateComboBox->clear();
|
||||||
|
|
||||||
const auto& Templates = mMinifigWidget->GetTemplates();
|
const auto& Templates = mMinifigWizard->GetTemplates();
|
||||||
for (const auto& Template : Templates)
|
for (const auto& Template : Templates)
|
||||||
ui->TemplateComboBox->addItem(Template.first);
|
ui->TemplateComboBox->addItem(Template.first);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +116,7 @@ void lcQMinifigDialog::UpdateTemplateCombo()
|
||||||
void lcQMinifigDialog::on_TemplateComboBox_currentIndexChanged(const QString& TemplateName)
|
void lcQMinifigDialog::on_TemplateComboBox_currentIndexChanged(const QString& TemplateName)
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||||
const auto& Templates = mMinifigWidget->GetTemplates();
|
const auto& Templates = mMinifigWizard->GetTemplates();
|
||||||
const auto& Position = Templates.find(TemplateName);
|
const auto& Position = Templates.find(TemplateName);
|
||||||
if (Position == Templates.end())
|
if (Position == Templates.end())
|
||||||
return;
|
return;
|
||||||
|
@ -121,7 +131,7 @@ void lcQMinifigDialog::on_TemplateComboBox_currentIndexChanged(const QString& Te
|
||||||
|
|
||||||
if (Info)
|
if (Info)
|
||||||
{
|
{
|
||||||
for (const lcMinifigPieceInfo& MinifigPieceInfo : mMinifigWidget->mSettings[PartIdx])
|
for (const lcMinifigPieceInfo& MinifigPieceInfo : mMinifigWizard->mSettings[PartIdx])
|
||||||
{
|
{
|
||||||
if (Info == MinifigPieceInfo.Info)
|
if (Info == MinifigPieceInfo.Info)
|
||||||
{
|
{
|
||||||
|
@ -142,6 +152,8 @@ void lcQMinifigDialog::on_TemplateComboBox_currentIndexChanged(const QString& Te
|
||||||
if (AngleSpinBox)
|
if (AngleSpinBox)
|
||||||
AngleSpinBox->setValue(Template.Angles[PartIdx]);
|
AngleSpinBox->setValue(Template.Angles[PartIdx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMinifigWizard->Calculate();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,13 +184,13 @@ void lcQMinifigDialog::on_TemplateSaveButton_clicked()
|
||||||
|
|
||||||
for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++)
|
for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++)
|
||||||
{
|
{
|
||||||
Template.Parts[PartIdx] = mMinifigWidget->mSettings[PartIdx][mComboBoxes[PartIdx]->currentIndex()].Info->mFileName;
|
Template.Parts[PartIdx] = mMinifigWizard->mSettings[PartIdx][mComboBoxes[PartIdx]->currentIndex()].Info->mFileName;
|
||||||
Template.Colors[PartIdx] = mColorPickers[PartIdx]->currentColorCode();
|
Template.Colors[PartIdx] = mColorPickers[PartIdx]->currentColorCode();
|
||||||
QDoubleSpinBox* AngleSpinBox = mSpinBoxes[PartIdx];
|
QDoubleSpinBox* AngleSpinBox = mSpinBoxes[PartIdx];
|
||||||
Template.Angles[PartIdx] = AngleSpinBox ? AngleSpinBox->value() : 0.0f;
|
Template.Angles[PartIdx] = AngleSpinBox ? AngleSpinBox->value() : 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
mMinifigWidget->SaveTemplate(TemplateName, Template);
|
mMinifigWizard->SaveTemplate(TemplateName, Template);
|
||||||
|
|
||||||
ui->TemplateComboBox->blockSignals(true);
|
ui->TemplateComboBox->blockSignals(true);
|
||||||
UpdateTemplateCombo();
|
UpdateTemplateCombo();
|
||||||
|
@ -195,7 +207,7 @@ void lcQMinifigDialog::on_TemplateDeleteButton_clicked()
|
||||||
if (QMessageBox::question(this, tr("Delete Template"), Question, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
|
if (QMessageBox::question(this, tr("Delete Template"), Question, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mMinifigWidget->DeleteTemplate(Template);
|
mMinifigWizard->DeleteTemplate(Template);
|
||||||
|
|
||||||
UpdateTemplateCombo();
|
UpdateTemplateCombo();
|
||||||
}
|
}
|
||||||
|
@ -216,7 +228,7 @@ void lcQMinifigDialog::on_TemplateImportButton_clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray FileData = File.readAll();
|
QByteArray FileData = File.readAll();
|
||||||
mMinifigWidget->AddTemplatesJson(FileData);
|
mMinifigWizard->AddTemplatesJson(FileData);
|
||||||
|
|
||||||
UpdateTemplateCombo();
|
UpdateTemplateCombo();
|
||||||
}
|
}
|
||||||
|
@ -236,7 +248,7 @@ void lcQMinifigDialog::on_TemplateExportButton_clicked()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray Templates = mMinifigWidget->GetTemplatesJson();
|
QByteArray Templates = mMinifigWizard->GetTemplatesJson();
|
||||||
File.write(Templates);
|
File.write(Templates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,8 +259,9 @@ void lcQMinifigDialog::TypeChanged(int Index)
|
||||||
if (Search == mComboBoxes.end())
|
if (Search == mComboBoxes.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mMinifigWidget->SetSelectionIndex(std::distance(mComboBoxes.begin(), Search), Index);
|
mView->MakeCurrent();
|
||||||
mMinifigWidget->Redraw();
|
mMinifigWizard->SetSelectionIndex(std::distance(mComboBoxes.begin(), Search), Index);
|
||||||
|
mView->Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcQMinifigDialog::ColorChanged(int Index)
|
void lcQMinifigDialog::ColorChanged(int Index)
|
||||||
|
@ -258,8 +271,8 @@ void lcQMinifigDialog::ColorChanged(int Index)
|
||||||
if (Search == mColorPickers.end())
|
if (Search == mColorPickers.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mMinifigWidget->SetColor(std::distance(mColorPickers.begin(), Search), Index);
|
mMinifigWizard->SetColor(std::distance(mColorPickers.begin(), Search), Index);
|
||||||
mMinifigWidget->Redraw();
|
mView->Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcQMinifigDialog::AngleChanged(double Value)
|
void lcQMinifigDialog::AngleChanged(double Value)
|
||||||
|
@ -269,6 +282,6 @@ void lcQMinifigDialog::AngleChanged(double Value)
|
||||||
if (Search == mSpinBoxes.end())
|
if (Search == mSpinBoxes.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mMinifigWidget->SetAngle(std::distance(mSpinBoxes.begin(), Search), Value);
|
mMinifigWizard->SetAngle(std::distance(mSpinBoxes.begin(), Search), Value);
|
||||||
mMinifigWidget->Redraw();
|
mView->Redraw();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "minifig.h"
|
#include "minifig.h"
|
||||||
class lcQColorPicker;
|
class lcQColorPicker;
|
||||||
|
class View;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class lcQMinifigDialog;
|
class lcQMinifigDialog;
|
||||||
|
@ -15,7 +16,7 @@ public:
|
||||||
explicit lcQMinifigDialog(QWidget* Parent);
|
explicit lcQMinifigDialog(QWidget* Parent);
|
||||||
~lcQMinifigDialog();
|
~lcQMinifigDialog();
|
||||||
|
|
||||||
MinifigWizard* mMinifigWidget;
|
MinifigWizard* mMinifigWizard;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_TemplateComboBox_currentIndexChanged(const QString& TemplateName);
|
void on_TemplateComboBox_currentIndexChanged(const QString& TemplateName);
|
||||||
|
@ -32,6 +33,7 @@ protected:
|
||||||
|
|
||||||
Ui::lcQMinifigDialog* ui;
|
Ui::lcQMinifigDialog* ui;
|
||||||
|
|
||||||
|
View* mView;
|
||||||
std::array<QComboBox*, LC_MFW_NUMITEMS> mComboBoxes;
|
std::array<QComboBox*, LC_MFW_NUMITEMS> mComboBoxes;
|
||||||
std::array<lcQColorPicker*, LC_MFW_NUMITEMS> mColorPickers;
|
std::array<lcQColorPicker*, LC_MFW_NUMITEMS> mColorPickers;
|
||||||
std::array<QDoubleSpinBox*, LC_MFW_NUMITEMS> mSpinBoxes;
|
std::array<QDoubleSpinBox*, LC_MFW_NUMITEMS> mSpinBoxes;
|
||||||
|
|
Loading…
Add table
Reference in a new issue