diff --git a/common/lc_application.cpp b/common/lc_application.cpp index b72fa4ce..f3c3aa2e 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -66,7 +66,11 @@ void lcApplication::SetProject(Project* Project) const lcArray& Views = gMainWindow->GetViews(); for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++) - Views[ViewIdx]->SetModel(lcGetActiveModel()); + { + View* View = Views[ViewIdx]; + View->ClearCameras(); + View->SetModel(lcGetActiveModel()); + } lcGetPiecesLibrary()->RemoveTemporaryPieces(); lcGetActiveModel()->UpdateInterface(); diff --git a/common/view.cpp b/common/view.cpp index c2770d9b..4579e8d8 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -33,8 +33,9 @@ View::~View() if (gMainWindow) gMainWindow->RemoveView(this); - if (mCamera && mCamera->IsSimple()) - delete mCamera; + foreach (lcCamera* Camera, mCameras) + if (Camera && Camera->IsSimple()) + delete Camera; } void View::SetModel(lcModel* Model) @@ -44,14 +45,28 @@ void View::SetModel(lcModel* Model) mModel = Model; - if (mCamera && !mCamera->IsSimple()) + lcCamera* Camera = mCameras.value(mModel); + + if (Camera) + mCamera = Camera; + else { - lcCamera* Camera = mCamera; + Camera = mCamera; mCamera = new lcCamera(true); if (Camera) mCamera->CopyPosition(Camera); + else + mCamera->SetViewpoint(LC_VIEWPOINT_HOME); } + + mCameras[mModel] = mCamera; +} + +void View::ClearCameras() +{ + mCamera = NULL; + mCameras.clear(); } void View::RemoveCamera() @@ -64,6 +79,10 @@ void View::RemoveCamera() if (Camera) mCamera->CopyPosition(Camera); + else + mCamera->SetViewpoint(LC_VIEWPOINT_HOME); + + mCameras[mModel] = mCamera; gMainWindow->UpdateCurrentCamera(-1); Redraw(); @@ -85,6 +104,8 @@ void View::SetCamera(lcCamera* Camera, bool ForceCopy) mCamera = Camera; } + + mCameras[mModel] = mCamera; } void View::SetCameraIndex(int Index) @@ -104,7 +125,10 @@ void View::SetCameraIndex(int Index) void View::SetViewpoint(lcViewpoint Viewpoint) { if (!mCamera || !mCamera->IsSimple()) + { mCamera = new lcCamera(true); + mCameras[mModel] = mCamera; + } mCamera->SetViewpoint(Viewpoint); ZoomExtents(); @@ -114,7 +138,10 @@ void View::SetViewpoint(lcViewpoint Viewpoint) void View::SetDefaultCamera() { if (!mCamera || !mCamera->IsSimple()) + { mCamera = new lcCamera(true); + mCameras[mModel] = mCamera; + } mCamera->SetViewpoint(LC_VIEWPOINT_HOME); } diff --git a/common/view.h b/common/view.h index 8efe0375..3d10436e 100644 --- a/common/view.h +++ b/common/view.h @@ -80,6 +80,7 @@ public: void LookAt(); void ZoomExtents(); + void ClearCameras(); void RemoveCamera(); void SetCamera(lcCamera* Camera, bool ForceCopy); void SetCameraIndex(int Index); @@ -95,6 +96,7 @@ public: lcModel* mModel; lcCamera* mCamera; + QMap mCameras; lcVector3 ProjectPoint(const lcVector3& Point) const {