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