Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestFillet.py
1 # Copyright (C) 2017-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       TestFillet.py
22       Unit test of FeaturesPlugin_Fillet class
23 """
24
25 from ModelAPI import *
26 from GeomDataAPI 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 geomDataAPI_Point(aPoint.attribute("point3d")).setValue(20, 5, 0)
55 aSession.finishOperation()
56
57 aSession.startOperation()
58 aCylinder = aPart.addFeature("Cylinder")
59 aCylinder.string("CreationMethod").setValue("Cylinder")
60 aCylinder.selection("base_point").selectSubShape("vertex", "Point_1")
61 aCylinder.selection("axis").selectSubShape("edge", "PartSet/OZ")
62 aCylinder.real("radius").setValue(5)
63 aCylinder.real("height").setValue(10)
64 aSession.finishOperation()
65
66 #=========================================================================
67 # Test 1. Create fillet with fixed radius
68 #=========================================================================
69 aSession.startOperation()
70 aFillet1 = aPart.addFeature("Fillet")
71 aFillet1.string("creation_method").setValue("fixed_radius")
72 anObjects = aFillet1.selectionList("main_objects")
73 anObjects.append("[Box_1_1/Left][Box_1_1/Top]", "edge")
74 aFillet1.real("radius1").setValue(3)
75 aSession.finishOperation()
76 assert(aFillet1.error() == ""), "FAILED: Fillet reports error \"{}\"".format(aFillet1.error())
77
78 #=========================================================================
79 # Test 2. Change fillet type
80 #=========================================================================
81 aSession.startOperation()
82 aFillet1.string("creation_method").setValue("variable_radius")
83 aFillet1.real("radius1").setValue(5)
84 aFillet1.real("radius2").setValue(1)
85 aSession.finishOperation()
86 assert(aFillet1.error() == ""), "FAILED: Fillet reports error \"{}\"".format(aFillet1.error())
87
88 #=========================================================================
89 # Test 3. Check fillet reports error if selected entities from different solids
90 #=========================================================================
91 aSession.startOperation()
92 aFillet2 = aPart.addFeature("Fillet")
93 aFillet2.string("creation_method").setValue("fixed_radius")
94 anObjects = aFillet2.selectionList("main_objects")
95 anObjects.append("Cylinder_1_1/Face_2", "face")
96 anObjects.append("Box_1_1/Right", "face")
97 aFillet2.real("radius1").setValue(2)
98 aSession.finishOperation()
99 assert(aFillet2.error() != ""), "FAILED: Fillet does not report error"
100
101 #=========================================================================
102 # Test 4. Fix the error
103 #=========================================================================
104 aSession.startOperation()
105 anObjects.removeLast()
106 aSession.finishOperation()
107 assert(aFillet2.error() == ""), "FAILED: Fillet reports error \"{}\"".format(aFillet1.error())
108
109 #=========================================================================
110 # Test 5. Check fillet reports error on smoothly connected edges
111 #=========================================================================
112 aSession.startOperation()
113 aFillet3 = aPart.addFeature("Fillet")
114 aFillet3.string("creation_method").setValue("fixed_radius")
115 aFillet3.selectionList("main_objects").append("Cylinder_1_1/Modified_Face_1", "face")
116 aFillet3.real("radius1").setValue(3)
117 aSession.finishOperation()
118 assert(aFillet3.lastResult() is None), "FAILED: Fillet should not produce a result"
119
120 #=========================================================================
121 # Test 6. Remove last fillet feature
122 #=========================================================================
123 aSession.startOperation()
124 aPart.removeFeature(aFillet3)
125 aSession.finishOperation()
126
127 #=========================================================================
128 # End of test
129 #=========================================================================
130
131 from salome.shaper import model
132 assert(model.checkPythonDump())