2012-05-18 09:45:23 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron 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.
//
/////////////////////////////////////////////////////////////////////////////////
2013-03-22 16:12:00 +01:00
#include "RiaStdInclude.h"
2012-05-18 09:45:23 +02:00
#include "cafAppEnum.h"
#include "cafPdmFieldCvfColor.h"
2013-03-22 16:58:44 +01:00
#include "RigSingleWellResultsData.h"
2012-05-18 09:45:23 +02:00
#include "RimWellCollection.h"
#include "RimWell.h"
#include "RimReservoirView.h"
namespace caf
{
template <>
void RimWellCollection :: WellVisibilityEnum :: setUp ()
{
2013-04-22 09:13:37 +02:00
addItem ( RimWellCollection :: PIPES_FORCE_ALL_OFF , "FORCE_ALL_OFF" , "All Off" );
addItem ( RimWellCollection :: PIPES_INDIVIDUALLY , "ALL_ON" , "Individual" );
addItem ( RimWellCollection :: PIPES_OPEN_IN_VISIBLE_CELLS , "OPEN_IN_VISIBLE_CELLS" , "Visible cells filtered" );
addItem ( RimWellCollection :: PIPES_FORCE_ALL_ON , "FORCE_ALL_ON" , "All On" );
}
}
namespace caf
{
template <>
void RimWellCollection :: WellCellsRangeFilterEnum :: setUp ()
{
addItem ( RimWellCollection :: RANGE_ADD_NONE , "FORCE_ALL_OFF" , "Off" );
addItem ( RimWellCollection :: RANGE_ADD_INDIVIDUAL , "ALL_ON" , "Individually" );
addItem ( RimWellCollection :: RANGE_ADD_ALL , "FORCE_ALL_ON" , "On" );
2012-05-18 09:45:23 +02:00
}
}
namespace caf
{
template <>
void RimWellCollection :: WellFenceEnum :: setUp ()
{
addItem ( RimWellCollection :: K_DIRECTION , "K_DIRECTION" , "K - Direction" );
addItem ( RimWellCollection :: J_DIRECTION , "J_DIRECTION" , "J - Direction" );
addItem ( RimWellCollection :: I_DIRECTION , "I_DIRECTION" , "I - Direction" );
setDefault ( RimWellCollection :: K_DIRECTION );
}
}
CAF_PDM_SOURCE_INIT ( RimWellCollection , "Wells" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellCollection :: RimWellCollection ()
{
CAF_PDM_InitObject ( "Wells" , ":/WellCollection.png" , "" , "" );
2013-04-25 09:07:29 +02:00
CAF_PDM_InitField ( & showWells , "ShowWells" , true , "Show well" , "" , "" , "" );
showWells . setUiHidden ( true );
2012-05-18 09:45:23 +02:00
CAF_PDM_InitField ( & showWellHead , "ShowWellHead" , true , "Show well heads" , "" , "" , "" );
2013-04-24 10:38:50 +02:00
CAF_PDM_InitField ( & showWellLabel , "ShowWellLabel" , true , "Show well labels" , "" , "" , "" );
CAF_PDM_InitField ( & wellHeadScaleFactor , "WellHeadScale" , 1.0 , "Well head scale" , "" , "" , "" );
2012-05-18 09:45:23 +02:00
2013-04-22 09:13:37 +02:00
CAF_PDM_InitField ( & wellPipeVisibility , "GlobalWellPipeVisibility" , WellVisibilityEnum ( PIPES_INDIVIDUALLY ), "Global well pipe visibility" , "" , "" , "" );
2012-06-26 16:10:41 +02:00
2013-04-24 10:38:50 +02:00
CAF_PDM_InitField ( & pipeRadiusScaleFactor , "WellPipeRadiusScale" , 0.1 , "Pipe radius scale" , "" , "" , "" );
2012-06-26 16:10:41 +02:00
CAF_PDM_InitField ( & pipeCrossSectionVertexCount , "WellPipeVertexCount" , 12 , "Pipe vertex count" , "" , "" , "" );
pipeCrossSectionVertexCount . setUiHidden ( true );
2012-05-18 09:45:23 +02:00
2013-04-22 09:13:37 +02:00
CAF_PDM_InitField ( & wellCellsToRangeFilterMode , "GlobalWellCellVisibility" , WellCellsRangeFilterEnum ( RANGE_ADD_NONE ), "Add cells to range filter" , "" , "" , "" );
2013-04-24 10:38:50 +02:00
CAF_PDM_InitField ( & showWellCellFences , "ShowWellFences" , false , "Use well fence" , "" , "" , "" );
CAF_PDM_InitField ( & wellCellFenceType , "DefaultWellFenceDirection" , WellFenceEnum ( K_DIRECTION ), "Well Fence direction" , "" , "" , "" );
2012-05-18 09:45:23 +02:00
CAF_PDM_InitField ( & wellCellTransparencyLevel , "WellCellTransparency" , 0.5 , "Well cell transparency" , "" , "" , "" );
2012-06-26 16:10:41 +02:00
CAF_PDM_InitField ( & isAutoDetectingBranches , "IsAutoDetectingBranches" , true , "Geometry based branch detection" , "" , "Toggle wether the well pipe visualization will try to detect when a part of the well \n is really a branch, and thus is starting from wellhead" , "" );
2012-05-18 09:45:23 +02:00
CAF_PDM_InitFieldNoDefault ( & wells , "Wells" , "Wells" , "" , "" , "" );
m_reservoirView = NULL ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellCollection ::~ RimWellCollection ()
{
2012-06-26 16:10:41 +02:00
wells . deleteAllChildObjects ();
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWell * RimWellCollection :: findWell ( QString name )
{
for ( size_t i = 0 ; i < this -> wells (). size (); ++ i )
{
if ( this -> wells ()[ i ] -> name () == name )
{
return this -> wells ()[ i ];
}
}
return NULL ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellCollection :: hasVisibleWellCells ()
{
2013-04-22 09:13:37 +02:00
if ( this -> wellCellsToRangeFilterMode () == RANGE_ADD_NONE ) return false ;
2012-05-18 09:45:23 +02:00
if ( this -> wells (). size () == 0 ) return false ;
bool hasCells = false ;
for ( size_t i = 0 ; ! hasCells && i < this -> wells (). size (); ++ i )
{
RimWell * well = this -> wells ()[ i ];
2013-04-22 09:13:37 +02:00
if ( well && well -> wellResults () && ( well -> showWellCells () || this -> wellCellsToRangeFilterMode () == RANGE_ADD_ALL ) )
2012-05-18 09:45:23 +02:00
{
for ( size_t tIdx = 0 ; ! hasCells && tIdx < well -> wellResults () -> m_wellCellsTimeSteps . size (); ++ tIdx )
{
const RigWellResultFrame & wellResultFrame = well -> wellResults () -> m_wellCellsTimeSteps [ tIdx ];
for ( size_t wsIdx = 0 ; ! hasCells && wsIdx < wellResultFrame . m_wellResultBranches . size (); ++ wsIdx )
{
if ( wellResultFrame . m_wellResultBranches [ wsIdx ]. m_wellCells . size () > 0 ) hasCells = true ;
}
}
}
}
if ( ! hasCells ) return false ;
2013-04-22 09:13:37 +02:00
if ( this -> wellCellsToRangeFilterMode () == RANGE_ADD_INDIVIDUAL || this -> wellCellsToRangeFilterMode () == RANGE_ADD_ALL ) return true ;
2012-05-18 09:45:23 +02:00
// Todo: Handle range filter intersection
return true ;
}
//--------------------------------------------------------------------------------------------------
/// Used to know if we need animation of timesteps due to the wells
//--------------------------------------------------------------------------------------------------
bool RimWellCollection :: hasVisibleWellPipes ()
{
2013-04-25 09:07:29 +02:00
if ( ! this -> showWells ()) return false ;
2013-04-22 09:13:37 +02:00
if ( this -> wellPipeVisibility () == PIPES_FORCE_ALL_OFF ) return false ;
2012-05-18 09:45:23 +02:00
if ( this -> wells (). size () == 0 ) return false ;
2013-04-22 09:13:37 +02:00
if ( this -> wellPipeVisibility () == PIPES_FORCE_ALL_ON ) return true ;
2012-05-18 09:45:23 +02:00
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellCollection :: fieldChangedByUi ( const caf :: PdmFieldHandle * changedField , const QVariant & oldValue , const QVariant & newValue )
{
2013-04-25 09:07:29 +02:00
if ( & showWellLabel == changedField || & showWells == changedField )
2012-05-18 09:45:23 +02:00
{
if ( m_reservoirView )
{
m_reservoirView -> createDisplayModelAndRedraw ();
}
}
2013-04-22 09:13:37 +02:00
if ( & wellCellsToRangeFilterMode == changedField )
2012-05-18 09:45:23 +02:00
{
if ( m_reservoirView )
{
m_reservoirView -> scheduleGeometryRegen ( RivReservoirViewPartMgr :: VISIBLE_WELL_CELLS );
m_reservoirView -> createDisplayModelAndRedraw ();
}
}
else if ( & showWellCellFences == changedField )
{
if ( m_reservoirView )
{
m_reservoirView -> scheduleGeometryRegen ( RivReservoirViewPartMgr :: VISIBLE_WELL_CELLS );
m_reservoirView -> createDisplayModelAndRedraw ();
}
}
else if ( & wellCellTransparencyLevel == changedField )
{
if ( m_reservoirView )
{
m_reservoirView -> createDisplayModelAndRedraw ();
}
}
else if ( & wellCellFenceType == changedField )
{
if ( m_reservoirView )
{
m_reservoirView -> scheduleGeometryRegen ( RivReservoirViewPartMgr :: VISIBLE_WELL_CELLS );
m_reservoirView -> createDisplayModelAndRedraw ();
}
}
else if ( & wellPipeVisibility == changedField )
{
if ( m_reservoirView )
{
m_reservoirView -> createDisplayModelAndRedraw ();
}
}
2012-06-26 16:10:41 +02:00
else if ( & pipeCrossSectionVertexCount == changedField
|| & pipeRadiusScaleFactor == changedField
|| & wellHeadScaleFactor == changedField
|| & showWellHead == changedField
|| & isAutoDetectingBranches == changedField )
2012-05-18 09:45:23 +02:00
{
if ( m_reservoirView )
{
m_reservoirView -> schedulePipeGeometryRegen ();
m_reservoirView -> createDisplayModelAndRedraw ();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellCollection :: setReservoirView ( RimReservoirView * ownerReservoirView )
{
m_reservoirView = ownerReservoirView ;
}
2013-04-24 10:38:50 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellCollection :: defineUiOrdering ( QString uiConfigName , caf :: PdmUiOrdering & uiOrdering )
{
caf :: PdmUiGroup * filterGroup = uiOrdering . addNewGroup ( "Range filter" );
filterGroup -> add ( & wellCellsToRangeFilterMode );
filterGroup -> add ( & showWellCellFences );
filterGroup -> add ( & wellCellFenceType );
caf :: PdmUiGroup * wellHeadGroup = uiOrdering . addNewGroup ( "Well head" );
wellHeadGroup -> add ( & showWellHead );
wellHeadGroup -> add ( & wellHeadScaleFactor );
wellHeadGroup -> add ( & showWellLabel );
caf :: PdmUiGroup * wellPipe = uiOrdering . addNewGroup ( "Well pipe" );
wellPipe -> add ( & wellPipeVisibility );
wellPipe -> add ( & pipeRadiusScaleFactor );
2013-04-25 06:33:37 +02:00
caf :: PdmUiGroup * advancedGroup = uiOrdering . addNewGroup ( "Advanced" );
advancedGroup -> add ( & wellCellTransparencyLevel );
advancedGroup -> add ( & isAutoDetectingBranches );
2013-04-24 10:38:50 +02:00
}
2013-04-25 09:07:29 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf :: PdmFieldHandle * RimWellCollection :: objectToggleField ()
{
return & showWells ;
}