From 2e49670f4046723c7f572f7f15d15a9b8d316b7f Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Fri, 23 Aug 2019 11:25:00 +0200 Subject: [PATCH 1/4] #4578 Add commands for create and clone view --- .../CMakeLists_files.cmake | 4 + .../CommandFileInterface/RicfCloneView.cpp | 80 +++++++++++++++++ .../CommandFileInterface/RicfCloneView.h | 41 +++++++++ .../CommandFileInterface/RicfCreateView.cpp | 85 +++++++++++++++++++ .../CommandFileInterface/RicfCreateView.h | 52 ++++++++++++ .../CommandFileInterface/RicfLoadCase.cpp | 1 - .../GrpcInterface/GrpcProtos/Commands.proto | 20 ++++- .../GrpcInterface/Python/rips/Case.py | 14 ++- .../GrpcInterface/Python/rips/Commands.py | 10 ++- .../Python/rips/GridCaseGroup.py | 4 +- .../GrpcInterface/Python/rips/Instance.py | 4 +- .../GrpcInterface/Python/rips/Project.py | 10 +-- .../Python/rips/PythonExamples/AllCases.py | 4 + .../Python/rips/PythonExamples/ViewExample.py | 8 +- .../GrpcInterface/Python/rips/View.py | 20 ++++- .../GrpcInterface/Python/rips/__init__.py | 1 - .../ProjectDataModel/Rim3dView.cpp | 3 - .../ProjectDataModel/RimEclipseCase.cpp | 4 +- .../ProjectDataModel/RimGeoMechCase.cpp | 27 +++++- .../ProjectDataModel/RimGeoMechCase.h | 1 + .../ProjectDataModel/RimGeoMechView.cpp | 2 +- .../ProjectDataModel/RimGeoMechView.h | 2 +- 22 files changed, 368 insertions(+), 29 deletions(-) create mode 100644 ApplicationCode/CommandFileInterface/RicfCloneView.cpp create mode 100644 ApplicationCode/CommandFileInterface/RicfCloneView.h create mode 100644 ApplicationCode/CommandFileInterface/RicfCreateView.cpp create mode 100644 ApplicationCode/CommandFileInterface/RicfCreateView.h diff --git a/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake b/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake index 17f60f1f6e..933045014f 100644 --- a/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake +++ b/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake @@ -31,6 +31,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.h ${CMAKE_CURRENT_LIST_DIR}/RicfExportFlowCharacteristics.h ${CMAKE_CURRENT_LIST_DIR}/RicfCreateGridCaseGroup.h ${CMAKE_CURRENT_LIST_DIR}/RicfCreateStatisticsCase.h +${CMAKE_CURRENT_LIST_DIR}/RicfCreateView.h +${CMAKE_CURRENT_LIST_DIR}/RicfCloneView.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -65,6 +67,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfExportFlowCharacteristics.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfCreateGridCaseGroup.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfCreateStatisticsCase.cpp +${CMAKE_CURRENT_LIST_DIR}/RicfCreateView.cpp +${CMAKE_CURRENT_LIST_DIR}/RicfCloneView.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/CommandFileInterface/RicfCloneView.cpp b/ApplicationCode/CommandFileInterface/RicfCloneView.cpp new file mode 100644 index 0000000000..ed78b7b359 --- /dev/null +++ b/ApplicationCode/CommandFileInterface/RicfCloneView.cpp @@ -0,0 +1,80 @@ +#include "RicfCloneView.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" + +#include "RicfCreateView.h" + +#include "Rim3dView.h" +#include "RimEclipseCase.h" +#include "RimEclipseView.h" +#include "RimGeoMechCase.h" +#include "RimGeoMechView.h" +#include "RimProject.h" + +#include "Riu3DMainWindowTools.h" + +#include "cafSelectionManager.h" + +#include + +CAF_PDM_SOURCE_INIT(RicfCloneView, "cloneView"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicfCloneView::RicfCloneView() +{ + RICF_InitField(&m_viewId, "viewId", -1, "View Id", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicfCommandResponse RicfCloneView::execute() +{ + RimProject* project = RiaApplication::instance()->project(); + std::vector allViews; + project->descendantsIncludingThisOfType(allViews); + + for (Rim3dView* view : allViews) + { + if (view->id() == m_viewId()) + { + const RimEclipseView* eclipseView = dynamic_cast(view); + const RimGeoMechView* geoMechView = dynamic_cast(view); + + int newViewId = -1; + if (eclipseView) + { + RimEclipseCase* eclipseCase = eclipseView->eclipseCase(); + RimEclipseView* newEclipseView = eclipseCase->createCopyAndAddView(eclipseView); + newViewId = newEclipseView->id(); + newEclipseView->loadDataAndUpdate(); + eclipseCase->updateConnectedEditors(); + Riu3DMainWindowTools::setExpanded(newEclipseView); + } + else if (geoMechView) + { + RimGeoMechCase* geoMechCase = geoMechView->geoMechCase(); + RimGeoMechView* newGeoMechView = geoMechCase->createCopyAndAddView(geoMechView); + newViewId = newGeoMechView->id(); + view->loadDataAndUpdate(); + geoMechCase->updateConnectedEditors(); + Riu3DMainWindowTools::setExpanded(view); + } + + if (newViewId) + { + RicfCommandResponse response; + response.setResult(new RicfCreateViewResult(newViewId)); + return response; + + } + } + } + + QString error = QString("cloneView: Could not clone view with id %1").arg(m_viewId()); + RiaLogging::error(error); + return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error); +} diff --git a/ApplicationCode/CommandFileInterface/RicfCloneView.h b/ApplicationCode/CommandFileInterface/RicfCloneView.h new file mode 100644 index 0000000000..64e96da95a --- /dev/null +++ b/ApplicationCode/CommandFileInterface/RicfCloneView.h @@ -0,0 +1,41 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RicfCommandObject.h" + +#include "cafPdmField.h" + +//================================================================================================== +// +// +// +//================================================================================================== +class RicfCloneView : public RicfCommandObject +{ + CAF_PDM_HEADER_INIT; + +public: + RicfCloneView(); + + RicfCommandResponse execute() override; + +private: + caf::PdmField m_viewId; +}; diff --git a/ApplicationCode/CommandFileInterface/RicfCreateView.cpp b/ApplicationCode/CommandFileInterface/RicfCreateView.cpp new file mode 100644 index 0000000000..51ed5117e7 --- /dev/null +++ b/ApplicationCode/CommandFileInterface/RicfCreateView.cpp @@ -0,0 +1,85 @@ +#include "RicfCreateView.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" + +#include "Rim3dView.h" +#include "RimEclipseCase.h" +#include "RimEclipseView.h" +#include "RimGeoMechCase.h" +#include "RimGeoMechView.h" +#include "RimProject.h" + +#include "Riu3DMainWindowTools.h" + +#include "cafSelectionManager.h" + +#include + +CAF_PDM_SOURCE_INIT(RicfCreateViewResult, "createViewResult"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicfCreateViewResult::RicfCreateViewResult(int viewId /*= -1*/) +{ + CAF_PDM_InitObject("view_result", "", "", ""); + CAF_PDM_InitField(&this->viewId, "viewId", viewId, "", "", "", ""); +} + +CAF_PDM_SOURCE_INIT(RicfCreateView, "createView"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicfCreateView::RicfCreateView() +{ + RICF_InitField(&m_caseId, "caseId", -1, "Case Id", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicfCommandResponse RicfCreateView::execute() +{ + RimProject* project = RiaApplication::instance()->project(); + std::vector allCases; + project->allCases(allCases); + + for (RimCase* rimCase : allCases) + { + if (rimCase->caseId == m_caseId()) + { + int viewId = -1; + RimEclipseCase* eclipseCase = dynamic_cast(rimCase); + RimGeoMechCase* geoMechCase = dynamic_cast(rimCase); + if (eclipseCase) + { + RimEclipseView* view = eclipseCase->createAndAddReservoirView(); + viewId = view->id(); + view->loadDataAndUpdate(); + eclipseCase->updateConnectedEditors(); + Riu3DMainWindowTools::setExpanded(view); + } + else if (geoMechCase) + { + RimGeoMechView* view = geoMechCase->createAndAddReservoirView(); + viewId = view->id(); + view->loadDataAndUpdate(); + geoMechCase->updateConnectedEditors(); + Riu3DMainWindowTools::setExpanded(view); + } + + if (viewId >= 0) + { + RicfCommandResponse response; + response.setResult(new RicfCreateViewResult(viewId)); + return response; + } + } + } + + QString error = QString("createView: Could not create view for case id %1").arg(m_caseId()); + RiaLogging::error(error); + return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error); +} diff --git a/ApplicationCode/CommandFileInterface/RicfCreateView.h b/ApplicationCode/CommandFileInterface/RicfCreateView.h new file mode 100644 index 0000000000..df9c809946 --- /dev/null +++ b/ApplicationCode/CommandFileInterface/RicfCreateView.h @@ -0,0 +1,52 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RicfCommandObject.h" + +#include "cafPdmField.h" + +class RicfCreateViewResult : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; + +public: + RicfCreateViewResult(int viewId = -1); + +public: + caf::PdmField viewId; +}; + +//================================================================================================== +// +// +// +//================================================================================================== +class RicfCreateView : public RicfCommandObject +{ + CAF_PDM_HEADER_INIT; + +public: + RicfCreateView(); + + RicfCommandResponse execute() override; + +private: + caf::PdmField m_caseId; +}; diff --git a/ApplicationCode/CommandFileInterface/RicfLoadCase.cpp b/ApplicationCode/CommandFileInterface/RicfLoadCase.cpp index a0ca993e00..bb03dfb341 100644 --- a/ApplicationCode/CommandFileInterface/RicfLoadCase.cpp +++ b/ApplicationCode/CommandFileInterface/RicfLoadCase.cpp @@ -70,7 +70,6 @@ RicfCommandResponse RicfLoadCase::execute() return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error); } CAF_ASSERT(fileCaseIdMap.size() == 1u); - RicfLoadCaseResult result; RicfCommandResponse response; response.setResult(new RicfLoadCaseResult(fileCaseIdMap.begin()->second)); return response; diff --git a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto index 970139eefe..8676996ecf 100644 --- a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto +++ b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto @@ -256,6 +256,16 @@ message ExportFlowInfoRequest double aquiferCellThreshold = 7; } +message CreateViewRequest +{ + int32 caseId = 1; +} + +message CloneViewRequest +{ + int32 viewId = 1; +} + /* CommandParams handles both command name and parameters in one. * The message type and content is used as parameters and * the name of the variable is used to find the command name. */ @@ -296,8 +306,8 @@ message CommandParams CreateGridCaseGroupRequest createGridCaseGroup = 27; CreateStatisticsCaseRequest createStatisticsCase = 28; ExportFlowInfoRequest exportFlowCharacteristics = 29; - - + CreateViewRequest createView = 30; + CloneViewRequest cloneView = 31; } } @@ -312,6 +322,11 @@ message CreateStatisticsCaseResult int32 caseId = 1; } +message CreateViewResult +{ + int32 viewId = 1; +} + /* Command reply handles the return values for the generic command * The name of the variable is used to map to the cafPdmObject classKeyword */ message CommandReply @@ -322,6 +337,7 @@ message CommandReply CaseRequest loadCaseResult = 2; GridCaseGroupResult createGridCaseGroupResult = 3; CreateStatisticsCaseResult createStatisticsCaseResult = 4; + CreateViewResult createViewResult = 5; } } diff --git a/ApplicationCode/GrpcInterface/Python/rips/Case.py b/ApplicationCode/GrpcInterface/Python/rips/Case.py index dde1466455..897bc68f95 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Case.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Case.py @@ -1,10 +1,11 @@ import grpc import os import sys -from .Grid import Grid -from .Properties import Properties -from .PdmObject import PdmObject -from .View import View +from rips.Commands import Commands +from rips.Grid import Grid +from rips.Properties import Properties +from rips.PdmObject import PdmObject +from rips.View import View sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated')) @@ -156,3 +157,8 @@ class Case (PdmObject): return viewObject return None + def createView(self): + """Create a new view in the current case""" + viewId = Commands(self.channel).createView(self.id) + return self.view(viewId) + diff --git a/ApplicationCode/GrpcInterface/Python/rips/Commands.py b/ApplicationCode/GrpcInterface/Python/rips/Commands.py index d07ba51327..ced55b5bfc 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Commands.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Commands.py @@ -7,7 +7,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated')) from Definitions_pb2 import Empty import Commands_pb2 as Cmd import Commands_pb2_grpc as CmdRpc -from .Case import Case +import rips.Case class Commands: """Command executor which can run ResInsight Command File commands nearly verbatim @@ -65,7 +65,7 @@ class Commands: """ commandReply = self.__execute(loadCase=Cmd.FilePathRequest(path=path)) - return Case(self.channel, commandReply.loadCaseResult.id) + return rips.Case(self.channel, commandReply.loadCaseResult.id) def replaceCase(self, newGridFile, caseId=0): """Replace the given case with a new case loaded from file @@ -276,3 +276,9 @@ class Commands: fileName=fileName, minimumCommunication = minimumCommunication, aquiferCellThreshold = aquiferCellThreshold)) + + def createView(self, caseId): + return self.__execute(createView=Cmd.CreateViewRequest(caseId=caseId)).createViewResult.viewId + + def cloneView(self, viewId): + return self.__execute(cloneView=Cmd.CloneViewRequest(viewId=viewId)).createViewResult.viewId \ No newline at end of file diff --git a/ApplicationCode/GrpcInterface/Python/rips/GridCaseGroup.py b/ApplicationCode/GrpcInterface/Python/rips/GridCaseGroup.py index 1f2802fb45..d00d2f9e40 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/GridCaseGroup.py +++ b/ApplicationCode/GrpcInterface/Python/rips/GridCaseGroup.py @@ -1,8 +1,8 @@ import grpc import os import sys -from .PdmObject import PdmObject -from .View import View +from rips.PdmObject import PdmObject +from rips.View import View sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated')) diff --git a/ApplicationCode/GrpcInterface/Python/rips/Instance.py b/ApplicationCode/GrpcInterface/Python/rips/Instance.py index d5b55b3ecd..55660ce274 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Instance.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Instance.py @@ -12,8 +12,8 @@ from Definitions_pb2 import Empty import RiaVersionInfo -from .Commands import Commands -from .Project import Project +from rips.Commands import Commands +from rips.Project import Project class Instance: """The ResInsight Instance class. Use to launch or find existing ResInsight instances diff --git a/ApplicationCode/GrpcInterface/Python/rips/Project.py b/ApplicationCode/GrpcInterface/Python/rips/Project.py index 42359f7a70..23c8e7ab2e 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Project.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Project.py @@ -2,11 +2,11 @@ import grpc import os import sys -from .Case import Case -from .Commands import Commands -from .GridCaseGroup import GridCaseGroup -from .PdmObject import PdmObject -from .View import View +from rips.Case import Case +from rips.Commands import Commands +from rips.GridCaseGroup import GridCaseGroup +from rips.PdmObject import PdmObject +from rips.View import View sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated')) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/AllCases.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/AllCases.py index f54195c1ff..91d2db22c3 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/AllCases.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/AllCases.py @@ -1,5 +1,6 @@ ################################################################################### # This example will connect to ResInsight, retrieve a list of cases and print info +# Also creates a new view for all cases ################################################################################### # Import the ResInsight Processing Server Module @@ -15,4 +16,7 @@ if resInsight is not None: for case in cases: print("Case name: " + case.name) print("Case grid path: " + case.gridPath()) + # Create a new view + view = case.createView() + diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ViewExample.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ViewExample.py index 63d70a76d5..3b03154125 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ViewExample.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ViewExample.py @@ -1,6 +1,7 @@ ############################################################# # This example will alter the views of all cases # By setting the background color and toggle the grid box +# Also clones the first view ############################################################# import rips # Connect to ResInsight instance @@ -18,4 +19,9 @@ if resInsight is not None: view.setShowGridBox(not view.showGridBox()) view.setBackgroundColor("#3388AA") # Update the view in ResInsight - view.update() \ No newline at end of file + view.update() + # Clone the first view + newView = views[0].clone() + view.setShowGridBox(False) + newView.setBackgroundColor("#FFAA33") + newView.update() \ No newline at end of file diff --git a/ApplicationCode/GrpcInterface/Python/rips/View.py b/ApplicationCode/GrpcInterface/Python/rips/View.py index d895e1bf34..115bf05238 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/View.py +++ b/ApplicationCode/GrpcInterface/Python/rips/View.py @@ -1,4 +1,6 @@ -from .PdmObject import PdmObject +import rips.Case +from rips.Commands import Commands +from rips.PdmObject import PdmObject class View (PdmObject): """ResInsight view class @@ -74,4 +76,18 @@ class View (PdmObject): if selectionMode == 'FLOW_TR_BY_SELECTION': cellResult.setValue("SelectedInjectorTracers", injectors) cellResult.setValue("SelectedProducerTracers", producers) - cellResult.update() \ No newline at end of file + cellResult.update() + + def case(self): + """Get the case the view belongs to""" + pdmCase = self.ancestor("EclipseCase") + if pdmCase is None: + pdmCase = self.ancestor("ResInsightGeoMechCase") + if pdmCase is None: + return None + return rips.Case(self.channel, pdmCase.getValue("CaseId")) + + def clone(self): + """Clone the current view""" + viewId = Commands(self.channel).cloneView(self.id) + return self.case().view(viewId) \ No newline at end of file diff --git a/ApplicationCode/GrpcInterface/Python/rips/__init__.py b/ApplicationCode/GrpcInterface/Python/rips/__init__.py index 84a933e156..973283f882 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/__init__.py +++ b/ApplicationCode/GrpcInterface/Python/rips/__init__.py @@ -3,7 +3,6 @@ from .Case import Case from .Grid import Grid from .Properties import Properties from .Instance import Instance -from .App import App from .Commands import Commands from .PdmObject import PdmObject from .View import View diff --git a/ApplicationCode/ProjectDataModel/Rim3dView.cpp b/ApplicationCode/ProjectDataModel/Rim3dView.cpp index bb99f51c81..e98faaadee 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dView.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dView.cpp @@ -141,9 +141,6 @@ Rim3dView::Rim3dView(void) m_measurementPartManager = new RivMeasurementPartMgr(this); this->setAs3DViewMdiWindow(); - - RimProject* proj = RiaApplication::instance()->project(); - proj->assignViewIdToView(this); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp index e5b9acec89..8f9530d5bd 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp @@ -271,6 +271,8 @@ void RimEclipseCase::initAfterRead() RimEclipseView* RimEclipseCase::createAndAddReservoirView() { RimEclipseView* rimEclipseView = new RimEclipseView(); + RiaApplication::instance()->project()->assignViewIdToView(rimEclipseView); + rimEclipseView->setEclipseCase(this); // Set default values @@ -306,7 +308,7 @@ RimEclipseView* RimEclipseCase::createCopyAndAddView(const RimEclipseView* sourc RimEclipseView* rimEclipseView = dynamic_cast( sourceView->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); CVF_ASSERT(rimEclipseView); - + RiaApplication::instance()->project()->assignViewIdToView(rimEclipseView); rimEclipseView->setEclipseCase(this); caf::PdmDocument::updateUiIconStateRecursively(rimEclipseView); diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp index 9d1bde616e..4b1a3ab914 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp @@ -181,13 +181,38 @@ void RimGeoMechCase::reloadDataAndUpdate() RimGeoMechView* RimGeoMechCase::createAndAddReservoirView() { RimGeoMechView* gmv = new RimGeoMechView(); - + RiaApplication::instance()->project()->assignViewIdToView(gmv); + gmv->setGeoMechCase(this); geoMechViews.push_back(gmv); return gmv; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimGeoMechView* RimGeoMechCase::createCopyAndAddView(const RimGeoMechView* sourceView) +{ + RimGeoMechView* rimGeoMechView = dynamic_cast( + sourceView->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); + CVF_ASSERT(rimGeoMechView); + + RiaApplication::instance()->project()->assignViewIdToView(rimGeoMechView); + rimGeoMechView->setGeoMechCase(this); + + caf::PdmDocument::updateUiIconStateRecursively(rimGeoMechView); + + geoMechViews.push_back(rimGeoMechView); + + // Resolve references after reservoir view has been inserted into Rim structures + rimGeoMechView->resolveReferencesRecursively(); + rimGeoMechView->initAfterReadRecursively(); + + return rimGeoMechView; + +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechCase.h b/ApplicationCode/ProjectDataModel/RimGeoMechCase.h index e7fa9b3ae1..a7e1cf8a3f 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechCase.h +++ b/ApplicationCode/ProjectDataModel/RimGeoMechCase.h @@ -67,6 +67,7 @@ public: void reloadDataAndUpdate(); RimGeoMechView* createAndAddReservoirView(); + RimGeoMechView* createCopyAndAddView(const RimGeoMechView* sourceView); void updateFilePathsFromProjectPath(const QString& projectPath, const QString& oldProjectPath) override; diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp index d46cc390a5..8d2271de86 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp @@ -682,7 +682,7 @@ void RimGeoMechView::convertCameraPositionFromOldProjectFiles() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimGeoMechCase* RimGeoMechView::geoMechCase() +RimGeoMechCase* RimGeoMechView::geoMechCase() const { return m_geomechCase; } diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.h b/ApplicationCode/ProjectDataModel/RimGeoMechView.h index 1701031518..ba91d0d21a 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.h +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.h @@ -64,7 +64,7 @@ public: ~RimGeoMechView(void) override; void setGeoMechCase(RimGeoMechCase* gmCase); - RimGeoMechCase* geoMechCase(); + RimGeoMechCase* geoMechCase() const; RimCase* ownerCase() const override; caf::PdmChildField cellResult; From e7f90c0ecfa79748e90a57e7d736b04dbc28d622 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Mon, 26 Aug 2019 09:57:50 +0200 Subject: [PATCH 2/4] Clang-format --- .../CommandFileInterface/RicfCloneView.cpp | 49 +++++++------ .../CommandFileInterface/RicfCreateView.cpp | 70 +++++++++---------- .../ProjectDataModel/RimEclipseCase.cpp | 2 +- .../ProjectDataModel/RimGeoMechCase.cpp | 7 +- 4 files changed, 63 insertions(+), 65 deletions(-) diff --git a/ApplicationCode/CommandFileInterface/RicfCloneView.cpp b/ApplicationCode/CommandFileInterface/RicfCloneView.cpp index ed78b7b359..ddc039ac9b 100644 --- a/ApplicationCode/CommandFileInterface/RicfCloneView.cpp +++ b/ApplicationCode/CommandFileInterface/RicfCloneView.cpp @@ -33,45 +33,44 @@ RicfCloneView::RicfCloneView() //-------------------------------------------------------------------------------------------------- RicfCommandResponse RicfCloneView::execute() { - RimProject* project = RiaApplication::instance()->project(); - std::vector allViews; - project->descendantsIncludingThisOfType(allViews); + RimProject* project = RiaApplication::instance()->project(); + std::vector allViews; + project->descendantsIncludingThisOfType(allViews); for (Rim3dView* view : allViews) { - if (view->id() == m_viewId()) - { - const RimEclipseView* eclipseView = dynamic_cast(view); - const RimGeoMechView* geoMechView = dynamic_cast(view); + if (view->id() == m_viewId()) + { + const RimEclipseView* eclipseView = dynamic_cast(view); + const RimGeoMechView* geoMechView = dynamic_cast(view); - int newViewId = -1; - if (eclipseView) - { - RimEclipseCase* eclipseCase = eclipseView->eclipseCase(); - RimEclipseView* newEclipseView = eclipseCase->createCopyAndAddView(eclipseView); - newViewId = newEclipseView->id(); + int newViewId = -1; + if (eclipseView) + { + RimEclipseCase* eclipseCase = eclipseView->eclipseCase(); + RimEclipseView* newEclipseView = eclipseCase->createCopyAndAddView(eclipseView); + newViewId = newEclipseView->id(); newEclipseView->loadDataAndUpdate(); eclipseCase->updateConnectedEditors(); Riu3DMainWindowTools::setExpanded(newEclipseView); - } - else if (geoMechView) - { - RimGeoMechCase* geoMechCase = geoMechView->geoMechCase(); - RimGeoMechView* newGeoMechView = geoMechCase->createCopyAndAddView(geoMechView); - newViewId = newGeoMechView->id(); + } + else if (geoMechView) + { + RimGeoMechCase* geoMechCase = geoMechView->geoMechCase(); + RimGeoMechView* newGeoMechView = geoMechCase->createCopyAndAddView(geoMechView); + newViewId = newGeoMechView->id(); view->loadDataAndUpdate(); geoMechCase->updateConnectedEditors(); Riu3DMainWindowTools::setExpanded(view); - } + } - if (newViewId) - { + if (newViewId) + { RicfCommandResponse response; response.setResult(new RicfCreateViewResult(newViewId)); return response; - - } - } + } + } } QString error = QString("cloneView: Could not clone view with id %1").arg(m_viewId()); diff --git a/ApplicationCode/CommandFileInterface/RicfCreateView.cpp b/ApplicationCode/CommandFileInterface/RicfCreateView.cpp index 51ed5117e7..c393519975 100644 --- a/ApplicationCode/CommandFileInterface/RicfCreateView.cpp +++ b/ApplicationCode/CommandFileInterface/RicfCreateView.cpp @@ -42,44 +42,44 @@ RicfCreateView::RicfCreateView() //-------------------------------------------------------------------------------------------------- RicfCommandResponse RicfCreateView::execute() { - RimProject* project = RiaApplication::instance()->project(); - std::vector allCases; - project->allCases(allCases); + RimProject* project = RiaApplication::instance()->project(); + std::vector allCases; + project->allCases(allCases); - for (RimCase* rimCase : allCases) - { - if (rimCase->caseId == m_caseId()) - { - int viewId = -1; - RimEclipseCase* eclipseCase = dynamic_cast(rimCase); - RimGeoMechCase* geoMechCase = dynamic_cast(rimCase); - if (eclipseCase) - { - RimEclipseView* view = eclipseCase->createAndAddReservoirView(); - viewId = view->id(); - view->loadDataAndUpdate(); - eclipseCase->updateConnectedEditors(); - Riu3DMainWindowTools::setExpanded(view); - } - else if (geoMechCase) - { - RimGeoMechView* view = geoMechCase->createAndAddReservoirView(); - viewId = view->id(); - view->loadDataAndUpdate(); - geoMechCase->updateConnectedEditors(); - Riu3DMainWindowTools::setExpanded(view); - } + for (RimCase* rimCase : allCases) + { + if (rimCase->caseId == m_caseId()) + { + int viewId = -1; + RimEclipseCase* eclipseCase = dynamic_cast(rimCase); + RimGeoMechCase* geoMechCase = dynamic_cast(rimCase); + if (eclipseCase) + { + RimEclipseView* view = eclipseCase->createAndAddReservoirView(); + viewId = view->id(); + view->loadDataAndUpdate(); + eclipseCase->updateConnectedEditors(); + Riu3DMainWindowTools::setExpanded(view); + } + else if (geoMechCase) + { + RimGeoMechView* view = geoMechCase->createAndAddReservoirView(); + viewId = view->id(); + view->loadDataAndUpdate(); + geoMechCase->updateConnectedEditors(); + Riu3DMainWindowTools::setExpanded(view); + } - if (viewId >= 0) - { - RicfCommandResponse response; - response.setResult(new RicfCreateViewResult(viewId)); - return response; - } - } - } + if (viewId >= 0) + { + RicfCommandResponse response; + response.setResult(new RicfCreateViewResult(viewId)); + return response; + } + } + } QString error = QString("createView: Could not create view for case id %1").arg(m_caseId()); RiaLogging::error(error); - return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error); + return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error); } diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp index 8f9530d5bd..7fa68fd72e 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp @@ -308,7 +308,7 @@ RimEclipseView* RimEclipseCase::createCopyAndAddView(const RimEclipseView* sourc RimEclipseView* rimEclipseView = dynamic_cast( sourceView->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); CVF_ASSERT(rimEclipseView); - RiaApplication::instance()->project()->assignViewIdToView(rimEclipseView); + RiaApplication::instance()->project()->assignViewIdToView(rimEclipseView); rimEclipseView->setEclipseCase(this); caf::PdmDocument::updateUiIconStateRecursively(rimEclipseView); diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp index 4b1a3ab914..c76c134b7c 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp @@ -198,8 +198,8 @@ RimGeoMechView* RimGeoMechCase::createCopyAndAddView(const RimGeoMechView* sourc sourceView->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); CVF_ASSERT(rimGeoMechView); - RiaApplication::instance()->project()->assignViewIdToView(rimGeoMechView); - rimGeoMechView->setGeoMechCase(this); + RiaApplication::instance()->project()->assignViewIdToView(rimGeoMechView); + rimGeoMechView->setGeoMechCase(this); caf::PdmDocument::updateUiIconStateRecursively(rimGeoMechView); @@ -209,8 +209,7 @@ RimGeoMechView* RimGeoMechCase::createCopyAndAddView(const RimGeoMechView* sourc rimGeoMechView->resolveReferencesRecursively(); rimGeoMechView->initAfterReadRecursively(); - return rimGeoMechView; - + return rimGeoMechView; } //-------------------------------------------------------------------------------------------------- From 51793ea7b3485f93d6363d018ecfb8e0362dc2ca Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Mon, 26 Aug 2019 10:01:40 +0200 Subject: [PATCH 3/4] Fix error in CloneView result --- ApplicationCode/CommandFileInterface/RicfCloneView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApplicationCode/CommandFileInterface/RicfCloneView.cpp b/ApplicationCode/CommandFileInterface/RicfCloneView.cpp index ddc039ac9b..f682f47f44 100644 --- a/ApplicationCode/CommandFileInterface/RicfCloneView.cpp +++ b/ApplicationCode/CommandFileInterface/RicfCloneView.cpp @@ -64,7 +64,7 @@ RicfCommandResponse RicfCloneView::execute() Riu3DMainWindowTools::setExpanded(view); } - if (newViewId) + if (newViewId >= 0) { RicfCommandResponse response; response.setResult(new RicfCreateViewResult(newViewId)); From a1f9c4c1cdf8f35e21e56d3b00d34018599e6161 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Mon, 26 Aug 2019 10:03:56 +0200 Subject: [PATCH 4/4] Comment for circular import of Python module --- ApplicationCode/GrpcInterface/Python/rips/View.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApplicationCode/GrpcInterface/Python/rips/View.py b/ApplicationCode/GrpcInterface/Python/rips/View.py index 115bf05238..1c4f34b6fa 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/View.py +++ b/ApplicationCode/GrpcInterface/Python/rips/View.py @@ -1,4 +1,4 @@ -import rips.Case +import rips.Case # Circular import of Case, which already imports View. Use full name. from rips.Commands import Commands from rips.PdmObject import PdmObject