From 6ce401716504de05074cbf219a3c7584d073d1fe Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Sat, 16 Jan 2021 07:37:55 +0100 Subject: [PATCH] Move Python Study ref creation to KERNEL --- src/KERNEL_PY/__init__.py | 4 ++-- src/SALOMEDS/CMakeLists.txt | 20 +++++++++++++++++++ src/SALOMEDS/KernelDS.cxx | 33 +++++++++++++++++++++++++++++++ src/SALOMEDS/KernelDS.hxx | 22 +++++++++++++++++++++ src/SALOMEDS/KernelDS.i | 39 +++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 src/SALOMEDS/KernelDS.cxx create mode 100644 src/SALOMEDS/KernelDS.hxx create mode 100644 src/SALOMEDS/KernelDS.i diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 2fa22b034..3b723ec3a 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -203,8 +203,8 @@ class StandAloneLifecyle: def salome_init_without_session(): global lcc,myStudy,orb lcc = StandAloneLifecyle() - import GeomHelper - myStudy = GeomHelper.myStudy() + import KernelDS + myStudy = KernelDS.myStudy() import CORBA orb=CORBA.ORB_init(['']) diff --git a/src/SALOMEDS/CMakeLists.txt b/src/SALOMEDS/CMakeLists.txt index 165da98c0..0ab1bd239 100644 --- a/src/SALOMEDS/CMakeLists.txt +++ b/src/SALOMEDS/CMakeLists.txt @@ -17,11 +17,14 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +include(${SWIG_USE_FILE}) + INCLUDE_DIRECTORIES( ${PTHREAD_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIR} ${HDF5_INCLUDE_DIRS} ${Boost_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/salome_adm ${CMAKE_CURRENT_SOURCE_DIR}/../HDFPersist ${CMAKE_CURRENT_SOURCE_DIR}/../Basics @@ -36,6 +39,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../LifeCycleCORBA ${CMAKE_CURRENT_SOURCE_DIR}/../TOOLSDS ${CMAKE_CURRENT_SOURCE_DIR}/../Container + ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR}/idl ) @@ -157,6 +161,22 @@ TARGET_LINK_LIBRARIES(SALOMEDS_Server SalomeDS SALOMEBasics ${COMMON_LIBS} ${OMN ADD_EXECUTABLE(SALOMEDS_Client SALOMEDS_Client.cxx) TARGET_LINK_LIBRARIES(SALOMEDS_Client SalomeDS SALOMEBasics ${COMMON_LIBS} ${OMNIORB_LIBRARIES}) +SET(KernelDS_HEADERS KernelDS.hxx KernelDS.i) +SET(KernelDS_SOURCES KernelDS.cxx ${KernelDS_HEADERS}) +SET_SOURCE_FILES_PROPERTIES(KernelDS.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(KernelDS.i PROPERTIES SWIG_FLAGS "-py3") +SET_SOURCE_FILES_PROPERTIES(KernelDS_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H") +SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelDS.py ) +IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(KernelDS python ${KernelDS_SOURCES}) +ELSE() + SWIG_ADD_LIBRARY(KernelDS LANGUAGE python SOURCES ${KernelDS_SOURCES}) +ENDIF() +SWIG_LINK_LIBRARIES(KernelDS ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeDS SalomeKernelHelpers) +install(TARGETS _KernelDS DESTINATION ${SALOME_INSTALL_LIBS}) +install(FILES ${KernelDS_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) +SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}" ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelDS_REAL_NAME}") + INSTALL(TARGETS SALOMEDS_Server SALOMEDS_Client EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS}) diff --git a/src/SALOMEDS/KernelDS.cxx b/src/SALOMEDS/KernelDS.cxx new file mode 100644 index 000000000..42e19aa70 --- /dev/null +++ b/src/SALOMEDS/KernelDS.cxx @@ -0,0 +1,33 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "KernelDS.hxx" + +#include "SALOME_KernelServices.hxx" +#include "SALOMEDS_Study_i.hxx" + +#include + +std::string GetSessionInstance() +{ + SALOMEDS::Study_var study = KERNEL::getStudyServantSA(); + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::String_var ior = orb->object_to_string(study); + return std::string(ior.in()); +} diff --git a/src/SALOMEDS/KernelDS.hxx b/src/SALOMEDS/KernelDS.hxx new file mode 100644 index 000000000..3d42fd8f8 --- /dev/null +++ b/src/SALOMEDS/KernelDS.hxx @@ -0,0 +1,22 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +std::string GetSessionInstance(); diff --git a/src/SALOMEDS/KernelDS.i b/src/SALOMEDS/KernelDS.i new file mode 100644 index 000000000..1298d9a9b --- /dev/null +++ b/src/SALOMEDS/KernelDS.i @@ -0,0 +1,39 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%module KernelDS + +%include "std_string.i" + +%{ +#include "KernelDS.hxx" +%} + +%inline +{ + std::string GetSessionInstance(); +} + +%pythoncode %{ +def myStudy(): + import SALOMEDS + import CORBA + orb=CORBA.ORB_init(['']) + return orb.string_to_object(GetSessionInstance()) +%} -- 2.39.2