Salome HOME
Update copyrights 2014.
[samples/pycalculator.git] / src / PYCALCULATOR / PYCALCULATOR.py
1 # Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 #============================================================================
24 # File   : PYCALCULATOR.py
25 # Author : Vadim SANDLER, OPEN CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #============================================================================
27
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
31 #
32 import DLFCN, sys
33 sys.setdlopenflags(DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL)
34
35 import PYCALCULATOR_ORB__POA
36 import SALOME_ComponentPy
37
38 import SALOME_MED
39 from MEDCouplingClient import *
40 from MEDCouplingCorba  import *
41
42 from salome_utils import verbose
43
44 class PYCALCULATOR(PYCALCULATOR_ORB__POA.PYCALCULATOR_Gen, SALOME_ComponentPy.SALOME_ComponentPy_i):
45
46     ## Constructor
47     def __init__(self, orb, poa, contID, containerName, instanceName,
48                  interfaceName):
49
50         if verbose(): print "Begin of PYCALCULATOR::__init__"
51
52         SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(
53             self,
54             orb,              # ORB instance
55             poa,              # POA instance
56             contID,           # SALOME container id
57             containerName,    # SALOME container name
58             instanceName,     # component instance name
59             interfaceName,    # component interface name
60             0)                # notification flag (for notification server)
61
62         self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i(self._orb)
63
64         if verbose(): print "End of PYCALCULATOR::__init__"
65
66         pass
67
68     ## base interface method: get version of the component
69     def getVersion( self ):
70         import salome_version
71         return salome_version.getVersion("PYCALCULATOR", True)
72
73     ## interface service: clone field
74     def Clone(self, field):
75         self.beginService("PYCALCULATOR::Clone")
76
77         if verbose(): 
78             print "Begin of PYCALCULATOR::Clone"
79             print "            field : ", field
80             pass
81
82         frescorba = None
83         
84         try:
85             # create local field from corba field
86             f = MEDCouplingFieldDoubleClient.New(field)
87
88             # create CORBA field
89             frescorba = MEDCouplingFieldDoubleServant._this(f)
90             
91         except Exception, e:
92             if verbose(): print e
93             pass
94         
95         if verbose(): 
96             print "End of PYCALCULATOR::Clone"
97             pass
98         
99         self.endService("PYCALCULATOR::Clone")
100
101         return frescorba
102
103     ## interface service: add two fields
104     def Add(self, field1, field2):
105         self.beginService("PYCALCULATOR::Add")
106
107         if verbose(): 
108             print "Begin of PYCALCULATOR::Add"
109             print "            field 1 : ", field1
110             print "            field 2 : ", field2
111             pass
112
113         frescorba = None
114         
115         try:
116             # create local fields from corba fields
117             f1 = MEDCouplingFieldDoubleClient.New(field1)
118             f2 = MEDCouplingFieldDoubleClient.New(field2)
119
120             # add fields
121             f2.changeUnderlyingMesh(f1.getMesh(), 0, 1e-12)
122             fres = f1 + f2
123
124             # create CORBA field
125             frescorba = MEDCouplingFieldDoubleServant._this(fres)
126             
127         except Exception, e:
128             if verbose(): print e
129             pass
130         
131         if verbose(): 
132             print "End of PYCALCULATOR::Add"
133             pass
134         
135         self.endService("PYCALCULATOR::Add")
136
137         return frescorba
138
139     ## interface service: multiply two fields
140     def Mul(self, field1, field2):
141         self.beginService("PYCALCULATOR::Mul")
142
143         if verbose(): 
144             print "Begin of PYCALCULATOR::Mul"
145             print "            field 1 : ", field1
146             print "            field 2 : ", field2
147             pass
148
149         frescorba = None
150         
151         try:
152             # create local fields from corba fields
153             f1 = MEDCouplingFieldDoubleClient.New(field1)
154             f2 = MEDCouplingFieldDoubleClient.New(field2)
155
156             # multiply fields
157             f2.changeUnderlyingMesh(f1.getMesh(), 0, 1e-12)
158             fres = f1 * f2
159
160             # create CORBA field
161             frescorba = MEDCouplingFieldDoubleServant._this(fres)
162             
163         except Exception, e:
164             if verbose(): print e
165             pass
166         
167         if verbose(): 
168             print "End of PYCALCULATOR::Mul"
169             pass
170         
171         self.endService("PYCALCULATOR::Mul")
172
173         return frescorba
174
175     ## interface service: add a constant to a field
176     def AddConstant(self, field, val):
177         self.beginService("PYCALCULATOR::AddConstant")
178
179         if verbose(): 
180             print "Begin of PYCALCULATOR::AddConstant"
181             print "            field    : ", field
182             print "            constant : ", val
183             pass
184
185         frescorba = None
186         
187         try:
188             # create local field from corba field
189             f = MEDCouplingFieldDoubleClient.New(field)
190
191             # add constant to a field
192             fres = f + val
193
194             # create CORBA field
195             frescorba = MEDCouplingFieldDoubleServant._this(fres)
196             
197         except Exception, e:
198             if verbose(): print e
199             pass
200         
201         if verbose(): 
202             print "End of PYCALCULATOR::AddConstant"
203             pass
204         
205         self.endService("PYCALCULATOR::AddConstant")
206
207         return frescorba
208
209     ## interface service: multiply a field to a constant
210     def MulConstant(self, field, val):
211         self.beginService("PYCALCULATOR::MulConstant")
212
213         if verbose(): 
214             print "Begin of PYCALCULATOR::MulConstant"
215             print "            field    : ", field
216             print "            constant : ", val
217             pass
218
219         frescorba = None
220         
221         try:
222             # create local field from corba field
223             f = MEDCouplingFieldDoubleClient.New(field)
224
225             # multiply field to a constant
226             fres = f * val
227
228             # create CORBA field
229             frescorba = MEDCouplingFieldDoubleServant._this(fres)
230             
231         except Exception, e:
232             if verbose(): print e
233             pass
234         
235         if verbose(): 
236             print "End of PYCALCULATOR::MulConstant"
237             pass
238         
239         self.endService("PYCALCULATOR::MulConstant")
240
241         return frescorba
242
243     pass # end of class PYCALCULATOR