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