Salome HOME
b697518aa6ebeb2b5cba78ae65a44ecd09135547
[samples/component.git] / src / FactorialComponent / FactorialComponent.py
1 #! /usr/bin/env python
2 #
3 #  SuperVisionTest FactorialComponent : example of component that calculates factorial
4 #
5 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
7
8 #  This library is free software; you can redistribute it and/or 
9 #  modify it under the terms of the GNU Lesser General Public 
10 #  License as published by the Free Software Foundation; either 
11 #  version 2.1 of the License. 
12
13 #  This library is distributed in the hope that it will be useful, 
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
16 #  Lesser General Public License for more details. 
17
18 #  You should have received a copy of the GNU Lesser General Public 
19 #  License along with this library; if not, write to the Free Software 
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
21
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24 #
25 #
26 #  File   : FactorialComponent.py
27 #  Author : 
28 #  Module : SuperVisionTest
29 #  $Header$
30
31 import sys
32 from omniORB import CORBA, PortableServer
33 import CosNaming
34 import Engines, Engines__POA
35 import SuperVisionTest, SuperVisionTest__POA
36 from SALOME_ComponentPy import *
37
38 from FactorialComponent_idl import *
39
40 class FactorialComponent( SuperVisionTest__POA.FactorialComponent, SALOME_ComponentPy_i):
41
42     def eval(self, val):
43         self.beginService( 'FactorialComponent eval' )
44         print "eval :",val
45         if (val < 0):
46             raise ArgumentError("factorial must be positive, not " + `val`)
47         if (val < 2):
48             print "eval return",val
49             self.sendMessage( NOTIF_STEP , "Done" )
50             self.endService( 'FactorialComponent eval' )
51             return val
52         else:
53             val1 = self.eval(val-1)
54             self.sendMessage( NOTIF_TRACE , "One More Time" )
55             print "eval return",val," * ",val1
56             return val * val1
57     
58     def sigma(self, val):
59         self.beginService( 'FactorialComponent sigma' )
60         print "sigma :",val
61         if (val < 0):
62             raise ArgumentError("sigma must be positive, not " + `val`)
63         i = 0
64         while i < 10000 :
65             n = 1
66             s = 0
67             while n <= val :
68                 s = s + n
69                 n = n + 1
70             i = i + 1
71         print "sigma returns",s
72         self.endService( 'FactorialComponent sigma' )
73         return s
74     
75     def __init__(self, orb, poa, this, containerName, instanceName, interfaceName):
76         SALOME_ComponentPy_i.__init__(self, orb, poa, this, containerName,
77                                       instanceName, interfaceName, 0)
78         print "FactorialComponent::__init__"
79