Salome HOME
41f9e5ce76c454209bf72fd18c59408d2b5c4532
[modules/shaper.git] / src / FeaturesPlugin / Test / TestCheckSharedFaces.py
1 # Copyright (C) 2014-2021  CEA/DEN, EDF R&D
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 """
21       Unit test of Check shared faces
22 """
23 #=========================================================================
24 # Initialization of the test
25 #=========================================================================
26
27
28 import os
29 import math
30
31 from ModelAPI import *
32 from GeomAPI import *
33 from salome.shaper import model
34
35
36 __updated__ = "2020-11-12"
37
38
39 if __name__ == '__main__':
40
41     model.begin()
42     partSet = model.moduleDocument()
43     Part_1 = model.addPart(partSet)
44     Part_1_doc = Part_1.document()
45     ### Create Box
46     Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
47     ### Create Point
48     Point_2 = model.addPoint(Part_1_doc, 20, 10, 10)
49     ### Create Box
50     Box_2 = model.addBox(Part_1_doc, model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Bottom]"), model.selection("VERTEX", "Point_1"))
51     ### Create CompSolid
52     CompSolid_1 = model.addCompSolid(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("SOLID", "Box_2_1")])
53     ### Create Box
54     Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
55     ### Create Box
56     Box_4 = model.addBox(Part_1_doc, 10, 10, 10)
57     ### Create Translation
58     Translation_1 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_4")], axis = model.selection("EDGE", "PartSet/OX"),
59                                          distance = 10, keepSubResults = True)
60     ### Create CompSolid
61     CompSolid_2 = model.addCompSolid(Part_1_doc, [model.selection("SOLID", "Box_3_1"), model.selection("COMPOUND", "Translation_1_1")])
62     ### Create Box
63     Box_5 = model.addBox(Part_1_doc, 10, 10, 10)
64     ### Create Translation
65     Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_5_1")], vector = [10, 0, 10], keepSubResults = True)
66     ### Create Compound
67     Compound_1 = model.addCompound(Part_1_doc, [model.selection("COMPSOLID", "CompSolid_1_1"), model.selection("SOLID", "Translation_2_1")])
68     Compound_1.result().setTransparency(0.5)
69     Compound_1.result().subResult(0).setTransparency(0.5)
70     Compound_1.result().subResult(0).subResult(0).setTransparency(0.5)
71     Compound_1.result().subResult(0).subResult(1).setTransparency(0.5)
72     Compound_1.result().subResult(1).setTransparency(0.5)
73
74     ### Create Shared_faces for compsolid
75     Shared_faces_1 = model.getSharedFaces(Part_1_doc, model.selection("COMPSOLID", "CompSolid_1_1"), "faces_compsolid")
76
77     ### Create Shared_faces for compound
78     Shared_faces_2 = model.getSharedFaces(Part_1_doc, model.selection("COMPOUND", "Compound_1_1"), 'faces_compound')
79
80     model.do()
81
82      # Check results
83     assert(Part_1_doc.size("Groups") == 2)
84     Shared_faces_1_Feature = Shared_faces_1.feature()
85     assert Shared_faces_1_Feature.error() == ''
86     assert Shared_faces_1_Feature.name() == "Shared_faces_1"
87
88     aSelectionList = Shared_faces_1_Feature.selectionList("group_list")
89     assert aSelectionList.size() == 1
90
91     Shared_faces_2_Feature = Shared_faces_2.feature()
92     assert Shared_faces_2_Feature.error() == ''
93     assert Shared_faces_2_Feature.name() == "Shared_faces_2"
94
95     aSelectionList = Shared_faces_2_Feature.selectionList("group_list")
96     assert aSelectionList.size() == 1
97
98     resShape_1 = modelAPI_Result(Part_1_doc.object("Groups", 0)).shape()
99     assert(not resShape_1.isNull())
100
101     # the group result is a face, check that this is one face
102     aShapeExplorer = GeomAPI_ShapeExplorer(resShape_1, GeomAPI_Shape.FACE)
103     assert(aShapeExplorer.more())
104     assert(aShapeExplorer.current().isFace())
105     aShapeExplorer.next()
106     assert(not aShapeExplorer.more())
107
108     resShape_2 = modelAPI_Result(Part_1_doc.object("Groups", 1)).shape()
109     assert(not resShape_2.isNull())
110
111     # the group result is a face, check that this is one face
112     aShapeExplorer = GeomAPI_ShapeExplorer(resShape_2, GeomAPI_Shape.FACE)
113     assert(aShapeExplorer.more())
114     assert(aShapeExplorer.current().isFace())
115     aShapeExplorer.next()
116     assert(not aShapeExplorer.more())
117
118     model.end()
119
120     #=========================================================================
121     # End of test
122     #=========================================================================