Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestSewing_Manifold.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
23 # Create document
24 model.begin()
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 Param_dx = model.addParameter(Part_1_doc, "dx", '10')
29 Param_alfa = model.addParameter(Part_1_doc, "alfa", '90')
30
31 # =============================================================================
32 # Test 1a. Sew two shells with a single common edge (create result)
33 # =============================================================================
34 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
35 Box_2 = model.addBox(Part_1_doc, 10, 10, 10)
36 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], axis = model.selection("EDGE", "PartSet/OX"), distance = "dx", keepSubResults = True)
37 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], axis = model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Right]"), angle = "alfa", keepSubResults = True)
38
39 Shell_1_objects = [model.selection("FACE", "Box_1_1/Top"),
40                    model.selection("FACE", "Box_1_1/Left"),
41                    model.selection("FACE", "Box_1_1/Right"),
42                    model.selection("FACE", "Box_1_1/Back"),
43                    model.selection("FACE", "Box_1_1/Bottom")]
44 Shell_1 = model.addShell(Part_1_doc, Shell_1_objects)
45
46 Shell_2_objects = [model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Top"),
47                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Left"),
48                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Front"),
49                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Right"),
50                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Bottom")]
51 Shell_2 = model.addShell(Part_1_doc, Shell_2_objects)
52 model.do()
53
54 Sewing_1a = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = True)
55 model.end()
56
57 # sewing successful
58 model.testResults(Sewing_1a, 1, [0], [1], [10], [23], [14])
59
60 # =============================================================================
61 # Test 1b. Sew two shells with a single common edge (do not create result)
62 # =============================================================================
63 model.undo()
64 model.begin()
65
66 Sewing_1b = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = False)
67 model.end()
68
69 # sewing successful
70 model.testResults(Sewing_1b, 1, [0], [1], [10], [23], [14])
71
72 # =============================================================================
73 # Test 2a. Sew two shells with four common edges (create result)
74 # =============================================================================
75 model.undo()
76 model.begin()
77 Param_alfa.setValue(0)
78 model.do()
79
80 Sewing_2a = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = True)
81 model.end()
82
83 # sewing successful
84 model.testResults(Sewing_2a, 1, [0], [1], [10], [20], [12])
85
86 # =============================================================================
87 # Test 2b. Sew two shells with four common edges (do not create result)
88 # =============================================================================
89 model.undo()
90 model.begin()
91
92 Sewing_2b = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = False)
93 model.end()
94
95 # sewing successful
96 model.testResults(Sewing_2b, 1, [0], [1], [10], [20], [12])
97
98 # =============================================================================
99 # Test 3a. Sew two slightly disconnected shells (create result)
100 # =============================================================================
101 model.undo()
102 model.begin()
103 Param_dx.setValue(10.0001)
104 model.do()
105
106 Sewing_3a = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = True)
107 model.end()
108
109 # no sewing done (result is a compound with the two input shells)
110 model.testResults(Sewing_3a, 1, [2], [2], [10], [24], [16])
111
112 # =============================================================================
113 # Test 3b. Sew two slightly disconnected shells (do not create result)
114 # =============================================================================
115 model.undo()
116 model.begin()
117
118 Sewing_3b = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = False)
119 model.end()
120
121 # no sewing done (no result was created)
122 model.testNbResults(Sewing_3b, 0)
123
124 # =============================================================================
125 # Test 4a. Sew two slightly disconnected shells with larger tolerance (create result)
126 # =============================================================================
127 model.undo()
128 model.begin()
129 Param_dx.setValue(10.0001)
130 model.do()
131
132 Sewing_4a = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-04, allowNonManifold = False, alwaysCreateResult = True)
133 model.end()
134
135 # sewing successful
136 model.testResults(Sewing_4a, 1, [0], [1], [10], [20], [12])
137
138 # =============================================================================
139 # Test 4b. Sew two slightly disconnected shells with larger tolerance (do not create result)
140 # =============================================================================
141 model.undo()
142 model.begin()
143
144 Sewing_4b = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-04, allowNonManifold = False, alwaysCreateResult = False)
145 model.end()
146
147 # sewing successful
148 model.testResults(Sewing_4b, 1, [0], [1], [10], [20], [12])