Salome HOME
Merge branch 'Pre_2.8.0_development'
[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 = aCircleSketchFeature.firstResult()
90 aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape()
91 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt()
92 dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir()
93 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir()
94 aCircleSketchFaces = ShapeList()
95 GeomAlgoAPI_SketchBuilder.createFaces(
96     origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces)
97 assert (len(aCircleSketchFaces) > 0)
98 assert (aCircleSketchFaces[0] is not None)
99
100 #=========================================================================
101 # Create a sketch line to revol
102 #=========================================================================
103 aSession.startOperation()
104 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
105 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
106 origin.setValue(0, 0, 0)
107 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
108 dirx.setValue(1, 0, 0)
109 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
110 norm.setValue(0, 0, 1)
111
112 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
113 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
114 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
115 aLineStartPoint.setValue(-100., -100.)
116 aLineEndPoint.setValue(100., -100.)
117 aSession.finishOperation()
118
119 # Build shape from sketcher results
120 aLineSketchResult = aLineSketchFeature.firstResult()
121 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
122 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
123 aLineEdge = aShapeExplorer.current()
124
125 #=========================================================================
126 # Test revol between from and to angles
127 #=========================================================================
128 aSession.startOperation()
129 aRevolFt = aPart.addFeature("Revolution")
130 assert (aRevolFt.getKind() == "Revolution")
131 # selection type FACE=4
132 aRevolFt.selectionList("base").append(
133     aCircleSketchResult, aCircleSketchFaces[0])
134 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
135 aRevolFt.string("CreationMethod").setValue("ByAngles")
136 aRevolFt.real("from_angle").setValue(10)
137 aRevolFt.real("to_angle").setValue(10)
138 aRevolFt.real("to_offset").setValue(0) #TODO: remove
139 aRevolFt.real("from_offset").setValue(0) #TODO: remove
140 aRevolFt.execute()
141 aSession.finishOperation()
142 assert (aRevolFt.real("from_angle").value() == 10.0)
143 assert (aRevolFt.real("to_angle").value() == 10.0)
144
145 # Check revol results
146 assert (len(aRevolFt.results()) > 0)
147 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
148 assert (aRevolResult is not None)
149
150 #=========================================================================
151 # Create bounding planes
152 #=========================================================================
153 # Create from plane
154 aSession.startOperation()
155 aFromPlaneFeature = aPart.addFeature("Plane")
156 aFromPlaneFeature.string("creation_method").setValue("by_general_equation")
157 aFromPlaneFeature.string("by_other_plane_option").setValue("by_distance_from_other") # TODO: remove
158 aFromPlaneFeature.real("A").setValue(0.)
159 aFromPlaneFeature.real("B").setValue(0.)
160 aFromPlaneFeature.real("C").setValue(1.)
161 aFromPlaneFeature.real("D").setValue(50.)
162 aSession.finishOperation()
163 aFromResult = aFromPlaneFeature.firstResult()
164 aFromShape = modelAPI_ResultConstruction(aFromResult).shape()
165
166 # Create to plane
167 aSession.startOperation()
168 aToPlaneFeature = aPart.addFeature("Plane")
169 aToPlaneFeature.string("creation_method").setValue("by_general_equation")
170 aToPlaneFeature.string("by_other_plane_option").setValue("by_distance_from_other") # TODO: remove
171 aToPlaneFeature.real("A").setValue(0.)
172 aToPlaneFeature.real("B").setValue(0.)
173 aToPlaneFeature.real("C").setValue(1.)
174 aToPlaneFeature.real("D").setValue(-50.)
175 aSession.finishOperation()
176 aToResult = aToPlaneFeature.firstResult()
177 aToShape = modelAPI_ResultConstruction(aToResult).shape()
178
179 #=========================================================================
180 # Test revol between bounding planes
181 #=========================================================================
182 aSession.startOperation()
183 aRevolFt = aPart.addFeature("Revolution")
184 assert (aRevolFt.getKind() == "Revolution")
185 # selection type FACE=4
186 aRevolFt.selectionList("base").append(
187     aCircleSketchResult, aCircleSketchFaces[0])
188 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
189 aRevolFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
190 aRevolFt.real("from_angle").setValue(0) #TODO: remove
191 aRevolFt.real("to_angle").setValue(0) #TODO: remove
192 aRevolFt.selection("to_object").setValue(aToResult, None)
193 aRevolFt.real("to_offset").setValue(0)
194 aRevolFt.selection("from_object").setValue(aFromResult, None)
195 aRevolFt.real("from_offset").setValue(0)
196 aRevolFt.execute()
197 aSession.finishOperation()
198
199 # Check revol results
200 assert (len(aRevolFt.results()) > 0)
201 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
202 assert (aRevolResult is not None)
203 aSession.undo()
204
205 #=========================================================================
206 # Test revol between bounding plane
207 #=========================================================================
208 aSession.startOperation()
209 aRevolFt = aPart.addFeature("Revolution")
210 assert (aRevolFt.getKind() == "Revolution")
211 # selection type FACE=4
212 aRevolFt.selectionList("base").append(
213     aCircleSketchResult, aCircleSketchFaces[0])
214 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
215 aRevolFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
216 aRevolFt.real("from_angle").setValue(0) #TODO: remove
217 aRevolFt.real("to_angle").setValue(0) #TODO: remove
218 aRevolFt.selection("to_object").setValue(aToResult, None)
219 aRevolFt.real("to_offset").setValue(0)
220 aRevolFt.selection("from_object").setValue(None, None)
221 aRevolFt.real("from_offset").setValue(0)
222 aRevolFt.execute()
223 aSession.finishOperation()
224
225 # Check revol results
226 assert (len(aRevolFt.results()) > 0)
227 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
228 assert (aRevolResult is not None)
229
230 from salome.shaper import model
231 assert(model.checkPythonDump())