]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/Test/TestRevolution.py
Salome HOME
Revolution tests.
[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 MY_TO_ANGLE_ID("to_angle");
10         static const std::string MY_FROM_ANGLE_ID("from_angle");
11         static const std::string MY_TO_OBJECT_ID("to_object");
12         static const std::string MY_FROM_OBJECT_ID("from_object");
13
14         data()->addAttribute(FeaturesPlugin_Revolution::LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
15         data()->addAttribute(FeaturesPlugin_Revolution::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
16         data()->addAttribute(FeaturesPlugin_Revolution::FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
17         data()->addAttribute(FeaturesPlugin_Revolution::FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
18         data()->addAttribute(FeaturesPlugin_Revolution::TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
19         data()->addAttribute(FeaturesPlugin_Revolution::TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
20 """
21 #=========================================================================
22 # Initialization of the test
23 #=========================================================================
24 from ModelAPI import *
25 from GeomDataAPI import *
26 from GeomAlgoAPI import *
27 from GeomAPI import *
28 import math
29
30 aSession = ModelAPI_Session.get()
31 aDocument = aSession.moduleDocument()
32 # Create a part for revol
33 aSession.startOperation()
34 aPartFeature = aDocument.addFeature("Part")
35 aSession.finishOperation()
36 assert (len(aPartFeature.results()) == 1)
37 # Another way is:
38 # aPart = aSession.activeDocument()
39 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
40 aPart = aPartResult.partDoc()
41
42 #=========================================================================
43 # Create a sketch circle to revol
44 #=========================================================================
45 aSession.startOperation()
46 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
47 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
48 origin.setValue(0, 0, 0)
49 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
50 dirx.setValue(1, 0, 0)
51 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
52 norm.setValue(0, 0, 1)
53
54 # Create circle
55 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
56 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
57 aCircleRadius = aSketchCircle.real("CircleRadius")
58 anCircleCentr.setValue(0., 0.)
59 aCircleRadius.setValue(30.)
60 aSession.finishOperation()
61
62 # Build shape from sketcher results
63 aCircleSketchResult = aCircleSketchFeature.firstResult()
64 aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape()
65 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt()
66 dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir()
67 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir()
68 aCircleSketchFaces = ShapeList()
69 GeomAlgoAPI_SketchBuilder.createFaces(
70     origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces)
71 assert (len(aCircleSketchFaces) > 0)
72 assert (aCircleSketchFaces[0] is not None)
73
74 #=========================================================================
75 # Create a sketch line to revol
76 #=========================================================================
77 aSession.startOperation()
78 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
79 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
80 origin.setValue(0, 0, 0)
81 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
82 dirx.setValue(1, 0, 0)
83 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
84 norm.setValue(0, 0, 1)
85
86 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
87 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
88 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
89 aLineStartPoint.setValue(-100., -100.)
90 aLineEndPoint.setValue(100., -100.)
91 aSession.finishOperation()
92
93 # Build shape from sketcher results
94 aLineSketchResult = aLineSketchFeature.firstResult()
95 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
96 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
97 aLineEdge = aShapeExplorer.current()
98
99 #=========================================================================
100 # Test revol between from and to angles
101 #=========================================================================
102 aSession.startOperation()
103 aRevolFt = aPart.addFeature("Revolution")
104 assert (aRevolFt.getKind() == "Revolution")
105 # selection type FACE=4
106 aRevolFt.selectionList("base").append(
107     aCircleSketchResult, aCircleSketchFaces[0])
108 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
109 aRevolFt.real("from_angle").setValue(10)
110 aRevolFt.real("to_angle").setValue(10)
111 aRevolFt.execute()
112 aSession.finishOperation()
113 assert (aRevolFt.real("from_angle").value() == 10.0)
114 assert (aRevolFt.real("to_angle").value() == 10.0)
115
116 # Check revol results
117 assert (len(aRevolFt.results()) > 0)
118 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
119 assert (aRevolResult is not None)
120