1 # Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #============================================================================
24 # File : PYCALCULATOR.py
25 # Author : Vadim SANDLER, OPEN CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #============================================================================
28 # Instruct Python to load dynamic libraries using global resolution of symbols
29 # This is necessary to ensure that different modules will have the same definition
30 # of dynamic types and C++ RTTI will work between them
33 sys.setdlopenflags(os.RTLD_NOW | os.RTLD_GLOBAL)
35 import PYCALCULATOR_ORB__POA
36 import SALOME_ComponentPy
37 import SALOME_Embedded_NamingService_ClientPy
40 from MEDCouplingClient import *
41 from MEDCouplingCorba import *
43 from salome_utils import verbose
45 class PYCALCULATOR(PYCALCULATOR_ORB__POA.PYCALCULATOR_Gen, SALOME_ComponentPy.SALOME_ComponentPy_i):
48 def __init__(self, orb, poa, contID, containerName, instanceName,
51 if verbose(): print("Begin of PYCALCULATOR::__init__")
53 SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(
57 contID, # SALOME container id
58 containerName, # SALOME container name
59 instanceName, # component instance name
60 interfaceName, # component interface name
61 False) # notification flag (for notification server)
63 emb_ns = self._contId.get_embedded_NS_if_ssl()
65 if CORBA.is_nil(emb_ns):
66 self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
68 self._naming_service = SALOME_Embedded_NamingService_ClientPy.SALOME_Embedded_NamingService_ClientPy(emb_ns)
70 if verbose(): print("End of PYCALCULATOR::__init__")
74 ## base interface method: get version of the component
75 def getVersion( self ):
77 return salome_version.getVersion("PYCALCULATOR", True)
79 ## interface service: clone field
80 def Clone(self, field):
81 self.beginService("PYCALCULATOR::Clone")
84 print("Begin of PYCALCULATOR::Clone")
85 print(" field : ", field)
91 # create local field from corba field
92 f = MEDCouplingFieldDoubleClient.New(field)
95 frescorba = MEDCouplingFieldDoubleServant._this(f)
97 except Exception as e:
98 if verbose(): print(e)
102 print("End of PYCALCULATOR::Clone")
105 self.endService("PYCALCULATOR::Clone")
109 ## interface service: add two fields
110 def Add(self, field1, field2):
111 self.beginService("PYCALCULATOR::Add")
114 print("Begin of PYCALCULATOR::Add")
115 print(" field 1 : ", field1)
116 print(" field 2 : ", field2)
122 # create local fields from corba fields
123 f1 = MEDCouplingFieldDoubleClient.New(field1)
124 f2 = MEDCouplingFieldDoubleClient.New(field2)
127 f2.changeUnderlyingMesh(f1.getMesh(), 0, 1e-12)
131 frescorba = MEDCouplingFieldDoubleServant._this(fres)
133 except Exception as e:
134 if verbose(): print(e)
138 print("End of PYCALCULATOR::Add")
141 self.endService("PYCALCULATOR::Add")
145 ## interface service: multiply two fields
146 def Mul(self, field1, field2):
147 self.beginService("PYCALCULATOR::Mul")
150 print("Begin of PYCALCULATOR::Mul")
151 print(" field 1 : ", field1)
152 print(" field 2 : ", field2)
158 # create local fields from corba fields
159 f1 = MEDCouplingFieldDoubleClient.New(field1)
160 f2 = MEDCouplingFieldDoubleClient.New(field2)
163 f2.changeUnderlyingMesh(f1.getMesh(), 0, 1e-12)
167 frescorba = MEDCouplingFieldDoubleServant._this(fres)
169 except Exception as e:
170 if verbose(): print(e)
174 print("End of PYCALCULATOR::Mul")
177 self.endService("PYCALCULATOR::Mul")
181 ## interface service: add a constant to a field
182 def AddConstant(self, field, val):
183 self.beginService("PYCALCULATOR::AddConstant")
186 print("Begin of PYCALCULATOR::AddConstant")
187 print(" field : ", field)
188 print(" constant : ", val)
194 # create local field from corba field
195 f = MEDCouplingFieldDoubleClient.New(field)
197 # add constant to a field
201 frescorba = MEDCouplingFieldDoubleServant._this(fres)
203 except Exception as e:
204 if verbose(): print(e)
208 print("End of PYCALCULATOR::AddConstant")
211 self.endService("PYCALCULATOR::AddConstant")
215 ## interface service: multiply a field to a constant
216 def MulConstant(self, field, val):
217 self.beginService("PYCALCULATOR::MulConstant")
220 print("Begin of PYCALCULATOR::MulConstant")
221 print(" field : ", field)
222 print(" constant : ", val)
228 # create local field from corba field
229 f = MEDCouplingFieldDoubleClient.New(field)
231 # multiply field to a constant
235 frescorba = MEDCouplingFieldDoubleServant._this(fres)
237 except Exception as e:
238 if verbose(): print(e)
242 print("End of PYCALCULATOR::MulConstant")
245 self.endService("PYCALCULATOR::MulConstant")
249 pass # end of class PYCALCULATOR