Salome HOME
7e8e2d5f6e6c31d748d7e66dac2082a558d25845
[modules/kernel.git] / src / Basics / KernelBasis.i
1 // Copyright (C) 2021-2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 %module KernelBasis
21
22 %pythonbegin %{
23   # new mechanism introduced in Python 3.8+ about DLL resolution
24   import os
25   def __add_dll_directory__(path):
26     paths = [ p.replace("\\\\", "\\").replace("/", "\\") for p in sys.path]
27     if not path in paths and os.path.exists(path):
28       os.add_dll_directory(path)
29     else:
30       print("DEBUG: directory is already present in {}".format(path))
31     return
32
33   import platform
34   if platform.system() == "Windows":
35     import sys
36     if sys.version_info > (3,8) :
37       try:
38         import os
39         _dll_exposed = os.getenv("KERNEL_DLLs_Exposed", "")
40         if _dll_exposed == "" :
41           print("INFO: Exposing DLL directories")
42           __add_dll_directory__(os.path.join(os.getenv("KERNEL_ROOT_DIR"),  "lib", "salome"))
43           __add_dll_directory__(os.path.join(os.getenv("GUI_ROOT_DIR"),     "lib", "salome"))
44           __add_dll_directory__(os.path.join(os.getenv("GUI_ROOT_DIR"),     "lib", "salome"))
45           __add_dll_directory__(os.path.join(os.getenv("PTHREAD_ROOT_DIR"), "lib"          ))
46           __add_dll_directory__(os.path.join(os.getenv("PRODUCT_ROOT_DIR"), "W64", "lib"   ))
47           __add_dll_directory__(os.path.join(os.getenv("PRODUCT_ROOT_DIR"), "W64", "bin"   ))
48           __add_dll_directory__(os.getenv("OMNIORB_BIN_DIR"))
49           os.environ["KERNEL_DLLs_Exposed"] = "1"
50       except Exception:
51         print("FATAL: Exception raise while trying to expose DLLs")
52 %}
53
54 %{
55 #include "KernelBasis.hxx"
56 #include "HeatMarcel.hxx"
57 #include "libSALOMELog.hxx"
58 #include "Monitoring.hxx"
59 using namespace SALOME;
60 %}
61
62 %include std_string.i
63 %include std_set.i
64 %include std_except.i
65 %include std_vector.i
66
67 %template(dvec) std::vector<double>;
68
69 %exception {
70    try 
71    {
72       $action
73    } 
74    catch(std::exception& e) 
75    {
76       SWIG_exception(SWIG_SystemError, e.what() );
77    } 
78    catch(...) 
79    {
80      SWIG_exception(SWIG_UnknownError, "Unknown exception");
81    }
82 }
83
84 %rename (HeatMarcel) HeatMarcelSwig;
85
86 bool getSSLMode();
87 void setSSLMode(bool sslMode);
88
89 bool getGUIMode();
90 void setGUIMode(bool guiMode);
91
92 std::string getIOROfEmbeddedNS();
93 void setIOROfEmbeddedNS(const std::string& ior);
94
95 double GetTimeAdjustmentCst();
96
97 long LaunchMonitoring(const std::string& pyScriptToEvaluate);
98
99 void StopMonitoring(long pid);
100
101 bool VerbosityActivated();
102
103 void SetVerbosityActivated(bool flag);
104
105 bool IsDebugLevel();
106
107 bool IsInfoLevel();
108
109 bool IsWarningLevel();
110
111 bool IsErrorLevel();
112
113 void WriteInStdout(const std::string& msg);
114
115 void WriteInStderr(const std::string& msg);
116
117 %rename (SetVerbosityLevel) SetVerbosityLevelSwig;
118 %rename (VerbosityLevel) VerbosityLevelSwig;
119
120 %inline
121 {
122 PyObject *HeatMarcelSwig(double timeAjustment, unsigned int nbThreads = 0)
123 {
124   double timeInS = 0.0;
125   long double piVal = HeatMarcel(timeAjustment,timeInS,nbThreads);
126   PyObject *ret(PyTuple_New(2));
127   PyTuple_SetItem(ret,0,SWIG_From_double((double)piVal));
128   PyTuple_SetItem(ret,1,SWIG_From_double(timeInS));
129   return ret;
130 }
131
132 std::vector<double> ReadFloatsInFileSwig(const std::string& fileName)
133 {
134   std::vector<double> ret;
135   try
136   {
137     ret = SALOME::ReadFloatsInFile( fileName );
138   }
139   catch(std::exception& e) { }
140   return ret;
141 }
142
143 void SetVerbosityLevelSwig(const std::string& level)
144 {
145   SetVerbosityLevelStr(level);
146 }
147
148 std::string VerbosityLevelSwig()
149 {
150   return VerbosityLevelStr();
151 }
152 }
153
154 %pythoncode %{
155 def ReadFloatsInFile( fileName ):
156   ret = ReadFloatsInFileSwig( fileName )
157   return ret
158 %}