1 # Copyright (C) 2019-2023 CEA, EDF
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 GeomAlgoAPI import *
21 from ModelAPI import *
22 from SketchAPI import *
23 from salome.shaper import model
29 partSet = model.moduleDocument()
30 Part_1 = model.addPart(partSet)
31 Part_1_doc = Part_1.document()
32 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
33 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 100)
34 Translation_1.setName("MovedBox")
35 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/YOZ"), model.selection("EDGE", "PartSet/OY"), 45)
39 filename = model.getTmpFileName('check_export', '.shaperpart')
40 model.removeTmpFile(filename)
42 # export all features from Part_1
44 model.exportPart(Part_1_doc, filename)
46 assert os.path.exists(filename), "ERROR: Cannot export features from {}".format(Part_1.name())
53 partSet = model.moduleDocument()
54 Part_1 = model.addPart(partSet)
55 Part_1_doc = Part_1.document()
56 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
57 SketchLine_1 = Sketch_1.addLine(-20, -40, -50, -40)
58 SketchLine_2 = Sketch_1.addLine(-50, -40, -50, -10)
59 SketchLine_3 = Sketch_1.addLine(-50, -10, -20, -10)
60 SketchLine_4 = Sketch_1.addLine(-20, -10, -20, -40)
61 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
62 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
63 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
64 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
65 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
66 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
67 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
68 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
69 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_2.result())
70 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30)
71 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
72 SketchPoint_1 = SketchProjection_1.createdFeature()
73 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_3.endPoint(), SketchAPI_Point(SketchPoint_1).coordinates(), 20)
74 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_3.endPoint(), SketchAPI_Point(SketchPoint_1).coordinates(), 10)
76 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection(), 30, 0)
77 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], model.selection("EDGE", "PartSet/OX"), 50)
81 def checkUniqueNames(theDocument):
82 features = theDocument.allObjects()
85 name = feat.data().name()
87 assert(not name in names), "'{}' already exists in {}".format(name, names)
91 # import the document at the end
93 model.importPart(Part_1_doc, filename)
95 checkUniqueNames(Part_1_doc)
97 # import the document after Extrusion_1
99 model.importPart(Part_1_doc, filename, Extrusion_1)
101 checkUniqueNames(Part_1_doc)
103 # import the document after Sketch_1
105 model.importPart(Part_1_doc, filename, Sketch_1)
107 checkUniqueNames(Part_1_doc)
109 # import the document after Translation_1
111 model.importPart(Part_1_doc, filename, Translation_1)
113 checkUniqueNames(Part_1_doc)
115 model.removeTmpFile(filename)
117 assert(model.checkPythonDump())