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