Salome HOME
bf71fc6c5be55b99385d35640cd0bf149f7e25d4
[modules/shaper.git] / src / ExchangePlugin / Test / TestImportPart_Construction_3.py
1 # Copyright (C) 2019-2022  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 # Part => PartSet
29
30 model.begin()
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)
41 model.do()
42 Axis_1 = model.addAxis(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("VERTEX", "Point_1"))
43 model.end()
44
45 # store the reference data
46 features = Part_1_doc.allFeatures()
47 refData = []
48 for feat in features:
49     res = []
50     for r in feat.results():
51         res.append(GeomAlgoAPI_ShapeTools.volume(r.shape()))
52     refData.append( (feat.getKind(), res) )
53
54 filename = model.getTmpFileName('check_export', '.shaperpart')
55 model.removeTmpFile(filename)
56
57 # emport the document
58 model.begin()
59 model.exportPart(Part_1_doc, filename)
60 model.end()
61 assert os.path.exists(filename), "ERROR: Cannot export {}".format(Part_1.name())
62
63 # close all documents
64 model.reset()
65
66 # import the document
67 model.begin()
68 partSet = model.moduleDocument()
69 model.importPart(partSet, filename)
70 model.end()
71
72 model.removeTmpFile(filename)
73
74 # Test 1. No new Part should be created
75 assert(partSet.size(ModelAPI_ResultPart.group()) == 0)
76
77 # Test 2. Compare results with the reference data
78 TOLERANCE = 1.e-7
79 features = partSet.allFeatures()
80 for i in range(0, 7):
81     # exclude Origin, coordinate axes and planes
82     features.pop_front()
83 assert(len(features) == len(refData))
84 for feat, ref in zip(features, refData):
85     assert(feat.getKind() == ref[0])
86     for fv, rv in zip(feat.results(), ref[1]):
87         assert(math.fabs(GeomAlgoAPI_ShapeTools.volume(fv.shape()) - rv) < TOLERANCE)
88
89 assert(model.checkPythonDump())