]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestPresentation.py
Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[modules/shaper.git] / src / SketchPlugin / Test / TestPresentation.py
1 ## Copyright (C) 2018-20xx  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22     TestPresentation.py
23     Test AIS presentations for constraints and macro-features
24 """
25
26 from salome.shaper import model
27 from GeomAPI import *
28 from ModelAPI import *
29 from GeomDataAPI import *
30
31 from ConfigAPI import *
32 Config_PropManager().registerProp("Visualization", "dimension_value_size", "Dimension value size", Config_Prop.IntSpin, "16")
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 # Test presentation for Fillet on low-level
94 aSession = ModelAPI_Session.get()
95 aSketchFeature = featureToCompositeFeature(Sketch_1.feature())
96 aSession.startOperation()
97 aFillet = aSketchFeature.addFeature("SketchFillet")
98 aFillet.refattr("fillet_point").setAttr(SketchLine_1.endPoint());
99 assert(featureToPresentation(aFillet).getAISObject(None) is not None)
100 aSession.finishOperation()
101
102 # Test presentation for MacroCircle on low-level
103 aSession.startOperation()
104 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
105 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
106 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
107 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
108 aCircleType = aCircle.string("circle_type")
109 aCircleType.setValue("circle_type_by_three_points")
110 aCirclePnt1.setValue(10, 0)
111 aCirclePnt2.setValue(-10, 0)
112 aCirclePnt3.setValue(0, 10)
113 assert(featureToPresentation(aCircle).getAISObject(None) is not None)
114 aSession.finishOperation()
115
116 # Test presentation for MacroArc on low-level
117 aSession.startOperation()
118 anArc = aSketchFeature.addFeature("SketchMacroArc")
119 anArcPnt1 = geomDataAPI_Point2D(anArc.attribute("start_point_2"))
120 anArcPnt2 = geomDataAPI_Point2D(anArc.attribute("end_point_2"))
121 anArcPnt3 = geomDataAPI_Point2D(anArc.attribute("passed_point"))
122 anArcType = anArc.string("arc_type")
123 anArcType.setValue("by_three_points")
124 anArcPnt1.setValue(5, 0)
125 anArcPnt2.setValue(-5, 0)
126 anArcPnt3.setValue(0, 5)
127 assert(featureToPresentation(anArc).getAISObject(None) is not None)
128 aSession.finishOperation()
129
130 model.end()