Salome HOME
Resolve batch runtime errors on debian squeeze
[modules/shaper.git] / src / FeaturesPlugin / Test / TestGroup.py
1 """
2       TestBoolean.py
3       Unit test of FeaturesPlugin_Group class
4       
5       class FeaturesPlugin_Group
6         static const std::string MY_GROUP_ID("Group");
7         static const std::string MY_GROUP_LIST_ID("group_list");
8         
9         data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
10 """
11 #=========================================================================
12 # Initialization of the test
13 #=========================================================================
14 from ModelAPI import *
15 from GeomDataAPI import *
16 from GeomAlgoAPI import *
17 from GeomAPI import *
18
19 __updated__ = "2014-12-16"
20
21 aSession = ModelAPI_Session.get()
22 # Create a part for extrusions & boolean
23 aSession.startOperation()
24 aPartFeature = aSession.moduleDocument().addFeature("Part")
25 aPart = aSession.activeDocument()
26 aSession.finishOperation()
27 #=========================================================================
28 # Create a sketch with triangle and extrude it
29 #=========================================================================
30 aSession.startOperation()
31 aTriangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
32 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
33 origin.setValue(0, 0, 0)
34 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
35 dirx.setValue(1, 0, 0)
36 diry = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirY"))
37 diry.setValue(0, 1, 0)
38 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
39 norm.setValue(0, 0, 1)
40 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
41 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
42 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
43 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
44 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
45 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
46 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
47 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
48 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
49 aLineAStartPoint.setValue(25., 25.)
50 aLineAEndPoint.setValue(100., 25.)
51 aLineBStartPoint.setValue(100., 25.)
52 aLineBEndPoint.setValue(60., 75.)
53 aLineCStartPoint.setValue(60., 75.)
54 aLineCEndPoint.setValue(25., 25.)
55 aSession.finishOperation()
56 # Build sketch faces
57 aSession.startOperation()
58 aSketchResult = aTriangleSketchFeature.firstResult()
59 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
60 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin")).pnt()
61 dirX = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX")).dir()
62 dirY = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirY")).dir()
63 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm")).dir()
64 aSketchFaces = ShapeList()
65 GeomAlgoAPI_SketchBuilder.createFaces(
66     origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
67 # Create extrusion on them
68 anExtrusionFt = aPart.addFeature("Extrusion")
69 anExtrusionFt.selection("extrusion_face").setValue(
70     aSketchResult, aSketchFaces[0])
71 anExtrusionFt.real("extrusion_size").setValue(50)
72 anExtrusionFt.boolean("extrusion_reverse").setValue(False)
73 anExtrusionFt.execute()
74 aSession.finishOperation()
75 anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
76 #=========================================================================
77 # Create group of edges
78 # TODO: After implementation of selection from batch script
79 # update this test to have proper reslts in the group feature
80 #=========================================================================
81 aSession.startOperation()
82 aGroupFeature = aSession.activeDocument().addFeature("Group")
83 aSelectionListAttr = aGroupFeature.selectionList("group_list")
84 topAbs_EdgeType = 6
85 aSelectionListAttr.setSelectionType(topAbs_EdgeType)
86 aSelectionListAttr.append("Extrusion_1/LateralFace_3|Extrusion_1/LateralFace_1")
87 aSession.finishOperation()
88 #=========================================================================
89 # Check results
90 #=========================================================================
91 aGroupResult = aGroupFeature.firstResult()
92 assert(aGroupResult)
93 #=========================================================================
94 # End of test
95 #=========================================================================