1 # -*- coding: latin-1 -*-
2 # HexaBlock : Module principal
11 component = hexablock_swig.hex_instance ()
13 # ======================================================== moduleName
14 # ### Gives the component name
18 # ======================================================== getEngine
19 # ### Gives the component
23 # ======================================================== what
27 # ======================================================== countDocument
28 def countDocument () :
29 return component.countDocument ()
31 # ======================================================== getDocument
32 def getDocument (nro) :
33 return component.getDocument (nro)
35 # ======================================================== removeDocument
36 def removeDocument (doc) :
37 return component.removeDocument (doc)
39 # ======================================================== addDocument
40 def addDocument (nomdoc) :
41 return component.addDocument (nomdoc)
43 # ======================================================== loadDocument
44 def loadDocument (filename) :
45 return component.loadDocument (filename)
47 # ======================================================== findDocument
48 def findDocument (name) :
49 return component.findDocument (name)
51 # ======================================================== dump
52 # ### Display informations about a document
53 def dump(doc, mesh=None, full=False):
55 hn = doc.countUsedHexa()
56 print "Model dump: number of hexas: ", hn
58 hh = doc.getUsedHexa(hi)
59 print " hexa: ", hi, "name: ", hh.getName()
62 fa = ff.getAssociations()
63 print " quadrangle: ", fi, "name: ", ff.getName(), " associated: ", fa!=[]
66 ea = ee.getAssociations()
67 print " edge: ", ei, "name: ", ee.getName(), " associated: ", ea!=[]
70 va = vv.getAssociation()
71 print " vertex: ", vi, "name: ", vv.getName(), " associated: ", va!=None
72 print " model: x= ", vv.getX(), " y= ", vv.getY(), " z= ", vv.getZ()
74 x, y, z = geompy.PointCoordinates(va)
75 print " assoc: x= ", x, " y= ", y, " z= ", z
77 uv = doc.countUsedVertex()
78 ue = doc.countUsedEdge()
79 uq = doc.countUsedQuad()
80 uh = doc.countUsedHexa()
82 print "Model vertices number: ", uv
83 print "Model edges number: ", ue
84 print "Model quadrangles number: ", uq
85 print "Model blocks number: ", uh
89 print "Mesh nodes number: ", mesh.NbNodes()
90 print "Mesh segments number: ", mesh.NbEdges()
91 print "Mesh quadrangles number: ", mesh.NbQuadrangles()
92 print "Mesh hexas number: ", mesh.NbHexas()
96 # ======================================================== mesh
98 def mesh (doc, name=None, dim=3, container="FactoryServer"):
99 study = salome.myStudy
101 if type(doc) == type(""):
102 doc = component.findDocument (doc)
103 docname = doc.getName()
105 #### if doc.countShape() == 0 :
106 #### shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
108 #### shape = doc.getShape (0)
110 shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
111 if (name == None) or (name == ""):
114 geompy.addToStudy(shape, name)
115 comp_smesh = salome.lcc.FindOrLoadComponent(container, "SMESH")
116 comp_smesh.init_smesh(study, geompy.geom)
117 meshexa = comp_smesh.Mesh(shape)
119 so = "libHexaBlockEngine.so"
121 algo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_3D", so)
122 meshexa.mesh.AddHypothesis(shape, algo)
124 hypo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_Parameters", so)
125 meshexa.mesh.AddHypothesis(shape, hypo)
127 ### hypo.SetDocument(doc.getXml()) ## Hexa6 TODO et a verifier
128 print " Maillage du document "
129 print " Maillage du document ", docname
130 hypo.SetDocument (docname);
131 hypo.SetDimension(dim)
137 # ======================================================== getFromStudy
138 def getFromStudy(entry):
139 study = salome.myStudy
140 sobject = study.FindObjectID(entry)
142 print " **** Entry ", entry, " is undefined"
145 builder = study.NewBuilder()
146 ok, attname = builder.FindAttribute(sobject, "AttributeName")
147 docname = attname.Value()
148 doc = component.findDocument(docname)
150 print " **** Entry ", entry, " doesn't correspond to an HexaBlock Document"
154 # ==================================================== findOrCreateComponent
155 # Find or create HexaBlock Study Component
156 def findOrCreateComponent( study, builder ):
157 father = study.FindComponent( moduleName() )
159 father = builder.NewComponent( moduleName() )
160 attr = builder.FindOrCreateAttribute( father, "AttributeName" )
161 attr.SetValue( "HexaBlock" )
162 attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
163 attr.SetPixMap( "ICO_MODULE_HEXABLOCK_SMALL" )
167 # ==================================================== addToStudy
168 # Add a document in the current study
171 print " *** addToStudy : Bad Document Pointer"
174 study = salome.myStudy
175 builder = study.NewBuilder()
176 father = findOrCreateComponent( study, builder )
177 name = doc.getName ()
179 present = study.FindObjectByName(name, moduleName())
181 print " *** addToStudy : Document ", name, "is already in the study"
184 object = builder.NewObject( father )
185 attr = builder.FindOrCreateAttribute( object, "AttributeName" )
186 attr.SetValue( name )
187 return object.GetID ()
189 # ==================================================== addShape
190 # Add a document in the current study
191 def addShape (doc, shape, name):
192 print "Call addShape"
193 forme = doc.addShape (shape.getShape(), name)