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 );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user