Salome HOME
updated copyright message
[modules/shaper.git] / src / ExchangePlugin / Test / TestImportPart_Construction_2.py
1 # Copyright (C) 2019-2023  CEA, EDF
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 => Part
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 (without Origin, coordinate axes and planes)
44 features = partSet.allFeatures()
45 for i in range(0, 7):
46     features.pop_front()
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(partSet, filename)
60 model.end()
61 assert os.path.exists(filename), "ERROR: Cannot export PartSet"
62
63 # close all documents
64 model.reset()
65
66 # import the document
67 model.begin()
68 partSet = model.moduleDocument()
69 Part_1 = model.addPart(partSet)
70 Part_1_doc = Part_1.document()
71 model.importPart(Part_1_doc, filename)
72 model.end()
73
74 model.removeTmpFile(filename)
75
76 # Test 1. No Part should be created
77 assert(partSet.size(ModelAPI_ResultPart.group()) == 1)
78
79 # Test 2. Compare results with the reference data
80 TOLERANCE = 1.e-7
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)
87
88 assert(model.checkPythonDump())