]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/Test/TestRevolutionSketch.py
Salome HOME
Tests for ExtrusionSketch and RevolutionSketch
[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 anRevolutionSketchFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
66 anRevolutionSketchFt.string("CreationMethod").setValue("ByAngles")
67 anRevolutionSketchFt.real("to_angle").setValue(50)
68 anRevolutionSketchFt.real("from_angle").setValue(50)
69 anRevolutionSketchFt.real("to_offset").setValue(0) #TODO: remove
70 anRevolutionSketchFt.real("from_offset").setValue(0) #TODO: remove
71 anRevolutionSketchFt.execute()
72 aSession.finishOperation()
73
74 #=========================================================================
75 # Test results
76 #=========================================================================
77 aFactory = ModelAPI_Session.get().validators()
78 assert (aFactory.validate(anRevolutionSketchFt))
79 assert (len(anRevolutionSketchFt.results()) > 0)
80 aCurrentResult = modelAPI_ResultBody(anRevolutionSketchFt.firstResult())
81 assert (aCurrentResult is not None)
82
83 #=========================================================================
84 # Test revolution between bounding planes
85 #=========================================================================
86 # Create from plane
87 aSession.startOperation()
88 aSketchPlaneFeature = aPart.addFeature("Plane")
89 aSketchPlaneFeature.string("CreationMethod").setValue("PlaneByGeneralEquation")
90 aSketchPlaneFeature.real("A").setValue(0.)
91 aSketchPlaneFeature.real("B").setValue(0.)
92 aSketchPlaneFeature.real("C").setValue(1.)
93 aSketchPlaneFeature.real("D").setValue(15.)
94 aSession.finishOperation()
95 aFromResult = aSketchPlaneFeature.firstResult()
96 aFromShape = modelAPI_ResultConstruction(aFromResult).shape()
97
98 # Create to plane
99 aSession.startOperation()
100 aToPlaneFeature = aPart.addFeature("Plane")
101 aToPlaneFeature.string("CreationMethod").setValue("PlaneByGeneralEquation")
102 aToPlaneFeature.real("A").setValue(0.)
103 aToPlaneFeature.real("B").setValue(0.)
104 aToPlaneFeature.real("C").setValue(1.)
105 aToPlaneFeature.real("D").setValue(-15.)
106 aSession.finishOperation()
107 aToResult = aToPlaneFeature.firstResult()
108 aToShape = modelAPI_ResultConstruction(aToResult).shape()
109
110 #=========================================================================
111 # Make revolution sketch
112 #=========================================================================
113 aSession.startOperation()
114 anRevolutionSketchFt = featureToCompositeFeature(aPart.addFeature("RevolutionSketch"))
115 assert (anRevolutionSketchFt.getKind() == "RevolutionSketch")
116 # selection type FACE=4
117 aSession.startOperation()
118 aCircleSketchFeature = featureToCompositeFeature(anRevolutionSketchFt.addFeature("Sketch"))
119 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
120 origin.setValue(0, 0, 0)
121 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
122 dirx.setValue(1, 0, 0)
123 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
124 norm.setValue(0, 0, 1)
125 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
126 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
127 aCircleRadius = aSketchCircle.real("CircleRadius")
128 anCircleCentr.setValue(0, 0)
129 aCircleRadius.setValue(10)
130 aSession.finishOperation()
131 anRevolutionSketchFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
132 anRevolutionSketchFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
133 anRevolutionSketchFt.real("to_angle").setValue(0) #TODO: remove
134 anRevolutionSketchFt.real("from_angle").setValue(0) #TODO: remove
135 anRevolutionSketchFt.selection("to_object").setValue(aToResult, aToShape)
136 anRevolutionSketchFt.real("to_offset").setValue(0)
137 anRevolutionSketchFt.selection("from_object").setValue(aFromResult, aFromShape)
138 anRevolutionSketchFt.real("from_offset").setValue(0)
139 anRevolutionSketchFt.execute()
140 aSession.finishOperation()
141
142 #=========================================================================
143 # Test results
144 #=========================================================================
145 aFactory = ModelAPI_Session.get().validators()
146 assert (aFactory.validate(anRevolutionSketchFt))
147 assert (len(anRevolutionSketchFt.results()) > 0)
148 aCurrentResult = modelAPI_ResultBody(anRevolutionSketchFt.firstResult())
149 assert (aCurrentResult is not None)