X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSalomeApp%2Fpluginsdemo%2Ftubebuilder.py;h=c0538f4630c1936df68e46c779aa561111bbe11f;hb=7c477e37f63b76012fb8695cd0563b4a086b54ae;hp=0a94cfa683280f236d4d36dc64fc3dafd8ef669e;hpb=cf4b329610f8c3ae4b77edd0449153bca117efa3;p=modules%2Fgui.git diff --git a/src/SalomeApp/pluginsdemo/tubebuilder.py b/src/SalomeApp/pluginsdemo/tubebuilder.py index 0a94cfa68..c0538f463 100644 --- a/src/SalomeApp/pluginsdemo/tubebuilder.py +++ b/src/SalomeApp/pluginsdemo/tubebuilder.py @@ -1,10 +1,10 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2010-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2010-2016 CEA/DEN, EDF R&D, OPEN CASCADE # # 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. +# 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 @@ -27,14 +27,13 @@ DEFAULT_WIDTH = 20 from salome.geom import geomtools -def createGeometry(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH): +def createGeometry(radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH): ''' This function creates the geometry on the specified study and with given parameters. ''' - print "TUBE: creating the geometry ..." - studyId = study._get_StudyId() - geompy = geomtools.getGeompy(studyId) + print("TUBE: creating the geometry ...") + geompy = geomtools.getGeompy() radius_ext = radius radius_int = radius_ext - width @@ -44,30 +43,29 @@ def createGeometry(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DE Tube = geompy.MakeCut(CylinderExt, CylinderInt) return Tube -def createGeometryWithPartition(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH): +def createGeometryWithPartition(radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH): ''' This function create the geometrical shape with a partition so that the hexaedric algorithm could be used for meshing. ''' - shape = createGeometry(study,radius,length,width) + shape = createGeometry(radius,length,width) # We have to create a partition so that we can use an hexaedric # meshing algorithm. - studyId = study._get_StudyId() - geompy = geomtools.getGeompy(studyId) + geompy = geomtools.getGeompy() - print "TUBE: creating a partition ..." + print("TUBE: creating a partition ...") toolPlane = geompy.MakeFaceHW(2.1*length,2.1*radius,3) partition = geompy.MakePartition([shape], [toolPlane], [], [], geompy.ShapeType["SOLID"], 0, [], 0) entry = geompy.addToStudy( partition, "TubeWithPartition" ) return partition -def createMesh(study, shape): - '''This function creates the mesh of the specified shape on the specified study''' - print "TUBE: creating the mesh ..." +def createMesh(shape): + '''This function creates the mesh of the specified shape on the current study''' + print("TUBE: creating the mesh ...") import SMESH from salome.smesh import smeshBuilder - smesh = smeshBuilder.New(study) + smesh = smeshBuilder.New() mesh = smesh.Mesh(shape) Regular_1D = mesh.Segment() @@ -84,29 +82,29 @@ def createMesh(study, shape): smesh.SetName(Nb_Segments, 'Nb. Segments_1') smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D') smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D') - salome.sg.updateObjBrowser(0) + salome.sg.updateObjBrowser() return mesh -def createModel(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH,width=DEFAULT_WIDTH): +def createModel(radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH,width=DEFAULT_WIDTH): ''' This function create the geomtrical shape AND the associated mesh. ''' # We first create a shape with a partition so that the hexaedric # algorithm could be used. - shape = createGeometryWithPartition(study,radius,length,width) + shape = createGeometryWithPartition(radius,length,width) # Then the mesh can be defined and computed - mesh = createMesh(study,shape) + mesh = createMesh(shape) def exportModel(mesh, filename): ''' This exports the mesh to the specified filename in the med format ''' - print "TUBE: exporting mesh to file %s ..."%filename + print("TUBE: exporting mesh to file %s ..."%filename) import SMESH - mesh.ExportMED(filename, 0, SMESH.MED_V2_2, 1 ) + mesh.ExportMED(filename) # @@ -116,25 +114,21 @@ def exportModel(mesh, filename): # def TEST_createGeometry(): salome.salome_init() - theStudy=salome.myStudy - createGeometry(theStudy) + createGeometry() def TEST_createMesh(): salome.salome_init() - theStudy=salome.myStudy - shape = createGeometryWithPartition(theStudy) - mesh = createMesh(theStudy, shape) + shape = createGeometryWithPartition() + mesh = createMesh(shape) def TEST_createModel(): salome.salome_init() - theStudy=salome.myStudy - createModel(theStudy) + createModel() def TEST_exportModel(): salome.salome_init() - theStudy=salome.myStudy - shape = createGeometryWithPartition(theStudy) - mesh = createMesh(theStudy, shape) + shape = createGeometryWithPartition() + mesh = createMesh(shape) exportModel(mesh,"tubemesh.med") if __name__ == "__main__":