# -*- coding: latin-1 -*-
+# Copyright (C) 2009-2020 CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
# HexaBlock : Module principal
import hexablock_swig
-import salome
-import smesh
import HEXABLOCKPlugin
-geompy = smesh.geompy
+import salome
+salome.salome_init()
+
+from salome.geom import geomBuilder
+geompy = geomBuilder.New()
+
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New()
+
component = hexablock_swig.hex_instance ()
# ======================================================== moduleName
def dump(doc, mesh=None, full=False):
if full:
hn = doc.countUsedHexa()
- print "Model dump: number of hexas: ", hn
- for hi in xrange(hn):
+ print("Model dump: number of hexas: ", hn)
+ for hi in range(hn):
hh = doc.getUsedHexa(hi)
- print " hexa: ", hi, "name: ", hh.getName()
- for fi in xrange(6):
+ print(" hexa: ", hi, "name: ", hh.getName())
+ for fi in range(6):
ff = hh.getQuad(fi)
fa = ff.getAssociations()
- print " quadrangle: ", fi, "name: ", ff.getName(), " associated: ", fa!=[]
- for ei in xrange(4):
+ print(" quadrangle: ", fi, "name: ", ff.getName(), " associated: ", fa!=[])
+ for ei in range(4):
ee = ff.getEdge(ei)
ea = ee.getAssociations()
- print " edge: ", ei, "name: ", ee.getName(), " associated: ", ea!=[]
- for vi in xrange(2):
+ print(" edge: ", ei, "name: ", ee.getName(), " associated: ", ea!=[])
+ for vi in range(2):
vv = ee.getVertex(vi)
va = vv.getAssociation()
- print " vertex: ", vi, "name: ", vv.getName(), " associated: ", va!=None
- print " model: x= ", vv.getX(), " y= ", vv.getY(), " z= ", vv.getZ()
+ print(" vertex: ", vi, "name: ", vv.getName(), " associated: ", va!=None)
+ print(" model: x= ", vv.getX(), " y= ", vv.getY(), " z= ", vv.getZ())
if va!=None:
x, y, z = geompy.PointCoordinates(va)
- print " assoc: x= ", x, " y= ", y, " z= ", z
+ print(" assoc: x= ", x, " y= ", y, " z= ", z)
uv = doc.countUsedVertex()
ue = doc.countUsedEdge()
uq = doc.countUsedQuad()
uh = doc.countUsedHexa()
- print "Model vertices number: ", uv
- print "Model edges number: ", ue
- print "Model quadrangles number: ", uq
- print "Model blocks number: ", uh
+ print("Model vertices number: ", uv)
+ print("Model edges number: ", ue)
+ print("Model quadrangles number: ", uq)
+ print("Model blocks number: ", uh)
if mesh != None:
- print
- print "Mesh nodes number: ", mesh.NbNodes()
- print "Mesh segments number: ", mesh.NbEdges()
- print "Mesh quadrangles number: ", mesh.NbQuadrangles()
- print "Mesh hexas number: ", mesh.NbHexas()
+ print()
+ print("Mesh nodes number: ", mesh.NbNodes())
+ print("Mesh segments number: ", mesh.NbEdges())
+ print("Mesh quadrangles number: ", mesh.NbQuadrangles())
+ print("Mesh hexas number: ", mesh.NbHexas())
return uv, ue, uq, uh
def mesh (doc, name=None, dim=3, container="FactoryServer"):
study = salome.myStudy
- if type(doc) == type(""):
+ if isinstance(doc, type("")):
doc = component.findDocument (doc)
docname = doc.getName()
#### shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
#### else :
#### shape = doc.getShape (0)
- ### shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
- ### stream = doc.getFirstExplicitShape ()
- ### if stream != None :
- ### shape = geompy.RestoreShape (stream)
- ### else :
- shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
+ ### shape = doc.getFirstExplicitShape_else_box(1)
+ ### the_stream = shape.getBREP() # sort une chaine de caractère
+ ### geom_object = geompy.RestoreShape(the_stream)
+
+ stream = doc.getFirstExplicitShape ()
+ if stream != None :
+ shape = geompy.RestoreShape (stream.encode())
+ else :
+ shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
- if (name == None) or (name == ""):
+ if (name == None) or (name == "") :
name = docname
geompy.addToStudy(shape, name)
comp_smesh = salome.lcc.FindOrLoadComponent(container, "SMESH")
- comp_smesh.init_smesh(study, geompy.geom)
+ comp_smesh.init_smesh(geomBuilder.geom)
meshexa = comp_smesh.Mesh(shape)
- so = "libHexaBlockEngine.so"
+ so = "libHexaBlockPluginEngine.so"
- algo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_3D", so)
+ algo = SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_3D", so)
meshexa.mesh.AddHypothesis(shape, algo)
- hypo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_Parameters", so)
+ hypo = SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_Parameters", so)
meshexa.mesh.AddHypothesis(shape, hypo)
### hypo.SetDocument(doc.getXml()) ## Hexa6 TODO et a verifier
- print " Maillage du document ", docname
+ print(" Maillage du document ", docname)
hypo.SetDocument (docname);
hypo.SetDimension(dim)
study = salome.myStudy
sobject = study.FindObjectID(entry)
if sobject == None :
- print " **** Entry ", entry, " is undefined"
+ print(" **** Entry ", entry, " is undefined")
return None
builder = study.NewBuilder()
docname = attname.Value()
doc = component.findDocument(docname)
if doc == None :
- print " **** Entry ", entry, " doesn't correspond to an HexaBlock Document"
+ print(" **** Entry ", entry, " doesn't correspond to an HexaBlock Document")
return doc
# ==================================================== findOrCreateComponent
# Find or create HexaBlock Study Component
-def findOrCreateComponent( study, builder ):
- father = study.FindComponent( moduleName() )
+def findOrCreateComponent( builder ):
+ father = salome.myStudy.FindComponent( moduleName() )
if father is None:
father = builder.NewComponent( moduleName() )
attr = builder.FindOrCreateAttribute( father, "AttributeName" )
# Add a document in the current study
def addToStudy(doc):
if doc == None :
- print " *** addToStudy : Bad Document Pointer"
+ print(" *** addToStudy : Bad Document Pointer")
return
study = salome.myStudy
builder = study.NewBuilder()
- father = findOrCreateComponent( study, builder )
+ father = findOrCreateComponent( builder )
name = doc.getName ()
present = study.FindObjectByName(name, moduleName())
if present != [] :
- print " *** addToStudy : Document ", name, "is already in the study"
+ print(" *** addToStudy : Document ", name, "is already in the study")
return
object = builder.NewObject( father )
# ==================================================== addShape
# Add a document in the current study
def addShape (doc, shape, name):
- print "Call addShape"
+ print("Call addShape")
forme = doc.addShape (shape.getShape(), name)
return forme