2013-12-03 20:30:32 +01:00
/////////////////////////////////////////////////////////////////////////////////
//
2014-09-24 07:14:52 +02:00
// Copyright (C) Statoil ASA
// Copyright (C) Ceetron Solutions AS
2013-12-03 20:30:32 +01:00
//
// 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 "RimFaultCollection.h"
#include "RiaApplication.h"
#include "RiaPreferences.h"
2013-12-04 12:13:01 +01:00
#include "RigCaseData.h"
2014-06-12 12:35:48 +02:00
#include "RimCase.h"
2014-08-22 09:28:25 +02:00
#include "RimNoCommonAreaNNC.h"
#include "RimNoCommonAreaNncCollection.h"
2014-06-12 12:35:48 +02:00
#include "RimReservoirView.h"
2014-01-23 07:31:07 +01:00
#include "RiuMainWindow.h"
2014-06-12 12:35:48 +02:00
#include "RivColorTableArray.h"
2013-12-04 12:13:01 +01:00
2014-07-24 10:11:43 +02:00
#include "cafAppEnum.h"
#include "cafPdmFieldCvfColor.h"
#include "cafPdmFieldCvfMat4d.h"
2013-12-03 20:30:32 +01:00
2013-12-18 08:57:22 +01:00
namespace caf
{
template <>
void AppEnum < RimFaultCollection :: FaultFaceCullingMode >:: setUp ()
{
2014-01-03 08:58:26 +01:00
addItem ( RimFaultCollection :: FAULT_BACK_FACE_CULLING , "FAULT_BACK_FACE_CULLING" , "Cell behind fault" );
addItem ( RimFaultCollection :: FAULT_FRONT_FACE_CULLING , "FAULT_FRONT_FACE_CULLING" , "Cell in front of fault" );
2014-01-03 13:42:33 +01:00
addItem ( RimFaultCollection :: FAULT_NO_FACE_CULLING , "FAULT_NO_FACE_CULLING" , "Show both" );
2013-12-18 08:57:22 +01:00
setDefault ( RimFaultCollection :: FAULT_NO_FACE_CULLING );
}
}
2013-12-03 20:30:32 +01:00
CAF_PDM_SOURCE_INIT ( RimFaultCollection , "Faults" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFaultCollection :: RimFaultCollection ()
{
CAF_PDM_InitObject ( "Faults" , ":/draw_style_faults_24x24.png" , "" , "" );
2013-12-20 08:48:54 +01:00
RiaPreferences * prefs = RiaApplication :: instance () -> preferences ();
2013-12-20 14:34:38 +01:00
CAF_PDM_InitField ( & showFaultCollection , "Active" , true , "Active" , "" , "" , "" );
2013-12-03 20:30:32 +01:00
showFaultCollection . setUiHidden ( true );
2014-01-03 13:42:33 +01:00
CAF_PDM_InitField ( & showFaultFaces , "ShowFaultFaces" , true , "Show defined faces" , "" , "" , "" );
CAF_PDM_InitField ( & showOppositeFaultFaces , "ShowOppositeFaultFaces" , true , "Show opposite faces" , "" , "" , "" );
2014-08-01 14:48:37 +02:00
CAF_PDM_InitField ( & m_showFaultsOutsideFilters , "ShowFaultsOutsideFilters" , true , "Show faults outside filters" , "" , "" , "" );
2013-12-06 09:08:45 +01:00
2014-01-08 07:34:22 +01:00
CAF_PDM_InitField ( & faultResult , "FaultFaceCulling" , caf :: AppEnum < RimFaultCollection :: FaultFaceCullingMode > ( RimFaultCollection :: FAULT_BACK_FACE_CULLING ), "Dynamic Face Selection" , "" , "" , "" );
2013-12-18 08:57:22 +01:00
2014-01-03 13:42:33 +01:00
CAF_PDM_InitField ( & showFaultLabel , "ShowFaultLabel" , false , "Show labels" , "" , "" , "" );
2013-12-03 20:30:32 +01:00
cvf :: Color3f defWellLabelColor = RiaApplication :: instance () -> preferences () -> defaultWellLabelColor ();
2014-01-03 13:42:33 +01:00
CAF_PDM_InitField ( & faultLabelColor , "FaultLabelColor" , defWellLabelColor , "Label color" , "" , "" , "" );
2014-08-26 11:55:26 +02:00
2014-09-09 13:07:01 +02:00
CAF_PDM_InitField ( & showNNCs , "ShowNNCs" , true , "Show NNCs" , "" , "" , "" );
CAF_PDM_InitField ( & hideNncsWhenNoResultIsAvailable , "HideNncsWhenNoResultIsAvailable" , true , "Hide NNC geometry if no NNC result is available" , "" , "" , "" );
2013-12-03 20:30:32 +01:00
2014-08-22 09:28:25 +02:00
CAF_PDM_InitFieldNoDefault ( & noCommonAreaNnncCollection , "NoCommonAreaNnncCollection" , "NNCs With No Common Area" , "" , "" , "" );
noCommonAreaNnncCollection = new RimNoCommonAreaNncCollection ;
2013-12-03 20:30:32 +01:00
2014-09-04 09:55:55 +02:00
CAF_PDM_InitFieldNoDefault ( & faults , "Faults" , "Faults" , "" , "" , "" );
2013-12-03 20:30:32 +01:00
m_reservoirView = NULL ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFaultCollection ::~ RimFaultCollection ()
{
faults . deleteAllChildObjects ();
2014-08-22 09:28:25 +02:00
delete noCommonAreaNnncCollection ();
2013-12-03 20:30:32 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection :: fieldChangedByUi ( const caf :: PdmFieldHandle * changedField , const QVariant & oldValue , const QVariant & newValue )
{
2014-08-01 13:35:52 +02:00
this -> updateUiIconFromToggleField ();
2013-12-10 07:43:17 +01:00
if ( & faultLabelColor == changedField )
{
m_reservoirView -> scheduleReservoirGridGeometryRegen ();
}
2014-07-31 14:05:40 +02:00
if ( & showFaultFaces == changedField ||
2013-12-06 19:39:55 +01:00
& showOppositeFaultFaces == changedField ||
& showFaultCollection == changedField ||
& showFaultLabel == changedField ||
2014-08-01 14:48:37 +02:00
& m_showFaultsOutsideFilters == changedField ||
2013-12-18 08:57:22 +01:00
& faultLabelColor == changedField ||
2014-08-26 11:55:26 +02:00
& faultResult == changedField ||
2014-09-09 13:07:01 +02:00
& showNNCs == changedField ||
& hideNncsWhenNoResultIsAvailable == changedField
2013-12-18 08:57:22 +01:00
)
2013-12-03 20:30:32 +01:00
{
if ( m_reservoirView )
{
m_reservoirView -> scheduleCreateDisplayModelAndRedraw ();
}
}
2014-01-23 07:31:07 +01:00
if ( & showFaultLabel == changedField )
{
RiuMainWindow :: instance () -> refreshDrawStyleActions ();
}
2013-12-03 20:30:32 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection :: setReservoirView ( RimReservoirView * ownerReservoirView )
{
m_reservoirView = ownerReservoirView ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf :: PdmFieldHandle * RimFaultCollection :: objectToggleField ()
{
return & showFaultCollection ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFault * RimFaultCollection :: findFaultByName ( QString name )
{
for ( size_t i = 0 ; i < this -> faults (). size (); ++ i )
{
if ( this -> faults ()[ i ] -> name () == name )
{
return this -> faults ()[ i ];
}
}
return NULL ;
}
2013-12-05 09:59:05 +01:00
2013-12-05 10:48:57 +01:00
//--------------------------------------------------------------------------------------------------
/// A comparing function used to sort Faults in the RimFaultCollection::syncronizeFaults() method
//--------------------------------------------------------------------------------------------------
bool faultComparator ( const cvf :: ref < RigFault >& a , const cvf :: ref < RigFault >& b )
{
CVF_TIGHT_ASSERT ( a . notNull () && b . notNull ());
int compareValue = a -> name (). compare ( b -> name (), Qt :: CaseInsensitive );
2014-01-22 14:05:20 +01:00
2013-12-05 10:48:57 +01:00
return ( compareValue < 0 );
}
2013-12-05 09:59:05 +01:00
2013-12-04 12:13:01 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection :: syncronizeFaults ()
{
2014-07-02 14:11:56 +02:00
if ( ! ( m_reservoirView && m_reservoirView -> eclipseCase () && m_reservoirView -> eclipseCase () -> reservoirData () && m_reservoirView -> eclipseCase () -> reservoirData () -> mainGrid ()) ) return ;
2013-12-04 12:13:01 +01:00
cvf :: ref < cvf :: Color3fArray > partColors = RivColorTableArray :: colorTableArray ();
2013-12-05 09:59:05 +01:00
const cvf :: Collection < RigFault > constRigFaults = m_reservoirView -> eclipseCase () -> reservoirData () -> mainGrid () -> faults ();
2014-01-22 14:05:20 +01:00
cvf :: Collection < RigFault > rigFaults ;
{
cvf :: Collection < RigFault > sortedFaults ( constRigFaults );
2013-12-05 09:59:05 +01:00
2014-01-22 14:05:20 +01:00
std :: sort ( sortedFaults . begin (), sortedFaults . end (), faultComparator );
cvf :: ref < RigFault > undefinedFaults ;
for ( size_t i = 0 ; i < sortedFaults . size (); i ++ )
{
if ( sortedFaults [ i ] -> name (). compare ( RimDefines :: undefinedGridFaultName (), Qt :: CaseInsensitive ) == 0 )
{
undefinedFaults = sortedFaults [ i ];
}
}
if ( undefinedFaults . notNull ())
{
sortedFaults . erase ( undefinedFaults . p ());
rigFaults . push_back ( undefinedFaults . p ());
}
for ( size_t i = 0 ; i < sortedFaults . size (); i ++ )
{
rigFaults . push_back ( sortedFaults [ i ]. p ());
}
}
// Find faults with
2013-12-04 12:13:01 +01:00
std :: vector < caf :: PdmPointer < RimFault > > newFaults ;
// Find corresponding fault from data model, or create a new
for ( size_t fIdx = 0 ; fIdx < rigFaults . size (); ++ fIdx )
{
RimFault * rimFault = this -> findFaultByName ( rigFaults [ fIdx ] -> name ());
if ( ! rimFault )
{
rimFault = new RimFault ();
rimFault -> faultColor = partColors -> get ( fIdx % partColors -> size ());
}
rimFault -> setFaultGeometry ( rigFaults [ fIdx ]. p ());
newFaults . push_back ( rimFault );
}
this -> faults (). clear ();
this -> faults (). insert ( 0 , newFaults );
2014-01-03 09:40:39 +01:00
QString toolTip = QString ( "Fault count (%1)" ). arg ( newFaults . size ());
setUiToolTip ( toolTip );
2014-08-22 09:28:25 +02:00
// NNCs
this -> noCommonAreaNnncCollection () -> noCommonAreaNncs (). deleteAllChildObjects ();
RigMainGrid * mainGrid = m_reservoirView -> eclipseCase () -> reservoirData () -> mainGrid ();
std :: vector < RigConnection >& nncConnections = mainGrid -> nncData () -> connections ();
for ( size_t i = 0 ; i < nncConnections . size (); i ++ )
{
if ( ! nncConnections [ i ]. hasCommonArea ())
{
RimNoCommonAreaNNC * noCommonAreaNnc = new RimNoCommonAreaNNC ();
2014-09-04 10:37:36 +02:00
QString firstConnectionText ;
QString secondConnectionText ;
{
const RigCell & cell = mainGrid -> cells ()[ nncConnections [ i ]. m_c1GlobIdx ];
RigGridBase * hostGrid = cell . hostGrid ();
size_t gridLocalCellIndex = cell . gridLocalCellIndex ();
size_t i , j , k ;
if ( hostGrid -> ijkFromCellIndex ( gridLocalCellIndex , & i , & j , & k ))
{
// Adjust to 1-based Eclipse indexing
i ++ ;
j ++ ;
k ++ ;
if ( ! hostGrid -> isMainGrid ())
{
QString gridName = QString :: fromStdString ( hostGrid -> gridName ());
firstConnectionText = gridName + " " ;
}
firstConnectionText += QString ( "[%1 %2 %3] - " ). arg ( i ). arg ( j ). arg ( k );
}
}
2014-08-22 09:28:25 +02:00
2014-09-04 10:37:36 +02:00
{
const RigCell & cell = mainGrid -> cells ()[ nncConnections [ i ]. m_c2GlobIdx ];
RigGridBase * hostGrid = cell . hostGrid ();
size_t gridLocalCellIndex = cell . gridLocalCellIndex ();
size_t i , j , k ;
if ( hostGrid -> ijkFromCellIndex ( gridLocalCellIndex , & i , & j , & k ))
{
// Adjust to 1-based Eclipse indexing
i ++ ;
j ++ ;
k ++ ;
if ( ! hostGrid -> isMainGrid ())
{
QString gridName = QString :: fromStdString ( hostGrid -> gridName ());
secondConnectionText = gridName + " " ;
}
secondConnectionText += QString ( "[%1 %2 %3]" ). arg ( i ). arg ( j ). arg ( k );
}
}
2014-08-22 09:28:25 +02:00
2014-09-04 10:37:36 +02:00
noCommonAreaNnc -> name = firstConnectionText + secondConnectionText ;
2014-08-22 09:28:25 +02:00
this -> noCommonAreaNnncCollection () -> noCommonAreaNncs (). push_back ( noCommonAreaNnc );
}
2014-09-04 09:55:55 +02:00
this -> noCommonAreaNnncCollection () -> updateName ();
2014-08-22 09:28:25 +02:00
}
2013-12-04 12:13:01 +01:00
}
2013-12-18 09:26:06 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFaultCollection :: isGridVisualizationMode () const
{
CVF_ASSERT ( m_reservoirView );
2013-12-18 23:37:30 +01:00
return m_reservoirView -> isGridVisualizationMode ();
2013-12-18 09:26:06 +01:00
}
2014-01-03 08:38:09 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection :: defineUiOrdering ( QString uiConfigName , caf :: PdmUiOrdering & uiOrdering )
{
bool isGridVizMode = isGridVisualizationMode ();
faultResult . setUiReadOnly ( isGridVizMode );
2014-01-03 13:42:33 +01:00
showFaultFaces . setUiReadOnly ( isGridVizMode );
showOppositeFaultFaces . setUiReadOnly ( isGridVizMode );
caf :: PdmUiGroup * labs = uiOrdering . addNewGroup ( "Fault Labels" );
labs -> add ( & showFaultLabel );
labs -> add ( & faultLabelColor );
2014-01-22 14:05:20 +01:00
caf :: PdmUiGroup * adv = uiOrdering . addNewGroup ( "Fault Options" );
2014-08-01 14:48:37 +02:00
adv -> add ( & m_showFaultsOutsideFilters );
2014-01-03 13:42:33 +01:00
2014-01-22 14:05:20 +01:00
caf :: PdmUiGroup * ffviz = uiOrdering . addNewGroup ( "Fault Face Visibility" );
ffviz -> add ( & showFaultFaces );
ffviz -> add ( & showOppositeFaultFaces );
ffviz -> add ( & faultResult );
2014-09-09 13:07:01 +02:00
caf :: PdmUiGroup * nncViz = uiOrdering . addNewGroup ( "NNC Visibility" );
nncViz -> add ( & showNNCs );
nncViz -> add ( & hideNncsWhenNoResultIsAvailable );
2014-01-03 08:38:09 +01:00
}
2014-08-01 14:48:37 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFaultCollection :: showFaultsOutsideFilters () const
{
if ( ! showFaultCollection ) return false ;
return m_showFaultsOutsideFilters ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection :: setShowFaultsOutsideFilters ( bool enableState )
{
m_showFaultsOutsideFilters = enableState ;
}
2014-08-22 09:28:25 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection :: addMockData ()
{
if ( ! ( m_reservoirView && m_reservoirView -> eclipseCase () && m_reservoirView -> eclipseCase () -> reservoirData () && m_reservoirView -> eclipseCase () -> reservoirData () -> mainGrid ())) return ;
}