]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOME_SWIG_WITHOUTIHM/salome.py
Salome HOME
PR: merge from tag mergeto_trunk_20Jan05
[modules/kernel.git] / src / SALOME_SWIG_WITHOUTIHM / 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 import Engines
32 from SALOME_NamingServicePy import *
33
34 from SALOME_utilities 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             MESSAGE( a + ">" + str(CSO.GetID()) + " " + str(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             MESSAGE( a + ">" + str(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         MESSAGE( "-> ComponentDataType is " + name )
74         DumpComponent(Study, SC, 1)
75         
76
77     #--------------------------------------------------------------------------
78
79 def ImportComponentGUI(ComponentName):
80     libName = "lib" + ComponentName + "_Swig"
81     command = "from " + libName + " import *"
82     exec ( command )
83     constructor = ComponentName + "_Swig()"
84     command = "gui = " + constructor
85     exec ( command )
86     return gui
87
88     #--------------------------------------------------------------------------
89
90 def SalomeGUIgetAllSelected(self):
91     selNumber = self.SelectedCount()
92     listSelected = []
93     for i in range(selNumber):
94         listSelected.append(self.getSelected(i))
95     return listSelected
96
97 class SalomeGUI(SALOMEGUI_Swig):
98     getAllSelected = SalomeGUIgetAllSelected
99     
100     #--------------------------------------------------------------------------
101
102 def IDToObject(id):
103     myObj = None
104     mySO = myStudy.FindObjectID(id);
105     if mySO is not None:
106         ok, anAttr = mySO.FindAttribute("AttributeIOR")
107         if ok:
108             AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
109             if AtIOR.Value() != "":
110                 myObj = orb.string_to_object(AtIOR.Value())
111     return myObj
112
113 def ObjectToSObject(obj):
114     mySO = None
115     if obj is not None:
116         ior =  orb.object_to_string(obj)
117         if ior != "":
118             mySO = myStudy.FindObjectIOR(ior)
119     return mySO
120
121 def ObjectToID(obj):
122     mySO = ObjectToSObject(obj)
123     if mySO:
124         return mySO.GetID()
125     return ""
126
127 def IDToSObject(id):
128     mySO = myStudy.FindObjectID(id);
129     return mySO
130
131     #--------------------------------------------------------------------------
132
133 # initialise the ORB
134 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
135
136 # create an LifeCycleCORBA instance
137 lcc = LifeCycleCORBA(orb)
138
139 # create an SALOMEGUI_Swig instance
140 sg = SalomeGUI()
141
142 #create an naming service instance
143 naming_service = SALOME_NamingServicePy_i(orb)
144
145 # get active study name and id
146 myStudyName = sg.getActiveStudyName()
147 MESSAGE( myStudyName )
148
149 myStudyId = sg.getActiveStudyId()
150 MESSAGE( str(myStudyId) )
151
152 # get Study Manager reference
153 obj = naming_service.Resolve('myStudyManager')
154 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
155
156 # get active study
157 myStudy = myStudyManager.GetStudyByName(myStudyName)
158
159 # get Container Manager
160 obj = naming_service.Resolve('/ContainerManager')
161 cm = obj._narrow(Engines.ContainerManager)