Salome HOME
Documentation reorganization
[modules/med.git] / doc / tutorial / medcouplingcorba_en.rst
1
2 Visualize a MEDCoupling instance in ParaViS through CORBA
3 ---------------------------------------------------------
4
5 ParaViS can be used to directly visualize a mesh or a field stored in memory in a Python 
6 process. For information, this technique will become the preferred choice for the MED
7 Calculator in a future Salome release. 
8 The following use cases can also be mentioned:
9
10 * YACS, to create visualization nodes
11 * create a Python mock-up script and use the standard Python interpreter whilst benefiting
12 from the ParaViS graphical interface
13
14 Implementation start
15 ~~~~~~~~~~~~~~~~~~~~
16
17 Import the whole Python module MEDCouplingCorba. ::
18
19         from MEDCouplingCorba import *
20
21
22 Create a 2D MEDCouplingUMesh instance 
23 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24
25 Create a trivial unstructured  mesh "m" which will be sent through CORBA to ParaViS.
26 ::
27
28         arr=DataArrayDouble(11)
29         arr.iota(0)
30         m=MEDCouplingCMesh()
31         m.setCoords(arr,arr)
32         m=m.buildUnstructured() 
33
34 .. note:: "m" is unstructured but a Cartesian mesh would also work perfectly fine.
35
36 Create a CORBA servant from "m", and turn the Python process into a CORBA server
37 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38
39 Invoke MEDCouplingUMeshServant._this() on "m" to turn it into a CORBA reference ("ref_m").
40 ::
41
42         ref_m=MEDCouplingUMeshServant._this(m)
43
44 .. note:: This command doesn't only create a CORBA servant but also makes the current 
45         Python process a full CORBA server.
46
47 Read the identifiers that are passed to ParaViS
48 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49
50 What follows holds for any omniORBpy code. Display the IOR "ior" of "ref_m".
51 This character string is given to the ParaViS  plugin (ParaMEDCorbaPlugin) to create 
52 a new ParaViS source.
53 ::
54
55         import CORBA
56         orb=CORBA.ORB_init()
57         ior=orb.object_to_string(ref_m)
58         print ior
59
60 A simple copy/paste in the ParaViS GUI allows to create the source and to have our
61 mesh rendered on screen.
62
63 Use ParaViS interactively
64 ~~~~~~~~~~~~~~~~~~~~~~~~~
65
66 This section simply highlights what can be done in principle. It should be regarded
67 as a starting point towards the creation of more advanced scripts.
68 With ParaViS still up, retrieve a remote handle on ParaViS:
69 ::
70
71         import PARAVIS_Gen_idl
72         import salome
73         salome.salome_init()
74         paravis=salome.lcc.FindOrLoadComponent("FactoryServer","PARAVIS")
75
76 Then send a script to ParaViS so that it displays "m":
77 ::
78
79         script="""
80         src1 = ParaMEDCorbaPluginSource()
81         src1.IORCorba = '%s'
82         asc=GetAnimationScene()
83         rw=GetRenderView()
84         dr=Show()\ndr.Visibility = 1
85         Render()
86         """
87         content=script%(ior)
88         paravis.ExecuteScript(content)
89
90
91 Solution
92 ~~~~~~~~
93
94 :ref:`python_testMEDCouplingcorba1_solution`