1 # Copyright (C) 2017-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 from ModelAPI import *
21 from GeomDataAPI import *
24 from salome.shaper.model.sketcher import tools
28 def assertPoint(thePoint, theCoords, theTolerance = TOLERANCE):
29 """ Verifies coordinates of the point
31 aPoint = tools.toList(thePoint)
32 assert((aPoint[0]-theCoords[0])**2 + (aPoint[1]-theCoords[1])**2 < theTolerance**2), "Wrong '{}' point {}, expected {}".format(thePoint.id(), aPoint, theCoords)
35 def assertLine(theLine, theStart, theEnd, theTolerance = TOLERANCE):
36 """ Verifies coordinates of line extremities
38 aLine = tools.toSketchFeature(theLine)
40 aStartPnt = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
41 aEndPnt = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
43 assertPoint(aStartPnt, theStart, theTolerance)
45 assertPoint(aEndPnt, theEnd, theTolerance)
48 def assertCircle(theCircle, theCenter, theRadius, theTolerance = TOLERANCE):
49 """ Verifies attributes of circle
51 aCircle = tools.toSketchFeature(theCircle)
53 aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
55 assertPoint(aCenter, theCenter, theTolerance)
57 aRadius = aCircle.real("circle_radius")
58 assert aRadius.value() == theRadius, "Wrong circle radius {}, expected {}".format(aRadius.value(), theRadius)
61 def assertArc(theArc, theCenter, theStart, theEnd, theTolerance = TOLERANCE):
62 """ Verifies coordinates of arc points and the consistency of the arc.
63 Some of points may be empty lists.
65 anArc = tools.toSketchFeature(theArc)
67 aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
68 aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
69 aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
71 assertPoint(aCenterPnt, theCenter, theTolerance)
73 assertPoint(aStartPnt, theStart, theTolerance)
75 assertPoint(aEndPnt, theEnd, theTolerance)
77 assertArcValidity(anArc)
80 def assertArcValidity(theArc):
81 """ Tests whether the arc is correctly defined
83 anArc = tools.toSketchFeature(theArc)
85 aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
86 aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
87 aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
88 aRadius = anArc.real("radius")
89 aDistCS = tools.distancePointPoint(aCenterPnt, aStartPnt)
90 aDistCE = tools.distancePointPoint(aCenterPnt, aEndPnt)
91 assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
92 assert math.fabs(aRadius.value() - aDistCS) < TOLERANCE, "Wrong arc: radius is {}, expected {}".format(aRadius.value(), aDistCS)
95 def checkSketch(theSketch, theDOF = -1):
96 """ Tests the sketch is valid and DoF is equal to the given
98 assert(theSketch.feature().error() == ""), "Sketch failed: {}".format(theSketch.feature().error())
99 assert(theSketch.solverError().value() == ""), "Sketch solver failed: {}".format(theSketch.solverError().value())
101 aDOF = tools.dof(theSketch)
102 assert(aDOF == theDOF), "Sketch DoF {} is wrong. Expected {}".format(aDOF, theDOF)
105 def checkSketchErrorDegenerated(theSketch):
106 """ Verify the sketch reports error about degenerated geometry
108 errorValue = theSketch.solverError().value()
109 assert(errorValue != "")
110 assert(errorValue.find("degenerated") >= 0)