2013-12-03 13:30:32 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
2013-12-04 02:39:50 -06:00
// Copyright (C) Statoil ASA, Ceetron Solutions AS
2013-12-03 13:30:32 -06: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 "cafAppEnum.h"
# include "cafPdmFieldCvfColor.h"
# include "cafPdmFieldCvfMat4d.h"
# include "RimReservoirView.h"
# include "RimResultSlot.h"
# include "RimCellRangeFilterCollection.h"
# include "RimCellPropertyFilterCollection.h"
# include "RimWellCollection.h"
# include "Rim3dOverlayInfoConfig.h"
# include "RimCellEdgeResultSlot.h"
# include "RiaApplication.h"
# include "RiaPreferences.h"
2013-12-04 05:13:01 -06:00
# include "RimCase.h"
# include "RimReservoirCellResultsCacher.h"
# include "RigCaseData.h"
# include "RivColorTableArray.h"
2013-12-03 13:30:32 -06:00
2013-12-18 01:57:22 -06:00
namespace caf
{
template < >
void AppEnum < RimFaultCollection : : FaultFaceCullingMode > : : setUp ( )
{
2014-01-03 01:58:26 -06: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 06:42:33 -06:00
addItem ( RimFaultCollection : : FAULT_NO_FACE_CULLING , " FAULT_NO_FACE_CULLING " , " Show both " ) ;
2013-12-18 01:57:22 -06:00
setDefault ( RimFaultCollection : : FAULT_NO_FACE_CULLING ) ;
}
}
2013-12-03 13:30:32 -06:00
CAF_PDM_SOURCE_INIT ( RimFaultCollection , " Faults " ) ;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFaultCollection : : RimFaultCollection ( )
{
CAF_PDM_InitObject ( " Faults " , " :/draw_style_faults_24x24.png " , " " , " " ) ;
2013-12-20 01:48:54 -06:00
RiaPreferences * prefs = RiaApplication : : instance ( ) - > preferences ( ) ;
2013-12-20 07:34:38 -06:00
CAF_PDM_InitField ( & showFaultCollection , " Active " , true , " Active " , " " , " " , " " ) ;
2013-12-03 13:30:32 -06:00
showFaultCollection . setUiHidden ( true ) ;
2013-12-18 12:02:07 -06:00
CAF_PDM_InitField ( & showGeometryDetectedFaults , " ShowGeometryDetectedFaults " , false , " Show geometry detected faults " , " " , " " , " " ) ;
2013-12-19 03:13:55 -06:00
showGeometryDetectedFaults . setUiHidden ( true ) ;
2013-12-03 13:30:32 -06:00
2014-01-03 06:42:33 -06:00
CAF_PDM_InitField ( & showFaultFaces , " ShowFaultFaces " , true , " Show defined faces " , " " , " " , " " ) ;
CAF_PDM_InitField ( & showOppositeFaultFaces , " ShowOppositeFaultFaces " , true , " Show opposite faces " , " " , " " , " " ) ;
2014-01-06 00:11:36 -06:00
CAF_PDM_InitField ( & showNNCs , " ShowNNCs " , false , " Show NNCs " , " " , " " , " " ) ;
2014-01-02 08:20:08 -06:00
CAF_PDM_InitField ( & showResultsOnFaults , " ShowResultsOnFaults " , true , " Show results on faults " , " " , " " , " " ) ;
2014-01-02 08:15:50 -06:00
CAF_PDM_InitField ( & showFaultsOutsideFilters , " ShowFaultsOutsideFilters " , false , " Show faults outside filters " , " " , " " , " " ) ;
2013-12-06 02:08:45 -06:00
2014-01-03 06:42:33 -06:00
CAF_PDM_InitField ( & faultResult , " FaultFaceCulling " , caf : : AppEnum < RimFaultCollection : : FaultFaceCullingMode > ( RimFaultCollection : : FAULT_FRONT_FACE_CULLING ) , " Dynamic Face Selection " , " " , " " , " " ) ;
2013-12-18 01:57:22 -06:00
2014-01-03 06:42:33 -06:00
CAF_PDM_InitField ( & showFaultLabel , " ShowFaultLabel " , false , " Show labels " , " " , " " , " " ) ;
2013-12-03 13:30:32 -06:00
cvf : : Color3f defWellLabelColor = RiaApplication : : instance ( ) - > preferences ( ) - > defaultWellLabelColor ( ) ;
2014-01-03 06:42:33 -06:00
CAF_PDM_InitField ( & faultLabelColor , " FaultLabelColor " , defWellLabelColor , " Label color " , " " , " " , " " ) ;
2013-12-03 13:30:32 -06:00
CAF_PDM_InitFieldNoDefault ( & faults , " Faults " , " Faults " , " " , " " , " " ) ;
m_reservoirView = NULL ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFaultCollection : : ~ RimFaultCollection ( )
{
faults . deleteAllChildObjects ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection : : fieldChangedByUi ( const caf : : PdmFieldHandle * changedField , const QVariant & oldValue , const QVariant & newValue )
{
if ( & showFaultCollection = = changedField )
{
this - > updateUiIconFromState ( showFaultCollection ) ;
}
2013-12-10 00:43:17 -06:00
if ( & faultLabelColor = = changedField )
{
m_reservoirView - > scheduleReservoirGridGeometryRegen ( ) ;
}
2013-12-06 02:08:45 -06:00
if ( & showGeometryDetectedFaults = = changedField | |
& showFaultFaces = = changedField | |
2013-12-06 12:39:55 -06:00
& showOppositeFaultFaces = = changedField | |
2013-12-16 04:29:48 -06:00
& showNNCs = = changedField | |
2013-12-06 12:39:55 -06:00
& showFaultCollection = = changedField | |
& showFaultLabel = = changedField | |
2014-01-02 08:15:50 -06:00
& showFaultsOutsideFilters = = changedField | |
2013-12-18 01:57:22 -06:00
& faultLabelColor = = changedField | |
2014-01-02 08:24:07 -06:00
& faultResult = = changedField | |
2014-01-02 08:20:08 -06:00
& showResultsOnFaults = = changedField
2013-12-18 01:57:22 -06:00
)
2013-12-03 13:30:32 -06:00
{
if ( m_reservoirView )
{
m_reservoirView - > scheduleCreateDisplayModelAndRedraw ( ) ;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 02:59:05 -06:00
2013-12-05 03:48:57 -06: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 ) ;
return ( compareValue < 0 ) ;
}
2013-12-05 02:59:05 -06:00
2013-12-04 05:13:01 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection : : syncronizeFaults ( )
{
if ( ! ( m_reservoirView & & m_reservoirView - > eclipseCase ( ) & & m_reservoirView - > eclipseCase ( ) - > reservoirData ( ) ) ) return ;
cvf : : ref < cvf : : Color3fArray > partColors = RivColorTableArray : : colorTableArray ( ) ;
2013-12-05 02:59:05 -06:00
const cvf : : Collection < RigFault > constRigFaults = m_reservoirView - > eclipseCase ( ) - > reservoirData ( ) - > mainGrid ( ) - > faults ( ) ;
cvf : : Collection < RigFault > rigFaults ( constRigFaults ) ;
2013-12-05 03:48:57 -06:00
std : : sort ( rigFaults . begin ( ) , rigFaults . end ( ) , faultComparator ) ;
2013-12-04 05:13:01 -06: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 02:40:39 -06:00
QString toolTip = QString ( " Fault count (%1) " ) . arg ( newFaults . size ( ) ) ;
setUiToolTip ( toolTip ) ;
2013-12-04 05:13:01 -06:00
}
2013-12-18 02:26:06 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFaultCollection : : isGridVisualizationMode ( ) const
{
CVF_ASSERT ( m_reservoirView ) ;
2013-12-18 16:37:30 -06:00
return m_reservoirView - > isGridVisualizationMode ( ) ;
2013-12-18 02:26:06 -06:00
}
2014-01-03 01:38:09 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultCollection : : defineUiOrdering ( QString uiConfigName , caf : : PdmUiOrdering & uiOrdering )
{
bool isGridVizMode = isGridVisualizationMode ( ) ;
faultResult . setUiReadOnly ( isGridVizMode ) ;
2014-01-03 06:42:33 -06:00
showFaultFaces . setUiReadOnly ( isGridVizMode ) ;
showOppositeFaultFaces . setUiReadOnly ( isGridVizMode ) ;
caf : : PdmUiGroup * ffviz = uiOrdering . addNewGroup ( " Fault Face Visibility " ) ;
ffviz - > add ( & showFaultFaces ) ;
ffviz - > add ( & showOppositeFaultFaces ) ;
ffviz - > add ( & showNNCs ) ;
ffviz - > add ( & faultResult ) ;
caf : : PdmUiGroup * labs = uiOrdering . addNewGroup ( " Fault Labels " ) ;
labs - > add ( & showFaultLabel ) ;
labs - > add ( & faultLabelColor ) ;
caf : : PdmUiGroup * adv = uiOrdering . addNewGroup ( " Advanced " ) ;
adv - > add ( & showFaultsOutsideFilters ) ;
adv - > add ( & showResultsOnFaults ) ;
2014-01-03 01:38:09 -06:00
}