Salome HOME
This commit was generated by cvs2git to create tag 'V1_3_0'.
[modules/kernel.git] / src / SALOME_SWIG / salome.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   : salome.py
23 #  Author : Paul RASCLE, EDF
24 #  Module : SALOME
25 #  $Header$
26
27 from omniORB import CORBA
28 from LifeCycleCORBA import *
29 from libSALOME_Swig import *
30 import SALOMEDS
31 from SALOME_NamingServicePy import *
32
33 from SALOME_utilities 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             MESSAGE( a + ">" + str(CSO.GetID()) + " " + str(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             MESSAGE( a + ">" + str(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         MESSAGE( "-> ComponentDataType is " + name )
73         DumpComponent(Study, SC, 1)
74         
75
76     #--------------------------------------------------------------------------
77
78 def ImportComponentGUI(ComponentName):
79     libName = "lib" + ComponentName + "_Swig"
80     command = "from " + libName + " import *"
81     exec ( command )
82     constructor = ComponentName + "_Swig()"
83     command = "gui = " + constructor
84     exec ( command )
85     return gui
86
87     #--------------------------------------------------------------------------
88
89 def SalomeGUIgetAllSelected(self):
90     selNumber = self.SelectedCount()
91     listSelected = []
92     for i in range(selNumber):
93         listSelected.append(self.getSelected(i))
94     return listSelected
95
96 class SalomeGUI(SALOMEGUI_Swig):
97     getAllSelected = SalomeGUIgetAllSelected
98     
99     #--------------------------------------------------------------------------
100
101 def IDToObject(id):
102     mySO = myStudy.FindObjectID(id);
103     Builder = myStudy.NewBuilder()
104     anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR")
105     AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
106     myObj = orb.string_to_object(AtIOR.Value())
107     return myObj
108
109 def IDToSObject(id):
110     mySO = myStudy.FindObjectID(id);
111     return mySO
112
113     #--------------------------------------------------------------------------
114
115 # initialise the ORB
116 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
117
118 # create an LifeCycleCORBA instance
119 lcc = LifeCycleCORBA(orb)
120
121 # create an SALOMEGUI_Swig instance
122 sg = SalomeGUI()
123
124 #create an naming service instance
125 naming_service = SALOME_NamingServicePy_i(orb)
126
127 # get active study name and id
128 myStudyName = sg.getActiveStudyName()
129 MESSAGE( myStudyName )
130
131 myStudyId = sg.getActiveStudyId()
132 MESSAGE( str(myStudyId) )
133
134 # get Study Manager reference
135 obj = naming_service.Resolve('myStudyManager')
136 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
137
138 # get active study
139 myStudy = myStudyManager.GetStudyByName(myStudyName)
140