mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2018 CSV data. First working version of CSV import
This commit is contained in:
@@ -31,6 +31,7 @@ ${CEE_CURRENT_LIST_DIR}RimCalculatedSummaryCase.h
|
||||
${CEE_CURRENT_LIST_DIR}RimCalculatedSummaryCurveReader.h
|
||||
${CEE_CURRENT_LIST_DIR}RimSummaryAddress.h
|
||||
${CEE_CURRENT_LIST_DIR}RimSummaryCrossPlot.h
|
||||
${CEE_CURRENT_LIST_DIR}RimCsvUserData.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -60,6 +61,7 @@ ${CEE_CURRENT_LIST_DIR}RimCalculatedSummaryCase.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimCalculatedSummaryCurveReader.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimSummaryAddress.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimSummaryCrossPlot.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimCsvUserData.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
105
ApplicationCode/ProjectDataModel/Summary/RimCsvUserData.cpp
Normal file
105
ApplicationCode/ProjectDataModel/Summary/RimCsvUserData.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RimCsvUserData.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RifCsvUserData.h"
|
||||
#include "RifColumnBasedUserDataParser.h"
|
||||
#include "RifKeywordVectorUserData.h"
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimCsvUserData, "RimCsvUserData");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCsvUserData::RimCsvUserData()
|
||||
{
|
||||
CAF_PDM_InitObject("Observed CSV Data File", ":/Default.png", "", "");
|
||||
m_summaryHeaderFilename.uiCapability()->setUiName("File");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCsvUserData::~RimCsvUserData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCsvUserData::createSummaryReaderInterface()
|
||||
{
|
||||
m_summaryReader = nullptr;
|
||||
|
||||
if (caf::Utils::fileExists(this->summaryHeaderFilename()))
|
||||
{
|
||||
QFile file(this->summaryHeaderFilename());
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
RiaLogging::error(QString("Failed to open %1").arg(this->summaryHeaderFilename()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QString fileContents = in.readAll();
|
||||
|
||||
RifCsvUserData* csvUserData = new RifCsvUserData();
|
||||
if (csvUserData->parse(fileContents, m_parseOptions, &m_errorText))
|
||||
{
|
||||
m_summaryReader = csvUserData;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_summaryReader = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifSummaryReaderInterface* RimCsvUserData::summaryReader()
|
||||
{
|
||||
return m_summaryReader.p();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimCsvUserData::errorMessagesFromReader()
|
||||
{
|
||||
return m_errorText;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCsvUserData::setParseOptions(const AsciiDataParseOptions &parseOptions)
|
||||
{
|
||||
m_parseOptions = parseOptions;
|
||||
}
|
||||
53
ApplicationCode/ProjectDataModel/Summary/RimCsvUserData.h
Normal file
53
ApplicationCode/ProjectDataModel/Summary/RimCsvUserData.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RimObservedData.h"
|
||||
|
||||
#include "../../Commands/SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
class RifSummaryReaderInterface;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RimCsvUserData : public RimObservedData
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
public:
|
||||
RimCsvUserData();
|
||||
virtual ~RimCsvUserData();
|
||||
|
||||
virtual void createSummaryReaderInterface() override;
|
||||
|
||||
virtual RifSummaryReaderInterface* summaryReader() override;
|
||||
|
||||
virtual QString errorMessagesFromReader() override;
|
||||
|
||||
void setParseOptions(const AsciiDataParseOptions &parseOptions);
|
||||
|
||||
private:
|
||||
cvf::ref<RifSummaryReaderInterface> m_summaryReader;
|
||||
QString m_errorText;
|
||||
AsciiDataParseOptions m_parseOptions;
|
||||
};
|
||||
@@ -22,15 +22,20 @@
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"
|
||||
|
||||
#include "RifKeywordVectorParser.h"
|
||||
|
||||
#include "RimObservedData.h"
|
||||
#include "RimCsvUserData.h"
|
||||
#include "RimObservedEclipseUserData.h"
|
||||
#include "RimSummaryObservedDataFile.h"
|
||||
|
||||
#include "RiuMainPlotWindow.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
#include "cafPdmSettings.h"
|
||||
#include "cafPdmUiPropertyViewDialog.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
@@ -92,59 +97,24 @@ RimObservedData* RimObservedDataCollection::createAndAddObservedDataFromFileName
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QString fileContents = in.readAll();
|
||||
|
||||
bool eclipseUserData = false;
|
||||
if (fileName.endsWith(".rsm", Qt::CaseInsensitive))
|
||||
{
|
||||
eclipseUserData = true;
|
||||
return createAndAddRsmObservedDataFromFile(file, errorText);
|
||||
}
|
||||
|
||||
if (RifKeywordVectorParser::canBeParsed(fileContents))
|
||||
else if (fileName.endsWith(".txt", Qt::CaseInsensitive) || fileName.endsWith(".csv", Qt::CaseInsensitive))
|
||||
{
|
||||
eclipseUserData = true;
|
||||
}
|
||||
|
||||
if (eclipseUserData)
|
||||
{
|
||||
RimObservedEclipseUserData* columnBasedUserData = new RimObservedEclipseUserData();
|
||||
|
||||
observedData = columnBasedUserData;
|
||||
}
|
||||
|
||||
if (observedData)
|
||||
{
|
||||
this->m_observedDataArray.push_back(observedData);
|
||||
observedData->setSummaryHeaderFileName(fileName);
|
||||
observedData->createSummaryReaderInterface();
|
||||
observedData->updateMetaData();
|
||||
observedData->updateOptionSensitivity();
|
||||
|
||||
if (errorText && !observedData->errorMessagesFromReader().isEmpty())
|
||||
{
|
||||
errorText->append(observedData->errorMessagesFromReader());
|
||||
}
|
||||
|
||||
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow();
|
||||
if (mainPlotWindow)
|
||||
{
|
||||
mainPlotWindow->selectAsCurrentItem(observedData);
|
||||
mainPlotWindow->setExpanded(observedData);
|
||||
}
|
||||
|
||||
this->updateConnectedEditors();
|
||||
return createAndAddCvsObservedDataFromFile(file, errorText);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (errorText)
|
||||
{
|
||||
errorText->append("Not able to import file. Make sure '*.rsm' is used as extension if data is in RMS format.");
|
||||
errorText->append("Not able to import file. Make sure '*.rsm' is used as extension if data is in RMS format or '*.txt' or '*.csv' if data is in CSV format.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return observedData;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -158,3 +128,88 @@ std::vector<RimSummaryCase*> RimObservedDataCollection::allObservedData()
|
||||
|
||||
return allObservedData;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimObservedData* RimObservedDataCollection::createAndAddRsmObservedDataFromFile(QFile& file, QString* errorText /*= nullptr*/)
|
||||
{
|
||||
RimObservedData* observedData = nullptr;
|
||||
|
||||
if (!file.isOpen()) return nullptr;
|
||||
|
||||
QTextStream in(&file);
|
||||
QString fileContents = in.readAll();
|
||||
|
||||
RimObservedEclipseUserData* columnBasedUserData = new RimObservedEclipseUserData();
|
||||
observedData = columnBasedUserData;
|
||||
|
||||
this->m_observedDataArray.push_back(observedData);
|
||||
observedData->setSummaryHeaderFileName(file.fileName());
|
||||
observedData->createSummaryReaderInterface();
|
||||
observedData->updateMetaData();
|
||||
observedData->updateOptionSensitivity();
|
||||
|
||||
if (errorText && !observedData->errorMessagesFromReader().isEmpty())
|
||||
{
|
||||
errorText->append(observedData->errorMessagesFromReader());
|
||||
}
|
||||
|
||||
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow();
|
||||
if (mainPlotWindow)
|
||||
{
|
||||
mainPlotWindow->selectAsCurrentItem(observedData);
|
||||
mainPlotWindow->setExpanded(observedData);
|
||||
}
|
||||
|
||||
this->updateConnectedEditors();
|
||||
return observedData;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimObservedData* RimObservedDataCollection::createAndAddCvsObservedDataFromFile(QFile& file, QString* errorText /*= nullptr*/)
|
||||
{
|
||||
RimObservedData* observedData = nullptr;
|
||||
|
||||
if (!file.isOpen()) return nullptr;
|
||||
|
||||
QTextStream in(&file);
|
||||
QString fileContents = in.readAll();
|
||||
|
||||
RicPasteAsciiDataToSummaryPlotFeatureUi parseOptionsUi;
|
||||
parseOptionsUi.setPreviewText(fileContents);
|
||||
caf::PdmSettings::readFieldsFromApplicationStore(&parseOptionsUi);
|
||||
|
||||
caf::PdmUiPropertyViewDialog propertyDialog(NULL, &parseOptionsUi, "CSV Import Options", "");
|
||||
if (propertyDialog.exec() != QDialog::Accepted)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RimCsvUserData* columnBasedUserData = new RimCsvUserData();
|
||||
columnBasedUserData->setParseOptions(parseOptionsUi.parseOptions());
|
||||
observedData = columnBasedUserData;
|
||||
|
||||
this->m_observedDataArray.push_back(observedData);
|
||||
observedData->setSummaryHeaderFileName(file.fileName());
|
||||
observedData->createSummaryReaderInterface();
|
||||
observedData->updateMetaData();
|
||||
observedData->updateOptionSensitivity();
|
||||
|
||||
if (errorText && !observedData->errorMessagesFromReader().isEmpty())
|
||||
{
|
||||
errorText->append(observedData->errorMessagesFromReader());
|
||||
}
|
||||
|
||||
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow();
|
||||
if (mainPlotWindow)
|
||||
{
|
||||
mainPlotWindow->selectAsCurrentItem(observedData);
|
||||
mainPlotWindow->setExpanded(observedData);
|
||||
}
|
||||
|
||||
this->updateConnectedEditors();
|
||||
return observedData;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
class RimSummaryCase;
|
||||
class RimObservedData;
|
||||
class QFile;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -40,6 +41,10 @@ public:
|
||||
RimObservedData* createAndAddObservedDataFromFileName(const QString& fileName, QString* errorText = nullptr);
|
||||
std::vector<RimSummaryCase*> allObservedData();
|
||||
|
||||
private:
|
||||
RimObservedData* createAndAddRsmObservedDataFromFile(QFile& file, QString* errorText = nullptr);
|
||||
RimObservedData* createAndAddCvsObservedDataFromFile(QFile& file, QString* errorText = nullptr);
|
||||
|
||||
private:
|
||||
caf::PdmChildArrayField<RimObservedData*> m_observedDataArray;
|
||||
};
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace caf
|
||||
addItem(RifEclipseSummaryAddress::SUMMARY_BLOCK, "SUMMARY_BLOCK", "Block");
|
||||
addItem(RifEclipseSummaryAddress::SUMMARY_BLOCK_LGR, "SUMMARY_BLOCK_LGR", "Lgr-Block");
|
||||
addItem(RifEclipseSummaryAddress::SUMMARY_CALCULATED, "SUMMARY_CALCULATED", "Calculated");
|
||||
addItem(RifEclipseSummaryAddress::SUMMARY_IMPORTED, "SUMMARY_IMPORTED", "Imported");
|
||||
setDefault(RifEclipseSummaryAddress::SUMMARY_FIELD);
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,7 @@ void RimSummaryTimeAxisProperties::setVisibleRangeMin(double value)
|
||||
m_visibleTimeRangeMin = value;
|
||||
m_visibleDateRangeMin = fromDisplayTimeToDate(value);
|
||||
}
|
||||
auto s = m_visibleDateRangeMin().toString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -153,6 +154,7 @@ void RimSummaryTimeAxisProperties::setVisibleRangeMax(double value)
|
||||
m_visibleTimeRangeMax = value;
|
||||
m_visibleDateRangeMax = fromDisplayTimeToDate(value);
|
||||
}
|
||||
auto s = m_visibleDateRangeMax().toString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user