From aa45875a2be8a6a43f150f18fd993aecde0785b0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 28 Jan 2021 16:22:40 +0100 Subject: [PATCH] Gui: modernize C++ --- src/Gui/View3DInventor.cpp | 49 ++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index ee55f39111..43a923a66b 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -782,42 +782,45 @@ bool View3DInventor::setCamera(const char* pCamera) CoinPtr camPtr(Cam, true); // toggle between perspective and orthographic camera - if (Cam->getTypeId() != CamViewer->getTypeId()) - { + if (Cam->getTypeId() != CamViewer->getTypeId()) { _viewer->setCameraType(Cam->getTypeId()); CamViewer = _viewer->getSoRenderManager()->getCamera(); } - SoPerspectiveCamera * CamViewerP = 0; - SoOrthographicCamera * CamViewerO = 0; + SoPerspectiveCamera * CamViewerP = nullptr; + SoOrthographicCamera * CamViewerO = nullptr; if (CamViewer->getTypeId() == SoPerspectiveCamera::getClassTypeId()) { - CamViewerP = (SoPerspectiveCamera *)CamViewer; // safe downward cast, knows the type - } else if (CamViewer->getTypeId() == SoOrthographicCamera::getClassTypeId()) { - CamViewerO = (SoOrthographicCamera *)CamViewer; // safe downward cast, knows the type + CamViewerP = static_cast(CamViewer); // safe downward cast, knows the type + } + else if (CamViewer->getTypeId() == SoOrthographicCamera::getClassTypeId()) { + CamViewerO = static_cast(CamViewer); // safe downward cast, knows the type } if (Cam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) { if (CamViewerP){ - CamViewerP->position = ((SoPerspectiveCamera *)Cam)->position; - CamViewerP->orientation = ((SoPerspectiveCamera *)Cam)->orientation; - CamViewerP->nearDistance = ((SoPerspectiveCamera *)Cam)->nearDistance; - CamViewerP->farDistance = ((SoPerspectiveCamera *)Cam)->farDistance; - CamViewerP->focalDistance = ((SoPerspectiveCamera *)Cam)->focalDistance; - } else { + CamViewerP->position = static_cast(Cam)->position; + CamViewerP->orientation = static_cast(Cam)->orientation; + CamViewerP->nearDistance = static_cast(Cam)->nearDistance; + CamViewerP->farDistance = static_cast(Cam)->farDistance; + CamViewerP->focalDistance = static_cast(Cam)->focalDistance; + } + else { throw Base::TypeError("Camera type mismatch"); } - } else if (Cam->getTypeId() == SoOrthographicCamera::getClassTypeId()) { + } + else if (Cam->getTypeId() == SoOrthographicCamera::getClassTypeId()) { if (CamViewerO){ - CamViewerO->viewportMapping = ((SoOrthographicCamera *)Cam)->viewportMapping; - CamViewerO->position = ((SoOrthographicCamera *)Cam)->position; - CamViewerO->orientation = ((SoOrthographicCamera *)Cam)->orientation; - CamViewerO->nearDistance = ((SoOrthographicCamera *)Cam)->nearDistance; - CamViewerO->farDistance = ((SoOrthographicCamera *)Cam)->farDistance; - CamViewerO->focalDistance = ((SoOrthographicCamera *)Cam)->focalDistance; - CamViewerO->aspectRatio = ((SoOrthographicCamera *)Cam)->aspectRatio ; - CamViewerO->height = ((SoOrthographicCamera *)Cam)->height; - } else { + CamViewerO->viewportMapping = static_cast(Cam)->viewportMapping; + CamViewerO->position = static_cast(Cam)->position; + CamViewerO->orientation = static_cast(Cam)->orientation; + CamViewerO->nearDistance = static_cast(Cam)->nearDistance; + CamViewerO->farDistance = static_cast(Cam)->farDistance; + CamViewerO->focalDistance = static_cast(Cam)->focalDistance; + CamViewerO->aspectRatio = static_cast(Cam)->aspectRatio ; + CamViewerO->height = static_cast(Cam)->height; + } + else { throw Base::TypeError("Camera type mismatch"); } }