Back to index

salome-kernel  6.5.0
Functions
KERNEL_PY.kernel.services Namespace Reference

Functions

def getComponent
def getComponentList
def getStudyManager
def __getStudyManager_demo
def IDToObject
def ObjectToSObject
def ObjectToID
def IDToSObject
def SObjectToID
def TEST_getComponent
def TEST_getComponentList
def TEST_createObject
def TEST_objectsManipulation

Function Documentation

Get a study manager to create and manage SALOME studies. WARN: you
should use instead the variable salome.myStudyManager. This
function is given for illustration of usage of the naming service

Definition at line 121 of file services.py.

00121 
00122 def __getStudyManager_demo():
00123     """
00124     Get a study manager to create and manage SALOME studies. WARN: you
00125     should use instead the variable salome.myStudyManager. This
00126     function is given for illustration of usage of the naming service
00127     """
00128     naming_service = SALOME_NamingServicePy_i( orb )
00129     obj = naming_service.Resolve( '/myStudyManager' )
00130     studyManager = obj._narrow( SALOMEDS.StudyManager)
00131     return studyManager
00132 
00133 
00134 #
00135 # ==============================================================================
00136 # Helper functions for manipulating objects, sobjects and entry
00137 # ==============================================================================
00138 #
00139 
00140 # - the SObject is an item in a study (Study Object).
00141 # - the entry is the identifier of an item.
00142 # - the ID is the entry
00143 # - the object (geom object or smesh object) is a CORBA servant
00144 #   embedded in the SALOME component container and with a reference in
00145 #   the SALOME study, so that it can be retrieved.
00146 
00147 # __GBO__ WARN: theses functions are already defined in
00148 # salome_study.py, but without the possibility to specify the
00149 # underlying study (in salome_study.py, the study is the default study
00150 # binded to the salome.myStudy attribute). TODO: see if it can be
00151 # extends to the prototype (with the study as an argument) below and
00152 # resorb the functions below.

def KERNEL_PY.kernel.services.getComponent (   componentName = "SalomeTestComponent",
  corbaModule = "Engines",
  containerType = "FactoryServer" 
)
Get a SALOME CORBA component from its name

Definition at line 89 of file services.py.

00089 
00090                  containerType = "FactoryServer"):
00091     """
00092     Get a SALOME CORBA component from its name
00093     """
00094     print "INF: getting component %s from CORBA module %s ..."%(componentName,corbaModule)
00095     __import__(corbaModule)
00096     component=salome.lcc.FindOrLoadComponent(containerType,componentName)
00097     if component is None:
00098         print "ERR: the SALOME component "+componentName+" can't be reached"
00099     print "INF: component %s obtained from CORBA module %s"%(componentName,corbaModule)
00100     return component
00101 
00102 # Note that an alternative (and maybe better) method to get a component
00103 # is to use the module catalog. Here, we just use the catalog to get
# the list of components defined in the current session.

Here is the caller graph for this function:

Get the list of names of all SALOME componenents register in
the catalog.

Definition at line 105 of file services.py.

00105 
00106 def getComponentList():
00107     """
00108     Get the list of names of all SALOME componenents register in
00109     the catalog.
00110     """
00111     obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
00112     catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
00113     if not catalog:
00114         raise RuntimeError, "Can't accesss module catalog"
00115     return catalog.GetComponentList()

Here is the caller graph for this function:

Get a study manager to create and manage SALOME studies

Definition at line 116 of file services.py.

00116 
00117 def getStudyManager():
00118     """Get a study manager to create and manage SALOME studies"""
00119     return salome.myStudyManager

Here is the caller graph for this function:

def KERNEL_PY.kernel.services.IDToObject (   id,
  study = None 
)

Definition at line 153 of file services.py.

00153 
00154 def IDToObject(id, study=None):
00155     myObj = None
00156     if study is None:
00157         myStudy = salome.myStudy
00158     else:
00159         myStudy = study
00160     mySO = myStudy.FindObjectID(id);
00161     if mySO is not None:
00162         ok, anAttr = mySO.FindAttribute("AttributeIOR")
00163         if ok:
00164             AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
00165             if AtIOR.Value() != "":
00166                 myObj = salome.orb.string_to_object(AtIOR.Value())
00167     return myObj

Here is the caller graph for this function:

def KERNEL_PY.kernel.services.IDToSObject (   id,
  study = None 
)

Definition at line 188 of file services.py.

00188 
00189 def IDToSObject(id, study=None):
00190     if study is None:
00191         myStudy = salome.myStudy
00192     else:
00193         myStudy = study
00194 
00195     mySO = myStudy.FindObjectID(id);
00196     return mySO

Here is the caller graph for this function:

def KERNEL_PY.kernel.services.ObjectToID (   obj,
  study = None 
)

Definition at line 182 of file services.py.

00182 
00183 def ObjectToID(obj, study=None):
00184     mySO = ObjectToSObject(obj,study)
00185     if mySO:
00186         return mySO.GetID()
00187     return ""

Here is the call graph for this function:

def KERNEL_PY.kernel.services.ObjectToSObject (   obj,
  study = None 
)

Definition at line 168 of file services.py.

00168 
00169 def ObjectToSObject(obj, study=None):
00170     mySO = None
00171 
00172     if study is None:
00173         myStudy = salome.myStudy
00174     else:
00175         myStudy = study
00176 
00177     if obj is not None:
00178         ior =  salome.orb.object_to_string(obj)
00179         if ior != "":
00180             mySO = myStudy.FindObjectIOR(ior)
00181     return mySO

Here is the caller graph for this function:

Definition at line 197 of file services.py.

00197 
00198 def SObjectToID(sobject):
00199     if sobject is None: return None
00200     return sobject.GetID()
00201 
00202 
00203 #
00204 # ==============================================================================
00205 # Basic use cases and unit tests
00206 # ==============================================================================
00207 #

Here is the caller graph for this function:

WARNING: for this test, we need GEOM (used to create an object 

Definition at line 223 of file services.py.

00223 
00224 def TEST_createObject():
00225     """
00226     WARNING: for this test, we need GEOM (used to create an object 
00227     """
00228     import geompy
00229     geompy.init_geom(salome.myStudy)
00230     box = geompy.MakeBoxDXDYDZ(200, 200, 200)
00231     id = geompy.addToStudy( box, 'box' )
00232     return id

Here is the caller graph for this function:

Definition at line 208 of file services.py.

00208 
00209 def TEST_getComponent():
00210     component=getComponent(componentName = "SalomeTestComponent")
00211     
00212     ref_string = 'TestComponent_i : L = 3'
00213     res_string = component.Coucou(3)
00214     if ref_string != ref_string:
00215         return False
00216     return True

Here is the call graph for this function:

Definition at line 217 of file services.py.

00217 
00218 def TEST_getComponentList():
00219     componentList=getComponentList()
00220     if 'SalomeTestComponent' not in componentList:
00221         return False
00222     return True

Here is the call graph for this function:

Definition at line 233 of file services.py.

00233 
00234 def TEST_objectsManipulation():
00235     myEntry = TEST_createObject()
00236 
00237     mySObject = IDToSObject(myEntry)
00238     entry     = SObjectToID(mySObject)
00239 
00240     if str(entry) != str(myEntry):
00241         return False
00242 
00243 
00244     myObject = IDToObject(myEntry)
00245     print myObject
00246     if myObject is None:
00247         return False
00248 
00249     return True

Here is the call graph for this function: