mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 23:46:00 -06:00
#4423 Improve API for setting cell results
This commit is contained in:
parent
b7c4a54d9a
commit
dcd3ff6754
@ -160,6 +160,7 @@ if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
||||
"rips/Properties.py"
|
||||
"rips/Instance.py"
|
||||
"rips/PdmObject.py"
|
||||
"rips/View.py"
|
||||
"rips/examples/InstanceExample.py"
|
||||
"rips/examples/CommandExample.py"
|
||||
"rips/examples/CaseInfoStreamingExample.py"
|
||||
|
@ -4,6 +4,7 @@ import sys
|
||||
from .Grid import Grid
|
||||
from .Properties import Properties
|
||||
from .PdmObject import PdmObject
|
||||
from .View import View
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||
|
||||
@ -109,5 +110,24 @@ class Case (PdmObject):
|
||||
return self.stub.GetDaysSinceStart(self.request).day_decimals
|
||||
|
||||
def views(self):
|
||||
return self.children("ReservoirView")
|
||||
"""Get a list of views belonging to a case"""
|
||||
pbmObjects = self.children("ReservoirView")
|
||||
viewList = []
|
||||
for pbmObject in pbmObjects:
|
||||
viewList.append(View(pbmObject))
|
||||
return viewList
|
||||
|
||||
def view(self, id):
|
||||
"""Get a particular view belonging to a case by providing view id
|
||||
Arguments:
|
||||
id(int): view id
|
||||
|
||||
Returns: a view object
|
||||
|
||||
"""
|
||||
views = self.views()
|
||||
for viewObject in views:
|
||||
if viewObject.id == id:
|
||||
return viewObject
|
||||
return None
|
||||
|
||||
|
@ -75,4 +75,4 @@ class PdmObject:
|
||||
return PdmObject(self.stub.GetAncestorPdmObject(request), self.channel)
|
||||
|
||||
def update(self):
|
||||
self.stub.UpdateExistingPdmObject(self.pb2Object)
|
||||
self.stub.UpdateExistingPdmObject(self.pb2Object)
|
||||
|
@ -5,6 +5,7 @@ import sys
|
||||
from .Case import Case
|
||||
from .Commands import Commands
|
||||
from .PdmObject import PdmObject
|
||||
from .View import View
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||
|
||||
@ -92,3 +93,24 @@ class Project (PdmObject):
|
||||
"""
|
||||
return Commands(self.channel).loadCase(path)
|
||||
|
||||
def views(self):
|
||||
"""Get a list of views belonging to a project"""
|
||||
pdmObjects = self.descendants("ReservoirView")
|
||||
viewList = []
|
||||
for pdmObject in pdmObjects:
|
||||
viewList.append(View(pdmObject))
|
||||
return viewList
|
||||
|
||||
def view(self, id):
|
||||
"""Get a particular view belonging to a case by providing view id
|
||||
Arguments:
|
||||
id(int): view id
|
||||
|
||||
Returns: a view object
|
||||
|
||||
"""
|
||||
views = self.views()
|
||||
for viewObject in views:
|
||||
if viewObject.id == id:
|
||||
return viewObject
|
||||
return None
|
33
ApplicationCode/GrpcInterface/Python/rips/View.py
Normal file
33
ApplicationCode/GrpcInterface/Python/rips/View.py
Normal file
@ -0,0 +1,33 @@
|
||||
from .PdmObject import PdmObject
|
||||
|
||||
class View (PdmObject):
|
||||
"""ResInsight view class
|
||||
|
||||
Attributes:
|
||||
id(int): View Id corresponding to the View Id in ResInsight project.
|
||||
|
||||
"""
|
||||
def __init__(self, pbmObject):
|
||||
self.id = pbmObject.getValue("ViewId")
|
||||
|
||||
PdmObject.__init__(self, pbmObject.pb2Object, pbmObject.channel)
|
||||
|
||||
def showGridBox(self):
|
||||
"""Check if the grid box is meant to be shown in the view"""
|
||||
return self.getValue("ShowGridBox")
|
||||
|
||||
def setShowGridBox(self, value):
|
||||
"""Set if the grid box is meant to be shown in the view"""
|
||||
self.setValue("ShowGridBox", value)
|
||||
|
||||
def backgroundColor(self):
|
||||
"""Get the current background color in the view"""
|
||||
return self.getValue("ViewBackgroundColor")
|
||||
|
||||
def setBackgroundColor(self, bgColor):
|
||||
"""Set the background color in the view"""
|
||||
self.setValue("ViewBackgroundColor", bgColor)
|
||||
|
||||
def cellResult(self):
|
||||
"""Retrieve the current cell results"""
|
||||
return self.children("ResultSlot")[0]
|
@ -5,4 +5,6 @@ from .Properties import Properties
|
||||
from .Instance import Instance
|
||||
from .App import App
|
||||
from .Commands import Commands
|
||||
from .PdmObject import PdmObject
|
||||
from .View import View
|
||||
from .Project import Project
|
@ -24,20 +24,23 @@ if resInsight is not None:
|
||||
|
||||
for keyword in resInsight.project.keywords():
|
||||
print (keyword + ": " + resInsight.project.getValue(keyword))
|
||||
pdmViews = resInsight.project.descendants(classKeyword="ReservoirView")
|
||||
pdmViews = resInsight.project.views()
|
||||
for view in pdmViews:
|
||||
print ("\n####View####")
|
||||
print(view.classKeyword(), view.address())
|
||||
for viewKeyword in view.keywords():
|
||||
print(viewKeyword + "-> " + str(view.getValue(viewKeyword)))
|
||||
view.setValue("ShowGridBox", not view.getValue("ShowGridBox"))
|
||||
view.setValue("ViewBackgroundColor", "#3388AA")
|
||||
view.setShowGridBox(not view.showGridBox())
|
||||
view.setBackgroundColor("#3388AA")
|
||||
view.update()
|
||||
|
||||
print ("\n####Cell Result####")
|
||||
cellResults = view.children(classKeyword="ResultSlot")
|
||||
for resultKeyword in cellResults[0].keywords():
|
||||
print(resultKeyword + "->" + str(cellResults[0].getValue(resultKeyword)))
|
||||
cellResults[0].setValue("ResultVariable", "SOIL")
|
||||
cellResults[0].setValue("ResultType", "DYNAMIC_NATIVE")
|
||||
cellResults[0].update()
|
||||
print ("\n####Cell Result####")
|
||||
firstView = case.view(id=0)
|
||||
assert(firstView is not None)
|
||||
cellResult = firstView.cellResult()
|
||||
print(cellResult.classKeyword(), cellResult.address())
|
||||
for resultKeyword in cellResult.keywords():
|
||||
print(resultKeyword + "->" + str(cellResult.getValue(resultKeyword)))
|
||||
cellResult.setValue("ResultVariable", "SOIL")
|
||||
cellResult.setValue("ResultType", "DYNAMIC_NATIVE")
|
||||
cellResult.update()
|
Loading…
Reference in New Issue
Block a user