1 # Copyright (C) 2014-2022 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 *
22 from salome.shaper import model
29 from salome.geom import geomBuilder
31 geompy = geomBuilder.New()
33 ## Get the last object published in the GEOM section of the object browser
34 def getGEOMShape(index):
35 sb = salome.myStudy.NewBuilder()
36 comp = salome.myStudy.FindComponent("GEOM")
39 iterator = salome.myStudy.NewChildIterator( comp )
42 while iterator.More() and i:
43 sobj = iterator.Value()
47 obj = sobj.GetObject()
49 raise Exception("GEOM component " + str(index) + " not found.")
52 ## Get the sub-object i of an object in the object browser
53 # Numerotation starts at 1
54 def getSubObject(obj, i):
55 ok, sub_sobj = salome.ObjectToSObject(obj).FindSubObject(i)
57 raise Exception("No child found at %i for %s"%(i, obj.GetName()))
58 sub_obj = sub_sobj.GetObject()
62 def testExportToGEOM():
64 partSet = model.moduleDocument()
65 Part_1 = model.addPart(partSet)
66 Part_1_doc = Part_1.document()
67 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ"))
68 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
69 SketchPoint_1 = SketchProjection_1.createdFeature()
70 SketchCircle_1 = Sketch_1.addCircle(0, 0, 25)
71 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center())
72 SketchCircle_2 = Sketch_1.addCircle(20, -15, 20)
73 SketchCircle_3 = Sketch_1.addCircle(0, 25, 24.7213595499958)
74 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.results()[1], SketchCircle_3.center())
75 SketchCircle_4 = Sketch_1.addCircle(-20, -15, 20)
76 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchCircle_1.results()[1], SketchCircle_4.center())
77 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchCircle_4.results()[1], SketchCircle_2.results()[1])
78 SketchConstraintTangent_2 = Sketch_1.setTangent(SketchCircle_3.results()[1], SketchCircle_2.results()[1])
79 SketchConstraintTangent_3 = Sketch_1.setTangent(SketchCircle_4.results()[1], SketchCircle_3.results()[1])
80 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchCircle_2.center(), SketchCircle_1.results()[1])
81 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchCircle_2.results()[1], SketchCircle_4.results()[1])
82 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_2.results()[1], 20)
83 SketchConstraintRadius_2 = Sketch_1.setRadius(SketchCircle_1.results()[1], 25)
84 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OZ"), False)
85 SketchLine_1 = SketchProjection_2.createdFeature()
86 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_3.center())
88 Extrusion_1_objects = [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f-SketchCircle_4_2r-SketchCircle_4_2r-SketchCircle_3_2r"), model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f-SketchCircle_3_2r-SketchCircle_2_2r-SketchCircle_2_2r"), model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f-SketchCircle_2_2r-SketchCircle_4_2r")]
89 Extrusion_1 = model.addExtrusion(Part_1_doc, Extrusion_1_objects, model.selection(), 10, 0)
90 # select all results of an extrusion feature
91 Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("COMPSOLID", "all-in-Extrusion_1")])
92 Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("SOLID", "Extrusion_1_2")])
93 GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "Group_1")], [model.selection("COMPOUND", "Group_2")])
95 model.exportToGEOM(Part_1_doc)
98 # check that in GEOM module there are 3-SOLIDs-reuslts, with 2 groups each
99 shape1 = getGEOMShape(0)
101 assert(shape1.GetName() == "Extrusion_1_1")
102 assert(geompy.NumberOfSolids(shape1) == 1)
103 assert(salome.ObjectToSObject(shape1).FindSubObject(1)[1])
104 assert(salome.ObjectToSObject(shape1).FindSubObject(1)[1].GetName() == "Group_1")
105 assert(salome.ObjectToSObject(shape1).FindSubObject(2)[1])
106 assert(salome.ObjectToSObject(shape1).FindSubObject(2)[1].GetName() == "GroupSubstraction_1")
108 shape2 = getGEOMShape(1)
110 assert(shape2.GetName() == "Extrusion_1_2")
111 assert(geompy.NumberOfSolids(shape2) == 1)
112 assert(salome.ObjectToSObject(shape2).FindSubObject(1)[1])
113 assert(salome.ObjectToSObject(shape2).FindSubObject(1)[1].GetName() == "Group_1")
114 assert(salome.ObjectToSObject(shape2).FindSubObject(2)[1])
115 assert(salome.ObjectToSObject(shape2).FindSubObject(2)[1].GetName() == "Group_2")
117 shape3 = getGEOMShape(2)
119 assert(shape3.GetName() == "Extrusion_1_3")
120 assert(geompy.NumberOfSolids(shape3) == 1)
121 assert(salome.ObjectToSObject(shape3).FindSubObject(1)[1])
122 assert(salome.ObjectToSObject(shape3).FindSubObject(1)[1].GetName() == "Group_1")
123 assert(salome.ObjectToSObject(shape3).FindSubObject(2)[1])
124 assert(salome.ObjectToSObject(shape3).FindSubObject(2)[1].GetName() == "GroupSubstraction_1")
126 shape4 = getGEOMShape(3)
130 if __name__ == '__main__':