1 # Copyright (C) 2018-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
21 from SketchAPI import *
23 from salome.shaper import model
29 def checkArc(theDocument, theEdgeName, theCenter, theRadius):
30 # check edge (arc of circle)
31 anEdge = model.addEdge(theDocument, [model.selection("EDGE", theEdgeName)])
32 aShape = anEdge.result().resultSubShapePair()[0].shape()
33 assert(aShape.isEdge())
34 anArcEdge = aShape.edge()
35 assert(anArcEdge.isArc())
36 aCircle = anArcEdge.circle()
37 assert(aCircle.center().distance(theCenter) < TOLERANCE)
38 assert(math.fabs(aCircle.radius() - theRadius) < TOLERANCE)
39 theDocument.removeFeature(anEdge.feature())
41 def assertSphere(theSphere, theCenter, theRadius):
42 assert(theSphere is not None)
43 assert(theSphere.center().distance(theCenter) < TOLERANCE)
44 assert(math.fabs(theSphere.radius() - theRadius) < TOLERANCE)
46 def checkSphereFace(theDocument, theFaceName, theCenter, theRadius):
47 # check spherical face
48 aFace = model.addFace(theDocument, [model.selection("FACE", theFaceName)])
49 aShape = aFace.result().resultSubShapePair()[0].shape()
50 assert(aShape.isFace())
51 assertSphere(aShape.face().getSphere(), theCenter, theRadius)
52 theDocument.removeFeature(aFace.feature())
54 def checkSphereShell(theDocument, theFaceName, theCenter, theRadius):
55 # check spherical shell
56 aShell = model.addShell(theDocument, [model.selection("FACE", theFaceName)])
57 aShape = aShell.result().resultSubShapePair()[0].shape()
58 assert(aShape.isShell())
59 assertSphere(aShape.shell().getSphere(), theCenter, theRadius)
60 theDocument.removeFeature(aShell.feature())
62 def checkSphereAll(theDocument, theFeature, theFaceName, theCenter, theRadius):
64 aShape = theFeature.result().resultSubShapePair()[0].shape()
65 assert(aShape.isSolid())
66 assertSphere(aShape.solid().getSphere(), theCenter, theRadius)
68 checkSphereShell(theDocument, theFaceName, theCenter, theRadius)
69 checkSphereFace(theDocument, theFaceName, theCenter, theRadius)
71 anArcName = "[" + theFaceName + "][weak_name_3]"
72 checkArc(theDocument, anArcName, theCenter, theRadius)
74 def checkNonSphereShell(theFeature):
75 aShape = theFeature.result().resultSubShapePair()[0].shape()
76 assert(aShape.isShell())
77 assert(aShape.shell().getSphere() is None)
81 partSet = model.moduleDocument()
82 Part_1 = model.addPart(partSet)
83 Part_1_doc = Part_1.document()
84 ParamR = model.addParameter(Part_1_doc, "R", "50")
85 ParamShift = model.addParameter(Part_1_doc, "Shift", "30")
86 ParamAngle = model.addParameter(Part_1_doc, "Angle", "30")
87 ParamAperture = model.addParameter(Part_1_doc, "Aperture", "360")
88 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
89 SketchArc_1 = Sketch_1.addArc(0, 0, 0, -50, 0, 50, False)
90 SketchLine_1 = Sketch_1.addLine(0, 50, 0, -50)
91 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_1.startPoint())
92 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.endPoint())
93 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
94 SketchPoint_1 = SketchProjection_1.createdFeature()
95 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_1).coordinates(), SketchArc_1.center())
96 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_1.center(), SketchLine_1.result())
97 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
98 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], "R")
101 # Test 1. Compose sphere
102 Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchArc_1_2r-SketchLine_1f")], model.selection("EDGE", "Sketch_1/SketchLine_1"), "Aperture", 0)
103 aCenter = GeomAPI.GeomAPI_Pnt(0, 0, 0)
104 checkSphereAll(Part_1_doc, Revolution_1, "Revolution_1_1/Generated_Face&Sketch_1/SketchArc_1_2", aCenter, ParamR.value())
106 # Test 2. Translate sphere
107 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Revolution_1_1")], model.selection("EDGE", "PartSet/OX"), "Shift")
108 aCenter.setX(aCenter.x() + ParamShift.value())
109 checkSphereAll(Part_1_doc, Translation_1, "Translation_1_1/MF:Translated&Sketch_1/SketchArc_1_2", aCenter, ParamR.value())
111 # Test 3. Rotate sphere
112 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("EDGE", "PartSet/OY"), "Angle")
113 anAngle = ParamAngle.value() * math.pi / 180.0
114 aCenter.setX(ParamShift.value() * math.cos(anAngle))
115 aCenter.setZ(-ParamShift.value() * math.sin(anAngle))
116 checkSphereAll(Part_1_doc, Rotation_1, "Rotation_1_1/MF:Rotated&Sketch_1/SketchArc_1_2", aCenter, ParamR.value())
118 # Test 4. Check result by changing parameters
121 checkSphereAll(Part_1_doc, Rotation_1, "Rotation_1_1/MF:Rotated&Sketch_1/SketchArc_1_2", aCenter, ParamR.value())
123 ParamAperture.setValue(270)
125 checkSphereFace(Part_1_doc, "Rotation_1_1/MF:Rotated&Sketch_1/SketchArc_1_2", aCenter, ParamR.value())
126 checkSphereShell(Part_1_doc, "Rotation_1_1/MF:Rotated&Sketch_1/SketchArc_1_2", aCenter, ParamR.value())
127 checkArc(Part_1_doc, "[Rotation_1_1/MF:Rotated&Sketch_1/SketchArc_1_2][Rotation_1_1/MF:Rotated&Revolution_1_1/From_Face]", aCenter, ParamR.value())
128 checkArc(Part_1_doc, "[Rotation_1_1/MF:Rotated&Sketch_1/SketchArc_1_2][Rotation_1_1/MF:Rotated&Revolution_1_1/To_Face]", aCenter, ParamR.value())
130 # Test 5. Sheck non-spherical shell
131 Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Rotation_1_1/MF:Rotated&Revolution_1_1/To_Face"), model.selection("FACE", "Rotation_1_1/MF:Rotated&Revolution_1_1/From_Face")])
132 checkNonSphereShell(Shell_1)
134 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
135 SketchLine_2 = Sketch_2.addLine(18.12152721893265, 20.53645178481853, 73.15172297255518, 20.53645178481853)
136 SketchConstraintHorizontal_1 = Sketch_2.setHorizontal(SketchLine_2.result())
137 SketchArc_2 = Sketch_2.addArc(60.28852631862447, 20.53645178481853, 73.15172297255518, 20.53645178481853, 58.16589238004093, 33.22330534748203, False)
138 SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchLine_2.result(), SketchArc_2.center())
139 SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchArc_2.startPoint())
140 SketchArc_3 = Sketch_2.addArc(40.15343392262997, 20.53645178481853, 18.12152721893265, 20.53645178481853, 58.16589238004093, 33.22330534748203, True)
141 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchLine_2.result(), SketchArc_3.center())
142 SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchArc_3.startPoint())
143 SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchArc_2.endPoint(), SketchArc_3.endPoint())
145 Revolution_2 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_2r-SketchArc_2_2f-SketchArc_3_2f")], model.selection("EDGE", "Sketch_2/SketchLine_2"), 360, 0)
146 Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Revolution_2_1/Generated_Face&Sketch_2/SketchArc_3_2"), model.selection("FACE", "Revolution_2_1/Generated_Face&Sketch_2/SketchArc_2_2")])
147 checkNonSphereShell(Shell_2)