1 # Copyright (C) 2014-2023 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, geom
22 def isCRImplemented():
23 CR = geom.CanonicalRecognition()
24 return CR.isImplemented()
26 def GetShapeType(theShape):
27 CR = geom.CanonicalRecognition()
28 if CR.isLine(theShape, 0.1)[0]:
30 if CR.isPlane(theShape, 0.1)[0]:
31 if CR.isCircle(theShape, 0.1)[0]:
32 return ("Plane","Circle")
33 if CR.isEllipse(theShape, 0.1)[0]:
34 return ("Plane","Ellipse")
36 if CR.isSphere(theShape, 0.1)[0]:
38 if CR.isCone(theShape, 0.1)[0]:
40 if CR.isCylinder(theShape, 0.1)[0]:
46 partSet = model.moduleDocument()
49 Part_1 = model.addPart(partSet)
50 Part_1_doc = Part_1.document()
53 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
56 Plane_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Cylinder_1_1/Face_2")])
59 Recover_1 = model.addRecover(Part_1_doc, Plane_1, [Cylinder_1.result()])
62 Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_1_1/Modified_Face&Cylinder_1_1/Face_1")])
65 Circle_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "[Recover_1_1/Modified_Face&Cylinder_1_1/Face_1][new_weak_name_2]")], False)
68 Recover_2 = model.addRecover(Part_1_doc, Circle_1, [Shell_2.result()])
71 Line_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "(Recover_2_1/Modified_Edge&Wire_1_1/Edge)")], False)
74 Cylinder_3 = model.addRecover(Part_1_doc, Line_1, [Recover_2.result()])
77 Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10)
78 SphereShell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sphere_1_1/Face_1")])
81 Cone_1 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 0, 10)
82 ConeShell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Cone_1_1/Face_1")])
85 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
87 ### Create SketchProjection
88 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
89 SketchPoint_1 = SketchProjection_1.createdFeature()
91 ### Create SketchEllipse
92 SketchEllipse_1 = Sketch_1.addEllipse(-37.39690313669599, -52.92905511857006, 61.08141071866921, -16.40734649833807, 41.5747486523393)
93 [SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchPoint_8, 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")
97 EllipseWire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchEllipse_1")], False)
101 ### Get shapes for tests
102 aPlaneShape = Plane_1.defaultResult().shape()
103 aCircleShape = Circle_1.defaultResult().shape()
104 aLineShape = Line_1.defaultResult().shape()
105 aCylinderShape = Cylinder_3.defaultResult().shape()
106 aSphereShape = SphereShell_1.defaultResult().shape()
107 aConeShape = ConeShell_1.defaultResult().shape()
108 aEllipseShape = EllipseWire_1.defaultResult().shape()
110 ### Check shapes types
111 if isCRImplemented():
112 assert (GetShapeType(aPlaneShape) == "Plane")
113 assert (GetShapeType(aCircleShape)[1] == "Circle")
114 assert (GetShapeType(aLineShape) == "Line")
115 assert (GetShapeType(aCylinderShape) == "Cylinder")
116 assert (GetShapeType(aSphereShape) == "Sphere")
117 assert (GetShapeType(aConeShape) == "Cone")
118 assert (GetShapeType(aEllipseShape)[1] == "Ellipse")