Salome HOME
Mise à jour du template PythonComponent:
[tools/sat.git] / data / templates / PythonComponent / src / PYCMP / PYCMP.py
1 #  Copyright (C) 2007-2010  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.
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   : :sat:{PYCMP}.py
25 # Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 # ---
27 #
28 import :sat:{PYCMP}_ORB__POA
29 import SALOME_ComponentPy
30 import SALOME_DriverPy
31
32 from :sat:{PYCMP}_utils import *
33
34 class :sat:{PYCMP}(:sat:{PYCMP}_ORB__POA.:sat:{PYCMP}_Gen,
35               SALOME_ComponentPy.SALOME_ComponentPy_i,
36               SALOME_DriverPy.SALOME_DriverPy_i):
37     """
38     Construct an instance of :sat:{PYCMP} module engine.
39     The class :sat:{PYCMP} implements CORBA interface :sat:{PYCMP}_Gen (see :sat:{PYCMP}_Gen.idl).
40     It is inherited from the classes SALOME_ComponentPy_i (implementation of
41     Engines::EngineComponent CORBA interface - SALOME component) and SALOME_DriverPy_i
42     (implementation of SALOMEDS::Driver CORBA interface - SALOME module's engine).
43     """
44     def __init__ ( self, orb, poa, contID, containerName, instanceName,
45                    interfaceName ):
46         SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
47                     contID, containerName, instanceName, interfaceName, 0)
48         SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
49         #
50         self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
51         #
52         pass
53
54     """
55     Touch the component
56     """
57     def touch(self, name):
58         message = "Touch: %s!" % name
59         return message
60
61     """
62     Create object.
63     """
64     def createObject( self, study, name ):
65         builder = study.NewBuilder()
66         father  = findOrCreateComponent( study )
67         object  = builder.NewObject( father )
68         attr    = builder.FindOrCreateAttribute( object, "AttributeName" )
69         attr.SetValue( name )
70         attr    = builder.FindOrCreateAttribute( object, "AttributeLocalID" )
71         attr.SetValue( objectID() )
72         pass
73
74     """
75     Dump module data to the Python script.
76     """
77     def DumpPython( self, study, isPublished ):
78         abuffer = []
79         abuffer.append( "def RebuildData( theStudy ):" )
80         names = []
81         father = study.FindComponent( moduleName() )
82         if father:
83             iter = study.NewChildIterator( father )
84             while iter.More():
85                 name = iter.Value().GetName()
86                 if name: names.append( name )
87                 iter.Next()
88                 pass
89             pass
90         if names:
91             abuffer += [ "  from batchmode_salome import lcc" ]
92             abuffer += [ "  import :sat:{PYCMP}_ORB" ]
93             abuffer += [ "  " ]
94             abuffer += [ "  myCompo = lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ]
95             abuffer += [ "  " ]
96             abuffer += [ "  myCompo.createObject( theStudy, '%s' )" % name for name in names ]
97             pass
98         abuffer += [ "  " ]
99         abuffer.append( "  pass" )
100         abuffer.append( "\0" )
101         return ("\n".join( abuffer ), 1)