Salome HOME
Rolling back incorrect integration
[modules/gui.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     myObj = None
103     mySO = myStudy.FindObjectID(id);
104     if mySO is not None:
105         ok, anAttr = mySO.FindAttribute("AttributeIOR")
106         if ok:
107             AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
108             if AtIOR.Value() != "":
109                 myObj = orb.string_to_object(AtIOR.Value())
110     return myObj
111
112 def ObjectToSObject(obj):
113     mySO = None
114     if obj is not None:
115         ior =  orb.object_to_string(obj)
116         if ior != "":
117             mySO = myStudy.FindObjectIOR(ior)
118     return mySO
119
120 def ObjectToID(obj):
121     mySO = ObjectToSObject(obj)
122     if mySO:
123         return mySO.GetID()
124     return ""
125
126 def IDToSObject(id):
127     mySO = myStudy.FindObjectID(id);
128     return mySO
129
130     #--------------------------------------------------------------------------
131
132 # initialise the ORB
133 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
134
135 # create an LifeCycleCORBA instance
136 lcc = LifeCycleCORBA(orb)
137
138 # create an SALOMEGUI_Swig instance
139 sg = SalomeGUI()
140
141 #create an naming service instance
142 naming_service = SALOME_NamingServicePy_i(orb)
143
144 # get active study name and id
145 myStudyName = sg.getActiveStudyName()
146 MESSAGE( myStudyName )
147
148 myStudyId = sg.getActiveStudyId()
149 MESSAGE( str(myStudyId) )
150
151 # get Study Manager reference
152 obj = naming_service.Resolve('myStudyManager')
153 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
154
155 # get active study
156 myStudy = myStudyManager.GetStudyByName(myStudyName)
157