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