diff --git a/ApplicationCode/GrpcInterface/CMakeLists.cmake b/ApplicationCode/GrpcInterface/CMakeLists.cmake index a67746c921..29e41cb87a 100644 --- a/ApplicationCode/GrpcInterface/CMakeLists.cmake +++ b/ApplicationCode/GrpcInterface/CMakeLists.cmake @@ -2,6 +2,7 @@ cmake_minimum_required (VERSION 2.8.12) set ( SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServer.h + ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcHelper.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCallbacks.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCallbacks.inl ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.h @@ -17,6 +18,7 @@ set ( SOURCE_GROUP_HEADER_FILES set ( SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServer.cpp + ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcHelper.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.cpp diff --git a/ApplicationCode/GrpcInterface/RiaGrpcCaseService.cpp b/ApplicationCode/GrpcInterface/RiaGrpcCaseService.cpp index d53b694b9c..a099cae4dd 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcCaseService.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcCaseService.cpp @@ -16,7 +16,9 @@ // ////////////////////////////////////////////////////////////////////////////////// #include "RiaGrpcCaseService.h" + #include "RiaGrpcCallbacks.h" +#include "RiaGrpcHelper.h" #include "RiaSocketTools.h" #include "RigActiveCellInfo.h" @@ -32,15 +34,6 @@ using namespace rips; -//-------------------------------------------------------------------------------------------------- -/// Convert internal ResInsight representation of cells with negative depth to positive depth. -//-------------------------------------------------------------------------------------------------- -static inline void convertVec3dToPositiveDepth( cvf::Vec3d* vec ) -{ - double& z = vec->z(); - z *= -1; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -254,7 +247,7 @@ void RiaActiveCellInfoStateHandler::assignCellCenter( rips::Vec3d* { cvf::Vec3d center = reservoirCells[cellIdx].center(); - convertVec3dToPositiveDepth( ¢er ); + RiaGrpcHelper::convertVec3dToPositiveDepth( ¢er ); cellCenter->set_x( center.x() ); cellCenter->set_y( center.y() ); @@ -309,17 +302,6 @@ Status RiaActiveCellInfoStateHandler::assignNextActiveCellCorners( rips::CellCor return Status( grpc::OUT_OF_RANGE, "We've reached the end. This is not an error but means transmission is finished" ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -// TODO: duped with TestGrpcGridService -void setCornerValues2( rips::Vec3d* out, const cvf::Vec3d& in ) -{ - out->set_x( in.x() ); - out->set_y( in.y() ); - out->set_z( in.z() ); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -332,17 +314,17 @@ void RiaActiveCellInfoStateHandler::assignCellCorners( rips::CellCorners* grid->cellCornerVertices( cellIdx, cornerVerts ); for ( cvf::Vec3d& corner : cornerVerts ) { - convertVec3dToPositiveDepth( &corner ); + RiaGrpcHelper::convertVec3dToPositiveDepth( &corner ); } - setCornerValues2( corners->mutable_c0(), cornerVerts[0] ); - setCornerValues2( corners->mutable_c1(), cornerVerts[1] ); - setCornerValues2( corners->mutable_c2(), cornerVerts[2] ); - setCornerValues2( corners->mutable_c3(), cornerVerts[3] ); - setCornerValues2( corners->mutable_c4(), cornerVerts[4] ); - setCornerValues2( corners->mutable_c5(), cornerVerts[5] ); - setCornerValues2( corners->mutable_c6(), cornerVerts[6] ); - setCornerValues2( corners->mutable_c7(), cornerVerts[7] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c0(), cornerVerts[0] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c1(), cornerVerts[1] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c2(), cornerVerts[2] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c3(), cornerVerts[3] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c4(), cornerVerts[4] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c5(), cornerVerts[5] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c6(), cornerVerts[6] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c7(), cornerVerts[7] ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/GrpcInterface/RiaGrpcGridService.cpp b/ApplicationCode/GrpcInterface/RiaGrpcGridService.cpp index 054232267b..f9994eef8b 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcGridService.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcGridService.cpp @@ -18,6 +18,7 @@ #include "RiaGrpcGridService.h" #include "RiaGrpcCallbacks.h" +#include "RiaGrpcHelper.h" #include "RigCell.h" #include "RigEclipseCaseData.h" @@ -27,15 +28,6 @@ using namespace rips; -//-------------------------------------------------------------------------------------------------- -/// Convert internal ResInsight representation of cells with negative depth to positive depth. -//-------------------------------------------------------------------------------------------------- -static inline void convertVec3dToPositiveDepth( cvf::Vec3d* vec ) -{ - double& z = vec->z(); - z *= -1; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -86,7 +78,7 @@ grpc::Status RiaCellCenterStateHandler::assignReply( rips::CellCenters* reply ) { cvf::Vec3d center = m_grid->cell( m_currentCellIdx ).center(); - convertVec3dToPositiveDepth( ¢er ); + RiaGrpcHelper::convertVec3dToPositiveDepth( ¢er ); Vec3d* cellCenter = reply->add_centers(); cellCenter->set_x( center.x() ); @@ -101,13 +93,6 @@ grpc::Status RiaCellCenterStateHandler::assignReply( rips::CellCenters* reply ) return Status( grpc::OUT_OF_RANGE, "We've reached the end. This is not an error but means transmission is finished" ); } -void setCornerValues( rips::Vec3d* out, const cvf::Vec3d& in ) -{ - out->set_x( in.x() ); - out->set_y( in.y() ); - out->set_z( in.z() ); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -123,18 +108,18 @@ grpc::Status RiaCellCenterStateHandler::assignCornersReply( rips::CellCornersArr m_grid->cellCornerVertices( m_currentCellIdx, cornerVerts ); for ( cvf::Vec3d& corner : cornerVerts ) { - convertVec3dToPositiveDepth( &corner ); + RiaGrpcHelper::convertVec3dToPositiveDepth( &corner ); } rips::CellCorners* corners = reply->add_cells(); - setCornerValues( corners->mutable_c0(), cornerVerts[0] ); - setCornerValues( corners->mutable_c1(), cornerVerts[1] ); - setCornerValues( corners->mutable_c2(), cornerVerts[2] ); - setCornerValues( corners->mutable_c3(), cornerVerts[3] ); - setCornerValues( corners->mutable_c4(), cornerVerts[4] ); - setCornerValues( corners->mutable_c5(), cornerVerts[5] ); - setCornerValues( corners->mutable_c6(), cornerVerts[6] ); - setCornerValues( corners->mutable_c7(), cornerVerts[7] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c0(), cornerVerts[0] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c1(), cornerVerts[1] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c2(), cornerVerts[2] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c3(), cornerVerts[3] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c4(), cornerVerts[4] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c5(), cornerVerts[5] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c6(), cornerVerts[6] ); + RiaGrpcHelper::setCornerValues( corners->mutable_c7(), cornerVerts[7] ); m_currentCellIdx++; } diff --git a/ApplicationCode/GrpcInterface/RiaGrpcHelper.cpp b/ApplicationCode/GrpcInterface/RiaGrpcHelper.cpp new file mode 100644 index 0000000000..8de881cd04 --- /dev/null +++ b/ApplicationCode/GrpcInterface/RiaGrpcHelper.cpp @@ -0,0 +1,37 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- 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. +// +////////////////////////////////////////////////////////////////////////////////// +#include "RiaGrpcHelper.h" + +//-------------------------------------------------------------------------------------------------- +/// Convert internal ResInsight representation of cells with negative depth to positive depth. +//-------------------------------------------------------------------------------------------------- +void RiaGrpcHelper::convertVec3dToPositiveDepth( cvf::Vec3d* vec ) +{ + double& z = vec->z(); + z *= -1; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaGrpcHelper::setCornerValues( rips::Vec3d* out, const cvf::Vec3d& in ) +{ + out->set_x( in.x() ); + out->set_y( in.y() ); + out->set_z( in.z() ); +} diff --git a/ApplicationCode/GrpcInterface/RiaGrpcHelper.h b/ApplicationCode/GrpcInterface/RiaGrpcHelper.h new file mode 100644 index 0000000000..4f29389fef --- /dev/null +++ b/ApplicationCode/GrpcInterface/RiaGrpcHelper.h @@ -0,0 +1,34 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- 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 "Definitions.grpc.pb.h" + +#include "cvfVector3.h" + +//================================================================================================== +// +// Various gRPC helper methods +// +//================================================================================================== +class RiaGrpcHelper +{ +public: + static void convertVec3dToPositiveDepth( cvf::Vec3d* vec ); + static void setCornerValues( rips::Vec3d* out, const cvf::Vec3d& in ); +};