2020-10-03 12:02:27 +02:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_previewwidget.h"
|
|
|
|
#include "pieceinf.h"
|
|
|
|
#include "piece.h"
|
|
|
|
#include "project.h"
|
|
|
|
#include "lc_model.h"
|
|
|
|
#include "lc_library.h"
|
2020-12-18 02:59:11 +01:00
|
|
|
#include "lc_viewwidget.h"
|
2020-12-25 19:43:22 +01:00
|
|
|
#include "lc_view.h"
|
2020-10-03 12:02:27 +02:00
|
|
|
|
2020-10-07 10:08:58 +02:00
|
|
|
lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow* Parent)
|
|
|
|
: QMainWindow(Parent)
|
2020-10-03 12:02:27 +02:00
|
|
|
{
|
2020-12-24 20:32:56 +01:00
|
|
|
mPreview = new lcPreview();
|
2020-12-18 02:59:11 +01:00
|
|
|
mViewWidget = new lcViewWidget(nullptr, mPreview);
|
2020-10-07 12:07:32 +02:00
|
|
|
setCentralWidget(mViewWidget);
|
2020-10-03 12:02:27 +02:00
|
|
|
setMinimumSize(200, 200);
|
2020-10-07 12:07:32 +02:00
|
|
|
|
2020-10-07 13:42:43 +02:00
|
|
|
mLockAction = new QAction(QIcon(":/resources/action_preview_unlocked.png"),tr("Lock Preview"), this);
|
|
|
|
mLockAction->setCheckable(true);
|
|
|
|
mLockAction->setChecked(false);
|
|
|
|
mLockAction->setShortcut(tr("Ctrl+L"));
|
|
|
|
connect(mLockAction, SIGNAL(triggered()), this, SLOT(SetPreviewLock()));
|
|
|
|
SetPreviewLock();
|
|
|
|
|
2020-12-24 20:32:56 +01:00
|
|
|
mLabel = new QLabel();
|
2020-10-07 13:42:43 +02:00
|
|
|
|
2020-10-13 01:23:15 +02:00
|
|
|
mToolBar = addToolBar(tr("Toolbar"));
|
|
|
|
mToolBar->setObjectName("Toolbar");
|
|
|
|
mToolBar->setStatusTip(tr("Preview Toolbar"));
|
2020-10-07 12:07:32 +02:00
|
|
|
mToolBar->setMovable(false);
|
2020-10-07 13:42:43 +02:00
|
|
|
mToolBar->addAction(mLockAction);
|
|
|
|
mToolBar->addSeparator();
|
2020-10-07 12:07:32 +02:00
|
|
|
mToolBar->addWidget(mLabel);
|
2020-10-13 01:23:15 +02:00
|
|
|
if (mToolBar->isHidden())
|
|
|
|
mToolBar->show();
|
2020-10-03 12:02:27 +02:00
|
|
|
}
|
|
|
|
|
2020-10-07 10:08:58 +02:00
|
|
|
bool lcPreviewDockWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
|
2020-10-03 12:02:27 +02:00
|
|
|
{
|
2020-10-07 13:42:43 +02:00
|
|
|
if (mLockAction->isChecked())
|
|
|
|
return true;
|
|
|
|
|
2020-10-07 12:07:32 +02:00
|
|
|
mLabel->setText(tr("Loading..."));
|
|
|
|
if (mPreview->SetCurrentPiece(PartType, ColorCode))
|
2020-10-07 10:08:58 +02:00
|
|
|
{
|
2020-10-07 12:07:32 +02:00
|
|
|
mLabel->setText(mPreview->GetDescription());
|
2020-10-03 12:02:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-12 22:59:14 +02:00
|
|
|
void lcPreviewDockWidget::UpdatePreview()
|
|
|
|
{
|
|
|
|
mPreview->UpdatePreview();
|
|
|
|
}
|
|
|
|
|
2020-10-03 12:02:27 +02:00
|
|
|
void lcPreviewDockWidget::ClearPreview()
|
|
|
|
{
|
2024-05-26 22:01:34 +02:00
|
|
|
if (mPreview->GetModel()->GetPieces().size())
|
2020-10-07 16:56:49 +02:00
|
|
|
mPreview->ClearPreview();
|
2020-12-24 20:32:56 +01:00
|
|
|
|
2020-10-07 12:07:32 +02:00
|
|
|
mLabel->setText(QString());
|
2020-10-03 12:02:27 +02:00
|
|
|
}
|
|
|
|
|
2020-10-07 13:42:43 +02:00
|
|
|
void lcPreviewDockWidget::SetPreviewLock()
|
|
|
|
{
|
|
|
|
bool Locked = mLockAction->isChecked();
|
2020-12-24 20:32:56 +01:00
|
|
|
|
2024-05-26 22:01:34 +02:00
|
|
|
if (Locked && mPreview->GetModel()->GetPieces().empty())
|
2020-10-07 13:42:43 +02:00
|
|
|
{
|
|
|
|
mLockAction->setChecked(false);
|
|
|
|
return;
|
|
|
|
}
|
2020-12-24 20:32:56 +01:00
|
|
|
|
2020-10-07 13:42:43 +02:00
|
|
|
QIcon LockIcon(Locked ? ":/resources/action_preview_locked.png" : ":/resources/action_preview_unlocked.png");
|
2022-05-16 21:36:52 +02:00
|
|
|
QString StatusTip(Locked
|
|
|
|
? tr("Unlock the preview display to enable updates")
|
|
|
|
: tr("Lock the preview display to disable updates"));
|
2020-12-24 20:32:56 +01:00
|
|
|
|
2022-05-16 21:36:52 +02:00
|
|
|
mLockAction->setToolTip(Locked ? tr("Unlock Preview") : tr("Lock Preview"));
|
2020-10-07 13:42:43 +02:00
|
|
|
mLockAction->setIcon(LockIcon);
|
|
|
|
mLockAction->setStatusTip(StatusTip);
|
|
|
|
}
|
|
|
|
|
2020-12-24 20:32:56 +01:00
|
|
|
lcPreview::lcPreview()
|
2020-12-25 19:54:33 +01:00
|
|
|
: lcView(lcViewType::Preview, nullptr), mLoader(new Project(true))
|
2020-10-03 12:02:27 +02:00
|
|
|
{
|
|
|
|
mLoader->SetActiveModel(0);
|
2020-10-07 10:08:58 +02:00
|
|
|
mModel = mLoader->GetActiveModel();
|
2020-10-03 12:02:27 +02:00
|
|
|
}
|
|
|
|
|
2020-12-24 20:32:56 +01:00
|
|
|
bool lcPreview::SetCurrentPiece(const QString& PartType, int ColorCode)
|
2020-10-03 12:02:27 +02:00
|
|
|
{
|
2020-10-07 10:08:58 +02:00
|
|
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
2020-10-03 12:02:27 +02:00
|
|
|
PieceInfo* Info = Library->FindPiece(PartType.toLatin1().constData(), nullptr, false, false);
|
2020-10-07 10:08:58 +02:00
|
|
|
|
|
|
|
if (Info)
|
|
|
|
{
|
2024-06-20 04:22:18 +02:00
|
|
|
for (const std::unique_ptr<lcPiece>& ModelPiece : mModel->GetPieces())
|
2020-10-08 15:17:31 +02:00
|
|
|
{
|
|
|
|
if (Info == ModelPiece->mPieceInfo)
|
|
|
|
{
|
2021-01-17 03:27:39 +01:00
|
|
|
int ModelColorCode = ModelPiece->GetColorCode();
|
2020-10-08 15:17:31 +02:00
|
|
|
if (ModelColorCode == ColorCode)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 12:07:32 +02:00
|
|
|
mIsModel = Info->IsModel();
|
2020-10-03 12:02:27 +02:00
|
|
|
mDescription = Info->m_strDescription;
|
|
|
|
|
2020-12-24 20:32:56 +01:00
|
|
|
mModel->SelectAllPieces();
|
|
|
|
mModel->DeleteSelectedObjects();
|
2020-10-03 12:02:27 +02:00
|
|
|
|
|
|
|
Library->LoadPieceInfo(Info, false, true);
|
|
|
|
Library->WaitForLoadQueue();
|
|
|
|
|
2021-01-09 00:11:02 +01:00
|
|
|
mModel->SetPreviewPieceInfo(Info, lcGetColorIndex(ColorCode));
|
2020-10-03 12:02:27 +02:00
|
|
|
|
2021-01-09 00:11:02 +01:00
|
|
|
Library->ReleasePieceInfo(Info);
|
2020-10-07 10:08:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString ModelPath = QString("%1/%2").arg(QDir::currentPath()).arg(PartType);
|
2020-10-03 12:02:27 +02:00
|
|
|
|
2021-04-17 20:49:41 +02:00
|
|
|
if (!mLoader->Load(ModelPath, false))
|
2020-10-03 12:02:27 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
mLoader->SetActiveModel(0);
|
|
|
|
lcGetPiecesLibrary()->RemoveTemporaryPieces();
|
|
|
|
mModel = mLoader->GetActiveModel();
|
|
|
|
if (!mModel->GetProperties().mDescription.isEmpty())
|
|
|
|
mDescription = mModel->GetProperties().mDescription;
|
|
|
|
else
|
|
|
|
mDescription = PartType;
|
2020-10-07 12:07:32 +02:00
|
|
|
mIsModel = true;
|
2020-10-03 12:02:27 +02:00
|
|
|
}
|
2020-10-07 10:08:58 +02:00
|
|
|
|
2020-10-03 12:02:27 +02:00
|
|
|
ZoomExtents();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-24 20:32:56 +01:00
|
|
|
void lcPreview::ClearPreview()
|
2020-10-03 12:02:27 +02:00
|
|
|
{
|
2020-12-24 20:32:56 +01:00
|
|
|
mLoader = std::unique_ptr<Project>(new Project(true/*IsPreview*/));
|
2020-10-03 12:02:27 +02:00
|
|
|
mLoader->SetActiveModel(0);
|
|
|
|
mModel = mLoader->GetActiveModel();
|
|
|
|
lcGetPiecesLibrary()->UnloadUnusedParts();
|
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
|
2020-12-24 20:32:56 +01:00
|
|
|
void lcPreview::UpdatePreview()
|
2020-10-12 22:59:14 +02:00
|
|
|
{
|
|
|
|
QString PartType;
|
|
|
|
int ColorCode = -1;
|
2020-12-24 20:32:56 +01:00
|
|
|
|
2024-06-20 04:22:18 +02:00
|
|
|
for (const std::unique_ptr<lcPiece>& ModelPiece : mModel->GetPieces())
|
2020-10-12 22:59:14 +02:00
|
|
|
{
|
|
|
|
if (ModelPiece->mPieceInfo)
|
|
|
|
{
|
|
|
|
PartType = ModelPiece->mPieceInfo->mFileName;
|
2021-01-17 03:27:39 +01:00
|
|
|
ColorCode = ModelPiece->GetColorCode();
|
2020-10-12 22:59:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearPreview();
|
|
|
|
|
|
|
|
if (!PartType.isEmpty() && ColorCode > -1)
|
|
|
|
SetCurrentPiece(PartType, ColorCode);
|
|
|
|
}
|