From 06d32ae97e9c033cee45bd14dae73f3b92a99acd Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 10 May 2013 15:35:33 +0200 Subject: [PATCH] Added groupId to case groups p4#: 21594 --- .../RimIdenticalGridCaseGroup.cpp | 3 + .../RimIdenticalGridCaseGroup.h | 1 + .../ProjectDataModel/RimProject.cpp | 88 +++++++++++++++---- ApplicationCode/ProjectDataModel/RimProject.h | 2 + .../ProjectDataModel/RimUiTreeModelPdm.cpp | 2 + 5 files changed, 79 insertions(+), 17 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp index 012fa95b23..2303f917ae 100644 --- a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp +++ b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp @@ -57,6 +57,9 @@ RimIdenticalGridCaseGroup::RimIdenticalGridCaseGroup() CAF_PDM_InitField(&name, "UserDescription", QString("Grid Case Group"), "Name", "", "", ""); + CAF_PDM_InitField(&groupId, "GroupId", -1, "Case Group ID", "", "" ,""); + groupId.setUiReadOnly(true); + CAF_PDM_InitFieldNoDefault(&statisticsCaseCollection, "StatisticsCaseCollection", "Derived Statistics", ":/Histograms16x16.png", "", ""); CAF_PDM_InitFieldNoDefault(&caseCollection, "CaseCollection", "Cases", ":/Cases16x16.png", "", ""); diff --git a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.h b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.h index c48351c9fa..e3da03cc8e 100644 --- a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.h +++ b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.h @@ -47,6 +47,7 @@ public: virtual ~RimIdenticalGridCaseGroup(); caf::PdmField name; + caf::PdmField groupId; caf::PdmField caseCollection; caf::PdmField statisticsCaseCollection; diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index b7c2fdcfb2..a1f7de4d3f 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -58,6 +58,9 @@ RimProject::RimProject(void) CAF_PDM_InitField(&nextValidCaseId, "NextValidCaseId", 0, "Next Valid Case ID", "", "" ,""); nextValidCaseId.setUiHidden(true); + CAF_PDM_InitField(&nextValidCaseGroupId, "NextValidCaseGroupId", 0, "Next Valid Case Group ID", "", "" ,""); + nextValidCaseGroupId.setUiHidden(true); + CAF_PDM_InitFieldNoDefault(&reservoirs, "Reservoirs", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&caseGroups, "CaseGroups", "", "", "", ""); @@ -102,6 +105,7 @@ void RimProject::close() fileName = ""; nextValidCaseId = 0; + nextValidCaseGroupId = 0; } //-------------------------------------------------------------------------------------------------- @@ -117,31 +121,64 @@ void RimProject::initAfterRead() this->setScriptDirectories(scriptDirectories); - // Find largest used caseId read from file - int largestCaseId = -1; - - std::vector cases; - allCases(cases); - - for (size_t i = 0; i < cases.size(); i++) + // Find largest used caseId read from file and make sure all cases have a valid caseId { - if (cases[i]->caseId > largestCaseId) + int largestId = -1; + + std::vector cases; + allCases(cases); + + for (size_t i = 0; i < cases.size(); i++) { - largestCaseId = cases[i]->caseId; + if (cases[i]->caseId > largestId) + { + largestId = cases[i]->caseId; + } + } + + if (largestId > this->nextValidCaseId) + { + this->nextValidCaseId = largestId + 1; + } + + // Assign case Id to cases with an invalid case Id + for (size_t i = 0; i < cases.size(); i++) + { + if (cases[i]->caseId < 0) + { + assignCaseIdToCase(cases[i]); + } } } - if (largestCaseId > nextValidCaseId) + // Find largest used groupId read from file and make sure all groups have a valid groupId { - nextValidCaseId = largestCaseId + 1; - } + int largestGroupId = -1; - // Assign case Id to cases with an invalid case Id - for (size_t i = 0; i < cases.size(); i++) - { - if (cases[i]->caseId < 0) + for (size_t i = 0; i < caseGroups.size(); i++) { - assignCaseIdToCase(cases[i]); + RimIdenticalGridCaseGroup* cg = caseGroups()[i]; + + if (cg->groupId > largestGroupId) + { + largestGroupId = cg->groupId; + } + } + + if (largestGroupId > this->nextValidCaseGroupId) + { + this->nextValidCaseGroupId = largestGroupId + 1; + } + + // Assign group Id to groups with an invalid Id + for (size_t i = 0; i < caseGroups.size(); i++) + { + RimIdenticalGridCaseGroup* cg = caseGroups()[i]; + + if (cg->groupId < 0) + { + assignIdToCaseGroup(cg); + } } } @@ -202,6 +239,8 @@ RimIdenticalGridCaseGroup* RimProject::createIdenticalCaseGroupFromMainCase(RimC CVF_ASSERT(equalGrid); RimIdenticalGridCaseGroup* group = new RimIdenticalGridCaseGroup; + assignIdToCaseGroup(group); + RimCase* createdCase = group->createAndAppendStatisticsCase(); assignCaseIdToCase(createdCase); @@ -239,6 +278,8 @@ void RimProject::moveEclipseCaseIntoCaseGroup(RimCase* rimReservoir) if (!foundGroup) { RimIdenticalGridCaseGroup* group = new RimIdenticalGridCaseGroup; + assignIdToCaseGroup(group); + group->addCase(rimReservoir); caseGroups().push_back(group); @@ -354,6 +395,19 @@ void RimProject::assignCaseIdToCase(RimCase* reservoirCase) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimProject::assignIdToCaseGroup(RimIdenticalGridCaseGroup* caseGroup) +{ + if (caseGroup) + { + caseGroup->groupId = nextValidCaseGroupId; + + nextValidCaseGroupId = nextValidCaseGroupId + 1; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimProject.h b/ApplicationCode/ProjectDataModel/RimProject.h index 93e034e178..41cd2379c6 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.h +++ b/ApplicationCode/ProjectDataModel/RimProject.h @@ -47,6 +47,7 @@ public: caf::PdmField treeViewState; caf::PdmField currentModelIndexPath; caf::PdmField nextValidCaseId; // Unique case ID within a project, used to identify a case from Octave scripts + caf::PdmField nextValidCaseGroupId; // Unique case group ID within a project, used to identify a case group from Octave scripts void setScriptDirectories(const QString& scriptDirectories); QString projectFileVersionString() const; @@ -61,6 +62,7 @@ public: void setProjectFileNameAndUpdateDependencies(const QString& fileName); void assignCaseIdToCase(RimCase* reservoirCase); + void assignIdToCaseGroup(RimIdenticalGridCaseGroup* caseGroup); private: RigMainGrid* registerCaseInGridCollection(RigCaseData* rigEclipseCase); diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp index a9dca3d859..3611926de0 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp @@ -599,6 +599,8 @@ RimIdenticalGridCaseGroup* RimUiTreeModelPdm::addCaseGroup(QModelIndex& inserted beginInsertRows(rootIndex, position, position); RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup; + proj->assignIdToCaseGroup(createdObject); + RimCase* createdReservoir = createdObject->createAndAppendStatisticsCase(); proj->assignCaseIdToCase(createdReservoir); createdObject->name = QString("Grid Case Group %1").arg(position + 1);