Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestChamfer.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       TestChamfer.py
22       Unit test of FeaturesPlugin_Chamfer 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 chamfer with two distances
68 #=========================================================================
69 aSession.startOperation()
70 aChamfer1 = aPart.addFeature("Chamfer")
71 aChamfer1.string("creation_method").setValue("distance_distance")
72 anObjects = aChamfer1.selectionList("main_objects")
73 anObjects.append("[Box_1_1/Left][Box_1_1/Top]", "edge")
74 aChamfer1.real("d1").setValue(1.5)
75 aChamfer1.real("d2").setValue(2)
76 aSession.finishOperation()
77 assert(aChamfer1.error() == ""), "FAILED: Chamfer reports error \"{}\"".format(aChamfer1.error())
78
79 #=========================================================================
80 # Test 2. Change chamfer type
81 #=========================================================================
82 aSession.startOperation()
83 aChamfer1.string("creation_method").setValue("distance_angle")
84 aChamfer1.real("d").setValue(1)
85 aChamfer1.real("angle").setValue(30)
86 aSession.finishOperation()
87 assert(aChamfer1.error() == ""), "FAILED: Chamfer reports error \"{}\"".format(aChamfer1.error())
88
89 ##=========================================================================
90 ## Test 3. Check chamfer reports error if selected entities from different solids
91 ##=========================================================================
92 aSession.startOperation()
93 aChamfer2 = aPart.addFeature("Chamfer")
94 aChamfer2.string("creation_method").setValue("distance_distance")
95 anObjects = aChamfer2.selectionList("main_objects")
96 anObjects.append("Box_1_1/Bottom", "face")
97 aChamfer2.real("d1").setValue(-2)
98 aChamfer2.real("d2").setValue(2)
99 aSession.finishOperation()
100 assert(aChamfer2.error() != ""), "FAILED: Chamfer does not report error"
101
102 ##=========================================================================
103 ## Test 4. Fix the error
104 ##=========================================================================
105 aSession.startOperation()
106 aChamfer2.real("d1").setValue(1)
107 aSession.finishOperation()
108 assert(aChamfer2.error() == ""), "FAILED: Chamfer reports error \"{}\"".format(aChamfer2.error())
109
110 #=========================================================================
111 # Test 5. Check chamfer reports error on smoothly connected edges
112 #=========================================================================
113 aSession.startOperation()
114 aChamfer3 = aPart.addFeature("Chamfer")
115 aChamfer3.string("creation_method").setValue("distance_distance")
116 aChamfer3.selectionList("main_objects").append("Cylinder_1_1/Modified_Face_1", "face")
117 aChamfer3.real("d1").setValue(1)
118 aChamfer3.real("d2").setValue(1)
119 aSession.finishOperation()
120 assert(aChamfer3.lastResult() is None), "FAILED: Chamfer chamfer not produce a result"
121
122 #=========================================================================
123 # Test 6. Remove last fillet feature
124 #=========================================================================
125 aSession.startOperation()
126 aPart.removeFeature(aChamfer3)
127 aSession.finishOperation()
128
129 #=========================================================================
130 # End of test
131 #=========================================================================
132
133 from salome.shaper import model
134 assert(model.checkPythonDump())