Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestFusionFaces.py
1 # Copyright (C) 2014-2023  CEA, EDF
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from salome.shaper import model
21
22 # Create document
23 model.begin()
24 partSet = model.moduleDocument()
25 Part_1 = model.addPart(partSet)
26 Part_1_doc = Part_1.document()
27
28 # =============================================================================
29 # Test 1. Fusion faces for shell of 2 adjacent faces lying on plane
30 # =============================================================================
31 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
32 Box_2 = model.addBox(Part_1_doc, 10, 10, 10)
33 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("EDGE", "PartSet/OX"), 10)
34
35 model.do()
36 Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Box_1_1/Top"), model.selection("FACE", "Translation_1_1/MF:Translated&Box_2_1/Top")])
37 model.do()
38
39 model.checkResult(Shell_1, model, 1, [0], [0], [2], [8], [16])
40
41 FusionFaces_1 = model.addFusionFaces(Part_1_doc, model.selection("SHELL", "Shell_1_1"))
42 model.end()
43
44 model.checkResult(FusionFaces_1, model, 1, [0], [0], [1], [4], [8])
45
46 model.undo() # to reuse Box_1_1 and Translation_1_1
47 model.undo()
48 model.begin()
49
50 # =============================================================================
51 # Test 2. Fusion faces for solid of 2 adjacent boxes
52 # =============================================================================
53 Fuse_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("SOLID", "Translation_1_1")], [])
54 model.do()
55
56 model.checkResult(Fuse_1, model, 1, [0], [1], [10], [40], [80])
57
58 FusionFaces_2 = model.addFusionFaces(Part_1_doc, model.selection("SOLID", "Fuse_1_1"))
59 model.do()
60
61 model.checkResult(FusionFaces_2, model, 1, [0], [1], [6], [24], [48])
62
63 # =============================================================================
64 # Test 3. Fusion faces for shell of adjacent faces lying on cylindrical surface
65 # =============================================================================
66 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
67 Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Cylinder_1_1/Face_1")])
68 Point_1 = model.addPoint(Part_1_doc, 0, 0, 5)
69 Plane_1 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/OZ"), model.selection("VERTEX", "Point_1"), True)
70
71 Partition_1 = model.addPartition(Part_1_doc, [model.selection("SHELL", "Shell_1_1"), model.selection("FACE", "Plane_1")])
72 model.do()
73
74 model.checkResult(Partition_1, model, 1, [0], [0], [2], [8], [16])
75
76 FusionFaces_3 = model.addFusionFaces(Part_1_doc, model.selection("SHELL", "Partition_1_1"))
77 model.do()
78
79 model.checkResult(FusionFaces_3, model, 1, [0], [0], [1], [4], [8])
80
81 # =============================================================================
82 # Test 4. Fusion faces for compsolid
83 # =============================================================================
84 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
85 SketchLine_1 = Sketch_1.addLine(25, 40, -50, 40)
86 SketchLine_2 = Sketch_1.addLine(-50, 40, -50, 0)
87 SketchLine_3 = Sketch_1.addLine(-50, 0, 25, 0)
88 SketchLine_4 = Sketch_1.addLine(25, 0, 25, 40)
89 SketchLine_5 = Sketch_1.addLine(-20, 40, -20, 0)
90 model.do()
91
92 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0)
93 Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
94
95 Fuse_2 = model.addFuse(Part_1_doc, [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("SOLID", "Box_3_1")])
96 model.do()
97
98 model.checkResult(Fuse_2, model, 1, [1], [1], [14], [64], [128])
99
100 FusionFaces_4 = model.addFusionFaces(Part_1_doc, model.selection("COMPSOLID", "Fuse_2_1"))
101 model.do()
102
103 model.checkResult(FusionFaces_4, model, 1, [1], [1], [6], [24], [48])
104
105 # =============================================================================
106 # Test 5. Fusion faces for compound
107 # =============================================================================
108 Box_4 = model.addBox(Part_1_doc, 10, 10, 10)
109 Box_5 = model.addBox(Part_1_doc, 10, 10, 10)
110 Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_5_1")], 0, 0, 5)
111 Box_6 = model.addBox(Part_1_doc, 10, 10, 10)
112 Translation_3 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_6_1")], 20, 0, 0)
113 Box_7 = model.addBox(Part_1_doc, 10, 10, 10)
114 Translation_4 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_7_1")], 20, 0, 5)
115 Fuse_3 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Box_4_1"), model.selection("SOLID", "Translation_2_1")], [])
116 Fuse_4 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Translation_3_1"), model.selection("SOLID", "Translation_4_1")], [])
117
118 Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Fuse_3_1"), model.selection("SOLID", "Fuse_4_1")])
119 model.do()
120
121 model.checkResult(Compound_1, model, 1, [2], [2], [28], [112], [224])
122
123 FusionFaces_5 = model.addFusionFaces(Part_1_doc, model.selection("COMPOUND", "Compound_1_1"))
124 model.do()
125
126 model.checkResult(FusionFaces_5, model, 1, [2], [2], [12], [48], [96])
127
128 # =============================================================================
129 # Test 6. Check subshapes naming
130 # =============================================================================
131 #model.testHaveNamingSubshapes(FusionFaces_1, model, Part_1_doc)
132 model.testHaveNamingSubshapes(FusionFaces_2, model, Part_1_doc)
133 #model.testHaveNamingSubshapes(FusionFaces_3, model, Part_1_doc)
134 model.testHaveNamingSubshapes(FusionFaces_4, model, Part_1_doc)
135 model.testHaveNamingSubshapes(FusionFaces_5, model, Part_1_doc)
136 model.end()
137
138 # =============================================================================
139 # Test 7. Check Python dump
140 # =============================================================================
141 assert(model.checkPythonDump())