From 733324634b4e9a38f44e5e3cbe85689c92480441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Tue, 27 Nov 2018 11:25:25 +0100 Subject: [PATCH] #3757, #3723 Split the RicPointTangentManipulator file into the different classes actually contained therein --- .../WellPathCommands/CMakeLists_files.cmake | 9 + .../RicPointTangentManipulator.cpp | 654 +----------------- .../RicPointTangentManipulator.h | 147 ---- .../RicPointTangentManipulatorPartMgr.cpp | 422 +++++++++++ .../RicPointTangentManipulatorPartMgr.h | 111 +++ .../RicWellPathGeometry3dEditor.cpp | 77 +++ .../RicWellPathGeometry3dEditor.h | 40 ++ .../RicWellTarget3dEditor.cpp | 204 ++++++ .../RicWellTarget3dEditor.h | 57 ++ .../RimWellPathGeometryDef.cpp | 2 +- 10 files changed, 925 insertions(+), 798 deletions(-) create mode 100644 ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulatorPartMgr.cpp create mode 100644 ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulatorPartMgr.h create mode 100644 ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp create mode 100644 ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h create mode 100644 ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellTarget3dEditor.cpp create mode 100644 ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellTarget3dEditor.h diff --git a/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake index 7af02e103f..b39937ff51 100644 --- a/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake @@ -16,6 +16,9 @@ ${CMAKE_CURRENT_LIST_DIR}/RicCreateWellTargetsPickEventHandler.h ${CMAKE_CURRENT_LIST_DIR}/RicIntersectionPickEventHandler.h ${CMAKE_CURRENT_LIST_DIR}/RicWellPathFormationsImportFileFeature.h ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulator.h +${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicWellTarget3dEditor.h +${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicWellPathGeometry3dEditor.h +${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulatorPartMgr.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -35,6 +38,9 @@ ${CMAKE_CURRENT_LIST_DIR}/RicCreateWellTargetsPickEventHandler.cpp ${CMAKE_CURRENT_LIST_DIR}/RicIntersectionPickEventHandler.cpp ${CMAKE_CURRENT_LIST_DIR}/RicWellPathFormationsImportFileFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulator.cpp +${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicWellTarget3dEditor.cpp +${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp +${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulatorPartMgr.cpp ) list(APPEND CODE_HEADER_FILES @@ -47,6 +53,9 @@ ${SOURCE_GROUP_SOURCE_FILES} list(APPEND QT_MOC_HEADERS ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulator.h +${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicWellTarget3dEditor.h +${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicWellPathGeometry3dEditor.h + ) source_group( "CommandFeature\\WellPath" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake ) diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.cpp b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.cpp index 8527080a7b..612717857f 100644 --- a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.cpp +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.cpp @@ -19,7 +19,11 @@ #include "RicPointTangentManipulator.h" +#include "RicPointTangentManipulatorPartMgr.h" +#include "RivPartPriority.h" + #include "cafViewer.h" +#include "cafPdmUiCommandSystemProxy.h" #include "cvfCamera.h" #include "cvfDrawableGeo.h" @@ -30,9 +34,6 @@ #include #include -#include "RivPartPriority.h" -#include "cafPdmUiCommandSystemProxy.h" -#include "RimModeledWellPath.h" //-------------------------------------------------------------------------------------------------- /// @@ -158,650 +159,3 @@ bool RicPointTangentManipulator::eventFilter(QObject *obj, QEvent* inputEvent) } - -//================================================================================================== -/// -/// -//================================================================================================== - - - -#include "RicPointTangentManipulator.h" - -#include "cafBoxManipulatorGeometryGenerator.h" -#include "cafEffectGenerator.h" -#include "cafLine.h" -#include "cafSelectionManager.h" - -#include "cvfBoxGenerator.h" -#include "cvfDrawableGeo.h" -#include "cvfGeometryBuilderFaceList.h" -#include "cvfModelBasicList.h" -#include "cvfPart.h" -#include "cvfPrimitiveSetIndexedUInt.h" -#include "cvfPrimitiveSetIndexedUShort.h" -#include "cvfRay.h" -#include "cvfPrimitiveSetDirect.h" -#include "cvfHitItem.h" -#include - -#include "cvfGeometryBuilderTriangles.h" -#include "cvfGeometryUtils.h" -// - - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RicPointTangentManipulatorPartMgr::RicPointTangentManipulatorPartMgr() - : m_tangentOnStartManipulation(cvf::Vec3d::UNDEFINED), - m_originOnStartManipulation(cvf::Vec3d::UNDEFINED), - m_currentHandleIndex(cvf::UNDEFINED_SIZE_T), - m_handleSize(1.0) -{ -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RicPointTangentManipulatorPartMgr::~RicPointTangentManipulatorPartMgr() -{ -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::setOrigin(const cvf::Vec3d& origin) -{ - if (isManipulatorActive()) return; - - m_origin = origin; - if (m_originOnStartManipulation.isUndefined()) m_originOnStartManipulation = origin; - - clearAllGeometryAndParts(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::setTangent(const cvf::Vec3d& tangent) -{ - if(isManipulatorActive()) return; - - m_tangent = tangent; - if (m_tangentOnStartManipulation.isUndefined()) m_tangentOnStartManipulation = m_tangent; - - clearAllGeometryAndParts(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::setHandleSize(double handleSize) -{ - m_handleSize = handleSize; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::originAndTangent(cvf::Vec3d* origin, cvf::Vec3d* tangent) -{ - *origin = m_origin; - *tangent = m_tangent; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RicPointTangentManipulatorPartMgr::isManipulatorActive() const -{ - return m_currentHandleIndex != cvf::UNDEFINED_SIZE_T; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::appendPartsToModel(cvf::ModelBasicList* model) -{ - if (!m_handleParts.size()) - { - recreateAllGeometryAndParts(); - } - - for (size_t i = 0; i < m_handleParts.size(); i++) - { - model->addPart(m_handleParts.at(i)); - } - - for (auto activeModePart: m_activeDragModeParts) - { - model->addPart(activeModePart.p()); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::tryToActivateManipulator(const cvf::HitItem* hitItem) -{ - endManipulator(); - - if (!hitItem) return; - - const cvf::Part* pickedPart = hitItem->part(); - const cvf::Vec3d intersectionPoint = hitItem->intersectionPoint(); - - if (!pickedPart) return; - - for (size_t i = 0; i < m_handleParts.size(); i++) - { - if (pickedPart == m_handleParts.at(i)) - { - m_initialPickPoint = intersectionPoint; - m_tangentOnStartManipulation = m_tangent; - m_originOnStartManipulation = m_origin; - m_currentHandleIndex = i; - } - } - -} - - -//-------------------------------------------------------------------------------------------------- -/// Calculate new origin and tangent based on the new ray position -/// Clear geometry to trigger regeneration -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::updateManipulatorFromRay(const cvf::Ray* newMouseRay) -{ - if (!isManipulatorActive()) return; - - if ( m_handleIds[m_currentHandleIndex] == HORIZONTAL_PLANE ) - { - cvf::Plane plane; - plane.setFromPointAndNormal(m_origin, cvf::Vec3d::Z_AXIS); - cvf::Vec3d newIntersection; - newMouseRay->planeIntersect(plane, &newIntersection); - - cvf::Vec3d newOrigin = m_originOnStartManipulation + (newIntersection - m_initialPickPoint); - - m_origin = newOrigin; - } - else if ( m_handleIds[m_currentHandleIndex] == VERTICAL_AXIS ) - { - cvf::Plane plane; - cvf::Vec3d planeNormal = (newMouseRay->direction() ^ cvf::Vec3d::Z_AXIS) ^ cvf::Vec3d::Z_AXIS; - double length = planeNormal.length(); - - if (length < 1e-5) return; - - planeNormal /= length; - plane.setFromPointAndNormal(m_initialPickPoint, planeNormal ); - cvf::Vec3d newIntersection; - newMouseRay->planeIntersect(plane, &newIntersection); - - cvf::Vec3d newOrigin = m_originOnStartManipulation; - newOrigin.z() += (newIntersection.z() - m_initialPickPoint.z()); - - m_origin = newOrigin; - } - //m_tangent = newTangent; - - clearAllGeometryAndParts(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::endManipulator() -{ - m_currentHandleIndex = cvf::UNDEFINED_SIZE_T; - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::clearAllGeometryAndParts() -{ - m_handleIds.clear(); - m_handleParts.clear(); - m_activeDragModeParts.clear(); -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::recreateAllGeometryAndParts() -{ - createAllHandleParts(); - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::createAllHandleParts() -{ - createHorizontalPlaneHandle(); - createVerticalAxisHandle(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::createHorizontalPlaneHandle() -{ - using namespace cvf; - cvf::ref vertexArray = new cvf::Vec3fArray(6); - - vertexArray->set(0, {-1, -1, 0} ); - vertexArray->set(1, { 1, -1, 0}); - vertexArray->set(2, { 1, 1, 0}); - vertexArray->set(3, {-1, -1, 0}); - vertexArray->set(4, { 1, 1, 0}); - vertexArray->set(5, {-1, 1, 0}); - - Vec3f origin(m_origin); - for (cvf::Vec3f& vx: *vertexArray) - { - vx *= 0.5*m_handleSize; - vx += origin; - } - - ref geo = createTriangelDrawableGeo(vertexArray.p()); - - HandleType handleId = HORIZONTAL_PLANE; - cvf::Color4f color = cvf::Color4f(1.0f, 0.0f, 1.0f, 0.5f); - cvf::String partName("PointTangentManipulator Horizontal Plane Handle"); - - addHandlePart(geo.p(), color, handleId, partName); -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::createVerticalAxisHandle() -{ - using namespace cvf; - - cvf::ref< cvf::GeometryBuilderTriangles> geomBuilder = new cvf::GeometryBuilderTriangles; - cvf::GeometryUtils::createBox({-0.3f, -0.3f, -1.0f}, { 0.3f, 0.3f, 1.0f}, geomBuilder.p()); - - cvf::ref vertexArray = geomBuilder->vertices(); - cvf::ref indexArray = geomBuilder->triangles(); - - Vec3f origin(m_origin); - for (cvf::Vec3f& vx: *vertexArray) - { - vx *= 0.5*m_handleSize; - vx += origin; - } - - ref geo = createIndexedTriangelDrawableGeo(vertexArray.p(), indexArray.p()); - - HandleType handleId = VERTICAL_AXIS; - cvf::Color4f color = cvf::Color4f(0.0f, 0.2f, 0.8f, 0.5f); - cvf::String partName("PointTangentManipulator Vertical Axis Handle"); - - addHandlePart(geo.p(), color, handleId, partName); -} - -#if 0 -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::createAzimuthHandle() -{ - using namespace cvf; - - cvf::ref< cvf::GeometryBuilderTriangles> geomBuilder = new cvf::GeometryBuilderTriangles; - cvf::GeometryUtils::createDisc(1.3, 1.1, 16, geomBuilder.p()); - - cvf::ref vertexArray = geomBuilder->vertices(); - cvf::ref indexArray = geomBuilder->triangles(); - - Vec3f origin(m_origin); - for (cvf::Vec3f& vx: *vertexArray) - { - vx *= 0.5*m_handleSize; - vx += origin; - } - - ref geo = createIndexedTriangelDrawableGeo(vertexArray.p(), indexArray.p()); - - HandleType handleId = AZIMUTH; - cvf::Color4f color = cvf::Color4f(0.0f, 0.2f, 0.8f, 0.5f); - cvf::String partName("PointTangentManipulator Azimuth Handle"); - - addHandlePart(geo.p(), color, handleId, partName); -} - -#endif - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::ref RicPointTangentManipulatorPartMgr::createIndexedTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray, - cvf::UIntArray* triangleIndices) -{ - using namespace cvf; - ref geo = new DrawableGeo; - ref primSet = new PrimitiveSetIndexedUInt(PT_TRIANGLES, triangleIndices); - - geo->setVertexArray(triangleVertexArray); - geo->addPrimitiveSet(primSet.p()); - geo->computeNormals(); - - return geo; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::ref RicPointTangentManipulatorPartMgr::createTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray) -{ - using namespace cvf; - ref geo = new DrawableGeo; - - geo->setVertexArray(triangleVertexArray); - ref primSet = new cvf::PrimitiveSetDirect(cvf::PT_TRIANGLES); - primSet->setIndexCount(triangleVertexArray->size()); - - geo->addPrimitiveSet(primSet.p()); - geo->computeNormals(); - - return geo; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::addHandlePart(cvf::DrawableGeo* geo, - const cvf::Color4f& color, - HandleType handleId, - const cvf::String& partName) -{ - cvf::ref handlePart = createPart(geo, color, partName); - - m_handleParts.push_back(handlePart.p()); - m_handleIds.push_back(handleId); -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicPointTangentManipulatorPartMgr::addActiveModePart(cvf::DrawableGeo* geo, - const cvf::Color4f& color, - HandleType handleId, - const cvf::String& partName) -{ - cvf::ref handlePart = createPart(geo, color, partName); - - m_activeDragModeParts.push_back(handlePart.p()); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::ref RicPointTangentManipulatorPartMgr::createPart(cvf::DrawableGeo* geo, - const cvf::Color4f& color, - const cvf::String& partName) -{ - cvf::ref part = new cvf::Part; - part->setName(partName); - part->setDrawable(geo); - part->updateBoundingBox(); - - caf::SurfaceEffectGenerator surfaceGen(color, caf::PO_1); - cvf::ref eff = surfaceGen.generateCachedEffect(); - part->setEffect(eff.p()); - if (color.a() < 1.0) part->setPriority(RivPartPriority::Transparent); - - return part; -} - - - - -//================================================================================================== -/// -/// -/// -//================================================================================================== - -#include "RimWellPathTarget.h" -#include "RimWellPathGeometryDef.h" - -CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicWellPathGeometry3dEditor); - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RicWellPathGeometry3dEditor::RicWellPathGeometry3dEditor() -{ - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RicWellPathGeometry3dEditor::~RicWellPathGeometry3dEditor() -{ - for (auto targetEditor: m_targetEditors) - { - delete targetEditor; - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicWellPathGeometry3dEditor::configureAndUpdateUi(const QString& uiConfigName) -{ - RimWellPathGeometryDef* geomDef = dynamic_cast(this->pdmObject()); - - for (auto targetEditor: m_targetEditors) - { - delete targetEditor; - } - m_targetEditors.clear(); - - if (!geomDef) return; - - - std::vector targets = geomDef->activeWellTargets(); - - for (auto target: targets) - { - auto targetEditor = new RicWellTarget3dEditor; - targetEditor->setViewer(ownerViewer()); - targetEditor->setPdmObject(target); - m_targetEditors.push_back(targetEditor); - targetEditor->updateUi(); - } -} - -//================================================================================================== -/// -/// -/// -//================================================================================================== - - -#include "RimWellPathTarget.h" -#include "RiuViewer.h" -#include "cafDisplayCoordTransform.h" -#include "Rim3dView.h" -#include "RimCase.h" - -CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicWellTarget3dEditor); - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RicWellTarget3dEditor::RicWellTarget3dEditor() -{ - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RicWellTarget3dEditor::~RicWellTarget3dEditor() -{ - RiuViewer* ownerRiuViewer = dynamic_cast(ownerViewer()); - - if (m_cvfModel.notNull() && ownerRiuViewer) - { - - // Could result in some circularities .... - ownerRiuViewer->removeStaticModel(m_cvfModel.p()); - } - - RimWellPathTarget* oldTarget = dynamic_cast(this->pdmObject()); - if (oldTarget) - { - oldTarget->m_targetType.uiCapability()->removeFieldEditor(this); - oldTarget->m_targetPoint.uiCapability()->removeFieldEditor(this); - oldTarget->m_azimuth.uiCapability()->removeFieldEditor(this); - oldTarget->m_inclination.uiCapability()->removeFieldEditor(this); - } - - delete m_manipulator; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicWellTarget3dEditor::configureAndUpdateUi(const QString& uiConfigName) -{ - RimWellPathTarget* target = dynamic_cast(this->pdmObject()); - RiuViewer* ownerRiuViewer = dynamic_cast(ownerViewer()); - - if ( !target || !target->isEnabled()) - { - m_cvfModel->removeAllParts(); - return; - } - - RimWellPathGeometryDef* geomDef; - target->firstAncestorOrThisOfTypeAsserted(geomDef); - - target->m_targetType.uiCapability()->addFieldEditor(this); - target->m_targetPoint.uiCapability()->addFieldEditor(this); - target->m_azimuth.uiCapability()->addFieldEditor(this); - target->m_inclination.uiCapability()->addFieldEditor(this); - - if (m_manipulator.isNull()) - { - m_manipulator = new RicPointTangentManipulator(ownerRiuViewer); - QObject::connect(m_manipulator, - SIGNAL( notifyUpdate(const cvf::Vec3d& , const cvf::Vec3d& ) ), - this, - SLOT( slotUpdated(const cvf::Vec3d& , const cvf::Vec3d& ) ) ); - QObject::connect(m_manipulator, - SIGNAL( notifySelected() ), - this, - SLOT( slotSelectedIn3D() ) ); - QObject::connect(m_manipulator, - SIGNAL( notifyDragFinished() ), - this, - SLOT( slotDragFinished() ) ); - m_cvfModel = new cvf::ModelBasicList; - ownerRiuViewer->addStaticModelOnce(m_cvfModel.p()); - } - - cvf::ref dispXf; - double handleSize = 1.0; - { - dispXf = ownerRiuViewer->ownerReservoirView()->displayCoordTransform(); - Rim3dView* view = dynamic_cast(ownerRiuViewer->ownerReservoirView()); - handleSize = 0.7 * view->ownerCase()->characteristicCellSize(); - } - - m_manipulator->setOrigin(dispXf->transformToDisplayCoord( target->targetPointXYZ() + geomDef->referencePointXyz())); - m_manipulator->setTangent(target->tangent()); - m_manipulator->setHandleSize(handleSize); - m_cvfModel->removeAllParts(); - m_manipulator->appendPartsToModel(m_cvfModel.p()); - - m_cvfModel->updateBoundingBoxesRecursive(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicWellTarget3dEditor::cleanupBeforeSettingPdmObject() -{ - RimWellPathTarget* oldTarget = dynamic_cast(this->pdmObject()); - if (oldTarget) - { - oldTarget->m_targetType.uiCapability()->removeFieldEditor(this); - oldTarget->m_targetPoint.uiCapability()->removeFieldEditor(this); - oldTarget->m_azimuth.uiCapability()->removeFieldEditor(this); - oldTarget->m_inclination.uiCapability()->removeFieldEditor(this); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicWellTarget3dEditor::slotUpdated(const cvf::Vec3d& origin, const cvf::Vec3d& tangent) -{ - RimWellPathTarget* target = dynamic_cast(this->pdmObject()); - - if ( !target) - { - return; - } - - cvf::ref dispXf; - { - RiuViewer* viewer = dynamic_cast(ownerViewer()); - dispXf = viewer->ownerReservoirView()->displayCoordTransform(); - } - - RimWellPathGeometryDef* geomDef; - target->firstAncestorOrThisOfTypeAsserted(geomDef); - - cvf::Vec3d domainOrigin = dispXf->transformToDomainCoord( origin) - geomDef->referencePointXyz(); - domainOrigin.z() = -domainOrigin.z(); - QVariant originVariant = caf::PdmValueFieldSpecialization < cvf::Vec3d >::convert(domainOrigin); - - target->enableFullUpdate(false); - caf::PdmUiCommandSystemProxy::instance()->setUiValueToField(target->m_targetPoint.uiCapability(), originVariant); - target->enableFullUpdate(true); -} - -void RicWellTarget3dEditor::slotSelectedIn3D() -{ - RimWellPathTarget* target = dynamic_cast(this->pdmObject()); - if ( !target) - { - return; - } - - caf::SelectionManager::instance()->setSelectedItemAtLevel(target, caf::SelectionManager::FIRST_LEVEL); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicWellTarget3dEditor::slotDragFinished() -{ - RimWellPathTarget* target = dynamic_cast(this->pdmObject()); - if ( !target) - { - return; - } - - RimModeledWellPath* wellpath; - target->firstAncestorOrThisOfTypeAsserted(wellpath); - wellpath->scheduleUpdateOfDependentVisualization(); -} diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h index 326a9711f8..e1875d9a53 100644 --- a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h @@ -72,150 +72,3 @@ private: cvf::ref m_partManager; }; - -#pragma once - -#include "cvfBase.h" -#include "cvfObject.h" - -#include "cvfVector3.h" -#include "cvfCollection.h" -#include "cvfMatrix4.h" -#include "cvfString.h" -#include "cvfColor4.h" - -namespace cvf -{ -class ModelBasicList; -class Part; -class DrawableGeo; -class Ray; -class HitItem; - -template class Array; -typedef Array Vec3fArray; -typedef Array UIntArray; - -} - -class RicPointTangentManipulatorPartMgr : public cvf::Object -{ -public: - enum HandleType - { - HORIZONTAL_PLANE, - VERTICAL_AXIS, - AZIMUTH, - INCLINATION - }; - -public: - RicPointTangentManipulatorPartMgr(); - ~RicPointTangentManipulatorPartMgr() override; - - void setOrigin(const cvf::Vec3d& origin); - void setTangent(const cvf::Vec3d& tangent); - void setHandleSize(double handleSize); - void originAndTangent(cvf::Vec3d* origin, cvf::Vec3d* tangent); - - bool isManipulatorActive() const; - void tryToActivateManipulator(const cvf::HitItem* hitItem); - void updateManipulatorFromRay(const cvf::Ray* ray); - void endManipulator(); - - void appendPartsToModel(cvf::ModelBasicList* model); - -private: - void createAllHandleParts(); - void clearAllGeometryAndParts(); - void recreateAllGeometryAndParts(); - - void createHorizontalPlaneHandle(); - void createVerticalAxisHandle(); - - void addHandlePart(cvf::DrawableGeo* geo, - const cvf::Color4f& color, - HandleType handleId, - const cvf::String& partName); - - void addActiveModePart(cvf::DrawableGeo* geo, - const cvf::Color4f& color, - HandleType handleId, - const cvf::String& partName); - - static cvf::ref createTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray); - static cvf::ref createIndexedTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray, - cvf::UIntArray* triangleIndices); - static cvf::ref createPart(cvf::DrawableGeo* geo, - const cvf::Color4f& color, - const cvf::String& partName); -private: - size_t m_currentHandleIndex; - std::vector< HandleType > m_handleIds; // These arrays have the same length - cvf::Collection m_handleParts; // These arrays have the same length - cvf::Collection m_activeDragModeParts; - - cvf::Vec3d m_origin; - cvf::Vec3d m_tangent; - double m_handleSize; - - cvf::Vec3d m_initialPickPoint; - cvf::Vec3d m_tangentOnStartManipulation; - cvf::Vec3d m_originOnStartManipulation; - -}; - - -//================================================================================================== -/// -/// -/// -//================================================================================================== -#include "cafPdmUi3dObjectEditorHandle.h" - -class RicWellTarget3dEditor; - -class RicWellPathGeometry3dEditor : public caf::PdmUi3dObjectEditorHandle -{ - CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT; - Q_OBJECT -public: - RicWellPathGeometry3dEditor(); - ~RicWellPathGeometry3dEditor() override; - -protected: - void configureAndUpdateUi(const QString& uiConfigName) override; - -private: - - std::vector m_targetEditors; -}; - -//================================================================================================== -/// -/// -/// -//================================================================================================== -#include "cafPdmUi3dObjectEditorHandle.h" - - -class RicWellTarget3dEditor : public caf::PdmUi3dObjectEditorHandle -{ - CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT; - Q_OBJECT -public: - RicWellTarget3dEditor(); - ~RicWellTarget3dEditor() override; - -protected: - void configureAndUpdateUi(const QString& uiConfigName) override; - void cleanupBeforeSettingPdmObject() override; - -private slots: - void slotUpdated(const cvf::Vec3d& origin, const cvf::Vec3d& tangent); - void slotSelectedIn3D(); - void slotDragFinished(); -private: - QPointer m_manipulator; - cvf::ref m_cvfModel; -}; diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulatorPartMgr.cpp b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulatorPartMgr.cpp new file mode 100644 index 0000000000..1ec4c34306 --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulatorPartMgr.cpp @@ -0,0 +1,422 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- equinor ASA +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicPointTangentManipulatorPartMgr.h" + +#include "RivPartPriority.h" + +#include "cafEffectGenerator.h" +#include "cafLine.h" +#include "cafSelectionManager.h" + +#include "cvfBoxGenerator.h" +#include "cvfDrawableGeo.h" +#include "cvfGeometryBuilderFaceList.h" +#include "cvfModelBasicList.h" +#include "cvfPart.h" +#include "cvfPrimitiveSetIndexedUInt.h" +#include "cvfRay.h" +#include "cvfPlane.h" +#include "cvfPrimitiveSetDirect.h" +#include "cvfHitItem.h" + +#include "cvfGeometryBuilderTriangles.h" +#include "cvfGeometryUtils.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicPointTangentManipulatorPartMgr::RicPointTangentManipulatorPartMgr() + : m_tangentOnStartManipulation(cvf::Vec3d::UNDEFINED), + m_originOnStartManipulation(cvf::Vec3d::UNDEFINED), + m_currentHandleIndex(cvf::UNDEFINED_SIZE_T), + m_handleSize(1.0) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicPointTangentManipulatorPartMgr::~RicPointTangentManipulatorPartMgr() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::setOrigin(const cvf::Vec3d& origin) +{ + if (isManipulatorActive()) return; + + m_origin = origin; + if (m_originOnStartManipulation.isUndefined()) m_originOnStartManipulation = origin; + + clearAllGeometryAndParts(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::setTangent(const cvf::Vec3d& tangent) +{ + if(isManipulatorActive()) return; + + m_tangent = tangent; + if (m_tangentOnStartManipulation.isUndefined()) m_tangentOnStartManipulation = m_tangent; + + clearAllGeometryAndParts(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::setHandleSize(double handleSize) +{ + m_handleSize = handleSize; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::originAndTangent(cvf::Vec3d* origin, cvf::Vec3d* tangent) +{ + *origin = m_origin; + *tangent = m_tangent; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicPointTangentManipulatorPartMgr::isManipulatorActive() const +{ + return m_currentHandleIndex != cvf::UNDEFINED_SIZE_T; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::appendPartsToModel(cvf::ModelBasicList* model) +{ + if (!m_handleParts.size()) + { + recreateAllGeometryAndParts(); + } + + for (size_t i = 0; i < m_handleParts.size(); i++) + { + model->addPart(m_handleParts.at(i)); + } + + for (auto activeModePart: m_activeDragModeParts) + { + model->addPart(activeModePart.p()); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::tryToActivateManipulator(const cvf::HitItem* hitItem) +{ + endManipulator(); + + if (!hitItem) return; + + const cvf::Part* pickedPart = hitItem->part(); + const cvf::Vec3d intersectionPoint = hitItem->intersectionPoint(); + + if (!pickedPart) return; + + for (size_t i = 0; i < m_handleParts.size(); i++) + { + if (pickedPart == m_handleParts.at(i)) + { + m_initialPickPoint = intersectionPoint; + m_tangentOnStartManipulation = m_tangent; + m_originOnStartManipulation = m_origin; + m_currentHandleIndex = i; + } + } + +} + + +//-------------------------------------------------------------------------------------------------- +/// Calculate new origin and tangent based on the new ray position +/// Clear geometry to trigger regeneration +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::updateManipulatorFromRay(const cvf::Ray* newMouseRay) +{ + if (!isManipulatorActive()) return; + + if ( m_handleIds[m_currentHandleIndex] == HORIZONTAL_PLANE ) + { + cvf::Plane plane; + plane.setFromPointAndNormal(m_origin, cvf::Vec3d::Z_AXIS); + cvf::Vec3d newIntersection; + newMouseRay->planeIntersect(plane, &newIntersection); + + cvf::Vec3d newOrigin = m_originOnStartManipulation + (newIntersection - m_initialPickPoint); + + m_origin = newOrigin; + } + else if ( m_handleIds[m_currentHandleIndex] == VERTICAL_AXIS ) + { + cvf::Plane plane; + cvf::Vec3d planeNormal = (newMouseRay->direction() ^ cvf::Vec3d::Z_AXIS) ^ cvf::Vec3d::Z_AXIS; + double length = planeNormal.length(); + + if (length < 1e-5) return; + + planeNormal /= length; + plane.setFromPointAndNormal(m_initialPickPoint, planeNormal ); + cvf::Vec3d newIntersection; + newMouseRay->planeIntersect(plane, &newIntersection); + + cvf::Vec3d newOrigin = m_originOnStartManipulation; + newOrigin.z() += (newIntersection.z() - m_initialPickPoint.z()); + + m_origin = newOrigin; + } + //m_tangent = newTangent; + + clearAllGeometryAndParts(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::endManipulator() +{ + m_currentHandleIndex = cvf::UNDEFINED_SIZE_T; + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::clearAllGeometryAndParts() +{ + m_handleIds.clear(); + m_handleParts.clear(); + m_activeDragModeParts.clear(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::recreateAllGeometryAndParts() +{ + createAllHandleParts(); + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::createAllHandleParts() +{ + createHorizontalPlaneHandle(); + createVerticalAxisHandle(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::createHorizontalPlaneHandle() +{ + using namespace cvf; + cvf::ref vertexArray = new cvf::Vec3fArray(6); + + vertexArray->set(0, {-1, -1, 0} ); + vertexArray->set(1, { 1, -1, 0}); + vertexArray->set(2, { 1, 1, 0}); + vertexArray->set(3, {-1, -1, 0}); + vertexArray->set(4, { 1, 1, 0}); + vertexArray->set(5, {-1, 1, 0}); + + Vec3f origin(m_origin); + for (cvf::Vec3f& vx: *vertexArray) + { + vx *= 0.5*m_handleSize; + vx += origin; + } + + ref geo = createTriangelDrawableGeo(vertexArray.p()); + + HandleType handleId = HORIZONTAL_PLANE; + cvf::Color4f color = cvf::Color4f(1.0f, 0.0f, 1.0f, 0.5f); + cvf::String partName("PointTangentManipulator Horizontal Plane Handle"); + + addHandlePart(geo.p(), color, handleId, partName); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::createVerticalAxisHandle() +{ + using namespace cvf; + + cvf::ref< cvf::GeometryBuilderTriangles> geomBuilder = new cvf::GeometryBuilderTriangles; + cvf::GeometryUtils::createBox({-0.3f, -0.3f, -1.0f}, { 0.3f, 0.3f, 1.0f}, geomBuilder.p()); + + cvf::ref vertexArray = geomBuilder->vertices(); + cvf::ref indexArray = geomBuilder->triangles(); + + Vec3f origin(m_origin); + for (cvf::Vec3f& vx: *vertexArray) + { + vx *= 0.5*m_handleSize; + vx += origin; + } + + ref geo = createIndexedTriangelDrawableGeo(vertexArray.p(), indexArray.p()); + + HandleType handleId = VERTICAL_AXIS; + cvf::Color4f color = cvf::Color4f(0.0f, 0.2f, 0.8f, 0.5f); + cvf::String partName("PointTangentManipulator Vertical Axis Handle"); + + addHandlePart(geo.p(), color, handleId, partName); +} + +#if 0 +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::createAzimuthHandle() +{ + using namespace cvf; + + cvf::ref< cvf::GeometryBuilderTriangles> geomBuilder = new cvf::GeometryBuilderTriangles; + cvf::GeometryUtils::createDisc(1.3, 1.1, 16, geomBuilder.p()); + + cvf::ref vertexArray = geomBuilder->vertices(); + cvf::ref indexArray = geomBuilder->triangles(); + + Vec3f origin(m_origin); + for (cvf::Vec3f& vx: *vertexArray) + { + vx *= 0.5*m_handleSize; + vx += origin; + } + + ref geo = createIndexedTriangelDrawableGeo(vertexArray.p(), indexArray.p()); + + HandleType handleId = AZIMUTH; + cvf::Color4f color = cvf::Color4f(0.0f, 0.2f, 0.8f, 0.5f); + cvf::String partName("PointTangentManipulator Azimuth Handle"); + + addHandlePart(geo.p(), color, handleId, partName); +} + +#endif + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RicPointTangentManipulatorPartMgr::createIndexedTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray, + cvf::UIntArray* triangleIndices) +{ + using namespace cvf; + ref geo = new DrawableGeo; + ref primSet = new PrimitiveSetIndexedUInt(PT_TRIANGLES, triangleIndices); + + geo->setVertexArray(triangleVertexArray); + geo->addPrimitiveSet(primSet.p()); + geo->computeNormals(); + + return geo; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RicPointTangentManipulatorPartMgr::createTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray) +{ + using namespace cvf; + ref geo = new DrawableGeo; + + geo->setVertexArray(triangleVertexArray); + ref primSet = new cvf::PrimitiveSetDirect(cvf::PT_TRIANGLES); + primSet->setIndexCount(triangleVertexArray->size()); + + geo->addPrimitiveSet(primSet.p()); + geo->computeNormals(); + + return geo; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::addHandlePart(cvf::DrawableGeo* geo, + const cvf::Color4f& color, + HandleType handleId, + const cvf::String& partName) +{ + cvf::ref handlePart = createPart(geo, color, partName); + + m_handleParts.push_back(handlePart.p()); + m_handleIds.push_back(handleId); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPointTangentManipulatorPartMgr::addActiveModePart(cvf::DrawableGeo* geo, + const cvf::Color4f& color, + HandleType handleId, + const cvf::String& partName) +{ + cvf::ref handlePart = createPart(geo, color, partName); + + m_activeDragModeParts.push_back(handlePart.p()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RicPointTangentManipulatorPartMgr::createPart(cvf::DrawableGeo* geo, + const cvf::Color4f& color, + const cvf::String& partName) +{ + cvf::ref part = new cvf::Part; + part->setName(partName); + part->setDrawable(geo); + part->updateBoundingBox(); + + caf::SurfaceEffectGenerator surfaceGen(color, caf::PO_1); + cvf::ref eff = surfaceGen.generateCachedEffect(); + part->setEffect(eff.p()); + if (color.a() < 1.0) part->setPriority(RivPartPriority::Transparent); + + return part; +} + + + + + + diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulatorPartMgr.h b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulatorPartMgr.h new file mode 100644 index 0000000000..42a0a373b7 --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulatorPartMgr.h @@ -0,0 +1,111 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- equinor ASA +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cvfBase.h" +#include "cvfObject.h" + +#include "cvfVector3.h" +#include "cvfCollection.h" +#include "cvfMatrix4.h" +#include "cvfColor4.h" + +namespace cvf +{ + +class ModelBasicList; +class Part; +class DrawableGeo; +class Ray; +class HitItem; +class String; + +template class Array; +typedef Array Vec3fArray; +typedef Array UIntArray; + +} + +class RicPointTangentManipulatorPartMgr : public cvf::Object +{ +public: + enum HandleType + { + HORIZONTAL_PLANE, + VERTICAL_AXIS, + AZIMUTH, + INCLINATION + }; + +public: + RicPointTangentManipulatorPartMgr(); + ~RicPointTangentManipulatorPartMgr() override; + + void setOrigin(const cvf::Vec3d& origin); + void setTangent(const cvf::Vec3d& tangent); + void setHandleSize(double handleSize); + void originAndTangent(cvf::Vec3d* origin, cvf::Vec3d* tangent); + + bool isManipulatorActive() const; + void tryToActivateManipulator(const cvf::HitItem* hitItem); + void updateManipulatorFromRay(const cvf::Ray* ray); + void endManipulator(); + + void appendPartsToModel(cvf::ModelBasicList* model); + +private: + void createAllHandleParts(); + void clearAllGeometryAndParts(); + void recreateAllGeometryAndParts(); + + void createHorizontalPlaneHandle(); + void createVerticalAxisHandle(); + + void addHandlePart(cvf::DrawableGeo* geo, + const cvf::Color4f& color, + HandleType handleId, + const cvf::String& partName); + + void addActiveModePart(cvf::DrawableGeo* geo, + const cvf::Color4f& color, + HandleType handleId, + const cvf::String& partName); + + static cvf::ref createTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray); + static cvf::ref createIndexedTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray, + cvf::UIntArray* triangleIndices); + static cvf::ref createPart(cvf::DrawableGeo* geo, + const cvf::Color4f& color, + const cvf::String& partName); +private: + size_t m_currentHandleIndex; + std::vector< HandleType > m_handleIds; // These arrays have the same length + cvf::Collection m_handleParts; // These arrays have the same length + cvf::Collection m_activeDragModeParts; + cvf::Vec3d m_origin; + cvf::Vec3d m_tangent; + double m_handleSize; + cvf::Vec3d m_initialPickPoint; + cvf::Vec3d m_tangentOnStartManipulation; + cvf::Vec3d m_originOnStartManipulation; + +}; + + + diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp new file mode 100644 index 0000000000..830db0b8ce --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp @@ -0,0 +1,77 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- equinor ASA +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicWellPathGeometry3dEditor.h" + +#include "RicWellPathGeometry3dEditor.h" +#include "RicWellTarget3dEditor.h" + +#include "RimWellPathTarget.h" +#include "RimWellPathGeometryDef.h" + + +CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicWellPathGeometry3dEditor); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicWellPathGeometry3dEditor::RicWellPathGeometry3dEditor() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicWellPathGeometry3dEditor::~RicWellPathGeometry3dEditor() +{ + for (auto targetEditor: m_targetEditors) + { + delete targetEditor; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicWellPathGeometry3dEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + RimWellPathGeometryDef* geomDef = dynamic_cast(this->pdmObject()); + + for (auto targetEditor: m_targetEditors) + { + delete targetEditor; + } + m_targetEditors.clear(); + + if (!geomDef) return; + + + std::vector targets = geomDef->activeWellTargets(); + + for (auto target: targets) + { + auto targetEditor = new RicWellTarget3dEditor; + targetEditor->setViewer(ownerViewer()); + targetEditor->setPdmObject(target); + m_targetEditors.push_back(targetEditor); + targetEditor->updateUi(); + } +} + + diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h new file mode 100644 index 0000000000..8b85ed99cb --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h @@ -0,0 +1,40 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- equinor ASA +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once +#include "cafPdmUi3dObjectEditorHandle.h" + +class RicWellTarget3dEditor; + +class RicWellPathGeometry3dEditor : public caf::PdmUi3dObjectEditorHandle +{ + CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT; + Q_OBJECT +public: + RicWellPathGeometry3dEditor(); + ~RicWellPathGeometry3dEditor() override; + +protected: + void configureAndUpdateUi(const QString& uiConfigName) override; + +private: + + std::vector m_targetEditors; +}; + + diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellTarget3dEditor.cpp b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellTarget3dEditor.cpp new file mode 100644 index 0000000000..dcea5f1e18 --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellTarget3dEditor.cpp @@ -0,0 +1,204 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- equinor ASA +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicWellTarget3dEditor.h" + +#include "RicPointTangentManipulator.h" + +#include "RimWellPathTarget.h" +#include "Rim3dView.h" +#include "RimCase.h" +#include "RimModeledWellPath.h" +#include "RimWellPathGeometryDef.h" + +#include "RiuViewer.h" + +#include "cafDisplayCoordTransform.h" +#include "cafPdmUiCommandSystemProxy.h" +#include "cafSelectionManager.h" + +#include "cvfPart.h" +#include "cvfModelBasicList.h" + +CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicWellTarget3dEditor); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicWellTarget3dEditor::RicWellTarget3dEditor() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicWellTarget3dEditor::~RicWellTarget3dEditor() +{ + RiuViewer* ownerRiuViewer = dynamic_cast(ownerViewer()); + + if (m_cvfModel.notNull() && ownerRiuViewer) + { + + // Could result in some circularities .... + ownerRiuViewer->removeStaticModel(m_cvfModel.p()); + } + + RimWellPathTarget* oldTarget = dynamic_cast(this->pdmObject()); + if (oldTarget) + { + oldTarget->m_targetType.uiCapability()->removeFieldEditor(this); + oldTarget->m_targetPoint.uiCapability()->removeFieldEditor(this); + oldTarget->m_azimuth.uiCapability()->removeFieldEditor(this); + oldTarget->m_inclination.uiCapability()->removeFieldEditor(this); + } + + delete m_manipulator; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicWellTarget3dEditor::configureAndUpdateUi(const QString& uiConfigName) +{ + RimWellPathTarget* target = dynamic_cast(this->pdmObject()); + RiuViewer* ownerRiuViewer = dynamic_cast(ownerViewer()); + + if ( !target || !target->isEnabled()) + { + m_cvfModel->removeAllParts(); + return; + } + + RimWellPathGeometryDef* geomDef; + target->firstAncestorOrThisOfTypeAsserted(geomDef); + + target->m_targetType.uiCapability()->addFieldEditor(this); + target->m_targetPoint.uiCapability()->addFieldEditor(this); + target->m_azimuth.uiCapability()->addFieldEditor(this); + target->m_inclination.uiCapability()->addFieldEditor(this); + + if (m_manipulator.isNull()) + { + m_manipulator = new RicPointTangentManipulator(ownerRiuViewer); + QObject::connect(m_manipulator, + SIGNAL( notifyUpdate(const cvf::Vec3d& , const cvf::Vec3d& ) ), + this, + SLOT( slotUpdated(const cvf::Vec3d& , const cvf::Vec3d& ) ) ); + QObject::connect(m_manipulator, + SIGNAL( notifySelected() ), + this, + SLOT( slotSelectedIn3D() ) ); + QObject::connect(m_manipulator, + SIGNAL( notifyDragFinished() ), + this, + SLOT( slotDragFinished() ) ); + m_cvfModel = new cvf::ModelBasicList; + ownerRiuViewer->addStaticModelOnce(m_cvfModel.p()); + } + + cvf::ref dispXf; + double handleSize = 1.0; + { + dispXf = ownerRiuViewer->ownerReservoirView()->displayCoordTransform(); + Rim3dView* view = dynamic_cast(ownerRiuViewer->ownerReservoirView()); + handleSize = 0.7 * view->ownerCase()->characteristicCellSize(); + } + + m_manipulator->setOrigin(dispXf->transformToDisplayCoord( target->targetPointXYZ() + geomDef->referencePointXyz())); + m_manipulator->setTangent(target->tangent()); + m_manipulator->setHandleSize(handleSize); + m_cvfModel->removeAllParts(); + m_manipulator->appendPartsToModel(m_cvfModel.p()); + + m_cvfModel->updateBoundingBoxesRecursive(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicWellTarget3dEditor::cleanupBeforeSettingPdmObject() +{ + RimWellPathTarget* oldTarget = dynamic_cast(this->pdmObject()); + if (oldTarget) + { + oldTarget->m_targetType.uiCapability()->removeFieldEditor(this); + oldTarget->m_targetPoint.uiCapability()->removeFieldEditor(this); + oldTarget->m_azimuth.uiCapability()->removeFieldEditor(this); + oldTarget->m_inclination.uiCapability()->removeFieldEditor(this); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicWellTarget3dEditor::slotUpdated(const cvf::Vec3d& origin, const cvf::Vec3d& tangent) +{ + RimWellPathTarget* target = dynamic_cast(this->pdmObject()); + + if ( !target) + { + return; + } + + cvf::ref dispXf; + { + RiuViewer* viewer = dynamic_cast(ownerViewer()); + dispXf = viewer->ownerReservoirView()->displayCoordTransform(); + } + + RimWellPathGeometryDef* geomDef; + target->firstAncestorOrThisOfTypeAsserted(geomDef); + + cvf::Vec3d domainOrigin = dispXf->transformToDomainCoord( origin) - geomDef->referencePointXyz(); + domainOrigin.z() = -domainOrigin.z(); + QVariant originVariant = caf::PdmValueFieldSpecialization < cvf::Vec3d >::convert(domainOrigin); + + target->enableFullUpdate(false); + caf::PdmUiCommandSystemProxy::instance()->setUiValueToField(target->m_targetPoint.uiCapability(), originVariant); + target->enableFullUpdate(true); +} + +void RicWellTarget3dEditor::slotSelectedIn3D() +{ + RimWellPathTarget* target = dynamic_cast(this->pdmObject()); + if ( !target) + { + return; + } + + caf::SelectionManager::instance()->setSelectedItemAtLevel(target, caf::SelectionManager::FIRST_LEVEL); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicWellTarget3dEditor::slotDragFinished() +{ + RimWellPathTarget* target = dynamic_cast(this->pdmObject()); + if ( !target) + { + return; + } + + RimModeledWellPath* wellpath; + target->firstAncestorOrThisOfTypeAsserted(wellpath); + wellpath->scheduleUpdateOfDependentVisualization(); +} + + diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellTarget3dEditor.h b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellTarget3dEditor.h new file mode 100644 index 0000000000..b618acc533 --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellTarget3dEditor.h @@ -0,0 +1,57 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- equinor ASA +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmUi3dObjectEditorHandle.h" + +class RicPointTangentManipulator; + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cvfVector3.h" + +namespace cvf { +class ModelBasicList; +} + +class QString; +#include + +class RicWellTarget3dEditor : public caf::PdmUi3dObjectEditorHandle +{ + CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT; + Q_OBJECT +public: + RicWellTarget3dEditor(); + ~RicWellTarget3dEditor() override; + +protected: + void configureAndUpdateUi(const QString& uiConfigName) override; + void cleanupBeforeSettingPdmObject() override; + +private slots: + void slotUpdated(const cvf::Vec3d& origin, const cvf::Vec3d& tangent); + void slotSelectedIn3D(); + void slotDragFinished(); +private: + QPointer m_manipulator; + cvf::ref m_cvfModel; +}; + + diff --git a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp index 6cc5df78b7..1296b3b22e 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp @@ -38,7 +38,7 @@ #include "cafPdmUiTableViewEditor.h" #include "cafPdmUiTreeOrdering.h" #include "cvfGeometryTools.h" -#include "WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h" +#include "WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h" namespace caf