You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
254 lines
9.9 KiB
254 lines
9.9 KiB
#include "signutils.h"
|
|
#include <QtDebug>
|
|
#include "sw_log.h"
|
|
|
|
QPointF CGPointZero = QPointF(0,0);
|
|
|
|
void CalculatePointcutWihtPoint(SWAnnotPath *curAnnotPath,CGPoint point, float radius, bool stroke, bool circle,qint64 ts)
|
|
{
|
|
/**
|
|
进行切点计算
|
|
*/
|
|
SWRealPoint curPenPoint;
|
|
curPenPoint.realPoint = point;
|
|
curPenPoint.radius = radius;
|
|
curPenPoint.timestamp = ts;
|
|
curAnnotPath->points.append(curPenPoint);
|
|
int realPointCount = curAnnotPath->points.count();
|
|
|
|
/**
|
|
* 判断点数大于2进行 防抖处理
|
|
*/
|
|
if (realPointCount > 3)
|
|
{
|
|
|
|
SWRealPoint penPoint0 = curAnnotPath->points.at(realPointCount - 3);
|
|
SWRealPoint penPoint1 = curAnnotPath->points.at(realPointCount - 2);
|
|
SWRealPoint penPoint2 = curAnnotPath->points.at(realPointCount - 1);
|
|
SWPosStatus ret = CalculateShake(SWPosPointMake(penPoint0.realPoint.x(), penPoint0.realPoint.y(),penPoint0.radius),
|
|
SWPosPointMake(penPoint1.realPoint.x(), penPoint1.realPoint.y(),penPoint1.radius),
|
|
SWPosPointMake(penPoint2.realPoint.x(), penPoint2.realPoint.y(),penPoint2.radius));
|
|
if (ret == SWPosRetSuccess)
|
|
{
|
|
if (penPoint0.circleCount != 0)
|
|
{
|
|
|
|
penPoint0.circleCount = 0;
|
|
penPoint0.circlePoints.clear();
|
|
}
|
|
penPoint0.pLeftBottomPoint = CGPointZero;
|
|
penPoint0.pRightBottomPoint = CGPointZero;
|
|
penPoint0.PLeftIntersectPoint = CGPointZero;
|
|
penPoint0.PRightIntersectPoint = CGPointZero;
|
|
if (curAnnotPath->isShake)
|
|
{
|
|
/**
|
|
* 判断边际值停止纠偏
|
|
**/
|
|
double distance = GetDistanceBetweenPoint(penPoint0.realPoint,penPoint2.realPoint);
|
|
if (distance >= 3) {
|
|
|
|
curAnnotPath->isShake = false;
|
|
|
|
} else {
|
|
|
|
curAnnotPath->points.removeAt(realPointCount - 2);
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
curAnnotPath->points.removeAt(realPointCount - 2);
|
|
curAnnotPath->isShake = true;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
curAnnotPath->isShake = false;
|
|
}
|
|
}
|
|
|
|
realPointCount = curAnnotPath->points.count();
|
|
|
|
if (realPointCount == 2)
|
|
{
|
|
SWRealPoint penPoint0 = curAnnotPath->points.at(0);
|
|
SWRealPoint penPoint1 = curAnnotPath->points.at(1);
|
|
SWPosRet ret = SWGetTangentcurPoint(SWPosPointMake(penPoint0.realPoint.x(), penPoint0.realPoint.y(), penPoint0.radius),
|
|
SWPosPointMake(penPoint1.realPoint.x(), penPoint1.realPoint.y(), penPoint1.radius),
|
|
SWLineMakeZero(), SWLineMakeZero(),circle ? 1 : 0);
|
|
|
|
if (ret.status == SWPosRetSuccess)
|
|
{
|
|
|
|
if (ret.circleCount > 0)
|
|
{
|
|
|
|
curAnnotPath->points[0].circleCount = ret.circleCount;
|
|
curAnnotPath->points[0].circlePoints = ret.circlePoints;
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
curAnnotPath->points[0].pLeftBottomPoint = CGPointMake(ret.prevLeftPoint.x, ret.prevLeftPoint.y);
|
|
curAnnotPath->points[0].pRightBottomPoint = CGPointMake(ret.prevRightPoint.x, ret.prevRightPoint.y);
|
|
curAnnotPath->points[1].pLeftTopPoint = CGPointMake(ret.curLeftPoint.x, ret.curLeftPoint.y);
|
|
curAnnotPath->points[1].pRightTopPoint = CGPointMake(ret.curRightPoint.x, ret.curRightPoint.y);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
curAnnotPath->points.removeLast();
|
|
}
|
|
|
|
}
|
|
else if (realPointCount > 2)
|
|
{
|
|
|
|
SWRealPoint penPoint0 = curAnnotPath->points.at(realPointCount - 3);
|
|
SWRealPoint penPoint1 = curAnnotPath->points.at(realPointCount - 2);
|
|
SWRealPoint penPoint2 = curAnnotPath->points.at(realPointCount - 1);
|
|
if (penPoint0.circleCount == 0)
|
|
{
|
|
|
|
CGPoint penPoint0Left = CGPointEqualToPoint(penPoint0.PLeftIntersectPoint, CGPointZero) ? penPoint0.pLeftBottomPoint : penPoint0.PLeftIntersectPoint;
|
|
|
|
CGPoint penPoint1Left = CGPointEqualToPoint(penPoint1.PLeftIntersectPoint, CGPointZero) ? penPoint1.pLeftTopPoint : penPoint1.PLeftIntersectPoint;
|
|
|
|
CGPoint penPoint0Right = CGPointEqualToPoint(penPoint0.PRightIntersectPoint, CGPointZero) ? penPoint0.pRightBottomPoint : penPoint0.PRightIntersectPoint;
|
|
|
|
CGPoint penPoint1Right = CGPointEqualToPoint(penPoint1.PRightIntersectPoint, CGPointZero) ? penPoint1.pRightTopPoint : penPoint1.PRightIntersectPoint;
|
|
|
|
SWPosRet ret = SWGetTangentcurPoint(SWPosPointMake(penPoint1.realPoint.x(), penPoint1.realPoint.y(), penPoint1.radius), SWPosPointMake(penPoint2.realPoint.x(), penPoint2.realPoint.y(), penPoint2.radius), SWLineMake(penPoint0Left.x(), penPoint0Left.y(), penPoint1Left.x(), penPoint1Left.y()), SWLineMake(penPoint0Right.x(), penPoint0Right.y(), penPoint1Right.x(), penPoint1Right.y()),circle ? 1 : 0);
|
|
if (ret.status == SWPosRetSuccess )
|
|
{
|
|
|
|
if (ret.circleCount > 0)
|
|
{
|
|
|
|
curAnnotPath->points[realPointCount - 2].circleCount = ret.circleCount;
|
|
curAnnotPath->points[realPointCount - 2].circlePoints = ret.circlePoints;
|
|
|
|
}
|
|
else
|
|
{
|
|
curAnnotPath->points[realPointCount - 2].PLeftIntersectPoint = CGPointMake(ret.prevLeftIntersectPoint.x, ret.prevLeftIntersectPoint.y);
|
|
curAnnotPath->points[realPointCount - 2].PRightIntersectPoint = CGPointMake(ret.prevRightIntersectPoint.x, ret.prevRightIntersectPoint.y);
|
|
curAnnotPath->points[realPointCount - 2].pLeftBottomPoint = CGPointMake(ret.prevLeftPoint.x, ret.prevLeftPoint.y);
|
|
curAnnotPath->points[realPointCount - 2].pRightBottomPoint = CGPointMake(ret.prevRightPoint.x, ret.prevRightPoint.y);
|
|
curAnnotPath->points[realPointCount - 1].pLeftTopPoint = CGPointMake(ret.curLeftPoint.x, ret.curLeftPoint.y);
|
|
curAnnotPath->points[realPointCount - 1].pRightTopPoint = CGPointMake(ret.curRightPoint.x, ret.curRightPoint.y);
|
|
}
|
|
}
|
|
else if (ret.status == SWPosRetFail)
|
|
{
|
|
curAnnotPath->points.removeLast();
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
SWPosRet ret = SWGetTangentcurPoint(SWPosPointMake(penPoint1.realPoint.x(), penPoint1.realPoint.y(), penPoint1.radius), SWPosPointMake(penPoint2.realPoint.x(), penPoint2.realPoint.y(), penPoint2.radius), SWLineMakeZero(), SWLineMakeZero(),circle ? 1 : 0);
|
|
if (ret.status == SWPosRetSuccess)
|
|
{
|
|
|
|
if (ret.circleCount > 0)
|
|
{
|
|
|
|
curAnnotPath->points[realPointCount - 2].circleCount = ret.circleCount;
|
|
curAnnotPath->points[realPointCount - 2].circlePoints = ret.circlePoints;
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
curAnnotPath->points[realPointCount - 2].pLeftBottomPoint = CGPointMake(ret.prevLeftPoint.x, ret.prevLeftPoint.y);
|
|
curAnnotPath->points[realPointCount - 2].pRightBottomPoint = CGPointMake(ret.prevRightPoint.x, ret.prevRightPoint.y);
|
|
curAnnotPath->points[realPointCount - 1].pLeftTopPoint = CGPointMake(ret.curLeftPoint.x, ret.curLeftPoint.y);
|
|
curAnnotPath->points[realPointCount - 1].pRightTopPoint = CGPointMake(ret.curRightPoint.x, ret.curRightPoint.y);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
curAnnotPath->points.removeLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
float GetDistanceBetweenPoint(QPointF start, QPointF end)
|
|
{
|
|
return sqrt(pow(start.y()-end.y(), 2.0) + pow(start.x()-end.x(), 2.0));
|
|
}
|
|
|
|
|
|
bool CGPointEqualToPoint(const CGPoint &point1, const CGPoint &point2)
|
|
{
|
|
return point1.x() == point2.x() && point1.y() == point2.y();
|
|
}
|
|
|
|
bool GetPointValid(SWRealPoint penPoint)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
CGPoint ConvertToCGPoint(SWPointcut cPoint)
|
|
{
|
|
return CGPointMake(cPoint.x, cPoint.y);
|
|
}
|
|
|
|
void AddStartPathElement(QList<Element> &elementList)
|
|
{
|
|
Element ele(StartFigure);
|
|
elementList.append(ele);
|
|
}
|
|
|
|
void AddMoveToElement(QList<Element> &elementList, QPointF point)
|
|
{
|
|
// qDebug() << __FUNCTION__ << point;
|
|
// SW_Log::Get()->info(QString("====AddMoveToElement x: %1 y: %2====").arg(point.x()).arg(point.y()));
|
|
|
|
Element ele(MoveToElement);
|
|
ele.AddEndPoint(point);
|
|
elementList.append(ele);
|
|
}
|
|
|
|
void AddCurveToElement(QList<Element> &elementList, QPointF control, QPointF control2, QPointF end)
|
|
{
|
|
// SW_Log::Get()->info(QString("====AddCurveToElement cx: %1 cy: %2 c2x: %3 c2y: %4 ex: %5 ey: %6====")
|
|
// .arg(control.x()).arg(control.y()).arg(control2.x()).arg(control2.y()).arg(end.x()).arg(end.y()));
|
|
Element ele(CurveToElement);
|
|
ele.AddEndPoint(end);
|
|
ele.AddControlPoint(control);
|
|
ele.AddControlPoint2(control2);
|
|
elementList.append(ele);
|
|
}
|
|
|
|
void AddCurveToElement(QList<Element> &elementList, qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty)
|
|
{
|
|
// SW_Log::Get()->info(QString("====AddCurveToElement cx: %1 cy: %2 c2x: %3 c2y: %4 ex: %5 ey: %6====")
|
|
// .arg(ctrlPt1x).arg(ctrlPt1y).arg(ctrlPt2x).arg(ctrlPt2y).arg(endPtx).arg(endPty));
|
|
AddCurveToElement(elementList,QPointF(ctrlPt1x,ctrlPt1y),QPointF(ctrlPt2x,ctrlPt2y),QPointF(endPtx,endPty));
|
|
}
|
|
|
|
void AddQuadToElement(QList<Element> &elementList, QPointF control, QPointF end)
|
|
{
|
|
// SW_Log::Get()->info(QString("====AddQuadToElement cx: %1 cy: %2 ex: %5 ey: %6====")
|
|
// .arg(control.x()).arg(control.y()).arg(end.x()).arg(end.y()));
|
|
Element ele(QuadToElement);
|
|
ele.AddEndPoint(end);
|
|
ele.AddControlPoint(control);
|
|
elementList.append(ele);
|
|
}
|