1 # Copyright (C) 2020 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 email : webmaster.salome@opencascade.com
20 from salome.shaper import model
23 from SketchAPI import *
26 partSet = model.moduleDocument()
27 Part_1 = model.addPart(partSet)
28 Part_1_doc = Part_1.document()
29 Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
30 SketchEllipse_1 = Sketch_1.addEllipse(11.18033988749894, -50, 22.36067977499789, -50, 10)
31 [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")
32 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
33 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30)
34 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20)
35 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
36 SketchLine_3 = SketchProjection_1.createdFeature()
37 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_3.result())
38 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 50, True)
39 SketchCircle_1 = Sketch_1.addCircle(41.18033988749897, -50, 5)
40 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.result())
41 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipse_1.majorAxisPositive(), SketchCircle_1.center(), 15, True)
42 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5)
43 SketchMultiRotation_1 = Sketch_1.addRotation([SketchEllipse_1.result(), SketchCircle_1.results()[1]], SketchAPI_Point(SketchPoint_3).coordinates(), 360, 3, True)
44 [SketchEllipse_2, SketchEllipse_3, SketchCircle_2, SketchCircle_3] = SketchMultiRotation_1.rotated()
46 Sketch_1.changeFacesOrder([[SketchEllipse_1.result(), SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()],
47 [SketchCircle_1.results()[1]],
48 [SketchEllipse_2.result(), SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_1.result()],
49 [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()],
50 [SketchEllipse_3.result(), SketchEllipse_2.result(), SketchEllipse_1.result()],
51 [SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()],
52 [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()],
53 [SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_3.result(), SketchEllipse_1.result()],
54 [SketchCircle_2.results()[1]],
55 [SketchCircle_3.results()[1]]
58 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0)
59 Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Extrusion_1_2"), model.selection("SOLID", "Extrusion_1_3")])
60 Compound_2_objects = [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPOUND", "Compound_1_1"), model.selection("SOLID", "Extrusion_1_4")]
61 Compound_2 = model.addCompound(Part_1_doc, Compound_2_objects)
68 def subsRefPoints(theResult):
70 for ind in range(0, theResult.numberOfSubs()):
71 res.append( theResult.subResult(ind).resultSubShapePair()[0].shape().middlePoint())
74 REFERENCE = subsRefPoints(Compound_2.result())
76 def assertResult(theFeature, theNbSolids, theNbFaces, theNbEdges, theNbVertices, theVolume):
77 model.testNbResults(theFeature, 1)
78 model.testNbSubResults(theFeature, [3])
79 model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [theNbSolids])
80 model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [theNbFaces])
81 model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [theNbEdges])
82 model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [theNbVertices])
83 model.testResultsVolumes(theFeature, [theVolume])
85 for ind in range(0, theFeature.result().numberOfSubs()):
87 midPoint = theFeature.result().subResult(ind).resultSubShapePair()[0].shape().middlePoint()
88 assert(midPoint.distance(ref) < TOLERANCE), "Sub-result {}; actual ({}, {}, {}) != expected ({}, {}, {})".format(ind, midPoint.x(), midPoint.y(), midPoint.z(), ref.x(), ref.y(), ref.z())
92 MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES, keepSubResults = True)
94 # selection of a compsolid part is prohibited
95 assert(MultiRotation_1.feature().error() != "")
98 MultiRotation_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")])
99 REFERENCE[0] = GeomAPI_Pnt(26.21750044779, -12.5, 5)
100 assertResult(MultiRotation_1, 24, 123, 450, 900, 38247.599)
102 MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "AngularCopy_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES, keepSubResults = True)
103 REFERENCE[1] = GeomAPI_Pnt(21.6506350946, 5.3316102, 5)
104 assertResult(MultiRotation_2, 26, 129, 462, 924, 39818.3954)
106 MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "AngularCopy_2_1_3")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES, keepSubResults = True)
107 REFERENCE[2] = GeomAPI_Pnt(31.94572, -30.3316102, 5)
108 assertResult(MultiRotation_3, 28, 135, 474, 948, 41389.19175)
110 MultiRotation_4 = model.addMultiRotation(Part_1_doc, [model.selection("COMPSOLID", "AngularCopy_3_1_1_1"), model.selection("SOLID", "AngularCopy_3_1_2_2"), model.selection("COMPOUND", "AngularCopy_3_1_3")], model.selection("EDGE", "PartSet/OZ"), -ANGLE, COPIES, keepSubResults = True)
111 REFERENCE[0] = GeomAPI_Pnt(0, -12.5, 5)
112 REFERENCE[1] = GeomAPI_Pnt(20.59016994, 5.3316102, 5)
113 REFERENCE[2] = GeomAPI_Pnt(0, -12.5, 5)
114 assertResult(MultiRotation_4, 50, 235, 810, 1620, 71599.98)
118 assert(model.checkPythonDump())