]> SALOME platform Git repositories - modules/eficas.git/blob - src/EFICASGUI/SMESH_utils.py
Salome HOME
PN
[modules/eficas.git] / src / EFICASGUI / SMESH_utils.py
1 #=============================================================================
2 # File      : SMESH_utils.py
3 # Created   : jeu fév 20 18:53:34 CET 2003
4 # Author    : Paul RASCLE, EDF
5 # Project   : SALOME
6 # Copyright : EDF 2003
7 #  $Header: /home/salome/PlateFormePAL/Bases_CVS_EDF/Modules_EDF/EFICAS_SRC/src/EFICASGUI/SMESH_utils.py,v 1.5 2005/02/03 15:15:09 salome Exp $
8 #=============================================================================
9
10 from omniORB import CORBA
11 import LifeCycleCORBA
12 import SALOMEDS
13 import GEOM
14 import SMESH
15 from eficasCL import *
16
17 # initialise the ORB
18 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
19
20 # create an LifeCycleCORBA instance
21 lcc = LifeCycleCORBA.LifeCycleCORBA(orb)
22
23 geom = lcc.FindOrLoadComponent("FactoryServer", "GEOM")
24 smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
25
26     #--------------------------------------------------------------------------
27
28 def entryToIor(myStudy,entry):
29     """
30     Retourne une référence ior de l'entry passée en argument.
31     """
32     ior = None
33     iorString = entryToIorString(myStudy,entry)
34     if iorString != None:
35         ior = orb.string_to_object(iorString)
36     return ior
37
38 def entryToIorString(myStudy,entry):
39     """
40     Retourne la sérialisation de l'ior de l'entry passée en
41     argument. Il s'agit de l'attribut AttributeIOR associé à l'entry
42     dans l'arbre d'étude.
43     """
44     myBuilder = myStudy.NewBuilder()
45     iorString = None
46     SO = None
47     try:
48         SO = myStudy.FindObjectID(entry)
49     except:
50         print "invalid entry: ",entry
51         SO = None
52     if SO != None:
53         boo,iorso = myBuilder.FindAttribute(SO,"AttributeIOR")
54         if boo == 0:
55             print "no IOR attribute on study object: ", entry
56         else:
57             iorString = iorso.Value()
58     return iorString
59
60
61     #--------------------------------------------------------------------------
62
63 def singleEntryToName(myStudy,entry):
64     """
65     Retourne le nom l'entry passée en argument. Il s'agit de
66     l'attribut AttributeName associé à l'entry dans l'arbre d'étude.
67     """
68     myBuilder = myStudy.NewBuilder()
69     name =[] 
70     SO = None
71     try:
72             SO = myStudy.FindObjectID(entry)
73     except:
74             print "invalid entry: ",entry
75             SO = None
76     if SO != None:
77             boo,nameso = myBuilder.FindAttribute(SO,"AttributeName")
78             if boo == 0:
79                 print "no Name attribute on study object: ", entry
80             else:
81                 name.append(nameso.Value())
82     return name
83
84 def entryListToName(myStudy,entryList):
85     """
86     Récupération de la liste des noms à partir d'une liste d'entry.
87     """
88     myBuilder = myStudy.NewBuilder()
89     name =[]
90     SO = None
91     for entry in entryList:
92         try:
93             SO = myStudy.FindObjectID(entry)
94         except:
95             print "invalid entry: ",entry
96             SO = None
97         if SO != None:
98             boo,nameso = myBuilder.FindAttribute(SO,"AttributeName")
99             if boo == 0:
100                 print "no Name attribute on study object: ", entry
101             else:
102                 name.append(nameso.Value())
103     return name
104
105 def entryToName(myStudy,entryList):
106     """
107     Cette méthode sert juste à assurer la compatibilité avec le
108     logiciel Eficas. Eficas (panelsSalome.py) fait appel à entryToList
109     en passant une entryList en argument.
110     """
111     return entryListToName(myStudy,entryList)
112
113
114     #--------------------------------------------------------------------------
115 def getMainShape(anObject):
116     """
117     Cette méthode retourne une référence ior de l'objet principal qui
118     contient l'entry passée en argument.
119     """
120     try :
121        subShape=anObject._narrow(GEOM.GEOM_Object)
122        objMain = subShape.GetMainShape()
123        IORobjMain = orb.object_to_string(objMain)
124     except :
125        IORobjMain= None
126     return IORobjMain
127
128 def getShapeContenante(myStudy,entry):
129     try :
130        anObject=entryToIor(myStudy,entry)
131        Shape=anObject._narrow(GEOM.GEOM_Object)
132        ShapeIor=orb.object_to_string(Shape)
133     except :
134        print "pb avec l IOR: pas un objet"
135        return None
136
137     MainShapeIOR=ShapeIor
138     while anObject != None :
139        iorStringMain = getMainShape(anObject) 
140        if iorStringMain == None :
141           break
142        if ( MainShapeIOR != iorStringMain ):
143           anObject =  orb.string_to_object(iorStringMain)
144           if anObject :
145              MainShapeIOR=iorStringMain
146        else : 
147           anObject = None
148           
149     return MainShapeIOR 
150
151     #--------------------------------------------------------------------------
152
153 def getSMESHSubShapeIndexes(myStudy, entryList, typenoeudorcell = 0):
154     # typenoeudorcell = 0 on traite des noeuds
155     # typenoeudorcell = 1 on traite des faces
156
157     refList = []
158     iorStringMain = None
159     myCLinit=CLinit()
160
161     if len(entryList) > 0:
162       for idShape in entryList:
163         try:
164            anObject=entryToIor(myStudy,idShape)
165            Shape=anObject._narrow(GEOM.GEOM_Object)
166            iorStringMain=orb.object_to_string(Shape)
167         except :
168            print "pb avec l IOR: pas un objet"
169
170         if iorStringMain == None:
171           # C'est le cas ou on a loade un fichier hdf et on est pas passe par geom
172           # par exemple ....
173           return refList
174     
175         myCL=myCLinit.GetOrCreateCL(iorStringMain)
176         refShape = singleEntryToName(myStudy,idShape)
177         if refShape != None:
178            for Shape in refShape:
179                refList.append(Shape)
180         IORShape = entryToIor(myStudy,idShape)
181         myCL.SetIdAsCL(orb.object_to_string(IORShape),typenoeudorcell)
182             
183     return refList
184
185     #--------------------------------------------------------------------------
186
187 def getAsterGroupNo(myStudy,entryList):
188     typenoeudorcell = 0
189     subShapeIndexes = getSMESHSubShapeIndexes(myStudy, entryList,typenoeudorcell)
190     labelGroupNo = []
191     if subShapeIndexes == None :
192        print "*************************************"
193        print "Pb au chargement de Geom --> pas d IOR"
194        print "*************************************"
195        return
196     for val in subShapeIndexes:
197         labelGroupNo.append(val)
198     return labelGroupNo
199
200     #--------------------------------------------------------------------------
201
202 def getAsterGroupMa(myStudy,entryList):
203     typenoeudorcell = 1
204     subShapeIndexes = getSMESHSubShapeIndexes(myStudy, entryList,typenoeudorcell)
205     labelGroupMa = []
206     if subShapeIndexes == None :
207        print "*************************************"
208        print "Pb au chargement de Geom --> pas d IOR"
209        print "*************************************"
210        return
211     for val in subShapeIndexes:
212         labelGroupMa.append(val)
213     return labelGroupMa
214
215     #--------------------------------------------------------------------------
216
217 def VisuGroupe(myStudy,GroupesListe):
218     import salomedsgui
219     aGuiDS=salomedsgui.guiDS()
220     aGuiDS.ClearSelection()
221     aGuiDS.DisplayByNameInGeom(GroupesListe)
222