1 # Copyright (C) 2019-2024 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
31 partSet = model.moduleDocument()
32 Point_1 = model.addPoint(partSet, 100, 100, 100)
33 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
34 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "Origin"), False)
35 SketchPoint_1 = SketchProjection_1.createdFeature()
36 SketchCircle_1 = Sketch_1.addCircle(0, 0, 30)
37 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center())
38 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 30)
40 Axis_1 = model.addAxis(partSet, model.selection("VERTEX", "Origin"), model.selection("VERTEX", "Point_2"))
43 # store the reference data (without Origin, coordinate axes and planes)
44 features = partSet.allFeatures()
50 for r in feat.results():
51 res.append(GeomAlgoAPI_ShapeTools.volume(r.shape()))
52 refData.append( (feat.getKind(), res) )
54 filename = model.getTmpFileName('check_export', '.shaperpart')
55 model.removeTmpFile(filename)
59 model.exportPart(partSet, filename)
61 assert os.path.exists(filename), "ERROR: Cannot export PartSet"
68 partSet = model.moduleDocument()
69 Part_1 = model.addPart(partSet)
70 Part_1_doc = Part_1.document()
71 model.importPart(Part_1_doc, filename)
74 model.removeTmpFile(filename)
76 # Test 1. No Part should be created
77 assert(partSet.size(ModelAPI_ResultPart.group()) == 1)
79 # Test 2. Compare results with the reference data
81 features = Part_1_doc.allFeatures()
82 assert(len(features) == len(refData))
83 for feat, ref in zip(features, refData):
84 assert(feat.getKind() == ref[0])
85 for fv, rv in zip(feat.results(), ref[1]):
86 assert(math.fabs(GeomAlgoAPI_ShapeTools.volume(fv.shape()) - rv) < TOLERANCE)
88 assert(model.checkPythonDump())