Salome HOME
Base implementation of Notebook
[modules/kernel.git] / src / KERNEL_PY / PyInterp.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2008  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.
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 #  File   : PyInterp.py
24 #  Author : Paul RASCLE, EDF
25 #  Module : SALOME
26 #  $Header$
27 #
28 import sys
29 from omniORB import CORBA
30 from LifeCycleCORBA import *
31 from libSALOME_Swig import *
32 import SALOMEDS
33 from SALOME_NamingServicePy import *
34
35     #--------------------------------------------------------------------------
36
37 def DumpComponent(Study, SO, offset):
38     it = Study.NewChildIterator(SO)
39     Builder = Study.NewBuilder()
40     while it.More():
41         CSO = it.Value()
42         it.Next()
43         anAttr = Builder.FindOrCreateAttribute(CSO, "AttributeName")
44         AtName = anAttr._narrow(SALOMEDS.AttributeName)
45         t_name = AtName.Value()
46         if t_name[0] == 1:
47             ofs = 1
48             a = ""
49             while ofs <= offset:
50                 a = a + "--"
51                 ofs = ofs +1
52             print a + ">" + CSO.GetID() + " " + t_name[1]
53         t_RefSO = CSO.ReferencedObject()
54         if t_RefSO[0] == 1:
55             RefSO = t_RefSO[1]
56             ofs = 1
57             a = ""
58             while ofs <= offset:
59                 a = a + "  "
60                 ofs = ofs +1
61             print a + ">" + RefSO.GetID()
62         DumpComponent(Study, CSO, offset+2)
63
64     #--------------------------------------------------------------------------
65
66 def DumpStudy(Study):
67     itcomp = Study.NewComponentIterator()
68     while itcomp.More():
69         SC = itcomp.Value()
70         itcomp.Next()
71         name = SC.ComponentDataType()
72         print "-> ComponentDataType is " + name
73         DumpComponent(Study, SC, 1)
74         
75
76     #--------------------------------------------------------------------------
77
78 # initialise the ORB
79 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
80
81 # create an LifeCycleCORBA instance
82 lcc = LifeCycleCORBA(orb)
83
84 # create an SALOMEGUI_Swig instance
85 sg = SALOMEGUI_Swig()
86
87 #create an naming service instance
88 naming_service = SALOME_NamingServicePy_i(orb)
89
90 # get active study name and id
91 myStudyName = sg.getActiveStudyName()
92 print myStudyName
93
94 myStudyId = sg.getActiveStudyId()
95 print myStudyId
96
97 # get Study Manager reference
98 obj = naming_service.Resolve('myStudyManager')
99 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
100
101 # get active study
102 myStudy = myStudyManager.GetStudyByName(myStudyName)