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