-# Copyright (C) 2007-2015 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 SALOME_DataContainerPy import *
-
-from PYHELLO_utils import *
+from PYHELLO_utils import findOrCreateComponent, objectID, moduleName, getStudy
class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
SALOME_ComponentPy.SALOME_ComponentPy_i,
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 )
+ 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.
"""
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 ):
- self._createdNew = True # used for getModifiedData method
+ 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:
- 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 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 += [ " pass" ]
+ abuffer = [ " " + s for s in abuffer ]
+ abuffer[0:0] = [ "def RebuildData():" ]
+ abuffer += [ " pass" ]
abuffer += [ "\0" ]
- return ("\n".join( abuffer ), 1)
-
- """
- Import file to restore module data
- """
- def importData(self, studyId, dataContainer, options):
- # get study by Id
- obj = self._naming_service.Resolve("myStudyManager")
- myStudyManager = obj._narrow(SALOMEDS.StudyManager)
- study = myStudyManager.GetStudyByID(studyId)
- # create all objects from the imported stream
- stream = dataContainer.get()
- for objname in stream.split("\n"):
- if len(objname) != 0:
- self.createObject(study, objname)
- self._createdNew = False # to store the modification of the study information later
- return ["objects"] # identifier what is in this file
-
- def getModifiedData(self, studyId):
- if self._createdNew:
- # get study by Id
- obj = self._naming_service.Resolve("myStudyManager")
- myStudyManager = obj._narrow(SALOMEDS.StudyManager)
- study = myStudyManager.GetStudyByID(studyId)
- # iterate all objects to get their names and store this information in stream
- stream=""
- father = study.FindComponent( moduleName() )
- if father:
- iter = study.NewChildIterator( father )
- while iter.More():
- name = iter.Value().GetName()
- stream += name + "\n"
- iter.Next()
- # store stream to the temporary file to send it in DataContainer
- dataContainer = SALOME_DataContainerPy_i(stream, "", "objects", False, True)
- aVar = dataContainer._this()
- return [aVar]
- return []
+ res = "\n".join( abuffer )
+ return (res.encode(), 1)