Salome HOME
Improve ExchangePlugin code coverage
[modules/shaper.git] / src / FeaturesPlugin / Test / TestFillet.py
1 ## Copyright (C) 2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22       TestFillet.py
23       Unit test of FeaturesPlugin_Fillet class
24 """
25
26 from ModelAPI import *
27 from GeomDataAPI import *
28
29 __updated__ = "2017-11-30"
30
31 #=========================================================================
32 # Initialization of the test
33 #=========================================================================
34 aSession = ModelAPI_Session.get()
35 aDocument = aSession.moduleDocument()
36 # Create a part for extrusion
37 aSession.startOperation()
38 aPartFeature = aDocument.addFeature("Part")
39 aSession.finishOperation()
40 aPart = aSession.activeDocument()
41
42 # Create a box and a cylinder for filleting
43 aSession.startOperation()
44 aBox = aPart.addFeature("Box")
45 aBox.string("CreationMethod").setValue("BoxByDimensions")
46 aBox.real("dx").setValue(10)
47 aBox.real("dy").setValue(10)
48 aBox.real("dz").setValue(10)
49 aSession.finishOperation()
50
51 # a point to anchor a cylinder
52 aSession.startOperation()
53 aPoint = aPart.addFeature("Point")
54 aPoint.string("creation_method").setValue("by_xyz")
55 geomDataAPI_Point(aPoint.attribute("point3d")).setValue(20, 5, 0)
56 aSession.finishOperation()
57
58 aSession.startOperation()
59 aCylinder = aPart.addFeature("Cylinder")
60 aCylinder.string("CreationMethod").setValue("Cylinder")
61 aCylinder.selection("base_point").selectSubShape("vertex", "Point_1")
62 aCylinder.selection("axis").selectSubShape("edge", "PartSet/OZ")
63 aCylinder.real("radius").setValue(5)
64 aCylinder.real("height").setValue(10)
65 aSession.finishOperation()
66
67 #=========================================================================
68 # Test 1. Create fillet with fixed radius
69 #=========================================================================
70 aSession.startOperation()
71 aFillet1 = aPart.addFeature("Fillet")
72 aFillet1.string("creation_method").setValue("fixed_radius")
73 anObjects = aFillet1.selectionList("main_objects")
74 anObjects.append("[Box_1_1/Left][Box_1_1/Top]", "edge")
75 aFillet1.real("radius1").setValue(3)
76 aSession.finishOperation()
77 assert(aFillet1.error() == ""), "FAILED: Fillet reports error \"{}\"".format(aFillet1.error())
78
79 #=========================================================================
80 # Test 2. Change fillet type
81 #=========================================================================
82 aSession.startOperation()
83 aFillet1.string("creation_method").setValue("variable_radius")
84 aFillet1.real("radius1").setValue(5)
85 aFillet1.real("radius2").setValue(1)
86 aSession.finishOperation()
87 assert(aFillet1.error() == ""), "FAILED: Fillet reports error \"{}\"".format(aFillet1.error())
88
89 #=========================================================================
90 # Test 3. Check fillet reports error if selected entities from different solids
91 #=========================================================================
92 aSession.startOperation()
93 aFillet2 = aPart.addFeature("Fillet")
94 aFillet2.string("creation_method").setValue("fixed_radius")
95 anObjects = aFillet2.selectionList("main_objects")
96 anObjects.append("Cylinder_1_1/Face_2", "face")
97 anObjects.append("Box_1_1/Right", "face")
98 aFillet2.real("radius1").setValue(2)
99 aSession.finishOperation()
100 assert(aFillet2.error() != ""), "FAILED: Fillet does not report error"
101
102 #=========================================================================
103 # Test 4. Fix the error
104 #=========================================================================
105 aSession.startOperation()
106 anObjects.removeLast()
107 aSession.finishOperation()
108 assert(aFillet2.error() == ""), "FAILED: Fillet reports error \"{}\"".format(aFillet1.error())
109
110 #=========================================================================
111 # Test 5. Check fillet reports error on smoothly connected edges
112 #=========================================================================
113 aSession.startOperation()
114 aFillet3 = aPart.addFeature("Fillet")
115 aFillet3.string("creation_method").setValue("fixed_radius")
116 aFillet3.selectionList("main_objects").append("Cylinder_1_1/Modified_Face_1", "face")
117 aFillet3.real("radius1").setValue(3)
118 aSession.finishOperation()
119 assert(aFillet3.lastResult() is None), "FAILED: Fillet should not produce a result"
120
121 #=========================================================================
122 # Test 6. Remove last fillet feature
123 #=========================================================================
124 aSession.startOperation()
125 aPart.removeFeature(aFillet3)
126 aSession.finishOperation()
127
128 #=========================================================================
129 # End of test
130 #=========================================================================
131
132 from salome.shaper import model
133 assert(model.checkPythonDump())