2024-06-28 12:33:19 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2024- 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 <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RimOsduWellPathDataLoader.h"
|
|
|
|
|
|
|
|
|
|
#include "Cloud/RiaOsduConnector.h"
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
|
#include "RiaLogging.h"
|
2026-05-06 12:00:10 +02:00
|
|
|
#include "RiaQStringFormatter.h"
|
2024-06-28 12:33:19 +02:00
|
|
|
|
|
|
|
|
#include "RimOsduWellPath.h"
|
|
|
|
|
|
|
|
|
|
#include "RifOsduWellPathReader.h"
|
|
|
|
|
|
2024-10-30 17:23:08 +01:00
|
|
|
#include "Well/RigWellPath.h"
|
2024-06-28 12:33:19 +02:00
|
|
|
|
|
|
|
|
#include "cafProgressInfo.h"
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimOsduWellPathDataLoader::RimOsduWellPathDataLoader()
|
|
|
|
|
: caf::DataLoader()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimOsduWellPathDataLoader::loadData( caf::PdmObject& pdmObject, const QString& dataType, int taskId, caf::ProgressInfo& progressInfo )
|
|
|
|
|
{
|
|
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
|
RiaOsduConnector* osduConnector = app->makeOsduConnector();
|
2024-08-16 16:48:04 +02:00
|
|
|
if ( !osduConnector )
|
|
|
|
|
{
|
|
|
|
|
RiaLogging::error( "Failed to create OSDU connector" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-28 12:33:19 +02:00
|
|
|
|
|
|
|
|
// TODO: this is weird?
|
|
|
|
|
m_dataType = dataType;
|
|
|
|
|
|
|
|
|
|
auto oWPath = dynamic_cast<RimOsduWellPath*>( &pdmObject );
|
|
|
|
|
if ( oWPath )
|
|
|
|
|
{
|
2024-08-16 16:48:04 +02:00
|
|
|
connect( osduConnector,
|
|
|
|
|
SIGNAL( parquetDownloadFinished( const QByteArray&, const QString&, const QString& ) ),
|
|
|
|
|
this,
|
|
|
|
|
SLOT( parquetDownloadComplete( const QByteArray&, const QString&, const QString& ) ),
|
|
|
|
|
Qt::ConnectionType( Qt::QueuedConnection | Qt::UniqueConnection ) );
|
|
|
|
|
|
2024-08-16 13:28:44 +02:00
|
|
|
QString trajectoryId = oWPath->wellboreTrajectoryId();
|
2024-06-28 12:33:19 +02:00
|
|
|
m_wellPaths[trajectoryId] = oWPath;
|
|
|
|
|
m_taskIds[trajectoryId] = taskId;
|
2024-08-16 13:28:44 +02:00
|
|
|
osduConnector->requestWellboreTrajectoryParquetDataById( trajectoryId );
|
2024-06-28 12:33:19 +02:00
|
|
|
}
|
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimOsduWellPathDataLoader::isRunnable() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-08-14 16:54:41 +02:00
|
|
|
void RimOsduWellPathDataLoader::cancel()
|
|
|
|
|
{
|
|
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
|
RiaOsduConnector* osduConnector = app->makeOsduConnector();
|
|
|
|
|
|
|
|
|
|
for ( auto& [trajectoryId, taskId] : m_taskIds )
|
|
|
|
|
{
|
|
|
|
|
osduConnector->cancelRequestForId( trajectoryId );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-06-28 12:33:19 +02:00
|
|
|
void RimOsduWellPathDataLoader::parquetDownloadComplete( const QByteArray& contents, const QString& url, const QString& id )
|
|
|
|
|
{
|
2026-06-17 11:40:48 +02:00
|
|
|
int taskId = -1;
|
2024-06-28 12:33:19 +02:00
|
|
|
{
|
2026-06-17 11:40:48 +02:00
|
|
|
QMutexLocker lock( &m_mutex );
|
|
|
|
|
|
|
|
|
|
if ( m_wellPaths.find( id ) == m_wellPaths.end() || m_taskIds.find( id ) == m_taskIds.end() ) return;
|
|
|
|
|
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::info( std::format( "Parquet download complete. Id: {} Size: {}", id, contents.size() ) );
|
2026-06-17 11:40:48 +02:00
|
|
|
taskId = m_taskIds[id];
|
2024-06-28 12:33:19 +02:00
|
|
|
|
2024-07-05 15:57:26 +02:00
|
|
|
if ( !contents.isEmpty() )
|
2024-06-28 12:33:19 +02:00
|
|
|
{
|
2024-07-05 15:57:26 +02:00
|
|
|
auto oWPath = m_wellPaths[id];
|
|
|
|
|
auto [wellPathGeometry, errorMessage] = RifOsduWellPathReader::readWellPathData( contents, oWPath->datumElevationFromOsdu() );
|
|
|
|
|
if ( wellPathGeometry.notNull() )
|
|
|
|
|
{
|
|
|
|
|
oWPath->setWellPathGeometry( wellPathGeometry.p() );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::warning( errorMessage.toStdString() );
|
2024-07-05 15:57:26 +02:00
|
|
|
}
|
2024-06-28 12:33:19 +02:00
|
|
|
}
|
2024-07-05 15:57:26 +02:00
|
|
|
}
|
2026-06-17 11:40:48 +02:00
|
|
|
|
|
|
|
|
// The lock is released above before emitting taskDone. The signal is delivered synchronously and triggers
|
|
|
|
|
// progress updates that call QApplication::processEvents(), which can re-enter this slot for another
|
|
|
|
|
// well. Holding the non-recursive m_mutex across send() would then deadlock the GUI thread (#14230).
|
|
|
|
|
taskDone.send( m_dataType, taskId );
|
2024-06-28 12:33:19 +02:00
|
|
|
}
|