Salome HOME
[Code coverage FeaturesPlugin]: Improve coverage for Boolean operations
[modules/shaper.git] / src / FeaturesPlugin / Test / TestRevolution.py
1 ## Copyright (C) 2014-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       TestRevolution.py
23       Unit test of FeaturesPlugin_Revolution class
24
25       class FeaturesPlugin_Revolution : public ModelAPI_Feature
26         static const std::string MY_REVOLUTION_ID("Revolution");
27         static const std::string MY_GROUP_LIST_ID("base");
28         static const std::string MY_TO_OBJECT_ID("axis_object");
29         static const std::string METHOD_ATTR("CreationMethod");
30         static const std::string MY_TO_ANGLE_ID("to_angle");
31         static const std::string MY_FROM_ANGLE_ID("from_angle");
32         static const std::string MY_TO_OBJECT_ID("to_object");
33         static const std::string MY_TO_OFFSET_ID("to_offset");
34         static const std::string MY_FROM_OBJECT_ID("from_object");
35         static const std::string MY_FROM_OFFSET_ID("from_offset");
36
37         data()->addAttribute(LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
38         data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
39         data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
40         data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
41         data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
42         data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
43         data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
44         data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
45         data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
46 """
47 #=========================================================================
48 # Initialization of the test
49 #=========================================================================
50 from ModelAPI import *
51 from GeomDataAPI import *
52 from GeomAlgoAPI import *
53 from GeomAPI import *
54 import math
55
56 aSession = ModelAPI_Session.get()
57 aDocument = aSession.moduleDocument()
58 # Create a part for revol
59 aSession.startOperation()
60 aPartFeature = aDocument.addFeature("Part")
61 aSession.finishOperation()
62 assert (len(aPartFeature.results()) == 1)
63 # Another way is:
64 # aPart = aSession.activeDocument()
65 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
66 aPart = aPartResult.partDoc()
67
68 #=========================================================================
69 # Create a sketch circle to revol
70 #=========================================================================
71 aSession.startOperation()
72 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
73 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
74 origin.setValue(0, 0, 0)
75 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
76 dirx.setValue(1, 0, 0)
77 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
78 norm.setValue(0, 0, 1)
79
80 # Create circle
81 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
82 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
83 aCircleRadius = aSketchCircle.real("circle_radius")
84 anCircleCentr.setValue(0., 0.)
85 aCircleRadius.setValue(30.)
86 aSession.finishOperation()
87
88 # Build shape from sketcher results
89 aCircleSketchResult = modelAPI_ResultConstruction(aCircleSketchFeature.firstResult())
90 assert (aCircleSketchResult.facesNum() > 0)
91
92 #=========================================================================
93 # Create a sketch line to revol
94 #=========================================================================
95 aSession.startOperation()
96 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
97 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
98 origin.setValue(0, 0, 0)
99 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
100 dirx.setValue(1, 0, 0)
101 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
102 norm.setValue(0, 0, 1)
103
104 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
105 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
106 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
107 aLineStartPoint.setValue(-100., -100.)
108 aLineEndPoint.setValue(100., -100.)
109 aSession.finishOperation()
110
111 # Build shape from sketcher results
112 aLineSketchResult = aLineSketchFeature.firstResult()
113 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
114 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
115 aLineEdge = aShapeExplorer.current()
116
117 #=========================================================================
118 # Test revol between from and to angles
119 #=========================================================================
120 aSession.startOperation()
121 aRevolFt = aPart.addFeature("Revolution")
122 assert (aRevolFt.getKind() == "Revolution")
123 # selection type FACE=4
124 aRevolFt.selectionList("base").append(
125     aCircleSketchResult, aCircleSketchResult.face(0))
126 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
127 aRevolFt.string("CreationMethod").setValue("ByAngles")
128 aRevolFt.real("from_angle").setValue(10)
129 aRevolFt.real("to_angle").setValue(10)
130 aRevolFt.real("to_offset").setValue(0) #TODO: remove
131 aRevolFt.real("from_offset").setValue(0) #TODO: remove
132 aRevolFt.execute()
133 aSession.finishOperation()
134 assert (aRevolFt.real("from_angle").value() == 10.0)
135 assert (aRevolFt.real("to_angle").value() == 10.0)
136
137 # Check revol results
138 assert (len(aRevolFt.results()) > 0)
139 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
140 assert (aRevolResult is not None)
141
142 #=========================================================================
143 # Create bounding planes
144 #=========================================================================
145 # Create from plane
146 aSession.startOperation()
147 aFromPlaneFeature = aPart.addFeature("Plane")
148 aFromPlaneFeature.string("creation_method").setValue("by_general_equation")
149 aFromPlaneFeature.string("by_other_plane_option").setValue("by_distance_from_other") # TODO: remove
150 aFromPlaneFeature.real("A").setValue(0.)
151 aFromPlaneFeature.real("B").setValue(0.)
152 aFromPlaneFeature.real("C").setValue(1.)
153 aFromPlaneFeature.real("D").setValue(50.)
154 aSession.finishOperation()
155 aFromResult = aFromPlaneFeature.firstResult()
156 aFromShape = modelAPI_ResultConstruction(aFromResult).shape()
157
158 # Create to plane
159 aSession.startOperation()
160 aToPlaneFeature = aPart.addFeature("Plane")
161 aToPlaneFeature.string("creation_method").setValue("by_general_equation")
162 aToPlaneFeature.string("by_other_plane_option").setValue("by_distance_from_other") # TODO: remove
163 aToPlaneFeature.real("A").setValue(0.)
164 aToPlaneFeature.real("B").setValue(0.)
165 aToPlaneFeature.real("C").setValue(1.)
166 aToPlaneFeature.real("D").setValue(-50.)
167 aSession.finishOperation()
168 aToResult = aToPlaneFeature.firstResult()
169 aToShape = modelAPI_ResultConstruction(aToResult).shape()
170
171 #=========================================================================
172 # Test revol between bounding planes
173 #=========================================================================
174 aSession.startOperation()
175 aRevolFt = aPart.addFeature("Revolution")
176 assert (aRevolFt.getKind() == "Revolution")
177 # selection type FACE=4
178 aRevolFt.selectionList("base").append(
179     aCircleSketchResult, aCircleSketchResult.face(0))
180 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
181 aRevolFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
182 aRevolFt.real("from_angle").setValue(0) #TODO: remove
183 aRevolFt.real("to_angle").setValue(0) #TODO: remove
184 aRevolFt.selection("to_object").setValue(aToResult, None)
185 aRevolFt.real("to_offset").setValue(0)
186 aRevolFt.selection("from_object").setValue(aFromResult, None)
187 aRevolFt.real("from_offset").setValue(0)
188 aRevolFt.execute()
189 aSession.finishOperation()
190
191 # Check revol results
192 assert (len(aRevolFt.results()) > 0)
193 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
194 assert (aRevolResult is not None)
195 aSession.undo()
196
197 #=========================================================================
198 # Test revol between bounding plane
199 #=========================================================================
200 aSession.startOperation()
201 aRevolFt = aPart.addFeature("Revolution")
202 assert (aRevolFt.getKind() == "Revolution")
203 # selection type FACE=4
204 aRevolFt.selectionList("base").append(
205     aCircleSketchResult, aCircleSketchResult.face(0))
206 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
207 aRevolFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
208 aRevolFt.real("from_angle").setValue(0) #TODO: remove
209 aRevolFt.real("to_angle").setValue(0) #TODO: remove
210 aRevolFt.selection("to_object").setValue(aToResult, None)
211 aRevolFt.real("to_offset").setValue(0)
212 aRevolFt.selection("from_object").setValue(None, None)
213 aRevolFt.real("from_offset").setValue(0)
214 aRevolFt.execute()
215 aSession.finishOperation()
216
217 # Check revol results
218 assert (len(aRevolFt.results()) > 0)
219 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
220 assert (aRevolResult is not None)
221
222 from salome.shaper import model
223 assert(model.checkPythonDump())