1 # Copyright (C) 2015-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 # File : smesh_selection.py
20 # Author : Roman NIKOLAEV, OPEN CASCADE ( roman.nikolaev@opencascade.com )
27 sm_gui = libSMESH_Swig.SMESH_Swig()
29 import SMESH, SALOMEDS
30 from salome.smesh import smeshBuilder
31 smesh = smeshBuilder.New(salome.myStudy)
37 libSMESH_Swig.EdgeOfCell : None, # TODO: check how to process it
38 libSMESH_Swig.Node : SMESH.NODE,
39 libSMESH_Swig.Edge : SMESH.EDGE,
40 libSMESH_Swig.Face : SMESH.FACE,
41 libSMESH_Swig.Volume : SMESH.VOLUME,
42 libSMESH_Swig.Elem0D : SMESH.ELEM0D,
43 libSMESH_Swig.Ball : SMESH.BALL,
44 libSMESH_Swig.Cell : SMESH.ALL
47 # Converts swig to idl enumeration
48 def _swig2idl( type ):
49 if _converter.has_key( type ) :
50 return _converter[type]
54 if isinstance( mesh, smeshBuilder.Mesh ) :
55 return salome.ObjectToID( mesh.GetMesh() )
57 if isinstance( mesh, str ) :
62 if isinstance( mesh, smeshBuilder.Mesh ) :
65 if isinstance( mesh, str ) :
66 return salome.IDToObject( mesh )
70 if isinstance( geom, GEOM._objref_GEOM_Object ) :
73 if isinstance( geom, str ) :
74 return salome.IDToObject( geom )
78 # Selects an elements lst on the mesh
79 def select( mesh, lst, append = False ) :
80 # Check mesh parameter
81 entry = _getEntry(mesh)
83 print "Wrong 'mesh' parameter"
88 if isinstance( lst, int ) :
91 if isinstance( lst,list ) :
94 print "Wrong 'lst' parameter"
96 sm_gui.select( entry, tmp, append )
99 def _preProcess(mesh) :
102 print "Wrong 'mesh' parameter"
105 elemType = _swig2idl(sm_gui.getSelectionMode())
112 # Selects an elements on the mesh inside the sphere with radius r and center (x, y, z)
113 def selectInsideSphere( mesh, x, y, z, r, append = False ) :
115 [m, elemType] = _preProcess(mesh)
116 if m is None or elemType is None :
119 l = smesh.GetInsideSphere( m, elemType, x, y, z, r )
121 select(mesh, l, append)
123 # Selects an elements on the mesh inside the box
124 def selectInsideBox( mesh, x1, y1, z1, x2, y2, z2 , append = False ) :
126 [m, elemType] = _preProcess(mesh)
127 if m is None or elemType is None :
130 l = smesh.GetInsideBox( m, elemType, x1, y1, z1, x2, y2, z2 )
132 select(mesh, l, append)
134 # Selects an elements on the mesh inside the cylinder
135 def selectInsideCylinder( mesh, x, y, z, dx, dy, dz, h, r, append = False ) :
137 [m, elemType] = _preProcess(mesh)
138 if m is None or elemType is None :
141 l = smesh.GetInsideCylinder( m, elemType, x, y, z, dx, dy, dz, h, r )
143 select(mesh, l, append)
145 # Selects an elements on the mesh inside the geometrical object
146 def selectInside( mesh, geom, tolerance , append = False ):
148 [m, elemType] = _preProcess(mesh)
149 if m is None or elemType is None :
154 l = smesh.GetInside( m, elemType, g ,tolerance )
156 select(mesh, l, append)