///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017 Statoil 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 "RicWellPathExportCompletionDataFeature.h" #include "RicWellPathExportCompletionDataFeatureImpl.h" #include "RiaApplication.h" #include "RiaLogging.h" #include "ExportCommands/RicExportLgrFeature.h" #include "RicExportFeatureImpl.h" #include "RimDialogData.h" #include "RimFishbones.h" #include "RimPerforationInterval.h" #include "RimProject.h" #include "RimSimWellFracture.h" #include "RimSimWellInView.h" #include "RimSimWellInViewCollection.h" #include "RimWellPath.h" #include "RimWellPathCollection.h" #include "RimWellPathCompletions.h" #include "RimWellPathFracture.h" #include "RimWellPathValve.h" #include "Riu3DMainWindowTools.h" #include "cafPdmUiPropertyViewDialog.h" #include "cafSelectionManager.h" #include #include CAF_CMD_SOURCE_INIT( RicWellPathExportCompletionDataFeature, "RicWellPathExportCompletionDataFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicWellPathExportCompletionDataFeature::prepareExportSettingsAndExportCompletions( const QString& dialogTitle, const std::vector& wellPaths, const std::vector& simWells ) { RiaApplication* app = RiaApplication::instance(); RimProject* project = app->project(); QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallbackToProjectFolder( "COMPLETIONS" ); RicExportCompletionDataSettingsUi* exportSettings = project->dialogData()->exportCompletionData(); if ( wellPaths.empty() ) { exportSettings->showForSimWells(); } else { exportSettings->showForWellPath(); } if ( !exportSettings->caseToApply() ) { std::vector cases; app->project()->allCases( cases ); for ( auto c : cases ) { RimEclipseCase* eclipseCase = dynamic_cast( c ); if ( eclipseCase != nullptr ) { exportSettings->caseToApply = eclipseCase; break; } } } if ( exportSettings->folder().isEmpty() ) exportSettings->folder = defaultDir; std::vector simWellFractures; std::vector wellPathFractures; std::vector wellPathFishbones; std::vector wellPathPerforations; for ( auto s : simWells ) { auto fratures = s->descendantsIncludingThisOfType(); simWellFractures.insert( simWellFractures.end(), fratures.begin(), fratures.end() ); } std::vector topLevelWells; { std::set myWells; for ( auto w : wellPaths ) { myWells.insert( w->topLevelWellPath() ); } topLevelWells.assign( myWells.begin(), myWells.end() ); } std::vector allLaterals; { std::set lateralSet; for ( auto t : topLevelWells ) { auto laterals = t->allWellPathLaterals(); for ( auto l : laterals ) { lateralSet.insert( l ); } } allLaterals.assign( lateralSet.begin(), lateralSet.end() ); } for ( auto w : allLaterals ) { auto fractures = w->descendantsIncludingThisOfType(); wellPathFractures.insert( wellPathFractures.end(), fractures.begin(), fractures.end() ); auto fishbones = w->descendantsIncludingThisOfType(); wellPathFishbones.insert( wellPathFishbones.end(), fishbones.begin(), fishbones.end() ); auto perforations = w->descendantsIncludingThisOfType(); wellPathPerforations.insert( wellPathPerforations.end(), perforations.begin(), perforations.end() ); } if ( ( !simWellFractures.empty() ) || ( !wellPathFractures.empty() ) ) { exportSettings->showFractureInUi( true ); } else { exportSettings->showFractureInUi( false ); } if ( !wellPathFishbones.empty() ) { exportSettings->showFishbonesInUi( true ); } else { exportSettings->showFishbonesInUi( false ); } if ( !wellPathPerforations.empty() ) { exportSettings->showPerforationsInUi( true ); std::vector perforationValves; for ( const auto& perf : wellPathPerforations ) { auto other = perf->descendantsIncludingThisOfType(); perforationValves.insert( perforationValves.end(), other.begin(), other.end() ); } if ( !perforationValves.empty() ) { exportSettings->enableIncludeMsw(); } } else { exportSettings->showPerforationsInUi( false ); } caf::PdmUiPropertyViewDialog propertyDialog( Riu3DMainWindowTools::mainWindowWidget(), exportSettings, dialogTitle, "" ); RicExportFeatureImpl::configureForExport( propertyDialog.dialogButtonBox() ); if ( propertyDialog.exec() == QDialog::Accepted ) { { QDir folder( exportSettings->folder ); if ( !folder.exists() ) { QString txt = QString( "The path '%1' does not exist. Aborting export." ).arg( exportSettings->folder ); RiaLogging::errorInMessageBox( Riu3DMainWindowTools::mainWindowWidget(), "Export", txt ); return; } } RiaApplication::instance()->setLastUsedDialogDirectory( "COMPLETIONS", exportSettings->folder ); RicWellPathExportCompletionDataFeatureImpl::exportCompletions( topLevelWells, simWells, *exportSettings ); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicWellPathExportCompletionDataFeature::isCommandEnabled() const { std::vector wellPaths = selectedWellPaths(); return !wellPaths.empty(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicWellPathExportCompletionDataFeature::onActionTriggered( bool isChecked ) { std::vector wellPaths = selectedWellPaths(); CVF_ASSERT( !wellPaths.empty() ); std::vector simWells; QString dialogTitle = "Export Completion Data for Selected Well Paths"; RicWellPathExportCompletionDataFeature::prepareExportSettingsAndExportCompletions( dialogTitle, wellPaths, simWells ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicWellPathExportCompletionDataFeature::setupActionLook( QAction* actionToSetup ) { std::vector selected = selectedWellPaths(); if ( selected.size() == 1u ) { actionToSetup->setText( "Export Completion Data for Current Well Path" ); } else { actionToSetup->setText( "Export Completion Data for Selected Well Paths" ); } actionToSetup->setIcon( QIcon( ":/ExportCompletionsSymbol16x16.png" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RicWellPathExportCompletionDataFeature::selectedWellPaths() { std::vector wellPaths; caf::SelectionManager::instance()->objectsByType( &wellPaths ); return wellPaths; }