#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
#include "ModelHighAPI_Interface.h"
{
return !(myAttribute && myObject);
}
+
+//--------------------------------------------------------------------------------------
+void ModelHighAPI_RefAttr::fillMessage(
+ const std::shared_ptr<ModelAPI_ObjectMovedMessage>& theMessage) const
+{
+ switch (myVariantType) {
+ case VT_ATTRIBUTE: theMessage->setMovedAttribute(myAttribute); return;
+ case VT_OBJECT: theMessage->setMovedObject(myObject); return;
+ }
+}
class ModelAPI_AttributeRefAttr;
class ModelAPI_AttributeRefAttrList;
class ModelAPI_Object;
+class ModelAPI_ObjectMovedMessage;
class ModelHighAPI_Interface;
//--------------------------------------------------------------------------------------
/**\class ModelHighAPI_RefAttr
MODELHIGHAPI_EXPORT
bool isEmpty() const;
+ /// Fill moved message by the attribute or object
+ MODELHIGHAPI_EXPORT
+ void fillMessage(const std::shared_ptr<ModelAPI_ObjectMovedMessage>& theMessage) const;
+
private:
enum VariantType { VT_ATTRIBUTE, VT_OBJECT } myVariantType;
std::shared_ptr<ModelAPI_Attribute> myAttribute;
from SketchAPI import addSketch
from tools import *
+from tests import *
--- /dev/null
+# Author: Artem Zhidkov
+# Copyright (C) 2017-20xx CEA/DEN, EDF R&D
+
+from ModelAPI import *
+from GeomDataAPI import *
+import ModelHighAPI
+import math
+from salome.shaper.model.sketcher import tools
+
+TOLERANCE = 1.e-7
+
+def assertPoint(thePoint, theCoords):
+ """ Verifies coordinates of the point
+ """
+ aPoint = tools.toPoint(thePoint)
+ assert aPoint.x() == theCoords[0] and aPoint.y() == theCoords[1], "Wrong '{}' point ({}, {}), expected ({}, {})".format(thePoint.id(), aPoint.x(), aPoint.y(), theCoords[0], theCoords[1])
+
+
+def assertLine(theLine, theStart, theEnd):
+ """ Verifies coordinates of line extremities
+ """
+ aLine = tools.toSketchFeature(theLine)
+
+ aStartPnt = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
+ aEndPnt = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
+ if len(theStart):
+ assertPoint(aStartPnt, theStart)
+ if len(theEnd):
+ assertPoint(aEndPnt, theEnd)
+
+
+def assertCircle(theCircle, theCenter, theRadius):
+ """ Verifies attributes of circle
+ """
+ aCircle = tools.toSketchFeature(theCircle)
+
+ aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
+ if len(theCenter):
+ assertPoint(aCenter, theCenter)
+
+ aRadius = aCircle.real("circle_radius")
+ assert aRadius.value() == theRadius, "Wrong circle radius {}, expected {}".format(aRadius.value(), theRadius)
+
+
+def assertArc(theArc, theCenter, theStart, theEnd):
+ """ Verifies coordinates of arc points and the consistency of the arc.
+ Some of points may be empty lists.
+ """
+ anArc = tools.toSketchFeature(theArc)
+
+ aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
+ aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
+ aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
+ if len(theCenter):
+ assertPoint(aCenterPnt, theCenter)
+ if len(theStart):
+ assertPoint(aStartPnt, theStart)
+ if len(theEnd):
+ assertPoint(aEndPnt, theEnd)
+
+ assertArcValidity(anArc)
+
+
+def assertArcValidity(theArc):
+ """ Tests whether the arc is correctly defined
+ """
+ anArc = tools.toSketchFeature(theArc)
+
+ aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
+ aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
+ aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
+ aRadius = anArc.real("radius")
+ aDistCS = tools.distancePointPoint(aCenterPnt, aStartPnt)
+ aDistCE = 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)
# Copyright (C) 2014-20xx CEA/DEN, EDF R&D
import ModelHighAPI
-import GeomDataAPI
+from GeomDataAPI import *
+import math
def addPolyline(sketch, *coords):
"""Add a poly-line to sketch.
return int(filter(str.isdigit, aSketch.string("SolverDOF").value()))
def distancePointPoint(thePoint1, thePoint2):
- aGeomPnt1 = thePoint1
- aGeomPnt2 = thePoint2
- if issubclass(type(thePoint1), GeomDataAPI.GeomDataAPI_Point2D):
- aGeomPnt1 = thePoint1.pnt()
- if issubclass(type(thePoint2), GeomDataAPI.GeomDataAPI_Point2D):
- aGeomPnt2 = thePoint2.pnt()
+ aGeomPnt1 = toPoint(thePoint1)
+ aGeomPnt2 = toPoint(thePoint2)
return aGeomPnt1.distance(aGeomPnt2)
+def distancePointLine(thePoint, theLine):
+ aPoint = toPoint(thePoint)
+ aLine = toSketchFeature(theLine)
+
+ aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint")).pnt().xy()
+ aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint")).pnt().xy()
+ aLineDir = aLineEnd.decreased(aLineStart)
+ aLineLen = aLineEnd.distance(aLineStart)
+ aPntDir = aPoint.xy().decreased(aLineStart)
+ return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
+
def lastSubFeature(theSketch, theKind):
"""
obtains last feature of given kind from the sketch
aSub = theSketch.subFeature(anIndex)
if (aSub.getKind() == theKind):
return aSub
+
+def toSketchFeature(theEntity):
+ """ Converts entity to sketch feature if possible
+ """
+ if issubclass(type(theEntity), ModelHighAPI.ModelHighAPI_Interface):
+ return theEntity.feature()
+ else:
+ return theEntity
+
+def toPoint(thePoint):
+ if issubclass(type(thePoint), GeomDataAPI_Point2D):
+ return thePoint.pnt()
+ else:
+ aPoint = toSketchFeature(thePoint)
+ return geomDataAPI_Point2D(aPoint.attribute("PointCoordinates")).pnt()
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)
aSession.startOperation()
anArcStartPoint.setValue(sx, sy+aDelta) # move start point
aSession.finishOperation()
- model.assertSketchArc(aSketchArc)
+ model.assertArcValidity(aSketchArc)
for aDelta in range(20, -1, -1):
aSession.startOperation()
anArcStartPoint.setValue(sx, sy+aDelta) # move start point
aSession.finishOperation()
- model.assertSketchArc(aSketchArc)
+ model.assertArcValidity(aSketchArc)
#=========================================================================
# Test that movement of end point of arc does not break the arc
#=========================================================================
aSession.startOperation()
anArcEndPoint.setValue(sx+aDelta, sy) # move end point
aSession.finishOperation()
- model.assertSketchArc(aSketchArc)
+ model.assertArcValidity(aSketchArc)
for aDelta in range(20, -1, -1):
aSession.startOperation()
anArcEndPoint.setValue(sx+aDelta, sy) # move end point
aSession.finishOperation()
- model.assertSketchArc(aSketchArc)
+ model.assertArcValidity(aSketchArc)
__updated__ = "2014-10-28"
-def distancePointLine(point, line):
- """
- subroutine to calculate distance between point and line
- result of calculated distance is has 10**-5 precision
- """
- aStartPoint = geomDataAPI_Point2D(line.attribute("StartPoint"))
- aEndPoint = geomDataAPI_Point2D(line.attribute("EndPoint"))
- # orthogonal direction
- aDirX = -(aEndPoint.y() - aStartPoint.y())
- aDirY = (aEndPoint.x() - aStartPoint.x())
- aLen = math.sqrt(aDirX**2 + aDirY**2)
- aDirX = aDirX / aLen
- aDirY = aDirY / aLen
- aVecX = point.x() - aStartPoint.x()
- aVecY = point.y() - aStartPoint.y()
- return round(math.fabs(aVecX * aDirX + aVecY * aDirY), 5)
-
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
#=========================================================================
# Add distance between point and line
#=========================================================================
PT_LINE_DIST = 50.
-aDist = distancePointLine(aSketchPointCoords, aSketchLine)
+aDist = model.distancePointLine(aSketchPointCoords, aSketchLine)
aSession.startOperation()
aConstraint = aSketchFeature.addFeature("SketchConstraintDistance")
aDistance = aConstraint.real("ConstraintValue")
aSession.startOperation()
aDistance.setValue(PT_LINE_DIST)
aSession.finishOperation()
-assert (math.fabs(distancePointLine(aSketchPointCoords, aSketchLine) - PT_LINE_DIST) < 1.e-10)
+assert (math.fabs(model.distancePointLine(aSketchPointCoords, aSketchLine) - PT_LINE_DIST) < 1.e-10)
assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# Set distance between line boundaries
__updated__ = "2015-03-17"
-def distancePointLine(point, line):
- """
- subroutine to calculate distance between point and line
- result of calculated distance is has 10**-5 precision
- """
- aStartPoint = geomDataAPI_Point2D(line.attribute("StartPoint"))
- aEndPoint = geomDataAPI_Point2D(line.attribute("EndPoint"))
- # orthogonal direction
- aDirX = -(aEndPoint.y() - aStartPoint.y())
- aDirY = (aEndPoint.x() - aStartPoint.x())
- aLen = math.sqrt(aDirX**2 + aDirY**2)
- aDirX = aDirX / aLen
- aDirY = aDirY / aLen
- aVecX = point.x() - aStartPoint.x()
- aVecY = point.y() - aStartPoint.y()
- return round(math.fabs(aVecX * aDirX + aVecY * aDirY), 5)
-
def checkArcLineTangency(theArc, theLine):
"""
subroutine to check that the line is tangent to arc/circle
aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
aStartPnt = geomDataAPI_Point2D(theArc.attribute("start_point"))
aRadius = model.distancePointPoint(aStartPnt, aCenter)
- aDist = distancePointLine(aCenter, theLine)
+ aDist = model.distancePointLine(aCenter, theLine)
assert math.fabs(aDist - aRadius) < 2.e-5, "aDist = {0}, aRadius = {1}".format(aDist, aRadius)
def checkArcArcTangency(theArc1, theArc2):
subroutine to verify position of last arc in the sketch
"""
aLastArc = model.lastSubFeature(theSketch, "SketchArc")
- aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
- aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point"))
- aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point"))
- if len(theCenter):
- verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1])
- if len(theStart):
- verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
- if len(theEnd):
- verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
- 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)
+ model.assertArc(aLastArc, theCenter, theStart, theEnd)
def verifyPointOnLine(thePoint, theLine):
- aDistance = distancePointLine(thePoint, theLine)
+ aDistance = model.distancePointLine(thePoint, theLine)
assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance)
def verifyPointOnCircle(thePoint, theCircular):
return
assert math.fabs(model.distancePointPoint(aCenterPoint, thePoint) - aRadius) < TOLERANCE
-def distancePointLine(thePoint, theLine):
- aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
- aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
- aLineDir = aLineEnd.decreased(aLineStart)
- aLineLen = aLineEnd.distance(aLineStart)
- aPntDir = thePoint.pnt().xy().decreased(aLineStart)
- return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
aEnd.setValue(aLineStart[0], aLineStart[1])
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 8), "Number of subs {}".format(aSketchFeature.numberOfSubs())
-verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1])
+model.assertPoint(aPointCoord, aPointCoordinates)
verifyLastArc(aSketchFeature, [aPrevArcStart.x(), aPrevArcStart.y()], aPointCoordinates, [])
model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 12), "Number of subs {}".format(aSketchFeature.numberOfSubs())
# check connected features do not change their positions
-verifyPointCoordinates(aPrevArcCenter, aPrevArcCenterXY[0], aPrevArcCenterXY[1])
-verifyPointCoordinates(aPrevArcStart, aPrevArcStartXY[0], aPrevArcStartXY[1])
-verifyPointCoordinates(aPrevArcEnd, aPrevArcEndXY[0], aPrevArcEndXY[1])
-verifyPointCoordinates(aLineStartPoint, aLineStart[0], aLineStart[1])
-verifyPointCoordinates(aLineEndPoint, aLineEnd[0], aLineEnd[1])
+model.assertArc(aPrevArc, aPrevArcCenterXY, aPrevArcStartXY, aPrevArcEndXY)
+model.assertLine(aLine, aLineStart, aLineEnd)
# verify newly created arc
anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
subroutine to verify position of last arc in the sketch
"""
aLastArc = model.lastSubFeature(theSketch, "SketchArc")
- aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
- aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point"))
- aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point"))
- if len(theCenter):
- verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1])
- if len(theStart):
- verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
- if len(theEnd):
- verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
- 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)
+ model.assertArc(aLastArc, theCenter, theStart, theEnd)
def verifyTangent(theFeature1, theFeature2):
anArcs = []
aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
aRadius = model.distancePointPoint(aStart, aCenter)
- aDistCL = distancePointLine(aCenter, theLine)
+ aDistCL = model.distancePointLine(aCenter, theLine)
assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Arc and line do not tangent"
-def distancePointLine(thePoint, theLine):
- aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
- aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
- aLineDir = aLineEnd.decreased(aLineStart)
- aLineLen = aLineEnd.distance(aLineStart)
- aPntDir = thePoint.pnt().xy().decreased(aLineStart)
- return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
def verifyPointOnLine(thePoint, theLine):
- aDistance = distancePointLine(thePoint, theLine)
+ aDistance = model.distancePointLine(thePoint, theLine)
assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance)
"""
aLastArc = model.lastSubFeature(theSketch, "SketchArc")
aCenter = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
- verifyPointCoordinates(aCenter, theX, theY)
+ model.assertPoint(aCenter, [theX, theY])
aRadius = aLastArc.real("radius")
assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
-def verifyPointCoordinates(thePoint, theX, theY):
- assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
-
def verifyPointOnArc(thePoint, theArc):
aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
aDistCP = model.distancePointPoint(aCenter, thePoint)
def verifyTangentArcLine(theArc, theLine):
aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
aRadius = theArc.real("radius").value()
- aDistCL = distancePointLine(aCenter, theLine)
+ aDistCL = model.distancePointLine(aCenter, theLine)
assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent"
-def distancePointLine(thePoint, theLine):
- aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
- aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
- aLineDir = aLineEnd.decreased(aLineStart)
- aLineLen = aLineEnd.distance(aLineStart)
- aPntDir = thePoint.pnt().xy().decreased(aLineStart)
- return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
#=========================================================================
# Start of test
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 7)
# check the points do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
-verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1])
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
+model.assertPoint(aPointCoord, aPointCoodinates)
+model.assertPoint(aStartPnt, aLineStart)
# check newly created arc passes through the points
anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
verifyPointOnArc(aPrevCenter, anArc)
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 9)
# check the points do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
-verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1])
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
+model.assertPoint(aPointCoord, aPointCoodinates)
+model.assertPoint(aStartPnt, aLineStart)
# check sub-features
model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 1)
subroutine to verify position of last arc in the sketch
"""
aLastArc = model.lastSubFeature(theSketch, "SketchArc")
- aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
- aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point"))
- aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point"))
- if len(theCenter):
- verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1])
- if len(theStart):
- verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
- if len(theEnd):
- verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
- 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)
+ model.assertArc(aLastArc, theCenter, theStart, theEnd)
#=========================================================================
subroutine to verify position of last circle in the sketch
"""
aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
- aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
- verifyPointCoordinates(aCenter, theX, theY)
- aRadius = aLastCircle.real("circle_radius")
- assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
-
-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)
+ model.assertCircle(aLastCircle, [theX, theY], theR)
def verifyPointOnLine(thePoint, theLine):
- aDistance = distancePointLine(thePoint, theLine)
+ aDistance = model.distancePointLine(thePoint, theLine)
assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance)
def verifyTangentCircles(theCircle1, theCircle2):
aRDiff = math.fabs(aRadius1 - aRadius2)
assert math.fabs(aRSum - aDistCC) < TOLERANCE or math.fabs(aRDiff - aDistCC) < TOLERANCE, "Circles do not tangent"
-def distancePointLine(thePoint, theLine):
- aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
- aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
- aLineDir = aLineEnd.decreased(aLineStart)
- aLineLen = aLineEnd.distance(aLineStart)
- aPntDir = thePoint.pnt().xy().decreased(aLineStart)
- return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
#=========================================================================
# Start of test
aRadius = model.distancePointPoint(aPrevCenter, aPointCoord)
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 6)
-verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1])
+model.assertPoint(aPointCoord, aPointCoordinates)
verifyLastCircle(aSketchFeature, aPointCoord.x(), aPointCoord.y(), aRadius)
model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 2)
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 10)
# check connected features do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
assert(aPrevCircle.real("circle_radius").value() == aPrevRadius)
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
-verifyPointCoordinates(aEndPnt, aLineEnd[0], aLineEnd[1])
+model.assertLine(aLine, aLineStart, aLineEnd)
# verify newly created circle
aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
-verifyPointCoordinates(aCenter, anExpectedCenter[0], anExpectedCenter[1])
+model.assertPoint(aCenter, anExpectedCenter)
verifyPointOnLine(aCenter, aLine)
verifyTangentCircles(aCircle, aPrevCircle)
model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
subroutine to verify position of last circle in the sketch
"""
aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
- aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
- verifyPointCoordinates(aCenter, theX, theY)
- aRadius = aLastCircle.real("circle_radius")
- assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
-
-def verifyPointCoordinates(thePoint, theX, theY):
- assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
+ model.assertCircle(aLastCircle, [theX, theY], theR)
def verifyPointOnCircle(thePoint, theCircle):
aCircleCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
def verifyTangentCircleLine(theCircle, theLine):
aCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
aRadius = theCircle.real("circle_radius").value()
- aDistCL = distancePointLine(aCenter, theLine)
+ aDistCL = model.distancePointLine(aCenter, theLine)
assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent"
-def distancePointLine(thePoint, theLine):
- aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
- aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
- aLineDir = aLineEnd.decreased(aLineStart)
- aLineLen = aLineEnd.distance(aLineStart)
- aPntDir = thePoint.pnt().xy().decreased(aLineStart)
- return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
#=========================================================================
# Start of test
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 7)
# check the points do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
-verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1])
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
+model.assertPoint(aPointCoord, aPointCoordinates)
+model.assertPoint(aStartPnt, aLineStart)
# check newly created circle passes through the points
aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
verifyPointOnCircle(aPrevCenter, aCircle)
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 12)
# check the tangent entities do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
assert (aPrevCircle.real("circle_radius").value() == aPrevCircleRadius)
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
-verifyPointCoordinates(aEndPnt, aLineEnd[0], aLineEnd[1])
-verifyPointCoordinates(anArcCenterPnt, anArcCenter[0], anArcCenter[1])
-verifyPointCoordinates(anArcStartPnt, anArcStart[0], anArcStart[1])
-verifyPointCoordinates(anArcEndPnt, anArcEnd[0], anArcEnd[1])
+model.assertLine(aLine, aLineStart, aLineEnd)
+model.assertArc(anArc, anArcCenter, anArcStart, anArcEnd)
# check newly created circle passes through the points
aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
verifyTangentCircles(aCircle, aPrevCircle)
subroutine to verify position of last circle in the sketch
"""
aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
- aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
- verifyPointCoordinates(aCenter, theX, theY)
- aRadius = aLastCircle.real("circle_radius")
- assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
-
-def verifyPointCoordinates(thePoint, theX, theY):
- assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
+ model.assertCircle(aLastCircle, [theX, theY], theR)
#=========================================================================
def checkArcLineSmoothness(theArc, theLine):
aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
- aDistance = distancePointLine(aCenter, theLine)
+ aDistance = model.distancePointLine(aCenter, theLine)
aRadius = arcRadius(theArc)
assert(math.fabs(aRadius - aDistance) < TOLERANCE)
aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
return model.distancePointPoint(aCenter, aStart)
-def distancePointLine(thePoint, theLine):
- aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint"))
- aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint"))
- aLength = model.distancePointPoint(aLineStart, aLineEnd)
-
- aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y()
- aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y()
- aCross = aDir1x * aDir2y - aDir1y * aDir2x
- return math.fabs(aCross) / aLength
-
#=========================================================================
# Initialization of the test
def isArcLineSmooth(theArc, theLine, theTolerance):
aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
- aDistance = distancePointLine(aCenter, theLine)
+ aDistance = model.distancePointLine(aCenter, theLine)
aRadius = arcRadius(theArc)
return math.fabs(aRadius - aDistance) < theTolerance
aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
return model.distancePointPoint(aCenter, aStart)
-def distancePointLine(thePoint, theLine):
- aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint"))
- aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint"))
- aLength = model.distancePointPoint(aLineStart, aLineEnd)
- aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y()
- aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y()
- aCross = aDir1x * aDir2y - aDir1y * aDir2x
- return math.fabs(aCross) / aLength
-
class TestFilletInteracting(unittest.TestCase):