2015-04-29 10:50:25 +02:00
# include "RimView.h"
2015-04-29 22:19:49 +02:00
# include "RiaApplication.h"
# include "RiaPreferences.h"
2015-08-25 12:40:55 +02:00
2015-09-03 13:06:00 +02:00
# include "RigCaseData.h"
2015-04-29 22:19:49 +02:00
# include "Rim3dOverlayInfoConfig.h"
2015-08-27 13:44:27 +02:00
# include "RimCellRangeFilterCollection.h"
2015-09-03 13:06:00 +02:00
# include "RimEclipseCase.h"
# include "RimEclipseView.h"
2015-09-11 13:46:37 +02:00
# include "RimViewLink.h"
2015-08-25 12:40:55 +02:00
# include "RimOilField.h"
# include "RimProject.h"
2015-09-07 14:29:46 +02:00
# include "RimViewLinker.h"
2015-08-25 12:40:55 +02:00
# include "RimWellPathCollection.h"
2015-04-30 10:34:15 +02:00
# include "RiuMainWindow.h"
2015-08-25 12:40:55 +02:00
# include "RiuViewer.h"
# include "RivWellPathCollectionPartMgr.h"
# include "cafFrameAnimationControl.h"
# include "cafPdmObjectFactory.h"
2015-04-30 10:34:15 +02:00
# include "cvfCamera.h"
2015-06-11 13:44:21 +02:00
# include "cvfModel.h"
# include "cvfModelBasicList.h"
# include "cvfPart.h"
# include "cvfScene.h"
2015-04-30 10:34:15 +02:00
# include "cvfViewport.h"
2015-04-29 22:19:49 +02:00
2015-05-11 09:48:55 +02:00
# include <limits.h>
2015-05-08 14:13:26 +02:00
namespace caf {
template < >
void caf : : AppEnum < RimView : : MeshModeType > : : setUp ( )
{
addItem ( RimView : : FULL_MESH , " FULL_MESH " , " All " ) ;
addItem ( RimView : : FAULTS_MESH , " FAULTS_MESH " , " Faults only " ) ;
addItem ( RimView : : NO_MESH , " NO_MESH " , " None " ) ;
setDefault ( RimView : : FULL_MESH ) ;
}
template < >
void caf : : AppEnum < RimView : : SurfaceModeType > : : setUp ( )
{
addItem ( RimView : : SURFACE , " SURFACE " , " All " ) ;
addItem ( RimView : : FAULTS , " FAULTS " , " Faults only " ) ;
addItem ( RimView : : NO_SURFACE , " NO_SURFACE " , " None " ) ;
setDefault ( RimView : : SURFACE ) ;
}
} // End namespace caf
2015-05-15 18:51:49 +02:00
# include "cafPdmAbstractClassSourceInit.h"
2015-05-08 14:13:26 +02:00
2015-04-29 22:19:49 +02:00
CAF_PDM_ABSTRACT_SOURCE_INIT ( RimView , " GenericView " ) ; // Do not use. Abstract class
2015-04-29 10:50:25 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimView : : RimView ( void )
{
2015-04-29 22:19:49 +02:00
RiaApplication * app = RiaApplication : : instance ( ) ;
RiaPreferences * preferences = app - > preferences ( ) ;
CVF_ASSERT ( preferences ) ;
CAF_PDM_InitField ( & name , " UserDescription " , QString ( " " ) , " Name " , " " , " " , " " ) ;
CAF_PDM_InitField ( & showWindow , " ShowWindow " , true , " Show 3D viewer " , " " , " " , " " ) ;
2015-08-05 13:27:36 +02:00
showWindow . uiCapability ( ) - > setUiHidden ( true ) ;
2015-04-29 22:19:49 +02:00
CAF_PDM_InitField ( & cameraPosition , " CameraPosition " , cvf : : Mat4d : : IDENTITY , " " , " " , " " , " " ) ;
2015-08-12 21:51:02 +02:00
cameraPosition . uiCapability ( ) - > setUiHidden ( true ) ;
2015-04-29 22:19:49 +02:00
double defaultScaleFactor = 1.0 ;
if ( preferences ) defaultScaleFactor = preferences - > defaultScaleFactorZ ;
CAF_PDM_InitField ( & scaleZ , " GridZScale " , defaultScaleFactor , " Z Scale " , " " , " Scales the scene in the Z direction " , " " ) ;
cvf : : Color3f defBackgColor = preferences - > defaultViewerBackgroundColor ( ) ;
CAF_PDM_InitField ( & backgroundColor , " ViewBackgroundColor " , defBackgColor , " Background " , " " , " " , " " ) ;
CAF_PDM_InitField ( & maximumFrameRate , " MaximumFrameRate " , 10 , " Maximum frame rate " , " " , " " , " " ) ;
2015-08-05 13:27:36 +02:00
maximumFrameRate . uiCapability ( ) - > setUiHidden ( true ) ;
2015-06-09 16:18:11 +02:00
CAF_PDM_InitField ( & hasUserRequestedAnimation , " AnimationMode " , false , " Animation Mode " , " " , " " , " " ) ;
2015-08-05 13:27:36 +02:00
hasUserRequestedAnimation . uiCapability ( ) - > setUiHidden ( true ) ;
2015-04-29 22:19:49 +02:00
CAF_PDM_InitField ( & m_currentTimeStep , " CurrentTimeStep " , 0 , " Current Time Step " , " " , " " , " " ) ;
2015-08-05 13:27:36 +02:00
m_currentTimeStep . uiCapability ( ) - > setUiHidden ( true ) ;
2015-04-29 22:19:49 +02:00
2015-08-27 13:44:27 +02:00
CAF_PDM_InitFieldNoDefault ( & m_overlayInfoConfig , " OverlayInfoConfig " , " Info Box " , " " , " " , " " ) ;
m_overlayInfoConfig = new Rim3dOverlayInfoConfig ( ) ;
m_overlayInfoConfig - > setReservoirView ( this ) ;
m_overlayInfoConfig . uiCapability ( ) - > setUiHidden ( true ) ;
2015-04-29 22:19:49 +02:00
2015-05-08 14:13:26 +02:00
caf : : AppEnum < RimView : : MeshModeType > defaultMeshType = NO_MESH ;
if ( preferences - > defaultGridLines ) defaultMeshType = FULL_MESH ;
CAF_PDM_InitField ( & meshMode , " MeshMode " , defaultMeshType , " Grid lines " , " " , " " , " " ) ;
CAF_PDM_InitFieldNoDefault ( & surfaceMode , " SurfaceMode " , " Grid surface " , " " , " " , " " ) ;
2015-04-29 10:50:25 +02:00
2015-06-18 13:20:54 +02:00
CAF_PDM_InitField ( & m_disableLighting , " DisableLighting " , false , " Disable Results Lighting " , " " , " Disable light model for scalar result colors " , " " ) ;
2015-06-17 15:04:55 +02:00
2015-09-01 22:11:39 +02:00
CAF_PDM_InitFieldNoDefault ( & windowGeometry , " WindowGeometry " , " " , " " , " " , " " ) ;
windowGeometry . uiCapability ( ) - > setUiHidden ( true ) ;
2015-05-08 14:13:26 +02:00
m_previousGridModeMeshLinesWasFaults = false ;
2015-04-29 10:50:25 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimView : : ~ RimView ( void )
{
2015-08-27 13:44:27 +02:00
delete this - > m_overlayInfoConfig ( ) ;
2015-04-30 10:34:15 +02:00
if ( m_viewer )
{
2015-09-02 15:53:49 +02:00
RiuMainWindow : : instance ( ) - > removeViewer ( m_viewer - > layoutWidget ( ) ) ;
2015-04-30 10:34:15 +02:00
}
delete m_viewer ;
2015-04-29 10:50:25 +02:00
}
2015-04-29 22:19:49 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuViewer * RimView : : viewer ( )
{
return m_viewer ;
}
2015-04-30 10:34:15 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : updateViewerWidget ( )
{
if ( showWindow ( ) )
{
bool isViewerCreated = false ;
if ( ! m_viewer )
{
QGLFormat glFormat ;
glFormat . setDirectRendering ( RiaApplication : : instance ( ) - > useShaders ( ) ) ;
m_viewer = new RiuViewer ( glFormat , NULL ) ;
m_viewer - > setOwnerReservoirView ( this ) ;
2015-09-02 15:53:49 +02:00
RiuMainWindow : : instance ( ) - > addViewer ( m_viewer - > layoutWidget ( ) , windowGeometry ( ) ) ;
2015-04-30 10:34:15 +02:00
m_viewer - > setMinNearPlaneDistance ( 10 ) ;
this - > resetLegendsInViewer ( ) ;
2015-07-02 12:44:57 +02:00
m_viewer - > updateNavigationPolicy ( ) ;
2015-04-30 10:34:15 +02:00
m_viewer - > enablePerfInfoHud ( RiaApplication : : instance ( ) - > showPerformanceInfo ( ) ) ;
isViewerCreated = true ;
}
2015-09-02 15:53:49 +02:00
RiuMainWindow : : instance ( ) - > setActiveViewer ( m_viewer - > layoutWidget ( ) ) ;
2015-04-30 10:34:15 +02:00
if ( isViewerCreated ) m_viewer - > mainCamera ( ) - > setViewMatrix ( cameraPosition ) ;
m_viewer - > mainCamera ( ) - > viewport ( ) - > setClearColor ( cvf : : Color4f ( backgroundColor ( ) ) ) ;
2015-09-01 18:04:35 +02:00
m_viewer - > update ( ) ;
2015-04-30 10:34:15 +02:00
}
else
{
if ( m_viewer )
{
if ( m_viewer - > layoutWidget ( ) - > parentWidget ( ) )
{
m_viewer - > layoutWidget ( ) - > parentWidget ( ) - > hide ( ) ;
}
else
{
m_viewer - > layoutWidget ( ) - > hide ( ) ;
}
}
}
updateViewerWidgetWindowTitle ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : scheduleCreateDisplayModelAndRedraw ( )
{
RiaApplication : : instance ( ) - > scheduleDisplayModelUpdateAndRedraw ( this ) ;
2015-09-13 08:54:32 +02:00
RimViewLinker * viewLinker = viewLinkerWithDepViews ( ) ;
if ( viewLinker )
{
viewLinker - > scheduleCreateDisplayModelAndRedrawForDependentViews ( ) ;
}
2015-04-30 10:34:15 +02:00
}
2015-05-08 10:38:10 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setCurrentTimeStep ( int frameIndex )
{
m_currentTimeStep = frameIndex ;
2015-08-31 12:31:38 +02:00
clampCurrentTimestep ( ) ;
2015-06-09 16:18:11 +02:00
this - > hasUserRequestedAnimation = true ;
2015-05-08 10:38:10 +02:00
this - > updateCurrentTimeStep ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : updateCurrentTimeStepAndRedraw ( )
{
this - > updateCurrentTimeStep ( ) ;
2015-09-01 18:04:35 +02:00
if ( m_viewer ) m_viewer - > update ( ) ;
2015-05-08 10:38:10 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : createDisplayModelAndRedraw ( )
{
if ( m_viewer )
{
this - > clampCurrentTimestep ( ) ;
createDisplayModel ( ) ;
updateDisplayModelVisibility ( ) ;
}
2015-06-17 15:04:55 +02:00
RiuMainWindow : : instance ( ) - > refreshAnimationActions ( ) ;
2015-05-08 10:38:10 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setDefaultView ( )
{
if ( m_viewer )
{
m_viewer - > setDefaultView ( ) ;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : endAnimation ( )
{
2015-06-09 16:18:11 +02:00
this - > hasUserRequestedAnimation = false ;
2015-05-08 10:38:10 +02:00
this - > updateStaticCellColors ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setupBeforeSave ( )
{
if ( m_viewer )
{
2015-06-09 16:18:11 +02:00
hasUserRequestedAnimation = m_viewer - > isAnimationActive ( ) ; // JJS: This is not conceptually correct. The variable is updated as we go, and store the user intentions. But I guess that in practice...
2015-05-08 10:38:10 +02:00
cameraPosition = m_viewer - > mainCamera ( ) - > viewMatrix ( ) ;
2015-09-01 22:11:39 +02:00
2015-09-02 15:53:49 +02:00
windowGeometry = RiuMainWindow : : instance ( ) - > windowGeometryForViewer ( m_viewer - > layoutWidget ( ) ) ;
2015-09-01 22:11:39 +02:00
}
2015-05-08 10:38:10 +02:00
}
2015-04-30 10:34:15 +02:00
2015-05-08 14:13:26 +02:00
//--------------------------------------------------------------------------------------------------
///
// Surf: No Fault Surf
// Mesh -------------
// No F F G
// Fault F F G
// Mesh G G G
//
//--------------------------------------------------------------------------------------------------
bool RimView : : isGridVisualizationMode ( ) const
{
return ( this - > surfaceMode ( ) = = SURFACE
| | this - > meshMode ( ) = = FULL_MESH ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setMeshOnlyDrawstyle ( )
{
if ( isGridVisualizationMode ( ) )
{
2015-08-05 12:34:07 +02:00
meshMode . uiCapability ( ) - > setValueFromUi ( FULL_MESH ) ;
2015-05-08 14:13:26 +02:00
}
else
{
2015-08-05 12:34:07 +02:00
meshMode . uiCapability ( ) - > setValueFromUi ( FAULTS_MESH ) ;
2015-05-08 14:13:26 +02:00
}
2015-08-05 12:34:07 +02:00
surfaceMode . uiCapability ( ) - > setValueFromUi ( NO_SURFACE ) ;
2015-05-08 14:13:26 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setMeshSurfDrawstyle ( )
{
if ( isGridVisualizationMode ( ) )
{
2015-08-05 12:34:07 +02:00
surfaceMode . uiCapability ( ) - > setValueFromUi ( SURFACE ) ;
meshMode . uiCapability ( ) - > setValueFromUi ( FULL_MESH ) ;
2015-05-08 14:13:26 +02:00
}
else
{
2015-08-05 12:34:07 +02:00
surfaceMode . uiCapability ( ) - > setValueFromUi ( FAULTS ) ;
meshMode . uiCapability ( ) - > setValueFromUi ( FAULTS_MESH ) ;
2015-05-08 14:13:26 +02:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setFaultMeshSurfDrawstyle ( )
{
// Surf: No Fault Surf
// Mesh -------------
// No FF FF SF
// Fault FF FF SF
// Mesh SF SF SF
if ( this - > isGridVisualizationMode ( ) )
{
2015-08-05 12:34:07 +02:00
surfaceMode . uiCapability ( ) - > setValueFromUi ( SURFACE ) ;
2015-05-08 14:13:26 +02:00
}
else
{
2015-08-05 12:34:07 +02:00
surfaceMode . uiCapability ( ) - > setValueFromUi ( FAULTS ) ;
2015-05-08 14:13:26 +02:00
}
2015-08-05 12:34:07 +02:00
meshMode . uiCapability ( ) - > setValueFromUi ( FAULTS_MESH ) ;
2015-05-08 14:13:26 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setSurfOnlyDrawstyle ( )
{
if ( isGridVisualizationMode ( ) )
{
2015-08-05 12:34:07 +02:00
surfaceMode . uiCapability ( ) - > setValueFromUi ( SURFACE ) ;
2015-05-08 14:13:26 +02:00
}
else
{
2015-08-05 12:34:07 +02:00
surfaceMode . uiCapability ( ) - > setValueFromUi ( FAULTS ) ;
2015-05-08 14:13:26 +02:00
}
2015-07-31 18:58:23 +02:00
2015-08-05 12:34:07 +02:00
meshMode . uiCapability ( ) - > setValueFromUi ( NO_MESH ) ;
2015-05-08 14:13:26 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setShowFaultsOnly ( bool showFaults )
{
if ( showFaults )
{
m_previousGridModeMeshLinesWasFaults = meshMode ( ) = = FAULTS_MESH ;
2015-08-05 12:34:07 +02:00
if ( surfaceMode ( ) ! = NO_SURFACE ) surfaceMode . uiCapability ( ) - > setValueFromUi ( FAULTS ) ;
if ( meshMode ( ) ! = NO_MESH ) meshMode . uiCapability ( ) - > setValueFromUi ( FAULTS_MESH ) ;
2015-05-08 14:13:26 +02:00
}
else
{
2015-08-05 12:34:07 +02:00
if ( surfaceMode ( ) ! = NO_SURFACE ) surfaceMode . uiCapability ( ) - > setValueFromUi ( SURFACE ) ;
if ( meshMode ( ) ! = NO_MESH ) meshMode . uiCapability ( ) - > setValueFromUi ( m_previousGridModeMeshLinesWasFaults ? FAULTS_MESH : FULL_MESH ) ;
2015-05-08 14:13:26 +02:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setSurfaceDrawstyle ( )
{
2015-08-05 12:34:07 +02:00
if ( surfaceMode ( ) ! = NO_SURFACE ) surfaceMode . uiCapability ( ) - > setValueFromUi ( SURFACE ) ;
2015-05-08 14:13:26 +02:00
}
2015-06-17 15:04:55 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : disableLighting ( bool disable )
{
m_disableLighting = disable ;
updateCurrentTimeStepAndRedraw ( ) ;
updateConnectedEditors ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimView : : isLightingDisabled ( ) const
{
return m_disableLighting ( ) ;
}
2015-05-08 14:13:26 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : fieldChangedByUi ( const caf : : PdmFieldHandle * changedField , const QVariant & oldValue , const QVariant & newValue )
{
if ( changedField = = & meshMode )
{
createDisplayModel ( ) ;
updateDisplayModelVisibility ( ) ;
RiuMainWindow : : instance ( ) - > refreshDrawStyleActions ( ) ;
}
2015-05-13 22:42:11 +02:00
else if ( changedField = = & scaleZ )
{
if ( scaleZ < 1 ) scaleZ = 1 ;
// Regenerate well paths
RimOilField * oilFields = RiaApplication : : instance ( ) - > project ( ) ? RiaApplication : : instance ( ) - > project ( ) - > activeOilField ( ) : NULL ;
RimWellPathCollection * wellPathCollection = ( oilFields ) ? oilFields - > wellPathCollection ( ) : NULL ;
if ( wellPathCollection ) wellPathCollection - > wellPathCollectionPartMgr ( ) - > scheduleGeometryRegen ( ) ;
if ( m_viewer )
{
cvf : : Vec3d poi = m_viewer - > pointOfInterest ( ) ;
cvf : : Vec3d eye , dir , up ;
eye = m_viewer - > mainCamera ( ) - > position ( ) ;
dir = m_viewer - > mainCamera ( ) - > direction ( ) ;
up = m_viewer - > mainCamera ( ) - > up ( ) ;
eye [ 2 ] = poi [ 2 ] * scaleZ ( ) / this - > scaleTransform ( ) - > worldTransform ( ) ( 2 , 2 ) + ( eye [ 2 ] - poi [ 2 ] ) ;
poi [ 2 ] = poi [ 2 ] * scaleZ ( ) / this - > scaleTransform ( ) - > worldTransform ( ) ( 2 , 2 ) ;
m_viewer - > mainCamera ( ) - > setFromLookAt ( eye , eye + dir , up ) ;
m_viewer - > setPointOfInterest ( poi ) ;
updateScaleTransform ( ) ;
createDisplayModelAndRedraw ( ) ;
2015-09-03 13:06:00 +02:00
RimProject * proj = NULL ;
this - > firstAnchestorOrThisOfType ( proj ) ;
2015-09-07 14:29:46 +02:00
RimViewLinker * viewLinker = proj - > findViewLinkerFromView ( this ) ;
if ( viewLinker )
2015-09-03 13:06:00 +02:00
{
2015-09-15 10:45:39 +02:00
RimViewLink * viewLink = viewLinker - > viewLinkFromView ( this ) ;
if ( this = = viewLinker - > mainView ( ) | | ( viewLink & & viewLink - > isActive ( ) & & viewLink - > syncCamera ( ) ) )
2015-09-03 13:06:00 +02:00
{
2015-09-07 14:29:46 +02:00
viewLinker - > updateScaleZ ( this , scaleZ ) ;
2015-09-03 13:06:00 +02:00
}
}
m_viewer - > navigationPolicyUpdate ( ) ;
2015-05-13 22:42:11 +02:00
}
RiuMainWindow : : instance ( ) - > updateScaleValue ( ) ;
}
2015-05-08 14:13:26 +02:00
else if ( changedField = = & surfaceMode )
{
createDisplayModel ( ) ;
updateDisplayModelVisibility ( ) ;
RiuMainWindow : : instance ( ) - > refreshDrawStyleActions ( ) ;
}
2015-06-17 15:04:55 +02:00
else if ( changedField = = & m_disableLighting )
{
createDisplayModel ( ) ;
RiuMainWindow : : instance ( ) - > refreshDrawStyleActions ( ) ;
}
2015-05-08 14:13:26 +02:00
else if ( changedField = = & name )
{
updateViewerWidgetWindowTitle ( ) ;
}
else if ( changedField = = & m_currentTimeStep )
{
if ( m_viewer )
{
2015-09-01 18:04:35 +02:00
m_viewer - > update ( ) ;
2015-08-25 12:40:55 +02:00
2015-09-01 17:14:22 +02:00
RimProject * proj = NULL ;
this - > firstAnchestorOrThisOfType ( proj ) ;
2015-09-07 14:29:46 +02:00
RimViewLinker * viewLinker = proj - > findViewLinkerFromView ( this ) ;
if ( viewLinker )
2015-09-01 17:14:22 +02:00
{
2015-09-15 10:45:39 +02:00
RimViewLink * viewLink = viewLinker - > viewLinkFromView ( this ) ;
if ( this = = viewLinker - > mainView ( ) | | ( viewLink & & viewLink - > isActive ( ) & & viewLink - > syncTimeStep ( ) ) )
{
viewLinker - > updateTimeStep ( this , m_currentTimeStep ) ;
}
2015-09-01 17:14:22 +02:00
}
2015-05-08 14:13:26 +02:00
}
}
else if ( changedField = = & backgroundColor )
{
if ( viewer ( ) ! = NULL )
{
updateViewerWidget ( ) ;
}
}
else if ( changedField = = & maximumFrameRate )
{
// !! Use cvf::UNDEFINED_INT or something if we end up with frame rate 0?
// !! Should be able to specify legal range for number properties
if ( m_viewer )
{
m_viewer - > animationControl ( ) - > setTimeout ( maximumFrameRate ! = 0 ? 1000 / maximumFrameRate : INT_MAX ) ;
}
}
}
2015-06-11 13:44:21 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-06-22 09:09:33 +02:00
void RimView : : addWellPathsToModel ( cvf : : ModelBasicList * wellPathModelBasicList ,
const cvf : : Vec3d & displayModelOffset ,
double characteristicCellSize ,
const cvf : : BoundingBox & wellPathClipBoundingBox ,
2015-06-12 09:25:09 +02:00
cvf : : Transform * scaleTransform )
2015-06-11 13:44:21 +02:00
{
RimOilField * oilFields = RiaApplication : : instance ( ) - > project ( ) ? RiaApplication : : instance ( ) - > project ( ) - > activeOilField ( ) : NULL ;
RimWellPathCollection * wellPathCollection = oilFields ? oilFields - > wellPathCollection ( ) : NULL ;
RivWellPathCollectionPartMgr * wellPathCollectionPartMgr = wellPathCollection ? wellPathCollection - > wellPathCollectionPartMgr ( ) : NULL ;
if ( wellPathCollectionPartMgr )
{
2015-06-22 09:09:33 +02:00
wellPathCollectionPartMgr - > appendStaticGeometryPartsToModel ( wellPathModelBasicList ,
displayModelOffset ,
scaleTransform ,
characteristicCellSize ,
wellPathClipBoundingBox ) ;
2015-06-11 13:44:21 +02:00
}
wellPathModelBasicList - > updateBoundingBoxesRecursive ( ) ;
}
2015-08-27 13:44:27 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCellRangeFilterCollection * RimView : : rangeFilterCollection ( )
{
if ( m_overrideRangeFilterCollection )
{
return m_overrideRangeFilterCollection ;
}
else
{
return m_rangeFilterCollection ;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RimCellRangeFilterCollection * RimView : : rangeFilterCollection ( ) const
{
if ( m_overrideRangeFilterCollection )
{
return m_overrideRangeFilterCollection ;
}
else
{
return m_rangeFilterCollection ;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setOverrideRangeFilterCollection ( RimCellRangeFilterCollection * rfc )
{
m_overrideRangeFilterCollection = rfc ;
2015-09-13 08:54:32 +02:00
this - > scheduleGeometryRegen ( RANGE_FILTERED ) ;
this - > scheduleGeometryRegen ( RANGE_FILTERED_INACTIVE ) ;
this - > scheduleCreateDisplayModelAndRedraw ( ) ;
2015-08-27 13:44:27 +02:00
}
2015-09-01 18:21:20 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : notifyCameraHasChanged ( )
{
2015-09-07 13:33:27 +02:00
if ( ! this - > viewer ( ) ) return ;
2015-09-01 18:21:20 +02:00
std : : vector < RimView * > viewsToUpdate ;
viewsToUpdate . push_back ( this ) ;
RimProject * proj = NULL ;
this - > firstAnchestorOrThisOfType ( proj ) ;
2015-09-07 14:29:46 +02:00
RimViewLinker * viewLinker = proj - > findViewLinkerFromView ( this ) ;
if ( viewLinker )
2015-09-01 18:21:20 +02:00
{
2015-09-15 10:45:39 +02:00
RimViewLink * viewLink = viewLinker - > viewLinkFromView ( this ) ;
2015-09-01 18:21:20 +02:00
2015-09-15 10:45:39 +02:00
if ( this = = viewLinker - > mainView ( ) | | ( viewLink & & viewLink - > isActive ( ) & & viewLink - > syncCamera ( ) ) )
2015-09-01 18:21:20 +02:00
{
2015-09-07 14:29:46 +02:00
viewLinker - > allViewsForCameraSync ( this , viewsToUpdate ) ;
2015-09-01 18:21:20 +02:00
}
}
2015-09-04 10:46:58 +02:00
cvf : : Vec3d sourceCamUp ;
cvf : : Vec3d sourceCamEye ;
cvf : : Vec3d sourceCamViewRefPoint ;
this - > viewer ( ) - > mainCamera ( ) - > toLookAt ( & sourceCamEye , & sourceCamViewRefPoint , & sourceCamUp ) ;
cvf : : Vec3d sourceCamGlobalEye = sourceCamEye ;
cvf : : Vec3d sourceCamGlobalViewRefPoint = sourceCamViewRefPoint ;
// Source bounding box in global coordinates including scaleZ
cvf : : BoundingBox sourceSceneBB = this - > viewer ( ) - > currentScene ( ) - > boundingBox ( ) ;
2015-09-03 13:06:00 +02:00
RimEclipseView * eclipseView = dynamic_cast < RimEclipseView * > ( this ) ;
if ( eclipseView
& & eclipseView - > eclipseCase ( )
& & eclipseView - > eclipseCase ( ) - > reservoirData ( )
& & eclipseView - > eclipseCase ( ) - > reservoirData ( ) - > mainGrid ( ) )
{
cvf : : Vec3d offset = eclipseView - > eclipseCase ( ) - > reservoirData ( ) - > mainGrid ( ) - > displayModelOffset ( ) ;
offset . z ( ) * = eclipseView - > scaleZ ( ) ;
2015-09-04 10:46:58 +02:00
sourceCamGlobalEye + = offset ;
sourceCamGlobalViewRefPoint + = offset ;
cvf : : Mat4d trans ;
trans . setTranslation ( offset ) ;
sourceSceneBB . transform ( trans ) ;
2015-09-03 13:06:00 +02:00
}
2015-09-01 18:21:20 +02:00
// Propagate view matrix to all relevant views
const cvf : : Mat4d mat = this - > viewer ( ) - > mainCamera ( ) - > viewMatrix ( ) ;
for ( size_t i = 0 ; i < viewsToUpdate . size ( ) ; i + + )
{
if ( viewsToUpdate [ i ] & & viewsToUpdate [ i ] - > viewer ( ) )
{
2015-09-04 10:46:58 +02:00
RiuViewer * destinationViewer = viewsToUpdate [ i ] - > viewer ( ) ;
// Destination bounding box in global coordinates including scaleZ
cvf : : BoundingBox destSceneBB = destinationViewer - > currentScene ( ) - > boundingBox ( ) ;
2015-09-03 13:06:00 +02:00
RimEclipseView * destEclipseView = dynamic_cast < RimEclipseView * > ( viewsToUpdate [ i ] ) ;
if ( destEclipseView
& & destEclipseView - > eclipseCase ( )
& & destEclipseView - > eclipseCase ( ) - > reservoirData ( )
& & destEclipseView - > eclipseCase ( ) - > reservoirData ( ) - > mainGrid ( ) )
{
cvf : : Vec3d destOffset = destEclipseView - > eclipseCase ( ) - > reservoirData ( ) - > mainGrid ( ) - > displayModelOffset ( ) ;
destOffset . z ( ) * = destEclipseView - > scaleZ ( ) ;
2015-09-04 10:46:58 +02:00
cvf : : Vec3d destinationCamEye = sourceCamGlobalEye - destOffset ;
cvf : : Vec3d destinationCamViewRefPoint = sourceCamGlobalViewRefPoint - destOffset ;
2015-09-03 13:06:00 +02:00
2015-09-04 10:46:58 +02:00
cvf : : Mat4d trans ;
trans . setTranslation ( destOffset ) ;
destSceneBB . transform ( trans ) ;
if ( isBoundingBoxesOverlappingOrClose ( sourceSceneBB , destSceneBB ) )
{
destinationViewer - > mainCamera ( ) - > setFromLookAt ( destinationCamEye , destinationCamViewRefPoint , sourceCamUp ) ;
}
else
{
// Fallback using values from source camera
destinationViewer - > mainCamera ( ) - > setFromLookAt ( sourceCamEye , sourceCamViewRefPoint , sourceCamUp ) ;
}
2015-09-03 13:06:00 +02:00
}
else
{
2015-09-04 10:46:58 +02:00
if ( isBoundingBoxesOverlappingOrClose ( sourceSceneBB , destSceneBB ) )
{
destinationViewer - > mainCamera ( ) - > setFromLookAt ( sourceCamGlobalEye , sourceCamGlobalViewRefPoint , sourceCamUp ) ;
}
else
{
// Fallback using values from source camera
destinationViewer - > mainCamera ( ) - > setFromLookAt ( sourceCamEye , sourceCamViewRefPoint , sourceCamUp ) ;
}
2015-09-03 13:06:00 +02:00
}
2015-09-01 18:21:20 +02:00
2015-09-04 10:46:58 +02:00
destinationViewer - > update ( ) ;
2015-09-01 18:21:20 +02:00
}
}
}
2015-09-01 22:11:39 +02:00
2015-09-03 13:06:00 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView : : setScaleZAndUpdate ( double scaleZ )
{
this - > scaleZ = scaleZ ;
updateScaleTransform ( ) ;
createDisplayModelAndRedraw ( ) ;
}
2015-09-04 10:46:58 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimView : : isBoundingBoxesOverlappingOrClose ( const cvf : : BoundingBox & sourceBB , const cvf : : BoundingBox & destBB )
{
2015-09-15 09:46:32 +02:00
if ( ! sourceBB . isValid ( ) | | ! destBB . isValid ( ) ) return false ;
2015-09-04 10:46:58 +02:00
if ( sourceBB . intersects ( destBB ) ) return true ;
double largestExtent = sourceBB . extent ( ) . length ( ) ;
if ( destBB . extent ( ) . length ( ) > largestExtent )
{
largestExtent = destBB . extent ( ) . length ( ) ;
}
double centerDist = ( sourceBB . center ( ) - destBB . center ( ) ) . length ( ) ;
if ( centerDist < largestExtent * 5 )
{
return true ;
}
return false ;
}
2015-09-11 16:45:04 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-09-13 08:54:32 +02:00
RimViewLinker * RimView : : viewLinkerWithDepViews ( )
2015-09-11 16:45:04 +02:00
{
RimViewLinker * viewLinker = NULL ;
std : : vector < caf : : PdmObjectHandle * > reffingObjs ;
this - > objectsWithReferringPtrFields ( reffingObjs ) ;
for ( size_t i = 0 ; i < reffingObjs . size ( ) ; + + i )
{
viewLinker = dynamic_cast < RimViewLinker * > ( reffingObjs [ i ] ) ;
if ( viewLinker ) break ;
}
return viewLinker ;
}