Salome HOME
Tests update
[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