virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) { RimProject* proj = RiaApplication::instance()->project(); RimEclipseCaseCollection* analysisModels = (proj && proj->activeOilField()) ? proj->activeOilField()->analysisModels() : NULL; if (analysisModels) { std::vector<QString> groupNames; std::vector<qint64> groupIds; size_t caseGroupCount = analysisModels->caseGroups().size(); quint64 byteCount = 0; for (size_t i = 0; i < caseGroupCount; i++) { RimIdenticalGridCaseGroup* cg = analysisModels->caseGroups()[i]; QString caseGroupName = cg->name; qint64 caseGroupId = cg->groupId; byteCount += caseGroupName.size() * sizeof(QChar); byteCount += sizeof(qint64); groupNames.push_back(caseGroupName); groupIds.push_back(caseGroupId); } socketStream << (quint64)byteCount; socketStream << (quint64)caseGroupCount; for (size_t i = 0; i < caseGroupCount; i++) { socketStream << groupNames[i]; socketStream << groupIds[i]; } } else { // ERROR } return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicImportInputEclipseCaseOpmFeature::onActionTriggered(bool isChecked) { RiaApplication* app = RiaApplication::instance(); QString defaultDir = app->lastUsedDialogDirectory("INPUT_FILES"); QString fileName = QFileDialog::getOpenFileName(RiuMainWindow::instance(), "Import Eclipse Input file", defaultDir, "Eclipse Input Files (*.GRDECL);;All Files (*.*)"); if (fileName.isEmpty()) return; // Remember the path to next time app->setLastUsedDialogDirectory("INPUT_FILES", QFileInfo(fileName).absolutePath()); RimProject* proj = app->project(); RimEclipseCaseCollection* analysisModels = proj->activeOilField() ? proj->activeOilField()->analysisModels() : NULL; if (analysisModels) { // This code originates from RiaApplication::openInputEclipseCaseFromFileNames RimEclipseInputCaseOpm* rimInputReservoir = new RimEclipseInputCaseOpm(); proj->assignCaseIdToCase(rimInputReservoir); rimInputReservoir->importNewEclipseGridAndProperties(fileName); analysisModels->cases.push_back(rimInputReservoir); RimEclipseView* riv = rimInputReservoir->createAndAddReservoirView(); riv->cellResult()->setResultType(RimDefines::INPUT_PROPERTY); riv->hasUserRequestedAnimation = true; riv->loadDataAndUpdate(); if (!riv->cellResult()->hasResult()) { riv->cellResult()->setResultVariable(RimDefines::undefinedResultName()); } analysisModels->updateConnectedEditors(); RiuMainWindow::instance()->selectAsCurrentItem(riv->cellResult()); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicPasteEclipseCasesFeature::addCasesToGridCaseGroup(PdmObjectGroup& objectGroup, RimIdenticalGridCaseGroup* gridCaseGroup) { RimProject* proj = RiaApplication::instance()->project(); CVF_ASSERT(proj); std::vector<RimEclipseResultCase*> resultCases; for (size_t i = 0; i < objectGroup.objects.size(); i++) { RimEclipseResultCase* eclCase = dynamic_cast<RimEclipseResultCase*>(objectGroup.objects[i]); if (eclCase) { RimEclipseResultCase* eclCaseCopy = dynamic_cast<RimEclipseResultCase*>(eclCase->copyByXmlSerialization(PdmDefaultObjectFactory::instance())); resultCases.push_back(eclCaseCopy); } } if (resultCases.size() == 0) { return; } RimEclipseResultCase* mainResultCase = NULL; std::vector< std::vector<int> > mainCaseGridDimensions; // Read out main grid and main grid dimensions if present in case group if (gridCaseGroup->mainCase()) { mainResultCase = dynamic_cast<RimEclipseResultCase*>(gridCaseGroup->mainCase()); CVF_ASSERT(mainResultCase); mainResultCase->readGridDimensions(mainCaseGridDimensions); } std::vector<RimEclipseResultCase*> insertedCases; // Add cases to case group for (size_t i = 0; i < resultCases.size(); i++) { RimEclipseResultCase* rimResultReservoir = resultCases[i]; proj->assignCaseIdToCase(rimResultReservoir); if (gridCaseGroup->contains(rimResultReservoir)) { continue; } insertedCases.push_back(rimResultReservoir); } // Load stuff for (size_t i = 0; i < insertedCases.size(); i++) { RimEclipseResultCase* rimResultReservoir = insertedCases[i]; if (!mainResultCase) { rimResultReservoir->openEclipseGridFile(); rimResultReservoir->readGridDimensions(mainCaseGridDimensions); mainResultCase = rimResultReservoir; } else { std::vector< std::vector<int> > caseGridDimensions; rimResultReservoir->readGridDimensions(caseGridDimensions); bool identicalGrid = RigGridManager::isGridDimensionsEqual(mainCaseGridDimensions, caseGridDimensions); if (!identicalGrid) { continue; } if (!rimResultReservoir->openAndReadActiveCellData(mainResultCase->reservoirData())) { CVF_ASSERT(false); } } RimOilField* activeOilField = proj ? proj->activeOilField() : NULL; RimEclipseCaseCollection* analysisModels = (activeOilField) ? activeOilField->analysisModels() : NULL; if (analysisModels) analysisModels->insertCaseInCaseGroup(gridCaseGroup, rimResultReservoir); caf::PdmDocument::updateUiIconStateRecursively(rimResultReservoir); gridCaseGroup->updateConnectedEditors(); for (size_t rvIdx = 0; rvIdx < rimResultReservoir->reservoirViews.size(); rvIdx++) { RimEclipseView* riv = rimResultReservoir->reservoirViews()[rvIdx]; riv->loadDataAndUpdate(); } } }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) { int argCaseGroupId = -1; if (args.size() == 2) { argCaseGroupId = args[1].toInt(); } RimProject* proj = RiaApplication::instance()->project(); RimEclipseCaseCollection* analysisModels = (proj && proj->activeOilField()) ? proj->activeOilField()->analysisModels() : NULL; if (analysisModels) { std::vector<RimCase*> cases; if (argCaseGroupId == -1) { proj->allCases(cases); } else { RimIdenticalGridCaseGroup* caseGroup = NULL; for (size_t i = 0; i < analysisModels->caseGroups().size(); i++) { RimIdenticalGridCaseGroup* cg = analysisModels->caseGroups()[i]; if (argCaseGroupId == cg->groupId()) { caseGroup = cg; } } if (caseGroup) { for (size_t i = 0; i < caseGroup->statisticsCaseCollection()->reservoirs.size(); i++) { cases.push_back(caseGroup->statisticsCaseCollection()->reservoirs[i]); } for (size_t i = 0; i < caseGroup->caseCollection()->reservoirs.size(); i++) { cases.push_back(caseGroup->caseCollection()->reservoirs[i]); } } } std::vector<qint64> caseIds; std::vector<QString> caseNames; std::vector<QString> caseTypes; std::vector<qint64> caseGroupIds; getCaseInfoFromCases(cases, caseIds, caseNames, caseTypes, caseGroupIds); quint64 byteCount = sizeof(quint64); quint64 caseCount = caseIds.size(); for (size_t i = 0; i < caseCount; i++) { byteCount += 2*sizeof(qint64); byteCount += caseNames[i].size() * sizeof(QChar); byteCount += caseTypes[i].size() * sizeof(QChar); } socketStream << byteCount; socketStream << caseCount; for (size_t i = 0; i < caseCount; i++) { socketStream << caseIds[i]; socketStream << caseNames[i]; socketStream << caseTypes[i]; socketStream << caseGroupIds[i]; } } return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimProject::initScriptDirectories() { // // TODO : Must store content of scripts in project file and notify user if stored content is different from disk on execute and edit // RiaApplication* app = RiaApplication::instance(); QString scriptDirectories = app->scriptDirectories(); this->setScriptDirectories(scriptDirectories); // Find largest used caseId read from file and make sure all cases have a valid caseId { int largestId = -1; std::vector<RimCase*> cases; allCases(cases); for (size_t i = 0; i < cases.size(); i++) { 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]); } } } // Find largest used groupId read from file and make sure all groups have a valid groupId RimEclipseCaseCollection* analysisModels = activeOilField() ? activeOilField()->analysisModels() : nullptr; if (analysisModels) { int largestGroupId = -1; for (size_t i = 0; i < analysisModels->caseGroups().size(); i++) { RimIdenticalGridCaseGroup* cg = analysisModels->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 < analysisModels->caseGroups().size(); i++) { RimIdenticalGridCaseGroup* cg = analysisModels->caseGroups()[i]; if (cg->groupId < 0) { assignIdToCaseGroup(cg); } } } }