X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPYHELLO%2FPYHELLO.py;h=9692c26a38de26857d3eee54338075c018fd03a1;hb=bb6886d6ebef016c3c7a86cc3ef6b32f128adade;hp=aa337db5e6c3fc16d7079a0a319d1ed63bd2fcb4;hpb=9022195b7a7660d963394eec6eea8f7463023486;p=samples%2Fpyhello.git diff --git a/src/PYHELLO/PYHELLO.py b/src/PYHELLO/PYHELLO.py index aa337db..9692c26 100644 --- a/src/PYHELLO/PYHELLO.py +++ b/src/PYHELLO/PYHELLO.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either -# version 2.1 of the License. +# version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -28,8 +28,8 @@ import PYHELLO_ORB__POA import SALOME_ComponentPy import SALOME_DriverPy - -from PYHELLO_utils import * +import SALOMEDS +from PYHELLO_utils import findOrCreateComponent, objectID, moduleName, getStudy class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen, SALOME_ComponentPy.SALOME_ComponentPy_i, @@ -41,10 +41,10 @@ class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen, Engines::EngineComponent CORBA interface - SALOME component) and SALOME_DriverPy_i (implementation of SALOMEDS::Driver CORBA interface - SALOME module's engine). """ - def __init__ ( self, orb, poa, contID, containerName, instanceName, + def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ): SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa, - contID, containerName, instanceName, interfaceName, 0) + contID, containerName, instanceName, interfaceName, False) SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName) # self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb ) @@ -65,44 +65,57 @@ class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen, banner = "Hello %s!" % name return banner + """ + Intentionnally raises an exception for test purposes. + """ + def raiseAnException( self ): + import SALOME + exData = SALOME.ExceptionStruct( SALOME.BAD_PARAM, "Test exception in raiseAnException()",'',0) + raise SALOME.SALOME_Exception( exData ) + """ Create object. """ - def createObject( self, study, name ): + def createObject( self, name ): + study = getStudy() builder = study.NewBuilder() - father = findOrCreateComponent( study ) - object = builder.NewObject( father ) - attr = builder.FindOrCreateAttribute( object, "AttributeName" ) + father = findOrCreateComponent() + obj = builder.NewObject( father ) + attr = builder.FindOrCreateAttribute( obj, "AttributeName" ) attr.SetValue( name ) - attr = builder.FindOrCreateAttribute( object, "AttributeLocalID" ) + attr = builder.FindOrCreateAttribute( obj, "AttributeLocalID" ) attr.SetValue( objectID() ) pass """ Dump module data to the Python script. """ - def DumpPython( self, study, isPublished ): + def DumpPython( self, isPublished, isMultiFile ): abuffer = [] - abuffer.append( "def RebuildData( theStudy ):" ) names = [] + study = getStudy() father = study.FindComponent( moduleName() ) if father: - iter = study.NewChildIterator( father ) - while iter.More(): - name = iter.Value().GetName() + iterator = study.NewChildIterator(father) + while iterator.More(): + name = iterator.Value().GetName() if name: names.append( name ) - iter.Next() + iterator.Next() pass pass if names: - abuffer += [ " from batchmode_salome import lcc" ] - abuffer += [ " import PYHELLO_ORB" ] - abuffer += [ " " ] - abuffer += [ " pyhello = lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ] - abuffer += [ " " ] - abuffer += [ " pyhello.createObject( theStudy, '%s' )" % name for name in names ] + abuffer += [ "import salome" ] + abuffer += [ "import PYHELLO_ORB" ] + abuffer += [ "" ] + abuffer += [ "pyhello = salome.lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ] + abuffer += [ "" ] + abuffer += [ "pyhello.createObject( '%s')" % name for name in names ] + abuffer += [ "" ] pass - abuffer += [ " " ] - abuffer.append( " pass" ) - abuffer.append( "\0" ) - return ("\n".join( abuffer ), 1) + if isMultiFile: + abuffer = [ " " + s for s in abuffer ] + abuffer[0:0] = [ "def RebuildData():" ] + abuffer += [ " pass" ] + abuffer += [ "\0" ] + res = "\n".join( abuffer ) + return (res.encode(), 1)