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