#5632 Python method commands (#5649)

* General PdmObjectMethods for scripting.
This commit is contained in:
Gaute Lindkvist
2020-03-10 14:11:22 +01:00
committed by GitHub
parent 587478cbd1
commit c51aa91c42
145 changed files with 2646 additions and 1587 deletions

View File

@@ -11,8 +11,9 @@ service PdmObjectService
rpc GetAncestorPdmObject(PdmParentObjectRequest) returns (PdmObject) {}
rpc CreateChildPdmObject(CreatePdmChildObjectRequest) returns (PdmObject) {}
rpc UpdateExistingPdmObject(PdmObject) returns (Empty) {}
rpc CallPdmObjectGetMethod(PdmObjectMethodRequest) returns (stream PdmObjectGetMethodReply) {}
rpc CallPdmObjectSetMethod(stream PdmObjectSetMethodChunk) returns (ClientToServerStreamReply) {}
rpc CallPdmObjectGetter(PdmObjectGetterRequest) returns (stream PdmObjectGetterReply) {}
rpc CallPdmObjectSetter(stream PdmObjectSetterChunk) returns (ClientToServerStreamReply) {}
rpc CallPdmObjectMethod(PdmObjectMethodRequest) returns (PdmObject) {}
}
message PdmDescendantObjectRequest
@@ -45,6 +46,7 @@ message PdmObject
uint64 address = 2;
map<string, string> parameters = 3;
bool visible = 4;
bool persistent = 5; // Does this object live on in ResInsight?
}
message PdmObjectArray
@@ -52,26 +54,26 @@ message PdmObjectArray
repeated PdmObject objects = 1;
}
message PdmObjectMethodRequest
message PdmObjectGetterRequest
{
PdmObject object = 1;
string method = 2;
}
message PdmObjectSetMethodRequest
message PdmObjectSetterRequest
{
PdmObjectMethodRequest request = 1;
PdmObjectGetterRequest request = 1;
int32 data_count = 2;
}
message PdmObjectSetMethodChunk
message PdmObjectSetterChunk
{
oneof data
{
PdmObjectSetMethodRequest set_request = 1;
DoubleArray doubles = 2;
IntArray ints = 3;
StringArray strings = 4;
PdmObjectSetterRequest set_request = 1;
DoubleArray doubles = 2;
IntArray ints = 3;
StringArray strings = 4;
}
}
@@ -91,7 +93,7 @@ message StringArray
repeated string data = 1;
}
message PdmObjectGetMethodReply
message PdmObjectGetterReply
{
oneof data
{
@@ -99,4 +101,11 @@ message PdmObjectGetMethodReply
IntArray ints = 2;
StringArray strings = 3;
}
}
}
message PdmObjectMethodRequest
{
PdmObject object = 1;
string method = 2;
PdmObject params = 3;
}

View File

@@ -0,0 +1,13 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# Example code
project = resinsight.project
summary_cases = project.descendants(rips.SummaryCase)
summary_plot_collection = project.descendants(rips.SummaryPlotCollection)[0]
summary_plot = summary_plot_collection.new_summary_plot(summary_cases=summary_cases)

View File

@@ -179,10 +179,12 @@ def __convert_to_grpc_value(self, value):
if value:
return "true"
return "false"
if isinstance(value, PdmObject):
return value.__class__.__name__ + ":" + str(value.address())
if isinstance(value, list):
list_of_strings = []
for val in value:
list_of_strings.append(self.__convert_to_grpc_value('\"' + val + '\"'))
list_of_strings.append('\"' + self.__convert_to_grpc_value(val) + '\"')
return "[" + ", ".join(list_of_strings) + "]"
return str(value)
@@ -301,8 +303,8 @@ def ancestor(self, class_definition):
@add_method(PdmObject)
def _call_get_method_async(self, method_name):
request = PdmObject_pb2.PdmObjectMethodRequest(object=self._pb2_object, method=method_name)
for chunk in self._pdm_object_stub.CallPdmObjectGetMethod(request):
request = PdmObject_pb2.PdmObjectGetterRequest(object=self._pb2_object, method=method_name)
for chunk in self._pdm_object_stub.CallPdmObjectGetter(request):
yield chunk
@add_method(PdmObject)
@@ -320,40 +322,48 @@ def __generate_set_method_chunks(self, array, method_request):
index = -1
while index < len(array):
chunk = PdmObject_pb2.PdmObjectSetMethodChunk()
chunk = PdmObject_pb2.PdmObjectSetterChunk()
if index is -1:
chunk.set_request.CopyFrom(PdmObject_pb2.PdmObjectSetMethodRequest(request=method_request, data_count=len(array)))
chunk.set_request.CopyFrom(PdmObject_pb2.PdmObjectSetterRequest(request=method_request, data_count=len(array)))
index += 1
else:
actual_chunk_size = min(len(array) - index + 1, self.__chunk_size)
if isinstance(array[0], float):
chunk.CopyFrom(
PdmObject_pb2.PdmObjectSetMethodChunk(doubles=PdmObject_pb2.DoubleArray(data=array[index:index +
PdmObject_pb2.PdmObjectSetterChunk(doubles=PdmObject_pb2.DoubleArray(data=array[index:index +
actual_chunk_size])))
elif isinstance(array[0], int):
chunk.CopyFrom(
PdmObject_pb2.PdmObjectSetMethodChunk(ints=PdmObject_pb2.IntArray(data=array[index:index +
PdmObject_pb2.PdmObjectSetterChunk(ints=PdmObject_pb2.IntArray(data=array[index:index +
actual_chunk_size])))
elif isinstance(array[0], str):
chunk.CopyFrom(
PdmObject_pb2.PdmObjectSetMethodChunk(strings=PdmObject_pb2.StringArray(data=array[index:index +
PdmObject_pb2.PdmObjectSetterChunk(strings=PdmObject_pb2.StringArray(data=array[index:index +
actual_chunk_size])))
else:
raise Exception("Wrong data type for set method")
index += actual_chunk_size
yield chunk
# Final empty message to signal completion
chunk = PdmObject_pb2.PdmObjectSetMethodChunk()
chunk = PdmObject_pb2.PdmObjectSetterChunk()
yield chunk
@add_method(PdmObject)
def _call_set_method(self, method_name, values):
method_request = PdmObject_pb2.PdmObjectMethodRequest(object=self._pb2_object, method=method_name)
method_request = PdmObject_pb2.PdmObjectGetterRequest(object=self._pb2_object, method=method_name)
request_iterator = self.__generate_set_method_chunks(values, method_request)
reply = self._pdm_object_stub.CallPdmObjectSetMethod(request_iterator)
reply = self._pdm_object_stub.CallPdmObjectSetter(request_iterator)
if reply.accepted_value_count < len(values):
raise IndexError
@add_method(PdmObject)
def _call_pdm_method(self, method_name, **kwargs):
pb2_params = PdmObject_pb2.PdmObject(class_keyword=method_name)
for key, value in kwargs.items():
pb2_params.parameters[snake_to_camel(key)] = self.__convert_to_grpc_value(value)
request = PdmObject_pb2.PdmObjectMethodRequest(object=self._pb2_object, method=method_name, params=pb2_params)
return self._pdm_object_stub.CallPdmObjectMethod(request)
@add_method(PdmObject)
def update(self):
"""Sync all fields from the Python Object to ResInsight"""

View File

@@ -79,14 +79,14 @@ grpc::Status RiaGrpcCommandService::Execute( grpc::ServerContext* context, const
}
// Execute command
RicfCommandResponse response = commandHandle->execute();
caf::PdmScriptResponse response = commandHandle->execute();
// Copy results
if ( response.status() == RicfCommandResponse::COMMAND_ERROR )
if ( response.status() == caf::PdmScriptResponse::COMMAND_ERROR )
{
return grpc::Status( grpc::FAILED_PRECONDITION, response.sanitizedResponseMessage().toStdString() );
}
else if ( response.status() == RicfCommandResponse::COMMAND_WARNING )
else if ( response.status() == caf::PdmScriptResponse::COMMAND_WARNING )
{
context->AddTrailingMetadata( "warning", response.sanitizedResponseMessage().toStdString() );
}

View File

@@ -19,13 +19,14 @@
#include "RiaApplication.h"
#include "RiaGrpcCallbacks.h"
#include "RicfObjectCapability.h"
#include "Rim3dView.h"
#include "RimEclipseResultDefinition.h"
#include "RimProject.h"
#include "cafPdmFieldScriptability.h"
#include "cafPdmObject.h"
#include "cafPdmObjectMethod.h"
#include "cafPdmObjectScriptability.h"
#include "cafPdmObjectScriptabilityRegister.h"
using namespace rips;
@@ -41,26 +42,26 @@ struct DataHolder : public AbstractDataHolder
size_t dataCount() const override { return data.size(); }
size_t dataSizeOf() const override { return sizeof( typename DataType::value_type ); }
void reserveReplyStorage( rips::PdmObjectGetMethodReply* reply ) const;
void addValueToReply( size_t valueIndex, rips::PdmObjectGetMethodReply* reply ) const;
size_t getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetMethodChunk* chunk );
void reserveReplyStorage( rips::PdmObjectGetterReply* reply ) const;
void addValueToReply( size_t valueIndex, rips::PdmObjectGetterReply* reply ) const;
size_t getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetterChunk* chunk );
void applyValuesToProxyField( caf::PdmProxyFieldHandle* proxyField );
DataType data;
};
template <>
void DataHolder<std::vector<int>>::reserveReplyStorage( rips::PdmObjectGetMethodReply* reply ) const
void DataHolder<std::vector<int>>::reserveReplyStorage( rips::PdmObjectGetterReply* reply ) const
{
reply->mutable_ints()->mutable_data()->Reserve( data.size() );
}
template <>
void DataHolder<std::vector<int>>::addValueToReply( size_t valueIndex, rips::PdmObjectGetMethodReply* reply ) const
void DataHolder<std::vector<int>>::addValueToReply( size_t valueIndex, rips::PdmObjectGetterReply* reply ) const
{
reply->mutable_ints()->add_data( data[valueIndex] );
}
template <>
size_t DataHolder<std::vector<int>>::getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetMethodChunk* chunk )
size_t DataHolder<std::vector<int>>::getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetterChunk* chunk )
{
size_t chunkSize = chunk->ints().data_size();
size_t currentIndex = startIndex;
@@ -83,17 +84,17 @@ void DataHolder<std::vector<int>>::applyValuesToProxyField( caf::PdmProxyFieldHa
}
template <>
void DataHolder<std::vector<double>>::reserveReplyStorage( rips::PdmObjectGetMethodReply* reply ) const
void DataHolder<std::vector<double>>::reserveReplyStorage( rips::PdmObjectGetterReply* reply ) const
{
reply->mutable_doubles()->mutable_data()->Reserve( data.size() );
}
template <>
void DataHolder<std::vector<double>>::addValueToReply( size_t valueIndex, rips::PdmObjectGetMethodReply* reply ) const
void DataHolder<std::vector<double>>::addValueToReply( size_t valueIndex, rips::PdmObjectGetterReply* reply ) const
{
reply->mutable_doubles()->add_data( data[valueIndex] );
}
template <>
size_t DataHolder<std::vector<double>>::getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetMethodChunk* chunk )
size_t DataHolder<std::vector<double>>::getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetterChunk* chunk )
{
size_t chunkSize = chunk->doubles().data_size();
size_t currentIndex = startIndex;
@@ -116,17 +117,17 @@ void DataHolder<std::vector<double>>::applyValuesToProxyField( caf::PdmProxyFiel
}
template <>
void DataHolder<std::vector<QString>>::reserveReplyStorage( rips::PdmObjectGetMethodReply* reply ) const
void DataHolder<std::vector<QString>>::reserveReplyStorage( rips::PdmObjectGetterReply* reply ) const
{
reply->mutable_strings()->mutable_data()->Reserve( data.size() );
}
template <>
void DataHolder<std::vector<QString>>::addValueToReply( size_t valueIndex, rips::PdmObjectGetMethodReply* reply ) const
void DataHolder<std::vector<QString>>::addValueToReply( size_t valueIndex, rips::PdmObjectGetterReply* reply ) const
{
reply->mutable_strings()->add_data( data[valueIndex].toStdString() );
}
template <>
size_t DataHolder<std::vector<QString>>::getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetMethodChunk* chunk )
size_t DataHolder<std::vector<QString>>::getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetterChunk* chunk )
{
size_t chunkSize = chunk->strings().data_size();
size_t currentIndex = startIndex;
@@ -162,7 +163,7 @@ RiaPdmObjectMethodStateHandler::RiaPdmObjectMethodStateHandler( bool clientToSer
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Status RiaPdmObjectMethodStateHandler::init( const rips::PdmObjectMethodRequest* request )
Status RiaPdmObjectMethodStateHandler::init( const rips::PdmObjectGetterRequest* request )
{
CAF_ASSERT( !m_clientToServerStreamer );
m_fieldOwner = RiaGrpcPdmObjectService::findCafObjectFromRipsObject( request->object() );
@@ -212,7 +213,7 @@ Status RiaPdmObjectMethodStateHandler::init( const rips::PdmObjectMethodRequest*
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Status RiaPdmObjectMethodStateHandler::init( const rips::PdmObjectSetMethodChunk* chunk )
Status RiaPdmObjectMethodStateHandler::init( const rips::PdmObjectSetterChunk* chunk )
{
CAF_ASSERT( m_clientToServerStreamer );
CAF_ASSERT( chunk->has_set_request() );
@@ -262,7 +263,7 @@ Status RiaPdmObjectMethodStateHandler::init( const rips::PdmObjectSetMethodChunk
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Status RiaPdmObjectMethodStateHandler::assignReply( rips::PdmObjectGetMethodReply* reply )
Status RiaPdmObjectMethodStateHandler::assignReply( rips::PdmObjectGetterReply* reply )
{
CAF_ASSERT( m_dataHolder );
const size_t packageSize = RiaGrpcServiceInterface::numberOfDataUnitsInPackage( m_dataHolder->dataSizeOf() );
@@ -285,8 +286,8 @@ Status RiaPdmObjectMethodStateHandler::assignReply( rips::PdmObjectGetMethodRepl
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Status RiaPdmObjectMethodStateHandler::receiveRequest( const rips::PdmObjectSetMethodChunk* chunk,
rips::ClientToServerStreamReply* reply )
Status RiaPdmObjectMethodStateHandler::receiveRequest( const rips::PdmObjectSetterChunk* chunk,
rips::ClientToServerStreamReply* reply )
{
size_t valuesWritten = m_dataHolder->getValuesFromChunk( m_currentDataIndex, chunk );
m_currentDataIndex += valuesWritten;
@@ -488,10 +489,10 @@ grpc::Status RiaGrpcPdmObjectService::CreateChildPdmObject( grpc::ServerContext*
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
grpc::Status RiaGrpcPdmObjectService::CallPdmObjectGetMethod( grpc::ServerContext* context,
const rips::PdmObjectMethodRequest* request,
rips::PdmObjectGetMethodReply* reply,
RiaPdmObjectMethodStateHandler* stateHandler )
grpc::Status RiaGrpcPdmObjectService::CallPdmObjectGetter( grpc::ServerContext* context,
const rips::PdmObjectGetterRequest* request,
rips::PdmObjectGetterReply* reply,
RiaPdmObjectMethodStateHandler* stateHandler )
{
return stateHandler->assignReply( reply );
}
@@ -499,70 +500,115 @@ grpc::Status RiaGrpcPdmObjectService::CallPdmObjectGetMethod( grpc::ServerContex
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
grpc::Status RiaGrpcPdmObjectService::CallPdmObjectSetMethod( grpc::ServerContext* context,
const rips::PdmObjectSetMethodChunk* chunk,
rips::ClientToServerStreamReply* reply,
RiaPdmObjectMethodStateHandler* stateHandler )
grpc::Status RiaGrpcPdmObjectService::CallPdmObjectSetter( grpc::ServerContext* context,
const rips::PdmObjectSetterChunk* chunk,
rips::ClientToServerStreamReply* reply,
RiaPdmObjectMethodStateHandler* stateHandler )
{
return stateHandler->receiveRequest( chunk, reply );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
grpc::Status RiaGrpcPdmObjectService::CallPdmObjectMethod( grpc::ServerContext* context,
const rips::PdmObjectMethodRequest* request,
rips::PdmObject* reply )
{
auto matchingObject = findCafObjectFromRipsObject( request->object() );
if ( matchingObject )
{
QString methodKeyword = QString::fromStdString( request->method() );
std::shared_ptr<caf::PdmObjectMethod> method =
caf::PdmObjectMethodFactory::instance()->createMethod( matchingObject, methodKeyword );
if ( method )
{
copyPdmObjectFromRipsToCaf( &( request->params() ), method.get() );
caf::PdmObjectHandle* result = method->execute();
copyPdmObjectFromCafToRips( result, reply );
if ( method->deleteObjectAfterReply() )
{
delete result;
}
return grpc::Status::OK;
}
return grpc::Status( grpc::NOT_FOUND, "Could not find Method" );
}
return grpc::Status( grpc::NOT_FOUND, "Could not find PdmObject" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RiaGrpcCallbackInterface*> RiaGrpcPdmObjectService::createCallbacks()
{
typedef RiaGrpcPdmObjectService Self;
return {new RiaGrpcUnaryCallback<Self, PdmParentObjectRequest, PdmObject>( this,
&Self::GetAncestorPdmObject,
&Self::RequestGetAncestorPdmObject ),
new RiaGrpcUnaryCallback<Self, PdmDescendantObjectRequest, PdmObjectArray>( this,
&Self::GetDescendantPdmObjects,
&Self::RequestGetDescendantPdmObjects ),
new RiaGrpcUnaryCallback<Self, PdmChildObjectRequest, PdmObjectArray>( this,
&Self::GetChildPdmObjects,
&Self::RequestGetChildPdmObjects ),
new RiaGrpcUnaryCallback<Self, PdmObject, Empty>( this,
&Self::UpdateExistingPdmObject,
&Self::RequestUpdateExistingPdmObject ),
new RiaGrpcUnaryCallback<Self, CreatePdmChildObjectRequest, PdmObject>( this,
&Self::CreateChildPdmObject,
&Self::RequestCreateChildPdmObject ),
new RiaGrpcServerToClientStreamCallback<Self,
PdmObjectMethodRequest,
PdmObjectGetMethodReply,
RiaPdmObjectMethodStateHandler>( this,
&Self::CallPdmObjectGetMethod,
&Self::RequestCallPdmObjectGetMethod,
new RiaPdmObjectMethodStateHandler ),
return {
new RiaGrpcUnaryCallback<Self, PdmParentObjectRequest, PdmObject>( this,
&Self::GetAncestorPdmObject,
&Self::RequestGetAncestorPdmObject ),
new RiaGrpcUnaryCallback<Self, PdmDescendantObjectRequest, PdmObjectArray>( this,
&Self::GetDescendantPdmObjects,
&Self::RequestGetDescendantPdmObjects ),
new RiaGrpcUnaryCallback<Self, PdmChildObjectRequest, PdmObjectArray>( this,
&Self::GetChildPdmObjects,
&Self::RequestGetChildPdmObjects ),
new RiaGrpcUnaryCallback<Self, PdmObject, Empty>( this,
&Self::UpdateExistingPdmObject,
&Self::RequestUpdateExistingPdmObject ),
new RiaGrpcUnaryCallback<Self, CreatePdmChildObjectRequest, PdmObject>( this,
&Self::CreateChildPdmObject,
&Self::RequestCreateChildPdmObject ),
new RiaGrpcServerToClientStreamCallback<Self,
PdmObjectGetterRequest,
PdmObjectGetterReply,
RiaPdmObjectMethodStateHandler>( this,
&Self::CallPdmObjectGetter,
&Self::RequestCallPdmObjectGetter,
new RiaPdmObjectMethodStateHandler ),
new RiaGrpcClientToServerStreamCallback<Self,
PdmObjectSetMethodChunk,
ClientToServerStreamReply,
RiaPdmObjectMethodStateHandler>( this,
&Self::CallPdmObjectSetMethod,
&Self::RequestCallPdmObjectSetMethod,
new RiaPdmObjectMethodStateHandler(
true ) )};
new RiaGrpcClientToServerStreamCallback<Self,
PdmObjectSetterChunk,
ClientToServerStreamReply,
RiaPdmObjectMethodStateHandler>( this,
&Self::CallPdmObjectSetter,
&Self::RequestCallPdmObjectSetter,
new RiaPdmObjectMethodStateHandler( true ) ),
new RiaGrpcUnaryCallback<Self, PdmObjectMethodRequest, PdmObject>( this,
&Self::CallPdmObjectMethod,
&Self::RequestCallPdmObjectMethod ),
};
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObject* RiaGrpcPdmObjectService::findCafObjectFromRipsObject( const rips::PdmObject& ripsObject )
{
QString scriptClassName = QString::fromStdString( ripsObject.class_keyword() );
uint64_t address = ripsObject.address();
return findCafObjectFromScriptNameAndAddress( scriptClassName, address );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObject* RiaGrpcPdmObjectService::findCafObjectFromScriptNameAndAddress( const QString& scriptClassName,
uint64_t address )
{
RimProject* project = RiaApplication::instance()->project();
std::vector<caf::PdmObject*> objectsOfCurrentClass;
QString scriptClassName = QString::fromStdString( ripsObject.class_keyword() );
QString classKeyword = caf::PdmObjectScriptabilityRegister::classKeywordFromScriptClassName( scriptClassName );
QString classKeyword = caf::PdmObjectScriptabilityRegister::classKeywordFromScriptClassName( scriptClassName );
project->descendantsIncludingThisFromClassKeyword( classKeyword, objectsOfCurrentClass );
caf::PdmObject* matchingObject = nullptr;
for ( caf::PdmObject* testObject : objectsOfCurrentClass )
{
if ( reinterpret_cast<uint64_t>( testObject ) == ripsObject.address() )
if ( reinterpret_cast<uint64_t>( testObject ) == address )
{
matchingObject = testObject;
}

View File

@@ -30,13 +30,13 @@ class PdmProxyFieldHandle;
struct AbstractDataHolder
{
virtual size_t dataCount() const = 0;
virtual size_t dataSizeOf() const = 0;
virtual void reserveReplyStorage( rips::PdmObjectGetMethodReply* reply ) const = 0;
virtual void addValueToReply( size_t valueIndex, rips::PdmObjectGetMethodReply* reply ) const = 0;
virtual size_t dataCount() const = 0;
virtual size_t dataSizeOf() const = 0;
virtual void reserveReplyStorage( rips::PdmObjectGetterReply* reply ) const = 0;
virtual void addValueToReply( size_t valueIndex, rips::PdmObjectGetterReply* reply ) const = 0;
virtual size_t getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetMethodChunk* chunk ) = 0;
virtual void applyValuesToProxyField( caf::PdmProxyFieldHandle* proxyField ) = 0;
virtual size_t getValuesFromChunk( size_t startIndex, const rips::PdmObjectSetterChunk* chunk ) = 0;
virtual void applyValuesToProxyField( caf::PdmProxyFieldHandle* proxyField ) = 0;
};
//==================================================================================================
@@ -51,10 +51,10 @@ class RiaPdmObjectMethodStateHandler
public:
RiaPdmObjectMethodStateHandler( bool clientToServerStreamer = false );
Status init( const rips::PdmObjectMethodRequest* request );
Status init( const rips::PdmObjectSetMethodChunk* chunk );
Status assignReply( rips::PdmObjectGetMethodReply* reply );
Status receiveRequest( const rips::PdmObjectSetMethodChunk* chunk, rips::ClientToServerStreamReply* reply );
Status init( const rips::PdmObjectGetterRequest* request );
Status init( const rips::PdmObjectSetterChunk* chunk );
Status assignReply( rips::PdmObjectGetterReply* reply );
Status receiveRequest( const rips::PdmObjectSetterChunk* chunk, rips::ClientToServerStreamReply* reply );
size_t streamedValueCount() const;
size_t totalValueCount() const;
void finish();
@@ -93,16 +93,20 @@ public:
const rips::PdmObject* request,
rips::Empty* response ) override;
grpc::Status CallPdmObjectGetMethod( grpc::ServerContext* context,
const rips::PdmObjectMethodRequest* request,
rips::PdmObjectGetMethodReply* reply,
RiaPdmObjectMethodStateHandler* stateHandler );
grpc::Status CallPdmObjectSetMethod( grpc::ServerContext* context,
const rips::PdmObjectSetMethodChunk* chunk,
rips::ClientToServerStreamReply* reply,
RiaPdmObjectMethodStateHandler* stateHandler );
grpc::Status CallPdmObjectGetter( grpc::ServerContext* context,
const rips::PdmObjectGetterRequest* request,
rips::PdmObjectGetterReply* reply,
RiaPdmObjectMethodStateHandler* stateHandler );
grpc::Status CallPdmObjectSetter( grpc::ServerContext* context,
const rips::PdmObjectSetterChunk* chunk,
rips::ClientToServerStreamReply* reply,
RiaPdmObjectMethodStateHandler* stateHandler );
grpc::Status CallPdmObjectMethod( grpc::ServerContext* context,
const rips::PdmObjectMethodRequest* request,
rips::PdmObject* reply ) override;
std::vector<RiaGrpcCallbackInterface*> createCallbacks() override;
static caf::PdmObject* findCafObjectFromRipsObject( const rips::PdmObject& ripsObject );
static caf::PdmObject* findCafObjectFromScriptNameAndAddress( const QString& scriptClassName, uint64_t address );
};

View File

@@ -21,13 +21,12 @@
#include "RimCase.h"
#include "RimProject.h"
#include "RicfFieldHandle.h"
#include "RicfObjectCapability.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmChildField.h"
#include "cafPdmDataValueField.h"
#include "cafPdmFieldScriptability.h"
#include "cafPdmObject.h"
#include "cafPdmObjectScriptability.h"
#include "cafPdmObjectScriptabilityRegister.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmScriptIOMessages.h"
@@ -99,7 +98,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromCafToRips( const caf::PdmObjectHa
if ( pdmValueField )
{
QString keyword = pdmValueField->keyword();
auto ricfHandle = field->template capability<RicfFieldHandle>();
auto ricfHandle = field->template capability<caf::PdmFieldScriptability>();
if ( ricfHandle != nullptr )
{
auto pdmProxyField = dynamic_cast<const caf::PdmProxyFieldHandle*>( field );
@@ -141,20 +140,16 @@ void RiaGrpcServiceInterface::copyPdmObjectFromRipsToCaf( const rips::PdmObject*
auto parametersMap = source->parameters();
for ( auto field : fields )
{
auto pdmValueField = dynamic_cast<caf::PdmValueField*>( field );
if ( pdmValueField )
auto scriptability = field->template capability<caf::PdmFieldScriptability>();
if ( scriptability )
{
auto ricfHandle = pdmValueField->template capability<RicfFieldHandle>();
if ( ricfHandle )
{
QString keyword = ricfHandle->scriptFieldName();
QString value = QString::fromStdString( parametersMap[keyword.toStdString()] );
QString keyword = scriptability->scriptFieldName();
QString value = QString::fromStdString( parametersMap[keyword.toStdString()] );
QVariant oldValue, newValue;
if ( assignFieldValue( value, pdmValueField, &oldValue, &newValue ) )
{
destination->uiCapability()->fieldChangedByUi( field, oldValue, newValue );
}
QVariant oldValue, newValue;
if ( assignFieldValue( value, field, &oldValue, &newValue ) )
{
destination->uiCapability()->fieldChangedByUi( field, oldValue, newValue );
}
}
}
@@ -163,21 +158,22 @@ void RiaGrpcServiceInterface::copyPdmObjectFromRipsToCaf( const rips::PdmObject*
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaGrpcServiceInterface::assignFieldValue( const QString& stringValue,
caf::PdmValueField* field,
QVariant* oldValue,
QVariant* newValue )
bool RiaGrpcServiceInterface::assignFieldValue( const QString& stringValue,
caf::PdmFieldHandle* field,
QVariant* oldValue,
QVariant* newValue )
{
CAF_ASSERT( oldValue && newValue );
auto ricfHandle = field->template capability<RicfFieldHandle>();
if ( field && ricfHandle != nullptr )
auto scriptability = field->template capability<caf::PdmFieldScriptability>();
if ( field && scriptability != nullptr )
{
caf::PdmValueField* valueField = dynamic_cast<caf::PdmValueField*>( field );
QTextStream stream( stringValue.toLatin1() );
caf::PdmScriptIOMessages messages;
*oldValue = field->toQVariant();
ricfHandle->writeToField( stream, nullptr, &messages, false );
*newValue = field->toQVariant();
if ( valueField ) *oldValue = valueField->toQVariant();
scriptability->writeToField( stream, nullptr, &messages, false, RiaApplication::instance()->project() );
if ( valueField ) *newValue = valueField->toQVariant();
return true;
}
return false;

View File

@@ -28,9 +28,9 @@ namespace caf
{
class PdmChildArrayFieldHandle;
class PdmChildFieldHandle;
class PdmFieldHandle;
class PdmObject;
class PdmObjectHandle;
class PdmValueField;
} // namespace caf
namespace rips
@@ -58,7 +58,7 @@ public:
static void copyPdmObjectFromRipsToCaf( const rips::PdmObject* source, caf::PdmObjectHandle* destination );
static bool
assignFieldValue( const QString& stringValue, caf::PdmValueField* field, QVariant* oldValue, QVariant* newValue );
assignFieldValue( const QString& stringValue, caf::PdmFieldHandle* field, QVariant* oldValue, QVariant* newValue );
static caf::PdmObjectHandle* emplaceChildField( caf::PdmObject* parent, const QString& fieldLabel );