Salome HOME
bos #29481 Merge branch 'CR29481'
[modules/shaper.git] / src / ModelAPI / Test / TestMovePart2.py
1 # Copyright (C) 2014-2021  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 salome.shaper import model
21
22 model.begin()
23 partSet = model.moduleDocument()
24
25 ### Create Part_1 : biggest cylinder
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 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
30 SketchPoint_1 = SketchProjection_1.createdFeature()
31 SketchCircle_1 = Sketch_1.addCircle(0, 0, 50)
32 Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center())
33 model.do()
34 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f")], model.selection(), 10, 0, "Faces|Wires")
35 model.do()
36
37 ### Create Plane_4 and Sketch_2, independent
38 Plane_4 = model.addPlane(partSet, model.selection("FACE", "XOY"), 10, False)
39 Sketch_2 = model.addSketch(partSet, model.selection("FACE", "Plane_4"))
40 SketchCircle_2 = Sketch_2.addCircle(0, 0, 20)
41 model.do()
42
43 ### Create Part_2, an edge on Sketch_2
44 Part_2 = model.addPart(partSet)
45 Part_2_doc = Part_2.document()
46 Edge_1 = model.addEdge(Part_2_doc, [model.selection("EDGE", "PartSet/Sketch_1/SketchCircle_1_2")], False)
47 model.do()
48
49 ### Create Part_3, small cylinder on a Sketch_2
50 Part_3 = model.addPart(partSet)
51 Part_3_doc = Part_3.document()
52 Extrusion_2 = model.addExtrusion(Part_3_doc, [model.selection("FACE", "PartSet/Sketch_1/Face-SketchCircle_1_2r")], model.selection(), 10, 0, "Faces|Wires")
53 model.do()
54
55 ### Create Part_4, a box, independent
56 Part_4 = model.addPart(partSet)
57 Part_4_doc = Part_4.document()
58 Sketch_3 = model.addSketch(Part_4_doc, model.defaultPlane("XOY"))
59 SketchLine_1 = Sketch_3.addLine(70, 60, 20, 60)
60 SketchLine_2 = Sketch_3.addLine(20, 60, 20, 30)
61 SketchLine_3 = Sketch_3.addLine(20, 30, 70, 30)
62 SketchLine_4 = Sketch_3.addLine(70, 30, 70, 60)
63 Sketch_3.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
64 Sketch_3.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
65 Sketch_3.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
66 Sketch_3.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
67 Sketch_3.setHorizontal(SketchLine_1.result())
68 Sketch_3.setVertical(SketchLine_2.result())
69 Sketch_3.setHorizontal(SketchLine_3.result())
70 Sketch_3.setVertical(SketchLine_4.result())
71 model.do()
72 Extrusion_3 = model.addExtrusion(Part_4_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), 10, 0, "Faces|Wires")
73 model.do()
74
75 ### Create Placement of Part_4 on the top face of Part_1
76 Placement_1 = model.addPlacement(partSet, [model.selection("COMPOUND", "Part_4/")], model.selection("FACE", "Part_4/Extrusion_1_1/From_Face"), model.selection("FACE", "Part_1/Extrusion_1_1/To_Face"), keepSubResults = True)
77
78 ### Create Part_5, revolution
79 Part_5 = model.addPart(partSet)
80 Part_5_doc = Part_5.document()
81 Sketch_4 = model.addSketch(Part_5_doc, model.defaultPlane("XOY"))
82 SketchCircle_3 = Sketch_4.addCircle(71.54809194299482, -51.10206832217438, 4.892982649360998)
83 model.do()
84 Revolution_1 = model.addRevolution(Part_5_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection("EDGE", "PartSet/OX"), -30, 0)
85 model.do()
86
87 ### Create Placement_2 of Part_5 revolution to Part_3 to face
88 Placement_2 = model.addPlacement(partSet, [model.selection("COMPOUND", "Part_5/")], model.selection("FACE", "Part_5/Revolution_1_1/From_Face"), model.selection("FACE", "Part_3/Extrusion_1_1/To_Face"), centering = True, keepSubResults = True)
89 model.end()
90
91 # Check multiple placement of Part_1, Part_3 and Part_5 after theSketch_2
92 aWhatList = model.FeatureList()
93 aWhatList.append(Part_1.feature())
94 aWhatList.append(Part_3.feature())
95 aWhatList.append(Part_5.feature())
96 anError = model.validateMovement(SketchCircle_2.feature(), aWhatList).strip()
97 assert(len(anError) == 0)
98 # check also that they cannot be moved after Placement_1
99 anError = model.validateMovement(Placement_1.feature(), aWhatList).strip()
100 assert(anError == 'Placement_1 -> Part_1')
101 # do movement
102 model.do()
103 partSet.moveFeature(Part_1.feature(), SketchCircle_2.feature())
104 partSet.moveFeature(Part_3.feature(), Part_1.feature())
105 partSet.moveFeature(Part_5.feature(), Part_3.feature())
106 model.end()
107
108 # check the resulting list of features
109 aNames = ['Plane_4', 'Sketch_1', 'Part_1', 'Part_3', 'Part_5', 'Part_2', 'Part_4', 'Placement_1', 'Placement_2']
110
111 for aNameIndex in range(9):
112   aFeatureName = model.objectToFeature(partSet.object("Features", aNameIndex)).name()
113   assert(aNames[aNameIndex] == aFeatureName)