Salome HOME
9183aacb578ce9eae0cd405429668c04f1bf18d8
[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 from salome.shaper import model
10
11 #=========================================================================
12 # Initialization of the test
13 #=========================================================================
14
15 __updated__ = "2016-05-16"
16
17
18 #=========================================================================
19 # Start of test
20 #=========================================================================
21 aSession = ModelAPI_Session.get()
22 aDocument = aSession.moduleDocument()
23 #=========================================================================
24 # Creation of a sketch
25 #=========================================================================
26 aSession.startOperation()
27 aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
28 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
29 origin.setValue(0, 0, 0)
30 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
31 dirx.setValue(1, 0, 0)
32 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
33 norm.setValue(0, 0, 1)
34 aSession.finishOperation()
35 #=========================================================================
36 # Create a line, circle and arc
37 #=========================================================================
38 aSession.startOperation()
39 aLine = aSketchFeature.addFeature("SketchLine")
40 aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
41 aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
42 aLineStart.setValue(10., 10.)
43 aLineEnd.setValue(40., 30.)
44
45 aCircle = aSketchFeature.addFeature("SketchCircle")
46 aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
47 aCircleRadius = aCircle.real("circle_radius")
48 aCircleCenter.setValue(-25., -25)
49 aCircleRadius.setValue(25.)
50
51 anArc = aSketchFeature.addFeature("SketchArc")
52 anArcCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
53 anArcStart = geomDataAPI_Point2D(anArc.attribute("start_point"))
54 anArcEnd = geomDataAPI_Point2D(anArc.attribute("end_point"))
55 anArcCenter.setValue(10., 10.)
56 anArcStart.setValue(50., 0.)
57 anArcEnd.setValue(0., 50.)
58 aSession.finishOperation()
59 assert (model.dof(aSketchFeature) == 12)
60 #=========================================================================
61 # Create another sketch
62 #=========================================================================
63 aSession.startOperation()
64 aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
65 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
66 origin.setValue(0, 0, 10)
67 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
68 dirx.setValue(1, 0, 0)
69 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
70 norm.setValue(0, 0, 1)
71 aSession.finishOperation()
72 #=========================================================================
73 # Project all features onto the new sketch
74 #=========================================================================
75 aSession.startOperation()
76 aLineProjector = aSketchFeature.addFeature("SketchProjection")
77 aLineProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchLine_1")
78 aLineProjector.execute()
79
80 aCircleProjector = aSketchFeature.addFeature("SketchProjection")
81 aCircleProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchCircle_1_2")
82 aCircleProjector.execute()
83
84 anArcProjector = aSketchFeature.addFeature("SketchProjection")
85 anArcProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchArc_1_2")
86 anArcProjector.execute()
87 aSession.finishOperation()
88 assert (model.dof(aSketchFeature) == 0)
89 #=========================================================================
90 # Check projection coordinates
91 #=========================================================================
92 aProjLine = ModelAPI_Feature.feature(aLineProjector.refattr("ProjectedFeature").object())
93 assert(aProjLine)
94 aProjLineStart = geomDataAPI_Point2D(aProjLine.attribute("StartPoint"))
95 aProjLineEnd = geomDataAPI_Point2D(aProjLine.attribute("EndPoint"))
96 assert(math.fabs(aProjLineStart.x() - aLineStart.x()) < 1.e-10)
97 assert(math.fabs(aProjLineStart.y() - aLineStart.y()) < 1.e-10)
98 assert(math.fabs(aProjLineEnd.x() - aLineEnd.x()) < 1.e-10)
99 assert(math.fabs(aProjLineEnd.y() - aLineEnd.y()) < 1.e-10)
100
101 aProjCircle = ModelAPI_Feature.feature(aCircleProjector.refattr("ProjectedFeature").object())
102 assert(aProjCircle)
103 aProjCircleCenter = geomDataAPI_Point2D(aProjCircle.attribute("circle_center"))
104 aProjCircleRadius = aProjCircle.real("circle_radius")
105 assert(math.fabs(aProjCircleCenter.x() - aCircleCenter.x()) < 1.e-10)
106 assert(math.fabs(aProjCircleCenter.y() - aCircleCenter.y()) < 1.e-10)
107 assert(math.fabs(aProjCircleRadius.value() - aCircleRadius.value()) < 1.e-10)
108
109 aProjArc = ModelAPI_Feature.feature(anArcProjector.refattr("ProjectedFeature").object())
110 aProjArcCenter = geomDataAPI_Point2D(aProjArc.attribute("center_point"))
111 aProjArcStart = geomDataAPI_Point2D(aProjArc.attribute("start_point"))
112 aProjArcEnd = geomDataAPI_Point2D(aProjArc.attribute("end_point"))
113 assert(math.fabs(aProjArcCenter.x() - anArcCenter.x()) < 1.e-10)
114 assert(math.fabs(aProjArcCenter.y() - anArcCenter.y()) < 1.e-10)
115 assert(math.fabs(aProjArcStart.x() - anArcStart.x()) < 1.e-10)
116 assert(math.fabs(aProjArcStart.y() - anArcStart.y()) < 1.e-10)
117 assert(math.fabs(aProjArcEnd.x() - anArcEnd.x()) < 1.e-10)
118 assert(math.fabs(aProjArcEnd.y() - anArcEnd.y()) < 1.e-10)
119 #=========================================================================
120 # Move original feature and check the projection is agreed
121 #=========================================================================
122 aSession.startOperation()
123 aLineStart.setValue(20., 0.)
124 aSession.finishOperation()
125 assert(math.fabs(aProjLineStart.x() - aLineStart.x()) < 1.e-10)
126 assert(math.fabs(aProjLineStart.y() - aLineStart.y()) < 1.e-10)
127 assert(math.fabs(aProjLineEnd.x() - aLineEnd.x()) < 1.e-10)
128 assert(math.fabs(aProjLineEnd.y() - aLineEnd.y()) < 1.e-10)
129 assert (model.dof(aSketchFeature) == 0)
130 #=========================================================================
131 # End of test
132 #=========================================================================
133
134 assert(model.checkPythonDump())