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