mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
* #14889: Do not change main window when importing well picks * #14889: Fix clipped bottom of plots in dock windows * #14889: Add Create RFT Correlation Report to Ensemble Correlation Plots menu * #14889: Show imported observed FMU RFT data as table * #14889: Use time step from source RFT plot in RFT correlation report * #14889: Show observed data in RFT cross plot when no RFT samples are available * #14889: Keep RFT plot zoom when toggling formation in RFT correlation report * #14889: Do not change main window when importing formations * #14889: Use general delete for observed data and improve FMU RFT data name
286 lines
11 KiB
C++
286 lines
11 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// 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 <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RimObservedDataCollection.h"
|
|
|
|
#include "RiaGuiApplication.h"
|
|
#include "RiaLogging.h"
|
|
|
|
#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"
|
|
|
|
#include "RifKeywordVectorParser.h"
|
|
|
|
#include "RimCsvUserData.h"
|
|
#include "RimMainPlotCollection.h"
|
|
#include "RimObservedEclipseUserData.h"
|
|
#include "RimObservedFmuRftData.h"
|
|
#include "RimObservedSummaryData.h"
|
|
#include "RimPlotCurve.h"
|
|
#include "RimPressureDepthData.h"
|
|
#include "RimProject.h"
|
|
#include "RimSummaryObservedDataFile.h"
|
|
|
|
#include "RiuPlotMainWindow.h"
|
|
#include "RiuPlotMainWindowTools.h"
|
|
|
|
#include "cafPdmSettings.h"
|
|
#include "cafPdmUiObjectEditorHandle.h"
|
|
#include "cafPdmUiPropertyViewDialog.h"
|
|
#include "cafUtils.h"
|
|
|
|
#include <QDir>
|
|
#include <QFile>
|
|
#include <QSet>
|
|
|
|
CAF_PDM_SOURCE_INIT( RimObservedDataCollection, "ObservedDataCollection" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimObservedDataCollection::RimObservedDataCollection()
|
|
{
|
|
CAF_PDM_InitObject( "Observed Data", ":/Folder.png" );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_observedDataArray, "ObservedDataArray", "" );
|
|
CAF_PDM_InitFieldNoDefault( &m_observedFmuRftArray, "ObservedFmuRftDataArray", "" );
|
|
CAF_PDM_InitFieldNoDefault( &m_observedPressureDepthArray, "PressureDepthDataArray", "" );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimObservedSummaryData*> RimObservedDataCollection::allObservedSummaryData() const
|
|
{
|
|
return m_observedDataArray.childrenByType();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimObservedFmuRftData*> RimObservedDataCollection::allObservedFmuRftData() const
|
|
{
|
|
return m_observedFmuRftArray.childrenByType();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimPressureDepthData*> RimObservedDataCollection::allPressureDepthData() const
|
|
{
|
|
return m_observedPressureDepthArray.childrenByType();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimObservedDataCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& referringObjects )
|
|
{
|
|
// Delete curves that referenced the deleted observed data
|
|
std::set<caf::PdmObjectHandle*> uniqueReferringObjects( referringObjects.begin(), referringObjects.end() );
|
|
for ( caf::PdmObjectHandle* obj : uniqueReferringObjects )
|
|
{
|
|
if ( auto curve = dynamic_cast<RimPlotCurve*>( obj ) )
|
|
{
|
|
curve->deleteIfDataSourceIsMissing();
|
|
}
|
|
}
|
|
|
|
RimMainPlotCollection::current()->loadDataAndUpdateAllPlots();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RimObservedDataCollection::fileExists( const QString& fileName, QString* errorText /*= nullptr*/ )
|
|
{
|
|
QFile file( fileName );
|
|
if ( !file.exists() )
|
|
{
|
|
QString s = QString( "File does not exist, %1" ).arg( fileName );
|
|
RiaLogging::error( s.toStdString() );
|
|
|
|
if ( errorText ) errorText->append( s );
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void updateNewObservedDataCreated( caf::PdmObject* object )
|
|
{
|
|
RiuPlotMainWindowTools::showPlotMainWindow();
|
|
RiuPlotMainWindowTools::onObjectAppended( object );
|
|
|
|
caf::PdmUiObjectEditorHandle::updateUiAllObjectEditors();
|
|
|
|
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
|
|
if ( mpw ) mpw->updateMultiPlotToolBar();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimObservedSummaryData* RimObservedDataCollection::createAndAddRsmObservedSummaryDataFromFile( const QString& fileName,
|
|
QString* errorText /*= nullptr*/ )
|
|
{
|
|
if ( !fileExists( fileName, errorText ) ) return nullptr;
|
|
|
|
RimObservedSummaryData* observedData = nullptr;
|
|
RimObservedEclipseUserData* columnBasedUserData = new RimObservedEclipseUserData();
|
|
observedData = columnBasedUserData;
|
|
|
|
m_observedDataArray.push_back( observedData );
|
|
observedData->setSummaryHeaderFileName( fileName );
|
|
observedData->createSummaryReaderInterface();
|
|
observedData->updateMetaData();
|
|
|
|
if ( errorText && !observedData->errorMessagesFromReader().isEmpty() )
|
|
{
|
|
errorText->append( observedData->errorMessagesFromReader() );
|
|
}
|
|
|
|
RimProject::current()->assignCaseIdToSummaryCase( observedData );
|
|
updateNewObservedDataCreated( observedData );
|
|
|
|
updateConnectedEditors();
|
|
|
|
return observedData;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimObservedSummaryData* RimObservedDataCollection::createAndAddCvsObservedSummaryDataFromFile( const QString& fileName,
|
|
bool useSavedFieldsValuesInDialog,
|
|
QString* errorText /*= nullptr*/ )
|
|
{
|
|
if ( !fileExists( fileName, errorText ) ) return nullptr;
|
|
|
|
RimObservedSummaryData* observedData = nullptr;
|
|
|
|
RimCsvUserData* userData = new RimCsvUserData();
|
|
RicPasteAsciiDataToSummaryPlotFeatureUi* parseOptions = userData->parseOptions();
|
|
|
|
if ( useSavedFieldsValuesInDialog )
|
|
{
|
|
caf::PdmSettings::readFieldsFromApplicationStore( parseOptions, parseOptions->contextString() );
|
|
}
|
|
parseOptions->setUiModeImport( fileName );
|
|
|
|
bool parseOptionsChanged = false;
|
|
if ( parseOptions->uiModeImport() != RicPasteAsciiDataToSummaryPlotFeatureUi::UI_MODE_SILENT )
|
|
{
|
|
caf::PdmUiPropertyViewDialog propertyDialog( nullptr, parseOptions, "CSV Import Options", "" );
|
|
if ( propertyDialog.exec() != QDialog::Accepted )
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
parseOptionsChanged = true;
|
|
}
|
|
|
|
if ( useSavedFieldsValuesInDialog && parseOptionsChanged )
|
|
{
|
|
caf::PdmSettings::writeFieldsToApplicationStore( parseOptions, parseOptions->contextString() );
|
|
}
|
|
|
|
// userData->setParseOptions(parseOptionsUi.parseOptions());
|
|
userData->setSummaryHeaderFileName( fileName );
|
|
userData->createSummaryReaderInterface();
|
|
userData->updateMetaData();
|
|
|
|
if ( errorText && !userData->errorMessagesFromReader().isEmpty() )
|
|
{
|
|
errorText->append( userData->errorMessagesFromReader() );
|
|
}
|
|
|
|
if ( userData->summaryReader() )
|
|
{
|
|
m_observedDataArray.push_back( userData );
|
|
observedData = userData;
|
|
}
|
|
else
|
|
{
|
|
delete userData;
|
|
return nullptr;
|
|
}
|
|
|
|
RimProject::current()->assignCaseIdToSummaryCase( observedData );
|
|
updateNewObservedDataCreated( observedData );
|
|
|
|
updateConnectedEditors();
|
|
|
|
return observedData;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimObservedFmuRftData* RimObservedDataCollection::createAndAddFmuRftDataFromPath( const QString& directoryPath )
|
|
{
|
|
// The data folder is often named e.g. "rft", so include the parent folder to make the name descriptive
|
|
const QDir dir( directoryPath );
|
|
QStringList pathParts = QDir::cleanPath( dir.absolutePath() ).split( '/', Qt::SkipEmptyParts );
|
|
QString baseName = pathParts.size() >= 2 ? pathParts.mid( pathParts.size() - 2 ).join( '/' ) : dir.dirName();
|
|
if ( baseName.isEmpty() ) baseName = "Observed FMU Data";
|
|
|
|
QSet<QString> existingNames;
|
|
for ( const auto& existing : m_observedFmuRftArray )
|
|
{
|
|
existingNames.insert( existing->name() );
|
|
}
|
|
|
|
QString name = baseName;
|
|
for ( int i = 2; existingNames.contains( name ); ++i )
|
|
{
|
|
name = QString( "%1 (%2)" ).arg( baseName ).arg( i );
|
|
}
|
|
|
|
RimObservedFmuRftData* fmuRftData = new RimObservedFmuRftData;
|
|
fmuRftData->setDirectoryPath( directoryPath );
|
|
fmuRftData->createRftReaderInterface();
|
|
fmuRftData->setName( name );
|
|
m_observedFmuRftArray.push_back( fmuRftData );
|
|
|
|
updateNewObservedDataCreated( fmuRftData );
|
|
updateConnectedEditors();
|
|
|
|
return fmuRftData;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimPressureDepthData* RimObservedDataCollection::createAndAddPressureDepthDataFromPath( const QString& filePath )
|
|
{
|
|
QString name = QString( "Imported Pressure/Depth Data %1" ).arg( m_observedPressureDepthArray.size() + 1 );
|
|
|
|
RimPressureDepthData* data = new RimPressureDepthData;
|
|
data->setFilePath( filePath );
|
|
data->createRftReaderInterface();
|
|
data->setName( name );
|
|
m_observedPressureDepthArray.push_back( data );
|
|
|
|
updateNewObservedDataCreated( data );
|
|
updateConnectedEditors();
|
|
|
|
return data;
|
|
}
|