X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHEXABLOCK_SWIG%2Fhexablock.py;h=f4d67e79ebe00d463347f90df60fbf50a6c954fd;hb=167be4931bccbbe01e53313d18a9d3dd1484ecb4;hp=5b422849aea8b14711460a37009da9d83e3e4d7a;hpb=5347e8abe119e8704d59c83638836f0fd94c732e;p=modules%2Fhexablock.git diff --git a/src/HEXABLOCK_SWIG/hexablock.py b/src/HEXABLOCK_SWIG/hexablock.py index 5b42284..f4d67e7 100644 --- a/src/HEXABLOCK_SWIG/hexablock.py +++ b/src/HEXABLOCK_SWIG/hexablock.py @@ -1,13 +1,40 @@ # -*- 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 @@ -53,43 +80,43 @@ def findDocument (name) : 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 @@ -98,7 +125,7 @@ def dump(doc, mesh=None, full=False): 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() @@ -106,32 +133,35 @@ def mesh (doc, name=None, dim=3, container="FactoryServer"): #### 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) @@ -144,7 +174,7 @@ def getFromStudy(entry): 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() @@ -152,14 +182,14 @@ def getFromStudy(entry): 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" ) @@ -173,17 +203,17 @@ def findOrCreateComponent( study, builder ): # 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 ) @@ -194,6 +224,6 @@ def addToStudy(doc): # ==================================================== 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