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->UpdateAllViews();
lcGLWidget::UpdateAllViews();
}

View file

@ -10,15 +10,19 @@
#include "lc_scene.h"
lcGLWidget* lcGLWidget::mLastFocusedView;
std::vector<lcGLWidget*> lcGLWidget::mViews;
lcGLWidget::lcGLWidget(lcModel* Model)
: mScene(new lcScene()), mModel(Model)
{
mContext = new lcContext();
mViews.push_back(this);
}
lcGLWidget::~lcGLWidget()
{
mViews.erase(std::find(mViews.begin(), mViews.end(), this));
if (mLastFocusedView == this)
mLastFocusedView = nullptr;
@ -26,6 +30,23 @@ lcGLWidget::~lcGLWidget()
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
{
return !mActiveSubmodelInstance ? mModel : mActiveSubmodelInstance->mPieceInfo->GetModel();
@ -484,6 +505,11 @@ lcVector3 lcGLWidget::GetCameraLightInsertPosition() const
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
{
const lcPreferences& Preferences = lcGetPreferences();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -458,9 +458,3 @@ void lcPreviewWidget::OnMouseMove()
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 OnRightButtonUp() override;
void OnMouseMove() override;
void OnMouseWheel(float Direction) override;
protected:
void StopTracking(bool Accept);

View file

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

View file

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

View file

@ -1610,10 +1610,10 @@ void View::BeginDrag(lcDragState DragState)
void View::EndDrag(bool Accept)
{
lcModel* ActiveModel = GetActiveModel();
if (Accept)
{
lcModel* ActiveModel = GetActiveModel();
switch (mDragState)
{
case lcDragState::None:
@ -1634,7 +1634,7 @@ void View::EndDrag(bool Accept)
mDragState = lcDragState::None;
UpdateTrackTool();
gMainWindow->UpdateAllViews();
ActiveModel->UpdateAllViews();
}
void View::SetProjection(bool Ortho)
@ -2125,7 +2125,7 @@ void View::UpdateTrackTool()
UpdateCursor();
if (Redraw)
gMainWindow->UpdateAllViews();
ActiveModel->UpdateAllViews();
}
bool View::IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const
@ -2293,7 +2293,7 @@ void View::StopTracking(bool Accept)
mTrackButton = lcTrackButton::None;
UpdateTrackTool();
gMainWindow->UpdateAllViews();
ActiveModel->UpdateAllViews();
}
void View::CancelTrackingOrClearSelection()
@ -2557,7 +2557,7 @@ void View::OnMouseMove()
UpdateTrackTool();
if (mTrackTool == lcTrackTool::Insert)
gMainWindow->UpdateAllViews();
ActiveModel->UpdateAllViews();
return;
}
@ -2869,8 +2869,3 @@ void View::OnMouseMove()
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 OnForwardButtonUp() override;
void OnMouseMove() override;
void OnMouseWheel(float Direction) override;
void BeginDrag(lcDragState DragState) override;
void EndDrag(bool Accept) override;