Salome HOME
Updated copyright comment
[modules/shaper.git] / src / PythonAPI / Test / TestCR.py
1 # Copyright (C) 2014-2024  CEA, EDF
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from salome.shaper import model, geom
21
22 def isCRImplemented():
23     CR = geom.CanonicalRecognition()
24     return CR.isImplemented()
25
26 def GetShapeType(theShape):
27     CR = geom.CanonicalRecognition()
28     if CR.isLine(theShape, 0.1)[0]:
29         return "Line"
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")
35         return "Plane"
36     if CR.isSphere(theShape, 0.1)[0]:
37         return "Sphere"
38     if CR.isCone(theShape, 0.1)[0]:
39         return "Cone"
40     if CR.isCylinder(theShape, 0.1)[0]:
41         return "Cylinder"
42     return "Not defined"
43
44
45 model.begin()
46 partSet = model.moduleDocument()
47
48 ### Create Part
49 Part_1 = model.addPart(partSet)
50 Part_1_doc = Part_1.document()
51
52 ### Create Cylinder
53 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
54
55 ### Create Shell
56 Plane_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Cylinder_1_1/Face_2")])
57
58 ### Create Recover
59 Recover_1 = model.addRecover(Part_1_doc, Plane_1, [Cylinder_1.result()])
60
61 ### Create Shell
62 Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_1_1/Modified_Face&Cylinder_1_1/Face_1")])
63
64 ### Create Wire
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)
66
67 ### Create Recover
68 Recover_2 = model.addRecover(Part_1_doc, Circle_1, [Shell_2.result()])
69
70 ### Create Edge
71 Line_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "(Recover_2_1/Modified_Edge&Wire_1_1/Edge)")], False)
72
73 ### Create Recover
74 Cylinder_3 = model.addRecover(Part_1_doc, Line_1, [Recover_2.result()])
75
76 ### Create Sphere
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")])
79
80 ### Create Cone
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")])
83
84 ### Create Sketch
85 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
86
87 ### Create SketchProjection
88 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
89 SketchPoint_1 = SketchProjection_1.createdFeature()
90
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")
94 model.do()
95
96 ### Create Wire
97 EllipseWire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchEllipse_1")], False)
98
99 model.end()
100
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()
109
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")