Files
ResInsight/ApplicationLibCode/Commands/ApplicationCommands/RicSumoDataFeature.cpp
T
Jørgen Herje 0d9d4fed19 Improved Sumo summary data fetching (#14551)
Sumo data is loaded so the application stays responsive while it waits.

Run Sumo transfers on a dedicated thread
Split RiaSumoConnector into transport and data delegates
Load Sumo summary vectors concurrently and without waiting
Show that Sumo data is being loaded
2026-08-20 11:48:25 +02:00

287 lines
10 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSumoDataFeature.h"
#include "RiaApplication.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RiaPreferences.h"
#include "RiaPreferencesSystem.h"
#include "RifArrowTools.h"
#include "RiuMainWindow.h"
#include <QAction>
#include <QSettings>
CAF_CMD_SOURCE_INIT( RicSumoDataFeature, "RicSumoDataFeature" );
SimpleDialog::SimpleDialog( QWidget* parent )
: QDialog( parent )
{
setWindowTitle( "Simple Dialog" );
QVBoxLayout* layout = new QVBoxLayout( this );
label = new QLabel( "This is a simple dialog.", this );
layout->addWidget( label );
authButton = new QPushButton( "Authenticate", this );
connect( authButton, &QPushButton::clicked, this, &SimpleDialog::onAuthClicked );
layout->addWidget( authButton );
assetsButton = new QPushButton( "Asset Names", this );
connect( assetsButton, &QPushButton::clicked, this, &SimpleDialog::onAssetsClicked );
layout->addWidget( assetsButton );
casesButton = new QPushButton( "Cases", this );
connect( casesButton, &QPushButton::clicked, this, &SimpleDialog::onCasesClicked );
layout->addWidget( casesButton );
vectorNamesButton = new QPushButton( "Vector Names", this );
connect( vectorNamesButton, &QPushButton::clicked, this, &SimpleDialog::onVectorNamesClicked );
layout->addWidget( vectorNamesButton );
blobIdButton = new QPushButton( "Blob Id", this );
connect( blobIdButton, &QPushButton::clicked, this, &SimpleDialog::onFindBlobIdClicked );
layout->addWidget( blobIdButton );
parquetDownloadButton = new QPushButton( "Parquet", this );
connect( parquetDownloadButton, &QPushButton::clicked, this, &SimpleDialog::onParquetClicked );
layout->addWidget( parquetDownloadButton );
showContentParquetButton = new QPushButton( "Show Content Parquet", this );
connect( showContentParquetButton, &QPushButton::clicked, this, &SimpleDialog::onShowContentParquetClicked );
layout->addWidget( showContentParquetButton );
realizationIdsButton = new QPushButton( "Realizations", this );
connect( realizationIdsButton, &QPushButton::clicked, this, &SimpleDialog::onRealizationsClicked );
layout->addWidget( realizationIdsButton );
okButton = new QPushButton( "OK", this );
connect( okButton, &QPushButton::clicked, this, &SimpleDialog::onOkClicked );
layout->addWidget( okButton );
cancelButton = new QPushButton( "Cancel", this );
connect( cancelButton, &QPushButton::clicked, this, &SimpleDialog::onCancelClicked );
layout->addWidget( cancelButton );
setLayout( layout );
m_sumoConnector = RiaApplication::instance()->makeSumoConnector();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
SimpleDialog::~SimpleDialog()
{
// The connector belongs to RiaApplication and is shared with everything else reading from Sumo, so it
// must outlive this dialog. Only the connection made in createConnection is ours to undo.
if ( m_sumoConnector )
{
disconnect( m_sumoConnector, &RiaSumoConnector::tokenReady, this, &SimpleDialog::onTokenReady );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::createConnection()
{
m_sumoConnector = RiaApplication::instance()->makeSumoConnector();
// Authenticating more than once would otherwise leave one connection per attempt, and onTokenReady
// would be called once for each of them.
connect( m_sumoConnector, &RiaSumoConnector::tokenReady, this, &SimpleDialog::onTokenReady, Qt::UniqueConnection );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onAuthClicked()
{
createConnection();
m_sumoConnector->requestToken();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onAssetsClicked()
{
if ( !isTokenValid() ) return;
const auto assets = m_sumoConnector->explore().assets();
label->setText( QString( "Received %1 assets" ).arg( assets.size() ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onCasesClicked()
{
if ( !isTokenValid() ) return;
QString fieldName = "Drogon";
const auto cases = m_sumoConnector->explore().cases( fieldName );
label->setText( QString( "Received %1 cases" ).arg( cases.size() ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onVectorNamesClicked()
{
if ( !isTokenValid() ) return;
SumoCaseId caseId( "5b783aab-ce10-4b78-b129-baf8d8ce4baa" );
QString iteration = "iter-0";
const auto vectorNames = m_sumoConnector->summary().vectorNames( caseId, iteration );
label->setText( QString( "Received %1 vector names" ).arg( vectorNames.size() ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onFindBlobIdClicked()
{
if ( !isTokenValid() ) return;
SumoCaseId caseId( "5b783aab-ce10-4b78-b129-baf8d8ce4baa" );
QString iteration = "iter-0";
QString vectorName = "FOPT";
m_blobId = m_sumoConnector->summary().vectorBlobId( caseId, iteration, vectorName );
label->setText( m_blobId.isEmpty() ? QString( "No blob ID received" ) : QString( "Blob ID: %1" ).arg( m_blobId ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onParquetClicked()
{
if ( !isTokenValid() ) return;
if ( m_blobId.isEmpty() )
{
onFindBlobIdClicked();
}
if ( !m_blobId.isEmpty() )
{
m_blobContents = m_sumoConnector->downloadBlobBlocking( m_blobId );
label->setText( QString( "Downloaded blob, %1 bytes" ).arg( m_blobContents.size() ) );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onShowContentParquetClicked()
{
if ( m_blobContents.isEmpty() ) return;
// TODO: show content using parquet reader
auto tableText = RifArrowTools::readFirstRowsOfTable( m_blobContents );
RiaLogging::info( tableText.toStdString() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onRealizationsClicked()
{
if ( !isTokenValid() ) return;
SumoCaseId caseId( "485041ce-ad72-48a3-ac8c-484c0ed95cf8" );
QString iteration = "iter-0";
auto ids = m_sumoConnector->explore().realizationIds( caseId, iteration );
for ( const auto& id : ids )
{
RiaLogging::info( id.toStdString() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool SimpleDialog::isTokenValid()
{
if ( !m_sumoConnector )
{
createConnection();
}
if ( m_sumoConnector->token().isEmpty() )
{
m_sumoConnector->requestToken();
}
return !m_sumoConnector->token().isEmpty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void SimpleDialog::onTokenReady( const QString& token )
{
RiaLogging::info( "Token ready: " + token.toStdString() );
}
void SimpleDialog::onOkClicked()
{
qDebug( "OK button clicked" );
accept();
}
void SimpleDialog::onCancelClicked()
{
qDebug( "Cancel button clicked" );
reject();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSumoDataFeature::onActionTriggered( bool isChecked )
{
if ( !m_dialog )
{
m_dialog = new SimpleDialog( RiaGuiApplication::widgetToUseAsParent() );
}
m_dialog->show();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSumoDataFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "SUMO" );
}