Salome HOME
Update projected coordinate axes when changing one coordinate plane to another.
[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 # Test presentation for Fillet on low-level
93 aSession = ModelAPI_Session.get()
94 aSketchFeature = featureToCompositeFeature(Sketch_1.feature())
95 aSession.startOperation()
96 aFillet = aSketchFeature.addFeature("SketchFillet")
97 aFillet.refattr("fillet_point").setAttr(SketchLine_1.endPoint());
98 assert(featureToPresentation(aFillet).getAISObject(None) is not None)
99 aSession.finishOperation()
100
101 # Test presentation for MacroCircle on low-level
102 aSession.startOperation()
103 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
104 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
105 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
106 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
107 aCircleType = aCircle.string("circle_type")
108 aCircleType.setValue("circle_type_by_three_points")
109 aCirclePnt1.setValue(10, 0)
110 aCirclePnt2.setValue(-10, 0)
111 aCirclePnt3.setValue(0, 10)
112 assert(featureToPresentation(aCircle).getAISObject(None) is not None)
113 aSession.finishOperation()
114
115 # Test presentation for MacroArc on low-level
116 aSession.startOperation()
117 anArc = aSketchFeature.addFeature("SketchMacroArc")
118 anArcPnt1 = geomDataAPI_Point2D(anArc.attribute("start_point_2"))
119 anArcPnt2 = geomDataAPI_Point2D(anArc.attribute("end_point_2"))
120 anArcPnt3 = geomDataAPI_Point2D(anArc.attribute("passed_point"))
121 anArcType = anArc.string("arc_type")
122 anArcType.setValue("by_three_points")
123 anArcPnt1.setValue(5, 0)
124 anArcPnt2.setValue(-5, 0)
125 anArcPnt3.setValue(0, 5)
126 assert(featureToPresentation(anArc).getAISObject(None) is not None)
127 aSession.finishOperation()
128
129 model.end()