Salome HOME
WIP
[modules/kernel.git] / src / KERNEL_PY / PyInterp.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 #  File   : PyInterp.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : SALOME
27 #  $Header$
28 #
29 import sys
30 from omniORB import CORBA
31 from LifeCycleCORBA import *
32 from libSALOME_Swig import *
33 import SALOMEDS
34 from SALOME_NamingServicePy import *
35
36     #--------------------------------------------------------------------------
37
38 def DumpComponent(SO, offset):
39     global myStudy
40     it = myStudy.NewChildIterator(SO)
41     Builder = myStudy.NewBuilder()
42     while it.More():
43         CSO = it.Value()
44         it.Next()
45         anAttr = Builder.FindOrCreateAttribute(CSO, "AttributeName")
46         AtName = anAttr._narrow(SALOMEDS.AttributeName)
47         t_name = AtName.Value()
48         if t_name[0] == 1:
49             ofs = 1
50             a = ""
51             while ofs <= offset:
52                 a = a + "--"
53                 ofs = ofs +1
54             print(a + ">" + CSO.GetID() + " " + t_name[1])
55         t_RefSO = CSO.ReferencedObject()
56         if t_RefSO[0] == 1:
57             RefSO = t_RefSO[1]
58             ofs = 1
59             a = ""
60             while ofs <= offset:
61                 a = a + "  "
62                 ofs = ofs +1
63             print(a + ">" + RefSO.GetID())
64         DumpComponent(CSO, offset+2)
65
66     #--------------------------------------------------------------------------
67
68 def DumpStudy():
69     global myStudy
70     itcomp = myStudy.NewComponentIterator()
71     while itcomp.More():
72         SC = itcomp.Value()
73         itcomp.Next()
74         name = SC.ComponentDataType()
75         print("-> ComponentDataType is " + name)
76         DumpComponent(SC, 1)
77         
78
79     #--------------------------------------------------------------------------
80
81 # initialise the ORB
82 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
83
84 # create an LifeCycleCORBA instance
85 lcc = LifeCycleCORBA(orb)
86
87 # create an SALOMEGUI_Swig instance
88 sg = SALOMEGUI_Swig()
89
90 #create an naming service instance
91 naming_service = SALOME_NamingServicePy_i(orb)
92
93 # get active study name
94 myStudyName = sg.getStudyName()
95 print(myStudyName)
96
97 # get Study reference
98 obj = naming_service.Resolve('/Study')
99 myStudy = obj._narrow(SALOMEDS.Study)