Salome HOME
98d7e2f39353b5fae1927b64b8ed72280283b0a2
[modules/shaper.git] / src / FeaturesPlugin / Test / TestImportResult.py
1 # Copyright (C) 2014-2024  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 salome.shaper import model
21 from ModelAPI import *
22 from GeomAPI import *
23
24 model.begin()
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
29 SketchCircle_1 = Sketch_1.addCircle(15, 13, 11)
30 model.do()
31 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), 10, 0)
32 model.do()
33
34 Part_2 = model.addPart(partSet)
35 Part_2_doc = Part_2.document()
36 Sketch_2 = model.addSketch(Part_2_doc, model.defaultPlane("XOZ"))
37 SketchCircle_2 = Sketch_2.addCircle(-13, -9, 5)
38 model.do()
39 Extrusion_2 = model.addExtrusion(Part_2_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), 10, 0)
40 ImportResult_1 = model.addImportResult(Part_2_doc, [model.selection("SOLID", "Part_1/Extrusion_1_1")])
41 model.do()
42
43 Part_3 = model.addPart(partSet)
44 Part_3_doc = Part_3.document()
45 Extrusion_3 = model.addExtrusion(Part_3_doc, [], model.selection(), 1, 0)
46 Sketch_3 = model.addSketch(Part_3_doc, model.defaultPlane("XOZ"))
47 SketchCircle_3 = Sketch_3.addCircle(-4, 2, 5)
48 Extrusion_3.setNestedSketch(Sketch_3)
49 model.do()
50
51 model.end()
52
53 # check Part_2 is ok and contains 2 solids in result
54 assert(Part_2.feature().results().size() == 1)
55 aPartShape = Part_2.feature().firstResult().shape()
56 assert(aPartShape.shapeTypeStr() == "COMPOUND")
57 aShapeExplorer = GeomAPI_ShapeExplorer(aPartShape, GeomAPI_Shape.SOLID)
58 assert(aShapeExplorer.more())
59 aShapeExplorer.next()
60 assert(aShapeExplorer.more())
61
62 # check that selection of this part and the lower part is impossible (by validator)
63 model.begin()
64 aSel = ImportResult_1.feature().selectionList("objects").value(0)
65 aSel.selectSubShape("SOLID", "Part_2/Extrusion_1_1")
66 model.end()
67 aFactory = ModelAPI_Session.get().validators()
68 assert(not aFactory.validate(ImportResult_1.feature()))
69
70 model.begin()
71 aSel = ImportResult_1.feature().selectionList("objects").value(0)
72 aSel.selectSubShape("SOLID", "Part_3/Extrusion_1_1")
73 model.end()
74 assert(not aFactory.validate(ImportResult_1.feature()))
75
76 # back to correct value
77 model.begin()
78 aSel = ImportResult_1.feature().selectionList("objects").value(0)
79 aSel.selectSubShape("SOLID", "Part_1/Extrusion_1_1")
80 model.end()
81 assert(aFactory.validate(ImportResult_1.feature()))
82
83 # TODO: implement for GEOMOETRICAL also
84 assert(model.checkPythonDump(model.ModelHighAPI.CHECK_NAMING))