from GeomAlgoAPI import *
from GeomAPI import *
+from GeomDataAPI import *
from ModelAPI import ModelAPI_Feature
import math
+from salome.shaper.model import sketcher
+TOLERANCE = 1.e-7
aShapeTypes = {
GeomAPI_Shape.SOLID: "GeomAPI_Shape.SOLID",
if aFeature is not None and aFeature.getKind() == theKindOfSub:
count += 1
assert (count == theExpectedCount), "Number of sub-features of type {}: {}, expected {}".format(theKindOfSub, count, theExpectedCount)
+
+def assertSketchArc(theArcFeature):
+ """ Tests whether the arc is correctly defined
+ """
+ aCenterPnt = geomDataAPI_Point2D(theArcFeature.attribute("center_point"))
+ aStartPnt = geomDataAPI_Point2D(theArcFeature.attribute("start_point"))
+ aEndPnt = geomDataAPI_Point2D(theArcFeature.attribute("end_point"))
+ aRadius = theArcFeature.real("radius")
+ aDistCS = sketcher.tools.distancePointPoint(aCenterPnt, aStartPnt)
+ aDistCE = sketcher.tools.distancePointPoint(aCenterPnt, aEndPnt)
+ assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
+ assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong arc: radius is {0}, expected {1}".format(aRadius.value(), aDistCS)
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
aSession.startOperation()
anArcEndPoint.setValue(10., 0.)
aSession.finishOperation()
-assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 47.
-assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 48.
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 46.5
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 47.5
aSession.startOperation()
anArcEndPoint.setValue(1., 10.)
aSession.finishOperation()
aSession.finishOperation()
assert aSketchArc.boolean("reversed").value() == anInversed
#=========================================================================
-# Test that movement of start point of arc does not change central point
+# Test that movement of start point of arc does not break the arc
#=========================================================================
-TOL = 1.e-5
x = anArcCentr.x()
y = anArcCentr.y()
sx = anArcStartPoint.x()
aSession.startOperation()
anArcStartPoint.setValue(sx, sy+aDelta) # move start point
aSession.finishOperation()
- assert math.fabs(anArcCentr.x() - x) < TOL
- assert math.fabs(anArcCentr.y() - y) < TOL
+ model.assertSketchArc(aSketchArc)
for aDelta in range(20, -1, -1):
aSession.startOperation()
anArcStartPoint.setValue(sx, sy+aDelta) # move start point
aSession.finishOperation()
- assert math.fabs(anArcCentr.x() - x) < TOL
- assert math.fabs(anArcCentr.y() - y) < TOL
+ model.assertSketchArc(aSketchArc)
#=========================================================================
-# Test that movement of end point of arc does not change central point
+# Test that movement of end point of arc does not break the arc
#=========================================================================
x = anArcCentr.x()
y = anArcCentr.y()
aSession.startOperation()
anArcEndPoint.setValue(sx+aDelta, sy) # move end point
aSession.finishOperation()
- assert math.fabs(anArcCentr.x() - x) < TOL
- assert math.fabs(anArcCentr.y() - y) < TOL
+ model.assertSketchArc(aSketchArc)
for aDelta in range(20, -1, -1):
aSession.startOperation()
anArcEndPoint.setValue(sx+aDelta, sy) # move end point
aSession.finishOperation()
- assert math.fabs(anArcCentr.x() - x) < TOL
- assert math.fabs(anArcCentr.y() - y) < TOL
+ model.assertSketchArc(aSketchArc)
verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
if len(theEnd):
verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
- aRadius = aLastArc.real("radius")
- aDistCS = model.distancePointPoint(aCenterPnt, aStartPnt)
- aDistCE = model.distancePointPoint(aCenterPnt, aEndPnt)
- assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
- assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong radius {0}, expected {1}".format(aRadius.value(), aDistCS)
+ model.assertSketchArc(aLastArc)
def verifyPointCoordinates(thePoint, theX, theY):
assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY)