Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
[modules/shaper.git] / src / SketchPlugin / Test / TestPresentation.py
1 # Copyright (C) 2018-2019  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 """
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
33 model.begin()
34 partSet = model.moduleDocument()
35 Part_1 = model.addPart(partSet)
36 Part_1_doc = Part_1.document()
37 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
38 SketchLine_1 = Sketch_1.addLine(-1.492165138365909, 9.860293583877349, 21.86930170264727, 26.80555863006795)
39 SketchLine_2 = Sketch_1.addLine(21.86930170264727, 26.80555863006795, 23.42558840321396, 11.88651135131589)
40 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
41 SketchConstraintAngle_1 = Sketch_1.setAngle(SketchLine_1.result(), SketchLine_2.result(), 60)
42 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.startPoint(), SketchLine_2.endPoint(), 25, True)
43 SketchLine_3 = Sketch_1.addLine(23.50783486163409, 27.99407041552052, 34.45590553653152, 35.9352652297464)
44 SketchConstraintCollinear_1 = Sketch_1.setCollinear(SketchLine_1.result(), SketchLine_3.result())
45 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_1.startPoint(), SketchLine_3.startPoint(), 25)
46 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), 15)
47 SketchLine_4 = Sketch_1.addLine(53.74716193144771, -7.706985565972583, 35.95905823005196, -7.706985565972583)
48 SketchLine_5 = Sketch_1.addLine(35.95905823005196, -7.706985565972583, 35.95905823005196, 16.71916358123427)
49 SketchLine_6 = Sketch_1.addLine(35.95905823005196, 16.71916358123427, 53.74716193144771, 16.71916358123427)
50 SketchLine_7 = Sketch_1.addLine(53.74716193144771, 16.71916358123427, 53.74716193144771, -7.706985565972583)
51 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_4.startPoint())
52 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
53 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
54 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
55 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_4.result())
56 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_5.result())
57 SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_5.result(), SketchLine_7.result())
58 SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_6.result(), SketchLine_7.result())
59 SketchCircle_1 = Sketch_1.addCircle(20.43340729011699, -17.26699099051272, 10)
60 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 10)
61 SketchConstraintRigid_1 = Sketch_1.setFixed(SketchCircle_1.center())
62 SketchArc_1 = Sketch_1.addArc(44.85311008074984, -7.706985565972585, 49.46781809225963, -16.57853954306742, 34.85430557643821, -7.861609252895618, False)
63 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchCircle_1.results()[1], SketchArc_1.results()[1])
64 SketchConstraintMiddle_1 = Sketch_1.setMiddlePoint(SketchArc_1.center(), SketchLine_4.result())
65 SketchLine_8 = Sketch_1.addLine(49.46781809225963, -16.57853954306742, 32.21747944141746, -25.55163221418553)
66 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_8.startPoint())
67 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_8.result())
68 SketchConstraintMirror_1 = Sketch_1.addMirror(SketchLine_1.result(), [SketchLine_2.result()])
69 SketchMultiTranslation_1 = Sketch_1.addTranslation([SketchLine_2.result()], SketchLine_3.startPoint(), SketchLine_3.endPoint(), 3, True)
70 SketchMultiRotation_1 = Sketch_1.addRotation([SketchLine_3.result()], SketchLine_3.endPoint(), 360, 4, True)
71 model.do()
72
73 assert(featureToPresentation(SketchConstraintAngle_1.feature()).getAISObject(None) is not None)
74 assert(featureToPresentation(SketchConstraintCoincidence_1.feature()).getAISObject(None) is not None)
75 assert(featureToPresentation(SketchConstraintCollinear_1.feature()).getAISObject(None) is not None)
76 assert(featureToPresentation(SketchConstraintDistance_1.feature()).getAISObject(None) is not None)
77 assert(featureToPresentation(SketchConstraintDistanceHorizontal_1.feature()).getAISObject(None) is not None)
78 assert(featureToPresentation(SketchConstraintEqual_1.feature()).getAISObject(None) is not None)
79 assert(featureToPresentation(SketchConstraintHorizontal_1.feature()).getAISObject(None) is not None)
80 assert(featureToPresentation(SketchConstraintLength_1.feature()).getAISObject(None) is not None)
81 assert(featureToPresentation(SketchConstraintMiddle_1.feature()).getAISObject(None) is not None)
82 assert(featureToPresentation(SketchConstraintParallel_1.feature()).getAISObject(None) is not None)
83 assert(featureToPresentation(SketchConstraintPerpendicular_1.feature()).getAISObject(None) is not None)
84 assert(featureToPresentation(SketchConstraintRadius_1.feature()).getAISObject(None) is not None)
85 assert(featureToPresentation(SketchConstraintRigid_1.feature()).getAISObject(None) is not None)
86 assert(featureToPresentation(SketchConstraintTangent_1.feature()).getAISObject(None) is not None)
87 assert(featureToPresentation(SketchConstraintVertical_1.feature()).getAISObject(None) is not None)
88 assert(featureToPresentation(SketchConstraintMirror_1.feature()).getAISObject(None) is not None)
89 assert(featureToPresentation(SketchMultiTranslation_1.feature()).getAISObject(None) is not None)
90 assert(featureToPresentation(SketchMultiRotation_1.feature()).getAISObject(None) is not None)
91
92 model.end()
93
94 # Test presentation for Fillet on low-level
95 aSession = ModelAPI_Session.get()
96 aSketchFeature = featureToCompositeFeature(Sketch_1.feature())
97 aSession.startOperation()
98 aFillet = aSketchFeature.addFeature("SketchFillet")
99 aFillet.refattr("fillet_point").setAttr(SketchLine_1.endPoint());
100 assert(featureToPresentation(aFillet).getAISObject(None) is not None)
101 aSession.finishOperation()
102
103 # Test presentation for MacroCircle on low-level
104 aSession.startOperation()
105 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
106 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
107 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
108 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
109 aCircleType = aCircle.string("circle_type")
110 aCircleType.setValue("circle_type_by_three_points")
111 aCirclePnt1.setValue(10, 0)
112 aCirclePnt2.setValue(-10, 0)
113 aCirclePnt3.setValue(0, 10)
114 assert(featureToPresentation(aCircle).getAISObject(None) is not None)
115 aSession.finishOperation()
116
117 # Test presentation for MacroArc on low-level
118 aSession.startOperation()
119 anArc = aSketchFeature.addFeature("SketchMacroArc")
120 anArcPnt1 = geomDataAPI_Point2D(anArc.attribute("start_point_2"))
121 anArcPnt2 = geomDataAPI_Point2D(anArc.attribute("end_point_2"))
122 anArcPnt3 = geomDataAPI_Point2D(anArc.attribute("passed_point"))
123 anArcType = anArc.string("arc_type")
124 anArcType.setValue("by_three_points")
125 anArcPnt1.setValue(5, 0)
126 anArcPnt2.setValue(-5, 0)
127 anArcPnt3.setValue(0, 5)
128 assert(featureToPresentation(anArc).getAISObject(None) is not None)
129 aSession.finishOperation()
130
131 # Test presentation for MacroEllipse on low-level
132 aSession.startOperation()
133 anEllipse = aSketchFeature.addFeature("SketchMacroEllipse")
134 anEllipsePnt1 = geomDataAPI_Point2D(anEllipse.attribute("first_point"))
135 anEllipsePnt2 = geomDataAPI_Point2D(anEllipse.attribute("second_point"))
136 anEllipsePnt3 = geomDataAPI_Point2D(anEllipse.attribute("passed_point"))
137 anEllipseType = anEllipse.string("ellipse_type")
138 anEllipseType.setValue("by_center_axis_point")
139 anEllipsePnt1.setValue(10, 0)
140 anEllipsePnt2.setValue(-10, 0)
141 anEllipsePnt3.setValue(0, 5)
142 assert(featureToPresentation(anEllipse).getAISObject(None) is not None)
143 aSession.finishOperation()
144
145 # Test presentation for MacroEllipticArc on low-level
146 aSession.startOperation()
147 anEllipticArc = aSketchFeature.addFeature("SketchMacroEllipticArc")
148 anEllipticArcPnt1 = geomDataAPI_Point2D(anEllipticArc.attribute("center"))
149 anEllipticArcPnt2 = geomDataAPI_Point2D(anEllipticArc.attribute("major_axis_point"))
150 anEllipticArcPnt3 = geomDataAPI_Point2D(anEllipticArc.attribute("start_point"))
151 anEllipticArcPnt4 = geomDataAPI_Point2D(anEllipticArc.attribute("end_point"))
152 anEllipticArcPnt1.setValue(0, 0)
153 anEllipticArcPnt2.setValue(10, 0)
154 anEllipticArcPnt3.setValue(0, 5)
155 anEllipticArcPnt4.setValue(-10, 0)
156 assert(featureToPresentation(anEllipticArc).getAISObject(None) is not None)
157 aSession.finishOperation()