1 # Copyright (C) 2007-2015 CEA/DEN, EDF R&D, 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
24 # File : PYHELLOGUI.py
25 # Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
28 import PYHELLO_ORB__POA
29 import SALOME_ComponentPy
30 import SALOME_DriverPy
32 from SALOME_DataContainerPy import *
34 from PYHELLO_utils import *
36 class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
37 SALOME_ComponentPy.SALOME_ComponentPy_i,
38 SALOME_DriverPy.SALOME_DriverPy_i):
40 Construct an instance of PYHELLO module engine.
41 The class PYHELLO implements CORBA interface PYHELLO_Gen (see PYHELLO_Gen.idl).
42 It is inherited from the classes SALOME_ComponentPy_i (implementation of
43 Engines::EngineComponent CORBA interface - SALOME component) and SALOME_DriverPy_i
44 (implementation of SALOMEDS::Driver CORBA interface - SALOME module's engine).
46 def __init__ ( self, orb, poa, contID, containerName, instanceName,
48 SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
49 contID, containerName, instanceName, interfaceName, 0)
50 SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
52 self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
57 Get version information.
59 def getVersion( self ):
61 return salome_version.getVersion("PYHELLO", True)
64 Generate hello banner.
66 def makeBanner( self, name ):
67 banner = "Hello %s!" % name
71 Intentionnally raises an exception for test purposes.
73 def raiseAnException( self ):
75 exData = SALOME.ExceptionStruct( SALOME.BAD_PARAM, "Test exception in raiseAnException()",'',0)
76 raise SALOME.SALOME_Exception( exData )
81 def createObject( self, study, name ):
82 self._createdNew = True # used for getModifiedData method
83 builder = study.NewBuilder()
84 father = findOrCreateComponent( study )
85 object = builder.NewObject( father )
86 attr = builder.FindOrCreateAttribute( object, "AttributeName" )
88 attr = builder.FindOrCreateAttribute( object, "AttributeLocalID" )
89 attr.SetValue( objectID() )
93 Dump module data to the Python script.
95 def DumpPython( self, study, isPublished, isMultiFile ):
98 father = study.FindComponent( moduleName() )
100 iter = study.NewChildIterator( father )
102 name = iter.Value().GetName()
103 if name: names.append( name )
108 abuffer += [ "from salome import lcc" ]
109 abuffer += [ "import PYHELLO_ORB" ]
111 abuffer += [ "pyhello = lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ]
113 abuffer += [ "pyhello.createObject( theStudy, '%s' )" % name for name in names ]
117 abuffer = [ " " + s for s in abuffer ]
118 abuffer[0:0] = [ "def RebuildData( theStudy ):" ]
119 abuffer += [ " pass" ]
121 return ("\n".join( abuffer ), 1)
124 Import file to restore module data
126 def importData(self, studyId, dataContainer, options):
128 obj = self._naming_service.Resolve("myStudyManager")
129 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
130 study = myStudyManager.GetStudyByID(studyId)
131 # create all objects from the imported stream
132 stream = dataContainer.get()
133 for objname in stream.split("\n"):
134 if len(objname) != 0:
135 self.createObject(study, objname)
136 self._createdNew = False # to store the modification of the study information later
137 return ["objects"] # identifier what is in this file
139 def getModifiedData(self, studyId):
142 obj = self._naming_service.Resolve("myStudyManager")
143 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
144 study = myStudyManager.GetStudyByID(studyId)
145 # iterate all objects to get their names and store this information in stream
147 father = study.FindComponent( moduleName() )
149 iter = study.NewChildIterator( father )
151 name = iter.Value().GetName()
152 stream += name + "\n"
154 # store stream to the temporary file to send it in DataContainer
155 dataContainer = SALOME_DataContainerPy_i(stream, "", "objects", False, True)
156 aVar = dataContainer._this()