1 # Copyright (C) 2020-2023 CEA, EDF
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 email : webmaster.salome@opencascade.com
20 from SketchAPI import *
22 from salome.shaper import model
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
29 LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2)
30 LinearCopy_2 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPOUND", "LinearCopy_1_1")], model.selection("EDGE", "PartSet/OY"), 20, 2)
31 Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
32 SketchEllipse_1 = Sketch_1.addEllipse(11.18033988749894, -50, 22.36067977499789, -50, 10)
33 [SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_1, SketchLine_2] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
34 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
35 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30)
36 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20)
37 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
38 SketchLine_3 = SketchProjection_1.createdFeature()
39 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_3.result())
40 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 50, True)
41 SketchCircle_1 = Sketch_1.addCircle(41.18033988749897, -50, 5)
42 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.result())
43 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipse_1.majorAxisPositive(), SketchCircle_1.center(), 15, True)
44 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5)
45 SketchMultiRotation_1 = Sketch_1.addRotation([SketchEllipse_1.result(), SketchCircle_1.results()[1]], SketchAPI_Point(SketchPoint_3).coordinates(), 360, 3, True)
46 [SketchEllipse_2, SketchEllipse_3, SketchCircle_2, SketchCircle_3] = SketchMultiRotation_1.rotated()
48 Sketch_1.changeFacesOrder([[SketchEllipse_1.result(), SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()],
49 [SketchCircle_1.results()[1]],
50 [SketchEllipse_2.result(), SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_1.result()],
51 [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()],
52 [SketchEllipse_3.result(), SketchEllipse_2.result(), SketchEllipse_1.result()],
53 [SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()],
54 [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()],
55 [SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_3.result(), SketchEllipse_1.result()],
56 [SketchCircle_2.results()[1]],
57 [SketchCircle_3.results()[1]]
60 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0)
61 Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Extrusion_1_2"), model.selection("SOLID", "Extrusion_1_3")])
62 Compound_2_objects = [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPOUND", "Compound_1_1"), model.selection("SOLID", "Extrusion_1_4")]
63 Compound_2 = model.addCompound(Part_1_doc, Compound_2_objects)
64 Placement_1 = model.addPlacement(Part_1_doc, [model.selection("SOLID", "LinearCopy_2_1_1_1")], model.selection("FACE", "LinearCopy_2_1_1_1/MF:Translated&Cylinder_1_1/Face_2"), model.selection("FACE", "Compound_2_1_2_1/Modified_Face&Extrusion_1_2/To_Face"), centering = True, keepSubResults = True)
70 model.testNbResults(Placement_1, 1)
71 model.testNbSubResults(Placement_1, [2])
72 model.testNbSubShapes(Placement_1, GeomAPI_Shape.SOLID, [4])
73 model.testNbSubShapes(Placement_1, GeomAPI_Shape.FACE, [12])
74 model.testNbSubShapes(Placement_1, GeomAPI_Shape.EDGE, [24])
75 model.testNbSubShapes(Placement_1, GeomAPI_Shape.VERTEX, [48])
76 model.testResultsVolumes(Placement_1, [3141.592653589793])
79 REF_C = GeomAPI_Pnt(20.590169943749483, -15, 10)
80 midPoint = Placement_1.defaultResult().shape().middlePoint()
81 assert(midPoint.distance(REF_C) < TOLERANCE)
83 REF_SUB = [GeomAPI_Pnt(30.590169943749483, -25, 10), GeomAPI_Pnt(10, 20, 5)]
84 for ind in range(0, len(REF_SUB)):
85 midPoint = Placement_1.result().subResult(ind).resultSubShapePair()[0].shape().middlePoint()
86 assert(midPoint.distance(REF_SUB[ind]) < TOLERANCE)
88 assert(model.checkPythonDump())