Salome HOME
Merge Python 3 porting.
[modules/kernel.git] / src / KERNEL_PY / kernel / services.py
index 5b15af882c9b4eb7e692dac99105f7e36e3bcfde..e14023b7e84afbae17d12aebe9fde18408c7ce7b 100644 (file)
@@ -1,10 +1,10 @@
 # -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # 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
 
 # Author: Guillaume Boulant (EDF/R&D)
 
+## \defgroup service service
+#  \{ 
+#  \details Helper for using %SALOME kernel services
+#  \}
+
 #
 # WARNING: development notes
 #
 # SALOME development).
 
 import salome
-from deprecation import is_called_by_sphinx
+from .deprecation import is_called_by_sphinx
 if not is_called_by_sphinx() and salome.lcc is None:
     try:
         salome.salome_init()
-    except Exception, e:
-        print e
+    except Exception as e:
+        print(e)
 
 # Note that the salome module provides you with standard SALOME
 # objects: CORBA broker (orb): salome.orb lyfe cycle (lcc) :
-# salome.lcc naming service : salome.naming_service study manager :
-# salome.myStudyManager The default study : salome.myStudy
+# salome.lcc naming service : salome.naming_service 
+# The default study : salome.myStudy
 #
 # Alternatively, you may obtain these objects directly with the
 # following instructions:
@@ -64,44 +69,49 @@ if not is_called_by_sphinx() and salome.lcc is None:
 # ==============================================================================
 #
 
+## Get a %SALOME CORBA component from its name
+#  \param componentName is the name of the component as declared in the XML
+#  %SALOME catalog. %A loadable library with name lib<componentName>Engine.so
+#  is supposed to be reachable. This library is supposed to provide a
+#  factory function with the prototype:
 #
-# componentName is the name of the component as declared in the XML
-# SALOME catalog. A loadable library with name lib<componentName>Engine.so
-# is supposed to be reachable. This library is supposed to provide a
-# factory function with the prototype:
-#
-#   PortableServer::ObjectId * <componentName>Engine_factory(
-#                                             CORBA::ORB_ptr orb,
-#                                            PortableServer::POA_ptr poa,
-#                                            PortableServer::ObjectId * contId,
-#                                            const char *instanceName,
-#                                            const char *interfaceName);
-#
-# corbaModule is the name of the IDL module that contains the
-# definition of the interface of the component. This name corresponds
-# to the namespace of the servant classes.
+#  \code
+#  PortableServer::ObjectId * <componentName>Engine_factory( CORBA::ORB_ptr orb,
+#                                                            PortableServer::POA_ptr poa,
+#                                                            PortableServer::ObjectId* contId,
+#                                                            const char *instanceName,
+#                                                            const char *interfaceName );
+#  \endcode
 #
-# containerType specified the container in which the servants are
-# executed.
+#  \param corbaModule is the name of the IDL module that contains the
+#  definition of the interface of the component. This name corresponds
+#  to the namespace of the servant classes.
 #
+#  \param containerType specified the container in which the servants are
+#  executed.
+#  \ingroup service
 def getComponent(componentName = "SalomeTestComponent",
                  corbaModule   = "Engines",
                  containerType = "FactoryServer"):
     """
     Get a SALOME CORBA component from its name
     """
-    print "INF: getting component %s from CORBA module %s ..."%(componentName,corbaModule)
+    print("INF: getting component %s from CORBA module %s ..."%(componentName,corbaModule))
     __import__(corbaModule)
     component=salome.lcc.FindOrLoadComponent(containerType,componentName)
     if component is None:
-        print "ERR: the SALOME component "+componentName+" can't be reached"
-    print "INF: component %s obtained from CORBA module %s"%(componentName,corbaModule)
+        print("ERR: the SALOME component "+componentName+" can't be reached")
+    print("INF: component %s obtained from CORBA module %s"%(componentName,corbaModule))
     return component
 
 # Note that an alternative (and maybe better) method to get a component
 # is to use the module catalog. Here, we just use the catalog to get
 # the list of components defined in the current session.
 import SALOME_ModuleCatalog
+
+## Get the list of names of all %SALOME componenents register in
+#  the catalog.
+#  \ingroup service
 def getComponentList():
     """
     Get the list of names of all SALOME componenents register in
@@ -110,24 +120,24 @@ def getComponentList():
     obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
     catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
     if not catalog:
-        raise RuntimeError, "Can't accesss module catalog"
+        raise RuntimeError("Can't accesss module catalog")
     return catalog.GetComponentList()
 
-def getStudyManager():
-    """Get a study manager to create and manage SALOME studies"""
-    return salome.myStudyManager
-
 import SALOMEDS
-def __getStudyManager_demo():
+## Get a study to create SALOME study. 
+#  \warning you should use instead the variable salome.myStudy. 
+#  This function is given for illustration of usage of the naming service
+#  \ingroup service
+def __getStudy_demo():
     """
-    Get a study manager to create and manage SALOME studies. WARN: you
-    should use instead the variable salome.myStudyManager. This
+    Get a study to create SALOME study. WARN: you
+    should use instead the variable salome.myStudy. This
     function is given for illustration of usage of the naming service
     """
     naming_service = SALOME_NamingServicePy_i( orb )
-    obj = naming_service.Resolve( '/myStudyManager' )
-    studyManager = obj._narrow( SALOMEDS.StudyManager)
-    return studyManager
+    obj = naming_service.Resolve( '/Study' )
+    study = obj._narrow( SALOMEDS.Study)
+    return study
 
 
 #
@@ -226,7 +236,7 @@ def TEST_createObject():
     """
     import GEOM
     from salome.geom import geomBuilder
-    geompy = geomBuilder.New(salome.myStudy)
+    geompy = geomBuilder.New()
 
     box = geompy.MakeBoxDXDYDZ(200, 200, 200)
     id = geompy.addToStudy( box, 'box' )
@@ -243,14 +253,14 @@ def TEST_objectsManipulation():
 
 
     myObject = IDToObject(myEntry)
-    print myObject
+    print(myObject)
     if myObject is None:
         return False
 
     return True
 
 if __name__ == "__main__":
-    import unittester
+    from . import unittester
     unittester.run("services","TEST_getComponent")
     unittester.run("services","TEST_getComponentList")
     unittester.run("services","TEST_objectsManipulation")