1 ## Copyright (C) 2017 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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 from ModelAPI import *
22 from GeomDataAPI import *
25 from salome.shaper.model.sketcher import tools
29 def assertPoint(thePoint, theCoords):
30 """ Verifies coordinates of the point
32 aPoint = tools.toList(thePoint)
33 assert aPoint[0] == theCoords[0] and aPoint[1] == theCoords[1], "Wrong '{}' point {}, expected {}".format(thePoint.id(), aPoint, theCoords)
36 def assertLine(theLine, theStart, theEnd):
37 """ Verifies coordinates of line extremities
39 aLine = tools.toSketchFeature(theLine)
41 aStartPnt = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
42 aEndPnt = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
44 assertPoint(aStartPnt, theStart)
46 assertPoint(aEndPnt, theEnd)
49 def assertCircle(theCircle, theCenter, theRadius):
50 """ Verifies attributes of circle
52 aCircle = tools.toSketchFeature(theCircle)
54 aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
56 assertPoint(aCenter, theCenter)
58 aRadius = aCircle.real("circle_radius")
59 assert aRadius.value() == theRadius, "Wrong circle radius {}, expected {}".format(aRadius.value(), theRadius)
62 def assertArc(theArc, theCenter, theStart, theEnd):
63 """ Verifies coordinates of arc points and the consistency of the arc.
64 Some of points may be empty lists.
66 anArc = tools.toSketchFeature(theArc)
68 aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
69 aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
70 aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
72 assertPoint(aCenterPnt, theCenter)
74 assertPoint(aStartPnt, theStart)
76 assertPoint(aEndPnt, theEnd)
78 assertArcValidity(anArc)
81 def assertArcValidity(theArc):
82 """ Tests whether the arc is correctly defined
84 anArc = tools.toSketchFeature(theArc)
86 aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
87 aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
88 aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
89 aRadius = anArc.real("radius")
90 aDistCS = tools.distancePointPoint(aCenterPnt, aStartPnt)
91 aDistCE = tools.distancePointPoint(aCenterPnt, aEndPnt)
92 assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
93 assert math.fabs(aRadius.value() - aDistCS) < TOLERANCE, "Wrong arc: radius is {}, expected {}".format(aRadius.value(), aDistCS)
96 def checkSketch(theSketch, theDOF = -1):
97 """ Tests the sketch is valid and DoF is equal to the given
99 assert(theSketch.feature().error() == ""), "Sketch failed: {}".format(theSketch.feature().error())
100 assert(theSketch.solverError().value() == ""), "Sketch solver failed: {}".format(theSketch.solverError().value())
102 aDOF = tools.dof(theSketch)
103 assert(aDOF == theDOF), "Sketch DoF {} is wrong. Expected {}".format(aDOF, theDOF)
106 def checkSketchErrorDegenerated(theSketch):
107 """ Verify the sketch reports error about degenerated geometry
109 errorValue = theSketch.solverError().value()
110 assert(errorValue != "")
111 assert(errorValue.find("degenerated") >= 0)