2017-05-05 04:21:40 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
2017-05-16 05:49:36 -05:00
// Copyright (C) 2017 Statoil ASA
2017-05-05 04:21:40 -05: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 "RicNewFishbonesSubsFeature.h"
2017-06-07 04:57:25 -05:00
# include "WellPathCommands/RicWellPathsUnitSystemSettingsImpl.h"
2017-05-20 13:21:19 -05:00
# include "RiaApplication.h"
2017-12-22 02:52:56 -06:00
# include "RigWellPath.h"
2017-05-31 09:16:28 -05:00
# include "RimProject.h"
2017-05-20 13:21:19 -05:00
# include "RimFishboneWellPathCollection.h"
2017-05-19 08:44:32 -05:00
# include "RimFishbonesCollection.h"
2017-05-20 13:21:19 -05:00
# include "RimFishbonesMultipleSubs.h"
2018-01-09 03:11:28 -06:00
# include "Rim3dView.h"
2017-05-20 13:21:19 -05:00
# include "RimWellPathCollection.h"
2017-05-05 04:21:40 -05:00
# include "RiuMainWindow.h"
# include "cafSelectionManager.h"
# include <QAction>
2017-05-20 13:21:19 -05:00
# include <QMessageBox>
2017-05-05 04:21:40 -05:00
2017-09-29 10:56:41 -05:00
# include <cmath>
2017-05-05 04:21:40 -05:00
CAF_CMD_SOURCE_INIT ( RicNewFishbonesSubsFeature , " RicNewFishbonesSubsFeature " ) ;
2017-12-22 02:52:56 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double getWellPathTipMd ( RimWellPath * wellPath ) ;
2017-05-05 04:21:40 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewFishbonesSubsFeature : : onActionTriggered ( bool isChecked )
{
2017-05-20 07:47:13 -05:00
RimFishbonesCollection * fishbonesCollection = selectedFishbonesCollection ( ) ;
CVF_ASSERT ( fishbonesCollection ) ;
2017-05-05 04:21:40 -05:00
2017-06-07 04:57:25 -05:00
RimWellPath * wellPath ;
fishbonesCollection - > firstAncestorOrThisOfTypeAsserted ( wellPath ) ;
if ( ! RicWellPathsUnitSystemSettingsImpl : : ensureHasUnitSystem ( wellPath ) ) return ;
2017-05-05 04:21:40 -05:00
RimFishbonesMultipleSubs * obj = new RimFishbonesMultipleSubs ;
2017-05-23 02:35:17 -05:00
fishbonesCollection - > appendFishbonesSubs ( obj ) ;
2017-05-05 04:21:40 -05:00
2017-12-22 02:52:56 -06:00
double wellPathTipMd = getWellPathTipMd ( wellPath ) ;
2017-12-22 04:18:37 -06:00
if ( wellPathTipMd ! = HUGE_VAL )
2017-12-22 02:52:56 -06:00
{
2017-12-22 04:18:37 -06:00
double startMd = wellPathTipMd - 150 - 100 ;
if ( startMd < 100 ) startMd = 100 ;
obj - > setMeasuredDepthAndCount ( startMd , 12.5 , 13 ) ;
2017-12-22 02:52:56 -06:00
}
2017-05-20 13:21:19 -05:00
RicNewFishbonesSubsFeature : : askUserToSetUsefulScaling ( fishbonesCollection ) ;
2017-06-16 08:36:59 -05:00
RimWellPathCollection * wellPathCollection = nullptr ;
fishbonesCollection - > firstAncestorOrThisOfType ( wellPathCollection ) ;
if ( wellPathCollection )
{
wellPathCollection - > uiCapability ( ) - > updateConnectedEditors ( ) ;
}
2017-05-05 04:21:40 -05:00
RiuMainWindow : : instance ( ) - > selectAsCurrentItem ( obj ) ;
2017-05-31 09:16:28 -05:00
RimProject * proj ;
fishbonesCollection - > firstAncestorOrThisOfTypeAsserted ( proj ) ;
2017-06-02 03:35:52 -05:00
proj - > reloadCompletionTypeResultsInAllViews ( ) ;
2017-05-05 04:21:40 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-05-20 07:47:13 -05:00
RimFishbonesCollection * RicNewFishbonesSubsFeature : : selectedFishbonesCollection ( )
2017-05-05 04:21:40 -05:00
{
2017-05-20 07:47:13 -05:00
RimFishbonesCollection * objToFind = nullptr ;
2017-05-05 04:21:40 -05:00
caf : : PdmUiItem * pdmUiItem = caf : : SelectionManager : : instance ( ) - > selectedItem ( ) ;
caf : : PdmObjectHandle * objHandle = dynamic_cast < caf : : PdmObjectHandle * > ( pdmUiItem ) ;
if ( objHandle )
{
2017-05-20 07:47:13 -05:00
objHandle - > firstAncestorOrThisOfType ( objToFind ) ;
2017-05-05 04:21:40 -05:00
}
2017-06-16 08:36:59 -05:00
if ( objToFind = = nullptr )
{
std : : vector < RimWellPath * > wellPaths ;
caf : : SelectionManager : : instance ( ) - > objectsByType ( & wellPaths ) ;
if ( ! wellPaths . empty ( ) )
{
return wellPaths [ 0 ] - > fishbonesCollection ( ) ;
}
}
2017-05-20 07:47:13 -05:00
return objToFind ;
2017-05-05 04:21:40 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewFishbonesSubsFeature : : setupActionLook ( QAction * actionToSetup )
{
2017-06-05 04:12:13 -05:00
actionToSetup - > setIcon ( QIcon ( " :/FishBoneGroup16x16.png " ) ) ;
2018-05-08 09:59:29 -05:00
actionToSetup - > setText ( " New Fishbones " ) ;
2017-05-05 04:21:40 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewFishbonesSubsFeature : : isCommandEnabled ( )
{
2017-05-20 07:47:13 -05:00
if ( selectedFishbonesCollection ( ) )
2017-05-05 04:21:40 -05:00
{
return true ;
}
return false ;
}
2017-05-20 13:21:19 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewFishbonesSubsFeature : : askUserToSetUsefulScaling ( RimFishbonesCollection * fishboneCollection )
{
// Always reset well path collection scale factor
CVF_ASSERT ( fishboneCollection ) ;
RimWellPathCollection * wellPathColl = nullptr ;
fishboneCollection - > firstAncestorOrThisOfTypeAsserted ( wellPathColl ) ;
wellPathColl - > wellPathRadiusScaleFactor = 0.01 ;
2018-01-09 03:11:28 -06:00
Rim3dView * activeView = RiaApplication : : instance ( ) - > activeReservoirView ( ) ;
2017-05-20 13:21:19 -05:00
if ( ! activeView ) return ;
RiaApplication * app = RiaApplication : : instance ( ) ;
QString sessionKey = " AutoAdjustSettingsForFishbones " ;
bool autoAdjustSettings = false ;
QVariant v = app - > cacheDataObject ( sessionKey ) ;
if ( ! v . isValid ( ) )
{
double currentScaleFactor = activeView - > scaleZ ( ) ;
if ( fabs ( currentScaleFactor - 1.0 ) < 0.1 ) return ;
QMessageBox msgBox ;
msgBox . setIcon ( QMessageBox : : Question ) ;
QString questionText ;
questionText = QString ( " When displaying Fishbones structures, the view scaling should be set to 1. \n \n Do you want ResInsight to automatically set view scaling to 1? " ) ;
msgBox . setText ( questionText ) ;
msgBox . setStandardButtons ( QMessageBox : : Yes | QMessageBox : : No ) ;
int ret = msgBox . exec ( ) ;
if ( ret = = QMessageBox : : Yes )
{
autoAdjustSettings = true ;
}
app - > setCacheDataObject ( sessionKey , autoAdjustSettings ) ;
}
else
{
autoAdjustSettings = v . toBool ( ) ;
}
if ( autoAdjustSettings )
{
activeView - > setScaleZAndUpdate ( 1.0 ) ;
2017-06-21 10:13:19 -05:00
activeView - > scheduleCreateDisplayModelAndRedraw ( ) ;
2018-12-10 06:03:53 -06:00
activeView - > updateZScaleLabel ( ) ;
2017-05-20 13:21:19 -05:00
RiuMainWindow : : instance ( ) - > updateScaleValue ( ) ;
}
}
2017-12-22 02:52:56 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double getWellPathTipMd ( RimWellPath * wellPath )
{
RigWellPath * geometry = wellPath ? wellPath - > wellPathGeometry ( ) : nullptr ;
if ( geometry & & ! geometry - > m_measuredDepths . empty ( ) )
{
return geometry - > m_measuredDepths . back ( ) ;
}
2017-12-22 04:18:37 -06:00
return HUGE_VAL ;
2017-12-22 02:52:56 -06:00
}