Salome HOME
de049e25cf1439b20c63d189d1d445a73daf0b7e
[modules/shaper.git] / src / ModelAPI / Test / Test1064.py
1 # Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 """
21       Test1064.py
22       Unit test for testing the Part sub-shapes naming, described in the issue 1064
23
24 """
25 #=========================================================================
26 # Initialization of the test
27 #=========================================================================
28 from ModelAPI import *
29 from GeomDataAPI import *
30 from GeomAlgoAPI import *
31 from GeomAPI import *
32
33 __updated__ = "2015-10-16"
34
35 aSession = ModelAPI_Session.get()
36
37 #=========================================================================
38 # Create a sketch triangle in PartSet
39 #=========================================================================
40 aPartSet = aSession.moduleDocument()
41 aSession.startOperation()
42 aSketchFeature = featureToCompositeFeature(aPartSet.addFeature("Sketch"))
43 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
44 origin.setValue(0, 0, 0)
45 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
46 dirx.setValue(1, 0, 0)
47 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
48 norm.setValue(0, 0, 1)
49 # Create lines
50 aLine1 = aSketchFeature.addFeature("SketchLine")
51 geomDataAPI_Point2D(aLine1.attribute("StartPoint")).setValue(0, 0)
52 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(200, 0)
53 aLine2 = aSketchFeature.addFeature("SketchLine")
54 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(200, 0)
55 geomDataAPI_Point2D(aLine2.attribute("EndPoint")).setValue(0, 200)
56 aLine3 = aSketchFeature.addFeature("SketchLine")
57 geomDataAPI_Point2D(aLine3.attribute("StartPoint")).setValue(0, 200)
58 geomDataAPI_Point2D(aLine3.attribute("EndPoint")).setValue(0, 0)
59 aSession.finishOperation()
60
61 #=========================================================================
62 # Create a part
63 #=========================================================================
64 aSession.startOperation()
65 aPartFeature = aPartSet.addFeature("Part")
66 aSession.finishOperation()
67 assert (len(aPartFeature.results()) == 1)
68 aPart = aSession.activeDocument()
69
70 #=========================================================================
71 # Make extrusion on triangle
72 #=========================================================================
73 aSketchResult = modelAPI_ResultConstruction(aSketchFeature.firstResult())
74 aSession.startOperation()
75 anExtrusionFt = aPart.addFeature("Extrusion")
76 anExtrusionFt.selectionList("base").append(aSketchResult, aSketchResult.face(0))
77 anExtrusionFt.string("CreationMethod").setValue("BySizes")
78 anExtrusionFt.real("to_size").setValue(50)
79 anExtrusionFt.real("from_size").setValue(0)
80 aSession.finishOperation()
81
82
83 #=========================================================================
84 # Make a plane in PartSet on lateral face of the Extrusion
85 #=========================================================================
86 aSession.startOperation("Make Plane")
87 aSession.setActiveDocument(aPartSet)
88 aPlane = aPartSet.addFeature("Plane")
89 aPlane.string("creation_method").setValue("by_other_plane")
90 aPlane.string("by_other_plane_option").setValue("by_distance_from_other")
91 aPlane.selection("plane").selectSubShape("face", "Part_1/_weak_name_5_Extrusion_1_1")
92 aPlane.real("distance").setValue(0.001)
93 aPlane.boolean("reverse").setValue(False)
94 aSession.finishOperation()
95
96 #=========================================================================
97 # Update the sketch edges in order to update the plane on the lateral face automatically
98 #=========================================================================
99 aSession.startOperation("UpdateLine")
100 geomDataAPI_Point2D(aLine1.attribute("EndPoint")).setValue(400, 0)
101 geomDataAPI_Point2D(aLine2.attribute("StartPoint")).setValue(400, 0)
102 aSession.finishOperation()
103
104 #=========================================================================
105 # Check that the plane is also updated
106 #=========================================================================
107
108 assert(len(aPlane.results()) > 0)
109 aShape = aPlane.firstResult().shape()
110 aFace = GeomAPI_Face(aShape)
111 assert(aFace.isPlanar())
112 aPln = aFace.getPlane()
113 # Must be 0.4472135955, 0.894427191, 0.0
114 assert(aPln.direction().x() > 0.44)
115 assert(aPln.direction().x() < 0.45)
116 assert(aPln.direction().y() > 0.89)
117 assert(aPln.direction().y() < 0.90)
118 assert(aPln.direction().z() == 0.)
119
120 #=========================================================================
121 # End of test
122 #=========================================================================
123
124 from salome.shaper import model
125 assert(model.checkPythonDump())