X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHEXABLOCK_SWIG%2Fhexablock.py;h=f4d67e79ebe00d463347f90df60fbf50a6c954fd;hb=167be4931bccbbe01e53313d18a9d3dd1484ecb4;hp=49489581918b1a83ce34231e7c6288492f6016a1;hpb=d2653597bfdcbc02089ac248dbee336ab7c01475;p=modules%2Fhexablock.git diff --git a/src/HEXABLOCK_SWIG/hexablock.py b/src/HEXABLOCK_SWIG/hexablock.py index 4948958..f4d67e7 100644 --- a/src/HEXABLOCK_SWIG/hexablock.py +++ b/src/HEXABLOCK_SWIG/hexablock.py @@ -1,4 +1,23 @@ # -*- 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 @@ -9,12 +28,12 @@ import salome salome.salome_init() from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) +geompy = geomBuilder.New() import SMESH from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) +smesh = smeshBuilder.New() component = hexablock_swig.hex_instance () @@ -61,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 @@ -106,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() @@ -121,7 +140,7 @@ def mesh (doc, name=None, dim=3, container="FactoryServer"): stream = doc.getFirstExplicitShape () if stream != None : - shape = geompy.RestoreShape (stream) + shape = geompy.RestoreShape (stream.encode()) else : shape = geompy.MakeBox(0, 0, 0, 1, 1, 1) @@ -130,7 +149,7 @@ def mesh (doc, name=None, dim=3, container="FactoryServer"): geompy.addToStudy(shape, name) comp_smesh = salome.lcc.FindOrLoadComponent(container, "SMESH") - comp_smesh.init_smesh(study, geomBuilder.geom) + comp_smesh.init_smesh(geomBuilder.geom) meshexa = comp_smesh.Mesh(shape) so = "libHexaBlockPluginEngine.so" @@ -142,7 +161,7 @@ def mesh (doc, name=None, dim=3, container="FactoryServer"): 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) @@ -155,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() @@ -163,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" ) @@ -184,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 ) @@ -205,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