1 # Author: Artem Zhidkov
2 # Copyright (C) 2017-20xx CEA/DEN, EDF R&D
5 from GeomDataAPI import *
8 from salome.shaper.model.sketcher import tools
12 def assertPoint(thePoint, theCoords):
13 """ Verifies coordinates of the point
15 aPoint = tools.toList(thePoint)
16 assert aPoint[0] == theCoords[0] and aPoint[1] == theCoords[1], "Wrong '{}' point {}, expected {}".format(thePoint.id(), aPoint, theCoords)
19 def assertLine(theLine, theStart, theEnd):
20 """ Verifies coordinates of line extremities
22 aLine = tools.toSketchFeature(theLine)
24 aStartPnt = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
25 aEndPnt = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
27 assertPoint(aStartPnt, theStart)
29 assertPoint(aEndPnt, theEnd)
32 def assertCircle(theCircle, theCenter, theRadius):
33 """ Verifies attributes of circle
35 aCircle = tools.toSketchFeature(theCircle)
37 aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
39 assertPoint(aCenter, theCenter)
41 aRadius = aCircle.real("circle_radius")
42 assert aRadius.value() == theRadius, "Wrong circle radius {}, expected {}".format(aRadius.value(), theRadius)
45 def assertArc(theArc, theCenter, theStart, theEnd):
46 """ Verifies coordinates of arc points and the consistency of the arc.
47 Some of points may be empty lists.
49 anArc = tools.toSketchFeature(theArc)
51 aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
52 aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
53 aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
55 assertPoint(aCenterPnt, theCenter)
57 assertPoint(aStartPnt, theStart)
59 assertPoint(aEndPnt, theEnd)
61 assertArcValidity(anArc)
64 def assertArcValidity(theArc):
65 """ Tests whether the arc is correctly defined
67 anArc = tools.toSketchFeature(theArc)
69 aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
70 aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
71 aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
72 aRadius = anArc.real("radius")
73 aDistCS = tools.distancePointPoint(aCenterPnt, aStartPnt)
74 aDistCE = tools.distancePointPoint(aCenterPnt, aEndPnt)
75 assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
76 assert math.fabs(aRadius.value() - aDistCS) < TOLERANCE, "Wrong arc: radius is {}, expected {}".format(aRadius.value(), aDistCS)