1 # -*- coding: latin-1 -*-
2 # Copyright (C) 2009-2015 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # HexaBlock : Module principal
25 import HEXABLOCKPlugin
30 from salome.geom import geomBuilder
31 geompy = geomBuilder.New(salome.myStudy)
35 from salome.smesh import smeshBuilder
36 smesh = smeshBuilder.New(salome.myStudy)
38 component = hexablock_swig.hex_instance ()
40 # ======================================================== moduleName
41 # ### Gives the component name
45 # ======================================================== getEngine
46 # ### Gives the component
50 # ======================================================== what
54 # ======================================================== countDocument
55 def countDocument () :
56 return component.countDocument ()
58 # ======================================================== getDocument
59 def getDocument (nro) :
60 return component.getDocument (nro)
62 # ======================================================== removeDocument
63 def removeDocument (doc) :
64 return component.removeDocument (doc)
66 # ======================================================== addDocument
67 def addDocument (nomdoc) :
68 return component.addDocument (nomdoc)
70 # ======================================================== loadDocument
71 def loadDocument (filename) :
72 return component.loadDocument (filename)
74 # ======================================================== findDocument
75 def findDocument (name) :
76 return component.findDocument (name)
78 # ======================================================== dump
79 # ### Display informations about a document
80 def dump(doc, mesh=None, full=False):
82 hn = doc.countUsedHexa()
83 print "Model dump: number of hexas: ", hn
85 hh = doc.getUsedHexa(hi)
86 print " hexa: ", hi, "name: ", hh.getName()
89 fa = ff.getAssociations()
90 print " quadrangle: ", fi, "name: ", ff.getName(), " associated: ", fa!=[]
93 ea = ee.getAssociations()
94 print " edge: ", ei, "name: ", ee.getName(), " associated: ", ea!=[]
97 va = vv.getAssociation()
98 print " vertex: ", vi, "name: ", vv.getName(), " associated: ", va!=None
99 print " model: x= ", vv.getX(), " y= ", vv.getY(), " z= ", vv.getZ()
101 x, y, z = geompy.PointCoordinates(va)
102 print " assoc: x= ", x, " y= ", y, " z= ", z
104 uv = doc.countUsedVertex()
105 ue = doc.countUsedEdge()
106 uq = doc.countUsedQuad()
107 uh = doc.countUsedHexa()
109 print "Model vertices number: ", uv
110 print "Model edges number: ", ue
111 print "Model quadrangles number: ", uq
112 print "Model blocks number: ", uh
116 print "Mesh nodes number: ", mesh.NbNodes()
117 print "Mesh segments number: ", mesh.NbEdges()
118 print "Mesh quadrangles number: ", mesh.NbQuadrangles()
119 print "Mesh hexas number: ", mesh.NbHexas()
121 return uv, ue, uq, uh
123 # ======================================================== mesh
124 # ### Mesh a document
125 def mesh (doc, name=None, dim=3, container="FactoryServer"):
126 study = salome.myStudy
128 if type(doc) == type(""):
129 doc = component.findDocument (doc)
130 docname = doc.getName()
132 #### if doc.countShape() == 0 :
133 #### shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
135 #### shape = doc.getShape (0)
137 ### shape = doc.getFirstExplicitShape_else_box(1)
138 ### the_stream = shape.getBREP() # sort une chaine de caractère
139 ### geom_object = geompy.RestoreShape(the_stream)
141 stream = doc.getFirstExplicitShape ()
143 shape = geompy.RestoreShape (stream)
145 shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
147 if (name == None) or (name == "") :
150 geompy.addToStudy(shape, name)
151 comp_smesh = salome.lcc.FindOrLoadComponent(container, "SMESH")
152 comp_smesh.init_smesh(study, geomBuilder.geom)
153 meshexa = comp_smesh.Mesh(shape)
155 so = "libHexaBlockPluginEngine.so"
157 algo = SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_3D", so)
158 meshexa.mesh.AddHypothesis(shape, algo)
160 hypo = SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_Parameters", so)
161 meshexa.mesh.AddHypothesis(shape, hypo)
163 ### hypo.SetDocument(doc.getXml()) ## Hexa6 TODO et a verifier
164 print " Maillage du document ", docname
165 hypo.SetDocument (docname);
166 hypo.SetDimension(dim)
172 # ======================================================== getFromStudy
173 def getFromStudy(entry):
174 study = salome.myStudy
175 sobject = study.FindObjectID(entry)
177 print " **** Entry ", entry, " is undefined"
180 builder = study.NewBuilder()
181 ok, attname = builder.FindAttribute(sobject, "AttributeName")
182 docname = attname.Value()
183 doc = component.findDocument(docname)
185 print " **** Entry ", entry, " doesn't correspond to an HexaBlock Document"
189 # ==================================================== findOrCreateComponent
190 # Find or create HexaBlock Study Component
191 def findOrCreateComponent( study, builder ):
192 father = study.FindComponent( moduleName() )
194 father = builder.NewComponent( moduleName() )
195 attr = builder.FindOrCreateAttribute( father, "AttributeName" )
196 attr.SetValue( "HexaBlock" )
197 attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
198 attr.SetPixMap( "ICO_MODULE_HEXABLOCK_SMALL" )
202 # ==================================================== addToStudy
203 # Add a document in the current study
206 print " *** addToStudy : Bad Document Pointer"
209 study = salome.myStudy
210 builder = study.NewBuilder()
211 father = findOrCreateComponent( study, builder )
212 name = doc.getName ()
214 present = study.FindObjectByName(name, moduleName())
216 print " *** addToStudy : Document ", name, "is already in the study"
219 object = builder.NewObject( father )
220 attr = builder.FindOrCreateAttribute( object, "AttributeName" )
221 attr.SetValue( name )
222 return object.GetID ()
224 # ==================================================== addShape
225 # Add a document in the current study
226 def addShape (doc, shape, name):
227 print "Call addShape"
228 forme = doc.addShape (shape.getShape(), name)