mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Python: Add support for manipulation of camera position
* Remove debug output in the views function * Add scripting support for Mat4d * Add scripting support to camera * Separate updates for background color and font size
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
#include "cafFrameAnimationControl.h"
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
#include "cafPdmFieldScriptingCapabilityCvfColor3.h"
|
||||
#include "cafPdmFieldScriptingCapabilityCvfVec3d.h"
|
||||
#include "cafPdmUiComboBoxEditor.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
@@ -112,6 +113,17 @@ Rim3dView::Rim3dView()
|
||||
CAF_PDM_InitField( &m_cameraPointOfInterest, "CameraPointOfInterest", cvf::Vec3d::ZERO, "" );
|
||||
m_cameraPointOfInterest.uiCapability()->setUiHidden( true );
|
||||
|
||||
CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault( &m_cameraPositionProxy, "CameraPositionProxy", "CameraMatrix", "Camera Matrix" );
|
||||
m_cameraPositionProxy.registerGetMethod( this, &Rim3dView::cameraPosition );
|
||||
m_cameraPositionProxy.registerSetMethod( this, &Rim3dView::setCameraPosition );
|
||||
|
||||
CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault( &m_cameraPointOfInterestProxy,
|
||||
"CameraPointOfInterestProxy",
|
||||
"CameraPointOfInterest",
|
||||
"Camera Point of Interest" );
|
||||
m_cameraPointOfInterestProxy.registerGetMethod( this, &Rim3dView::cameraPointOfInterest );
|
||||
m_cameraPointOfInterestProxy.registerSetMethod( this, &Rim3dView::setCameraPointOfInterest );
|
||||
|
||||
CAF_PDM_InitScriptableField( &isPerspectiveView, "PerspectiveProjection", true, "Perspective Projection" );
|
||||
|
||||
double defaultScaleFactor = preferences->defaultScaleFactorZ();
|
||||
@@ -829,6 +841,8 @@ void Rim3dView::setupBeforeSave()
|
||||
{
|
||||
if ( m_viewer )
|
||||
{
|
||||
// The update of these fields is also done in cameraPosition() and cameraPointOfInterest(). When the
|
||||
// project is saved to file, these functions are not used, so we need to update the fields here.
|
||||
m_cameraPosition = m_viewer->mainCamera()->viewMatrix();
|
||||
m_cameraPointOfInterest = m_viewer->pointOfInterest();
|
||||
}
|
||||
@@ -993,17 +1007,22 @@ void Rim3dView::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const
|
||||
m_viewer->update();
|
||||
}
|
||||
}
|
||||
else if ( changedField == &m_backgroundColor || changedField == &m_fontSize )
|
||||
else if ( changedField == &m_backgroundColor )
|
||||
{
|
||||
if ( changedField == &m_fontSize )
|
||||
if ( viewer() != nullptr )
|
||||
{
|
||||
auto fontHolderChildren = descendantsOfType<caf::FontHolderInterface>();
|
||||
for ( auto fontHolder : fontHolderChildren )
|
||||
{
|
||||
fontHolder->updateFonts();
|
||||
}
|
||||
viewer()->mainCamera()->viewport()->setClearColor( cvf::Color4f( backgroundColor() ) );
|
||||
}
|
||||
this->applyBackgroundColorAndFontChanges();
|
||||
this->scheduleCreateDisplayModelAndRedraw();
|
||||
}
|
||||
else if ( changedField == &m_fontSize )
|
||||
{
|
||||
auto fontHolderChildren = descendantsOfType<caf::FontHolderInterface>();
|
||||
for ( auto fontHolder : fontHolderChildren )
|
||||
{
|
||||
fontHolder->updateFonts();
|
||||
}
|
||||
this->applyFontChanges();
|
||||
this->updateConnectedEditors();
|
||||
}
|
||||
else if ( changedField == &maximumFrameRate )
|
||||
@@ -1035,6 +1054,13 @@ void Rim3dView::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const
|
||||
m_viewer->update();
|
||||
}
|
||||
}
|
||||
else if ( changedField == &m_cameraPositionProxy || changedField == &m_cameraPointOfInterestProxy )
|
||||
{
|
||||
if ( m_viewer )
|
||||
{
|
||||
m_viewer->repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1342,11 +1368,10 @@ void Rim3dView::setShowGridBox( bool showGridBox )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Rim3dView::applyBackgroundColorAndFontChanges()
|
||||
void Rim3dView::applyFontChanges()
|
||||
{
|
||||
if ( viewer() != nullptr )
|
||||
{
|
||||
viewer()->mainCamera()->viewport()->setClearColor( cvf::Color4f( backgroundColor() ) );
|
||||
viewer()->updateFonts( fontSize() );
|
||||
}
|
||||
updateGridBoxData();
|
||||
@@ -1370,7 +1395,7 @@ int Rim3dView::fontSize() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Rim3dView::updateFonts()
|
||||
{
|
||||
applyBackgroundColorAndFontChanges();
|
||||
applyFontChanges();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1510,6 +1535,11 @@ QList<caf::PdmOptionItemInfo> Rim3dView::calculateValueOptions( const caf::PdmFi
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Mat4d Rim3dView::cameraPosition() const
|
||||
{
|
||||
if ( m_viewer && m_viewer->mainCamera() )
|
||||
{
|
||||
m_cameraPosition = m_viewer->mainCamera()->viewMatrix();
|
||||
}
|
||||
|
||||
return m_cameraPosition();
|
||||
}
|
||||
|
||||
@@ -1518,6 +1548,11 @@ cvf::Mat4d Rim3dView::cameraPosition() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec3d Rim3dView::cameraPointOfInterest() const
|
||||
{
|
||||
if ( m_viewer )
|
||||
{
|
||||
m_cameraPointOfInterest = m_viewer->pointOfInterest();
|
||||
}
|
||||
|
||||
return m_cameraPointOfInterest();
|
||||
}
|
||||
|
||||
@@ -1545,6 +1580,10 @@ QWidget* Rim3dView::viewWidget()
|
||||
void Rim3dView::setCameraPosition( const cvf::Mat4d& cameraPosition )
|
||||
{
|
||||
m_cameraPosition = cameraPosition;
|
||||
if ( m_viewer && m_viewer->mainCamera() )
|
||||
{
|
||||
m_viewer->mainCamera()->setViewMatrix( m_cameraPosition );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1553,6 +1592,10 @@ void Rim3dView::setCameraPosition( const cvf::Mat4d& cameraPosition )
|
||||
void Rim3dView::setCameraPointOfInterest( const cvf::Vec3d& cameraPointOfInterest )
|
||||
{
|
||||
m_cameraPointOfInterest = cameraPointOfInterest;
|
||||
if ( m_viewer )
|
||||
{
|
||||
m_viewer->setPointOfInterest( m_cameraPointOfInterest );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -133,10 +133,10 @@ public:
|
||||
|
||||
void setBackgroundColor( const cvf::Color3f& newBackgroundColor );
|
||||
cvf::Color3f backgroundColor() const override; // Implementation of RiuViewerToViewInterface
|
||||
void applyBackgroundColorAndFontChanges();
|
||||
|
||||
int fontSize() const override;
|
||||
void updateFonts() override;
|
||||
void applyFontChanges();
|
||||
|
||||
void disableLighting( bool disable );
|
||||
bool isLightingDisabled() const;
|
||||
@@ -281,7 +281,6 @@ protected:
|
||||
cvf::ref<cvf::ModelBasicList> m_screenSpaceModel;
|
||||
|
||||
caf::PdmField<double> m_scaleZ;
|
||||
caf::PdmField<double> m_customScaleZ;
|
||||
|
||||
caf::PdmChildField<RimAnnotationInViewCollection*> m_annotationCollection;
|
||||
|
||||
@@ -329,13 +328,19 @@ private:
|
||||
caf::PdmField<int> m_id;
|
||||
caf::PdmChildField<RimViewNameConfig*> m_nameConfig;
|
||||
caf::PdmField<bool> m_disableLighting;
|
||||
caf::PdmField<cvf::Mat4d> m_cameraPosition;
|
||||
caf::PdmField<cvf::Vec3d> m_cameraPointOfInterest;
|
||||
caf::PdmField<cvf::Color3f> m_backgroundColor;
|
||||
caf::PdmField<bool> m_showGridBox;
|
||||
caf::PdmField<bool> m_showZScaleLabel;
|
||||
caf::PdmPtrField<Rim3dView*> m_comparisonView;
|
||||
|
||||
// Camera position and point of interest. The member variables are mutable to allow for setting them from const methods.
|
||||
// The camera position and point of interest can change rapidly as the user interacts with the 3D view. Only update the Pdm field values
|
||||
// when the application requests the camera position or point of interest.
|
||||
mutable caf::PdmField<cvf::Mat4d> m_cameraPosition;
|
||||
mutable caf::PdmField<cvf::Vec3d> m_cameraPointOfInterest;
|
||||
caf::PdmProxyValueField<cvf::Vec3d> m_cameraPointOfInterestProxy;
|
||||
caf::PdmProxyValueField<cvf::Mat4d> m_cameraPositionProxy;
|
||||
|
||||
caf::PdmField<bool> m_useCustomAnnotationStrategy;
|
||||
caf::PdmField<caf::AppEnum<RivAnnotationTools::LabelPositionStrategy>> m_annotationStrategy;
|
||||
caf::PdmField<int> m_annotationCountHint;
|
||||
|
||||
Reference in New Issue
Block a user