1 # -*- coding: latin-1 -*-
2 # HexaBlock : Module principal
11 from salome.geom import geomBuilder
12 geompy = geomBuilder.New(salome.myStudy)
16 from salome.smesh import smeshBuilder
17 smesh = smeshBuilder.New(salome.myStudy)
19 component = hexablock_swig.hex_instance ()
21 # ======================================================== moduleName
22 # ### Gives the component name
26 # ======================================================== getEngine
27 # ### Gives the component
31 # ======================================================== what
35 # ======================================================== countDocument
36 def countDocument () :
37 return component.countDocument ()
39 # ======================================================== getDocument
40 def getDocument (nro) :
41 return component.getDocument (nro)
43 # ======================================================== removeDocument
44 def removeDocument (doc) :
45 return component.removeDocument (doc)
47 # ======================================================== addDocument
48 def addDocument (nomdoc) :
49 return component.addDocument (nomdoc)
51 # ======================================================== loadDocument
52 def loadDocument (filename) :
53 return component.loadDocument (filename)
55 # ======================================================== findDocument
56 def findDocument (name) :
57 return component.findDocument (name)
59 # ======================================================== dump
60 # ### Display informations about a document
61 def dump(doc, mesh=None, full=False):
63 hn = doc.countUsedHexa()
64 print "Model dump: number of hexas: ", hn
66 hh = doc.getUsedHexa(hi)
67 print " hexa: ", hi, "name: ", hh.getName()
70 fa = ff.getAssociations()
71 print " quadrangle: ", fi, "name: ", ff.getName(), " associated: ", fa!=[]
74 ea = ee.getAssociations()
75 print " edge: ", ei, "name: ", ee.getName(), " associated: ", ea!=[]
78 va = vv.getAssociation()
79 print " vertex: ", vi, "name: ", vv.getName(), " associated: ", va!=None
80 print " model: x= ", vv.getX(), " y= ", vv.getY(), " z= ", vv.getZ()
82 x, y, z = geompy.PointCoordinates(va)
83 print " assoc: x= ", x, " y= ", y, " z= ", z
85 uv = doc.countUsedVertex()
86 ue = doc.countUsedEdge()
87 uq = doc.countUsedQuad()
88 uh = doc.countUsedHexa()
90 print "Model vertices number: ", uv
91 print "Model edges number: ", ue
92 print "Model quadrangles number: ", uq
93 print "Model blocks number: ", uh
97 print "Mesh nodes number: ", mesh.NbNodes()
98 print "Mesh segments number: ", mesh.NbEdges()
99 print "Mesh quadrangles number: ", mesh.NbQuadrangles()
100 print "Mesh hexas number: ", mesh.NbHexas()
102 return uv, ue, uq, uh
104 # ======================================================== mesh
105 # ### Mesh a document
106 def mesh (doc, name=None, dim=3, container="FactoryServer"):
107 study = salome.myStudy
109 if type(doc) == type(""):
110 doc = component.findDocument (doc)
111 docname = doc.getName()
113 #### if doc.countShape() == 0 :
114 #### shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
116 #### shape = doc.getShape (0)
118 ### shape = doc.getFirstExplicitShape_else_box(1)
119 ### the_stream = shape.getBREP() # sort une chaine de caractère
120 ### geom_object = geompy.RestoreShape(the_stream)
122 stream = doc.getFirstExplicitShape ()
124 shape = geompy.RestoreShape (stream)
126 shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
128 if (name == None) or (name == "") :
131 geompy.addToStudy(shape, name)
132 comp_smesh = salome.lcc.FindOrLoadComponent(container, "SMESH")
133 comp_smesh.init_smesh(study, geomBuilder.geom)
134 meshexa = comp_smesh.Mesh(shape)
136 so = "libHexaBlockPluginEngine.so"
138 algo = SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_3D", so)
139 meshexa.mesh.AddHypothesis(shape, algo)
141 hypo = SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_Parameters", so)
142 meshexa.mesh.AddHypothesis(shape, hypo)
144 ### hypo.SetDocument(doc.getXml()) ## Hexa6 TODO et a verifier
145 print " Maillage du document ", docname
146 hypo.SetDocument (docname);
147 hypo.SetDimension(dim)
153 # ======================================================== getFromStudy
154 def getFromStudy(entry):
155 study = salome.myStudy
156 sobject = study.FindObjectID(entry)
158 print " **** Entry ", entry, " is undefined"
161 builder = study.NewBuilder()
162 ok, attname = builder.FindAttribute(sobject, "AttributeName")
163 docname = attname.Value()
164 doc = component.findDocument(docname)
166 print " **** Entry ", entry, " doesn't correspond to an HexaBlock Document"
170 # ==================================================== findOrCreateComponent
171 # Find or create HexaBlock Study Component
172 def findOrCreateComponent( study, builder ):
173 father = study.FindComponent( moduleName() )
175 father = builder.NewComponent( moduleName() )
176 attr = builder.FindOrCreateAttribute( father, "AttributeName" )
177 attr.SetValue( "HexaBlock" )
178 attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
179 attr.SetPixMap( "ICO_MODULE_HEXABLOCK_SMALL" )
183 # ==================================================== addToStudy
184 # Add a document in the current study
187 print " *** addToStudy : Bad Document Pointer"
190 study = salome.myStudy
191 builder = study.NewBuilder()
192 father = findOrCreateComponent( study, builder )
193 name = doc.getName ()
195 present = study.FindObjectByName(name, moduleName())
197 print " *** addToStudy : Document ", name, "is already in the study"
200 object = builder.NewObject( father )
201 attr = builder.FindOrCreateAttribute( object, "AttributeName" )
202 attr.SetValue( name )
203 return object.GetID ()
205 # ==================================================== addShape
206 # Add a document in the current study
207 def addShape (doc, shape, name):
208 print "Call addShape"
209 forme = doc.addShape (shape.getShape(), name)