2018-01-09 10:11:28 +01:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// 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 "Rim3dView.h"
2019-05-06 10:36:05 +02:00
#include "RiaGuiApplication.h"
2018-11-05 14:28:07 +01:00
#include "RiaFieldHandleTools.h"
2018-01-09 10:11:28 +01:00
#include "RiaPreferences.h"
2018-01-12 11:31:01 +01:00
#include "RiaViewRedrawScheduler.h"
2018-01-09 10:11:28 +01:00
2018-10-11 16:03:49 +02:00
#include "Rim3dWellLogCurve.h"
2018-11-23 13:33:59 +01:00
#include "RimAnnotationInViewCollection.h"
2018-04-04 22:34:41 +02:00
#include "RimCase.h"
2018-01-16 09:37:08 +01:00
#include "RimGridView.h"
2018-01-09 10:11:28 +01:00
#include "RimMainPlotCollection.h"
#include "RimProject.h"
2018-06-26 10:12:49 +02:00
#include "RimTools.h"
2018-01-09 10:11:28 +01:00
#include "RimViewController.h"
#include "RimViewLinker.h"
#include "RimWellPathCollection.h"
2018-12-14 13:41:35 +01:00
#include "RimViewNameConfig.h"
2018-12-19 14:41:17 +01:00
#include "RimMeasurement.h"
2018-01-09 10:11:28 +01:00
2018-11-23 13:33:59 +01:00
#include "RivAnnotationsPartMgr.h"
2018-02-05 14:11:23 +01:00
#include "RivWellPathsPartMgr.h"
2018-12-19 14:41:17 +01:00
#include "RivMeasurementPartMgr.h"
2018-02-05 14:11:23 +01:00
2018-01-09 10:11:28 +01:00
#include "RiuMainWindow.h"
#include "RiuViewer.h"
#include "RiuTimeStepChangedHandler.h"
#include "cafDisplayCoordTransform.h"
#include "cafFrameAnimationControl.h"
#include "cvfCamera.h"
#include "cvfModelBasicList.h"
#include "cvfPart.h"
2018-01-16 09:37:08 +01:00
#include "cvfTransform.h"
2018-01-09 10:11:28 +01:00
#include "cvfViewport.h"
2018-01-16 11:21:02 +01:00
#include <climits>
2018-03-13 16:16:41 +01:00
#include "cvfScene.h"
2018-01-09 10:11:28 +01:00
namespace caf {
template <>
void caf :: AppEnum < Rim3dView :: SurfaceModeType >:: setUp ()
{
addItem ( Rim3dView :: SURFACE , "SURFACE" , "All" );
addItem ( Rim3dView :: FAULTS , "FAULTS" , "Faults only" );
addItem ( Rim3dView :: NO_SURFACE , "NO_SURFACE" , "None" );
setDefault ( Rim3dView :: SURFACE );
}
} // End namespace caf
CAF_PDM_XML_ABSTRACT_SOURCE_INIT ( Rim3dView , "GenericView" ); // Do not use. Abstract class
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Rim3dView :: Rim3dView ( void )
{
RiaApplication * app = RiaApplication :: instance ();
RiaPreferences * preferences = app -> preferences ();
CVF_ASSERT ( preferences );
2018-12-14 13:41:35 +01:00
CAF_PDM_InitFieldNoDefault ( & m_nameConfig , "NameConfig" , "" , "" , "" , "" );
m_nameConfig = new RimViewNameConfig ( this );
2018-01-09 10:11:28 +01:00
2018-12-14 13:41:35 +01:00
CAF_PDM_InitField ( & m_name_OBSOLETE , "UserDescription" , QString ( "" ), "Name" , "" , "" , "" );
m_name_OBSOLETE . xmlCapability () -> setIOWritable ( false );
2018-01-09 10:11:28 +01:00
2018-01-11 12:59:52 +01:00
CAF_PDM_InitField ( & m_cameraPosition , "CameraPosition" , cvf :: Mat4d :: IDENTITY , "" , "" , "" , "" );
m_cameraPosition . uiCapability () -> setUiHidden ( true );
2018-01-09 10:11:28 +01:00
2018-01-11 12:59:52 +01:00
CAF_PDM_InitField ( & m_cameraPointOfInterest , "CameraPointOfInterest" , cvf :: Vec3d :: ZERO , "" , "" , "" , "" );
m_cameraPointOfInterest . uiCapability () -> setUiHidden ( true );
2018-01-09 10:11:28 +01:00
CAF_PDM_InitField ( & isPerspectiveView , "PerspectiveProjection" , true , "Perspective Projection" , "" , "" , "" );
double defaultScaleFactor = preferences -> defaultScaleFactorZ ;
CAF_PDM_InitField ( & scaleZ , "GridZScale" , defaultScaleFactor , "Z Scale" , "" , "Scales the scene in the Z direction" , "" );
cvf :: Color3f defBackgColor = preferences -> defaultViewerBackgroundColor ();
2018-01-11 12:59:52 +01:00
CAF_PDM_InitField ( & m_backgroundColor , "ViewBackgroundColor" , defBackgColor , "Background" , "" , "" , "" );
2018-01-09 10:11:28 +01:00
CAF_PDM_InitField ( & maximumFrameRate , "MaximumFrameRate" , 10 , "Maximum Frame Rate" , "" , "" , "" );
maximumFrameRate . uiCapability () -> setUiHidden ( true );
CAF_PDM_InitField ( & hasUserRequestedAnimation , "AnimationMode" , false , "Animation Mode" , "" , "" , "" );
hasUserRequestedAnimation . uiCapability () -> setUiHidden ( true );
CAF_PDM_InitField ( & m_currentTimeStep , "CurrentTimeStep" , 0 , "Current Time Step" , "" , "" , "" );
m_currentTimeStep . uiCapability () -> setUiHidden ( true );
2019-04-10 12:49:20 +02:00
caf :: AppEnum < RiaDefines :: MeshModeType > defaultMeshType = preferences -> defaultMeshModeType ();
2018-01-09 10:11:28 +01:00
CAF_PDM_InitField ( & meshMode , "MeshMode" , defaultMeshType , "Grid Lines" , "" , "" , "" );
CAF_PDM_InitFieldNoDefault ( & surfaceMode , "SurfaceMode" , "Grid Surface" , "" , "" , "" );
2018-01-25 17:37:22 +01:00
CAF_PDM_InitField ( & m_showGridBox , "ShowGridBox" , true , "Show Grid Box" , "" , "" , "" );
2018-01-09 10:11:28 +01:00
CAF_PDM_InitField ( & m_disableLighting , "DisableLighting" , false , "Disable Results Lighting" , "" , "Disable light model for scalar result colors" , "" );
2018-12-10 13:03:53 +01:00
CAF_PDM_InitField ( & m_showZScaleLabel , "ShowZScale" , true , "Show Z Scale Label" , "" , "" , "" );
2018-01-09 10:11:28 +01:00
m_crossSectionVizModel = new cvf :: ModelBasicList ;
m_crossSectionVizModel -> setName ( "CrossSectionModel" );
m_highlightVizModel = new cvf :: ModelBasicList ;
m_highlightVizModel -> setName ( "HighlightModel" );
m_wellPathPipeVizModel = new cvf :: ModelBasicList ;
m_wellPathPipeVizModel -> setName ( "WellPathPipeModel" );
2018-02-05 14:11:23 +01:00
m_wellPathsPartManager = new RivWellPathsPartMgr ( this );
2018-11-23 13:33:59 +01:00
m_annotationsPartManager = new RivAnnotationsPartMgr ( this );
2018-02-05 14:11:23 +01:00
2018-12-19 14:41:17 +01:00
m_measurementPartManager = new RivMeasurementPartMgr ( this );
2018-01-09 10:11:28 +01:00
this -> setAs3DViewMdiWindow ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Rim3dView ::~ Rim3dView ( void )
{
2018-11-28 08:21:49 +01:00
if ( m_viewer )
{
m_viewer -> clearRimView ();
}
2018-01-09 10:11:28 +01:00
removeMdiWindowFromMdiArea ();
deleteViewWidget ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-09-12 10:04:15 +02:00
RiuViewer * Rim3dView :: viewer () const
2018-01-09 10:11:28 +01:00
{
return m_viewer ;
}
2018-09-24 22:15:34 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setName ( const QString & name )
{
2018-12-14 13:41:35 +01:00
m_nameConfig -> setCustomName ( name );
2018-09-24 22:15:34 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString Rim3dView :: name () const
{
2018-12-14 13:41:35 +01:00
return m_nameConfig -> customName ();
2018-09-24 22:15:34 +02:00
}
2018-01-09 10:11:28 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWidget * Rim3dView :: createViewWidget ( QWidget * mainWindowParent )
{
QGLFormat glFormat ;
2019-05-06 10:36:05 +02:00
glFormat . setDirectRendering ( RiaGuiApplication :: instance () -> useShaders ());
2018-01-09 10:11:28 +01:00
2019-01-01 15:12:13 +01:00
m_viewer = new RiuViewer ( glFormat , mainWindowParent );
2018-01-09 10:11:28 +01:00
m_viewer -> setOwnerReservoirView ( this );
2018-01-11 12:59:52 +01:00
cvf :: String xLabel ;
cvf :: String yLabel ;
cvf :: String zLabel ;
this -> axisLabels ( & xLabel , & yLabel , & zLabel );
m_viewer -> setAxisLabels ( xLabel , yLabel , zLabel );
2018-12-10 13:03:53 +01:00
updateZScaleLabel ();
2018-01-09 10:11:28 +01:00
return m_viewer -> layoutWidget ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateViewWidgetAfterCreation ()
{
m_viewer -> setDefaultPerspectiveNearPlaneDistance ( 10 );
this -> resetLegendsInViewer ();
m_viewer -> updateNavigationPolicy ();
2019-05-06 10:36:05 +02:00
m_viewer -> enablePerfInfoHud ( RiaGuiApplication :: instance () -> showPerformanceInfo ());
2018-01-09 10:11:28 +01:00
2018-01-11 12:59:52 +01:00
m_viewer -> mainCamera () -> setViewMatrix ( m_cameraPosition );
m_viewer -> setPointOfInterest ( m_cameraPointOfInterest ());
2018-01-09 10:11:28 +01:00
m_viewer -> enableParallelProjection ( ! isPerspectiveView ());
m_viewer -> mainCamera () -> viewport () -> setClearColor ( cvf :: Color4f ( backgroundColor ()));
this -> updateGridBoxData ();
this -> updateAnnotationItems ();
this -> createHighlightAndGridBoxDisplayModel ();
m_viewer -> update ();
}
2018-12-14 13:41:35 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: initAfterRead ()
{
RimViewWindow :: initAfterRead ();
if ( ! m_name_OBSOLETE (). isEmpty ())
{
nameConfig () -> setCustomName ( m_name_OBSOLETE ());
nameConfig () -> setAddCaseName ( false );
nameConfig () -> setAddAggregationType ( false );
nameConfig () -> setAddProperty ( false );
nameConfig () -> setAddSampleSpacing ( false );
}
}
2018-01-09 10:11:28 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateMdiWindowTitle ()
{
if ( m_viewer )
{
QString windowTitle ;
if ( ownerCase ())
{
2018-12-14 13:41:35 +01:00
windowTitle = QString ( "%1 - %2" ). arg ( ownerCase () -> caseUserDescription ()). arg ( name ());
2018-01-09 10:11:28 +01:00
}
else
{
2018-12-14 13:41:35 +01:00
windowTitle = name ();
2018-01-09 10:11:28 +01:00
}
m_viewer -> layoutWidget () -> setWindowTitle ( windowTitle );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: deleteViewWidget ()
{
2018-12-04 10:07:52 +01:00
// Earlier implementations has used m_viewer->deleteLater(). This caused issues triggered by 3D editors and interaction with
// the event processing. deleteLater() will not be handeled by processEvents() if we are in the state of processing UI events,
// ie in the process of handling a QAction
delete m_viewer ;
m_viewer = nullptr ;
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: defineUiOrdering ( QString uiConfigName , caf :: PdmUiOrdering & uiOrdering )
{
2018-11-15 14:58:22 +01:00
caf :: PdmUiGroup * viewGroup = uiOrdering . addNewGroupWithKeyword ( "Viewer" , "ViewGroup" );
2018-12-14 13:41:35 +01:00
//viewGroup->add(m_nameConfig->nameField());
2018-01-11 12:59:52 +01:00
viewGroup -> add ( & m_backgroundColor );
2018-12-10 13:03:53 +01:00
viewGroup -> add ( & m_showZScaleLabel );
2018-01-25 17:37:22 +01:00
viewGroup -> add ( & m_showGridBox );
2018-01-09 10:11:28 +01:00
viewGroup -> add ( & isPerspectiveView );
viewGroup -> add ( & m_disableLighting );
caf :: PdmUiGroup * gridGroup = uiOrdering . addNewGroup ( "Grid Appearance" );
gridGroup -> add ( & scaleZ );
gridGroup -> add ( & meshMode );
gridGroup -> add ( & surfaceMode );
2018-12-14 13:41:35 +01:00
uiOrdering . skipRemainingFields ( true );
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QImage Rim3dView :: snapshotWindowContent ()
{
if ( m_viewer )
{
// Force update of scheduled display models before snapshotting
2018-05-21 23:46:35 +02:00
RiaViewRedrawScheduler :: instance () -> updateAndRedrawScheduledViews ();
2018-01-09 10:11:28 +01:00
m_viewer -> repaint ();
return m_viewer -> snapshotImage ();
}
return QImage ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: scheduleCreateDisplayModelAndRedraw ()
{
2018-01-12 11:31:01 +01:00
RiaViewRedrawScheduler :: instance () -> scheduleDisplayModelUpdateAndRedraw ( this );
2018-01-09 10:11:28 +01:00
if ( this -> isMasterView ())
{
RimViewLinker * viewLinker = this -> assosiatedViewLinker ();
if ( viewLinker )
{
viewLinker -> scheduleCreateDisplayModelAndRedrawForDependentViews ();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setCurrentTimeStepAndUpdate ( int frameIndex )
{
setCurrentTimeStep ( frameIndex );
this -> updateCurrentTimeStep ();
RimProject * project ;
firstAncestorOrThisOfTypeAsserted ( project );
project -> mainPlotCollection () -> updateCurrentTimeStepInPlots ();
2018-11-23 13:33:59 +01:00
appendAnnotationsToModel ();
2018-12-19 14:41:17 +01:00
appendMeasurementToModel ();
2018-01-09 10:11:28 +01:00
}
2018-01-11 12:59:52 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString Rim3dView :: timeStepName ( int frameIdx ) const
{
return this -> ownerCase () -> timeStepName ( frameIdx );
}
2018-01-09 10:11:28 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setCurrentTimeStep ( int frameIndex )
{
const int oldTimeStep = m_currentTimeStep ;
m_currentTimeStep = frameIndex ;
clampCurrentTimestep ();
if ( m_currentTimeStep != oldTimeStep )
{
RiuTimeStepChangedHandler :: instance () -> handleTimeStepChanged ( this );
2018-01-15 14:52:22 +01:00
this -> onTimeStepChanged ();
2018-01-09 10:11:28 +01:00
}
this -> hasUserRequestedAnimation = true ;
2018-01-15 14:52:22 +01:00
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateCurrentTimeStepAndRedraw ()
{
this -> updateCurrentTimeStep ();
RimProject * project ;
firstAncestorOrThisOfTypeAsserted ( project );
project -> mainPlotCollection () -> updateCurrentTimeStepInPlots ();
if ( m_viewer ) m_viewer -> update ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: createDisplayModelAndRedraw ()
{
if ( m_viewer )
{
this -> clampCurrentTimestep ();
createDisplayModel ();
createHighlightAndGridBoxDisplayModel ();
updateDisplayModelVisibility ();
2018-01-11 12:59:52 +01:00
if ( m_cameraPosition (). isIdentity ())
2018-01-09 10:11:28 +01:00
{
setDefaultView ();
2018-01-11 12:59:52 +01:00
m_cameraPosition = m_viewer -> mainCamera () -> viewMatrix ();
m_cameraPointOfInterest = m_viewer -> pointOfInterest ();
2018-01-09 10:11:28 +01:00
}
}
2019-05-06 10:36:05 +02:00
if ( RiuMainWindow :: instance ())
{
RiuMainWindow :: instance () -> refreshAnimationActions ();
}
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
2018-03-13 16:16:41 +01:00
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: removeModelByName ( cvf :: Scene * scene , const cvf :: String & modelName )
{
std :: vector < cvf :: Model *> modelsToBeRemoved ;
for ( cvf :: uint i = 0 ; i < scene -> modelCount (); i ++ )
{
if ( scene -> model ( i ) -> name () == modelName )
{
modelsToBeRemoved . push_back ( scene -> model ( i ));
}
}
for ( size_t i = 0 ; i < modelsToBeRemoved . size (); i ++ )
{
scene -> removeModel ( modelsToBeRemoved [ i ]);
}
}
//--------------------------------------------------------------------------------------------------
2018-01-09 10:11:28 +01:00
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setDefaultView ()
{
if ( m_viewer )
{
m_viewer -> setDefaultView ();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: endAnimation ()
{
this -> hasUserRequestedAnimation = false ;
this -> updateStaticCellColors ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-01-31 15:53:02 +01:00
RimWellPathCollection * Rim3dView :: wellPathCollection () const
2018-01-09 10:11:28 +01:00
{
2018-06-26 10:12:49 +02:00
return RimTools :: wellPathCollection ();
2018-01-09 10:11:28 +01:00
}
2018-09-03 14:52:00 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rim3dView :: hasVisibleTimeStepDependent3dWellLogCurves () const
{
2019-04-24 07:41:11 +02:00
if ( wellPathCollection ())
2018-09-03 14:52:00 +02:00
{
2019-04-24 07:41:11 +02:00
std :: vector < Rim3dWellLogCurve *> wellLogCurves ;
wellPathCollection () -> descendantsIncludingThisOfType ( wellLogCurves );
for ( const Rim3dWellLogCurve * curve : wellLogCurves )
2018-09-03 14:52:00 +02:00
{
2019-04-24 07:41:11 +02:00
if ( curve -> showInView ( this ) && curve -> isShowingTimeDependentResult ())
{
return true ;
}
2018-09-03 14:52:00 +02:00
}
}
2019-04-24 07:41:11 +02:00
2018-09-03 14:52:00 +02:00
return false ;
}
2018-01-09 10:11:28 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setupBeforeSave ()
{
if ( m_viewer )
{
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...
2018-01-11 12:59:52 +01:00
m_cameraPosition = m_viewer -> mainCamera () -> viewMatrix ();
m_cameraPointOfInterest = m_viewer -> pointOfInterest ();
2018-01-09 10:11:28 +01:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setMeshOnlyDrawstyle ()
{
2019-04-10 12:49:20 +02:00
meshMode . setValueWithFieldChanged ( RiaDefines :: FULL_MESH );
2018-01-09 10:11:28 +01:00
surfaceMode . setValueWithFieldChanged ( NO_SURFACE );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setMeshSurfDrawstyle ()
{
2018-04-04 22:34:41 +02:00
surfaceMode . setValueWithFieldChanged ( SURFACE );
2019-04-10 12:49:20 +02:00
meshMode . setValueWithFieldChanged ( RiaDefines :: FULL_MESH );
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setFaultMeshSurfDrawstyle ()
{
2018-04-04 22:34:41 +02:00
surfaceMode . setValueWithFieldChanged ( SURFACE );
2019-04-10 12:49:20 +02:00
meshMode . setValueWithFieldChanged ( RiaDefines :: FAULTS_MESH );
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setSurfOnlyDrawstyle ()
{
2018-04-04 22:34:41 +02:00
surfaceMode . setValueWithFieldChanged ( SURFACE );
2019-04-10 12:49:20 +02:00
meshMode . setValueWithFieldChanged ( RiaDefines :: NO_MESH );
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setSurfaceDrawstyle ()
{
if ( surfaceMode () != NO_SURFACE ) surfaceMode . setValueWithFieldChanged ( SURFACE );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: disableLighting ( bool disable )
{
m_disableLighting = disable ;
updateCurrentTimeStepAndRedraw ();
updateConnectedEditors ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rim3dView :: isLightingDisabled () const
{
return m_disableLighting ();
}
2018-12-14 13:41:35 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf :: PdmFieldHandle * Rim3dView :: userDescriptionField ()
{
return m_nameConfig -> nameField ();
}
2018-01-09 10:11:28 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: fieldChangedByUi ( const caf :: PdmFieldHandle * changedField , const QVariant & oldValue , const QVariant & newValue )
{
RimViewWindow :: fieldChangedByUi ( changedField , oldValue , newValue );
if ( changedField == & meshMode )
{
createDisplayModel ();
updateDisplayModelVisibility ();
RiuMainWindow :: instance () -> refreshDrawStyleActions ();
RiuMainWindow :: instance () -> refreshAnimationActions ();
}
else if ( changedField == & isPerspectiveView )
{
if ( m_viewer ) m_viewer -> enableParallelProjection ( ! isPerspectiveView ());
}
else if ( changedField == & scaleZ )
{
2019-04-02 13:28:31 +02:00
updateScaling ();
2018-01-09 10:11:28 +01:00
RiuMainWindow :: instance () -> updateScaleValue ();
}
else if ( changedField == & surfaceMode )
{
createDisplayModel ();
updateDisplayModelVisibility ();
RiuMainWindow :: instance () -> refreshDrawStyleActions ();
RiuMainWindow :: instance () -> refreshAnimationActions ();
}
2018-01-25 17:37:22 +01:00
else if ( changedField == & m_showGridBox )
2018-01-09 10:11:28 +01:00
{
createHighlightAndGridBoxDisplayModelWithRedraw ();
}
else if ( changedField == & m_disableLighting )
{
createDisplayModel ();
RiuMainWindow :: instance () -> refreshDrawStyleActions ();
RiuMainWindow :: instance () -> refreshAnimationActions ();
}
2018-12-14 13:41:35 +01:00
else if ( changedField == m_nameConfig -> nameField ())
2018-01-09 10:11:28 +01:00
{
updateMdiWindowTitle ();
if ( viewController ())
{
viewController () -> updateDisplayNameAndIcon ();
viewController () -> updateConnectedEditors ();
}
else
{
if ( isMasterView ())
{
assosiatedViewLinker () -> updateUiNameAndIcon ();
assosiatedViewLinker () -> updateConnectedEditors ();
}
}
}
else if ( changedField == & m_currentTimeStep )
{
if ( m_viewer )
{
m_viewer -> update ();
2018-01-15 14:52:22 +01:00
2018-01-09 10:11:28 +01:00
}
}
2018-01-11 12:59:52 +01:00
else if ( changedField == & m_backgroundColor )
2018-01-09 10:11:28 +01:00
{
2019-04-10 12:49:20 +02:00
this -> applyBackgroundColorAndFontChanges ();
2018-01-09 10:11:28 +01:00
}
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 )
{
2018-04-19 13:12:28 +02:00
m_viewer -> animationControl () -> setTimeout ( maximumFrameRate != 0 ? 1000 / maximumFrameRate : std :: numeric_limits < int >:: max ());
2018-01-09 10:11:28 +01:00
}
}
2018-12-10 13:03:53 +01:00
else if ( changedField == & m_showZScaleLabel )
{
m_viewer -> showZScaleLabel ( m_showZScaleLabel ());
m_viewer -> update ();
}
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: addWellPathsToModel ( cvf :: ModelBasicList * wellPathModelBasicList ,
const cvf :: BoundingBox & wellPathClipBoundingBox )
{
if ( ! this -> ownerCase ()) return ;
cvf :: ref < caf :: DisplayCoordTransform > transForm = displayCoordTransform ();
2018-02-05 14:11:23 +01:00
m_wellPathsPartManager -> appendStaticGeometryPartsToModel ( wellPathModelBasicList ,
2018-03-16 11:21:57 +01:00
transForm . p (),
2018-02-05 14:11:23 +01:00
this -> ownerCase () -> characteristicCellSize (),
2018-03-16 11:21:57 +01:00
wellPathClipBoundingBox );
2018-01-09 10:11:28 +01:00
wellPathModelBasicList -> updateBoundingBoxesRecursive ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: addDynamicWellPathsToModel ( cvf :: ModelBasicList * wellPathModelBasicList , const cvf :: BoundingBox & wellPathClipBoundingBox )
{
if ( ! this -> ownerCase ()) return ;
cvf :: ref < caf :: DisplayCoordTransform > transForm = displayCoordTransform ();
2018-03-16 11:21:57 +01:00
size_t timeStepIndex = currentTimeStep ();
2018-02-05 14:11:23 +01:00
m_wellPathsPartManager -> appendDynamicGeometryPartsToModel ( wellPathModelBasicList ,
2018-03-16 11:21:57 +01:00
timeStepIndex ,
transForm . p (),
2018-03-12 14:08:45 +01:00
this -> ownerCase () -> characteristicCellSize (),
2018-03-16 11:21:57 +01:00
wellPathClipBoundingBox );
2018-01-09 10:11:28 +01:00
wellPathModelBasicList -> updateBoundingBoxesRecursive ();
}
2018-11-23 13:33:59 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: addAnnotationsToModel ( cvf :: ModelBasicList * wellPathModelBasicList )
{
if ( ! this -> ownerCase ()) return ;
std :: vector < RimAnnotationInViewCollection *> annotationCollections ;
descendantsIncludingThisOfType ( annotationCollections );
if ( annotationCollections . empty () || ! annotationCollections . front () -> isActive ())
{
m_annotationsPartManager -> clearGeometryCache ();
}
else
{
cvf :: ref < caf :: DisplayCoordTransform > transForm = displayCoordTransform ();
2018-11-29 14:28:33 +01:00
m_annotationsPartManager -> appendGeometryPartsToModel ( wellPathModelBasicList , transForm . p (), ownerCase () -> allCellsBoundingBox ());
2018-11-23 13:33:59 +01:00
}
wellPathModelBasicList -> updateBoundingBoxesRecursive ();
}
2018-12-19 14:41:17 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: addMeasurementToModel ( cvf :: ModelBasicList * wellPathModelBasicList )
{
if ( ! this -> ownerCase ()) return ;
RimMeasurement * measurement = RiaApplication :: instance () -> project () -> measurement ();
2019-01-03 07:18:22 +01:00
if ( ! measurement || measurement -> pointsInDomainCoords (). empty ())
2018-12-19 14:41:17 +01:00
{
m_measurementPartManager -> clearGeometryCache ();
}
else
{
cvf :: ref < caf :: DisplayCoordTransform > transForm = displayCoordTransform ();
2019-02-04 15:28:32 +01:00
m_measurementPartManager -> appendGeometryPartsToModel ( m_viewer -> mainCamera (),
2018-12-19 14:41:17 +01:00
wellPathModelBasicList , transForm . p (), ownerCase () -> allCellsBoundingBox ());
}
wellPathModelBasicList -> updateBoundingBoxesRecursive ();
}
2018-01-09 10:11:28 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-09-24 22:42:13 +02:00
void Rim3dView :: setScaleZAndUpdate ( double scalingFactor )
2018-01-09 10:11:28 +01:00
{
2018-09-24 22:42:13 +02:00
this -> scaleZ = scalingFactor ;
2018-01-09 10:11:28 +01:00
updateScaleTransform ();
this -> updateGridBoxData ();
this -> scheduleCreateDisplayModelAndRedraw ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rim3dView :: isMasterView () const
{
RimViewLinker * viewLinker = this -> assosiatedViewLinker ();
if ( viewLinker && this == viewLinker -> masterView ())
{
return true ;
}
return false ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateGridBoxData ()
{
2018-01-11 12:59:52 +01:00
if ( m_viewer && ownerCase ())
2018-01-09 10:11:28 +01:00
{
2018-01-11 12:59:52 +01:00
m_viewer -> updateGridBoxData ( scaleZ (),
ownerCase () -> displayModelOffset (),
backgroundColor (),
showActiveCellsOnly () ? ownerCase () -> activeCellsBoundingBox ()
: ownerCase () -> allCellsBoundingBox ()
);
2018-01-09 10:11:28 +01:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateAnnotationItems ()
{
if ( m_viewer )
{
m_viewer -> updateAnnotationItems ();
}
}
2019-04-02 13:28:31 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateScaling ()
{
if ( scaleZ < 1 ) scaleZ = 1 ;
this -> updateGridBoxData ();
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 ();
m_viewer -> update ();
updateZScaleLabel ();
}
}
2018-12-10 13:03:53 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateZScaleLabel ()
{
// Update Z scale label
int scale = static_cast < int > ( scaleZ ());
m_viewer -> setZScale ( scale );
}
2019-03-25 15:43:19 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateMeasurement ()
{
if ( m_viewer )
{
appendMeasurementToModel ();
m_viewer -> update ();
}
}
2018-01-09 10:11:28 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: createHighlightAndGridBoxDisplayModelWithRedraw ()
{
createHighlightAndGridBoxDisplayModel ();
if ( m_viewer )
{
m_viewer -> update ();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: createHighlightAndGridBoxDisplayModel ()
{
m_viewer -> removeStaticModel ( m_highlightVizModel . p ());
m_highlightVizModel -> removeAllParts ();
cvf :: Collection < cvf :: Part > parts ;
createPartCollectionFromSelection ( & parts );
if ( parts . size () > 0 )
{
for ( size_t i = 0 ; i < parts . size (); i ++ )
{
m_highlightVizModel -> addPart ( parts [ i ]. p ());
}
m_highlightVizModel -> updateBoundingBoxesRecursive ();
m_viewer -> addStaticModelOnce ( m_highlightVizModel . p ());
}
2018-01-25 17:37:22 +01:00
m_viewer -> showGridBox ( m_showGridBox ());
}
2018-10-31 09:39:27 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setBackgroundColor ( const cvf :: Color3f & newBackgroundColor )
{
m_backgroundColor = newBackgroundColor ;
}
2018-10-31 12:13:04 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setShowGridBox ( bool showGridBox )
{
m_showGridBox = showGridBox ;
}
2018-04-06 11:52:29 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2019-04-10 12:49:20 +02:00
void Rim3dView :: applyBackgroundColorAndFontChanges ()
2018-04-06 11:52:29 +02:00
{
if ( m_viewer != nullptr )
{
m_viewer -> mainCamera () -> viewport () -> setClearColor ( cvf :: Color4f ( backgroundColor ()));
2019-04-10 12:49:20 +02:00
m_viewer -> updateFonts ();
2018-04-06 11:52:29 +02:00
}
updateGridBoxData ();
updateAnnotationItems ();
2018-04-09 11:51:30 +02:00
updateLegends ();
2018-04-06 11:52:29 +02:00
}
2019-02-15 13:36:20 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2019-02-21 12:52:23 +01:00
void Rim3dView :: performAutoNameUpdate ()
2019-02-15 13:36:20 +01:00
{
updateMdiWindowTitle ();
}
2018-01-25 17:37:22 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: updateDisplayModelVisibility ()
{
if ( m_viewer . isNull ()) return ;
const cvf :: uint uintSurfaceBit = surfaceBit ;
const cvf :: uint uintMeshSurfaceBit = meshSurfaceBit ;
const cvf :: uint uintFaultBit = faultBit ;
const cvf :: uint uintMeshFaultBit = meshFaultBit ;
2018-04-04 22:34:41 +02:00
const cvf :: uint uintIntersectionCellFaceBit = intersectionCellFaceBit ;
const cvf :: uint uintIntersectionCellMeshBit = intersectionCellMeshBit ;
const cvf :: uint uintIntersectionFaultMeshBit = intersectionFaultMeshBit ;
2018-01-25 17:37:22 +01:00
// Initialize the mask to show everything except the the bits controlled here
2018-04-04 22:34:41 +02:00
unsigned int mask =
0xffffffff
& ~ uintSurfaceBit
& ~ uintFaultBit
& ~ uintMeshSurfaceBit
& ~ uintMeshFaultBit
& ~ intersectionCellFaceBit
& ~ intersectionCellMeshBit
& ~ intersectionFaultMeshBit ;
2018-01-25 17:37:22 +01:00
// Then turn the appropriate bits on according to the user settings
if ( surfaceMode == SURFACE )
{
mask |= uintSurfaceBit ;
mask |= uintFaultBit ;
2018-04-04 22:34:41 +02:00
mask |= intersectionCellFaceBit ;
2018-01-25 17:37:22 +01:00
}
else if ( surfaceMode == FAULTS )
{
mask |= uintFaultBit ;
2018-04-04 22:34:41 +02:00
mask |= intersectionCellFaceBit ;
2018-01-25 17:37:22 +01:00
}
2019-04-10 12:49:20 +02:00
if ( meshMode == RiaDefines :: FULL_MESH )
2018-01-25 17:37:22 +01:00
{
mask |= uintMeshSurfaceBit ;
mask |= uintMeshFaultBit ;
2018-04-04 22:34:41 +02:00
mask |= intersectionCellMeshBit ;
mask |= intersectionFaultMeshBit ;
2018-01-25 17:37:22 +01:00
}
2019-04-10 12:49:20 +02:00
else if ( meshMode == RiaDefines :: FAULTS_MESH )
2018-01-25 17:37:22 +01:00
{
mask |= uintMeshFaultBit ;
2018-04-04 22:34:41 +02:00
mask |= intersectionFaultMeshBit ;
2018-01-25 17:37:22 +01:00
}
m_viewer -> setEnableMask ( mask );
m_viewer -> update ();
2018-01-09 10:11:28 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rim3dView :: showActiveCellsOnly ()
{
return false ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: zoomAll ()
{
if ( m_viewer )
{
m_viewer -> zoomAll ();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf :: ref < caf :: DisplayCoordTransform > Rim3dView :: displayCoordTransform () const
{
cvf :: ref < caf :: DisplayCoordTransform > coordTrans = new caf :: DisplayCoordTransform ;
cvf :: Vec3d scale ( 1.0 , 1.0 , scaleZ );
coordTrans -> setScale ( scale );
RimCase * rimCase = ownerCase ();
if ( rimCase )
{
coordTrans -> setTranslation ( rimCase -> displayModelOffset ());
}
return coordTrans ;
}
2019-04-10 16:13:40 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rim3dView :: hasCustomFontSizes ( RiaDefines :: FontSettingType fontSettingType , int defaultFontSize ) const
{
return false ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Rim3dView :: applyFontSize ( RiaDefines :: FontSettingType fontSettingType , int oldFontSize , int fontSize , bool forceChange /*= false*/ )
{
if ( fontSettingType == RiaDefines :: SCENE_FONT )
{
applyBackgroundColorAndFontChanges ();
return true ;
}
return false ;
}
2018-05-18 19:23:36 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf :: Mat4d Rim3dView :: cameraPosition () const
{
return m_cameraPosition ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf :: Vec3d Rim3dView :: cameraPointOfInterest () const
{
return m_cameraPointOfInterest ();
}
2018-12-14 13:41:35 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewNameConfig * Rim3dView :: nameConfig () const
{
return m_nameConfig ();
}
2018-01-09 10:11:28 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWidget * Rim3dView :: viewWidget ()
{
if ( m_viewer ) return m_viewer -> layoutWidget ();
else return nullptr ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: forceShowWindowOn ()
{
m_showWindow . setValueWithFieldChanged ( true );
}
2018-01-25 17:37:22 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-01-29 11:24:53 +01:00
void Rim3dView :: disableGridBoxField ()
2018-01-25 17:37:22 +01:00
{
m_showGridBox = false ;
2018-11-05 14:28:07 +01:00
RiaFieldhandleTools :: disableWriteAndSetFieldHidden ( & m_showGridBox );
2018-01-29 11:24:53 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: disablePerspectiveProjectionField ()
{
isPerspectiveView = false ;
2018-11-05 14:28:07 +01:00
RiaFieldhandleTools :: disableWriteAndSetFieldHidden ( & isPerspectiveView );
2018-01-25 17:37:22 +01:00
}
2018-01-11 12:59:52 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: handleMdiWindowClosed ()
{
RimViewWindow :: handleMdiWindowClosed ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: setMdiWindowGeometry ( const RimMdiWindowGeometry & windowGeometry )
{
RimViewWindow :: setMdiWindowGeometry ( windowGeometry );
}
2018-01-12 14:12:31 +01:00
//--------------------------------------------------------------------------------------------------
2018-11-23 13:33:59 +01:00
///
2018-01-12 14:12:31 +01:00
//--------------------------------------------------------------------------------------------------
2018-11-23 13:33:59 +01:00
void Rim3dView :: appendAnnotationsToModel ()
{
if ( ! m_viewer ) return ;
cvf :: Scene * frameScene = m_viewer -> frame ( m_currentTimeStep );
if ( frameScene )
{
cvf :: String name = "Annotations" ;
this -> removeModelByName ( frameScene , name );
cvf :: ref < cvf :: ModelBasicList > model = new cvf :: ModelBasicList ;
model -> setName ( name );
addAnnotationsToModel ( model . p ());
frameScene -> addModel ( model . p ());
}
}
2018-12-19 14:41:17 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView :: appendMeasurementToModel ()
{
if ( ! m_viewer ) return ;
cvf :: Scene * frameScene = m_viewer -> frame ( m_currentTimeStep );
if ( frameScene )
{
cvf :: String name = "Measurement" ;
this -> removeModelByName ( frameScene , name );
cvf :: ref < cvf :: ModelBasicList > model = new cvf :: ModelBasicList ;
model -> setName ( name );
addMeasurementToModel ( model . p ());
frameScene -> addModel ( model . p ());
}
}