1 # Copyright (C) 2019 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
26 def checkPerpendicular(theLine, theEllipse):
27 focus1 = theEllipse.firstFocus()
28 focus2 = theEllipse.secondFocus()
29 pf1 = theLine.project(focus1)
30 pf2 = theLine.project(focus2)
31 dist1 = focus1.distance(pf1)
32 dist2 = focus2.distance(pf2)
33 if math.fabs(dist1 - dist2) < TOLERANCE:
34 # no need further check, the line is equal to one of the ellipses axis
36 x = (dist2 * pf1.x() - dist1 * pf2.x()) / (dist2 - dist1)
37 y = (dist2 * pf1.y() - dist1 * pf2.y()) / (dist2 - dist1)
38 pnt = GeomAPI_Pnt(x, y, 0)
39 # check point on ellipse
40 majorRad = theEllipse.majorRadius()
41 assert(math.fabs(pnt.distance(focus1) + pnt.distance(focus2) - 2.0 * majorRad) < TOLERANCE * majorRad)
45 partSet = model.moduleDocument()
46 Part_1 = model.addPart(partSet)
47 Part_1_doc = Part_1.document()
48 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
49 SketchLine_1 = Sketch_1.addLine(-40, 10, -20, 30)
50 SketchArc_1 = Sketch_1.addArc(25, -30, 42, -34, 13, -17.31142245955048, False)
51 SketchEllipse_1 = Sketch_1.addEllipse(-50, 0, -30, -5, 15)
52 [SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_2, SketchLine_3] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
53 SketchEllipticArc_1 = Sketch_1.addEllipticArc(5, 30, -5, 45, -7, 47, 15, 33.68010611, False)
54 [SketchPoint_8, SketchPoint_9, SketchPoint_10, SketchPoint_11, SketchPoint_12, SketchPoint_13, SketchPoint_14, SketchLine_4, SketchLine_5] = SketchEllipticArc_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
57 # check error on perpendicularity of arc and elliptic arc
58 SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchArc_1.results()[1], SketchEllipticArc_1.result())
60 assert(SketchConstraintPerpendicular_1.feature().error() != "")
63 Part_1_doc.removeFeature(SketchConstraintPerpendicular_1.feature())
65 assert(Sketch_1.feature().error() == "")
67 # set correct constraints
68 SketchConstraintPerpendicular_2 = Sketch_1.setPerpendicular(SketchEllipticArc_1.result(), SketchLine_1.result())
69 SketchConstraintPerpendicular_3 = Sketch_1.setPerpendicular(SketchLine_1.result(), SketchEllipse_1.result())
72 checkPerpendicular(SketchLine_1.defaultResult().shape().edge().line(), SketchEllipse_1.defaultResult().shape().edge().ellipse())
73 checkPerpendicular(SketchLine_1.defaultResult().shape().edge().line(), SketchEllipticArc_1.defaultResult().shape().edge().ellipse())
76 assert(model.checkPythonDump())