Salome HOME
Correct behavior of the Part remove feature in the test.
[modules/shaper.git] / src / PartSetAPI / Test / TestRemoveDuplicate.py
1 ## Copyright (C) 2014-2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 # Created a Part Remove/Duplicate API functionality since from low level and python dump it is not
22 # tested: feature history infor is not stored.
23
24 from salome.shaper import model
25
26 # prepare axis created by PartSet and Part points
27 model.begin()
28 PartSet = model.moduleDocument()
29 Part_1 = model.addPart(PartSet)
30 Part_1_doc = Part_1.document()
31 Point_2 = model.addPoint(Part_1_doc, 100, 50, 20)
32 Axis_4 = model.addAxis(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("VERTEX", "Point_1"))
33 model.do()
34
35 # Duplicate this part twice, duplicate the first Copy also
36 Copy_1 = model.duplicatePart(Part_1)
37 Copy_2 = model.duplicatePart(Part_1)
38 Copy_3 = model.duplicatePart(Copy_1)
39 model.do()
40
41 # check the intermediate result
42 assert PartSet.size("Parts") == 4
43 i = 0
44 for n in ["Part_1", "Part_3", "Part_2", "Part_4"]:
45   assert PartSet.object("Parts", i).data().name() == n
46   i = i + 1
47
48 # Remove the middle Part
49 model.removePart(Copy_2)
50 # move the history line to the end, because remove makes the current feature up
51 PartSet.setCurrentFeature(Copy_3.feature(), False)
52 model.do()
53
54 # check the intermediate result
55 assert PartSet.size("Parts") == 3
56 i = 0
57 for n in ["Part_1", "Part_2", "Part_4"]:
58   assert PartSet.object("Parts", i).data().name() == n
59   i = i + 1
60
61 # Remove a first copy
62 model.removePart(Copy_1)
63 # move the history line to the end, because remove makes the current feature up
64 PartSet.setCurrentFeature(Copy_3.feature(), False)
65 model.end()
66
67 # Undo the last remove
68 model.undo()
69
70 # Check the result
71 assert PartSet.size("Parts") == 3
72 i = 0
73 for n in ["Part_1", "Part_2", "Part_4"]:
74   assert PartSet.object("Parts", i).data().name() == n
75   i = i + 1