Salome HOME
CCAR (EDF-RD):
[modules/kernel.git] / src / SALOME_SWIG / salome.py
1 #==============================================================================
2 #  File      : salome.py
3 #  Created   : sam nov 10 00:49:00 CET 2001
4 #  Author    : Paul RASCLE, EDF
5 #  Project   : SALOME
6 #  Copyright : EDF 2001
7 #  $Header$
8 #==============================================================================
9
10 from omniORB import CORBA
11 from LifeCycleCORBA import *
12 from libSALOME_Swig import *
13 import SALOMEDS
14 from SALOME_NamingServicePy import *
15
16 from SALOME_utilities import *
17
18 #--------------------------------------------------------------------------
19
20 def DumpComponent(Study, SO, offset):
21     it = Study.NewChildIterator(SO)
22     Builder = Study.NewBuilder()
23     while it.More():
24         CSO = it.Value()
25         it.Next()
26         anAttr = Builder.FindOrCreateAttribute(CSO, "AttributeName")
27         AtName = anAttr._narrow(SALOMEDS.AttributeName)
28         t_name = AtName.Value()
29         if t_name[0] == 1:
30             ofs = 1
31             a = ""
32             while ofs <= offset:
33                 a = a + "--"
34                 ofs = ofs +1
35             MESSAGE( a + ">" + str(CSO.GetID()) + " " + str(t_name[1]) )
36         t_RefSO = CSO.ReferencedObject()
37         if t_RefSO[0] == 1:
38             RefSO = t_RefSO[1]
39             ofs = 1
40             a = ""
41             while ofs <= offset:
42                 a = a + "  "
43                 ofs = ofs +1
44             MESSAGE( a + ">" + str(RefSO.GetID()) )
45         DumpComponent(Study, CSO, offset+2)
46
47     #--------------------------------------------------------------------------
48
49 def DumpStudy(Study):
50     itcomp = Study.NewComponentIterator()
51     while itcomp.More():
52         SC = itcomp.Value()
53         itcomp.Next()
54         name = SC.ComponentDataType()
55         MESSAGE( "-> ComponentDataType is " + name )
56         DumpComponent(Study, SC, 1)
57         
58
59     #--------------------------------------------------------------------------
60
61 def ImportComponentGUI(ComponentName):
62     libName = "lib" + ComponentName + "_Swig"
63     command = "from " + libName + " import *"
64     exec ( command )
65     constructor = ComponentName + "_Swig()"
66     command = "gui = " + constructor
67     exec ( command )
68     return gui
69
70     #--------------------------------------------------------------------------
71
72 def SalomeGUIgetAllSelected(self):
73     selNumber = self.SelectedCount()
74     listSelected = []
75     for i in range(selNumber):
76         listSelected.append(self.getSelected(i))
77     return listSelected
78
79 class SalomeGUI(SALOMEGUI_Swig):
80     getAllSelected = SalomeGUIgetAllSelected
81     
82     #--------------------------------------------------------------------------
83
84 def IDToObject(id):
85     mySO = myStudy.FindObjectID(id);
86     Builder = myStudy.NewBuilder()
87     anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR")
88     AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
89     myObj = orb.string_to_object(AtIOR.Value())
90     return myObj
91
92 def IDToSObject(id):
93     mySO = myStudy.FindObjectID(id);
94     return mySO
95
96     #--------------------------------------------------------------------------
97
98 # initialise the ORB
99 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
100
101 # create an LifeCycleCORBA instance
102 lcc = LifeCycleCORBA(orb)
103
104 # create an SALOMEGUI_Swig instance
105 sg = SalomeGUI()
106
107 #create an naming service instance
108 naming_service = SALOME_NamingServicePy_i(orb)
109
110 # get active study name and id
111 myStudyName = sg.getActiveStudyName()
112 MESSAGE( myStudyName )
113
114 myStudyId = sg.getActiveStudyId()
115 MESSAGE( str(myStudyId) )
116
117 # get Study Manager reference
118 obj = naming_service.Resolve('myStudyManager')
119 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
120
121 # get active study
122 myStudy = myStudyManager.GetStudyByName(myStudyName)
123