Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestPresentation.py
1 # Copyright (C) 2018-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 """
21     TestPresentation.py
22     Test AIS presentations for constraints and macro-features
23 """
24
25 from salome.shaper import model
26 from GeomAPI import *
27 from ModelAPI import *
28 from GeomDataAPI import *
29
30 from ConfigAPI import *
31 Config_PropManager().registerProp("Visualization", "dimension_value_size", "Dimension value size", Config_Prop.IntSpin, "16")
32 Config_PropManager().registerProp("Visualization", "sketch_dimension_color", "Dimension color", Config_Prop.Color, "64,128,255")
33
34 model.begin()
35 partSet = model.moduleDocument()
36 Part_1 = model.addPart(partSet)
37 Part_1_doc = Part_1.document()
38 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
39 SketchLine_1 = Sketch_1.addLine(-1.492165138365909, 9.860293583877349, 21.86930170264727, 26.80555863006795)
40 SketchLine_2 = Sketch_1.addLine(21.86930170264727, 26.80555863006795, 23.42558840321396, 11.88651135131589)
41 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
42 SketchConstraintAngle_1 = Sketch_1.setAngle(SketchLine_1.result(), SketchLine_2.result(), 60)
43 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.startPoint(), SketchLine_2.endPoint(), 25, True)
44 SketchLine_3 = Sketch_1.addLine(23.50783486163409, 27.99407041552052, 34.45590553653152, 35.9352652297464)
45 SketchConstraintCollinear_1 = Sketch_1.setCollinear(SketchLine_1.result(), SketchLine_3.result())
46 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_1.startPoint(), SketchLine_3.startPoint(), 25)
47 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), 15)
48 SketchLine_4 = Sketch_1.addLine(53.74716193144771, -7.706985565972583, 35.95905823005196, -7.706985565972583)
49 SketchLine_5 = Sketch_1.addLine(35.95905823005196, -7.706985565972583, 35.95905823005196, 16.71916358123427)
50 SketchLine_6 = Sketch_1.addLine(35.95905823005196, 16.71916358123427, 53.74716193144771, 16.71916358123427)
51 SketchLine_7 = Sketch_1.addLine(53.74716193144771, 16.71916358123427, 53.74716193144771, -7.706985565972583)
52 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_4.startPoint())
53 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
54 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
55 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
56 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_4.result())
57 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_5.result())
58 SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_5.result(), SketchLine_7.result())
59 SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_6.result(), SketchLine_7.result())
60 SketchCircle_1 = Sketch_1.addCircle(20.43340729011699, -17.26699099051272, 10)
61 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 10)
62 SketchConstraintRigid_1 = Sketch_1.setFixed(SketchCircle_1.center())
63 SketchArc_1 = Sketch_1.addArc(44.85311008074984, -7.706985565972585, 49.46781809225963, -16.57853954306742, 34.85430557643821, -7.861609252895618, False)
64 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchCircle_1.results()[1], SketchArc_1.results()[1])
65 SketchConstraintMiddle_1 = Sketch_1.setMiddlePoint(SketchArc_1.center(), SketchLine_4.result())
66 SketchLine_8 = Sketch_1.addLine(49.46781809225963, -16.57853954306742, 32.21747944141746, -25.55163221418553)
67 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_8.startPoint())
68 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_8.result())
69 SketchConstraintMirror_1 = Sketch_1.addMirror(SketchLine_1.result(), [SketchLine_2.result()])
70 SketchMultiTranslation_1 = Sketch_1.addTranslation([SketchLine_2.result()], SketchLine_3.startPoint(), SketchLine_3.endPoint(), 3, True)
71 SketchMultiRotation_1 = Sketch_1.addRotation([SketchLine_3.result()], SketchLine_3.endPoint(), 360, 4, True)
72 model.do()
73
74 assert(featureToPresentation(SketchConstraintAngle_1.feature()).getAISObject(None) is not None)
75 assert(featureToPresentation(SketchConstraintCoincidence_1.feature()).getAISObject(None) is not None)
76 assert(featureToPresentation(SketchConstraintCollinear_1.feature()).getAISObject(None) is not None)
77 assert(featureToPresentation(SketchConstraintDistance_1.feature()).getAISObject(None) is not None)
78 assert(featureToPresentation(SketchConstraintDistanceHorizontal_1.feature()).getAISObject(None) is not None)
79 assert(featureToPresentation(SketchConstraintEqual_1.feature()).getAISObject(None) is not None)
80 assert(featureToPresentation(SketchConstraintHorizontal_1.feature()).getAISObject(None) is not None)
81 assert(featureToPresentation(SketchConstraintLength_1.feature()).getAISObject(None) is not None)
82 assert(featureToPresentation(SketchConstraintMiddle_1.feature()).getAISObject(None) is not None)
83 assert(featureToPresentation(SketchConstraintParallel_1.feature()).getAISObject(None) is not None)
84 assert(featureToPresentation(SketchConstraintPerpendicular_1.feature()).getAISObject(None) is not None)
85 assert(featureToPresentation(SketchConstraintRadius_1.feature()).getAISObject(None) is not None)
86 assert(featureToPresentation(SketchConstraintRigid_1.feature()).getAISObject(None) is not None)
87 assert(featureToPresentation(SketchConstraintTangent_1.feature()).getAISObject(None) is not None)
88 assert(featureToPresentation(SketchConstraintVertical_1.feature()).getAISObject(None) is not None)
89 assert(featureToPresentation(SketchConstraintMirror_1.feature()).getAISObject(None) is not None)
90 assert(featureToPresentation(SketchMultiTranslation_1.feature()).getAISObject(None) is not None)
91 assert(featureToPresentation(SketchMultiRotation_1.feature()).getAISObject(None) is not None)
92
93 model.end()
94
95 # Test presentation for Fillet on low-level
96 aSession = ModelAPI_Session.get()
97 aSketchFeature = featureToCompositeFeature(Sketch_1.feature())
98 aSession.startOperation()
99 aFillet = aSketchFeature.addFeature("SketchFillet")
100 aFillet.refattr("fillet_point").setAttr(SketchLine_1.endPoint());
101 assert(featureToPresentation(aFillet).getAISObject(None) is not None)
102 aSession.finishOperation()
103
104 # Test presentation for MacroCircle on low-level
105 aSession.startOperation()
106 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
107 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
108 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
109 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
110 aCircleType = aCircle.string("circle_type")
111 aCircleType.setValue("circle_type_by_three_points")
112 aCirclePnt1.setValue(10, 0)
113 aCirclePnt2.setValue(-10, 0)
114 aCirclePnt3.setValue(0, 10)
115 assert(featureToPresentation(aCircle).getAISObject(None) is not None)
116 aSession.finishOperation()
117
118 # Test presentation for MacroArc on low-level
119 aSession.startOperation()
120 anArc = aSketchFeature.addFeature("SketchMacroArc")
121 anArcPnt1 = geomDataAPI_Point2D(anArc.attribute("start_point_2"))
122 anArcPnt2 = geomDataAPI_Point2D(anArc.attribute("end_point_2"))
123 anArcPnt3 = geomDataAPI_Point2D(anArc.attribute("passed_point"))
124 anArcType = anArc.string("arc_type")
125 anArcType.setValue("by_three_points")
126 anArcPnt1.setValue(5, 0)
127 anArcPnt2.setValue(-5, 0)
128 anArcPnt3.setValue(0, 5)
129 assert(featureToPresentation(anArc).getAISObject(None) is not None)
130 aSession.finishOperation()
131
132 # Test presentation for MacroEllipse on low-level
133 aSession.startOperation()
134 anEllipse = aSketchFeature.addFeature("SketchMacroEllipse")
135 anEllipsePnt1 = geomDataAPI_Point2D(anEllipse.attribute("first_point"))
136 anEllipsePnt2 = geomDataAPI_Point2D(anEllipse.attribute("second_point"))
137 anEllipsePnt3 = geomDataAPI_Point2D(anEllipse.attribute("passed_point"))
138 anEllipseType = anEllipse.string("ellipse_type")
139 anEllipseType.setValue("by_center_axis_point")
140 anEllipsePnt1.setValue(10, 0)
141 anEllipsePnt2.setValue(-10, 0)
142 anEllipsePnt3.setValue(0, 5)
143 assert(featureToPresentation(anEllipse).getAISObject(None) is not None)
144 aSession.finishOperation()
145
146 # Test presentation for MacroEllipticArc on low-level
147 aSession.startOperation()
148 anEllipticArc = aSketchFeature.addFeature("SketchMacroEllipticArc")
149 anEllipticArcPnt1 = geomDataAPI_Point2D(anEllipticArc.attribute("center"))
150 anEllipticArcPnt2 = geomDataAPI_Point2D(anEllipticArc.attribute("major_axis_point"))
151 anEllipticArcPnt3 = geomDataAPI_Point2D(anEllipticArc.attribute("start_point"))
152 anEllipticArcPnt4 = geomDataAPI_Point2D(anEllipticArc.attribute("end_point"))
153 anEllipticArcPnt1.setValue(0, 0)
154 anEllipticArcPnt2.setValue(10, 0)
155 anEllipticArcPnt3.setValue(0, 5)
156 anEllipticArcPnt4.setValue(-10, 0)
157 assert(featureToPresentation(anEllipticArc).getAISObject(None) is not None)
158 aSession.finishOperation()
159
160 # Test presentation for MacroBSpline on low-level
161 aSession.startOperation()
162 aBSpline = aSketchFeature.addFeature("SketchMacroBSpline")
163 aPoles = geomDataAPI_Point2DArray(aBSpline.attribute("poles"))
164 aPoles.setSize(4)
165 aPoles.setPnt(0, 0, 0)
166 aPoles.setPnt(1, 10, 0)
167 aPoles.setPnt(2, 10, 10)
168 aPoles.setPnt(3, 0, 10)
169 aWeights = aBSpline.data().realArray("weights")
170 aWeights.setSize(4)
171 aWeights.setValue(0, 1)
172 aWeights.setValue(1, 2)
173 aWeights.setValue(2, 2)
174 aWeights.setValue(3, 1)
175 aBSpline.boolean("need_control_poly").setValue(True)
176 assert(featureToPresentation(aBSpline).getAISObject(None) is not None)
177 aSession.finishOperation()
178
179 # Test presentation for MacroBSplinePeriodic on low-level
180 aSession.startOperation()
181 aBSplineP = aSketchFeature.addFeature("SketchMacroBSplinePeriodic")
182 aPoles = geomDataAPI_Point2DArray(aBSplineP.attribute("poles"))
183 aPoles.setSize(4)
184 aPoles.setPnt(0, 0, 0)
185 aPoles.setPnt(1, 10, 0)
186 aPoles.setPnt(2, 10, 10)
187 aPoles.setPnt(3, 0, 10)
188 aWeights = aBSplineP.data().realArray("weights")
189 aWeights.setSize(4)
190 aWeights.setValue(0, 1)
191 aWeights.setValue(1, 2)
192 aWeights.setValue(2, 2)
193 aWeights.setValue(3, 1)
194 aBSplineP.boolean("need_control_poly").setValue(True)
195 assert(featureToPresentation(aBSplineP).getAISObject(None) is not None)
196 aSession.finishOperation()