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