ResInsight/ApplicationLibCode/Commands/RicImportPressureDepthDataFeature.cpp
2023-01-19 09:00:05 +01:00

101 lines
3.9 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2023- 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 "RicImportPressureDepthDataFeature.h"
#include "RiaApplication.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RicImportFormationNamesFeature.h"
#include "RifReaderFmuRft.h"
#include "RimFormationNames.h"
#include "RimObservedDataCollection.h"
#include "RimObservedSummaryData.h"
#include "RimOilField.h"
#include "RimPressureDepthData.h"
#include "RimProject.h"
#include "RiuFileDialogTools.h"
#include "RiuPlotMainWindowTools.h"
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QDir>
#include <QFileInfo>
CAF_CMD_SOURCE_INIT( RicImportPressureDepthDataFeature, "RicImportPressureDepthDataFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportPressureDepthDataFeature::selectPressureDepthDataPathInDialog()
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory( "SUMMARY_CASE_DIR" );
QString filePath = RiuFileDialogTools::getOpenFileName( nullptr, "Import Pressure/Depth Data", defaultDir );
RimProject* proj = app->project();
RimObservedDataCollection* observedDataCollection =
proj->activeOilField() ? proj->activeOilField()->observedDataCollection() : nullptr;
if ( !observedDataCollection ) return;
const RimPressureDepthData* importedData = observedDataCollection->createAndAddPressureDepthDataFromPath( filePath );
if ( importedData != nullptr )
{
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( importedData );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportPressureDepthDataFeature::isCommandEnabled()
{
std::vector<RimObservedDataCollection*> selectionObservedDataCollection;
caf::SelectionManager::instance()->objectsByType( &selectionObservedDataCollection );
std::vector<RimObservedSummaryData*> selectionObservedData;
caf::SelectionManager::instance()->objectsByType( &selectionObservedData );
return ( !selectionObservedDataCollection.empty() || !selectionObservedData.empty() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportPressureDepthDataFeature::onActionTriggered( bool isChecked )
{
selectPressureDepthDataPathInDialog();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportPressureDepthDataFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/ObservedDataFile16x16.png" ) );
actionToSetup->setText( "Import Pressure Depth Data" );
}