Salome HOME
Implemented [bos #35094] [EDF] (2023-T1) X,Y,Z to U,V.
[modules/geom.git] / test / test_patch_face_01.py
1 # Check patch face functionality
2
3 def CheckFacesOnHoles( faces ):
4         """
5         check that none of the faces in the list have holes
6         param faces - list of faces
7         return bool - *True* if all faces not have hole; *False* otherwise
8         """
9         for face in faces:
10             newFaces = geompy.PatchFace(face)
11             if len(newFaces) != 1:
12                 return False
13         return True
14
15 def CompareAreaAfterPatchFace( originalFace, patchFaceResult, eps=1e-06 ):
16         """
17         Specific function for check result of PatchFace operation.
18         Check that area of original face equal area first face from list (face by outer wire of original face)
19         minus the areas of the rest elements from list (holes)
20         param originalFace - original face
21         param patchFaceResult - list of faces result PatchFace operation. 
22                               First element - face from outer wire of original face,
23                               other elements - faces from holes on original face
24         param eps - defines tolerance for comparison
25         return bool - *True* if area of original face is equal of area face[0] minus area of holes; *False* otherwise
26         """
27         areaOfHoles = 0.
28         for index in range(1, len(patchFaceResult)):
29             areaOfHoles += geompy.BasicProperties(patchFaceResult[index])[1]
30         return geompy.BasicProperties(originalFace)[1] - (geompy.BasicProperties(patchFaceResult[0])[1] - areaOfHoles) <= eps
31
32 import math
33 import salome
34 salome.salome_init_without_session()
35 import GEOM
36 from salome.geom import geomBuilder
37 geompy = geomBuilder.New()
38
39 # Create shape
40 vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
41 pyz = geompy.MakeVertex(0, -150, 100)
42
43 geomObj = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
44 sk = geompy.Sketcher2D()
45 sk.addPoint(30.0000000, 50.0000000)
46 sk.addArcAbsolute(70.0000000, 20.0000000)
47 sk.addSegmentAbsolute(0.0000000, 0.0000000)
48 sk.close()
49 sketch = sk.wire(geomObj)
50 face_1 = geompy.MakeFaceWires([sketch], 1)
51 multiTranslation = geompy.MakeMultiTranslation1D(face_1, None, 105, 3)
52 [face_2,face_3,face_4] = geompy.ExtractShapes(multiTranslation, geompy.ShapeType["FACE"], True)
53 scale_1 = geompy.MakeScaleTransform(face_3, None, 0.3)
54 scale_2 = geompy.MakeScaleTransform(face_4, None, 0.3)
55
56 translation_1 = geompy.MakeTranslation(scale_1, -10, 25, 0)
57 translation_2 = geompy.MakeTranslation(scale_2, -25, 20, 0)
58
59 rotation_1 = geompy.MakeRotation(translation_1, vz, -19*math.pi/180.0)
60 rotation_2 = geompy.MakeRotation(translation_2, vz, 15*math.pi/180.0)
61
62 cut = geompy.MakeCutList(face_1, [rotation_2, rotation_1], True)
63
64 #Perform oepration
65 faces = geompy.PatchFace(cut)
66
67 # Check, that result faces haven't holes
68 assert(CheckFacesOnHoles(faces))
69
70 #Check area
71 assert(CompareAreaAfterPatchFace(cut, faces))