Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusionFuse_ByPlanesAndOffsets.py
1 ## Copyright (C) 2018-20xx  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 from salome.shaper import model
22 from GeomAPI import *
23 from SketchAPI import *
24
25 import math
26
27 def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7):
28     assert(shape is not None)
29     middlePoint = shape.middlePoint()
30     assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x)
31     assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y)
32     assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z)
33
34 model.begin()
35 partSet = model.moduleDocument()
36 Part_1 = model.addPart(partSet)
37 Part_1_doc = Part_1.document()
38 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
39 Axis_4 = model.addAxis(Part_1_doc, 10, 10, 10)
40
41 ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [], model.selection("FACE", "Box_1_1/Right"), 0, model.selection(), 0, [model.selection("SOLID", "Box_1_1")])
42 Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left"))
43 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False)
44 SketchLine_1 = SketchProjection_1.createdFeature()
45 SketchCircle_1 = Sketch_1.addCircle(5, 10, 2)
46 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center())
47 ExtrusionFuse_1.setNestedSketch(Sketch_1)
48 model.do()
49 Shape = ExtrusionFuse_1.results()[0].resultSubShapePair()[0].shape()
50 checkMiddlePoint(Shape, 5, 5, 5.421244124)
51
52 ExtrusionFuse_2 = model.addExtrusionFuse(Part_1_doc, [], model.selection("EDGE", "Axis_1"), model.selection(), 0, model.selection("FACE", "ExtrusionFuse_1_1/Modified_Face&Box_1_1/Left&ExtrusionFuse_1_1/From_Face"), 0, [model.selection("SOLID", "ExtrusionFuse_1_1")])
53 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Front"))
54 SketchCircle_2 = Sketch_2.addCircle(10, 10, 2.040695131136049)
55 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "[(Box_1_1/Back)(Box_1_1/Bottom)(Box_1_1/Front)(ExtrusionFuse_1_1/Modified_Face&Box_1_1/Right&ExtrusionFuse_1_1/To_Face)][Box_1_1/Bottom][Box_1_1/Front]"), False)
56 SketchPoint_1 = SketchProjection_2.createdFeature()
57 SketchConstraintCoincidence_2 = Sketch_2.setCoincident(SketchCircle_2.center(), SketchAPI_Point(SketchPoint_1).coordinates())
58 ExtrusionFuse_2.setNestedSketch(Sketch_2)
59 model.do()
60 Shape = ExtrusionFuse_2.results()[0].resultSubShapePair()[0].shape()
61 checkMiddlePoint(Shape, 4.88886637164, 4.89804988224, 2.94104936673)
62
63 model.end()
64
65 assert(model.checkPythonDump())