Back to index

salome-smesh  6.5.0
SMESH_test.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
00025 #  File   : SMESH_test.py
00026 #  Module : SMESH
00027 #
00028 import salome
00029 import geompy
00030 import smesh
00031 
00032 # ---- define a box
00033 
00034 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
00035 idb = geompy.addToStudy(box, "box")
00036 
00037 # ---- add first face of box in study
00038 
00039 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
00040 face = subShapeList[0]
00041 name = geompy.SubShapeName(face, box)
00042 idf = geompy.addToStudyInFather(box, face, name)
00043 
00044 # ---- add shell from box  in study
00045 
00046 subShellList = geompy.SubShapeAll(box, geompy.ShapeType["SHELL"])
00047 shell = subShellList[0]
00048 name = geompy.SubShapeName(shell, box)
00049 ids = geompy.addToStudyInFather(box, shell, name)
00050 
00051 # ---- add first edge of face in study
00052 
00053 edgeList = geompy.SubShapeAll(face, geompy.ShapeType["EDGE"])
00054 edge = edgeList[0];
00055 name = geompy.SubShapeName(edge, face)
00056 ide = geompy.addToStudyInFather(face, edge, name)
00057 
00058 # ---- SMESH
00059 
00060 smesh.SetCurrentStudy(salome.myStudy)
00061 box = salome.IDToObject(idb)
00062 mesh = smesh.Mesh(box, "Meshbox")
00063 
00064 print "-------------------------- add hypothesis to box"
00065 
00066 algo_1 = mesh.Segment(box)
00067 hyp = algo_1.LocalLength(100)
00068 print hyp.GetName()
00069 print hyp.GetId()
00070 print hyp.GetLength()
00071 
00072 algo_2 = mesh.Triangle(smesh.MEFISTO, box)
00073 hyp = algo_2.MaxElementArea(5000)
00074 print hyp.GetName()
00075 print hyp.GetId()
00076 print hyp.GetMaxElementArea()
00077 
00078 smesh.SetName(algo_2.GetSubMesh(), "SubMeshBox")
00079 
00080 
00081 print "-------------------------- add hypothesis to edge"
00082 
00083 edge = salome.IDToObject(ide)
00084 
00085 algo_3 = mesh.Segment(edge)
00086 hyp = algo_3.LocalLength(100)
00087 print hyp.GetName()
00088 print hyp.GetId()
00089 print hyp.GetLength()
00090 
00091 smesh.SetName(algo_3.GetSubMesh(), "SubMeshEdge")
00092 
00093 
00094 print "-------------------------- compute face"
00095 
00096 face = salome.IDToObject(idf)
00097 
00098 ret = mesh.Compute(face)
00099 print ret
00100 log = mesh.GetLog(0) # 0 - GetLog without ClearLog after, else if 1 - ClearLog after
00101 for a in log:
00102     print "-------"
00103     ii = 0
00104     ir = 0
00105     comType = a.commandType
00106     if comType == 0:
00107         for i in range(a.number):
00108             ind = a.indexes[ii]
00109             ii = ii+1
00110             r1 = a.coords[ir]
00111             ir = ir+1
00112             r2 = a.coords[ir]
00113             ir = ir+1
00114             r3 = a.coords[ir]
00115             ir = ir+1
00116             print "AddNode %i - %g %g %g" % (ind, r1, r2, r3)
00117     elif comType == 1:
00118         for i in range(a.number):
00119             ind = a.indexes[ii]
00120             ii = ii+1
00121             i1 = a.indexes[ii]
00122             ii = ii+1
00123             i2 = a.indexes[ii]
00124             ii = ii+1
00125             print "AddEdge %i - %i %i" % (ind, i1, i2)
00126     elif comType == 2:
00127         for i in range(a.number):
00128             ind = a.indexes[ii]
00129            print ind
00130             ii = ii+1
00131            print ii
00132             i1 = a.indexes[ii]
00133             ii = ii+1
00134             i2 = a.indexes[ii]
00135            print i2
00136             ii = ii+1
00137            print "ii", ii
00138             i3 = a.indexes[ii]
00139            print i3
00140             #ii = ii+1
00141             ii = ii+1
00142             print "AddTriangle %i - %i %i %i" % (ind, i1, i2, i3)