Skip to content

Commit

Permalink
#11693 Store camera position for each associated case
Browse files Browse the repository at this point in the history
A top level view can change the connected grid case. Add option to store the camera position for each grid case. Add option Store View Settings for Case , default off.
  • Loading branch information
magnesj committed Sep 13, 2024
1 parent 281706e commit f4da2d7
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ApplicationLibCode/ProjectDataModel/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimEmCase.h
${CMAKE_CURRENT_LIST_DIR}/RimEclipseViewCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimEclipseCaseEnsemble.h
${CMAKE_CURRENT_LIST_DIR}/RimCameraPosition.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -266,6 +267,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimPolylinePickerInterface.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEclipseViewCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEclipseCaseEnsemble.cpp
${CMAKE_CURRENT_LIST_DIR}/RimCameraPosition.cpp
)

if(RESINSIGHT_USE_QT_CHARTS)
Expand Down
4 changes: 1 addition & 3 deletions ApplicationLibCode/ProjectDataModel/Rim3dView.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class Rim3dView : public RimViewWindow, public RiuViewerToViewInterface, public
QWidget* createViewWidget( QWidget* mainWindowParent ) override;

void setCameraPosition( const cvf::Mat4d& cameraPosition ) override;
void setCameraPointOfInterest( const cvf::Vec3d& cameraPointOfInterest ) override;

protected:
// Timestep Field. Children clamps this differently
Expand Down Expand Up @@ -295,9 +296,6 @@ class Rim3dView : public RimViewWindow, public RiuViewerToViewInterface, public
// Implementation of RimNameConfigHolderInterface
void performAutoNameUpdate() final;

// Implementation of RiuViewerToViewInterface
void setCameraPointOfInterest( const cvf::Vec3d& cameraPointOfInterest ) override;

void endAnimation() override;

caf::PdmObjectHandle* implementingPdmObject() override;
Expand Down
87 changes: 87 additions & 0 deletions ApplicationLibCode/ProjectDataModel/RimCameraPosition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#include "RimCameraPosition.h"

#include "RimEclipseCase.h"

CAF_PDM_SOURCE_INIT( RimCameraPosition, "RimCameraPosition" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCameraPosition::RimCameraPosition()
{
CAF_PDM_InitObject( "Camera Position for Case" );

CAF_PDM_InitFieldNoDefault( &m_eclipseCase, "EclipseCase", "Eclipse Case" );

CAF_PDM_InitField( &m_cameraPosition, "CameraPosition", cvf::Mat4d::IDENTITY, "" );
m_cameraPosition.uiCapability()->setUiHidden( true );

CAF_PDM_InitField( &m_cameraPointOfInterest, "CameraPointOfInterest", cvf::Vec3d::ZERO, "" );
m_cameraPointOfInterest.uiCapability()->setUiHidden( true );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseCase* RimCameraPosition::eclipseCase() const
{
return m_eclipseCase();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCameraPosition::setEclipseCase( RimEclipseCase* eclipseCase )
{
m_eclipseCase = eclipseCase;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Mat4d RimCameraPosition::cameraPosition() const
{
return m_cameraPosition();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCameraPosition::setCameraPosition( const cvf::Mat4d& cameraPosition )
{
m_cameraPosition = cameraPosition;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RimCameraPosition::cameraPointOfInterest() const
{
return m_cameraPointOfInterest();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCameraPosition::setCameraPointOfInterest( const cvf::Vec3d& cameraPointOfInterest )
{
m_cameraPointOfInterest = cameraPointOfInterest;
}
54 changes: 54 additions & 0 deletions ApplicationLibCode/ProjectDataModel/RimCameraPosition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "cafPdmObject.h"

#include "cafPdmField.h"
#include "cafPdmFieldCvfMat4d.h"
#include "cafPdmFieldCvfVec3d.h"
#include "cafPdmPtrField.h"

class RimEclipseCase;

//==================================================================================================
///
///
//==================================================================================================
class RimCameraPosition : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;

public:
RimCameraPosition();

RimEclipseCase* eclipseCase() const;
void setEclipseCase( RimEclipseCase* eclipseCase );

cvf::Mat4d cameraPosition() const;
void setCameraPosition( const cvf::Mat4d& cameraPosition );

cvf::Vec3d cameraPointOfInterest() const;
void setCameraPointOfInterest( const cvf::Vec3d& cameraPointOfInterest );

private:
caf::PdmPtrField<RimEclipseCase*> m_eclipseCase;
caf::PdmField<cvf::Mat4d> m_cameraPosition;
caf::PdmField<cvf::Vec3d> m_cameraPointOfInterest;
};
73 changes: 71 additions & 2 deletions ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "Rim3dOverlayInfoConfig.h"
#include "RimAnnotationCollection.h"
#include "RimAnnotationInViewCollection.h"
#include "RimCameraPosition.h"
#include "RimCellEdgeColors.h"
#include "RimCellFilterCollection.h"
#include "RimEclipseCase.h"
Expand Down Expand Up @@ -147,6 +148,7 @@ RimEclipseView::RimEclipseView()
CAF_PDM_InitFieldNoDefault( &m_customEclipseCase_OBSOLETE, "CustomEclipseCase", "Custom Case" );

CAF_PDM_InitScriptableFieldNoDefault( &m_eclipseCase, "EclipseCase", "Eclipse Case" );
CAF_PDM_InitField( &m_storeViewSettingsPerCase, "StoreViewSettingsPerCase", false, "Store View Settings for Case" );

CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault( &m_cellResult, "GridCellResult", "CellResult", "Cell Result", ":/CellResult.png" );
m_cellResult = new RimEclipseCellColors();
Expand Down Expand Up @@ -218,6 +220,8 @@ RimEclipseView::RimEclipseView()

m_cellResult()->setAdditionalUiTreeObjects( { m_additionalResultsForResultInfo() } );

CAF_PDM_InitFieldNoDefault( &m_cameraPositions, "CameraPositions", "Camera Positions for Cases" );

setDeletable( true );

updateAnimations.connect( this, &RimEclipseView::onAnimationsUpdate );
Expand Down Expand Up @@ -394,6 +398,55 @@ void RimEclipseView::propagateEclipseCaseToChildObjects()
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseView::storeCurrentAndApplyNewCameraPosition( RimEclipseCase* currentCase, RimEclipseCase* newCase )
{
auto settingsForCases = m_cameraPositions.childrenByType();

// Propagate viewer UI settings to RimEclipseView before accessing camera positions
setupBeforeSave();

auto findSettingsForCase = [&]( RimEclipseCase* eclipseCase ) -> RimCameraPosition*
{
for ( auto settingsForCase : settingsForCases )
{
if ( settingsForCase->eclipseCase() == eclipseCase )
{
return settingsForCase;
}
}
return nullptr;
};

if ( currentCase )
{
RimCameraPosition* settingsForCurrentCase = findSettingsForCase( currentCase );
if ( !settingsForCurrentCase )
{
settingsForCurrentCase = new RimCameraPosition;
settingsForCurrentCase->setEclipseCase( currentCase );
m_cameraPositions.push_back( settingsForCurrentCase );
}

settingsForCurrentCase->setCameraPosition( cameraPosition() );
settingsForCurrentCase->setCameraPointOfInterest( cameraPointOfInterest() );
}

if ( newCase )
{
if ( RimCameraPosition* settingsForNewCase = findSettingsForCase( newCase ) )
{
viewer()->mainCamera()->setViewMatrix( settingsForNewCase->cameraPosition() );
viewer()->setPointOfInterest( settingsForNewCase->cameraPointOfInterest() );
return;
}
}

zoomAll();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -410,7 +463,15 @@ void RimEclipseView::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
updateGridBoxData();
updateAnnotationItems();

zoomAll();
if ( m_storeViewSettingsPerCase() )
{
auto currentEclipseCase = dynamic_cast<RimEclipseCase*>( oldValue.value<caf::PdmPointer<PdmObjectHandle>>().rawPtr() );
storeCurrentAndApplyNewCameraPosition( currentEclipseCase, m_eclipseCase );
}
else
{
zoomAll();
}

return;
}
Expand Down Expand Up @@ -1564,6 +1625,8 @@ void RimEclipseView::updateLegendRangesTextAndVisibility( RimRegularLegendConfig
//--------------------------------------------------------------------------------------------------
void RimEclipseView::setEclipseCase( RimEclipseCase* reservoir )
{
// TODO: How should we manage the view settings? See storeCurrentAndApplyNewCameraPosition()

m_eclipseCase = reservoir;

propagateEclipseCaseToChildObjects();
Expand Down Expand Up @@ -1900,7 +1963,13 @@ const std::vector<RivCellSetEnum>& RimEclipseView::visibleGridParts() const
void RimEclipseView::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
// Only show case option when not under a case in the project tree.
if ( !firstAncestorOrThisOfType<RimEclipseCase>() ) uiOrdering.add( &m_eclipseCase );
if ( !firstAncestorOrThisOfType<RimEclipseCase>() )
{
caf::PdmUiGroup* dataSourceGroup = uiOrdering.addNewGroup( "Data Source" );

dataSourceGroup->add( &m_eclipseCase );
dataSourceGroup->add( &m_storeViewSettingsPerCase );
}

Rim3dView::defineUiOrdering( uiConfigName, uiOrdering );

Expand Down
7 changes: 6 additions & 1 deletion ApplicationLibCode/ProjectDataModel/RimEclipseView.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class RimStreamlineInViewCollection;
class RimMultipleEclipseResults;
class RigEclipseResultAddress;
class RimFaultReactivationModelCollection;
class RimCameraPosition;

namespace cvf
{
Expand Down Expand Up @@ -220,10 +221,13 @@ class RimEclipseView : public RimGridView
void setVisibleGridPartsWatertight();

void propagateEclipseCaseToChildObjects();
void storeCurrentAndApplyNewCameraPosition( RimEclipseCase* previousCase, RimEclipseCase* newCase );

protected:
cvf::ref<cvf::ModelBasicList> m_faultReactVizModel;
cvf::ref<cvf::ModelBasicList> m_faultReactVizModel;

caf::PdmPtrField<RimEclipseCase*> m_eclipseCase;
caf::PdmField<bool> m_storeViewSettingsPerCase;

private:
caf::PdmField<bool> m_showInvalidCells;
Expand Down Expand Up @@ -255,4 +259,5 @@ class RimEclipseView : public RimGridView
std::vector<RivCellSetEnum> m_visibleGridParts;

caf::PdmChildField<RimMultipleEclipseResults*> m_additionalResultsForResultInfo;
caf::PdmChildArrayField<RimCameraPosition*> m_cameraPositions;
};

0 comments on commit f4da2d7

Please sign in to comment.