Salome HOME
updated copyright message
[modules/shaper.git] / src / CollectionPlugin / Test / TestGroup2.py
1 # Copyright (C) 2014-2023  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 # Test that splitted edges in the group are still correct edges in the group
21 # Based on the CEA report mail 04.12.2018, page 4
22
23 from SketchAPI import *
24 from ModelAPI import *
25 from GeomAPI import *
26 from salome.shaper import model
27
28 model.begin()
29 partSet = model.moduleDocument()
30 Part_1 = model.addPart(partSet)
31 Part_1_doc = Part_1.document()
32 param_p = model.addParameter(Part_1_doc, "r", "15")
33 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
34 SketchArc_1 = Sketch_1.addArc(7.5, 7.5, 22.5, 7.499992770095306, 7.499999582962127, 22.5, False)
35 SketchLine_1 = Sketch_1.addLine(7.499999582962127, 22.5, 7.499999582962127, 52.5)
36 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_1.startPoint())
37 SketchLine_2 = Sketch_1.addLine(22.5, 7.499992770095306, 52.5, 7.499992770095306)
38 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_2.startPoint())
39 SketchArc_2 = Sketch_1.addArc(7.5, 7.5, 52.5, 7.499992770095306, 7.499999582962127, 52.5, False)
40 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.center(), SketchArc_2.center())
41 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchArc_2.startPoint())
42 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchArc_2.endPoint(), SketchLine_1.endPoint())
43 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
44 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_2.result())
45 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), "r*2")
46 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_2.result())
47 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], "r")
48 SketchConstraintRadius_2 = Sketch_1.setRadius(SketchArc_2.results()[1], "3*r")
49 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
50 SketchPoint_1 = SketchProjection_1.createdFeature()
51 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchArc_2.center(), "r/2")
52 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchArc_1.center(), "r/2")
53 model.do()
54 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_2f-SketchArc_2_2f-SketchLine_1r-SketchArc_1_2r")])
55 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Sketch_1/Face-SketchLine_2f-SketchArc_2_2f-SketchLine_1r-SketchArc_1_2r"))
56 SketchCircle_1 = Sketch_2.addCircle(27.71638597484288, 11.4805029721516, 3)
57 SketchCircle_2 = Sketch_2.addCircle(45.03912720992525, 18.6558173277981, 3)
58 SketchLine_3 = Sketch_2.addLine(0, 0, 45.03912720992525, 18.6558173277981)
59 SketchLine_3.setAuxiliary(True)
60 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
61 SketchPoint_2 = SketchProjection_2.createdFeature()
62 SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchLine_3.startPoint(), SketchPoint_2.result())
63 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchCircle_2.center(), SketchLine_3.endPoint())
64 SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_3.result(), SketchCircle_1.center())
65 SketchConstraintRadius_3 = Sketch_2.setRadius(SketchCircle_1.results()[1], "r/5")
66 SketchConstraintRadius_4 = Sketch_2.setRadius(SketchCircle_2.results()[1], "r/5")
67 SketchConstraintDistance_1 = Sketch_2.setDistance(SketchLine_3.startPoint(), SketchCircle_1.center(), "2*r", True)
68 SketchConstraintDistance_2 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_3.endPoint(), "r*1.25", True)
69 SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/OX"), False)
70 SketchLine_4 = SketchProjection_3.createdFeature()
71 SketchConstraintAngle_1 = Sketch_2.setAngle(SketchLine_4.result(), SketchLine_3.result(), "r*1.5")
72 model.do()
73 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")], model.selection(), 10, 0)
74 AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("COMPOUND", "all-in-Extrusion_1")], model.selection("EDGE", "PartSet/OZ"), "90.-r*3", 2)
75 Cut_1 = model.addCut(Part_1_doc, [model.selection("FACE", "Face_1_1")], [model.selection("COMPOUND", "AngularCopy_1_1")])
76 Group_1 = model.addGroup(Part_1_doc, [model.selection("EDGE", "Face_1_1/Modified_Edge&Sketch_1/SketchArc_1_2")])
77 Group_1.setName("edge_int")
78 Group_1.result().setName("edge_int")
79 Group_2 = model.addGroup(Part_1_doc, [model.selection("EDGE", "Face_1_1/Modified_Edge&Sketch_1/SketchLine_2")])
80 Group_2.setName("edge_bottom")
81 Group_2.result().setName("edge_bottom")
82 Group_3 = model.addGroup(Part_1_doc, [model.selection("EDGE", "Face_1_1/Modified_Edge&Sketch_1/SketchLine_1")])
83 Group_3.setName("edge_left")
84 Group_3.result().setName("edge_left")
85 Group_4 = model.addGroup(Part_1_doc, [model.selection("EDGE", "Face_1_1/Modified_Edge&Sketch_1/SketchArc_2_2")])
86 Group_4.setName("edge_ext")
87 Group_4.result().setName("edge_ext")
88 model.do()
89 # change parameter "p" to make one ylinder split bottom and left edges
90 param_p.setValue(12)
91 model.end()
92
93 # check that int and ext groups are still edges, bottom and left groups are compounds of edges
94 aFactory = ModelAPI_Session.get().validators()
95
96 for group in [Group_1, Group_4]:
97   assert(aFactory.validate(group.feature()))
98   selectionList = group.feature().selectionList("group_list")
99   assert(selectionList.size() == 1)
100   assert(group.groupList().value(0).value().shapeType() == GeomAPI_Shape.EDGE)
101
102 for group in [Group_2, Group_3]:
103   assert(aFactory.validate(group.feature()))
104   selectionList = group.feature().selectionList("group_list")
105   assert(selectionList.size() == 2)
106   assert(group.groupList().value(0).value().shapeType() == GeomAPI_Shape.EDGE)
107   assert(group.groupList().value(1).value().shapeType() == GeomAPI_Shape.EDGE)
108
109 assert(model.checkPythonDump())