From d1cc48235523aac772f4395cef08ef945f7a9ee6 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 22 Mar 2013 11:47:46 +0100 Subject: [PATCH] Use same collection type for source cases and statistics cases in RimIdenticalGridCaseGroup p4#: 21053 --- ApplicationCode/Application/RIApplication.cpp | 2 +- .../ProjectDataModel/RigStatistics.cpp | 24 +++++++-- .../ProjectDataModel/RigStatistics.h | 4 +- .../RimIdenticalGridCaseGroup.cpp | 50 +++++++++++++------ .../RimIdenticalGridCaseGroup.h | 6 ++- .../RimStatisticalCalculation.cpp | 6 +-- .../RimStatisticalCalculation.h | 2 +- .../ProjectDataModel/RimUiTreeModelPdm.cpp | 37 ++++++++++---- .../ProjectDataModel/RimUiTreeView.cpp | 10 +++- 9 files changed, 104 insertions(+), 37 deletions(-) diff --git a/ApplicationCode/Application/RIApplication.cpp b/ApplicationCode/Application/RIApplication.cpp index 1d3b5c5073..dc2e5ba83a 100644 --- a/ApplicationCode/Application/RIApplication.cpp +++ b/ApplicationCode/Application/RIApplication.cpp @@ -286,7 +286,7 @@ bool RIApplication::loadProject(const QString& projectFileName) { if (m_project->caseGroups[cgIdx]->statisticsCaseCollection()) { - caf::PdmPointersField & statCases = m_project->caseGroups[cgIdx]->statisticsCaseCollection()->cases(); + caf::PdmPointersField & statCases = m_project->caseGroups[cgIdx]->statisticsCaseCollection()->reservoirs(); for (size_t scIdx = 0; scIdx < statCases.size(); ++scIdx) { casesToLoad.push_back(statCases[scIdx]); diff --git a/ApplicationCode/ProjectDataModel/RigStatistics.cpp b/ApplicationCode/ProjectDataModel/RigStatistics.cpp index 0ff0bf3619..781ae35874 100644 --- a/ApplicationCode/ProjectDataModel/RigStatistics.cpp +++ b/ApplicationCode/ProjectDataModel/RigStatistics.cpp @@ -57,6 +57,7 @@ QString createResultNameMin(const QString& resultName) { return resultName + "_ QString createResultNameMax(const QString& resultName) { return resultName + "_MAX"; } QString createResultNameMean(const QString& resultName) { return resultName + "_MEAN"; } QString createResultNameDev(const QString& resultName) { return resultName + "_DEV"; } +QString createResultNameRange(const QString& resultName) { return resultName + "_RANGE"; } //-------------------------------------------------------------------------------------------------- @@ -127,6 +128,7 @@ void RimStatisticsCaseEvaluator::evaluateForResults(const QList 0) { @@ -134,6 +136,7 @@ void RimStatisticsCaseEvaluator::evaluateForResults(const QList dataAccessObjectMax = NULL; cvf::ref dataAccessObjectMean = NULL; cvf::ref dataAccessObjectDev = NULL; + cvf::ref dataAccessObjectRange = NULL; { size_t scalarResultIndex = matrixResults->findScalarResultIndex(resultType, createResultNameMin(resultName)); @@ -219,13 +223,21 @@ void RimStatisticsCaseEvaluator::evaluateForResults(const QListfindScalarResultIndex(resultType, createResultNameRange(resultName)); + if (scalarResultIndex != cvf::UNDEFINED_SIZE_T) + { + dataAccessObjectRange = m_destinationCase->dataAccessObject(grid, RifReaderInterface::MATRIX_RESULTS, dataAccessTimeStepIndex, scalarResultIndex); + } + } + + double min, max, mean, dev, range; for (size_t cellIdx = 0; cellIdx < grid->cellCount(); cellIdx++) { std::vector values(dataAccesObjectList.size(), HUGE_VAL); size_t globalGridCellIdx = grid->globalGridCellIndex(cellIdx); - if (m_destinationCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->isActive(globalGridCellIdx)) + if (m_destinationCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->isActive(globalGridCellIdx)) { bool foundAnyValidValues = false; for (size_t caseIdx = 0; caseIdx < dataAccesObjectList.size(); caseIdx++) @@ -243,11 +255,12 @@ void RimStatisticsCaseEvaluator::evaluateForResults(const QListsetCellScalar(cellIdx, dev); } + + if (dataAccessObjectRange.notNull()) + { + dataAccessObjectRange->setCellScalar(cellIdx, range); + } } } } diff --git a/ApplicationCode/ProjectDataModel/RigStatistics.h b/ApplicationCode/ProjectDataModel/RigStatistics.h index de1b76764a..8d885ac4ab 100644 --- a/ApplicationCode/ProjectDataModel/RigStatistics.h +++ b/ApplicationCode/ProjectDataModel/RigStatistics.h @@ -47,7 +47,7 @@ public: } - void getStatistics(double& min, double& max, double& mean, double& dev) + void getStatistics(double& min, double& max, double& mean, double& dev, double& range) { evaluate(); @@ -55,6 +55,8 @@ public: max = m_max; mean = m_mean; dev = m_dev; + + range = m_max - m_min; } private: diff --git a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp index 064b3a6c8f..8d6b2efd98 100644 --- a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp +++ b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp @@ -47,7 +47,7 @@ RimIdenticalGridCaseGroup::RimIdenticalGridCaseGroup() CAF_PDM_InitFieldNoDefault(&caseCollection, "CaseCollection", "Cases", ":/Cases16x16.png", "", ""); caseCollection = new RimCaseCollection; - statisticsCaseCollection = new RimStatisticsCaseCollection; + statisticsCaseCollection = new RimCaseCollection; m_mainGrid = NULL; @@ -89,7 +89,7 @@ void RimIdenticalGridCaseGroup::addCase(RimReservoir* reservoir) caseCollection()->reservoirs().push_back(reservoir); - if (statisticsCaseCollection->cases().size() == 0) + if (statisticsCaseCollection->reservoirs().size() == 0) { createAndAppendStatisticsCase(); } @@ -174,9 +174,9 @@ void RimIdenticalGridCaseGroup::loadMainCaseAndActiveCellInfo() // Check if we need to calculate the union of the active cells bool foundResultsInCache = false; - for (size_t i = 0; i < statisticsCaseCollection()->cases.size(); i++) + for (size_t i = 0; i < statisticsCaseCollection()->reservoirs.size(); i++) { - RimStatisticsCase* rimReservoir = statisticsCaseCollection()->cases[i]; + RimReservoir* rimReservoir = statisticsCaseCollection()->reservoirs[i]; // Check if any results are stored in cache if (rimReservoir->results(RifReaderInterface::MATRIX_RESULTS)->storedResultsCount() > 0 || @@ -194,9 +194,9 @@ void RimIdenticalGridCaseGroup::loadMainCaseAndActiveCellInfo() // "Load" the statistical cases - for (size_t i = 0; i < statisticsCaseCollection()->cases.size(); i++) + for (size_t i = 0; i < statisticsCaseCollection()->reservoirs.size(); i++) { - RimStatisticsCase* rimReservoir = statisticsCaseCollection()->cases[i]; + RimReservoir* rimReservoir = statisticsCaseCollection()->reservoirs[i]; rimReservoir->openEclipseGridFile(); @@ -297,14 +297,14 @@ void RimIdenticalGridCaseGroup::computeUnionOfActiveCells() //-------------------------------------------------------------------------------------------------- RimStatisticsCase* RimIdenticalGridCaseGroup::createAndAppendStatisticsCase() { - RimStatisticsCase* newObject = new RimStatisticsCase; + RimStatisticsCase* newStatisticsCase = new RimStatisticsCase; - newObject->caseName = QString("Statistics ") + QString::number(statisticsCaseCollection()->cases.size()+1); - statisticsCaseCollection()->cases.push_back(newObject); + newStatisticsCase->caseName = QString("Statistics ") + QString::number(statisticsCaseCollection()->reservoirs.size()+1); + statisticsCaseCollection()->reservoirs.push_back(newStatisticsCase); - newObject->openEclipseGridFile(); + newStatisticsCase->openEclipseGridFile(); - return newObject; + return newStatisticsCase; } //-------------------------------------------------------------------------------------------------- @@ -312,9 +312,9 @@ RimStatisticsCase* RimIdenticalGridCaseGroup::createAndAppendStatisticsCase() //-------------------------------------------------------------------------------------------------- void RimIdenticalGridCaseGroup::updateMainGridAndActiveCellsForStatisticsCases() { - for (size_t i = 0; i < statisticsCaseCollection->cases().size(); i++) + for (size_t i = 0; i < statisticsCaseCollection->reservoirs().size(); i++) { - RimStatisticsCase* rimStaticsCase = statisticsCaseCollection->cases[i]; + RimReservoir* rimStaticsCase = statisticsCaseCollection->reservoirs[i]; rimStaticsCase->reservoirData()->setMainGrid(this->mainGrid()); @@ -330,9 +330,11 @@ void RimIdenticalGridCaseGroup::updateMainGridAndActiveCellsForStatisticsCases() //-------------------------------------------------------------------------------------------------- void RimIdenticalGridCaseGroup::clearStatisticsResults() { - for (size_t i = 0; i < statisticsCaseCollection->cases().size(); i++) + for (size_t i = 0; i < statisticsCaseCollection->reservoirs().size(); i++) { - RimStatisticsCase* rimStaticsCase = statisticsCaseCollection->cases[i]; + RimReservoir* rimStaticsCase = statisticsCaseCollection->reservoirs[i]; + if (!rimStaticsCase) continue; + rimStaticsCase->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->clearAllResults(); rimStaticsCase->results(RifReaderInterface::FRACTURE_RESULTS)->cellResults()->clearAllResults(); @@ -385,3 +387,21 @@ RigActiveCellInfo* RimIdenticalGridCaseGroup::unionOfActiveCells(RifReaderInterf return m_unionOfFractureActiveCells.p(); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimIdenticalGridCaseGroup::isStatisticsCaseCollection(RimCaseCollection* rimCaseCollection) +{ + std::vector fields; + rimCaseCollection->parentFields(fields); + if (fields.size() == 1) + { + if (fields[0]->keyword() == "StatisticsCaseCollection") + { + return true; + } + } + + return false; +} diff --git a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.h b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.h index 4b5e1564f0..fb1218dade 100644 --- a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.h +++ b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.h @@ -51,8 +51,8 @@ public: RimStatisticsCase* createAndAppendStatisticsCase(); - caf::PdmField caseCollection; - caf::PdmField statisticsCaseCollection; + caf::PdmField caseCollection; + caf::PdmField statisticsCaseCollection; void loadMainCaseAndActiveCellInfo(); @@ -61,6 +61,8 @@ public: void computeUnionOfActiveCells(); + static bool isStatisticsCaseCollection(RimCaseCollection* rimCaseCollection); + protected: virtual caf::PdmFieldHandle* userDescriptionField(); diff --git a/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.cpp b/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.cpp index da0a4371a8..5b75d52b78 100644 --- a/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.cpp +++ b/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.cpp @@ -98,9 +98,9 @@ void RimStatisticsCase::defineUiOrdering(QString uiConfigName, caf::PdmUiOrderin //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimStatisticsCaseCollection* RimStatisticsCase::parentStatisticsCaseCollection() +RimCaseCollection* RimStatisticsCase::parentStatisticsCaseCollection() { - std::vector parentObjects; + std::vector parentObjects; this->parentObjectsOfType(parentObjects); if (parentObjects.size() > 0) @@ -210,7 +210,7 @@ void RimStatisticsCase::getSourceCases(std::vector& sourceCases) //-------------------------------------------------------------------------------------------------- RimIdenticalGridCaseGroup* RimStatisticsCase::caseGroup() { - RimStatisticsCaseCollection* parentCollection = parentStatisticsCaseCollection(); + RimCaseCollection* parentCollection = parentStatisticsCaseCollection(); if (parentCollection) { return parentCollection->parentCaseGroup(); diff --git a/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.h b/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.h index 5c828d4451..df9dd0f022 100644 --- a/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.h +++ b/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.h @@ -50,7 +50,7 @@ public: caf::PdmField m_resultName; - RimStatisticsCaseCollection* parentStatisticsCaseCollection(); + RimCaseCollection* parentStatisticsCaseCollection(); virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) const; void computeStatistics(); diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp index 4d54ded8c5..cc3f59602a 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp @@ -229,8 +229,18 @@ void RimUiTreeModelPdm::deleteReservoir(RimReservoir* reservoir) removeRows_special(mi.row(), 1, mi.parent()); } - RimProject* proj = RIApplication::instance()->project(); - proj->removeCaseFromAllGroups(reservoir); + if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(caseCollection)) + { + RimIdenticalGridCaseGroup* caseGroup = caseCollection->parentCaseGroup(); + CVF_ASSERT(caseGroup); + + caseGroup->statisticsCaseCollection()->reservoirs.removeChildObject(reservoir); + } + else + { + RimProject* proj = RIApplication::instance()->project(); + proj->removeCaseFromAllGroups(reservoir); + } delete reservoir; @@ -492,25 +502,32 @@ RimStatisticsCase* RimUiTreeModelPdm::addStatisticalCalculation(const QModelInde position = itemIndex.row(); collectionIndex = itemIndex.parent(); } - else if (dynamic_cast(currentItem->dataObject().p())) + else if (dynamic_cast(currentItem->dataObject().p())) { - RimStatisticsCaseCollection* statColl = dynamic_cast(currentItem->dataObject().p()); + RimCaseCollection* statColl = dynamic_cast(currentItem->dataObject().p()); caseGroup = statColl->parentCaseGroup(); parentCollectionItem = currentItem; position = parentCollectionItem->childCount(); collectionIndex = itemIndex; } - beginInsertRows(collectionIndex, position, position); + if (parentCollectionItem && caseGroup) + { + beginInsertRows(collectionIndex, position, position); - RimStatisticsCase* createdObject = caseGroup->createAndAppendStatisticsCase(); - caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentCollectionItem, position, createdObject); + RimStatisticsCase* createdObject = caseGroup->createAndAppendStatisticsCase(); + caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentCollectionItem, position, createdObject); - endInsertRows(); + endInsertRows(); - insertedModelIndex = index(position, 0, collectionIndex); + insertedModelIndex = index(position, 0, collectionIndex); - return createdObject; + return createdObject; + } + else + { + return NULL; + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp index 9fe884f306..9189928f68 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp @@ -196,6 +196,14 @@ void RimUiTreeView::contextMenuEvent(QContextMenuEvent* event) { QMenu menu; menu.addAction(m_pasteAction); + + // Check if parent field is a StatisticsCaseCollection + RimCaseCollection* rimCaseCollection = dynamic_cast(uiItem->dataObject().p()); + if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(rimCaseCollection)) + { + menu.addAction(QString("New Statistics Case"), this, SLOT(slotNewStatisticsCase())); + } + menu.exec(event->globalPos()); } } @@ -803,7 +811,7 @@ void RimUiTreeView::slotCloseCase() group.addObject(uiItem->dataObject().p()); } - std::vector > typedObjects; + std::vector > typedObjects; group.objectsByType(&typedObjects); for (size_t i = 0; i < typedObjects.size(); i++)