Salome HOME
*** empty log message ***
[modules/eficas.git] / src / EFICASGUI / eficasCL.py
1 import salome
2 import SALOMEDS
3 import SMESH
4 import GEOM
5 import SalomePyQt
6 import MonChoixMaillage
7
8 Tag_RefOnShape = 1
9 dict_CL={}
10
11 class CLinit:
12     def __init__(self):
13        geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
14        self.GroupOp  = geom.GetIGroupOperations(salome.myStudyId)
15        self.smesh=None
16        self.geomcompID=None
17        self._d = SalomePyQt.SalomePyQt().getDesktop()
18        self.correspondanceNomIOR = {}
19        self.correspondanceNomIORshape = {}
20        self.name="CL"
21        print "fin init"
22
23     def GetOrCreateCL(self,myShapeName):
24        if not (dict_CL.has_key(myShapeName)):
25           dict_CL[myShapeName] = CL()
26        return dict_CL[myShapeName]
27
28
29     def traiteCL(self):
30        self.get_geoms()
31        self.get_maillages()
32        # Récupere tous les Mesh
33        if len(dict_CL) > 0:
34           Choix=MonChoixMaillage.MonChoixMaillage(self,0,self._d)
35        salome.sg.updateObjBrowser(0)
36        
37     
38     def traiteMaillage(self,indiceIOR,NomMaillage):
39        MeshIOR = self.correspondanceNomIOR[str(NomMaillage)]
40        Mesh = salome.orb.string_to_object(MeshIOR)
41        GEOMIor = dict_CL.keys()[indiceIOR]
42        for monIOR in dict_CL[GEOMIor].CLOnNode.keys():
43            GEOMShape = salome.orb.string_to_object(monIOR)
44            aShapeSO = salome.myStudy.FindObjectIOR(monIOR)
45            attrName  = aShapeSO.FindAttribute("AttributeName")[1]
46            anAttr = attrName._narrow(SALOMEDS.AttributeName)
47            Name = anAttr.Value()
48            Mesh.CreateGroupFromGEOM(SMESH.NODE,Name,GEOMShape)
49        for monIOR in dict_CL[GEOMIor].CLOnCell.keys():
50            GEOMShape = salome.orb.string_to_object(monIOR)
51            aShapeSO = salome.myStudy.FindObjectIOR(monIOR)
52            attrName  = aShapeSO.FindAttribute("AttributeName")[1]
53            anAttr = attrName._narrow(SALOMEDS.AttributeName)
54            Name = anAttr.Value()
55            #_CS_cbo: ajout de la determination de la dimension de la geometrie
56            type = self.getShapeType(GEOMShape)
57            Mesh.CreateGroupFromGEOM(type,Name,GEOMShape)           
58        del dict_CL[GEOMIor]
59            
60
61     def traiteNewMaillage(self,numero,indiceIOR,NomMaillage):
62        GEOMIor=dict_CL.keys()[numero]
63        GEOMShapeIor=self.correspondanceNomIORshape[str(indiceIOR)]
64        shape = salome.orb.string_to_object(GEOMShapeIor)
65        if self.smesh == None :
66            self.smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
67            self.smesh.SetCurrentStudy(salome.myStudy)
68        assert (self.smesh)
69        newMesh  = self.smesh.CreateMesh(shape)
70        self.SetName(salome.ObjectToID(newMesh),NomMaillage)
71        for monIOR in dict_CL[GEOMIor].CLOnNode.keys():
72            GEOMShape = salome.orb.string_to_object(monIOR)
73            aShapeSO = salome.myStudy.FindObjectIOR(monIOR)
74            attrName  = aShapeSO.FindAttribute("AttributeName")[1]
75            anAttr = attrName._narrow(SALOMEDS.AttributeName)
76            Name = anAttr.Value()
77            newMesh.CreateGroupFromGEOM(SMESH.NODE,Name,GEOMShape)
78        for monIOR in dict_CL[GEOMIor].CLOnCell.keys():
79            GEOMShape = salome.orb.string_to_object(monIOR)
80            aShapeSO = salome.myStudy.FindObjectIOR(monIOR)
81            attrName  = aShapeSO.FindAttribute("AttributeName")[1]
82            anAttr = attrName._narrow(SALOMEDS.AttributeName)
83            Name = anAttr.Value()
84            #_CS_cbo: ajout de la determination de la dimension de la geometrie
85            type = self.getShapeType(GEOMShape)
86            newMesh.CreateGroupFromGEOM(type,Name,GEOMShape)
87        del dict_CL[GEOMIor]
88
89     def NomShape(self,numero):
90        GEOMIor = dict_CL.keys()[numero]
91        aShapeSO = salome.myStudy.FindObjectIOR(GEOMIor)
92        attrName  = aShapeSO.FindAttribute("AttributeName")[1]
93        anAttr = attrName._narrow(SALOMEDS.AttributeName)
94        Name = anAttr.Value()
95        return Name
96
97 # NodeorCell = 0 on traite des noeuds
98 # NodeorCell = 1 on traite des mailles
99
100     def Possibles(self,numero,GeomChoisie):
101        GEOMIor=self.correspondanceNomIORshape[str(GeomChoisie)]
102        liste=[]
103        if GEOMIor in self.Liste_maillages.keys():
104         for MeshIor in self.Liste_maillages[GEOMIor]:
105            aMeshSO = salome.myStudy.FindObjectIOR(MeshIor)
106            attrName  = aMeshSO.FindAttribute("AttributeName")[1]
107            anAttr = attrName._narrow(SALOMEDS.AttributeName)
108            Name = anAttr.Value()
109            self.correspondanceNomIOR[Name] = MeshIor
110            liste.append(Name)
111        return liste
112
113
114     def MainShapes(self,numero):
115        GEOMIor = dict_CL.keys()[numero]
116        listeNoms=[]
117        for MainID in  self.Liste_geoms[GEOMIor]:
118            aSO = salome.myStudy.FindObjectID(MainID)
119            if aSO==None:
120               print "pb dans MainShapes"
121               return listeNoms
122            attrName  = aSO.FindAttribute("AttributeName")[1]
123            anAttr = attrName._narrow(SALOMEDS.AttributeName)
124            Name = anAttr.Value()
125            listeNoms.append(Name)
126            IORAttr = aSO.FindAttribute("AttributeIOR")[1]
127            anAttr  = IORAttr._narrow(SALOMEDS.AttributeIOR)
128            GEOMShapeIOR  = anAttr.Value()
129            self.correspondanceNomIORshape[Name]=GEOMShapeIOR
130        return listeNoms
131
132
133     def getShapeType(self,GEOMShape):
134        """
135        Determination du type de geometrie pour les conditions aux limites.
136        
137        Le type de geometrie determine le type de mailles.
138        Voir le dictionnnaire ShapeType dans geompy.py pour les correspondances type - numero.
139        """ 
140        type = []
141        tgeo = str(GEOMShape.GetShapeType())
142        if tgeo == "VERTEX":
143            type = SMESH.NODE
144        elif tgeo == "EDGE":
145            type = SMESH.EDGE
146        elif tgeo == "FACE":
147            type = SMESH.FACE
148        elif tgeo == "SOLID":
149            type = SMESH.VOLUME
150        elif tgeo == "COMPOUND":
151            tgeo = self.GroupOp.GetType(GEOMShape)
152            if tgeo == 7:
153                type = SMESH.NODE
154            elif tgeo == 6:
155                type = SMESH.EDGE
156            elif tgeo == 4:
157                type = SMESH.FACE
158            elif tgeo == 2:
159                type = SMESH.VOLUME
160        return type
161
162     def get_maillages(self):
163        self.Liste_maillages={}
164        if self.smesh == None :
165          self.smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
166          self.smesh.SetCurrentStudy(salome.myStudy)
167        stringIOR=salome.orb.object_to_string(self.smesh)
168        print stringIOR
169        SO_smesh=salome.myStudy.FindObjectIOR(stringIOR)
170        if SO_smesh != None:
171          print salome.myStudy
172          ChildIterator = salome.myStudy.NewChildIterator(SO_smesh)
173          while ChildIterator.More() :
174             aSObj = ChildIterator.Value()
175             ChildIterator.Next()
176             anAttr =aSObj.FindAttribute("AttributeName")[1]
177             anAttr = anAttr._narrow(SALOMEDS.AttributeName)
178             Name = anAttr.Value()
179             if (Name != "Hypotheses" and Name != "Algorithms"):
180                res, Ref = aSObj.FindSubObject( Tag_RefOnShape )
181                if res == 1 :
182                   ok,MyShapeSO = Ref.ReferencedObject()
183                   if ok :
184                     IORAttr = MyShapeSO.FindAttribute("AttributeIOR")[1]
185                     anAttr  = IORAttr._narrow(SALOMEDS.AttributeIOR)
186                     GEOMShapeIOR  = anAttr.Value()
187
188                     IORAttr2 = aSObj.FindAttribute("AttributeIOR")[1]
189                     anAttr2  = IORAttr2._narrow(SALOMEDS.AttributeIOR)
190                     MeshIOR  = anAttr2.Value()
191
192                     if GEOMShapeIOR in self.Liste_maillages.keys():
193                      self.Liste_maillages[GEOMShapeIOR].append(MeshIOR)
194                     else :
195                      self.Liste_maillages[GEOMShapeIOR]=[MeshIOR]
196
197     def get_geoms(self):
198        self.Liste_geoms={}
199        for GeomCLIOR in dict_CL.keys():
200           self.Liste_geoms[GeomCLIOR]=[]
201           self.chercheMain(GeomCLIOR,GeomCLIOR)
202
203     def chercheMain(self,GEOMIor,GeomCLIOR):
204
205
206         sobj = salome.myStudy.FindObjectIOR(GEOMIor)
207         if sobj == None :
208            print "objet nul dans chercheMain"
209            return
210
211         # On cherche les dépendances et
212         # on ajoute l objet lui-même à la liste
213         Listedep=salome.myStudy.FindDependances(sobj)
214         Listedep.append(sobj)
215
216         ListeAtraiter=[]
217         for sobj in Listedep :
218            # tant que l objet est une reference
219            # on cherche son pere
220            current=sobj
221            boo,iorso = sobj.FindAttribute("AttributeIOR")
222            while ( boo==0 ) :
223               current=current.GetFather()
224               boo,iorso = current.FindAttribute("AttributeIOR")
225            iorString = iorso.Value()
226            shapeobj=salome.orb.string_to_object(iorString)
227            Shape=shapeobj._narrow(GEOM.GEOM_Object)
228            if Shape != None :
229               if self.geomcompID == None:
230                  self.geomcompID = current.GetFatherComponent().GetID()
231               ListeAtraiter.append(current)
232
233         for sobj in ListeAtraiter:
234            current=sobj
235            while ( current.GetFather().GetID() != self.geomcompID):
236               current=current.GetFather()
237            MainID=current.GetID()
238            if (MainID not in self.Liste_geoms[GeomCLIOR]):
239               self.Liste_geoms[GeomCLIOR].append(MainID)
240               Attr = current.FindAttribute("AttributeIOR")[1]
241               if (Attr != None):
242                  MainIORAttr  = Attr._narrow(SALOMEDS.AttributeIOR)
243                  MainIor = MainIORAttr.Value()
244                  self.chercheMain(MainIor,GeomCLIOR)
245
246     def SetName(self,Entry, Name):
247        SO = salome.myStudy.FindObjectID( Entry )
248        if SO != None :
249           myStudyBuilder = salome.myStudy.NewBuilder()
250           aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")
251           aName.SetValue(Name)
252
253 class CL:
254
255    def __init__(self):
256       self.CLOnCell={}
257       self.CLOnNode={}
258
259 # nodeOrCell = 0 on traite des noeuds
260 # nodeOrCell = 1 on traite des faces
261
262    def SetIdAsCL(self,CLName,nodeOrCell):
263       if (nodeOrCell == 0) :
264           print "NOEUD"
265           if self.CLOnNode.has_key(CLName):
266              self.CLOnNode[CLName] = self.CLOnNode[CLName] + 1
267           else :
268              self.CLOnNode[CLName] = 1
269       if (nodeOrCell == 1) :
270           print "MAILLE"
271           if self.CLOnCell.has_key(CLName):
272              self.CLOnCell[CLName] = self.CLOnCell[CLName] + 1
273           else :
274              self.CLOnCell[CLName] = 1
275
276    def UnSetIdAsCL(self,CLName,nodeOrCell):
277       if (nodeOrCell == 0) :
278           if self.CLOnNode.has_key(CLName):
279              self.CLOnNode[CLName] = self.CLOnNode[CLName] - 1
280       if (nodeOrCell == 1) :
281           if self.CLOnCell.has_key(CLName):
282              self.CLOnCell[CLName] = self.CLOnCell[CLName] - 1
283
284