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