From 61117162da06d165916c1e0f0cd8c625034cae92 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 25 Aug 2026 11:17:49 +0200 Subject: [PATCH] #14602 Contour map: Keep interactive panning when reloading a project Viewer::setView() moves the camera to look straight at the point of interest. Panning does not move the point of interest, so this discarded the camera position restored from the project file. Only reset the view direction if the camera is not already oriented top-down, which is the case when a contour map has been rotated by a linked 3D view. --- .../ContourMap/RimEclipseContourMapView.cpp | 13 +++++++++++-- .../GeoMech/RimGeoMechContourMapView.cpp | 13 +++++++++++-- ApplicationLibCode/ProjectDataModel/Rim3dView.cpp | 13 +++++++++++++ ApplicationLibCode/ProjectDataModel/Rim3dView.h | 1 + 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapView.cpp b/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapView.cpp index d5baa3feb6..8765deea33 100644 --- a/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapView.cpp +++ b/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapView.cpp @@ -506,9 +506,18 @@ void RimEclipseContourMapView::updateViewFollowingCellFilterUpdates() void RimEclipseContourMapView::onLoadDataAndUpdate() { RimEclipseView::onLoadDataAndUpdate(); - if ( nativeOrOverrideViewer() ) + if ( auto viewer = nativeOrOverrideViewer() ) { - nativeOrOverrideViewer()->setView( cvf::Vec3d( 0, 0, -1 ), cvf::Vec3d( 0, 1, 0 ) ); + const cvf::Vec3d viewDirection( 0, 0, -1 ); + const cvf::Vec3d upDirection( 0, 1, 0 ); + + // setView() moves the camera to look straight at the point of interest. Panning does not move the point of + // interest, so calling setView() will discard the panning restored from the project file. The camera is + // already oriented correctly for a contour map, unless the view has been rotated by a linked 3D view. + if ( !isCameraOriented( viewDirection, upDirection ) ) + { + viewer->setView( viewDirection, upDirection ); + } } } diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp index 499bbfddbc..f5468850d3 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp @@ -460,9 +460,18 @@ void RimGeoMechContourMapView::updateViewFollowingCellFilterUpdates() void RimGeoMechContourMapView::onLoadDataAndUpdate() { RimGeoMechView::onLoadDataAndUpdate(); - if ( nativeOrOverrideViewer() ) + if ( auto viewer = nativeOrOverrideViewer() ) { - nativeOrOverrideViewer()->setView( cvf::Vec3d( 0, 0, -1 ), cvf::Vec3d( 0, 1, 0 ) ); + const cvf::Vec3d viewDirection( 0, 0, -1 ); + const cvf::Vec3d upDirection( 0, 1, 0 ); + + // setView() moves the camera to look straight at the point of interest. Panning does not move the point of + // interest, so calling setView() will discard the panning restored from the project file. The camera is + // already oriented correctly for a contour map, unless the view has been rotated by a linked 3D view. + if ( !isCameraOriented( viewDirection, upDirection ) ) + { + viewer->setView( viewDirection, upDirection ); + } } } diff --git a/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp b/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp index f4a8574bb1..370778302b 100644 --- a/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp @@ -1653,6 +1653,19 @@ cvf::Vec3d Rim3dView::cameraPointOfInterest() const return m_cameraPointOfInterest(); } +//-------------------------------------------------------------------------------------------------- +/// Returns true if the camera is already oriented along the given view direction and up direction +//-------------------------------------------------------------------------------------------------- +bool Rim3dView::isCameraOriented( const cvf::Vec3d& viewDirection, const cvf::Vec3d& upDirection ) const +{ + auto viewer = nativeOrOverrideViewer(); + if ( !viewer || !viewer->mainCamera() ) return false; + + const double tolerance = 1.0e-6; + return ( viewer->mainCamera()->direction() - viewDirection ).length() < tolerance && + ( viewer->mainCamera()->up() - upDirection ).length() < tolerance; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Rim3dView.h b/ApplicationLibCode/ProjectDataModel/Rim3dView.h index 4ddee74370..01e2d8e851 100644 --- a/ApplicationLibCode/ProjectDataModel/Rim3dView.h +++ b/ApplicationLibCode/ProjectDataModel/Rim3dView.h @@ -214,6 +214,7 @@ protected: virtual void setDefaultView(); cvf::Mat4d cameraPosition() const; cvf::Vec3d cameraPointOfInterest() const; + bool isCameraOriented( const cvf::Vec3d& viewDirection, const cvf::Vec3d& upDirection ) const; void disableGridBoxField(); void disablePerspectiveProjectionField();