mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4428 Implement support for repeated fields as parameters and add exportWellPaths to client library
This commit is contained in:
parent
c7f8edad04
commit
af054fb95e
@ -25,7 +25,9 @@
|
|||||||
|
|
||||||
#include "cafAssert.h"
|
#include "cafAssert.h"
|
||||||
#include "cafPdmDefaultObjectFactory.h"
|
#include "cafPdmDefaultObjectFactory.h"
|
||||||
|
#include "cafPdmDataValueField.h"
|
||||||
#include "cafPdmValueField.h"
|
#include "cafPdmValueField.h"
|
||||||
|
#include <google/protobuf/reflection.h>
|
||||||
|
|
||||||
using namespace rips;
|
using namespace rips;
|
||||||
using namespace google::protobuf;
|
using namespace google::protobuf;
|
||||||
@ -101,6 +103,29 @@ std::vector<RiaAbstractGrpcCallback*> RiaGrpcCommandService::createCallbacks()
|
|||||||
return {new RiaGrpcCallback<Self, CommandParams, CommandReply>(this, &Self::Execute, &Self::RequestExecute)};
|
return {new RiaGrpcCallback<Self, CommandParams, CommandReply>(this, &Self::Execute, &Self::RequestExecute)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename T>
|
||||||
|
caf::PdmField<T>* RiaGrpcCommandService::dataValueField(caf::PdmValueField* valueField)
|
||||||
|
{
|
||||||
|
caf::PdmField<T>* dataValField = dynamic_cast<caf::PdmField<T>*>(valueField);
|
||||||
|
CAF_ASSERT(dataValField);
|
||||||
|
return dataValField;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template<typename T>
|
||||||
|
const caf::PdmField<T>* RiaGrpcCommandService::constDataValueField(const caf::PdmValueField* valueField)
|
||||||
|
{
|
||||||
|
const caf::PdmField<T>* dataValField = dynamic_cast<const caf::PdmField<T>*>(valueField);
|
||||||
|
CAF_ASSERT(dataValField);
|
||||||
|
return dataValField;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -109,56 +134,77 @@ void RiaGrpcCommandService::assignPdmFieldValue(caf::PdmValueField* pdmValueF
|
|||||||
const FieldDescriptor* paramDescriptor)
|
const FieldDescriptor* paramDescriptor)
|
||||||
{
|
{
|
||||||
FieldDescriptor::Type fieldDataType = paramDescriptor->type();
|
FieldDescriptor::Type fieldDataType = paramDescriptor->type();
|
||||||
QVariant qValue;
|
const Reflection* reflection = params.GetReflection();
|
||||||
|
|
||||||
switch (fieldDataType)
|
switch (fieldDataType)
|
||||||
{
|
{
|
||||||
case FieldDescriptor::TYPE_BOOL: {
|
case FieldDescriptor::TYPE_BOOL: {
|
||||||
auto value = params.GetReflection()->GetBool(params, paramDescriptor);
|
auto value = reflection->GetBool(params, paramDescriptor);
|
||||||
qValue = QVariant(value);
|
auto dataField = dataValueField<bool>(pdmValueField);
|
||||||
|
dataField->setValue(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_INT32: {
|
case FieldDescriptor::TYPE_INT32: {
|
||||||
int value = params.GetReflection()->GetInt32(params, paramDescriptor);
|
if (paramDescriptor->is_repeated())
|
||||||
qValue = QVariant(value);
|
{
|
||||||
|
RepeatedFieldRef<int> repeatedField =
|
||||||
|
reflection->GetRepeatedFieldRef<int>(params, paramDescriptor);
|
||||||
|
auto dataField = dataValueField<std::vector<int>>(pdmValueField);
|
||||||
|
dataField->setValue(std::vector<int>(repeatedField.begin(), repeatedField.end()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int value = reflection->GetInt32(params, paramDescriptor);
|
||||||
|
auto dataField = dataValueField<int>(pdmValueField);
|
||||||
|
dataField->setValue(value);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_UINT32: {
|
case FieldDescriptor::TYPE_UINT32: {
|
||||||
uint value = params.GetReflection()->GetUInt32(params, paramDescriptor);
|
uint value = reflection->GetUInt32(params, paramDescriptor);
|
||||||
qValue = QVariant(value);
|
auto dataField = dataValueField<uint>(pdmValueField);
|
||||||
break;
|
dataField->setValue(value);
|
||||||
}
|
|
||||||
case FieldDescriptor::TYPE_INT64: {
|
|
||||||
int64_t value = params.GetReflection()->GetInt64(params, paramDescriptor);
|
|
||||||
qValue = QVariant((qlonglong)value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FieldDescriptor::TYPE_UINT64: {
|
|
||||||
uint64_t value = params.GetReflection()->GetUInt64(params, paramDescriptor);
|
|
||||||
qValue = QVariant((qulonglong)value);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_STRING: {
|
case FieldDescriptor::TYPE_STRING: {
|
||||||
auto value = params.GetReflection()->GetString(params, paramDescriptor);
|
if (paramDescriptor->is_repeated())
|
||||||
qValue = QVariant(QString::fromStdString(value));
|
{
|
||||||
|
RepeatedFieldRef<std::string> repeatedField =
|
||||||
|
reflection->GetRepeatedFieldRef<std::string>(params, paramDescriptor);
|
||||||
|
std::vector<QString> stringVector;
|
||||||
|
for (const std::string& string : repeatedField)
|
||||||
|
{
|
||||||
|
stringVector.push_back(QString::fromStdString(string));
|
||||||
|
}
|
||||||
|
auto dataField = dataValueField<std::vector<QString>>(pdmValueField);
|
||||||
|
dataField->setValue(stringVector);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto value = QString::fromStdString(reflection->GetString(params, paramDescriptor));
|
||||||
|
auto dataField = dataValueField<QString>(pdmValueField);
|
||||||
|
dataField->setValue(value);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_FLOAT: {
|
case FieldDescriptor::TYPE_FLOAT: {
|
||||||
auto value = params.GetReflection()->GetFloat(params, paramDescriptor);
|
auto value = reflection->GetFloat(params, paramDescriptor);
|
||||||
qValue = QVariant(value);
|
auto dataField = dataValueField<float>(pdmValueField);
|
||||||
|
dataField->setValue(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_DOUBLE: {
|
case FieldDescriptor::TYPE_DOUBLE: {
|
||||||
auto value = params.GetReflection()->GetDouble(params, paramDescriptor);
|
auto value = reflection->GetDouble(params, paramDescriptor);
|
||||||
qValue = QVariant(value);
|
auto dataField = dataValueField<double>(pdmValueField);
|
||||||
|
dataField->setValue(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_ENUM: {
|
case FieldDescriptor::TYPE_ENUM: {
|
||||||
auto value = params.GetReflection()->GetEnumValue(params, paramDescriptor);
|
auto value = reflection->GetEnumValue(params, paramDescriptor);
|
||||||
qValue = QVariant(value);
|
pdmValueField->setFromQVariant(QVariant(value));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pdmValueField->setFromQVariant(qValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -170,42 +216,44 @@ void RiaGrpcCommandService::assignGrpcFieldValue(google::protobuf::Message*
|
|||||||
{
|
{
|
||||||
FieldDescriptor::Type fieldDataType = fieldDescriptor->type();
|
FieldDescriptor::Type fieldDataType = fieldDescriptor->type();
|
||||||
QVariant qValue = pdmValueField->toQVariant();
|
QVariant qValue = pdmValueField->toQVariant();
|
||||||
|
|
||||||
|
auto reflection = reply->GetReflection();
|
||||||
switch (fieldDataType)
|
switch (fieldDataType)
|
||||||
{
|
{
|
||||||
case FieldDescriptor::TYPE_BOOL: {
|
case FieldDescriptor::TYPE_BOOL: {
|
||||||
reply->GetReflection()->SetBool(reply, fieldDescriptor, qValue.toBool());
|
reflection->SetBool(reply, fieldDescriptor, qValue.toBool());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_INT32: {
|
case FieldDescriptor::TYPE_INT32: {
|
||||||
reply->GetReflection()->SetInt32(reply, fieldDescriptor, qValue.toInt());
|
reflection->SetInt32(reply, fieldDescriptor, qValue.toInt());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_UINT32: {
|
case FieldDescriptor::TYPE_UINT32: {
|
||||||
reply->GetReflection()->SetUInt32(reply, fieldDescriptor, qValue.toUInt());
|
reflection->SetUInt32(reply, fieldDescriptor, qValue.toUInt());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_INT64: {
|
case FieldDescriptor::TYPE_INT64: {
|
||||||
reply->GetReflection()->SetInt64(reply, fieldDescriptor, qValue.toLongLong());
|
reflection->SetInt64(reply, fieldDescriptor, qValue.toLongLong());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_UINT64: {
|
case FieldDescriptor::TYPE_UINT64: {
|
||||||
reply->GetReflection()->SetUInt64(reply, fieldDescriptor, qValue.toULongLong());
|
reflection->SetUInt64(reply, fieldDescriptor, qValue.toULongLong());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_STRING: {
|
case FieldDescriptor::TYPE_STRING: {
|
||||||
reply->GetReflection()->SetString(reply, fieldDescriptor, qValue.toString().toStdString());
|
reflection->SetString(reply, fieldDescriptor, qValue.toString().toStdString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_FLOAT: {
|
case FieldDescriptor::TYPE_FLOAT: {
|
||||||
reply->GetReflection()->SetFloat(reply, fieldDescriptor, qValue.toFloat());
|
reflection->SetFloat(reply, fieldDescriptor, qValue.toFloat());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_DOUBLE: {
|
case FieldDescriptor::TYPE_DOUBLE: {
|
||||||
reply->GetReflection()->SetDouble(reply, fieldDescriptor, qValue.toDouble());
|
reflection->SetDouble(reply, fieldDescriptor, qValue.toDouble());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FieldDescriptor::TYPE_ENUM: {
|
case FieldDescriptor::TYPE_ENUM: {
|
||||||
reply->GetReflection()->SetEnumValue(reply, fieldDescriptor, qValue.toInt());
|
reflection->SetEnumValue(reply, fieldDescriptor, qValue.toInt());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ namespace caf
|
|||||||
{
|
{
|
||||||
class PdmValueField;
|
class PdmValueField;
|
||||||
class PdmObject;
|
class PdmObject;
|
||||||
|
template<typename T>
|
||||||
|
class PdmField;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace google
|
namespace google
|
||||||
@ -48,6 +50,10 @@ public:
|
|||||||
std::vector<RiaAbstractGrpcCallback*> createCallbacks() override;
|
std::vector<RiaAbstractGrpcCallback*> createCallbacks() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template<typename T>
|
||||||
|
static caf::PdmField<T>* dataValueField(caf::PdmValueField* valueField);
|
||||||
|
template<typename T>
|
||||||
|
static const caf::PdmField<T>* constDataValueField(const caf::PdmValueField* valueField);
|
||||||
void assignPdmFieldValue(caf::PdmValueField* pdmValueField,
|
void assignPdmFieldValue(caf::PdmValueField* pdmValueField,
|
||||||
const google::protobuf::Message& params,
|
const google::protobuf::Message& params,
|
||||||
const google::protobuf::FieldDescriptor* paramDescriptor);
|
const google::protobuf::FieldDescriptor* paramDescriptor);
|
||||||
|
@ -12,8 +12,8 @@ sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
|||||||
from Empty_pb2 import Empty
|
from Empty_pb2 import Empty
|
||||||
import CaseInfo_pb2
|
import CaseInfo_pb2
|
||||||
import CaseInfo_pb2_grpc
|
import CaseInfo_pb2_grpc
|
||||||
import Commands_pb2
|
import Commands_pb2 as Cmd
|
||||||
import Commands_pb2_grpc
|
import Commands_pb2_grpc as CmdRpc
|
||||||
import GridInfo_pb2
|
import GridInfo_pb2
|
||||||
import GridInfo_pb2_grpc
|
import GridInfo_pb2_grpc
|
||||||
import ProjectInfo_pb2
|
import ProjectInfo_pb2
|
||||||
@ -40,7 +40,7 @@ class ResInfo:
|
|||||||
|
|
||||||
class CommandExecutor:
|
class CommandExecutor:
|
||||||
def __init__(self, channel):
|
def __init__(self, channel):
|
||||||
self.commands = Commands_pb2_grpc.CommandsStub(channel)
|
self.commands = CmdRpc.CommandsStub(channel)
|
||||||
|
|
||||||
def execute(self, commandParams):
|
def execute(self, commandParams):
|
||||||
try:
|
try:
|
||||||
@ -52,21 +52,28 @@ class CommandExecutor:
|
|||||||
print("Other error")
|
print("Other error")
|
||||||
|
|
||||||
def setTimeStep(self, caseId, timeStep):
|
def setTimeStep(self, caseId, timeStep):
|
||||||
return self.execute(Commands_pb2.CommandParams(setTimeStep=Commands_pb2.SetTimeStepParams(caseId=caseId, timeStep=timeStep)))
|
return self.execute(Cmd.CommandParams(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep)))
|
||||||
|
|
||||||
def setMainWindowSize(self, width, height):
|
def setMainWindowSize(self, width, height):
|
||||||
return self.execute(Commands_pb2.CommandParams(setMainWindowSize=Commands_pb2.SetMainWindowSizeParams(width=width, height=height)))
|
return self.execute(Cmd.CommandParams(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height)))
|
||||||
|
|
||||||
def openProject(self, path):
|
def openProject(self, path):
|
||||||
return self.execute(Commands_pb2.CommandParams(openProject=Commands_pb2.FilePathRequest(path=path)))
|
return self.execute(Cmd.CommandParams(openProject=Cmd.FilePathRequest(path=path)))
|
||||||
|
|
||||||
def loadCase(self, path):
|
def loadCase(self, path):
|
||||||
commandReply = self.execute(Commands_pb2.CommandParams(loadCase=Commands_pb2.FilePathRequest(path=path)))
|
commandReply = self.execute(Cmd.CommandParams(loadCase=Cmd.FilePathRequest(path=path)))
|
||||||
assert commandReply.HasField("loadCaseResult")
|
assert commandReply.HasField("loadCaseResult")
|
||||||
return commandReply.loadCaseResult.id
|
return commandReply.loadCaseResult.id
|
||||||
|
|
||||||
def closeProject(self):
|
def closeProject(self):
|
||||||
return self.execute(Commands_pb2.CommandParams(closeProject=Empty()))
|
return self.execute(Cmd.CommandParams(closeProject=Empty()))
|
||||||
|
|
||||||
|
def exportWellPaths(self, wellPaths=[], mdStepSize=5.0):
|
||||||
|
if isinstance(wellPaths, str):
|
||||||
|
wellPathArray = [str]
|
||||||
|
elif isinstance(wellPaths, list):
|
||||||
|
wellPathArray = wellPaths
|
||||||
|
return self.execute(Cmd.CommandParams(exportWellPaths=Cmd.ExportWellPathRequest(wellPathNames=wellPathArray, mdStepSize=mdStepSize)))
|
||||||
|
|
||||||
class GridInfo:
|
class GridInfo:
|
||||||
def __init__(self, channel):
|
def __init__(self, channel):
|
||||||
|
@ -9,3 +9,4 @@ resInsight = ResInsight.Instance.find()
|
|||||||
# Run a couple of commands
|
# Run a couple of commands
|
||||||
resInsight.commands.setTimeStep(caseId=0, timeStep=3)
|
resInsight.commands.setTimeStep(caseId=0, timeStep=3)
|
||||||
resInsight.commands.setMainWindowSize(width=800, height=500)
|
resInsight.commands.setMainWindowSize(width=800, height=500)
|
||||||
|
resInsight.commands.exportWellPaths()
|
Loading…
Reference in New Issue
Block a user