1 # Copyright (C) 2014-2023 CEA, EDF
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from salome.shaper import model
23 partSet = model.moduleDocument()
26 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
27 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "Origin"), False)
28 SketchPoint_1 = SketchProjection_1.createdFeature()
29 SketchCircle_1 = Sketch_1.addCircle(0, 0, 50)
30 Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center())
33 ### Create Sketch_2 with reference to Sketch_1 circle
34 Sketch_2 = model.addSketch(partSet, model.defaultPlane("XOY"))
35 SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/SketchCircle_1_2"), False)
36 SketchCircle_2 = SketchProjection_2.createdFeature()
37 SketchCircle_3 = Sketch_2.addCircle(34.92852513931564, 34.57180354201876, 20)
38 Sketch_2.setCoincident(SketchCircle_2.results()[1], SketchCircle_3.center())
41 ### Create Part_1: Extrusion of Sketch_1
42 Part_1 = model.addPart(partSet)
43 Part_1_doc = Part_1.document()
44 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "PartSet/Sketch_1/Face-SketchCircle_1_2f")], model.selection(), 10, 0, "Faces|Wires")
47 ### Create Part_2: Extrusion of Sketch_2
48 Part_2 = model.addPart(partSet)
49 Part_2_doc = Part_2.document()
50 Extrusion_2 = model.addExtrusion(Part_2_doc, [model.selection("FACE", "PartSet/Sketch_2/Face-SketchCircle_3_2f")], model.selection(), 20, 0, "Faces|Wires")
53 ### Create Placement of Part_2 over a Part_1
54 Placement_1 = model.addPlacement(partSet, [model.selection("COMPOUND", "Part_2/")], model.selection("FACE", "Part_2/Extrusion_1_1/From_Face"), model.selection("FACE", "Part_1/Extrusion_1_1/To_Face"), centering = True, keepSubResults = True)
56 ### Create independent Part_3
57 Part_3 = model.addPart(partSet)
58 Part_3_doc = Part_3.document()
59 Sketch_3 = model.addSketch(Part_3_doc, model.defaultPlane("XOY"))
60 SketchCircle_4 = Sketch_3.addCircle(-60, 65, 10)
62 Extrusion_3 = model.addExtrusion(Part_3_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), 10, 0, "Faces|Wires")
67 # test the movement of parts ability and produced errors
69 # checking ability to move theWhat to position after theTo and produced error theError
70 def checkMovement(theWhat, theTo, theError):
71 aWhatList = model.FeatureList()
72 aWhatList.append(theWhat.feature())
73 if not theTo is None and not isinstance(theTo, model.ModelAPI_Object):
74 theTo = theTo.feature()
75 anError = model.validateMovement(theTo, aWhatList).strip()
76 aListCheck = theError.split('\n')
77 aListGet = anError.split('\n')
78 assert(len(aListCheck) == len(aListGet))
79 # sort the second part of received list strings by name to keep stability of tests
81 for aLGet in aListGet:
82 if aLGet.find("-> ") > 0:
83 aRightPart = aLGet.split('-> ')[1].split(' ')
85 aListGetSort.append(aLGet.split('-> ')[0] + '-> ' + ' '.join(aRightPart))
87 aListGetSort.append(aLGet)
88 for anErr in aListCheck:
89 #print("Looking for " + anErr + " in " + str(aListGet))
90 assert(aListGetSort.count(anErr) == 1)
92 # movement to very first location actually means movement after the first invisible objects, coordinate system hidden ones
94 for aFeat in partSet.allObjects():
95 if aFeat.isInHistory():
97 aLastHidden = model.objectToFeature(aFeat)
99 checkMovement(Part_1, None, 'Part_1 -> Origin Sketch_1')
100 checkMovement(Part_1, aLastHidden, 'Part_1 -> Sketch_1')
101 checkMovement(Part_1, Sketch_1, 'Part_1 -> Sketch_1')
102 checkMovement(Part_1, Sketch_2, '')
103 checkMovement(Part_1, Part_2, '')
104 checkMovement(Part_1, Placement_1, 'Placement_1 -> Part_1')
105 checkMovement(Part_1, Part_3, 'Placement_1 -> Part_1')
107 checkMovement(Part_2, None, 'Part_2 -> Origin Sketch_1 Sketch_2')
108 checkMovement(Part_2, aLastHidden, 'Part_2 -> Sketch_1 Sketch_2')
109 checkMovement(Part_2, Sketch_1, 'Part_2 -> Sketch_1 Sketch_2') # in GUI this is not the case, because it drops after invisible sketch components
110 checkMovement(Part_2, Sketch_2, 'Part_2 -> Sketch_2') # in GUI this is not the case, because it drops after invisible sketch components
111 checkMovement(Part_2, Part_1, '')
112 checkMovement(Part_2, Placement_1, 'Placement_1 -> Part_2')
113 checkMovement(Part_2, Part_3, 'Placement_1 -> Part_2')
115 checkMovement(Part_3, None, '')
116 checkMovement(Part_3, aLastHidden, '')
117 checkMovement(Part_3, Sketch_1, '')
118 checkMovement(Part_3, Sketch_2, '')
119 checkMovement(Part_3, Part_1, '')
120 checkMovement(Part_3, Part_2, '')
121 checkMovement(Part_3, Placement_1, '')
123 # do movement Part_2 after Sketch_2
124 anAfterSketch_2 = partSet.nextFeature(Part_1.feature(), True)
126 partSet.moveFeature(Part_2.feature(), anAfterSketch_2)
128 # check the movement is performed
129 anAfter = partSet.nextFeature(anAfterSketch_2)
130 assert(anAfter.name() == 'Part_2')
131 anAfter = partSet.nextFeature(anAfter)
132 assert(anAfter.name() == 'Part_1')
133 anAfter = partSet.nextFeature(anAfter)
134 assert(anAfter.name() == 'Placement_1')