10.2 Wrapping corba batch mode

The previous way to call the module is quite complicated and the usual way in Salome to hide the technical lines is to write a client file which does the corba job (see for instance geompy.py or smeshpy.py for the GEOM and SMESH modules).

Indeed, in xdata module, the client classes are the python classes themselves !!! It's the same code with some flags at some points to ensure the compatibility pure python / corba. The advantage is that the same code can be called in the two modes without any modification. For instance, the test:

# --
# Copyright (C) CEA, EDF
# Author : Erwan ADAM (CEA)
# --

from circle import Circle

c = Circle(r=1.0)

assert c.r == 1.0

bounds = c.bounds

assert bounds == [-1.0, 1.0, -1.0, 1.0]

from material import Material

m = Material()

assert m.name == "m"

from technologyobject import TechnologyObject

to = TechnologyObject(material=m,
                      shape=c,
                      )

c = to.shape

assert c.r == 1.0
assert c.bounds == [-1.0, 1.0, -1.0, 1.0]
is called in pure python mode with
# --
# Copyright (C) CEA, EDF
# Author : Erwan ADAM (CEA)
# --

import unittest

class XDataTestTestCase(unittest.TestCase):
    def test(self):
        import TECHOBJusecase
        return
    pass

if __name__ == '__main__':
    unittest.main()
    pass
and in corba mode with
# --
# Copyright (C) CEA, EDF
# Author : Erwan ADAM (CEA)
# --

import unittest

class XDataTestTestCase(unittest.TestCase):
    def test(self):
        from xsalome import XSalomeSession
        salome = XSalomeSession(modules=["TECHOBJ"], logger=1)
        #
        import TECHOBJusecase
        # --
        # Testing the hidden corba objects
        to = TECHOBJusecase.to
        self.failIfEqual(to.__corba__component__, None)
        to = to.__corba__object__
        shape = to.getShape()
        bounds = shape.getBounds()
        self.failUnlessEqual(bounds, [-1.0, 1.0, -1.0, 1.0])
##        # --
##        # Testing if xtype accept corba objects
##        # since it is needed from salome gui ...
##        from technologyobject import TechnologyObject
##        xattrs = TechnologyObject.getAllInitXAttributes()
##        shape_xattr = None
##        for x in xattrs:
##            if x.name == "shape":
##                shape_xattr = x
##                break
##            pass
##        xtype = x.xtype
##        xtype(shape)
        #
        return
    pass

if __name__ == '__main__':
    unittest.main()
    pass