Reorganized redraw.

This commit is contained in:
Leonardo Zide 2020-12-15 17:19:32 -08:00
parent a0385a3783
commit de29c49608
13 changed files with 136 additions and 121 deletions

View file

@ -1057,5 +1057,5 @@ void lcApplication::ShowPreferencesDialog()
*/ */
gMainWindow->SetShadingMode(Options.Preferences.mShadingMode); gMainWindow->SetShadingMode(Options.Preferences.mShadingMode);
gMainWindow->UpdateAllViews(); lcGLWidget::UpdateAllViews();
} }

View file

@ -10,15 +10,19 @@
#include "lc_scene.h" #include "lc_scene.h"
lcGLWidget* lcGLWidget::mLastFocusedView; lcGLWidget* lcGLWidget::mLastFocusedView;
std::vector<lcGLWidget*> lcGLWidget::mViews;
lcGLWidget::lcGLWidget(lcModel* Model) lcGLWidget::lcGLWidget(lcModel* Model)
: mScene(new lcScene()), mModel(Model) : mScene(new lcScene()), mModel(Model)
{ {
mContext = new lcContext(); mContext = new lcContext();
mViews.push_back(this);
} }
lcGLWidget::~lcGLWidget() lcGLWidget::~lcGLWidget()
{ {
mViews.erase(std::find(mViews.begin(), mViews.end(), this));
if (mLastFocusedView == this) if (mLastFocusedView == this)
mLastFocusedView = nullptr; mLastFocusedView = nullptr;
@ -26,6 +30,23 @@ lcGLWidget::~lcGLWidget()
delete mContext; delete mContext;
} }
void lcGLWidget::UpdateProjectViews(const Project* Project)
{
for (lcGLWidget* View : mViews)
{
const lcModel* ViewModel = View->GetActiveModel();
if (ViewModel->GetProject() == Project)
View->Redraw();
}
}
void lcGLWidget::UpdateAllViews()
{
for (lcGLWidget* View : mViews)
View->Redraw();
}
lcModel* lcGLWidget::GetActiveModel() const lcModel* lcGLWidget::GetActiveModel() const
{ {
return !mActiveSubmodelInstance ? mModel : mActiveSubmodelInstance->mPieceInfo->GetModel(); return !mActiveSubmodelInstance ? mModel : mActiveSubmodelInstance->mPieceInfo->GetModel();
@ -484,6 +505,11 @@ lcVector3 lcGLWidget::GetCameraLightInsertPosition() const
return lcRayPointClosestPoint(Center, ClickPoints[0], ClickPoints[1]); return lcRayPointClosestPoint(Center, ClickPoints[0], ClickPoints[1]);
} }
void lcGLWidget::OnMouseWheel(float Direction)
{
mModel->Zoom(mCamera, (int)(((mMouseModifiers & Qt::ControlModifier) ? 100 : 10) * Direction));
}
void lcGLWidget::DrawBackground() const void lcGLWidget::DrawBackground() const
{ {
const lcPreferences& Preferences = lcGetPreferences(); const lcPreferences& Preferences = lcGetPreferences();

View file

@ -91,6 +91,9 @@ public:
lcGLWidget(const lcGLWidget&) = delete; lcGLWidget(const lcGLWidget&) = delete;
lcGLWidget& operator=(const lcGLWidget&) = delete; lcGLWidget& operator=(const lcGLWidget&) = delete;
static void UpdateProjectViews(const Project* Project);
static void UpdateAllViews();
lcModel* GetActiveModel() const; lcModel* GetActiveModel() const;
lcCamera* GetCamera() const lcCamera* GetCamera() const
@ -186,7 +189,7 @@ public:
virtual void OnForwardButtonDown() { } virtual void OnForwardButtonDown() { }
virtual void OnForwardButtonUp() { } virtual void OnForwardButtonUp() { }
virtual void OnMouseMove() { } virtual void OnMouseMove() { }
virtual void OnMouseWheel(float Direction) { Q_UNUSED(Direction); } void OnMouseWheel(float Direction);
virtual void BeginDrag(lcDragState DragState) { Q_UNUSED(DragState); } virtual void BeginDrag(lcDragState DragState) { Q_UNUSED(DragState); }
virtual void EndDrag(bool Accept) { Q_UNUSED(Accept); } virtual void EndDrag(bool Accept) { Q_UNUSED(Accept); }
@ -227,4 +230,5 @@ protected:
bool mDeleteContext = true; bool mDeleteContext = true;
static lcGLWidget* mLastFocusedView; static lcGLWidget* mLastFocusedView;
static std::vector<lcGLWidget*> mViews;
}; };

View file

@ -1111,7 +1111,7 @@ void lcMainWindow::ProjectFileChanged(const QString& Path)
QByteArray TabLayout = GetTabLayout(); QByteArray TabLayout = GetTabLayout();
gApplication->SetProject(NewProject); gApplication->SetProject(NewProject);
RestoreTabLayout(TabLayout); RestoreTabLayout(TabLayout);
UpdateAllViews(); lcGLWidget::UpdateAllViews();
} }
} }
else else
@ -1320,7 +1320,7 @@ void lcMainWindow::SetShadingMode(lcShadingMode ShadingMode)
{ {
lcGetPreferences().mShadingMode = ShadingMode; lcGetPreferences().mShadingMode = ShadingMode;
UpdateShadingMode(); UpdateShadingMode();
UpdateAllViews(); lcGLWidget::UpdateAllViews();
if (mPartSelectionWidget) if (mPartSelectionWidget)
mPartSelectionWidget->Redraw(); mPartSelectionWidget->Redraw();
} }
@ -1335,21 +1335,21 @@ void lcMainWindow::ToggleViewSphere()
{ {
lcGetPreferences().mViewSphereEnabled = !lcGetPreferences().mViewSphereEnabled; lcGetPreferences().mViewSphereEnabled = !lcGetPreferences().mViewSphereEnabled;
UpdateAllViews(); lcGLWidget::UpdateAllViews();
} }
void lcMainWindow::ToggleAxisIcon() void lcMainWindow::ToggleAxisIcon()
{ {
lcGetPreferences().mDrawAxes = !lcGetPreferences().mDrawAxes; lcGetPreferences().mDrawAxes = !lcGetPreferences().mDrawAxes;
UpdateAllViews(); lcGLWidget::UpdateAllViews();
} }
void lcMainWindow::ToggleFadePreviousSteps() void lcMainWindow::ToggleFadePreviousSteps()
{ {
lcGetPreferences().mFadeSteps = !lcGetPreferences().mFadeSteps; lcGetPreferences().mFadeSteps = !lcGetPreferences().mFadeSteps;
UpdateAllViews(); lcGLWidget::UpdateAllViews();
} }
QByteArray lcMainWindow::GetTabLayout() QByteArray lcMainWindow::GetTabLayout()
@ -1691,19 +1691,6 @@ void lcMainWindow::SetActiveView(View* ActiveView)
UpdatePerspective(); UpdatePerspective();
} }
void lcMainWindow::UpdateAllViews()
{
lcModelTabWidget* CurrentTab = (lcModelTabWidget*)mModelTabWidget->currentWidget();
if (CurrentTab)
{
const lcArray<View*>* Views = CurrentTab->GetViews();
for (int ViewIdx = 0; ViewIdx < Views->GetSize(); ViewIdx++)
(*Views)[ViewIdx]->Redraw();
}
}
void lcMainWindow::SetTool(lcTool Tool) void lcMainWindow::SetTool(lcTool Tool)
{ {
mTool = Tool; mTool = Tool;
@ -1713,7 +1700,7 @@ void lcMainWindow::SetTool(lcTool Tool)
if (Action) if (Action)
Action->setChecked(true); Action->setChecked(true);
UpdateAllViews(); lcGLWidget::UpdateAllViews();
} }
void lcMainWindow::SetColorIndex(int ColorIndex) void lcMainWindow::SetColorIndex(int ColorIndex)
@ -1760,7 +1747,7 @@ void lcMainWindow::SetRelativeTransform(bool RelativeTransform)
{ {
mRelativeTransform = RelativeTransform; mRelativeTransform = RelativeTransform;
UpdateLockSnap(); UpdateLockSnap();
UpdateAllViews(); lcGLWidget::UpdateAllViews();
} }
void lcMainWindow::SetLocalTransform(bool SelectionTransform) void lcMainWindow::SetLocalTransform(bool SelectionTransform)
@ -2378,7 +2365,7 @@ bool lcMainWindow::OpenProjectFile(const QString& FileName)
{ {
gApplication->SetProject(NewProject); gApplication->SetProject(NewProject);
AddRecentFile(FileName); AddRecentFile(FileName);
UpdateAllViews(); lcGLWidget::UpdateProjectViews(NewProject);
return true; return true;
} }
@ -2434,7 +2421,7 @@ void lcMainWindow::ImportLDD()
if (NewProject->ImportLDD(LoadFileName)) if (NewProject->ImportLDD(LoadFileName))
{ {
gApplication->SetProject(NewProject); gApplication->SetProject(NewProject);
UpdateAllViews(); lcGLWidget::UpdateProjectViews(NewProject);
} }
else else
delete NewProject; delete NewProject;
@ -2454,7 +2441,7 @@ void lcMainWindow::ImportInventory()
if (NewProject->ImportInventory(Dialog.GetSetInventory(), Dialog.GetSetName(), Dialog.GetSetDescription())) if (NewProject->ImportInventory(Dialog.GetSetInventory(), Dialog.GetSetName(), Dialog.GetSetDescription()))
{ {
gApplication->SetProject(NewProject); gApplication->SetProject(NewProject);
UpdateAllViews(); lcGLWidget::UpdateProjectViews(NewProject);
} }
else else
delete NewProject; delete NewProject;

View file

@ -286,7 +286,6 @@ public:
void AddView(View* View); void AddView(View* View);
void RemoveView(View* View); void RemoveView(View* View);
void SetActiveView(View* ActiveView); void SetActiveView(View* ActiveView);
void UpdateAllViews();
void SetTool(lcTool Tool); void SetTool(lcTool Tool);
void SetTransformType(lcTransformType TransformType); void SetTransformType(lcTransformType TransformType);

View file

@ -109,8 +109,8 @@ void lcModelProperties::ParseLDrawLine(QTextStream& Stream)
} }
} }
lcModel::lcModel(const QString& FileName, bool Preview) lcModel::lcModel(const QString& FileName, Project* Project, bool Preview)
: mIsPreview(Preview) : mProject(Project), mIsPreview(Preview)
{ {
mProperties.mModelName = FileName; mProperties.mModelName = FileName;
mProperties.mFileName = FileName; mProperties.mFileName = FileName;
@ -228,6 +228,11 @@ void lcModel::UpdateMesh()
mPieceInfo->SetModel(this, true, nullptr, false); mPieceInfo->SetModel(this, true, nullptr, false);
} }
void lcModel::UpdateAllViews() const
{
View::UpdateProjectViews(mProject);
}
void lcModel::UpdatePieceInfo(std::vector<lcModel*>& UpdatedModels) void lcModel::UpdatePieceInfo(std::vector<lcModel*>& UpdatedModels)
{ {
if (std::find(UpdatedModels.begin(), UpdatedModels.end(), this) != UpdatedModels.end()) if (std::find(UpdatedModels.begin(), UpdatedModels.end(), this) != UpdatedModels.end())
@ -1110,7 +1115,7 @@ void lcModel::Cut()
{ {
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Cutting")); SaveCheckpoint(tr("Cutting"));
} }
} }
@ -1130,7 +1135,7 @@ void lcModel::Paste()
if (gApplication->mClipboard.isEmpty()) if (gApplication->mClipboard.isEmpty())
return; return;
lcModel* Model = new lcModel(QString()); lcModel* Model = new lcModel(QString(), nullptr, false);
QBuffer Buffer(&gApplication->mClipboard); QBuffer Buffer(&gApplication->mClipboard);
Buffer.open(QIODevice::ReadOnly); Buffer.open(QIODevice::ReadOnly);
@ -1158,7 +1163,7 @@ void lcModel::Paste()
CalculateStep(mCurrentStep); CalculateStep(mCurrentStep);
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::DuplicateSelectedPieces() void lcModel::DuplicateSelectedPieces()
@ -1699,7 +1704,7 @@ void lcModel::LoadCheckPoint(lcModelHistoryEntry* CheckPoint)
gMainWindow->UpdateCameraMenu(); gMainWindow->UpdateCameraMenu();
gMainWindow->UpdateCurrentStep(); gMainWindow->UpdateCurrentStep();
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
for (PieceInfo* Info : LoadedInfos) for (PieceInfo* Info : LoadedInfos)
Library->ReleasePieceInfo(Info); Library->ReleasePieceInfo(Info);
@ -1740,7 +1745,7 @@ void lcModel::SetCurrentStep(lcStep Step)
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdateCurrentStep(); gMainWindow->UpdateCurrentStep();
} }
@ -2255,7 +2260,7 @@ void lcModel::DeleteAllCameras()
gMainWindow->UpdateCameraMenu(); gMainWindow->UpdateCameraMenu();
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Resetting Cameras")); SaveCheckpoint(tr("Resetting Cameras"));
} }
@ -2266,7 +2271,7 @@ void lcModel::DeleteSelectedObjects()
if (!mIsPreview) { if (!mIsPreview) {
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Deleting")); SaveCheckpoint(tr("Deleting"));
} }
} }
@ -2278,7 +2283,7 @@ void lcModel::ResetSelectedPiecesPivotPoint()
if (Piece->IsSelected()) if (Piece->IsSelected())
Piece->ResetPivotPoint(); Piece->ResetPivotPoint();
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::RemoveSelectedPiecesKeyFrames() void lcModel::RemoveSelectedPiecesKeyFrames()
@ -2295,7 +2300,7 @@ void lcModel::RemoveSelectedPiecesKeyFrames()
if (Light->IsSelected()) if (Light->IsSelected())
Light->RemoveKeyFrames(); Light->RemoveKeyFrames();
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Removing Key Frames")); SaveCheckpoint(tr("Removing Key Frames"));
} }
@ -2315,7 +2320,7 @@ void lcModel::InsertControlPoint()
{ {
SaveCheckpoint(tr("Modifying")); SaveCheckpoint(tr("Modifying"));
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
} }
@ -2332,7 +2337,7 @@ void lcModel::RemoveFocusedControlPoint()
{ {
SaveCheckpoint(tr("Modifying")); SaveCheckpoint(tr("Modifying"));
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
} }
@ -2375,7 +2380,7 @@ void lcModel::ShowSelectedPiecesEarlier()
SaveCheckpoint(tr("Modifying")); SaveCheckpoint(tr("Modifying"));
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::ShowSelectedPiecesLater() void lcModel::ShowSelectedPiecesLater()
@ -2420,7 +2425,7 @@ void lcModel::ShowSelectedPiecesLater()
SaveCheckpoint(tr("Modifying")); SaveCheckpoint(tr("Modifying"));
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::SetPieceSteps(const QList<QPair<lcPiece*, lcStep>>& PieceSteps) void lcModel::SetPieceSteps(const QList<QPair<lcPiece*, lcStep>>& PieceSteps)
@ -2453,7 +2458,7 @@ void lcModel::SetPieceSteps(const QList<QPair<lcPiece*, lcStep>>& PieceSteps)
if (Modified) if (Modified)
{ {
SaveCheckpoint(tr("Modifying")); SaveCheckpoint(tr("Modifying"));
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
} }
@ -2713,7 +2718,7 @@ void lcModel::MoveSelectedObjects(const lcVector3& PieceDistance, const lcVector
if (Moved && Update) if (Moved && Update)
{ {
gMainWindow->UpdateAllViews(); UpdateAllViews();
if (Checkpoint) if (Checkpoint)
SaveCheckpoint(tr("Moving")); SaveCheckpoint(tr("Moving"));
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
@ -2808,7 +2813,7 @@ void lcModel::RotateSelectedPieces(const lcVector3& Angles, bool Relative, bool
if (Rotated && Update) if (Rotated && Update)
{ {
gMainWindow->UpdateAllViews(); UpdateAllViews();
if (Checkpoint) if (Checkpoint)
SaveCheckpoint(tr("Rotating")); SaveCheckpoint(tr("Rotating"));
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
@ -2834,7 +2839,7 @@ void lcModel::ScaleSelectedPieces(const float Scale, bool Update, bool Checkpoin
if (Update) if (Update)
{ {
gMainWindow->UpdateAllViews(); UpdateAllViews();
if (Checkpoint) if (Checkpoint)
SaveCheckpoint(tr("Scaling")); SaveCheckpoint(tr("Scaling"));
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
@ -2884,7 +2889,7 @@ void lcModel::SetSelectedPiecesColorIndex(int ColorIndex)
{ {
SaveCheckpoint(tr("Painting")); SaveCheckpoint(tr("Painting"));
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdateTimeline(false, true); gMainWindow->UpdateTimeline(false, true);
} }
} }
@ -2908,7 +2913,7 @@ void lcModel::SetSelectedPiecesPieceInfo(PieceInfo* Info)
{ {
SaveCheckpoint(tr("Setting Part")); SaveCheckpoint(tr("Setting Part"));
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdateTimeline(false, true); gMainWindow->UpdateTimeline(false, true);
} }
} }
@ -2937,7 +2942,7 @@ void lcModel::SetSelectedPiecesStepShow(lcStep Step)
if (Modified) if (Modified)
{ {
SaveCheckpoint(tr("Showing Pieces")); SaveCheckpoint(tr("Showing Pieces"));
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(SelectionChanged); gMainWindow->UpdateSelectedObjects(SelectionChanged);
} }
@ -2967,7 +2972,7 @@ void lcModel::SetSelectedPiecesStepHide(lcStep Step)
if (Modified) if (Modified)
{ {
SaveCheckpoint(tr("Hiding Pieces")); SaveCheckpoint(tr("Hiding Pieces"));
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(SelectionChanged); gMainWindow->UpdateSelectedObjects(SelectionChanged);
} }
@ -2982,7 +2987,7 @@ void lcModel::SetCameraOrthographic(lcCamera* Camera, bool Ortho)
Camera->UpdatePosition(mCurrentStep); Camera->UpdatePosition(mCurrentStep);
SaveCheckpoint(tr("Editing Camera")); SaveCheckpoint(tr("Editing Camera"));
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdatePerspective(); gMainWindow->UpdatePerspective();
} }
@ -2995,7 +3000,7 @@ void lcModel::SetCameraFOV(lcCamera* Camera, float FOV)
Camera->UpdatePosition(mCurrentStep); Camera->UpdatePosition(mCurrentStep);
SaveCheckpoint(tr("Changing FOV")); SaveCheckpoint(tr("Changing FOV"));
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::SetCameraZNear(lcCamera* Camera, float ZNear) void lcModel::SetCameraZNear(lcCamera* Camera, float ZNear)
@ -3007,7 +3012,7 @@ void lcModel::SetCameraZNear(lcCamera* Camera, float ZNear)
Camera->UpdatePosition(mCurrentStep); Camera->UpdatePosition(mCurrentStep);
SaveCheckpoint(tr("Editing Camera")); SaveCheckpoint(tr("Editing Camera"));
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::SetCameraZFar(lcCamera* Camera, float ZFar) void lcModel::SetCameraZFar(lcCamera* Camera, float ZFar)
@ -3019,7 +3024,7 @@ void lcModel::SetCameraZFar(lcCamera* Camera, float ZFar)
Camera->UpdatePosition(mCurrentStep); Camera->UpdatePosition(mCurrentStep);
SaveCheckpoint(tr("Editing Camera")); SaveCheckpoint(tr("Editing Camera"));
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::SetCameraName(lcCamera* Camera, const QString& Name) void lcModel::SetCameraName(lcCamera* Camera, const QString& Name)
@ -3031,7 +3036,7 @@ void lcModel::SetCameraName(lcCamera* Camera, const QString& Name)
SaveCheckpoint(tr("Renaming Camera")); SaveCheckpoint(tr("Renaming Camera"));
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdateCameraMenu(); gMainWindow->UpdateCameraMenu();
} }
@ -3484,7 +3489,7 @@ void lcModel::ClearSelection(bool UpdateInterface)
if (UpdateInterface) if (UpdateInterface)
{ {
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
} }
@ -3540,7 +3545,7 @@ void lcModel::FocusOrDeselectObject(const lcObjectSection& ObjectSection)
} }
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::ClearSelectionAndSetFocus(lcObject* Object, quint32 Section, bool EnableSelectionMode) void lcModel::ClearSelectionAndSetFocus(lcObject* Object, quint32 Section, bool EnableSelectionMode)
@ -3564,7 +3569,7 @@ void lcModel::ClearSelectionAndSetFocus(lcObject* Object, quint32 Section, bool
} }
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection, bool EnableSelectionMode) void lcModel::ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection, bool EnableSelectionMode)
@ -3618,7 +3623,7 @@ void lcModel::AddToSelection(const lcArray<lcObject*>& Objects, bool EnableSelec
if (UpdateInterface) if (UpdateInterface)
{ {
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
} }
@ -3652,7 +3657,7 @@ void lcModel::RemoveFromSelection(const lcArray<lcObject*>& Objects)
} }
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::RemoveFromSelection(const lcObjectSection& ObjectSection) void lcModel::RemoveFromSelection(const lcObjectSection& ObjectSection)
@ -3692,7 +3697,7 @@ void lcModel::RemoveFromSelection(const lcObjectSection& ObjectSection)
} }
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::SelectAllPieces() void lcModel::SelectAllPieces()
@ -3701,10 +3706,9 @@ void lcModel::SelectAllPieces()
if (Piece->IsVisible(mCurrentStep)) if (Piece->IsVisible(mCurrentStep))
Piece->SetSelected(true); Piece->SetSelected(true);
if (!mIsPreview) { if (!mIsPreview)
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
}
} }
void lcModel::InvertSelection() void lcModel::InvertSelection()
@ -3714,7 +3718,7 @@ void lcModel::InvertSelection()
Piece->SetSelected(!Piece->IsSelected()); Piece->SetSelected(!Piece->IsSelected());
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::HideSelectedPieces() void lcModel::HideSelectedPieces()
@ -3736,7 +3740,7 @@ void lcModel::HideSelectedPieces()
gMainWindow->UpdateTimeline(false, true); gMainWindow->UpdateTimeline(false, true);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Hide")); SaveCheckpoint(tr("Hide"));
} }
@ -3759,7 +3763,7 @@ void lcModel::HideUnselectedPieces()
gMainWindow->UpdateTimeline(false, true); gMainWindow->UpdateTimeline(false, true);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Hide")); SaveCheckpoint(tr("Hide"));
} }
@ -3782,7 +3786,7 @@ void lcModel::UnhideSelectedPieces()
gMainWindow->UpdateTimeline(false, true); gMainWindow->UpdateTimeline(false, true);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Unhide")); SaveCheckpoint(tr("Unhide"));
} }
@ -3805,7 +3809,7 @@ void lcModel::UnhideAllPieces()
gMainWindow->UpdateTimeline(false, true); gMainWindow->UpdateTimeline(false, true);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Unhide")); SaveCheckpoint(tr("Unhide"));
} }
@ -4014,7 +4018,7 @@ void lcModel::UpdateSpotLightTool(const lcVector3& Position)
mMouseToolDistance = Position; mMouseToolDistance = Position;
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::BeginCameraTool(const lcVector3& Position, const lcVector3& Target) void lcModel::BeginCameraTool(const lcVector3& Position, const lcVector3& Target)
@ -4038,7 +4042,7 @@ void lcModel::UpdateCameraTool(const lcVector3& Position)
mMouseToolDistance = Position; mMouseToolDistance = Position;
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::UpdateMoveTool(const lcVector3& Distance, bool AlternateButtonDrag) void lcModel::UpdateMoveTool(const lcVector3& Distance, bool AlternateButtonDrag)
@ -4050,7 +4054,7 @@ void lcModel::UpdateMoveTool(const lcVector3& Distance, bool AlternateButtonDrag
mMouseToolDistance = Distance; mMouseToolDistance = Distance;
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::UpdateRotateTool(const lcVector3& Angles, bool AlternateButtonDrag) void lcModel::UpdateRotateTool(const lcVector3& Angles, bool AlternateButtonDrag)
@ -4060,7 +4064,7 @@ void lcModel::UpdateRotateTool(const lcVector3& Angles, bool AlternateButtonDrag
mMouseToolDistance = Angles; mMouseToolDistance = Angles;
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::UpdateScaleTool(const float Scale) void lcModel::UpdateScaleTool(const float Scale)
@ -4068,7 +4072,7 @@ void lcModel::UpdateScaleTool(const float Scale)
ScaleSelectedPieces(Scale, true, false); ScaleSelectedPieces(Scale, true, false);
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::EraserToolClicked(lcObject* Object) void lcModel::EraserToolClicked(lcObject* Object)
@ -4109,7 +4113,7 @@ void lcModel::EraserToolClicked(lcObject* Object)
delete Object; delete Object;
gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews(); UpdateAllViews();
SaveCheckpoint(tr("Deleting")); SaveCheckpoint(tr("Deleting"));
} }
@ -4126,7 +4130,7 @@ void lcModel::PaintToolClicked(lcObject* Object)
SaveCheckpoint(tr("Painting")); SaveCheckpoint(tr("Painting"));
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
gMainWindow->UpdateTimeline(false, true); gMainWindow->UpdateTimeline(false, true);
} }
} }
@ -4145,33 +4149,36 @@ void lcModel::UpdateZoomTool(lcCamera* Camera, float Mouse)
{ {
Camera->Zoom(Mouse - mMouseToolDistance.x, mCurrentStep, gMainWindow->GetAddKeys()); Camera->Zoom(Mouse - mMouseToolDistance.x, mCurrentStep, gMainWindow->GetAddKeys());
mMouseToolDistance.x = Mouse; mMouseToolDistance.x = Mouse;
gMainWindow->UpdateAllViews();
UpdateAllViews();
} }
void lcModel::UpdatePanTool(lcCamera* Camera, const lcVector3& Distance) void lcModel::UpdatePanTool(lcCamera* Camera, const lcVector3& Distance)
{ {
Camera->Pan(Distance - mMouseToolDistance, mCurrentStep, gMainWindow->GetAddKeys()); Camera->Pan(Distance - mMouseToolDistance, mCurrentStep, gMainWindow->GetAddKeys());
mMouseToolDistance = Distance; mMouseToolDistance = Distance;
if (!mIsPreview)
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::UpdateOrbitTool(lcCamera* Camera, float MouseX, float MouseY) void lcModel::UpdateOrbitTool(lcCamera* Camera, float MouseX, float MouseY)
{ {
lcVector3 Center; lcVector3 Center;
GetSelectionCenter(Center); GetSelectionCenter(Center);
Camera->Orbit(MouseX - mMouseToolDistance.x, MouseY - mMouseToolDistance.y, Center, mCurrentStep, gMainWindow->GetAddKeys()); Camera->Orbit(MouseX - mMouseToolDistance.x, MouseY - mMouseToolDistance.y, Center, mCurrentStep, gMainWindow->GetAddKeys());
mMouseToolDistance.x = MouseX; mMouseToolDistance.x = MouseX;
mMouseToolDistance.y = MouseY; mMouseToolDistance.y = MouseY;
if (!mIsPreview)
gMainWindow->UpdateAllViews(); UpdateAllViews();
} }
void lcModel::UpdateRollTool(lcCamera* Camera, float Mouse) void lcModel::UpdateRollTool(lcCamera* Camera, float Mouse)
{ {
Camera->Roll(Mouse - mMouseToolDistance.x, mCurrentStep, gMainWindow->GetAddKeys()); Camera->Roll(Mouse - mMouseToolDistance.x, mCurrentStep, gMainWindow->GetAddKeys());
mMouseToolDistance.x = Mouse; mMouseToolDistance.x = Mouse;
gMainWindow->UpdateAllViews();
UpdateAllViews();
} }
void lcModel::ZoomRegionToolClicked(lcCamera* Camera, float AspectRatio, const lcVector3& Position, const lcVector3& TargetPosition, const lcVector3* Corners) void lcModel::ZoomRegionToolClicked(lcCamera* Camera, float AspectRatio, const lcVector3& Position, const lcVector3& TargetPosition, const lcVector3* Corners)
@ -4179,7 +4186,7 @@ void lcModel::ZoomRegionToolClicked(lcCamera* Camera, float AspectRatio, const l
Camera->ZoomRegion(AspectRatio, Position, TargetPosition, Corners, mCurrentStep, gMainWindow->GetAddKeys()); Camera->ZoomRegion(AspectRatio, Position, TargetPosition, Corners, mCurrentStep, gMainWindow->GetAddKeys());
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
if (!Camera->IsSimple()) if (!Camera->IsSimple())
SaveCheckpoint(tr("Zoom")); SaveCheckpoint(tr("Zoom"));
@ -4202,7 +4209,7 @@ void lcModel::LookAt(lcCamera* Camera)
Camera->Center(Center, mCurrentStep, gMainWindow->GetAddKeys()); Camera->Center(Center, mCurrentStep, gMainWindow->GetAddKeys());
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
if (!Camera->IsSimple()) if (!Camera->IsSimple())
SaveCheckpoint(tr("Look At")); SaveCheckpoint(tr("Look At"));
@ -4212,7 +4219,7 @@ void lcModel::MoveCamera(lcCamera* Camera, const lcVector3& Direction)
{ {
Camera->MoveRelative(Direction, mCurrentStep, gMainWindow->GetAddKeys()); Camera->MoveRelative(Direction, mCurrentStep, gMainWindow->GetAddKeys());
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
if (!Camera->IsSimple()) if (!Camera->IsSimple())
SaveCheckpoint(tr("Moving Camera")); SaveCheckpoint(tr("Moving Camera"));
@ -4232,10 +4239,9 @@ void lcModel::ZoomExtents(lcCamera* Camera, float Aspect)
Camera->ZoomExtents(Aspect, Center, Points, 8, mCurrentStep, mIsPreview ? false : gMainWindow->GetAddKeys()); Camera->ZoomExtents(Aspect, Center, Points, 8, mCurrentStep, mIsPreview ? false : gMainWindow->GetAddKeys());
if (!mIsPreview) { if (!mIsPreview)
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
}
if (!Camera->IsSimple()) if (!Camera->IsSimple())
SaveCheckpoint(tr("Zoom")); SaveCheckpoint(tr("Zoom"));
@ -4244,10 +4250,11 @@ void lcModel::ZoomExtents(lcCamera* Camera, float Aspect)
void lcModel::Zoom(lcCamera* Camera, float Amount) void lcModel::Zoom(lcCamera* Camera, float Amount)
{ {
Camera->Zoom(Amount, mCurrentStep, mIsPreview ? false : gMainWindow->GetAddKeys()); Camera->Zoom(Amount, mCurrentStep, mIsPreview ? false : gMainWindow->GetAddKeys());
if (!mIsPreview) {
if (!mIsPreview)
gMainWindow->UpdateSelectedObjects(false); gMainWindow->UpdateSelectedObjects(false);
gMainWindow->UpdateAllViews(); UpdateAllViews();
}
if (!Camera->IsSimple()) if (!Camera->IsSimple())
SaveCheckpoint(tr("Zoom")); SaveCheckpoint(tr("Zoom"));
} }

View file

@ -82,13 +82,16 @@ struct lcModelHistoryEntry
class lcModel class lcModel
{ {
public: public:
lcModel(const QString& FileName, bool Preview = false); lcModel(const QString& FileName, Project* Project, bool Preview);
~lcModel(); ~lcModel();
lcModel(const lcModel&) = delete; lcModel(const lcModel&) = delete;
lcModel(lcModel&&) = delete;
lcModel& operator=(const lcModel&) = delete; lcModel& operator=(const lcModel&) = delete;
lcModel& operator=(lcModel&&) = delete;
Project* GetProject() const
{
return mProject;
}
bool IsModified() const bool IsModified() const
{ {
@ -105,6 +108,7 @@ public:
void CreatePieceInfo(Project* Project); void CreatePieceInfo(Project* Project);
void UpdatePieceInfo(std::vector<lcModel*>& UpdatedModels); void UpdatePieceInfo(std::vector<lcModel*>& UpdatedModels);
void UpdateMesh(); void UpdateMesh();
void UpdateAllViews() const;
PieceInfo* GetPieceInfo() const PieceInfo* GetPieceInfo() const
{ {
@ -365,6 +369,7 @@ protected:
void InsertPiece(lcPiece* Piece, int Index); void InsertPiece(lcPiece* Piece, int Index);
lcModelProperties mProperties; lcModelProperties mProperties;
Project* const mProject;
PieceInfo* mPieceInfo; PieceInfo* mPieceInfo;
bool mIsPreview; bool mIsPreview;

View file

@ -458,9 +458,3 @@ void lcPreviewWidget::OnMouseMove()
break; break;
} }
} }
void lcPreviewWidget::OnMouseWheel(float Direction)
{
mModel->Zoom(mCamera, (int)(((mMouseModifiers & Qt::ControlModifier) ? 100 : 10) * Direction));
Redraw();
}

View file

@ -60,7 +60,6 @@ public:
void OnRightButtonDown() override; void OnRightButtonDown() override;
void OnRightButtonUp() override; void OnRightButtonUp() override;
void OnMouseMove() override; void OnMouseMove() override;
void OnMouseWheel(float Direction) override;
protected: protected:
void StopTracking(bool Accept); void StopTracking(bool Accept);

View file

@ -41,7 +41,7 @@ MinifigWizard::MinifigWizard()
LoadSettings(); LoadSettings();
LoadTemplates(); LoadTemplates();
mModel = new lcModel(QString(), false); mModel = new lcModel(QString(), nullptr, false);
mCamera = new lcCamera(true); mCamera = new lcCamera(true);
mRotateX = 75.0f; mRotateX = 75.0f;

View file

@ -64,7 +64,7 @@ Project::Project(bool IsPreview)
: mIsPreview(IsPreview) : mIsPreview(IsPreview)
{ {
mModified = false; mModified = false;
mActiveModel = new lcModel(tr(mIsPreview ? "Preview.ldr" : "New Model.ldr"), mIsPreview); mActiveModel = new lcModel(tr(mIsPreview ? "Preview.ldr" : "New Model.ldr"), this, mIsPreview);
mActiveModel->CreatePieceInfo(this); mActiveModel->CreatePieceInfo(this);
mActiveModel->SetSaved(); mActiveModel->SetSaved();
mModels.Add(mActiveModel); mModels.Add(mActiveModel);
@ -249,7 +249,7 @@ lcModel* Project::CreateNewModel(bool ShowModel)
return nullptr; return nullptr;
mModified = true; mModified = true;
lcModel* Model = new lcModel(Name); lcModel* Model = new lcModel(Name, this, false);
Model->CreatePieceInfo(this); Model->CreatePieceInfo(this);
Model->SetSaved(); Model->SetSaved();
mModels.Add(Model); mModels.Add(Model);
@ -285,11 +285,11 @@ void Project::ShowModelListDialog()
if (!Source) if (!Source)
{ {
Model = new lcModel(Entry.Name); Model = new lcModel(Entry.Name, this, false);
} }
else else
{ {
Model = new lcModel(Source->GetProperties().mFileName); Model = new lcModel(Source->GetProperties().mFileName, this, false);
QByteArray File; QByteArray File;
@ -396,7 +396,7 @@ bool Project::Load(const QString& FileName)
while (!Buffer.atEnd()) while (!Buffer.atEnd())
{ {
lcModel* Model = new lcModel(QString(), mIsPreview); lcModel* Model = new lcModel(QString(), this, mIsPreview);
int Pos = Model->SplitMPD(Buffer); int Pos = Model->SplitMPD(Buffer);
if (Models.empty() || !Model->GetFileName().isEmpty()) if (Models.empty() || !Model->GetFileName().isEmpty())
@ -433,7 +433,7 @@ bool Project::Load(const QString& FileName)
MemFile.WriteBuffer(FileData.constData(), FileData.size()); MemFile.WriteBuffer(FileData.constData(), FileData.size());
MemFile.Seek(0, SEEK_SET); MemFile.Seek(0, SEEK_SET);
lcModel* Model = new lcModel(QString(), mIsPreview); lcModel* Model = new lcModel(QString(), this, mIsPreview);
if (Model->LoadBinary(&MemFile)) if (Model->LoadBinary(&MemFile))
{ {
@ -566,7 +566,7 @@ bool Project::ImportLDD(const QString& FileName)
mModels.DeleteAll(); mModels.DeleteAll();
QString ModelName = QFileInfo(FileName).completeBaseName(); QString ModelName = QFileInfo(FileName).completeBaseName();
lcModel* Model = new lcModel(ModelName); lcModel* Model = new lcModel(ModelName, this, false);
if (Model->LoadLDD(QString::fromUtf8((const char*)XMLFile.mBuffer))) if (Model->LoadLDD(QString::fromUtf8((const char*)XMLFile.mBuffer)))
{ {
@ -599,7 +599,7 @@ bool Project::ImportInventory(const QByteArray& Inventory, const QString& Name,
return false; return false;
mModels.DeleteAll(); mModels.DeleteAll();
lcModel* Model = new lcModel(Name); lcModel* Model = new lcModel(Name, this, false);
if (Model->LoadInventory(Inventory)) if (Model->LoadInventory(Inventory))
{ {

View file

@ -1609,11 +1609,11 @@ void View::BeginDrag(lcDragState DragState)
} }
void View::EndDrag(bool Accept) void View::EndDrag(bool Accept)
{
if (Accept)
{ {
lcModel* ActiveModel = GetActiveModel(); lcModel* ActiveModel = GetActiveModel();
if (Accept)
{
switch (mDragState) switch (mDragState)
{ {
case lcDragState::None: case lcDragState::None:
@ -1634,7 +1634,7 @@ void View::EndDrag(bool Accept)
mDragState = lcDragState::None; mDragState = lcDragState::None;
UpdateTrackTool(); UpdateTrackTool();
gMainWindow->UpdateAllViews(); ActiveModel->UpdateAllViews();
} }
void View::SetProjection(bool Ortho) void View::SetProjection(bool Ortho)
@ -2125,7 +2125,7 @@ void View::UpdateTrackTool()
UpdateCursor(); UpdateCursor();
if (Redraw) if (Redraw)
gMainWindow->UpdateAllViews(); ActiveModel->UpdateAllViews();
} }
bool View::IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const bool View::IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const
@ -2293,7 +2293,7 @@ void View::StopTracking(bool Accept)
mTrackButton = lcTrackButton::None; mTrackButton = lcTrackButton::None;
UpdateTrackTool(); UpdateTrackTool();
gMainWindow->UpdateAllViews(); ActiveModel->UpdateAllViews();
} }
void View::CancelTrackingOrClearSelection() void View::CancelTrackingOrClearSelection()
@ -2557,7 +2557,7 @@ void View::OnMouseMove()
UpdateTrackTool(); UpdateTrackTool();
if (mTrackTool == lcTrackTool::Insert) if (mTrackTool == lcTrackTool::Insert)
gMainWindow->UpdateAllViews(); ActiveModel->UpdateAllViews();
return; return;
} }
@ -2869,8 +2869,3 @@ void View::OnMouseMove()
break; break;
} }
} }
void View::OnMouseWheel(float Direction)
{
mModel->Zoom(mCamera, (int)(((mMouseModifiers & Qt::ControlModifier) ? 100 : 10) * Direction));
}

View file

@ -46,7 +46,6 @@ public:
void OnBackButtonUp() override; void OnBackButtonUp() override;
void OnForwardButtonUp() override; void OnForwardButtonUp() override;
void OnMouseMove() override; void OnMouseMove() override;
void OnMouseWheel(float Direction) override;
void BeginDrag(lcDragState DragState) override; void BeginDrag(lcDragState DragState) override;
void EndDrag(bool Accept) override; void EndDrag(bool Accept) override;