Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / SketchPlugin / Test / TestSketchPointLine.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 # Initialization of the test
23 #=========================================================================
24 from GeomDataAPI import *
25 from ModelAPI import *
26
27 __updated__ = "2014-10-28"
28
29 aSession = ModelAPI_Session.get()
30 aDocument = aSession.moduleDocument()
31 #=========================================================================
32 # Creation of a sketch
33 #=========================================================================
34 aSession.startOperation()
35 aSketchCommonFeature = aDocument.addFeature("Sketch")
36 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
37 assert (aSketchFeature.getKind() == "Sketch")
38 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
39 origin.setValue(0, 0, 0)
40 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
41 dirx.setValue(1, 0, 0)
42 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
43 norm.setValue(0, 0, 1)
44 aSession.finishOperation()
45 # check that values have been changed
46 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
47 assert (origin.x() == 0)
48 assert (origin.y() == 0)
49 assert (origin.z() == 0)
50 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
51 assert (dirx.x() == 1)
52 assert (dirx.y() == 0)
53 assert (dirx.z() == 0)
54 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
55 assert (norm.x() == 0)
56 assert (norm.y() == 0)
57 assert (norm.z() == 1)
58 #=========================================================================
59 # Creation of a point
60 #=========================================================================
61 aSession.startOperation()
62 aSketchReflist = aSketchFeature.reflist("Features")
63 assert (not aSketchReflist.isInitialized())
64 assert(aSketchReflist.size() == 0)
65 assert (len(aSketchReflist.list()) == 0)
66 # aSketchPoint = aDocument.addFeature("SketchPoint")
67 aSketchPoint = aSketchFeature.addFeature("SketchPoint")
68 assert (aSketchPoint.getKind() == "SketchPoint")
69 coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordinates"))
70 assert (not coords.isInitialized())
71 # Simulate SketchPlugin_Point::move(...)
72 coords.setValue(10., 10.)
73 assert (coords.isInitialized())
74 aSession.finishOperation()
75 # check that values have been changed
76 aSketchReflist = aSketchFeature.reflist("Features")
77 assert (aSketchReflist.size() == 1)
78 assert (len(aSketchReflist.list()) == 1)
79 coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordinates"))
80 assert (coords.x() == 10.0)
81 assert (coords.y() == 10.0)
82 #=========================================================================
83 # Creation of a line
84 #=========================================================================
85 aSession.startOperation()
86 # aSketchLine = aDocument.addFeature("SketchLine")
87 aSketchLine = aSketchFeature.addFeature("SketchLine")
88 assert (aSketchLine.getKind() == "SketchLine")
89 assert (aSketchReflist.size() == 2)
90 assert (len(aSketchReflist.list()) == 2)
91 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
92 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
93 assert (not aLineStartPoint.isInitialized())
94 assert (not aLineEndPoint.isInitialized())
95 # Simulate SketchPlugin_Line::move(...)
96 aLineStartPoint.setValue(50., 50.)
97 aLineEndPoint.setValue(60., 60.)
98 assert (aLineStartPoint.isInitialized())
99 assert (aLineEndPoint.isInitialized())
100 aSession.finishOperation()
101 # check that values have been changed
102 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
103 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
104 assert (aLineStartPoint.x() == 50.0)
105 assert (aLineStartPoint.y() == 50.0)
106 assert (aLineEndPoint.x() == 60.0)
107 assert (aLineEndPoint.y() == 60.0)
108 #=========================================================================
109 # Check the results
110 #=========================================================================
111 aResult = aSketchLine.firstResult()
112 assert (aResult is not None)
113 aResultConstruction = modelAPI_ResultConstruction(aResult)
114 aShape = aResultConstruction.shape()
115 assert (aShape is not None)
116 assert (not aShape.isNull())
117
118 from salome.shaper import model
119 assert(model.checkPythonDump())