]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestProjection.py
Salome HOME
Update unit-tests for SketchPlugin. Test case for the Projection has been added
[modules/shaper.git] / src / SketchPlugin / Test / TestProjection.py
1 """
2     TestProjection.py
3     Unit test of SketchPlugin_Projection class
4
5 """
6 from GeomDataAPI import *
7 from ModelAPI import *
8 import math
9 #=========================================================================
10 # Initialization of the test
11 #=========================================================================
12
13 __updated__ = "2016-05-16"
14
15
16 #=========================================================================
17 # Start of test
18 #=========================================================================
19 aSession = ModelAPI_Session.get()
20 aDocument = aSession.moduleDocument()
21 #=========================================================================
22 # Creation of a sketch
23 #=========================================================================
24 aSession.startOperation()
25 aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
26 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
27 origin.setValue(0, 0, 0)
28 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
29 dirx.setValue(1, 0, 0)
30 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
31 norm.setValue(0, 0, 1)
32 aSession.finishOperation()
33 #=========================================================================
34 # Create a line, circle and arc
35 #=========================================================================
36 aSession.startOperation()
37 aLine = aSketchFeature.addFeature("SketchLine")
38 aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
39 aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
40 aLineStart.setValue(10., 10.)
41 aLineEnd.setValue(40., 30.)
42
43 aCircle = aSketchFeature.addFeature("SketchCircle")
44 aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("CircleCenter"))
45 aCircleRadius = aCircle.real("CircleRadius")
46 aCircleCenter.setValue(-25., -25)
47 aCircleRadius.setValue(25.)
48
49 anArc = aSketchFeature.addFeature("SketchArc")
50 anArcCenter = geomDataAPI_Point2D(anArc.attribute("ArcCenter"))
51 anArcStart = geomDataAPI_Point2D(anArc.attribute("ArcStartPoint"))
52 anArcEnd = geomDataAPI_Point2D(anArc.attribute("ArcEndPoint"))
53 anArcCenter.setValue(10., 10.)
54 anArcStart.setValue(50., 0.)
55 anArcEnd.setValue(0., 50.)
56 aSession.finishOperation()
57 #=========================================================================
58 # Create another sketch
59 #=========================================================================
60 aSession.startOperation()
61 aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
62 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
63 origin.setValue(0, 0, 10)
64 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
65 dirx.setValue(1, 0, 0)
66 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
67 norm.setValue(0, 0, 1)
68 aSession.finishOperation()
69 #=========================================================================
70 # Project all features onto the new sketch
71 #=========================================================================
72 aSession.startOperation()
73 anExtLineRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchLine_1"))
74 assert(anExtLineRes)
75 anExtLineShape = anExtLineRes.shape()
76 assert(anExtLineShape)
77 aLineProjector = aSketchFeature.addFeature("SketchProjection")
78 aLineProjector.selection("ExternalFeature").setValue(anExtLineRes, anExtLineShape)
79 aLineProjector.execute()
80
81 anExtCircRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchCircle_1_2"))
82 assert(anExtCircRes)
83 anExtCircShape = anExtCircRes.shape()
84 assert(anExtCircShape)
85 aCircleProjector = aSketchFeature.addFeature("SketchProjection")
86 aCircleProjector.selection("ExternalFeature").setValue(anExtCircRes, anExtCircShape)
87 aCircleProjector.execute()
88
89 anExtArcRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchArc_1_2"))
90 assert(anExtArcRes)
91 anExtArcShape = anExtArcRes.shape()
92 assert(anExtArcShape)
93 anArcProjector = aSketchFeature.addFeature("SketchProjection")
94 anArcProjector.selection("ExternalFeature").setValue(anExtArcRes, anExtArcShape)
95 anArcProjector.execute()
96 aSession.finishOperation()
97 #=========================================================================
98 # Check projection coordinates
99 #=========================================================================
100 aProjLine = ModelAPI_Feature.feature(aLineProjector.refattr("ProjectedFeature").object())
101 assert(aProjLine)
102 aProjLineStart = geomDataAPI_Point2D(aProjLine.attribute("StartPoint"))
103 aProjLineEnd = geomDataAPI_Point2D(aProjLine.attribute("EndPoint"))
104 assert(math.fabs(aProjLineStart.x() - aLineStart.x()) < 1.e-10)
105 assert(math.fabs(aProjLineStart.y() - aLineStart.y()) < 1.e-10)
106 assert(math.fabs(aProjLineEnd.x() - aLineEnd.x()) < 1.e-10)
107 assert(math.fabs(aProjLineEnd.y() - aLineEnd.y()) < 1.e-10)
108
109 aProjCircle = ModelAPI_Feature.feature(aCircleProjector.refattr("ProjectedFeature").object())
110 assert(aProjCircle)
111 aProjCircleCenter = geomDataAPI_Point2D(aProjCircle.attribute("CircleCenter"))
112 aProjCircleRadius = aProjCircle.real("CircleRadius")
113 assert(math.fabs(aProjCircleCenter.x() - aCircleCenter.x()) < 1.e-10)
114 assert(math.fabs(aProjCircleCenter.y() - aCircleCenter.y()) < 1.e-10)
115 assert(math.fabs(aProjCircleRadius.value() - aCircleRadius.value()) < 1.e-10)
116
117 aProjArc = ModelAPI_Feature.feature(anArcProjector.refattr("ProjectedFeature").object())
118 aProjArcCenter = geomDataAPI_Point2D(aProjArc.attribute("ArcCenter"))
119 aProjArcStart = geomDataAPI_Point2D(aProjArc.attribute("ArcStartPoint"))
120 aProjArcEnd = geomDataAPI_Point2D(aProjArc.attribute("ArcEndPoint"))
121 assert(math.fabs(aProjArcCenter.x() - anArcCenter.x()) < 1.e-10)
122 assert(math.fabs(aProjArcCenter.y() - anArcCenter.y()) < 1.e-10)
123 assert(math.fabs(aProjArcStart.x() - anArcStart.x()) < 1.e-10)
124 assert(math.fabs(aProjArcStart.y() - anArcStart.y()) < 1.e-10)
125 assert(math.fabs(aProjArcEnd.x() - anArcEnd.x()) < 1.e-10)
126 assert(math.fabs(aProjArcEnd.y() - anArcEnd.y()) < 1.e-10)
127 #=========================================================================
128 # Move original feature and check the projection is agreed
129 #=========================================================================
130 aSession.startOperation()
131 aLineStart.setValue(20., 0.)
132 aSession.finishOperation()
133 assert(math.fabs(aProjLineStart.x() - aLineStart.x()) < 1.e-10)
134 assert(math.fabs(aProjLineStart.y() - aLineStart.y()) < 1.e-10)
135 assert(math.fabs(aProjLineEnd.x() - aLineEnd.x()) < 1.e-10)
136 assert(math.fabs(aProjLineEnd.y() - aLineEnd.y()) < 1.e-10)
137 #=========================================================================
138 # End of test
139 #=========================================================================