2018-11-27 11:25:25 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2019-01-09 15:21:38 +01:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2018-11-27 11:25:25 +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.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2018-11-27 11:25:25 +01:00
|
|
|
// 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.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-11-27 11:25:25 +01:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RicWellTarget3dEditor.h"
|
|
|
|
|
|
|
|
|
|
#include "RicPointTangentManipulator.h"
|
|
|
|
|
|
|
|
|
|
#include "Rim3dView.h"
|
|
|
|
|
#include "RimCase.h"
|
|
|
|
|
#include "RimModeledWellPath.h"
|
|
|
|
|
#include "RimWellPathGeometryDef.h"
|
2021-06-29 14:17:35 +02:00
|
|
|
#include "RimWellPathGeometryDefTools.h"
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "RimWellPathTarget.h"
|
2018-11-27 11:25:25 +01:00
|
|
|
|
|
|
|
|
#include "RiuViewer.h"
|
|
|
|
|
|
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
|
|
|
|
#include "cafPdmUiCommandSystemProxy.h"
|
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
|
|
#include "cvfModelBasicList.h"
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "cvfPart.h"
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT( RicWellTarget3dEditor );
|
2018-11-27 11:25:25 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-27 11:25:25 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 11:13:38 +01:00
|
|
|
RicWellTarget3dEditor::RicWellTarget3dEditor()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-11-27 11:25:25 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-27 11:25:25 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RicWellTarget3dEditor::~RicWellTarget3dEditor()
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
RiuViewer* ownerRiuViewer = dynamic_cast<RiuViewer*>( ownerViewer() );
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_cvfModel.notNull() && ownerRiuViewer )
|
2018-11-27 11:25:25 +01:00
|
|
|
{
|
|
|
|
|
// Could result in some circularities ....
|
2019-09-06 10:40:57 +02:00
|
|
|
ownerRiuViewer->removeStaticModel( m_cvfModel.p() );
|
2018-11-27 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-28 09:48:38 +02:00
|
|
|
removeAllFieldEditors();
|
2018-11-27 11:25:25 +01:00
|
|
|
|
|
|
|
|
delete m_manipulator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-27 11:25:25 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicWellTarget3dEditor::configureAndUpdateUi( const QString& uiConfigName )
|
2018-11-27 11:25:25 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
RimWellPathTarget* target = dynamic_cast<RimWellPathTarget*>( this->pdmObject() );
|
|
|
|
|
RiuViewer* ownerRiuViewer = dynamic_cast<RiuViewer*>( ownerViewer() );
|
2019-11-06 14:04:42 +01:00
|
|
|
Rim3dView* view = mainOrComparisonView();
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2019-11-06 14:04:42 +01:00
|
|
|
if ( !target || !target->isEnabled() || !view )
|
2018-11-27 11:25:25 +01:00
|
|
|
{
|
2019-11-06 14:04:42 +01:00
|
|
|
if ( m_cvfModel.notNull() ) m_cvfModel->removeAllParts();
|
|
|
|
|
|
2018-11-27 11:25:25 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 14:27:59 +01:00
|
|
|
RimWellPathGeometryDef* geomDef;
|
2019-09-06 10:40:57 +02:00
|
|
|
target->firstAncestorOrThisOfTypeAsserted( geomDef );
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2021-06-28 09:48:38 +02:00
|
|
|
for ( auto field : target->fieldsFor3dManipulator() )
|
|
|
|
|
{
|
|
|
|
|
field->uiCapability()->addFieldEditor( this );
|
|
|
|
|
}
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_manipulator.isNull() )
|
2018-11-27 11:25:25 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
m_manipulator = new RicPointTangentManipulator( ownerRiuViewer );
|
2019-11-06 11:08:20 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
QObject::connect( m_manipulator,
|
|
|
|
|
SIGNAL( notifyUpdate( const cvf::Vec3d&, const cvf::Vec3d& ) ),
|
|
|
|
|
this,
|
|
|
|
|
SLOT( slotUpdated( const cvf::Vec3d&, const cvf::Vec3d& ) ) );
|
2019-11-06 11:08:20 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
QObject::connect( m_manipulator, SIGNAL( notifySelected() ), this, SLOT( slotSelectedIn3D() ) );
|
|
|
|
|
QObject::connect( m_manipulator, SIGNAL( notifyDragFinished() ), this, SLOT( slotDragFinished() ) );
|
2019-11-06 11:08:20 +01:00
|
|
|
|
2018-11-27 11:25:25 +01:00
|
|
|
m_cvfModel = new cvf::ModelBasicList;
|
2019-11-06 14:04:42 +01:00
|
|
|
ownerRiuViewer->addStaticModelOnce( m_cvfModel.p(), isInComparisonView() );
|
2018-11-27 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-06 14:04:42 +01:00
|
|
|
cvf::ref<caf::DisplayCoordTransform> dispXf = view->displayCoordTransform();
|
|
|
|
|
double handleSize = 0.7 * view->ownerCase()->characteristicCellSize();
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2021-01-04 11:09:01 +01:00
|
|
|
m_manipulator->setOrigin( dispXf->transformToDisplayCoord( target->targetPointXYZ() + geomDef->anchorPointXyz() ) );
|
2019-09-06 10:40:57 +02:00
|
|
|
m_manipulator->setTangent( target->tangent() );
|
|
|
|
|
m_manipulator->setHandleSize( handleSize );
|
2019-11-06 11:08:20 +01:00
|
|
|
|
2018-11-27 11:25:25 +01:00
|
|
|
m_cvfModel->removeAllParts();
|
2019-09-06 10:40:57 +02:00
|
|
|
m_manipulator->appendPartsToModel( m_cvfModel.p() );
|
2018-11-27 11:25:25 +01:00
|
|
|
|
|
|
|
|
m_cvfModel->updateBoundingBoxesRecursive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-27 11:25:25 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RicWellTarget3dEditor::cleanupBeforeSettingPdmObject()
|
|
|
|
|
{
|
2021-06-28 09:48:38 +02:00
|
|
|
removeAllFieldEditors();
|
2018-11-27 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-27 11:25:25 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicWellTarget3dEditor::slotUpdated( const cvf::Vec3d& origin, const cvf::Vec3d& tangent )
|
2018-11-27 11:25:25 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
RimWellPathTarget* target = dynamic_cast<RimWellPathTarget*>( this->pdmObject() );
|
2019-11-06 14:04:42 +01:00
|
|
|
Rim3dView* view = mainOrComparisonView();
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2019-11-06 14:04:42 +01:00
|
|
|
if ( !target || !view )
|
2018-11-27 11:25:25 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 14:27:59 +01:00
|
|
|
RimWellPathGeometryDef* geomDef;
|
2019-09-06 10:40:57 +02:00
|
|
|
target->firstAncestorOrThisOfTypeAsserted( geomDef );
|
2021-06-28 09:48:38 +02:00
|
|
|
if ( !geomDef ) return;
|
|
|
|
|
|
2021-06-28 11:18:04 +02:00
|
|
|
if ( geomDef->useReferencePointFromTopLevelWell() )
|
|
|
|
|
{
|
|
|
|
|
RimModeledWellPath* modeledWellPath = nullptr;
|
|
|
|
|
geomDef->firstAncestorOfType( modeledWellPath );
|
|
|
|
|
if ( modeledWellPath )
|
|
|
|
|
{
|
|
|
|
|
auto topLevelWellPath = dynamic_cast<RimModeledWellPath*>( modeledWellPath->topLevelWellPath() );
|
|
|
|
|
if ( topLevelWellPath )
|
|
|
|
|
{
|
|
|
|
|
// Manipulate the reference point of top level well path
|
|
|
|
|
geomDef = topLevelWellPath->geometryDefinition();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 09:48:38 +02:00
|
|
|
cvf::ref<caf::DisplayCoordTransform> dispXf = view->displayCoordTransform();
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2021-06-28 09:48:38 +02:00
|
|
|
auto domainCoordXYZ = dispXf->transformToDomainCoord( origin );
|
2018-11-27 11:25:25 +01:00
|
|
|
|
2021-06-28 09:48:38 +02:00
|
|
|
// If CTRL is pressed, modify the reference point instead of the well path target
|
|
|
|
|
bool modifyReferencePoint = ( QApplication::keyboardModifiers() & Qt::ControlModifier );
|
|
|
|
|
if ( modifyReferencePoint )
|
|
|
|
|
{
|
|
|
|
|
auto relativePositionXYZ = domainCoordXYZ - geomDef->anchorPointXyz();
|
|
|
|
|
auto delta = target->targetPointXYZ() - relativePositionXYZ;
|
|
|
|
|
|
2021-06-29 14:17:35 +02:00
|
|
|
// Find all linked wells and update with delta change
|
|
|
|
|
|
|
|
|
|
std::vector<RimWellPathGeometryDef*> linkedWellPathGeoDefs;
|
|
|
|
|
if ( geomDef->isReferencePointUpdatesLinked() )
|
|
|
|
|
{
|
|
|
|
|
linkedWellPathGeoDefs = RimWellPathGeometryDefTools::linkedDefinitions();
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-06-28 09:48:38 +02:00
|
|
|
{
|
2021-06-29 14:17:35 +02:00
|
|
|
linkedWellPathGeoDefs.push_back( geomDef );
|
2021-06-28 09:48:38 +02:00
|
|
|
}
|
2021-06-29 14:17:35 +02:00
|
|
|
|
|
|
|
|
RimWellPathGeometryDefTools::updateLinkedGeometryDefinitions( linkedWellPathGeoDefs, delta );
|
2021-06-28 09:48:38 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cvf::Vec3d relativePositionXYD = domainCoordXYZ - geomDef->anchorPointXyz();
|
|
|
|
|
relativePositionXYD.z() = -relativePositionXYD.z();
|
|
|
|
|
|
|
|
|
|
target->updateFrom3DManipulator( relativePositionXYD );
|
|
|
|
|
}
|
2018-11-27 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-06 14:04:42 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-27 11:25:25 +01:00
|
|
|
void RicWellTarget3dEditor::slotSelectedIn3D()
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
RimWellPathTarget* target = dynamic_cast<RimWellPathTarget*>( this->pdmObject() );
|
|
|
|
|
if ( !target )
|
2018-11-27 11:25:25 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
caf::SelectionManager::instance()->setSelectedItemAtLevel( target, caf::SelectionManager::FIRST_LEVEL );
|
2018-11-27 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-27 11:25:25 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RicWellTarget3dEditor::slotDragFinished()
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
RimWellPathTarget* target = dynamic_cast<RimWellPathTarget*>( this->pdmObject() );
|
|
|
|
|
if ( !target )
|
2018-11-27 11:25:25 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 11:09:01 +01:00
|
|
|
target->onMoved();
|
2018-11-27 11:25:25 +01:00
|
|
|
}
|
2021-06-28 09:48:38 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RicWellTarget3dEditor::removeAllFieldEditors()
|
|
|
|
|
{
|
|
|
|
|
if ( RimWellPathTarget* oldTarget = dynamic_cast<RimWellPathTarget*>( this->pdmObject() ) )
|
|
|
|
|
{
|
|
|
|
|
for ( auto field : oldTarget->fieldsFor3dManipulator() )
|
|
|
|
|
{
|
|
|
|
|
field->uiCapability()->removeFieldEditor( this );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|