Files
ResInsight/ApplicationLibCode/Commands/OsduImportCommands/RicWellPathsImportOsduFeature.cpp

132 lines
4.7 KiB
C++
Raw Normal View History

2015-08-14 09:45:57 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
2024-02-28 08:10:52 +01:00
// Copyright (C) 2024- Equinor ASA
2019-06-14 10:45:47 +02:00
//
2015-08-14 09:45:57 +02: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-06-14 10:45:47 +02:00
//
2015-08-14 09:45:57 +02: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-06-14 10:45:47 +02:00
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
2015-08-14 09:45:57 +02:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
2024-02-26 15:40:13 +01:00
#include "RicWellPathsImportOsduFeature.h"
#include "RiaApplication.h"
#include "RiaGuiApplication.h"
2024-02-28 08:10:52 +01:00
#include "RiaLogging.h"
#include "RiaOsduConnector.h"
#include "RiaPreferences.h"
2024-02-28 08:10:52 +01:00
#include "RiaPreferencesOsdu.h"
#include "RigWellPath.h"
#include "RimFileWellPath.h"
2024-02-28 08:10:52 +01:00
#include "RimOilField.h"
#include "RimOsduWellPath.h"
#include "RimProject.h"
#include "RimTools.h"
2024-02-28 08:10:52 +01:00
#include "RimWellPathCollection.h"
#include "RimWellPathImport.h"
#include "RiuMainWindow.h"
#include "RiuWellImportWizard.h"
#include "cafProgressInfo.h"
2024-02-28 08:10:52 +01:00
#include "cvfObject.h"
#include <QAction>
#include <QDir>
2024-02-28 08:10:52 +01:00
CAF_CMD_SOURCE_INIT( RicWellPathsImportOsduFeature, "RicWellPathsImportOsduFeature" );
//--------------------------------------------------------------------------------------------------
2019-06-14 10:45:47 +02:00
///
//--------------------------------------------------------------------------------------------------
2024-02-28 08:10:52 +01:00
void RicWellPathsImportOsduFeature::onActionTriggered( bool isChecked )
{
RiaApplication* app = RiaApplication::instance();
if ( !app->project() ) return;
2017-10-17 12:48:36 +02:00
// Update the UTM bounding box from the reservoir
app->project()->computeUtmAreaOfInterest();
2024-02-28 08:10:52 +01:00
QString wellPathsFolderPath = QStandardPaths::writableLocation( QStandardPaths::CacheLocation ) + QString( "/wellpaths/" );
QDir::root().mkpath( wellPathsFolderPath );
if ( !app->project()->wellPathImport() ) return;
// Keep a copy of the import settings, and restore if cancel is pressed in the import wizard
QString copyOfOriginalObject = app->project()->wellPathImport()->writeObjectToXmlString();
if ( !app->preferences() ) return;
2024-02-28 08:10:52 +01:00
RimProject* project = RimProject::current();
if ( !project ) return;
if ( project->oilFields.empty() ) return;
RimOilField* oilField = project->activeOilField();
if ( !oilField ) return;
RiaOsduConnector* osduConnector = app->makeOsduConnector();
2024-02-28 08:10:52 +01:00
RiuWellImportWizard wellImportwizard( wellPathsFolderPath, osduConnector, app->project()->wellPathImport(), RiuMainWindow::instance() );
if ( QDialog::Accepted == wellImportwizard.exec() )
{
2024-02-28 08:10:52 +01:00
std::vector<RiuWellImportWizard::WellInfo> importedWells = wellImportwizard.importedWells();
caf::ProgressInfo progress( importedWells.size(), "Importing wells from OSDU" );
2024-02-28 08:10:52 +01:00
for ( auto w : importedWells )
{
auto task = progress.task( QString( "Importing well: %1" ).arg( w.name ) );
auto [wellPathGeometry, errorMessage] =
RimWellPathCollection::loadWellPathGeometryFromOsdu( osduConnector, w.wellboreTrajectoryId, w.datumElevation );
2024-02-28 08:10:52 +01:00
if ( wellPathGeometry.notNull() )
{
auto wellPath = new RimOsduWellPath;
wellPath->setName( w.name );
wellPath->setWellId( w.wellId );
wellPath->setWellboreId( w.wellboreId );
wellPath->setWellboreTrajectoryId( w.wellboreTrajectoryId );
wellPath->setDatumElevationFromOsdu( w.datumElevation );
oilField->wellPathCollection->addWellPath( wellPath );
2024-02-28 08:10:52 +01:00
wellPath->setWellPathGeometry( wellPathGeometry.p() );
}
else
{
RiaLogging::error( "Importing OSDU well failed: " + errorMessage );
}
oilField->wellPathCollection->updateConnectedEditors();
}
2024-02-28 08:10:52 +01:00
project->updateConnectedEditors();
app->project()->scheduleCreateDisplayModelAndRedrawAllViews();
}
else
{
app->project()->wellPathImport()->readObjectFromXmlString( copyOfOriginalObject, caf::PdmDefaultObjectFactory::instance() );
}
}
//--------------------------------------------------------------------------------------------------
2019-06-14 10:45:47 +02:00
///
//--------------------------------------------------------------------------------------------------
2024-02-28 08:10:52 +01:00
void RicWellPathsImportOsduFeature::setupActionLook( QAction* actionToSetup )
{
2024-02-28 08:10:52 +01:00
actionToSetup->setText( "Import Well Paths from &OSDU" );
actionToSetup->setIcon( QIcon( ":/WellCollection.png" ) );
}