Added inherited object of MimeData to carry model index list

p4#: 20926
This commit is contained in:
Magne Sjaastad 2013-03-18 11:40:39 +01:00
parent e92ed43fc3
commit 62e4cac4b0
33 changed files with 472 additions and 106 deletions

View File

@ -24,7 +24,7 @@ include_directories(
)
# Use all cpp and h files in the subdirectories
# Use all h files in the subdirectories to make them available in the project
file( GLOB_RECURSE HEADER_FILES *.h )
list( APPEND CPP_SOURCES
@ -85,6 +85,7 @@ list( APPEND CPP_SOURCES
ProjectDataModel/Rim3dOverlayInfoConfig.cpp
ProjectDataModel/RimUiTreeModelPdm.cpp
ProjectDataModel/RimUiTreeView.cpp
ProjectDataModel/RimReservoirCellResultsCacher.cpp
)
# Populate the filenames into variable lists

View File

@ -46,7 +46,7 @@ RifEclipseOutputFileTools::~RifEclipseOutputFileTools()
//--------------------------------------------------------------------------------------------------
/// Get list of time step texts (dates)
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList<QDateTime>* timeSteps, bool* detectedFractionOfDay )
void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, std::vector<QDateTime>* timeSteps, bool* detectedFractionOfDay )
{
CVF_ASSERT(timeSteps);
CVF_ASSERT(ecl_file);
@ -84,7 +84,7 @@ void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList<QDateTi
}
}
QList<QDateTime> timeStepsFound;
std::vector<QDateTime> timeStepsFound;
if (hasFractionOfDay)
{
@ -110,7 +110,7 @@ void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList<QDateTi
reportDate = reportDate.addDays(floorDayValue);
QDateTime reportDateTime(reportDate, time);
if (timeStepsFound.indexOf(reportDateTime) < 0)
if (std::find(timeStepsFound.begin(), timeStepsFound.end(), reportDateTime) == timeStepsFound.end())
{
timeStepsFound.push_back(reportDateTime);
}
@ -132,7 +132,7 @@ void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList<QDateTi
CVF_ASSERT(reportDate.isValid());
QDateTime reportDateTime(reportDate);
if (timeStepsFound.indexOf(reportDateTime) < 0)
if (std::find(timeStepsFound.begin(), timeStepsFound.end(), reportDateTime) == timeStepsFound.end())
{
timeStepsFound.push_back(reportDateTime);
}

View File

@ -48,7 +48,7 @@ public:
static bool keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector<int>* values);
// static void timeStepsText(ecl_file_type* ecl_file, QStringList* timeSteps);
static void timeSteps(ecl_file_type* ecl_file, QList<QDateTime>* timeSteps, bool* detectedFractionOfDay = NULL);
static void timeSteps(ecl_file_type* ecl_file, std::vector<QDateTime>* timeSteps, bool* detectedFractionOfDay = NULL);
static bool fileSet(const QString& fileName, QStringList* fileSet);

View File

@ -46,9 +46,9 @@ public:
virtual void setFileSet(const QStringList& fileSet) = 0;
virtual void close() = 0;
virtual void setTimeSteps(const QList<QDateTime>& timeSteps) {};
virtual void setTimeSteps(const std::vector<QDateTime>& timeSteps) {};
virtual size_t timeStepCount() = 0;
virtual QList<QDateTime> timeSteps() = 0;
virtual std::vector<QDateTime> timeSteps() = 0;
virtual void resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts) = 0;
virtual bool results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector<double>* values) = 0;

View File

@ -97,7 +97,7 @@ void RifEclipseRestartFilesetAccess::close()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseRestartFilesetAccess::setTimeSteps(const QList<QDateTime>& timeSteps)
void RifEclipseRestartFilesetAccess::setTimeSteps(const std::vector<QDateTime>& timeSteps)
{
CVF_ASSERT(m_fileNames.size() == timeSteps.size());
m_timeSteps = timeSteps;
@ -114,7 +114,7 @@ size_t RifEclipseRestartFilesetAccess::timeStepCount()
//--------------------------------------------------------------------------------------------------
/// Get the time steps
//--------------------------------------------------------------------------------------------------
QList<QDateTime> RifEclipseRestartFilesetAccess::timeSteps()
std::vector<QDateTime> RifEclipseRestartFilesetAccess::timeSteps()
{
if (m_timeSteps.size() == 0)
{
@ -122,7 +122,7 @@ QList<QDateTime> RifEclipseRestartFilesetAccess::timeSteps()
size_t i;
for (i = 0; i < numSteps; i++)
{
QList<QDateTime> stepTime;
std::vector<QDateTime> stepTime;
openTimeStep(i);

View File

@ -39,9 +39,9 @@ public:
void setFileSet(const QStringList& fileSet);
void close();
void setTimeSteps(const QList<QDateTime>& timeSteps);
void setTimeSteps(const std::vector<QDateTime>& timeSteps);
size_t timeStepCount();
QList<QDateTime> timeSteps();
std::vector<QDateTime> timeSteps();
void resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts);
bool results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector<double>* values);
@ -53,7 +53,7 @@ private:
private:
QStringList m_fileNames;
QList<QDateTime> m_timeSteps;
std::vector<QDateTime> m_timeSteps;
std::vector< ecl_file_type* > m_ecl_files;
};

View File

@ -89,9 +89,9 @@ size_t RifEclipseUnifiedRestartFileAccess::timeStepCount()
//--------------------------------------------------------------------------------------------------
/// Get the time steps
//--------------------------------------------------------------------------------------------------
QList<QDateTime> RifEclipseUnifiedRestartFileAccess::timeSteps()
std::vector<QDateTime> RifEclipseUnifiedRestartFileAccess::timeSteps()
{
QList<QDateTime> timeSteps;
std::vector<QDateTime> timeSteps;
if (openFile())
{

View File

@ -42,7 +42,7 @@ public:
void close();
size_t timeStepCount();
QList<QDateTime> timeSteps();
std::vector<QDateTime> timeSteps();
void resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts);
bool results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector<double>* values);

View File

@ -432,7 +432,7 @@ bool RifReaderEclipseOutput::openAndReadActiveCellData(const QString& fileName,
m_dynamicResultsAccess = createDynamicResultsAccess(m_fileSet);
QList<QDateTime> mainCaseTimeSteps = mainEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->readerInterface()->timeSteps();
std::vector<QDateTime> mainCaseTimeSteps = mainEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->readerInterface()->timeSteps();
m_dynamicResultsAccess->setTimeSteps(mainCaseTimeSteps);
return true;
@ -608,7 +608,7 @@ bool RifReaderEclipseOutput::buildMetaData()
m_eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS),
RifReaderInterface::MATRIX_RESULTS, 1);
QList<QDateTime> staticDate;
std::vector<QDateTime> staticDate;
if (m_timeSteps.size() > 0)
{
staticDate.push_back(m_timeSteps.front());
@ -627,7 +627,7 @@ bool RifReaderEclipseOutput::buildMetaData()
m_eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS),
RifReaderInterface::FRACTURE_RESULTS, 1);
QList<QDateTime> staticDate;
std::vector<QDateTime> staticDate;
if (m_timeSteps.size() > 0)
{
staticDate.push_back(m_timeSteps.front());
@ -1045,7 +1045,7 @@ bool RifReaderEclipseOutput::openInitFile()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<QDateTime> RifReaderEclipseOutput::timeSteps()
std::vector<QDateTime> RifReaderEclipseOutput::timeSteps()
{
return m_timeSteps;
}

View File

@ -66,14 +66,14 @@ private:
QStringList validKeywordsForPorosityModel(const QStringList& keywords, const std::vector<size_t>& keywordDataItemCounts, const RigActiveCellInfo* activeCellInfo, const RigActiveCellInfo* fractureActiveCellInfo, PorosityModelResultType matrixOrFracture, size_t timeStepCount) const;
virtual QList<QDateTime> timeSteps();
virtual std::vector<QDateTime> timeSteps();
private:
QString m_fileName; // Name of file used to start accessing Eclipse output files
QStringList m_fileSet; // Set of files in filename's path with same base name as filename
RigEclipseCase* m_eclipseCase;
QList<QDateTime> m_timeSteps;
std::vector<QDateTime> m_timeSteps;
ecl_file_type* m_ecl_init_file; // File access to static results
cvf::ref<RifEclipseRestartDataAccess> m_dynamicResultsAccess; // File access to dynamic results

View File

@ -54,5 +54,5 @@ public:
virtual bool staticResult(const QString& result, PorosityModelResultType matrixOrFracture, std::vector<double>* values) = 0;
virtual bool dynamicResult(const QString& result, PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values) = 0;
virtual QList<QDateTime> timeSteps() { QList<QDateTime> timeSteps; return timeSteps; }
virtual std::vector<QDateTime> timeSteps() { std::vector<QDateTime> timeSteps; return timeSteps; }
};

View File

@ -34,7 +34,7 @@ bool RifReaderMockModel::open(const QString& fileName, RigEclipseCase* eclipseCa
RigReservoirCellResults* cellResults = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS);
QList<QDateTime> dates;
std::vector<QDateTime> dates;
for (int i = 0; i < static_cast<int>(m_reservoirBuilder.timeStepCount()); i++)
{
@ -49,7 +49,7 @@ bool RifReaderMockModel::open(const QString& fileName, RigEclipseCase* eclipseCa
if (m_reservoirBuilder.timeStepCount() == 0) return true;
QList<QDateTime> staticDates;
std::vector<QDateTime> staticDates;
staticDates.push_back(dates[0]);
for (int i = 0; i < static_cast<int>(m_reservoirBuilder.resultCount()); i++)
{

View File

@ -70,7 +70,7 @@ void RifReaderStatisticalCalculation::buildMetaData(RigEclipseCase* eclipseCase)
fractureModelResults->setTimeStepDates(resIndex, m_timeSteps);
}
QList<QDateTime> staticDate;
std::vector<QDateTime> staticDate;
if (m_timeSteps.size() > 0)
{
staticDate.push_back(m_timeSteps.front());
@ -111,7 +111,7 @@ void RifReaderStatisticalCalculation::setFractureResultNames(const QStringList&
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderStatisticalCalculation::setTimeSteps(const QList<QDateTime>& timesteps)
void RifReaderStatisticalCalculation::setTimeSteps(const std::vector<QDateTime>& timesteps)
{
m_timeSteps = timesteps;
}

View File

@ -28,23 +28,23 @@ public:
virtual ~RifReaderStatisticalCalculation();
// Virtual interface implementation
virtual bool open(const QString& fileName, RigEclipseCase* eclipseCase);
virtual bool open(const QString& fileName, RigEclipseCase* eclipseCase);
virtual void close() {}
virtual void close() {}
virtual bool staticResult(const QString& result, PorosityModelResultType matrixOrFracture, std::vector<double>* values );
virtual bool dynamicResult(const QString& result, PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values );
virtual bool staticResult(const QString& result, PorosityModelResultType matrixOrFracture, std::vector<double>* values );
virtual bool dynamicResult(const QString& result, PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values );
void setMatrixResultNames(const QStringList& staticResultNames, const QStringList& dynamicResultNames);
void setFractureResultNames(const QStringList& staticResultNames, const QStringList& dynamicResultNames);
void setMatrixResultNames(const QStringList& staticResultNames, const QStringList& dynamicResultNames);
void setFractureResultNames(const QStringList& staticResultNames, const QStringList& dynamicResultNames);
void setTimeSteps(const QList<QDateTime>& timesteps);
void setTimeSteps(const std::vector<QDateTime>& timesteps);
private:
void buildMetaData(RigEclipseCase* eclipseCase);
void buildMetaData(RigEclipseCase* eclipseCase);
private:
QList<QDateTime> m_timeSteps;
std::vector<QDateTime> m_timeSteps;
QStringList m_matrixDynamicResultNames;
QStringList m_fractureDynamicResultNames;

View File

@ -35,7 +35,9 @@
#include <QString>
#include "RimProject.h"
//--------------------------------------------------------------------------------------------------
CAF_PDM_SOURCE_INIT(RimReservoir, "RimReservoir");
//------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoir::RimReservoir()

View File

@ -40,12 +40,12 @@ class RimCaseCollection;
//==================================================================================================
class RimReservoir : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimReservoir();
virtual ~RimReservoir();
virtual bool openEclipseGridFile() = 0;
virtual bool openEclipseGridFile() { return false;}; // Should be pure virtual but PDM does not allow that.
RigEclipseCase* reservoirData();
const RigEclipseCase* reservoirData() const;
@ -78,5 +78,5 @@ private:
protected:
cvf::ref<RigEclipseCase> m_rigEclipseCase;
};
};

View File

@ -0,0 +1,164 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// 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 "RIStdInclude.h"
#include "RimReservoirCellResultsCacher.h"
#include "RigReservoirCellResults.h"
#include "RIApplication.h"
CAF_PDM_SOURCE_INIT(RimReservoirCellResultsCacher, "ReservoirCellResultCacher");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsCacher::RimReservoirCellResultsCacher()
: m_cellResults(NULL)
{
CAF_PDM_InitObject("Cacher", "", "", "");
CAF_PDM_InitField(&m_resultCacheFileName, "ResultCacheFileName", QString(), "UiDummyname", "", "" ,"");
m_resultCacheFileName.setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_resultCacheMetaData, "ResultCacheEntries", "UiDummyname", "", "", "");
m_resultCacheMetaData.setUiHidden(true);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsCacher::~RimReservoirCellResultsCacher()
{
m_resultCacheMetaData.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirCellResultsCacher::setupBeforeSave()
{
if (!m_cellResults) return;
const std::vector<RigReservoirCellResults::ResultInfo>& resInfo = m_cellResults->infoForEachResultIndex();
m_resultCacheMetaData.deleteAllChildObjects();
if(resInfo.size())
{
QDir::root().mkpath(getCacheDirectoryPath());
QString newValidCacheFileName = getValidCacheFileName();
QFile cacheFile(newValidCacheFileName);
if (!cacheFile.open(QIODevice::WriteOnly)) qWarning() << "Saving project: Can't open the cache file : " + newValidCacheFileName;
QDataStream stream(&cacheFile);
stream.setVersion(QDataStream::Qt_4_0);
stream << (quint32)0xCEECAC4E; // magic number
stream << (qint32)1; // Version
for (int rIdx = 0; rIdx < resInfo.size(); ++rIdx)
{
RimReservoirCellResultsCacheEntryInfo* cacheEntry = new RimReservoirCellResultsCacheEntryInfo;
m_resultCacheMetaData.push_back(cacheEntry);
cacheEntry->m_resultType = resInfo[rIdx].m_resultType;
cacheEntry->m_resultName = resInfo[rIdx].m_resultName;
cacheEntry->m_timeStepDates = resInfo[rIdx].m_timeStepDates;
cacheEntry->m_filePosition = cacheFile.pos();
for (int tsIdx = 0; tsIdx < resInfo[rIdx].m_timeStepDates.size() ; ++tsIdx)
{
std::vector<double>& data = m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex, tsIdx);
if (data.size())
{
cacheEntry->m_timeStepHasData.v().push_back(1);
for (size_t cIdx = 0; cIdx < data.size(); ++cIdx)
{
stream << data[cIdx];
}
}
else
{
cacheEntry->m_timeStepHasData.v().push_back(0);
}
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimReservoirCellResultsCacher::getValidCacheFileName()
{
QString cacheFileName;
if (m_resultCacheFileName().isEmpty())
{
QString newCacheDirPath = getCacheDirectoryPath();
QUuid guid = QUuid::createUuid();
cacheFileName = newCacheDirPath + "/" + guid.toString();
}
else
{
// Make the path correct related to the possibly new project filename
QString newCacheDirPath = getCacheDirectoryPath();
QFileInfo oldCacheFile(m_resultCacheFileName());
cacheFileName = newCacheDirPath + "/" + oldCacheFile.fileName();
}
return cacheFileName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimReservoirCellResultsCacher::getCacheDirectoryPath()
{
QString cacheDirPath;
QString projectFileName = RIApplication::instance()->project()->fileName();
QFileInfo fileInfo(projectFileName);
cacheDirPath = fileInfo.canonicalPath();
cacheDirPath += "/" + fileInfo.completeBaseName() + "_cache";
return cacheDirPath;
}
CAF_PDM_SOURCE_INIT(RimReservoirCellResultsCacheEntryInfo, "ResultCacheEntryInfo");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsCacheEntryInfo::RimReservoirCellResultsCacheEntryInfo()
{
CAF_PDM_InitObject("Cache Entry", "", "", "");
CAF_PDM_InitField(&m_resultType, "ResultType", caf::AppEnum<RimDefines::ResultCatType>(RimDefines::REMOVED), "ResultType", "", "" ,"");
CAF_PDM_InitField(&m_resultName, "ResultName", QString(), "ResultName", "", "" ,"");
CAF_PDM_InitFieldNoDefault(&m_timeStepDates, "TimeSteps", "TimeSteps", "", "" ,"");
CAF_PDM_InitField(&m_filePosition, "FilePositionDataStart", qint64(-1), "FilePositionDataStart", "", "" ,"");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsCacheEntryInfo::~RimReservoirCellResultsCacheEntryInfo()
{
}

View File

@ -0,0 +1,69 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// 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 <QDateTime>
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafAppEnum.h"
#include "RimDefines.h"
class RimReservoirCellResultsCacheEntryInfo;
class RigReservoirCellResults;
class RimReservoirCellResultsCacher : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimReservoirCellResultsCacher();
virtual ~RimReservoirCellResultsCacher();
//RigReservoirCellResults* cellResults() const { return m_cellResults; }
void setCellResults(RigReservoirCellResults* cellResults) { m_cellResults = cellResults; }
virtual void setupBeforeSave();
caf::PdmField<QString> m_resultCacheFileName;
caf::PdmPointersField<RimReservoirCellResultsCacheEntryInfo*> m_resultCacheMetaData;
private:
QString getValidCacheFileName();
QString getCacheDirectoryPath();
RigReservoirCellResults* m_cellResults;
};
class RimReservoirCellResultsCacheEntryInfo : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimReservoirCellResultsCacheEntryInfo();
virtual ~RimReservoirCellResultsCacheEntryInfo();
caf::PdmField<caf::AppEnum< RimDefines::ResultCatType> > m_resultType;
caf::PdmField<QString> m_resultName;
caf::PdmField< std::vector <QDateTime> > m_timeStepDates;
caf::PdmField< std::vector <int> > m_timeStepHasData;
caf::PdmField<qint64> m_filePosition;
};

View File

@ -22,6 +22,8 @@
#include "cafPdmPointer.h"
#include "cafUiTreeModelPdm.h"
#include <QMimeData>
class QFileSystemWatcher;
class RimCellPropertyFilter;
@ -31,6 +33,55 @@ class RimInputProperty;
class RimStatisticalCalculation;
class RimIdenticalGridCaseGroup;
//--------------------------------------------------------------------------------------------------
/// MimeData class used to carry a QModelIndexList
//--------------------------------------------------------------------------------------------------
class MimeDataWithIndexes : public QMimeData
{
Q_OBJECT
public:
MimeDataWithIndexes()
{
}
MimeDataWithIndexes(const MimeDataWithIndexes & other)
{
setIndexes(other.indexes());
}
void setIndexes(const QModelIndexList & indexes)
{
m_indexes = indexes;
}
const QModelIndexList& indexes() const { return m_indexes; }
virtual bool hasFormat( const QString &mimetype ) const
{
return (mimetype == formatName());
}
virtual QStringList formats() const
{
QStringList supportedFormats = QMimeData::formats();
supportedFormats << formatName();
return supportedFormats;
}
static QString formatName()
{
return "MimeDataWithIndexes";
}
private:
QModelIndexList m_indexes;
};
Q_DECLARE_METATYPE(MimeDataWithIndexes)
//==================================================================================================
///
///

View File

@ -110,7 +110,7 @@ TEST(RigReservoirTest, BasicTest)
}
int resultTimeStepCount = 2 * wellTimeStepCount;
QList<QDateTime> resultTimes;
std::vector<QDateTime> resultTimes;
for (i = 0; i < resultTimeStepCount; i++)
{
resultTimes.push_back(QDateTime(wellStartTime).addMonths(i * 6));

View File

@ -777,18 +777,18 @@ QDateTime RigReservoirCellResults::timeStepDate(size_t scalarResultIndex, size_t
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<QDateTime> RigReservoirCellResults::timeStepDates(size_t scalarResultIndex) const
std::vector<QDateTime> RigReservoirCellResults::timeStepDates(size_t scalarResultIndex) const
{
if (scalarResultIndex < m_resultInfos.size() )
return m_resultInfos[scalarResultIndex].m_timeStepDates;
else
return QList<QDateTime>();
return std::vector<QDateTime>();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigReservoirCellResults::setTimeStepDates(size_t scalarResultIndex, const QList<QDateTime>& dates)
void RigReservoirCellResults::setTimeStepDates(size_t scalarResultIndex, const std::vector<QDateTime>& dates)
{
CVF_ASSERT(scalarResultIndex < m_resultInfos.size() );

View File

@ -54,8 +54,8 @@ public:
bool isUsingGlobalActiveIndex(size_t scalarResultIndex) const;
QDateTime timeStepDate(size_t scalarResultIndex, size_t timeStepIndex) const;
QList<QDateTime> timeStepDates(size_t scalarResultIndex) const;
void setTimeStepDates(size_t scalarResultIndex, const QList<QDateTime>& dates);
std::vector<QDateTime> timeStepDates(size_t scalarResultIndex) const;
void setTimeStepDates(size_t scalarResultIndex, const std::vector<QDateTime>& dates);
// Find or create a slot for the results
size_t findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex);
@ -80,19 +80,8 @@ public:
double cellScalarResult(size_t scalarResultIndex, size_t timeStepIndex, size_t resultValueIndex);
static RifReaderInterface::PorosityModelResultType convertFromProjectModelPorosityModel(RimDefines::PorosityModelType porosityModel);
private:
size_t addStaticScalarResult(RimDefines::ResultCatType type, const QString& resultName, size_t resultValueCount);
private:
std::vector< std::vector< std::vector<double> > > m_cellScalarResults; ///< Scalar results for each timestep for each Result index (ResultVariable)
std::vector< std::pair<double, double> > m_maxMinValues; ///< Max min values for each Result index
std::vector< std::vector<size_t> > m_histograms; ///< Histogram for each Result Index
std::vector< std::pair<double, double> > m_p10p90; ///< P10 and p90 values for each Result Index
std::vector< double > m_meanValues; ///< Mean value for each Result Index
std::vector< std::vector< std::pair<double, double> > > m_maxMinValuesPrTs; ///< Max min values for each timestep and Result index
public:
class ResultInfo
{
public:
@ -103,9 +92,26 @@ private:
RimDefines::ResultCatType m_resultType;
QString m_resultName;
size_t m_gridScalarResultIndex;
QList<QDateTime> m_timeStepDates;
std::vector<QDateTime> m_timeStepDates;
};
const std::vector<ResultInfo>& infoForEachResultIndex() { return m_resultInfos;}
private:
size_t addStaticScalarResult(RimDefines::ResultCatType type, const QString& resultName, size_t resultValueCount);
private:
std::vector< std::vector< std::vector<double> > > m_cellScalarResults; ///< Scalar results on the complete reservoir for each Result index (ResultVariable) and timestep
std::vector< std::pair<double, double> > m_maxMinValues; ///< Max min values for each Result index
std::vector< std::vector<size_t> > m_histograms; ///< Histogram for each Result Index
std::vector< std::pair<double, double> > m_p10p90; ///< P10 and p90 values for each Result Index
std::vector< double > m_meanValues; ///< Mean value for each Result Index
std::vector< std::vector< std::pair<double, double> > > m_maxMinValuesPrTs; ///< Max min values for each Result index and timestep
private:
std::vector<ResultInfo> m_resultInfos;
cvf::ref<RifReaderInterface> m_readerInterface;
RigMainGrid* m_ownerMainGrid;

View File

@ -30,7 +30,7 @@ void RigStatistics::addNamedResult(RigReservoirCellResults* destinationCellResul
// Use time step dates from first result in first source case
CVF_ASSERT(m_sourceCases.size() > 0);
QList<QDateTime> sourceTimeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(0);
std::vector<QDateTime> sourceTimeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(0);
size_t destinationScalarResultIndex = destinationCellResults->addEmptyScalarResult(resultType, resultName);
CVF_ASSERT(destinationScalarResultIndex != cvf::UNDEFINED_SIZE_T);
@ -143,7 +143,7 @@ void RigStatistics::buildSourceMetaData(RimDefines::ResultCatType resultType, co
{
if (m_sourceCases.size() == 0) return;
QList<QDateTime> timeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(0);
std::vector<QDateTime> timeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(0);
for (size_t caseIdx = 1; caseIdx < m_sourceCases.size(); caseIdx++)
{

View File

@ -37,7 +37,7 @@ const RigWellResultFrame& RigWellResults::wellResultFrame(size_t resultTimeStepI
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigWellResults::computeMappingFromResultTimeIndicesToWellTimeIndices(const QList<QDateTime>& resultTimes)
void RigWellResults::computeMappingFromResultTimeIndicesToWellTimeIndices(const std::vector<QDateTime>& resultTimes)
{
m_resultTimeStepIndexToWellTimeStepIndex.clear();
if (m_wellCellsTimeSteps.size() == 0) return;

View File

@ -109,7 +109,7 @@ public:
void computeStaticWellCellPath();
void computeMappingFromResultTimeIndicesToWellTimeIndices(const QList<QDateTime>& resultTimes);
void computeMappingFromResultTimeIndicesToWellTimeIndices(const std::vector<QDateTime>& resultTimes);
public:
QString m_wellName;

View File

@ -546,7 +546,7 @@ void RIMainWindow::refreshAnimationActions()
|| app->activeReservoirView()->propertyFilterCollection()->hasActiveDynamicFilters()
|| app->activeReservoirView()->wellCollection()->hasVisibleWellPipes())
{
QList<QDateTime> timeStepDates = app->activeReservoirView()->currentGridCellResults()->timeStepDates(0);
std::vector<QDateTime> timeStepDates = app->activeReservoirView()->currentGridCellResults()->timeStepDates(0);
bool showHoursAndMinutes = false;
for (int i = 0; i < timeStepDates.size(); i++)
{

View File

@ -44,7 +44,6 @@ public:
void removeNullPtrs();
void addObject(PdmObject * obj);
// Needs renaming to objectsByType
template <typename T>
void objectsByType(std::vector<PdmPointer<T> >* typedObjects ) const
{
@ -57,6 +56,44 @@ public:
}
}
template <typename T>
void createCopyByType(std::vector<PdmPointer<T> >* copyOfTypedObjects) const
{
std::vector<PdmPointer<T> > sourceTypedObjects;
objectsByType(&sourceTypedObjects);
QString encodedXml;
{
// Write original objects to XML file
PdmObjectGroup typedObjectGroup;
for (size_t i = 0; i < sourceTypedObjects.size(); i++)
{
typedObjectGroup.addObject(sourceTypedObjects[i]);
}
QXmlStreamWriter xmlStream(&encodedXml);
xmlStream.setAutoFormatting(true);
typedObjectGroup.writeFields(xmlStream);
// Call clear to avoid destruction of objects
typedObjectGroup.objects().clear();
}
// Read back XML into object group, factory methods will be called that will create new objects
PdmObjectGroup destinationObjectGroup;
QXmlStreamReader xmlStream(encodedXml);
destinationObjectGroup.readFields(xmlStream);
for (size_t it = 0; it < destinationObjectGroup.objects.size(); it++)
{
T* obj = dynamic_cast<T*>(destinationObjectGroup.objects[it]);
if (obj) copyOfTypedObjects->push_back(obj);
}
// Call clear to avoid destruction of objects
destinationObjectGroup.objects().clear();
}
};
//==================================================================================================

View File

@ -59,13 +59,13 @@ bool PdmFieldHandle::assertValid() const
{
if (m_keyword == "UNDEFINED")
{
std::cout << "Detected use of non-initialized field\n";
std::cout << "PdmField: Detected use of non-initialized field. Did you forget to do CAF_PDM_InitField() on this field ?\n";
return false;
}
if (!PdmObject::isValidXmlElementName(m_keyword))
{
std::cout << "Detected keyword " << m_keyword.toStdString() << " which is an invalid Xml element name\n";
std::cout << "PdmField: The supplied keyword: \"" << m_keyword.toStdString() << "\" is an invalid XML element name, and will break your file format!\n";
return false;
}
@ -136,18 +136,40 @@ void PdmFieldReader<QString>::readFieldData(PdmField<QString> & field, QXmlStrea
//--------------------------------------------------------------------------------------------------
/// Specialized read operation for Bool`s
//--------------------------------------------------------------------------------------------------
void operator >> (QTextStream& str, bool& value)
QTextStream& operator >> (QTextStream& str, bool& value)
{
QString text;
str >> text;
if (text == "True" || text == "true" || text == "1" || text == "Yes" || text == "yes") value = true;
else value = false;
return str;
}
void operator << (QTextStream& str, const bool& value)
QTextStream& operator << (QTextStream& str, const bool& value)
{
if (value) str << "True ";
else str << "False ";
return str;
}
//--------------------------------------------------------------------------------------------------
/// Specialized read operation for QDateTimes`s
//--------------------------------------------------------------------------------------------------
#include <QDateTime>
QTextStream& operator >> (QTextStream& str, QDateTime& value)
{
QString text;
str >> text;
value = QDateTime::fromString(text, "yyyy_MM_dd-HH:mm:ss");
return str;
}
QTextStream& operator << (QTextStream& str, const QDateTime& value)
{
QString text = value.toString("yyyy_MM_dd-HH:mm:ss");
str << text;
return str;
}

View File

@ -212,6 +212,7 @@ public:
void push_back(DataType* pointer);
void set(size_t index, DataType* pointer);
void insert(size_t indexAfter, DataType* pointer);
void insert(size_t indexAfter, const std::vector<PdmPointer<DataType> >& objects);
void clear();
void erase(size_t index);

View File

@ -422,6 +422,25 @@ void PdmPointersField<DataType*>::insert(size_t indexAfter, DataType* pointer)
if (pointer) pointer->addParentField(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::insert(size_t indexAfter, const std::vector<PdmPointer<DataType> >& objects)
{
m_pointers.insert(m_pointers.begin()+indexAfter, objects.begin(), objects.end());
typename std::vector< PdmPointer< DataType > >::iterator it;
for (it = m_pointers.begin()+indexAfter; it != m_pointers.end(); ++it)
{
if (!it->isNull())
{
(*it)->addParentField(this);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -411,6 +411,24 @@ struct PdmFieldReader<std::list< PdmPointer<T> > >
} // End of namespace caf
//==================================================================================================
/// QTextStream Stream operator overloading for bool`s
/// Prints bool`s as "True"/"False", and reads them too
//==================================================================================================
QTextStream& operator >> (QTextStream& str, bool& value);
QTextStream& operator << (QTextStream& str, const bool& value);
//==================================================================================================
/// QTextStream Stream operator overloading for QDateTimes`s
///
//==================================================================================================
//class QDateTime;
QTextStream& operator >> (QTextStream& str, QDateTime& value);
QTextStream& operator << (QTextStream& str, const QDateTime& value);
//==================================================================================================
/// QTextStream Stream operator overloading for std::vector of things.
/// Makes automated IO of PdmField< std::vector< Whatever > possible as long as
@ -418,17 +436,18 @@ struct PdmFieldReader<std::list< PdmPointer<T> > >
//==================================================================================================
template < typename T >
void operator << (QTextStream& str, const std::vector<T>& sobj)
QTextStream& operator << (QTextStream& str, const std::vector<T>& sobj)
{
size_t i;
for (i = 0; i < sobj.size(); ++i)
{
str << sobj[i] << " ";
}
return str;
}
template < typename T >
void operator >> (QTextStream& str, std::vector<T>& sobj)
QTextStream& operator >> (QTextStream& str, std::vector<T>& sobj)
{
while (str.status() == QTextStream::Ok )
{
@ -436,13 +455,5 @@ void operator >> (QTextStream& str, std::vector<T>& sobj)
str >> d;
if (str.status() == QTextStream::Ok ) sobj.push_back(d);
}
return str;
}
//==================================================================================================
/// QTextStream Stream operator overloading for bool`s
/// Prints bool`s as "True"/"False", and reads them too
//==================================================================================================
void operator >> (QTextStream& str, bool& value);
void operator << (QTextStream& str, const bool& value);

View File

@ -37,29 +37,6 @@ namespace caf
//--------------------------------------------------------------------------------------------------
void PdmObject::readFields (QXmlStreamReader& xmlStream )
{
if (!xmlStream.isStartElement())
{
// Error
return ;
}
/*
Attributes will not be used ...
QXmlStreamAttributes attribs = xmlStream.attributes();
int i;
for (i = 0; i < attribs.size(); ++i)
{
QString name = attribs[i].name().toString();
PdmFieldBase* field = findField(name);
if (field)
{
//field->readFieldData(attribs[i].value().toString());
}
}
*/
bool isObjectFinished = false;
QXmlStreamReader::TokenType type;
while(!isObjectFinished)

View File

@ -61,14 +61,16 @@ class PdmUiEditorAttribute;
#define CAF_PDM_HEADER_INIT \
public: \
virtual QString classKeyword() { return classKeywordStatic(); } \
static QString classKeywordStatic()
static QString classKeywordStatic(); \
static bool Error_You_forgot_to_add_the_macro_CAF_PDM_HEADER_INIT_and_or_CAF_PDM_SOURCE_INIT_to_your_cpp_file_for_this_class()
/// CAF_PDM_SOURCE_INIT associates the file keyword used for storage with the class and initializes the factory
/// Place this in the cpp file, preferably above the constructor
#define CAF_PDM_SOURCE_INIT(ClassName, keyword) \
bool ClassName::Error_You_forgot_to_add_the_macro_CAF_PDM_HEADER_INIT_and_or_CAF_PDM_SOURCE_INIT_to_your_cpp_file_for_this_class() { return false;} \
QString ClassName::classKeywordStatic() { assert(PdmObject::isValidXmlElementName(keyword)); return keyword; } \
static bool PDM_OBJECT_STRING_CONCATENATE(pdm_object_factory_init_, __LINE__) = caf::PdmObjectFactory::instance()->registerCreator<ClassName>()
static bool PDM_OBJECT_STRING_CONCATENATE(pdm_object_factory_init_, __LINE__) = caf::PdmObjectFactory::instance()->registerCreator<ClassName>()
/// InitObject sets up the user interface related information for the object
/// Placed in the constructor of your PdmObject
@ -86,6 +88,8 @@ public: \
#define CAF_PDM_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis) \
{ \
static bool chekingThePresenceOfHeaderAndSourceInitMacros = Error_You_forgot_to_add_the_macro_CAF_PDM_HEADER_INIT_and_or_CAF_PDM_SOURCE_INIT_to_your_cpp_file_for_this_class(); \
\
static caf::PdmUiItemInfo objDescr(uiName, QIcon(QString(iconResourceName)), toolTip, whatsThis); \
addField(field, keyword, default, &objDescr); \
}
@ -94,6 +98,8 @@ public: \
#define CAF_PDM_InitFieldNoDefault(field, keyword, uiName, iconResourceName, toolTip, whatsThis) \
{ \
static bool chekingThePresenceOfHeaderAndSourceInitMacros = Error_You_forgot_to_add_the_macro_CAF_PDM_HEADER_INIT_and_or_CAF_PDM_SOURCE_INIT_to_your_cpp_file_for_this_class(); \
\
static caf::PdmUiItemInfo objDescr(uiName, QIcon(QString(iconResourceName)), toolTip, whatsThis); \
addFieldNoDefault(field, keyword, &objDescr); \
}