|
| 1 | +///////////////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// Copyright (C) 2024 Equinor ASA |
| 4 | +// |
| 5 | +// ResInsight is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | +// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +// FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | +// |
| 14 | +// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> |
| 15 | +// for more details. |
| 16 | +// |
| 17 | +///////////////////////////////////////////////////////////////////////////////// |
| 18 | + |
| 19 | +#include "RicSetParentWellPathFeature.h" |
| 20 | + |
| 21 | +#include "RigWellPath.h" |
| 22 | + |
| 23 | +#include "RimTools.h" |
| 24 | +#include "RimWellPath.h" |
| 25 | +#include "RimWellPathCollection.h" |
| 26 | +#include "RimWellPathTieIn.h" |
| 27 | + |
| 28 | +#include "RiuMainWindow.h" |
| 29 | + |
| 30 | +#include "cafPdmUiPropertyViewDialog.h" |
| 31 | +#include "cafSelectionManager.h" |
| 32 | + |
| 33 | +#include <QAction> |
| 34 | + |
| 35 | +CAF_PDM_SOURCE_INIT( RicSelectWellPathUi, "RicSelectWellPathUi" ); |
| 36 | + |
| 37 | +//-------------------------------------------------------------------------------------------------- |
| 38 | +/// |
| 39 | +//-------------------------------------------------------------------------------------------------- |
| 40 | +RicSelectWellPathUi::RicSelectWellPathUi() |
| 41 | +{ |
| 42 | + CAF_PDM_InitObject( "RicSelectWellPathUi" ); |
| 43 | + |
| 44 | + CAF_PDM_InitFieldNoDefault( &m_selectedWellPath, "SelectedWellPath", "Well Path" ); |
| 45 | +} |
| 46 | + |
| 47 | +//-------------------------------------------------------------------------------------------------- |
| 48 | +/// |
| 49 | +//-------------------------------------------------------------------------------------------------- |
| 50 | +void RicSelectWellPathUi::setWellPaths( const std::vector<RimWellPath*>& wellPaths ) |
| 51 | +{ |
| 52 | + m_wellPaths = wellPaths; |
| 53 | +} |
| 54 | + |
| 55 | +//-------------------------------------------------------------------------------------------------- |
| 56 | +/// |
| 57 | +//-------------------------------------------------------------------------------------------------- |
| 58 | +void RicSelectWellPathUi::setSelectedWell( RimWellPath* selectedWell ) |
| 59 | +{ |
| 60 | + m_selectedWellPath = selectedWell; |
| 61 | +} |
| 62 | + |
| 63 | +//-------------------------------------------------------------------------------------------------- |
| 64 | +/// |
| 65 | +//-------------------------------------------------------------------------------------------------- |
| 66 | +RimWellPath* RicSelectWellPathUi::wellPath() const |
| 67 | +{ |
| 68 | + return m_selectedWellPath(); |
| 69 | +} |
| 70 | + |
| 71 | +//-------------------------------------------------------------------------------------------------- |
| 72 | +/// |
| 73 | +//-------------------------------------------------------------------------------------------------- |
| 74 | +QList<caf::PdmOptionItemInfo> RicSelectWellPathUi::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) |
| 75 | +{ |
| 76 | + QList<caf::PdmOptionItemInfo> options; |
| 77 | + |
| 78 | + options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) ); |
| 79 | + |
| 80 | + RimTools::optionItemsForSpecifiedWellPaths( m_wellPaths, &options ); |
| 81 | + return options; |
| 82 | +} |
| 83 | + |
| 84 | +CAF_CMD_SOURCE_INIT( RicSetParentWellPathFeature, "RicSetParentWellPathFeature" ); |
| 85 | + |
| 86 | +//-------------------------------------------------------------------------------------------------- |
| 87 | +/// |
| 88 | +//-------------------------------------------------------------------------------------------------- |
| 89 | +void RicSetParentWellPathFeature::onActionTriggered( bool isChecked ) |
| 90 | +{ |
| 91 | + auto selectedWellPath = caf::SelectionManager::instance()->selectedItemOfType<RimWellPath>(); |
| 92 | + if ( !selectedWellPath ) return; |
| 93 | + |
| 94 | + auto wpc = RimTools::wellPathCollection(); |
| 95 | + if ( !wpc ) return; |
| 96 | + |
| 97 | + std::vector<RimWellPath*> wellPathCandidates; |
| 98 | + for ( auto w : wpc->allWellPaths() ) |
| 99 | + { |
| 100 | + if ( w != selectedWellPath ) wellPathCandidates.push_back( w ); |
| 101 | + } |
| 102 | + |
| 103 | + RicSelectWellPathUi ui; |
| 104 | + ui.setWellPaths( wellPathCandidates ); |
| 105 | + |
| 106 | + RimWellPath* parentWell = nullptr; |
| 107 | + if ( selectedWellPath->wellPathTieIn() ) parentWell = selectedWellPath->wellPathTieIn()->parentWell(); |
| 108 | + ui.setSelectedWell( parentWell ); |
| 109 | + |
| 110 | + caf::PdmUiPropertyViewDialog propertyDialog( nullptr, &ui, "Select Parent Well", "" ); |
| 111 | + propertyDialog.resize( QSize( 400, 200 ) ); |
| 112 | + |
| 113 | + if ( propertyDialog.exec() == QDialog::Accepted ) |
| 114 | + { |
| 115 | + auto parentWellPath = ui.wellPath(); |
| 116 | + |
| 117 | + double tieInMeasuredDepth = 0.0; |
| 118 | + if ( parentWellPath ) |
| 119 | + { |
| 120 | + if ( !parentWellPath->wellPathGeometry() || parentWellPath->wellPathGeometry()->measuredDepths().size() < 2 ) return; |
| 121 | + if ( selectedWellPath->wellPathGeometry()->wellPathPoints().empty() ) return; |
| 122 | + |
| 123 | + auto headOfLateral = selectedWellPath->wellPathGeometry()->wellPathPoints().front(); |
| 124 | + |
| 125 | + cvf::Vec3d p1, p2; |
| 126 | + parentWellPath->wellPathGeometry()->twoClosestPoints( headOfLateral, &p1, &p2 ); |
| 127 | + |
| 128 | + tieInMeasuredDepth = parentWellPath->wellPathGeometry()->closestMeasuredDepth( p1 ); |
| 129 | + } |
| 130 | + |
| 131 | + selectedWellPath->connectWellPaths( parentWellPath, tieInMeasuredDepth ); |
| 132 | + |
| 133 | + wpc->rebuildWellPathNodes(); |
| 134 | + wpc->scheduleRedrawAffectedViews(); |
| 135 | + wpc->updateAllRequiredEditors(); |
| 136 | + |
| 137 | + RiuMainWindow::instance()->setExpanded( selectedWellPath ); |
| 138 | + RiuMainWindow::instance()->selectAsCurrentItem( selectedWellPath ); |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +//-------------------------------------------------------------------------------------------------- |
| 143 | +/// |
| 144 | +//-------------------------------------------------------------------------------------------------- |
| 145 | +void RicSetParentWellPathFeature::setupActionLook( QAction* actionToSetup ) |
| 146 | +{ |
| 147 | + actionToSetup->setText( "Set Parent Well Path" ); |
| 148 | + actionToSetup->setIcon( QIcon( ":/Well.svg" ) ); |
| 149 | +} |
0 commit comments