6 import MonChoixMaillage
14 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
15 self.GroupOp = geom.GetIGroupOperations(salome.myStudyId)
18 self._d = SalomePyQt.SalomePyQt().getDesktop()
19 self.correspondanceNomIOR = {}
20 self.correspondanceNomIORshape = {}
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]
35 #print "Debut de TraiteCL"
38 # Récupere tous les Mesh
40 Choix=MonChoixMaillage.MonChoixMaillage(self,0,self._d)
41 salome.sg.updateObjBrowser(0)
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)
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)
61 #_CS_cbo: ajout de la determination de la dimension de la geometrie
62 type = self.getShapeType(GEOMShape)
63 Mesh.CreateGroupFromGEOM(type,Name,GEOMShape)
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)
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)
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)
90 #_CS_cbo: ajout de la determination de la dimension de la geometrie
91 type = self.getShapeType(GEOMShape)
92 newMesh.CreateGroupFromGEOM(type,Name,GEOMShape)
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()
103 # NodeorCell = 0 on traite des noeuds
104 # NodeorCell = 1 on traite des mailles
106 def Possibles(self,numero,GeomChoisie):
107 GEOMIor=self.correspondanceNomIORshape[str(GeomChoisie)]
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
120 def MainShapes(self,numero):
121 GEOMIor = dict_CL.keys()[numero]
123 for MainID in self.Liste_geoms[GEOMIor]:
124 aSO = salome.myStudy.FindObjectID(MainID)
126 print "pb dans MainShapes"
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
139 def getShapeType(self,GEOMShape):
141 Determination du type de geometrie pour les conditions aux limites.
143 Le type de geometrie determine le type de mailles.
144 Voir le dictionnnaire ShapeType dans geompy.py pour les correspondances type - numero.
147 tgeo = str(GEOMShape.GetShapeType())
154 elif tgeo == "SOLID":
156 elif tgeo == "COMPOUND":
157 tgeo = self.GroupOp.GetType(GEOMShape)
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)
176 ChildIterator = salome.myStudy.NewChildIterator(SO_smesh)
177 while ChildIterator.More() :
178 aSObj = ChildIterator.Value()
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 )
186 ok,MyShapeSO = Ref.ReferencedObject()
188 IORAttr = MyShapeSO.FindAttribute("AttributeIOR")[1]
189 anAttr = IORAttr._narrow(SALOMEDS.AttributeIOR)
190 GEOMShapeIOR = anAttr.Value()
192 IORAttr2 = aSObj.FindAttribute("AttributeIOR")[1]
193 anAttr2 = IORAttr2._narrow(SALOMEDS.AttributeIOR)
194 MeshIOR = anAttr2.Value()
196 if GEOMShapeIOR in self.Liste_maillages.keys():
197 self.Liste_maillages[GEOMShapeIOR].append(MeshIOR)
199 self.Liste_maillages[GEOMShapeIOR]=[MeshIOR]
203 for GeomCLIOR in dict_CL.keys():
204 self.Liste_geoms[GeomCLIOR]=[]
205 self.chercheMain(GeomCLIOR,GeomCLIOR)
207 def chercheMain(self,GEOMIor,GeomCLIOR):
208 sobj = salome.myStudy.FindObjectIOR(GEOMIor)
209 #print "_______________________________________________________"
210 #print "Cherchemain", sobj.GetID()
211 #print "_______________________________________________________"
213 print "objet nul dans chercheMain"
216 # Recherche du composant GEOM
217 if self.geomcompID == None:
218 self.geomcompID = sobj.GetFatherComponent().GetID()
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
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)
233 for sobj in self.dict_listedep[MonEntry] :
235 # tant que l objet est une reference
236 # on cherche son pere
238 boo,iorso = sobj.FindAttribute("AttributeIOR")
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)
246 ListeAtraiter.append(current)
248 for sobj in ListeAtraiter:
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]
258 MainIORAttr = Attr._narrow(SALOMEDS.AttributeIOR)
259 MainIor = MainIORAttr.Value()
260 self.chercheMain(MainIor,GeomCLIOR)
262 def ChercheRef(self,entry,geomSobj):
263 #print "ChercheRef", entry,geomSobj.GetID()
264 aIter=salome.myStudy.NewChildIterator(geomSobj)
266 aIterSObj = aIter.Value()
267 aIterID=aIterSObj.GetID()
270 bool,obj=aIterSObj.ReferencedObject()
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)
283 def SetName(self,Entry, Name):
284 SO = salome.myStudy.FindObjectID( Entry )
286 myStudyBuilder = salome.myStudy.NewBuilder()
287 aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")
296 # nodeOrCell = 0 on traite des noeuds
297 # nodeOrCell = 1 on traite des faces
299 def SetIdAsCL(self,CLName,nodeOrCell):
300 if (nodeOrCell == 0) :
302 if self.CLOnNode.has_key(CLName):
303 self.CLOnNode[CLName] = self.CLOnNode[CLName] + 1
305 self.CLOnNode[CLName] = 1
306 if (nodeOrCell == 1) :
308 if self.CLOnCell.has_key(CLName):
309 self.CLOnCell[CLName] = self.CLOnCell[CLName] + 1
311 self.CLOnCell[CLName] = 1
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