Salome HOME
Adjust test cases according to redesigned Arc and Circle features
[modules/shaper.git] / src / FeaturesPlugin / Test / TestPipe.py
1 # Initialization of the test
2 from ModelAPI import *
3 from GeomDataAPI import *
4 from GeomAlgoAPI import *
5 from GeomAPI import *
6
7 # Get document
8 aSession = ModelAPI_Session.get()
9 aDocument = aSession.moduleDocument()
10
11 # Create a part
12 aSession.startOperation()
13 aPartFeature = aDocument.addFeature("Part")
14 aSession.finishOperation()
15 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
16 aPart = aPartResult.partDoc()
17
18 # Create a sketch with circle for pipe profile
19 aSession.startOperation()
20 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
21 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
22 origin.setValue(0, 0, 0)
23 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
24 dirx.setValue(1, 0, 0)
25 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
26 norm.setValue(0, 0, 1)
27
28 # Create circle
29 aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
30 anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("circle_center"))
31 aCircleRadius = aSketchCircleFeature.real("circle_radius")
32 anCircleCentr.setValue(0, 0)
33 aCircleRadius.setValue(10)
34 aSession.finishOperation()
35 aSketchResult = aSketchFeature.firstResult()
36 aSketchShape = aSketchResult.shape()
37
38 # Create face
39 aSession.startOperation()
40 aFaceFeature = aPart.addFeature("Face")
41 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
42 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
43 while aShapeExplorer.more():
44     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
45     aShapeExplorer.next()
46 aSession.finishOperation()
47 aFaceResult1 = aFaceFeature.firstResult()
48
49 # Create a sketch with edges for pipe path
50 aSession.startOperation()
51 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
52 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
53 origin.setValue(0, 0, 0)
54 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
55 dirx.setValue(1, 0, 0)
56 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
57 norm.setValue(0, -1, 0)
58
59 # Create line
60 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
61 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
62 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
63 aSketchLineStartPoint.setValue(0, 0)
64 aSketchLineEndPoint.setValue(0, 200)
65
66 # Create arc
67 aSketchArcFeature = aSketchFeature.addFeature("SketchArc")
68 aSketchArcCenterPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("center_point"))
69 aSketchArcStartPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("start_point"))
70 aSketchArcEndPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("end_point"))
71 aSketchArcCenterPoint.setValue(100, 200)
72 aSketchArcStartPoint.setValue(200, 200)
73 aSketchArcEndPoint.setValue(0, 200)
74
75 aSession.finishOperation()
76 aSketchResult = aSketchFeature.firstResult()
77 aSketchShape = aSketchResult.shape()
78
79 # Create wire
80 aSession.startOperation()
81 aWireFeature = aPart.addFeature("Wire")
82 aBaseObjectsList = aWireFeature.selectionList("base_objects")
83 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
84 while aShapeExplorer.more():
85     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
86     aShapeExplorer.next()
87 aSession.finishOperation()
88 aWireResult = aWireFeature.firstResult()
89
90 # Create simple pipe
91 aSession.startOperation()
92 aPipeFeature = aPart.addFeature("Pipe")
93 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
94 aBaseObjectsList.append(aFaceResult1, None)
95 aPathObjectSelection = aPipeFeature.selection("path_object")
96 aPathObjectSelection.setValue(aWireResult, None)
97 aPipeFeature.string("creation_method").setValue("simple")
98 aSession.finishOperation()
99
100 # Test results
101 assert (len(aPipeFeature.results()) > 0)
102 # aSession.undo()
103
104 # Create pipe with bi-normal
105 aSession.startOperation()
106 aPipeFeature = aPart.addFeature("Pipe")
107 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
108 aBaseObjectsList.append(aFaceResult1, None)
109 aPathObjectSelection = aPipeFeature.selection("path_object")
110 aPathObjectSelection.setValue(aWireResult, None)
111 aPipeFeature.string("creation_method").setValue("binormal")
112 aBinormalObjectSelection = aPipeFeature.selection("binormal")
113 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
114 aBinormalObjectSelection.setValue(aSketchResult, aShapeExplorer.current())
115 aSession.finishOperation()
116
117 # Test results
118 assert (len(aPipeFeature.results()) > 0)
119 # aSession.undo()
120
121 # Create pipe with locations
122 # Create a sketch with circle for pipe profile
123 aSession.startOperation()
124 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
125 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
126 origin.setValue(0, 0, 200)
127 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
128 dirx.setValue(1, 0, 0)
129 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
130 norm.setValue(0, 0, 1)
131
132 # Create circle
133 aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
134 anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("circle_center"))
135 aCircleRadius = aSketchCircleFeature.real("circle_radius")
136 anCircleCentr.setValue(0, 0)
137 aCircleRadius.setValue(20)
138 aSession.finishOperation()
139 aSketchResult = aSketchFeature.firstResult()
140 aSketchShape = aSketchResult.shape()
141
142 # Create face
143 aSession.startOperation()
144 aFaceFeature = aPart.addFeature("Face")
145 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
146 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
147 while aShapeExplorer.more():
148     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
149     aShapeExplorer.next()
150 aSession.finishOperation()
151 aFaceResult2 = aFaceFeature.firstResult()
152
153 aSession.startOperation()
154 aPipeFeature = aPart.addFeature("Pipe")
155 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
156 aBaseObjectsList.append(aFaceResult1, None)
157 aBaseObjectsList.append(aFaceResult2, None)
158 aPathObjectSelection = aPipeFeature.selection("path_object")
159 aPathObjectSelection.setValue(aWireResult, None)
160 aPipeFeature.string("creation_method").setValue("locations")
161 aSession.finishOperation()
162
163 # Test results
164 assert (len(aPipeFeature.results()) > 0)
165
166 from salome.shaper import model
167 assert(model.checkPythonDump())