1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## Lesser General Public License for more details.
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
23 Unit test for testing the Part sub-shapes naming, described in the issue 1064
26 #=========================================================================
27 # Initialization of the test
28 #=========================================================================
29 from ModelAPI import *
30 from GeomDataAPI import *
31 from GeomAlgoAPI import *
34 __updated__ = "2015-10-16"
36 aSession = ModelAPI_Session.get()
38 #=========================================================================
39 # Create a sketch triangle in PartSet
40 #=========================================================================
41 aPartSet = aSession.moduleDocument()
42 aSession.startOperation()
43 aSketchFeature = featureToCompositeFeature(aPartSet.addFeature("Sketch"))
44 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
45 origin.setValue(0, 0, 0)
46 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
47 dirx.setValue(1, 0, 0)
48 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
49 norm.setValue(0, 0, 1)
51 aLine1 = aSketchFeature.addFeature("SketchLine")
52 geomDataAPI_Point2D(aLine1.attribute("StartPoint")).setValue(0, 0)
53 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(200, 0)
54 aLine2 = aSketchFeature.addFeature("SketchLine")
55 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(200, 0)
56 geomDataAPI_Point2D(aLine2.attribute("EndPoint")).setValue(0, 200)
57 aLine3 = aSketchFeature.addFeature("SketchLine")
58 geomDataAPI_Point2D(aLine3.attribute("StartPoint")).setValue(0, 200)
59 geomDataAPI_Point2D(aLine3.attribute("EndPoint")).setValue(0, 0)
60 aSession.finishOperation()
62 #=========================================================================
64 #=========================================================================
65 aSession.startOperation()
66 aPartFeature = aPartSet.addFeature("Part")
67 aSession.finishOperation()
68 assert (len(aPartFeature.results()) == 1)
69 aPart = aSession.activeDocument()
71 #=========================================================================
72 # Make extrusion on triangle
73 #=========================================================================
74 aSketchResult = aSketchFeature.firstResult()
75 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
76 aSketchFaces = ShapeList()
77 GeomAlgoAPI_SketchBuilder.createFaces(
78 origin.pnt(), dirx.dir(), norm.dir(), aSketchEdges, aSketchFaces)
79 aSession.startOperation()
80 anExtrusionFt = aPart.addFeature("Extrusion")
81 anExtrusionFt.selectionList("base").append(aSketchResult, aSketchFaces[0])
82 anExtrusionFt.string("CreationMethod").setValue("BySizes")
83 anExtrusionFt.real("to_size").setValue(50)
84 anExtrusionFt.real("from_size").setValue(0)
85 aSession.finishOperation()
88 #=========================================================================
89 # Make a plane in PartSet on lateral face of the Extrusion
90 #=========================================================================
91 aSession.startOperation("Make Plane")
92 aSession.setActiveDocument(aPartSet)
93 aPlane = aPartSet.addFeature("Plane")
94 aPlane.string("creation_method").setValue("by_other_plane")
95 aPlane.string("by_other_plane_option").setValue("by_distance_from_other")
96 aPlane.selection("plane").selectSubShape("face", "Part_1/Extrusion_1_1/Generated_Face_2")
97 aPlane.real("distance").setValue(0.001)
98 aPlane.boolean("reverse").setValue(False)
99 aSession.finishOperation()
101 #=========================================================================
102 # Update the sketch edges in order to update the plane on the lateral face automatically
103 #=========================================================================
104 aSession.startOperation("UpdateLine")
105 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(400, 0)
106 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(400, 0)
107 aSession.finishOperation()
109 #=========================================================================
110 # Check that the plane is also updated
111 #=========================================================================
113 assert(len(aPlane.results()) > 0)
114 aShape = aPlane.firstResult().shape()
115 aFace = GeomAPI_Face(aShape)
116 assert(aFace.isPlanar())
117 aPln = aFace.getPlane()
118 # Must be 0.4472135955, 0.894427191, 0.0
119 assert(aPln.direction().x() > 0.44)
120 assert(aPln.direction().x() < 0.45)
121 assert(aPln.direction().y() > 0.89)
122 assert(aPln.direction().y() < 0.90)
123 assert(aPln.direction().z() == 0.)
125 #=========================================================================
127 #=========================================================================
129 from salome.shaper import model
130 assert(model.checkPythonDump())