Major rewrite of MSW export model

This commit is contained in:
Magne Sjaastad
2021-04-13 07:22:56 +02:00
parent 9ecfefe094
commit 63690d5196
65 changed files with 2766 additions and 2225 deletions

View File

@@ -15,6 +15,7 @@
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicNewWellPathLateralAtDepthFeature.h"
#include "WellPathCommands/RicWellPathsUnitSystemSettingsImpl.h"
@@ -23,12 +24,11 @@
#include "RimFishbones.h"
#include "RimFishbonesCollection.h"
#include "RimModeledWellPath.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimTools.h"
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RimWellPathGeometryDef.h"
#include "RimWellPathGroup.h"
#include "RimWellPathTarget.h"
#include "Riu3DMainWindowTools.h"
@@ -38,6 +38,7 @@
#include <QAction>
#include "RiaTextStringTools.h"
#include <cmath>
CAF_CMD_SOURCE_INIT( RicNewWellPathLateralAtDepthFeature, "RicNewWellPathLateralAtDepthFeature" );
@@ -63,56 +64,44 @@ void RicNewWellPathLateralAtDepthFeature::onActionTriggered( bool isChecked )
RiuWellPathSelectionItem* wellPathSelItem = wellPathSelectionItem();
CVF_ASSERT( wellPathSelItem );
RimWellPath* wellPath = wellPathSelItem->m_wellpath;
CVF_ASSERT( wellPath );
RimWellPathGroup* wellPathGroup = nullptr;
wellPath->firstAncestorOrThisOfType( wellPathGroup );
RimWellPath* parentWellPath = wellPathSelItem->m_wellpath;
CVF_ASSERT( parentWellPath );
RimProject* project = RimProject::current();
if ( project && RimProject::current()->activeOilField() )
RimProject* project = RimProject::current();
RimWellPathCollection* wellPathColl = RimTools::wellPathCollection();
if ( project && wellPathColl )
{
RimWellPathCollection* wellPathCollection = RimProject::current()->activeOilField()->wellPathCollection();
double parentWellMD = wellPathSelItem->m_measuredDepth;
if ( wellPathCollection )
{
auto newModeledWellPath = new RimModeledWellPath();
auto newModeledWellPath = new RimModeledWellPath();
auto [pointVector, measuredDepths] =
wellPath->wellPathGeometry()->clippedPointSubset( wellPath->wellPathGeometry()->measuredDepths().front(),
wellPathSelItem->m_measuredDepth );
if ( pointVector.size() < 2u ) return;
newModeledWellPath->geometryDefinition()->setMdAtFirstTarget( measuredDepths.back() );
newModeledWellPath->geometryDefinition()->setUseAutoGeneratedTargetAtSeaLevel( false );
newModeledWellPath->geometryDefinition()->setFixedWellPathPoints( pointVector );
newModeledWellPath->geometryDefinition()->setFixedMeasuredDepths( measuredDepths );
newModeledWellPath->setName( wellPath->name() + QString( " md=%1" ).arg( wellPathSelItem->m_measuredDepth ) );
auto [pointVector, measuredDepths] =
parentWellPath->wellPathGeometry()
->clippedPointSubset( parentWellPath->wellPathGeometry()->measuredDepths().front(), parentWellMD );
if ( pointVector.size() < 2u ) return;
{
RimWellPathTarget* newTarget = newModeledWellPath->geometryDefinition()->appendTarget();
auto lastPoint = pointVector.back();
auto tangent = lastPoint - pointVector[pointVector.size() - 2];
newTarget->setAsPointXYZAndTangentTarget( { lastPoint[0], lastPoint[1], lastPoint[2] }, tangent );
}
newModeledWellPath->geometryDefinition()->setIsAttachedToParentWell( true );
newModeledWellPath->geometryDefinition()->setMdAtFirstTarget( measuredDepths.back() );
newModeledWellPath->geometryDefinition()->setUseAutoGeneratedTargetAtSeaLevel( false );
newModeledWellPath->geometryDefinition()->setFixedWellPathPoints( pointVector );
newModeledWellPath->geometryDefinition()->setFixedMeasuredDepths( measuredDepths );
newModeledWellPath->geometryDefinition()->enableTargetPointPicking( true );
auto nameOfNewWell = updateNameOfParentAndFindNameOfSideStep( parentWellPath );
newModeledWellPath->setName( nameOfNewWell );
newModeledWellPath->connectWellPaths( parentWellPath, parentWellMD );
newModeledWellPath->createWellPathGeometry();
if ( wellPathGroup )
{
wellPathGroup->addChildWellPath( newModeledWellPath );
}
else
{
bool importedWellPath = false;
wellPathCollection->addWellPath( newModeledWellPath, importedWellPath );
wellPathCollection->groupWellPaths( { wellPath, newModeledWellPath } );
}
newModeledWellPath->firstAncestorOrThisOfTypeAsserted( wellPathGroup );
wellPathGroup->updateAllRequiredEditors();
project->scheduleCreateDisplayModelAndRedrawAllViews();
newModeledWellPath->geometryDefinition()->enableTargetPointPicking( true );
newModeledWellPath->setUnitSystem( parentWellPath->unitSystem() );
Riu3DMainWindowTools::selectAsCurrentItem( newModeledWellPath->geometryDefinition() );
}
newModeledWellPath->createWellPathGeometry();
bool importGrouped = false;
wellPathColl->addWellPath( newModeledWellPath, importGrouped );
wellPathColl->updateAllRequiredEditors();
project->scheduleCreateDisplayModelAndRedrawAllViews();
Riu3DMainWindowTools::selectAsCurrentItem( newModeledWellPath->geometryDefinition() );
}
}
@@ -137,3 +126,76 @@ RiuWellPathSelectionItem* RicNewWellPathLateralAtDepthFeature::wellPathSelection
return wellPathItem;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicNewWellPathLateralAtDepthFeature::updateNameOfParentAndFindNameOfSideStep( RimWellPath* parentwWellPath )
{
if ( !parentwWellPath ) return "";
QString nameOfNewWell;
auto topLevelWell = parentwWellPath->topLevelWellPath();
QStringList allNames;
{
RimProject* proj = RimProject::current();
const std::vector<RimWellPath*>& wellPaths = proj->allWellPaths();
for ( auto wellPath : wellPaths )
{
if ( wellPath )
{
auto currentTopLevelWell = wellPath->topLevelWellPath();
if ( topLevelWell == currentTopLevelWell )
{
allNames.push_back( wellPath->name() );
}
}
}
}
if ( allNames.size() == 1 )
{
QString name = parentwWellPath->name();
if ( name.contains( "Y1" ) )
{
nameOfNewWell = name.replace( "Y1", "Y2" );
}
else
{
parentwWellPath->setNameNoUpdateOfExportName( name + " Y1" );
nameOfNewWell = name + " Y2";
}
return nameOfNewWell;
}
{
QString commonRoot = RiaTextStringTools::commonRoot( allNames );
QString trimmedCommonRoot = RiaTextStringTools::trimNonAlphaNumericCharacters( commonRoot );
// Remove side step prefix
trimmedCommonRoot.replace( " Y", "" );
int maxYValue = 0;
for ( auto n : allNames )
{
auto suffix = n.replace( trimmedCommonRoot, "" );
int candidate = suffix.toInt();
maxYValue = std::max( maxYValue, candidate );
}
if ( !trimmedCommonRoot.isEmpty() && trimmedCommonRoot.endsWith( "Y" ) )
{
trimmedCommonRoot = trimmedCommonRoot.left( trimmedCommonRoot.size() - 1 ).trimmed();
}
nameOfNewWell = QString( "%1 Y%2" ).arg( trimmedCommonRoot ).arg( maxYValue + 1 );
}
return nameOfNewWell;
}