Salome HOME
Tests update
[modules/shaper.git] / src / FeaturesPlugin / Test / TestRevolutionSketch.py
1 #=========================================================================
2 # Initialization of the test
3 #=========================================================================
4 from ModelAPI import *
5 from GeomDataAPI import *
6 from GeomAlgoAPI import *
7 from GeomAPI import *
8 import math
9
10 aSession = ModelAPI_Session.get()
11 aDocument = aSession.moduleDocument()
12
13 aSession.startOperation()
14 aPartFeature = aDocument.addFeature("Part")
15 aSession.finishOperation()
16 assert (len(aPartFeature.results()) == 1)
17 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
18 aPart = aPartResult.partDoc()
19
20 #=========================================================================
21 # Create a sketch line to revol
22 #=========================================================================
23 aSession.startOperation()
24 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
25 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
26 origin.setValue(0, 0, 0)
27 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
28 dirx.setValue(1, 0, 0)
29 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
30 norm.setValue(0, 0, 1)
31 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
32 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
33 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
34 aLineStartPoint.setValue(-20, -20)
35 aLineEndPoint.setValue(20, -20)
36 aSession.finishOperation()
37
38 # Build shape from sketcher results
39 aLineSketchResult = aLineSketchFeature.firstResult()
40 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
41 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
42 aLineEdge = aShapeExplorer.current()
43
44 #=========================================================================
45 # Make revolution sketch
46 #=========================================================================
47 aSession.startOperation()
48 anRevolutionSketchFt = featureToCompositeFeature(aPart.addFeature("RevolutionSketch"))
49 assert (anRevolutionSketchFt.getKind() == "RevolutionSketch")
50 # selection type FACE=4
51 aSession.startOperation()
52 aCircleSketchFeature = featureToCompositeFeature(anRevolutionSketchFt.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 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
60 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
61 aCircleRadius = aSketchCircle.real("CircleRadius")
62 anCircleCentr.setValue(0, 0)
63 aCircleRadius.setValue(10)
64 aSession.finishOperation()
65 aSession.startOperation()
66 anRevolutionSketchFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
67 anRevolutionSketchFt.string("CreationMethod").setValue("ByAngles")
68 anRevolutionSketchFt.real("to_angle").setValue(50)
69 anRevolutionSketchFt.real("from_angle").setValue(50)
70 anRevolutionSketchFt.real("to_offset").setValue(0) #TODO: remove
71 anRevolutionSketchFt.real("from_offset").setValue(0) #TODO: remove
72 anRevolutionSketchFt.execute()
73 aSession.finishOperation()
74 aSession.finishOperation()
75
76 #=========================================================================
77 # Test results
78 #=========================================================================
79 aFactory = ModelAPI_Session.get().validators()
80 assert (aFactory.validate(anRevolutionSketchFt))
81 assert (len(anRevolutionSketchFt.results()) > 0)
82 aCurrentResult = modelAPI_ResultBody(anRevolutionSketchFt.firstResult())
83 assert (aCurrentResult is not None)
84
85 #=========================================================================
86 # Test revolution between bounding planes
87 #=========================================================================
88 # Create from plane
89 aSession.startOperation()
90 aSketchPlaneFeature = aPart.addFeature("Plane")
91 aSketchPlaneFeature.string("CreationMethod").setValue("PlaneByGeneralEquation")
92 aSketchPlaneFeature.real("A").setValue(0.)
93 aSketchPlaneFeature.real("B").setValue(0.)
94 aSketchPlaneFeature.real("C").setValue(1.)
95 aSketchPlaneFeature.real("D").setValue(15.)
96 aSession.finishOperation()
97 aFromResult = aSketchPlaneFeature.firstResult()
98 aFromShape = modelAPI_ResultConstruction(aFromResult).shape()
99
100 # Create to plane
101 aSession.startOperation()
102 aToPlaneFeature = aPart.addFeature("Plane")
103 aToPlaneFeature.string("CreationMethod").setValue("PlaneByGeneralEquation")
104 aToPlaneFeature.real("A").setValue(0.)
105 aToPlaneFeature.real("B").setValue(0.)
106 aToPlaneFeature.real("C").setValue(1.)
107 aToPlaneFeature.real("D").setValue(-15.)
108 aSession.finishOperation()
109 aToResult = aToPlaneFeature.firstResult()
110 aToShape = modelAPI_ResultConstruction(aToResult).shape()
111
112 #=========================================================================
113 # Make revolution sketch
114 #=========================================================================
115 aSession.startOperation()
116 anRevolutionSketchFt = featureToCompositeFeature(aPart.addFeature("RevolutionSketch"))
117 assert (anRevolutionSketchFt.getKind() == "RevolutionSketch")
118 # selection type FACE=4
119 aSession.startOperation()
120 aCircleSketchFeature = featureToCompositeFeature(anRevolutionSketchFt.addFeature("Sketch"))
121 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
122 origin.setValue(0, 0, 0)
123 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
124 dirx.setValue(1, 0, 0)
125 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
126 norm.setValue(0, 0, 1)
127 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
128 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
129 aCircleRadius = aSketchCircle.real("CircleRadius")
130 anCircleCentr.setValue(0, 0)
131 aCircleRadius.setValue(10)
132 aSession.finishOperation()
133 aSession.startOperation()
134 anRevolutionSketchFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
135 anRevolutionSketchFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
136 anRevolutionSketchFt.real("to_angle").setValue(0) #TODO: remove
137 anRevolutionSketchFt.real("from_angle").setValue(0) #TODO: remove
138 anRevolutionSketchFt.selection("to_object").setValue(aToResult, aToShape)
139 anRevolutionSketchFt.real("to_offset").setValue(0)
140 anRevolutionSketchFt.selection("from_object").setValue(aFromResult, aFromShape)
141 anRevolutionSketchFt.real("from_offset").setValue(0)
142 anRevolutionSketchFt.execute()
143 aSession.finishOperation()
144 aSession.finishOperation()
145
146 #=========================================================================
147 # Test results
148 #=========================================================================
149 aFactory = ModelAPI_Session.get().validators()
150 assert (aFactory.validate(anRevolutionSketchFt))
151 assert (len(anRevolutionSketchFt.results()) > 0)
152 aCurrentResult = modelAPI_ResultBody(anRevolutionSketchFt.firstResult())
153 assert (aCurrentResult is not None)