Salome HOME
Issue #803: Put all the python modules in the same python package newgeom
[modules/shaper.git] / src / ModelAPI / Test / Test1512.py
1 """
2       Test1512.py
3       Unit test for testing the correct selection of feature by the faces after the BOPs applied
4
5 """
6 #=========================================================================
7 # Initialization of the test
8 #=========================================================================
9 from ModelAPI import *
10 from GeomDataAPI import *
11 from GeomAlgoAPI import *
12 from GeomAPI import *
13
14 __updated__ = "2016-05-31"
15
16 aSession = ModelAPI_Session.get()
17 aPartSet = aSession.moduleDocument()
18
19 #=========================================================================
20 # Create a part
21 #=========================================================================
22 aSession.startOperation()
23 aPartFeature = aPartSet.addFeature("Part")
24 aSession.finishOperation()
25 assert (len(aPartFeature.results()) == 1)
26 aPart = aSession.activeDocument()
27
28 #=========================================================================
29 # Create a sketch rectangle in PartSet
30 #=========================================================================
31 aSession.startOperation()
32 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
33 aXOYPlane = objectToResult(aPartSet.objectByName("Construction", "XOY"))
34 aSketchFeature.selection("External").setValue(aXOYPlane, None)
35 # Create lines
36 aLine1 = aSketchFeature.addFeature("SketchLine")
37 geomDataAPI_Point2D(aLine1.attribute("StartPoint")).setValue(0, 0)
38 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(200, 0)
39 aLine2 = aSketchFeature.addFeature("SketchLine")
40 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(200, 0)
41 geomDataAPI_Point2D(aLine2.attribute("EndPoint")).setValue(200, 100)
42 aLine3 = aSketchFeature.addFeature("SketchLine")
43 geomDataAPI_Point2D(aLine3.attribute("StartPoint")).setValue(200, 100)
44 geomDataAPI_Point2D(aLine3.attribute("EndPoint")).setValue(0, 100)
45 aLine4 = aSketchFeature.addFeature("SketchLine")
46 geomDataAPI_Point2D(aLine4.attribute("StartPoint")).setValue(0, 100)
47 geomDataAPI_Point2D(aLine4.attribute("EndPoint")).setValue(0, 0)
48 aSession.finishOperation()
49
50 #=========================================================================
51 # Make extrusion on rectangle
52 #=========================================================================
53 aSession.startOperation()
54 aBox = aPart.addFeature("Extrusion")
55 aBox.selectionList("base").append(aSketchFeature.firstResult(), None)
56 aBox.string("CreationMethod").setValue("BySizes")
57 aBox.real("to_size").setValue(50)
58 aBox.real("from_size").setValue(0)
59 aSession.finishOperation()
60
61 #=========================================================================
62 # Create a cylindrical sketch for a big hole
63 #=========================================================================
64 aSession.startOperation()
65 aSketchFeature2 = featureToCompositeFeature(aPart.addFeature("Sketch"))
66 aSketchFeature2.selection("External").setValue(aXOYPlane, None);
67 aCirc1 = aSketchFeature2.addFeature("SketchCircle")
68 geomDataAPI_Point2D(aCirc1.attribute("CircleCenter")).setValue(100, 50)
69 aCirc1.real("CircleRadius").setValue(40)
70 aSession.finishOperation()
71
72 #=========================================================================
73 # Make extrusion on a big circle
74 #=========================================================================
75 aSession.startOperation()
76 aHoleExt = aPart.addFeature("Extrusion")
77 aHoleExt.selectionList("base").append(aSketchFeature2.firstResult(), None)
78 aHoleExt.string("CreationMethod").setValue("BySizes")
79 aHoleExt.real("to_size").setValue(60)
80 aHoleExt.real("from_size").setValue(0)
81 aSession.finishOperation()
82
83 #=========================================================================
84 # Do cut a hole from a box
85 #=========================================================================
86 aSession.startOperation()
87 aCut1 = aPart.addFeature("Boolean")
88 aCut1.selectionList("main_objects").append(aBox.firstResult(), None)
89 aCut1.selectionList("tool_objects").append(aHoleExt.firstResult(), None)
90 aCut1.integer("bool_type").setValue(0) # cut
91 aSession.finishOperation()
92
93 #=========================================================================
94 # Create a cylindrical sketch for a small tower
95 #=========================================================================
96 aSession.startOperation()
97 aSketchFeature3 = featureToCompositeFeature(aPart.addFeature("Sketch"))
98 aSketchFeature3.selection("External").setValue(aXOYPlane, None);
99 aCirc2 = aSketchFeature3.addFeature("SketchCircle")
100 geomDataAPI_Point2D(aCirc2.attribute("CircleCenter")).setValue(20, 20)
101 aCirc2.real("CircleRadius").setValue(10)
102 aSession.finishOperation()
103
104 #=========================================================================
105 # Make extrusion on a small circle
106 #=========================================================================
107 aSession.startOperation()
108 aTower = aPart.addFeature("Extrusion")
109 aTower.selectionList("base").append(aSketchFeature3.firstResult(), None)
110 aTower.string("CreationMethod").setValue("BySizes")
111 aTower.real("to_size").setValue(100)
112 aTower.real("from_size").setValue(0)
113 aSession.finishOperation()
114
115 #=========================================================================
116 # Do fuse with a tower. Tower must be an argument (not tool) to add the problem to the faces owners detection.
117 #=========================================================================
118 aSession.startOperation()
119 aFuse = aPart.addFeature("Boolean")
120 aFuse.selectionList("main_objects").append(aTower.firstResult(), None)
121 aFuse.selectionList("tool_objects").append(aCut1.firstResult(), None)
122 aFuse.integer("bool_type").setValue(1) # fuse
123 aSession.finishOperation()
124
125 #=========================================================================
126 # Create a group feature to use the selection attribute for selection of faces by the name.
127 #=========================================================================
128 def check_owner(selection, topology_type, feature):
129   aSession.startOperation()
130   aGroup = aPart.addFeature("Group")
131   aGroup.selectionList("group_list").append(selection, topology_type)
132   aFace = aGroup.selectionList("group_list").value(0).value()
133   aTestFeature = aPart.producedByFeature(aFuse.firstResult(), aFace)
134   assert(aTestFeature.name() == feature.name())
135   aSession.abortOperation()
136
137 # check faces
138 check_owner("Extrusion_1_1/Generated_Face_1", "face", aBox)
139 check_owner("Boolean_2_1/Modified_3", "face", aBox)
140 check_owner("Boolean_1_1/Modified_1", "face", aHoleExt)
141 check_owner("Boolean_2_1/Modified_2", "face", aTower)
142 # check edges without ambiguity
143 check_owner("Boolean_2_1/Modified_3&Extrusion_1_1/Generated_Face_2", "edge", aBox)
144 check_owner("Boolean_2_1/Modified_2&Extrusion_3_1/To_Face_1_1", "edge", aTower)
145
146 # check the connected topology method: solid is not a compound of connected topology
147 assert(aFuse.firstResult().shape().isConnectedTopology() == False)
148
149 #=========================================================================
150 # End of test
151 #=========================================================================
152
153 from salome.shaper import model
154 assert(model.checkPythonDump())