]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/Test/Test1064.py
Salome HOME
e4fb9291cad09331ec3d176bd0cb67ad3dc2dcb6
[modules/shaper.git] / src / ModelAPI / Test / Test1064.py
1 """
2       Test1064.py
3       Unit test for testing the Part sub-shapes naming, described in the issue 1064
4       
5 """
6 #=========================================================================
7 # Initialization of the test
8 #=========================================================================
9 from ModelAPI import *
10 from GeomDataAPI import *
11 from GeomAlgoAPI import *
12
13 __updated__ = "2015-10-16"
14
15 aSession = ModelAPI_Session.get()
16
17 #=========================================================================
18 # Create a sketch triangle in PartSet
19 #=========================================================================
20 aPartSet = aSession.moduleDocument()
21 aSession.startOperation()
22 aSketchFeature = featureToCompositeFeature(aPartSet.addFeature("Sketch"))
23 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
24 origin.setValue(0, 0, 0)
25 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
26 dirx.setValue(1, 0, 0)
27 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
28 norm.setValue(0, 0, 1)
29 # Create lines
30 aLine1 = aSketchFeature.addFeature("SketchLine")
31 geomDataAPI_Point2D(aLine1.attribute("StartPoint")).setValue(0, 0)
32 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(200, 0)
33 aLine2 = aSketchFeature.addFeature("SketchLine")
34 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(200, 0)
35 geomDataAPI_Point2D(aLine2.attribute("EndPoint")).setValue(0, 200)
36 aLine3 = aSketchFeature.addFeature("SketchLine")
37 geomDataAPI_Point2D(aLine3.attribute("StartPoint")).setValue(0, 200)
38 geomDataAPI_Point2D(aLine3.attribute("EndPoint")).setValue(0, 0)
39 aSession.finishOperation()
40
41 #=========================================================================
42 # Create a part
43 #=========================================================================
44 aSession.startOperation()
45 aPartFeature = aPartSet.addFeature("Part")
46 aSession.finishOperation()
47 assert (len(aPartFeature.results()) == 1)
48 aPart = aSession.activeDocument()
49
50 #=========================================================================
51 # Make extrusion on triangle
52 #=========================================================================
53 aSketchResult = aSketchFeature.firstResult()
54 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
55 aSketchFaces = ShapeList()
56 GeomAlgoAPI_SketchBuilder.createFaces(
57     origin.pnt(), dirx.dir(), norm.dir(), aSketchEdges, aSketchFaces)
58 aSession.startOperation()
59 anExtrusionFt = aPart.addFeature("Extrusion")
60 anExtrusionFt.selectionList("base").append(aSketchResult, aSketchFaces[0])
61 anExtrusionFt.string("CreationMethod").setValue("BySizes")
62 anExtrusionFt.real("to_size").setValue(50)
63 anExtrusionFt.real("from_size").setValue(0)
64 aSession.finishOperation()
65
66
67 #=========================================================================
68 # Make a plane in PartSet on lateral face of the Extrusion
69 #=========================================================================
70 aSession.startOperation()
71 aSession.setActiveDocument(aPartSet)
72 aPlane = aPartSet.addFeature("Plane")
73 aPlane.string("CreationMethod").setValue("PlaneByFaceAndDistance")
74 aPlane.real("distance").setValue(0)
75 aPlane.selection("planeFace").selectSubShape("face", "Part_1/Extrusion_1_1/LateralFace_3")
76 aSession.finishOperation()
77
78 #=========================================================================
79 # Update the sketch edges in order to update the plane on the lateral face automatically
80 #=========================================================================
81 aSession.startOperation()
82 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(400, 0)
83 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(400, 0)
84 aSession.finishOperation()
85
86 #=========================================================================
87 # Check that the plane is also updated
88 #=========================================================================
89
90 assert(len(aPlane.results()) > 0)
91 aShape = aPlane.firstResult().shape()
92 aFace = GeomAPI_Face(aShape)
93 assert(aFace.isPlanar())
94 aPln = aFace.getPlane()
95 # Must be 0.4472135955, 0.894427191, 0.0
96 assert(aPln.direction().x() > 0.44)
97 assert(aPln.direction().x() < 0.45)
98 assert(aPln.direction().y() > 0.89)
99 assert(aPln.direction().y() < 0.90)
100 assert(aPln.direction().z() == 0.)
101
102 #=========================================================================
103 # End of test
104 #=========================================================================