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