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