Salome HOME
Make PYHELLO component appear into SALOME_Session_Server_No_Server application
[samples/pyhello.git] / src / PYHELLO / PYHELLO.py
index 72897c38ff96517cfa1473ced78ed8cb0fe19e7b..77ed258a712fdf4634e9c684955b6c7806feab7b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2021  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
 #
 import PYHELLO_ORB__POA
 import SALOME_ComponentPy
+import SALOME_Embedded_NamingService_ClientPy
 import SALOME_DriverPy
 import SALOMEDS
-from PYHELLO_utils import findOrCreateComponent, objectID, moduleName
+from PYHELLO_utils import findOrCreateComponent, objectID, moduleName, getStudy
 
 class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
               SALOME_ComponentPy.SALOME_ComponentPy_i,
@@ -47,10 +48,18 @@ class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
                     contID, containerName, instanceName, interfaceName, False)
         SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
         #
-        self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
+        emb_ns = self._contId.get_embedded_NS_if_ssl()
+        import CORBA
+        if CORBA.is_nil(emb_ns):
+            self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
+        else:
+            self._naming_service = SALOME_Embedded_NamingService_ClientPy.SALOME_Embedded_NamingService_ClientPy(emb_ns)
         #
         pass
 
+    def getNamingService(self):
+        return self._naming_service
+
     """
     Get version information.
     """
@@ -76,22 +85,24 @@ class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
     """
     Create object.
     """
-    def createObject( self, study, name ):
+    def createObject( self, name ):
+        study = getStudy( self._naming_service )
         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, isMultiFile ):
+    def DumpPython( self, isPublished, isMultiFile ):
         abuffer = []
         names = []
+        study = getStudy()
         father = study.FindComponent( moduleName() )
         if father:
             iterator = study.NewChildIterator(father)
@@ -102,17 +113,18 @@ class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
                 pass
             pass
         if names:
-            abuffer += [ "from salome import lcc" ]
+            abuffer += [ "import salome" ]
             abuffer += [ "import PYHELLO_ORB" ]
             abuffer += [ "" ]
-            abuffer += [ "pyhello = lcc.FindOrLoadComponent('FactoryServerPy', '%s')" % moduleName() ]
+            abuffer += [ "pyhello = salome.lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ]
             abuffer += [ "" ]
-            abuffer += [ "pyhello.createObject(theStudy, '%s')" % name for name in names ]
+            abuffer += [ "pyhello.createObject( '%s')" % name for name in names ]
             abuffer += [ "" ]
             pass
         if isMultiFile:
             abuffer = [ "  " + s for s in abuffer ]
-            abuffer[0:0] = [ "def RebuildData( theStudy ):" ]
+            abuffer[0:0] = [ "def RebuildData():" ]
             abuffer += [ "    pass" ]
         abuffer += [ "\0" ]
-        return ("\n".join( abuffer ), 1)
+        res = "\n".join( abuffer )
+        return (res.encode(), 1)