Salome HOME
a6920f31990fa0211b2dbc4b1c70d5a59c6f463d
[modules/shaper.git] / src / ExchangePlugin / Test / TestImportPart_Construction_1.py
1 # Copyright (C) 2019-2021  CEA/DEN, EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from GeomAlgoAPI import *
21 from ModelAPI import *
22 from SketchAPI import *
23 from salome.shaper import model
24
25 import os
26 import math
27
28 # PartSet => PartSet
29
30 model.begin()
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)
39 model.do()
40 Axis_1 = model.addAxis(partSet, model.selection("VERTEX", "Origin"), model.selection("VERTEX", "Point_2"))
41 model.end()
42
43 # store the reference data
44 features = partSet.allFeatures()
45 refData = []
46 for feat in features:
47     res = []
48     for r in feat.results():
49         res.append(GeomAlgoAPI_ShapeTools.volume(r.shape()))
50     refData.append( (feat.getKind(), res) )
51
52 filename = model.getTmpFileName('check_export', '.shaperpart')
53 model.removeTmpFile(filename)
54
55 # emport the document
56 model.begin()
57 model.exportPart(partSet, filename)
58 model.end()
59 assert os.path.exists(filename), "ERROR: Cannot export PartSet"
60
61 # close all documents
62 model.reset()
63
64 # import the document
65 model.begin()
66 partSet = model.moduleDocument()
67 model.importPart(partSet, filename)
68 model.end()
69
70 # Test 1. No Part should be created
71 assert(partSet.size(ModelAPI_ResultPart.group()) == 0)
72
73 # Test 2. Compare results with the reference data
74 TOLERANCE = 1.e-7
75 features = partSet.allFeatures()
76 assert(len(features) == len(refData))
77 for feat, ref in zip(features, refData):
78     assert(feat.getKind() == ref[0])
79     for fv, rv in zip(feat.results(), ref[1]):
80         assert(math.fabs(GeomAlgoAPI_ShapeTools.volume(fv.shape()) - rv) < TOLERANCE)
81
82 assert(model.checkPythonDump())