Salome HOME
Issue #803: Put all the python modules in the same python package newgeom
[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 from GeomAPI import *
13
14 __updated__ = "2015-10-16"
15
16 aSession = ModelAPI_Session.get()
17
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)
30 # Create lines
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()
41
42 #=========================================================================
43 # Create a part
44 #=========================================================================
45 aSession.startOperation()
46 aPartFeature = aPartSet.addFeature("Part")
47 aSession.finishOperation()
48 assert (len(aPartFeature.results()) == 1)
49 aPart = aSession.activeDocument()
50
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()
66
67
68 #=========================================================================
69 # Make a plane in PartSet on lateral face of the Extrusion
70 #=========================================================================
71 aSession.startOperation("Make Plane")
72 aSession.setActiveDocument(aPartSet)
73 aPlane = aPartSet.addFeature("Plane")
74 aPlane.string("creation_method").setValue("by_other_plane")
75 aPlane.string("by_other_plane_option").setValue("by_distance_from_other")
76 aPlane.selection("plane").selectSubShape("face", "Part_1/Extrusion_1_1/Generated_Face_3")
77 aPlane.real("distance").setValue(0.001)
78 aPlane.boolean("reverse").setValue(False)
79 aSession.finishOperation()
80
81 #=========================================================================
82 # Update the sketch edges in order to update the plane on the lateral face automatically
83 #=========================================================================
84 aSession.startOperation("UpdateLine")
85 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(400, 0)
86 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(400, 0)
87 aSession.finishOperation()
88
89 #=========================================================================
90 # Check that the plane is also updated
91 #=========================================================================
92
93 assert(len(aPlane.results()) > 0)
94 aShape = aPlane.firstResult().shape()
95 aFace = GeomAPI_Face(aShape)
96 assert(aFace.isPlanar())
97 aPln = aFace.getPlane()
98 # Must be 0.4472135955, 0.894427191, 0.0
99 assert(aPln.direction().x() > 0.44)
100 assert(aPln.direction().x() < 0.45)
101 assert(aPln.direction().y() > 0.89)
102 assert(aPln.direction().y() < 0.90)
103 assert(aPln.direction().z() == 0.)
104
105 #=========================================================================
106 # End of test
107 #=========================================================================
108
109 from salome.shaper import model
110 assert(model.checkPythonDump())