Salome HOME
Intégration eficas_novice
[modules/eficas.git] / src / EELIH / c_geometrie.py
1 # -*- coding: iso-8859-1 -*-
2
3 # module salome
4 import salome
5 # module eficas
6 import SMESH_utils
7 # module GEOM
8 import GEOM
9 # module de bases
10 import string
11 # module pour le maillage
12 import maillage
13
14 class C_geometrie:
15     """
16     controleur de la classe Geometrie, permet la sélection de la géométrie dans l'arbre d'étude
17     de Salome. Met à jour les champs correspondants (sous-géométries, ...)
18     """
19     def __init__(self, appli, geometrie):
20         self.appli = appli
21         self.geometrie = geometrie
22         self.dicoSousGeom = []
23         
24     def getGeometrie(self):
25         """
26         affecte le nom de la géométrie sélectionnée dans l'arbre d'étude de Salome
27         à l'instance étude de l'application et au lineedit correspondant
28         """
29         # récupération de tous les objets sélectionnés dans l'arbre d'étude
30         listeSelection = salome.sg.getAllSelected()
31         if len(listeSelection) > 1:
32             print "----------------------------------------"
33             print "1 seule géométrie doit être sélectionnée"
34         elif len(listeSelection)  == 0:
35             print "----------------------------------------"
36             print "Sélectionnez une géométrie"
37         else:
38             # on teste si l'objet sélectionné est une géométrie et s'il possède des fils
39             import EFICASGUI
40             import salomedsgui
41             anObject=SMESH_utils.entryToIor(salome.myStudy,listeSelection[0])
42             if not anObject: # l'objet n'a pas encore chargé
43                strContainer, strComponentName = "FactoryServer", "GEOM"
44                myComponent = salome.lcc.FindOrLoadComponent( strContainer, strComponentName )
45                SCom=salome.myStudy.FindComponent( strComponentName )
46                myBuilder = salome.myStudy.NewBuilder()
47                myBuilder.LoadWith( SCom , myComponent  )
48                anObject=SMESH_utils.entryToIor(salome.myStudy,listeSelection[0])
49             type = None
50             try:
51                type = anObject._narrow(GEOM.GEOM_Object)
52             except:
53                pass
54                
55             # le type doit être une géométrie
56             if type == None:
57                print "----------------------------------------"
58                print "Sélectionnez une géométrie"
59             # type = géométrie
60             else:
61               # on vérifie que cette géométrie possède au moins un fils qui soit une géoméotrie 
62               geom = salome.lcc.FindOrLoadComponent( "FactoryServer", "GEOM" )
63               group = geom.GetIMeasureOperations(EFICASGUI.currentStudyId)
64               nom = SMESH_utils.entryToName(salome.myStudy, listeSelection)
65               
66               # modelisation 3D --> il faut un SOLID
67               if self.appli.etude.modelisation == '3D':
68                  n = string.find(group.WhatIs(type), 'SOLID')
69                  if group.WhatIs(type)[n+8] != 0:
70                     liste = []
71                     liste = [nom[0], listeSelection[0]]
72                     self.geometrie.ln.setText(nom[0])
73                     self.appli.etude.setGeometrie(liste)
74                     # groupes de mailles = face ou shell
75                     self.dicoSousGeom = SMESH_utils.getSubGeometryIorAndName(salome.myStudy, self.appli.etude.geometrie)
76                     listeSousGeom = []
77                     for maille in self.dicoSousGeom.keys():
78                        anObject = SMESH_utils.iorStringToIor(maille)
79                        type = anObject._narrow(GEOM.GEOM_Object)
80                        n = string.find(group.WhatIs(type), 'FACE')
81                        if group.WhatIs(type)[n+7] != 0:
82                           listeSousGeom.append(self.dicoSousGeom[maille])
83                        else:
84                           n = string.find(group.WhatIs(type), 'SHELL')
85                           if group.WhatIs(type)[n+8] != 0:
86                              listeSousGeom.append(self.dicoSousGeom[maille])
87                     
88                     listeSousGeom.sort()
89                     self.appli.etude.setSousGeometrie(listeSousGeom)
90                     
91                  else:
92                     print "----------------------------------------"
93                     print "Pour une modélisation 3D, la géométrie sélectionnée doit être un solide."
94               
95               # modelisation 2D --> SHELL ou FACE
96               if string.find(self.appli.etude.modelisation, '2D') != -1:
97                  liste = []
98                  liste = [nom[0], listeSelection[0]]
99                  self.geometrie.ln.setText(nom[0])
100                  self.appli.etude.setGeometrie(liste)
101                  self.dicoSousGeom = SMESH_utils.getSubGeometryIorAndName(salome.myStudy, self.appli.etude.geometrie)
102                  listeSousGeom = []
103                  n = string.find(group.WhatIs(type), 'SHELL')
104                  if group.WhatIs(type)[n+8] != 0:
105                     # groupes de mailles = edge
106                     for maille in self.dicoSousGeom.keys():
107                        anObject = SMESH_utils.iorStringToIor(maille)
108                        type = anObject._narrow(GEOM.GEOM_Object)
109                        n = string.find(group.WhatIs(type), 'EDGE')
110                        if group.WhatIs(type)[n+7] != 0:
111                           listeSousGeom.append(self.dicoSousGeom[maille])
112                  else:
113                     n = string.find(group.WhatIs(type), 'FACE')
114                     if group.WhatIs(type)[n+7] != 0:
115                        # groupes de mailles = edge
116                        for maille in self.dicoSousGeom.keys():
117                           anObject = SMESH_utils.iorStringToIor(maille)
118                           type = anObject._narrow(GEOM.GEOM_Object)
119                           n = string.find(group.WhatIs(type), 'EDGE')
120                           if group.WhatIs(type)[n+7] != 0:
121                              listeSousGeom.append(self.dicoSousGeom[maille])
122                   
123                  listeSousGeom.sort()   
124                  self.appli.etude.setSousGeometrie(listeSousGeom)
125
126     def getSousGeometrie(self):
127         """
128         retourne les sous-géométries de la géométrie sélectionnée dans l'arbre d'étude de Salome
129         """
130         liste = SMESH_utils.getSubGeometry(salome.myStudy, self.geometrie.appli.etude.geometrie)
131         liste.sort()
132         return liste
133     
134     def updateComboSousGeom(self):
135         """
136         affecte les combobox des tables des panneaux ddl et pression avec les valeurs
137         des sous-géométries
138         """
139         # insertion pour le panneau ddl
140         for cmb in self.geometrie.appli.mw.ddl.controleurNouvelleLigneTable.controleurTable.listeComboGeom:
141             cmb.insertStrList(self.geometrie.appli.etude.sousGeometrie)
142         
143         # insertion pour le panneau pression
144         for cmb in self.geometrie.appli.mw.pression.controleurNouvelleLigneTable.controleurTable.listeComboGeom:
145             cmb.insertStrList(self.geometrie.appli.etude.sousGeometrie)