1 # Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #=========================================================================
21 # Initialization of the test
22 #=========================================================================
23 from GeomDataAPI import *
24 from ModelAPI import *
26 __updated__ = "2014-10-28"
28 aSession = ModelAPI_Session.get()
29 aDocument = aSession.moduleDocument()
30 #=========================================================================
31 # Creation of a sketch
32 #=========================================================================
33 aSession.startOperation()
34 aSketchCommonFeature = aDocument.addFeature("Sketch")
35 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
36 assert (aSketchFeature.getKind() == "Sketch")
37 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
38 origin.setValue(0, 0, 0)
39 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
40 dirx.setValue(1, 0, 0)
41 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
42 norm.setValue(0, 0, 1)
43 aSession.finishOperation()
44 # check that values have been changed
45 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
46 assert (origin.x() == 0)
47 assert (origin.y() == 0)
48 assert (origin.z() == 0)
49 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
50 assert (dirx.x() == 1)
51 assert (dirx.y() == 0)
52 assert (dirx.z() == 0)
53 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
54 assert (norm.x() == 0)
55 assert (norm.y() == 0)
56 assert (norm.z() == 1)
57 #=========================================================================
59 #=========================================================================
60 aSession.startOperation()
61 aSketchReflist = aSketchFeature.reflist("Features")
62 assert (not aSketchReflist.isInitialized())
63 assert(aSketchReflist.size() == 0)
64 assert (len(aSketchReflist.list()) == 0)
65 # aSketchPoint = aDocument.addFeature("SketchPoint")
66 aSketchPoint = aSketchFeature.addFeature("SketchPoint")
67 assert (aSketchPoint.getKind() == "SketchPoint")
68 coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordinates"))
69 assert (not coords.isInitialized())
70 # Simulate SketchPlugin_Point::move(...)
71 coords.setValue(10., 10.)
72 assert (coords.isInitialized())
73 aSession.finishOperation()
74 # check that values have been changed
75 aSketchReflist = aSketchFeature.reflist("Features")
76 assert (aSketchReflist.size() == 1)
77 assert (len(aSketchReflist.list()) == 1)
78 coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordinates"))
79 assert (coords.x() == 10.0)
80 assert (coords.y() == 10.0)
81 #=========================================================================
83 #=========================================================================
84 aSession.startOperation()
85 # aSketchLine = aDocument.addFeature("SketchLine")
86 aSketchLine = aSketchFeature.addFeature("SketchLine")
87 assert (aSketchLine.getKind() == "SketchLine")
88 assert (aSketchReflist.size() == 2)
89 assert (len(aSketchReflist.list()) == 2)
90 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
91 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
92 assert (not aLineStartPoint.isInitialized())
93 assert (not aLineEndPoint.isInitialized())
94 # Simulate SketchPlugin_Line::move(...)
95 aLineStartPoint.setValue(50., 50.)
96 aLineEndPoint.setValue(60., 60.)
97 assert (aLineStartPoint.isInitialized())
98 assert (aLineEndPoint.isInitialized())
99 aSession.finishOperation()
100 # check that values have been changed
101 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
102 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
103 assert (aLineStartPoint.x() == 50.0)
104 assert (aLineStartPoint.y() == 50.0)
105 assert (aLineEndPoint.x() == 60.0)
106 assert (aLineEndPoint.y() == 60.0)
107 #=========================================================================
109 #=========================================================================
110 aResult = aSketchLine.firstResult()
111 assert (aResult is not None)
112 aResultConstruction = modelAPI_ResultConstruction(aResult)
113 aShape = aResultConstruction.shape()
114 assert (aShape is not None)
115 assert (not aShape.isNull())
117 from salome.shaper import model
118 assert(model.checkPythonDump())