1 # Copyright (C) 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
20 from GeomAlgoAPI import *
21 from ModelAPI import *
22 from SketchAPI import *
23 from salome.shaper import model
31 partSet = model.moduleDocument()
32 Part_1 = model.addPart(partSet)
33 Part_1_doc = Part_1.document()
34 Point_1 = model.addPoint(Part_1_doc, 100, 100, 100)
35 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
36 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
37 SketchPoint_1 = SketchProjection_1.createdFeature()
38 SketchCircle_1 = Sketch_1.addCircle(0, 0, 30)
39 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center())
40 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 30)
42 Axis_1 = model.addAxis(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("VERTEX", "Point_1"))
45 # store the reference data
46 features = Part_1_doc.allFeatures()
50 for r in feat.results():
51 res.append(GeomAlgoAPI_ShapeTools.volume(r.shape()))
52 refData.append( (feat.getKind(), res) )
54 filename = model.tempFileName()
55 model.removeFile(filename)
59 model.exportPart(Part_1_doc, filename)
61 assert os.path.exists(filename), "ERROR: Cannot export {}".format(Part_1.name())
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 # Test 1. No new Part should be created
75 assert(partSet.size(ModelAPI_ResultPart.group()) == 1)
77 # Test 2. Compare results with the reference data
79 features = Part_1_doc.allFeatures()
80 assert(len(features) == len(refData))
81 for feat, ref in zip(features, refData):
82 assert(feat.getKind() == ref[0])
83 for fv, rv in zip(feat.results(), ref[1]):
84 assert(math.fabs(GeomAlgoAPI_ShapeTools.volume(fv.shape()) - rv) < TOLERANCE)
86 assert(model.checkPythonDump())