Salome HOME
Fix other crashs with attractors in other out of bounds cases
[plugins/blsurfplugin.git] / tests / attractor_edge_on_border.py
1 # -*- coding: utf-8 -*-
2
3 import sys
4 import salome
5
6 salome.salome_init()
7 theStudy = salome.myStudy
8
9 import  SMESH, SALOMEDS
10
11 ## Compute the minimum area of the faces of the mesh
12 def getMinArea(mesh):
13   faces = mesh.GetElementsByType(SMESH.FACE)
14   areas = [mesh.GetArea(face) for face in faces]
15   return min(areas)
16
17 ###
18 ### GEOM component
19 ###
20
21 import GEOM
22 from salome.geom import geomBuilder
23 import math
24 import SALOMEDS
25
26
27 geompy = geomBuilder.New(theStudy)
28
29 O = geompy.MakeVertex(0, 0, 0)
30 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
31 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
32 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
33 Face_1 = geompy.MakeFaceHW(100, 100, 1)
34 Box_1 = geompy.MakePrismVecH(Face_1, OZ, -100)
35 # define the edge slightly longer than the face to test out of bounds case.
36 P1 = geompy.MakeVertex(-50.5, 0, 0)
37 P2 = geompy.MakeVertex(50.5, 0, 0)
38 Edge_1 = geompy.MakeEdge(P1, P2)
39 geompy.addToStudy( O, 'O' )
40 geompy.addToStudy( OX, 'OX' )
41 geompy.addToStudy( OY, 'OY' )
42 geompy.addToStudy( OZ, 'OZ' )
43 geompy.addToStudy( Face_1, 'Face_1' )
44 geompy.addToStudy( Box_1, 'Box_1' )
45 geompy.addToStudy( Edge_1, 'Edge_1' )
46
47 sub_Face_1 = geompy.GetInPlace(Box_1, Face_1)
48 geompy.addToStudyInFather(Box_1, sub_Face_1, "Face_1")
49
50 ###
51 ### SMESH component
52 ###
53
54 from salome.smesh import smeshBuilder
55
56 smesh = smeshBuilder.New(theStudy)
57 Mesh_1 = smesh.Mesh(Box_1)
58 MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
59 MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
60 MG_CADSurf_Parameters_1.SetPhySize( 14.1421 )
61 MG_CADSurf_Parameters_1.SetMinSize( 0.141421 )
62 MG_CADSurf_Parameters_1.SetMaxSize( 28.2843 )
63 MG_CADSurf_Parameters_1.SetChordalError( 7.07107 )
64 #MG_CADSurf_Parameters_1.SetAttractorGeom( sub_Face_1, Edge_1, 1, 14.1421, 5, 5 )
65
66 Mesh_1.Compute()
67
68 min_area_without_attractor = getMinArea(Mesh_1)
69
70 print "min_area_without_attractor: ", min_area_without_attractor
71
72 MG_CADSurf_Parameters_1.SetAttractorGeom( sub_Face_1, Edge_1, 1, 14.1421, 5, 5 )
73
74 Mesh_1.Compute()
75
76 min_area_with_attractor = getMinArea(Mesh_1)
77
78 print "min_area_with_attractor: ", min_area_with_attractor
79
80 assert min_area_with_attractor < min_area_without_attractor
81
82 assert min_area_with_attractor < 1
83
84 if salome.sg.hasDesktop():
85   salome.sg.updateObjBrowser(True)