Salome HOME
63bd43512b067274bd3bcda3245a5ca72beeaad3
[modules/shaper.git] / src / ModelAPI / Test / Test1512.py
1 # Copyright (C) 2014-2023  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       Test1512.py
22       Unit test for testing the correct selection of feature by the faces after the BOPs applied
23
24 """
25 #=========================================================================
26 # Initialization of the test
27 #=========================================================================
28 from ModelAPI import *
29 from GeomDataAPI import *
30 from GeomAlgoAPI import *
31 from GeomAPI import *
32
33 __updated__ = "2016-05-31"
34
35 aSession = ModelAPI_Session.get()
36 aPartSet = aSession.moduleDocument()
37
38 #=========================================================================
39 # Create a part
40 #=========================================================================
41 aSession.startOperation()
42 aPartFeature = aPartSet.addFeature("Part")
43 aSession.finishOperation()
44 assert (len(aPartFeature.results()) == 1)
45 aPart = aSession.activeDocument()
46
47 #=========================================================================
48 # Create a sketch rectangle in PartSet
49 #=========================================================================
50 aSession.startOperation()
51 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
52 aXOYPlane = objectToResult(aPartSet.objectByName("Construction", "XOY"))
53 aSketchFeature.selection("External").setValue(aXOYPlane, None)
54 # Create lines
55 aLine1 = aSketchFeature.addFeature("SketchLine")
56 geomDataAPI_Point2D(aLine1.attribute("StartPoint")).setValue(0, 0)
57 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(200, 0)
58 aLine2 = aSketchFeature.addFeature("SketchLine")
59 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(200, 0)
60 geomDataAPI_Point2D(aLine2.attribute("EndPoint")).setValue(200, 100)
61 aLine3 = aSketchFeature.addFeature("SketchLine")
62 geomDataAPI_Point2D(aLine3.attribute("StartPoint")).setValue(200, 100)
63 geomDataAPI_Point2D(aLine3.attribute("EndPoint")).setValue(0, 100)
64 aLine4 = aSketchFeature.addFeature("SketchLine")
65 geomDataAPI_Point2D(aLine4.attribute("StartPoint")).setValue(0, 100)
66 geomDataAPI_Point2D(aLine4.attribute("EndPoint")).setValue(0, 0)
67 aSession.finishOperation()
68
69 #=========================================================================
70 # Make extrusion on rectangle
71 #=========================================================================
72 aSession.startOperation()
73 aBox = aPart.addFeature("Extrusion")
74 aBox.selectionList("base").append(aSketchFeature.firstResult(), None)
75 aBox.string("CreationMethod").setValue("BySizes")
76 aBox.real("to_size").setValue(50)
77 aBox.real("from_size").setValue(0)
78 aSession.finishOperation()
79
80 #=========================================================================
81 # Create a cylindrical sketch for a big hole
82 #=========================================================================
83 aSession.startOperation()
84 aSketchFeature2 = featureToCompositeFeature(aPart.addFeature("Sketch"))
85 aSketchFeature2.selection("External").setValue(aXOYPlane, None);
86 aCirc1 = aSketchFeature2.addFeature("SketchCircle")
87 geomDataAPI_Point2D(aCirc1.attribute("circle_center")).setValue(100, 50)
88 aCirc1.real("circle_radius").setValue(40)
89 aSession.finishOperation()
90
91 #=========================================================================
92 # Make extrusion on a big circle
93 #=========================================================================
94 aSession.startOperation()
95 aHoleExt = aPart.addFeature("Extrusion")
96 aHoleExt.selectionList("base").append(aSketchFeature2.firstResult(), None)
97 aHoleExt.string("CreationMethod").setValue("BySizes")
98 aHoleExt.real("to_size").setValue(60)
99 aHoleExt.real("from_size").setValue(0)
100 aSession.finishOperation()
101
102 #=========================================================================
103 # Do cut a hole from a box
104 #=========================================================================
105 aSession.startOperation()
106 aCut1 = aPart.addFeature("Cut")
107 aCut1.selectionList("main_objects").append(aBox.firstResult(), None)
108 aCut1.selectionList("tool_objects").append(aHoleExt.firstResult(), None)
109 aSession.finishOperation()
110
111 #=========================================================================
112 # Create a cylindrical sketch for a small tower
113 #=========================================================================
114 aSession.startOperation()
115 aSketchFeature3 = featureToCompositeFeature(aPart.addFeature("Sketch"))
116 aSketchFeature3.selection("External").setValue(aXOYPlane, None);
117 aCirc2 = aSketchFeature3.addFeature("SketchCircle")
118 geomDataAPI_Point2D(aCirc2.attribute("circle_center")).setValue(20, 20)
119 aCirc2.real("circle_radius").setValue(10)
120 aSession.finishOperation()
121
122 #=========================================================================
123 # Make extrusion on a small circle
124 #=========================================================================
125 aSession.startOperation()
126 aTower = aPart.addFeature("Extrusion")
127 aTower.selectionList("base").append(aSketchFeature3.firstResult(), None)
128 aTower.string("CreationMethod").setValue("BySizes")
129 aTower.real("to_size").setValue(100)
130 aTower.real("from_size").setValue(0)
131 aSession.finishOperation()
132
133 #=========================================================================
134 # Do fuse with a tower. Tower must be an argument (not tool) to add the problem to the faces owners detection.
135 #=========================================================================
136 aSession.startOperation()
137 aFuse = aPart.addFeature("Fuse")
138 aFuse.string("creation_method").setValue("advanced")
139 aFuse.selectionList("main_objects").append(aTower.firstResult(), None)
140 aFuse.selectionList("tool_objects").append(aCut1.firstResult(), None)
141 aFuse.boolean("remove_intersection_edges").setValue(False)
142 aSession.finishOperation()
143
144 #=========================================================================
145 # Create a group feature to use the selection attribute for selection of faces by the name.
146 #=========================================================================
147 def check_owner(selection, topology_type, feature):
148   aSession.startOperation()
149   aGroup = aPart.addFeature("Group")
150   aGroup.selectionList("group_list").append(selection, topology_type)
151   aFace = aGroup.selectionList("group_list").value(0).value()
152   aTestFeature = aPart.producedByFeature(aFuse.firstResult(), aFace)
153   assert(aTestFeature.name() == feature.name())
154   aSession.abortOperation()
155
156 # check faces
157 check_owner("Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4", "face", aBox)
158 check_owner("Fuse_1_1/Modified_Face&Extrusion_1_1/To_Face", "face", aBox)
159 check_owner("Cut_1_1/Modified_Face&Sketch_2/SketchCircle_1_2", "face", aHoleExt)
160 check_owner("Fuse_1_1/Modified_Face&Sketch_3/SketchCircle_2_2", "face", aTower)
161 # check edges without ambiguity
162 check_owner("[Fuse_1_1/Modified_Face&Extrusion_1_1/To_Face][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3]", "edge", aBox)
163 check_owner("[Fuse_1_1/Modified_Face&Sketch_3/SketchCircle_2_2][Extrusion_3_1/To_Face]", "edge", aTower)
164
165 # check the connected topology method: solid is not a compound of connected topology
166 assert(aFuse.firstResult().shape().isConnectedTopology() == False)
167
168 #=========================================================================
169 # End of test
170 #=========================================================================
171
172 from salome.shaper import model
173 assert(model.checkPythonDump())