2019-09-03 16:46:09 +02:00
|
|
|
|
/************************************************************************
|
2016-11-03 19:15:53 +01:00
|
|
|
|
**
|
|
|
|
|
** @file
|
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
|
** @date 3 11, 2016
|
|
|
|
|
**
|
|
|
|
|
** @brief
|
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-11-03 19:15:53 +01:00
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
|
** Copyright (C) 2016 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2016-11-03 19:15:53 +01:00
|
|
|
|
**
|
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
** (at your option) any later version.
|
|
|
|
|
**
|
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
|
**
|
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
**
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "vabstractpiece.h"
|
2016-11-09 14:53:22 +01:00
|
|
|
|
#include "vabstractpiece_p.h"
|
2020-10-15 17:05:21 +02:00
|
|
|
|
#include "../vmisc/vabstractvalapplication.h"
|
2016-11-19 17:27:06 +01:00
|
|
|
|
#include "../vgeometry/vpointf.h"
|
2022-10-28 15:16:02 +02:00
|
|
|
|
#include "../vgeometry/vlayoutplacelabel.h"
|
|
|
|
|
#include "../vgeometry/varc.h"
|
2018-10-22 13:43:06 +02:00
|
|
|
|
#include "../ifc/exception/vexception.h"
|
2020-01-16 16:34:08 +01:00
|
|
|
|
#include "../vmisc/compatibility.h"
|
2019-01-28 19:35:10 +01:00
|
|
|
|
#include "../vpatterndb/floatItemData/vgrainlinedata.h"
|
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
|
#include "../vpatterndb/calculator.h"
|
2019-08-29 14:01:27 +02:00
|
|
|
|
#include "testpath.h"
|
2019-11-03 09:01:32 +01:00
|
|
|
|
#include "vrawsapoint.h"
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
|
|
|
|
#include <QLineF>
|
|
|
|
|
#include <QSet>
|
|
|
|
|
#include <QVector>
|
2017-01-11 13:53:16 +01:00
|
|
|
|
#include <QPainterPath>
|
2018-09-19 14:16:29 +02:00
|
|
|
|
#include <QTemporaryFile>
|
2019-08-07 16:53:18 +02:00
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
2022-08-13 18:26:55 +02:00
|
|
|
|
#include <QtMath>
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
2019-07-01 11:26:08 +02:00
|
|
|
|
const quint32 VAbstractPieceData::streamHeader = 0x05CDD73A; // CRC-32Q string "VAbstractPieceData"
|
2020-04-22 13:32:25 +02:00
|
|
|
|
const quint16 VAbstractPieceData::classVersion = 3;
|
2019-07-01 11:26:08 +02:00
|
|
|
|
|
2020-03-25 14:28:23 +01:00
|
|
|
|
const qreal maxL = 3.5;
|
2018-09-13 15:46:04 +02:00
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
2019-08-31 08:32:43 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
inline auto IsSameDirection(QPointF p1, QPointF p2, QPointF px) -> bool
|
2019-08-31 08:32:43 +02:00
|
|
|
|
{
|
|
|
|
|
return qAbs(QLineF(p1, p2).angle() - QLineF(p1, px).angle()) < 0.001;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:25:22 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-09-13 15:46:04 +02:00
|
|
|
|
// Do we create a point outside of a path?
|
2022-08-12 17:50:13 +02:00
|
|
|
|
inline auto IsOutsidePoint(QPointF p1, QPointF p2, QPointF px) -> bool
|
2018-09-13 15:46:04 +02:00
|
|
|
|
{
|
2019-08-31 08:32:43 +02:00
|
|
|
|
QLineF seg1(p1, p2);
|
|
|
|
|
QLineF seg2(p1, px);
|
|
|
|
|
|
|
|
|
|
return IsSameDirection(p1, p2, px) && seg2.length() >= seg1.length();
|
2018-09-13 15:46:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-17 14:06:46 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
Q_DECL_CONSTEXPR auto PointPosition(const QPointF &p, const QLineF &line) -> qreal
|
2017-12-17 14:06:46 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return (line.p2().x() - line.p1().x()) * (p.y() - line.p1().y()) -
|
|
|
|
|
(line.p2().y() - line.p1().y()) * (p.x() - line.p1().x());
|
2017-12-17 14:06:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-10 11:53:02 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto AngleByLength(QVector<VRawSAPoint> points, QPointF p1, QPointF p2, QPointF p3,
|
|
|
|
|
const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2, const VSAPoint &p,
|
|
|
|
|
qreal width, bool *needRollback = nullptr) -> QVector<VRawSAPoint>
|
2016-11-10 11:53:02 +01:00
|
|
|
|
{
|
2019-01-07 17:20:36 +01:00
|
|
|
|
if (needRollback != nullptr)
|
|
|
|
|
{
|
2019-01-09 16:46:02 +01:00
|
|
|
|
*needRollback = false;
|
2019-01-07 17:20:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
const QPointF sp1 = bigLine1.p1();
|
|
|
|
|
const QPointF sp3 = bigLine2.p2();
|
2018-09-13 16:31:14 +02:00
|
|
|
|
const qreal localWidth = p.MaxLocalSA(width);
|
2016-11-10 11:53:02 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), sp2) && IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), sp2) )
|
|
|
|
|
{
|
|
|
|
|
QLineF line(p2, sp2);
|
|
|
|
|
const qreal length = line.length();
|
|
|
|
|
if (length > localWidth*maxL)
|
|
|
|
|
{ // Cutting too long acut angle
|
|
|
|
|
line.setLength(localWidth);
|
|
|
|
|
QLineF cutLine(line.p2(), sp2); // Cut line is a perpendicular
|
2018-12-23 17:41:51 +01:00
|
|
|
|
cutLine.setLength(length); // Decided to take this length
|
2016-11-10 11:53:02 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
// We do not check intersection type because intersection must alwayse exist
|
|
|
|
|
QPointF px;
|
|
|
|
|
cutLine.setAngle(cutLine.angle()+90);
|
2020-01-16 16:34:08 +01:00
|
|
|
|
QLineF::IntersectType type = Intersects(QLineF(sp1, sp2), cutLine, &px);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"Couldn't find intersection with cut line.";
|
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(px, p.CurvePoint(), p.TurnPoint()));
|
2017-04-05 12:22:33 +02:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
cutLine.setAngle(cutLine.angle()-180);
|
2020-01-16 16:34:08 +01:00
|
|
|
|
type = Intersects(QLineF(sp2, sp3), cutLine, &px);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"Couldn't find intersection with cut line.";
|
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(px, p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{// The point just fine
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(sp2, p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
QLineF edge1(p2, p1);
|
|
|
|
|
QLineF edge2(p2, p3);
|
|
|
|
|
const qreal angle = edge1.angleTo(edge2);
|
|
|
|
|
|
2019-11-03 09:13:02 +01:00
|
|
|
|
if (angle > 180 && p.GetAngleType() != PieceNodeAngle::ByLengthCurve)
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
2020-07-31 15:31:27 +02:00
|
|
|
|
if (VGObject::IsPointOnLineSegment(sp2, bigLine2.p1(), bigLine2.p2()))
|
|
|
|
|
{
|
|
|
|
|
QLineF loop(bigLine1.p2(), sp2);
|
|
|
|
|
loop.setLength(loop.length() + accuracyPointOnLine*2.);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(loop.p2(), p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
points.append(VRawSAPoint(sp2, p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
points.append(VRawSAPoint(bigLine1.p2(), p.CurvePoint(), p.TurnPoint(), true));
|
2020-07-31 15:31:27 +02:00
|
|
|
|
|
|
|
|
|
loop = QLineF(bigLine2.p2(), sp2);
|
|
|
|
|
loop.setLength(loop.length() + localWidth);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(loop.p2(), p.CurvePoint(), p.TurnPoint(), true));
|
2020-07-31 15:31:27 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QLineF loop(sp2, bigLine1.p1());
|
|
|
|
|
loop.setLength(accuracyPointOnLine*2.);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(loop.p2(), p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
points.append(VRawSAPoint(sp2, p.CurvePoint(), p.TurnPoint()));
|
2020-07-31 15:31:27 +02:00
|
|
|
|
|
|
|
|
|
loop = QLineF(bigLine1.p1(), sp2);
|
|
|
|
|
loop.setLength(loop.length() + localWidth);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(loop.p2(), p.CurvePoint(), p.TurnPoint(), true));
|
|
|
|
|
points.append(VRawSAPoint(bigLine2.p1(), p.CurvePoint(), p.TurnPoint(), true));
|
2020-07-31 15:31:27 +02:00
|
|
|
|
}
|
2019-09-03 16:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (not IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), sp2))
|
|
|
|
|
{
|
|
|
|
|
if (p.GetAngleType() != PieceNodeAngle::ByLengthCurve)
|
2019-09-01 12:01:10 +02:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
bool success = false;
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = points;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.append(VRawSAPoint(bigLine1.p2(), p.CurvePoint(), p.TurnPoint()));
|
2019-09-03 16:46:09 +02:00
|
|
|
|
temp = VAbstractPiece::RollbackSeamAllowance(temp, bigLine2, &success);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
points = temp;
|
|
|
|
|
}
|
2019-09-01 12:01:10 +02:00
|
|
|
|
|
2019-09-03 16:46:09 +02:00
|
|
|
|
if (needRollback != nullptr)
|
|
|
|
|
{
|
|
|
|
|
*needRollback = not success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2019-01-07 17:20:36 +01:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(sp2, p.CurvePoint(), p.TurnPoint()));
|
2019-01-07 17:20:36 +01:00
|
|
|
|
}
|
2018-10-19 15:54:06 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
if (p.GetAngleType() != PieceNodeAngle::ByLengthCurve)
|
|
|
|
|
{
|
|
|
|
|
// Need to create artificial loop
|
|
|
|
|
QLineF loop1(sp2, sp1);
|
|
|
|
|
loop1.setLength(loop1.length()*0.2);
|
2017-04-05 12:22:33 +02:00
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
|
// Need for the main path rule
|
|
|
|
|
points.append(VRawSAPoint(loop1.p2(), p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
2019-09-03 16:46:09 +02:00
|
|
|
|
loop1.setAngle(loop1.angle() + 180);
|
|
|
|
|
loop1.setLength(localWidth);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(loop1.p2(), p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
points.append(VRawSAPoint(bigLine2.p1(), p.CurvePoint(), p.TurnPoint()));
|
2019-09-03 16:46:09 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(sp2, p.CurvePoint(), p.TurnPoint()));
|
2019-09-03 16:46:09 +02:00
|
|
|
|
}
|
2018-10-17 17:12:39 +02:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return points;
|
2017-05-16 14:16:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto AngleByIntersection(const QVector<VRawSAPoint> &points, QPointF p1, QPointF p2, QPointF p3,
|
|
|
|
|
const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2,
|
|
|
|
|
const VSAPoint &p, qreal width, bool *needRollback = nullptr) -> QVector<VRawSAPoint>
|
2017-05-16 14:16:50 +02:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
{
|
|
|
|
|
QLineF edge1(p2, p1);
|
|
|
|
|
QLineF edge2(p2, p3);
|
|
|
|
|
const qreal angle = edge1.angleTo(edge2);
|
|
|
|
|
|
|
|
|
|
if (angle > 180)
|
|
|
|
|
{
|
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 17:20:36 +01:00
|
|
|
|
if (needRollback != nullptr)
|
|
|
|
|
{
|
2019-01-09 16:46:02 +01:00
|
|
|
|
*needRollback = false;
|
2019-01-07 17:20:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:31:14 +02:00
|
|
|
|
const qreal localWidth = p.MaxLocalSA(width);
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> pointsIntr = points;
|
2017-05-16 14:16:50 +02:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
// First point
|
|
|
|
|
QLineF edge2(p2, p3);
|
2016-11-10 11:53:02 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
QPointF px;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
QLineF::IntersectType type = Intersects(edge2, bigLine1, &px);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), px))
|
|
|
|
|
{
|
|
|
|
|
if (QLineF(p2, px).length() > localWidth*maxL)
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(px, p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{// Because artificial loop can lead to wrong clipping we must rollback current seam allowance points
|
|
|
|
|
bool success = false;
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = pointsIntr;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.append(VRawSAPoint(bigLine1.p2(), p.CurvePoint(), p.TurnPoint()));
|
2019-09-10 12:17:06 +02:00
|
|
|
|
temp = VAbstractPiece::RollbackSeamAllowance(temp, edge2, &success);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
pointsIntr = temp;
|
|
|
|
|
}
|
2019-01-09 16:46:02 +01:00
|
|
|
|
|
|
|
|
|
if (needRollback != nullptr)
|
|
|
|
|
{
|
2019-09-01 12:01:10 +02:00
|
|
|
|
*needRollback = not success;
|
2019-01-09 16:46:02 +01:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Second point
|
|
|
|
|
QLineF edge1(p1, p2);
|
2020-01-16 16:34:08 +01:00
|
|
|
|
type = Intersects(edge1, bigLine2, &px);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), px))
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(px, p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(px, p.CurvePoint(), p.TurnPoint()));
|
2019-08-07 11:25:22 +02:00
|
|
|
|
|
2019-08-31 14:30:07 +02:00
|
|
|
|
QLineF allowance(p2, px);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
allowance.setLength(allowance.length() + localWidth * 3.);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(allowance.p2(), p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
pointsIntr.append(VRawSAPoint(bigLine2.p1(), p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pointsIntr;
|
2016-11-10 11:53:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-10 13:06:09 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto AngleByFirstSymmetry(const QVector<VRawSAPoint> &points, QPointF p1, QPointF p2, QPointF p3,
|
|
|
|
|
const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2,
|
|
|
|
|
const VSAPoint &p, qreal width, bool *needRollback = nullptr) -> QVector<VRawSAPoint>
|
2016-11-10 13:06:09 +01:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
{
|
|
|
|
|
QLineF edge1(p2, p1);
|
|
|
|
|
QLineF edge2(p2, p3);
|
|
|
|
|
const qreal angle = edge1.angleTo(edge2);
|
|
|
|
|
|
|
|
|
|
if (angle > 180)
|
|
|
|
|
{
|
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 17:20:36 +01:00
|
|
|
|
if (needRollback != nullptr)
|
|
|
|
|
{
|
2019-01-09 16:46:02 +01:00
|
|
|
|
*needRollback = false;
|
2019-01-07 17:20:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:32:38 +01:00
|
|
|
|
const QLineF axis = QLineF(p1, p2);
|
|
|
|
|
|
|
|
|
|
QLineF sEdge(VPointF::FlipPF(axis, bigLine2.p1()), VPointF::FlipPF(axis, bigLine2.p2()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
2019-02-12 13:51:21 +01:00
|
|
|
|
QPointF px1;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
QLineF::IntersectType type = Intersects(sEdge, bigLine1, &px1);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
2016-11-10 13:06:09 +01:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2016-11-10 13:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 13:51:21 +01:00
|
|
|
|
QPointF px2;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
type = Intersects(sEdge, bigLine2, &px2);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2019-02-12 13:51:21 +01:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
2016-11-10 13:06:09 +01:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
2019-01-09 16:46:02 +01:00
|
|
|
|
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> pointsIntr = points;
|
2019-02-12 13:51:21 +01:00
|
|
|
|
|
2019-02-13 15:32:38 +01:00
|
|
|
|
if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), px1))
|
2019-02-12 13:51:21 +01:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(px1, p.CurvePoint(), p.TurnPoint()));
|
2019-02-13 15:32:38 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{// Because artificial loop can lead to wrong clipping we must rollback current seam allowance points
|
|
|
|
|
bool success = false;
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = pointsIntr;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.append(VRawSAPoint(bigLine1.p2(), p.CurvePoint(), p.TurnPoint()));
|
2019-09-01 12:01:10 +02:00
|
|
|
|
temp = VAbstractPiece::RollbackSeamAllowance(temp, sEdge, &success);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
pointsIntr = temp;
|
|
|
|
|
}
|
2016-11-10 13:06:09 +01:00
|
|
|
|
|
2019-02-13 15:32:38 +01:00
|
|
|
|
if (needRollback != nullptr)
|
2019-02-12 13:51:21 +01:00
|
|
|
|
{
|
2019-09-01 12:01:10 +02:00
|
|
|
|
*needRollback = not success;
|
2016-11-10 13:06:09 +01:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
2019-02-13 15:32:38 +01:00
|
|
|
|
|
|
|
|
|
if (IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), px2))
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(px2, p.CurvePoint(), p.TurnPoint()));
|
2019-02-13 15:32:38 +01:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-02-13 15:32:38 +01:00
|
|
|
|
QLineF allowance(px2, p2);
|
|
|
|
|
allowance.setAngle(allowance.angle() + 90);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(px2, p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
pointsIntr.append(VRawSAPoint(allowance.p2(), p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
pointsIntr.append(VRawSAPoint(bigLine2.p1(), p.CurvePoint(), p.TurnPoint()));
|
2016-11-10 13:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return pointsIntr;
|
2016-11-10 13:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-03 19:15:53 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto AngleBySecondSymmetry(const QVector<VRawSAPoint> &points, QPointF p1, QPointF p2, QPointF p3,
|
|
|
|
|
const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2,
|
|
|
|
|
const VSAPoint &p, qreal width, bool *needRollback = nullptr) -> QVector<VRawSAPoint>
|
2016-11-03 19:15:53 +01:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
{
|
|
|
|
|
QLineF edge1(p2, p1);
|
|
|
|
|
QLineF edge2(p2, p3);
|
|
|
|
|
const qreal angle = edge1.angleTo(edge2);
|
|
|
|
|
|
|
|
|
|
if (angle > 180)
|
|
|
|
|
{
|
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 17:20:36 +01:00
|
|
|
|
if (needRollback != nullptr)
|
|
|
|
|
{
|
2019-01-09 16:46:02 +01:00
|
|
|
|
*needRollback = false;
|
2019-01-07 17:20:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:32:38 +01:00
|
|
|
|
const QLineF axis = QLineF(p3, p2);
|
|
|
|
|
|
|
|
|
|
QLineF sEdge(VPointF::FlipPF(axis, bigLine1.p1()), VPointF::FlipPF(axis, bigLine1.p2()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
2019-02-12 13:51:21 +01:00
|
|
|
|
QPointF px1;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
QLineF::IntersectType type = Intersects(sEdge, bigLine1, &px1);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
2016-11-03 19:15:53 +01:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 13:51:21 +01:00
|
|
|
|
QPointF px2;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
type = Intersects(sEdge, bigLine2, &px2);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2019-02-12 13:51:21 +01:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2016-11-03 19:15:53 +01:00
|
|
|
|
}
|
2019-01-09 16:46:02 +01:00
|
|
|
|
|
2019-02-12 13:51:21 +01:00
|
|
|
|
const qreal localWidth = p.MaxLocalSA(width);
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> pointsIntr = points;
|
2019-02-12 13:51:21 +01:00
|
|
|
|
|
2019-02-13 15:32:38 +01:00
|
|
|
|
if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), px1))
|
2019-02-12 13:51:21 +01:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(px1, p.CurvePoint(), p.TurnPoint()));
|
2019-02-13 15:32:38 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{// Because artificial loop can lead to wrong clipping we must rollback current seam allowance points
|
|
|
|
|
bool success = false;
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = pointsIntr;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.append(VRawSAPoint(bigLine1.p2(), p.CurvePoint(), p.TurnPoint()));
|
2019-09-01 12:01:10 +02:00
|
|
|
|
temp = VAbstractPiece::RollbackSeamAllowance(temp, sEdge, &success);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
pointsIntr = temp;
|
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
2019-02-13 15:32:38 +01:00
|
|
|
|
if (needRollback != nullptr)
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
2019-09-01 12:01:10 +02:00
|
|
|
|
*needRollback = not success;
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
2019-02-13 15:32:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), px2))
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(px2, p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-02-13 15:32:38 +01:00
|
|
|
|
QLineF allowance(p2, px2);
|
|
|
|
|
allowance.setLength(p.GetSAAfter(width)*0.98);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(allowance.p2(), p.CurvePoint(), p.TurnPoint()));
|
2019-02-13 15:32:38 +01:00
|
|
|
|
allowance.setLength(allowance.length() + localWidth * 3.);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsIntr.append(VRawSAPoint(allowance.p2(), p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
pointsIntr.append(VRawSAPoint(bigLine2.p1(), p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pointsIntr;
|
2016-11-03 19:15:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto AngleByFirstRightAngle(const QVector<VRawSAPoint> &points, QPointF p1, QPointF p2, QPointF p3,
|
|
|
|
|
const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2,
|
|
|
|
|
const VSAPoint &p, qreal width, bool *needRollback = nullptr) -> QVector<VRawSAPoint>
|
2016-11-03 19:15:53 +01:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
{
|
|
|
|
|
QLineF edge1(p2, p1);
|
|
|
|
|
QLineF edge2(p2, p3);
|
|
|
|
|
const qreal angle = edge1.angleTo(edge2);
|
|
|
|
|
|
2019-09-06 10:12:01 +02:00
|
|
|
|
if (angle > 270)
|
2019-09-03 16:46:09 +02:00
|
|
|
|
{
|
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:31:14 +02:00
|
|
|
|
const qreal localWidth = p.MaxLocalSA(width);
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> pointsRA = points;
|
2018-09-13 16:16:40 +02:00
|
|
|
|
QLineF edge(p1, p2);
|
|
|
|
|
|
|
|
|
|
QPointF px;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
QLineF::IntersectType type = Intersects(edge, bigLine2, &px);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
2016-11-03 19:15:53 +01:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2016-11-03 19:15:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
QLineF seam(px, p1);
|
|
|
|
|
seam.setAngle(seam.angle()-90);
|
|
|
|
|
seam.setLength(p.GetSABefore(width));
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
2019-09-06 10:12:01 +02:00
|
|
|
|
if (IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), seam.p1()) && IsSameDirection(p1, p2, px))
|
2016-11-03 19:15:53 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (QLineF(p2, px).length() > localWidth*maxL)
|
2016-11-03 19:15:53 +01:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2016-11-03 19:15:53 +01:00
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsRA.append(VRawSAPoint(seam.p2(), p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
pointsRA.append(VRawSAPoint(seam.p1(), p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-06 10:12:01 +02:00
|
|
|
|
QLineF edge1(p2, p1);
|
|
|
|
|
QLineF edge2(p2, p3);
|
|
|
|
|
const qreal angle = edge1.angleTo(edge2);
|
|
|
|
|
|
|
|
|
|
if (angle > 180)
|
|
|
|
|
{
|
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
|
|
|
|
}
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsRA.append(VRawSAPoint(seam.p2(), p.CurvePoint(), p.TurnPoint()));
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
|
QLineF loopLine(px, sp2);
|
|
|
|
|
const qreal length = loopLine.length()*0.98;
|
|
|
|
|
loopLine.setLength(length);
|
2019-09-06 10:12:01 +02:00
|
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
|
QLineF tmp(seam.p2(), seam.p1());
|
|
|
|
|
tmp.setLength(tmp.length()+length);
|
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
|
pointsRA.append(VRawSAPoint(tmp.p2(), p.CurvePoint(), p.TurnPoint()));
|
|
|
|
|
pointsRA.append(VRawSAPoint(loopLine.p2(), p.CurvePoint(), p.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return pointsRA;
|
|
|
|
|
}
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto AngleBySecondRightAngle(QVector<VRawSAPoint> points, QPointF p1, QPointF p2, QPointF p3, const QLineF &bigLine1,
|
|
|
|
|
QPointF sp2, const QLineF &bigLine2, const VSAPoint &p, qreal width,
|
|
|
|
|
bool *needRollback = nullptr) -> QVector<VRawSAPoint>
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
{
|
|
|
|
|
QLineF edge1(p2, p1);
|
|
|
|
|
QLineF edge2(p2, p3);
|
|
|
|
|
const qreal angle = edge1.angleTo(edge2);
|
|
|
|
|
|
2019-09-06 10:12:01 +02:00
|
|
|
|
if (angle > 270)
|
2019-09-03 16:46:09 +02:00
|
|
|
|
{
|
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 17:20:36 +01:00
|
|
|
|
if (needRollback != nullptr)
|
|
|
|
|
{
|
2019-01-09 16:46:02 +01:00
|
|
|
|
*needRollback = false;
|
2019-01-07 17:20:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:31:14 +02:00
|
|
|
|
const qreal localWidth = p.MaxLocalSA(width);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
QLineF edge(p2, p3);
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
QPointF px;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
QLineF::IntersectType type = Intersects(edge, bigLine1, &px);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (type == QLineF::NoIntersection)
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
2019-09-06 10:12:01 +02:00
|
|
|
|
if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), px) && IsSameDirection(p3, p2, px))
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
|
|
|
|
if (QLineF(p2, px).length() > localWidth*maxL)
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2016-11-03 19:15:53 +01:00
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(px, p.CurvePoint(), p.TurnPoint()));
|
2019-01-07 17:20:36 +01:00
|
|
|
|
|
|
|
|
|
QLineF seam(px, p3);
|
|
|
|
|
seam.setAngle(seam.angle()+90);
|
|
|
|
|
seam.setLength(p.GetSAAfter(width));
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(seam.p2(), p.CurvePoint(), p.TurnPoint()));
|
2019-02-20 08:59:59 +01:00
|
|
|
|
|
|
|
|
|
if (needRollback != nullptr)
|
|
|
|
|
{
|
|
|
|
|
*needRollback = true;
|
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-06 10:12:01 +02:00
|
|
|
|
QLineF edge1(p2, p1);
|
|
|
|
|
QLineF edge2(p2, p3);
|
|
|
|
|
const qreal angle = edge1.angleTo(edge2);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
2019-09-06 10:12:01 +02:00
|
|
|
|
if (angle > 180)
|
2019-01-07 17:20:36 +01:00
|
|
|
|
{
|
2019-09-06 10:12:01 +02:00
|
|
|
|
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
|
2019-01-07 17:20:36 +01:00
|
|
|
|
}
|
2019-09-06 10:12:01 +02:00
|
|
|
|
|
2021-04-07 19:38:56 +02:00
|
|
|
|
// Because artificial loop can lead to wrong clipping we must rollback current seam allowance points
|
|
|
|
|
bool success = false;
|
|
|
|
|
const int countBefore = points.size();
|
|
|
|
|
QVector<VRawSAPoint> temp = points;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.append(VRawSAPoint(bigLine1.p2(), p.CurvePoint(), p.TurnPoint()));
|
2021-04-07 19:38:56 +02:00
|
|
|
|
temp = VAbstractPiece::RollbackSeamAllowance(temp, edge, &success);
|
2019-09-06 10:12:01 +02:00
|
|
|
|
|
2021-04-07 19:38:56 +02:00
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
points = temp;
|
2022-01-29 09:59:02 +01:00
|
|
|
|
px = ConstLast(points);
|
2021-04-07 19:38:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (countBefore > 0)
|
2021-03-30 17:11:18 +02:00
|
|
|
|
{
|
|
|
|
|
QLineF seam(px, p3);
|
|
|
|
|
seam.setAngle(seam.angle()+90);
|
|
|
|
|
seam.setLength(p.GetSAAfter(width));
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(seam.p2(), p.CurvePoint(), p.TurnPoint()));
|
2021-03-30 17:11:18 +02:00
|
|
|
|
}
|
2019-01-07 17:20:36 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-07 19:38:56 +02:00
|
|
|
|
if (needRollback != nullptr)
|
2019-09-06 10:12:01 +02:00
|
|
|
|
{
|
2021-04-07 19:38:56 +02:00
|
|
|
|
*needRollback = not success;
|
2019-09-06 10:12:01 +02:00
|
|
|
|
}
|
2021-04-07 19:38:56 +02:00
|
|
|
|
else if (IsSameDirection(bigLine1.p1(), bigLine1.p2(), px))
|
2019-09-06 10:12:01 +02:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(px, p.CurvePoint(), p.TurnPoint()));
|
2019-09-06 10:12:01 +02:00
|
|
|
|
QLineF seam(px, p3);
|
|
|
|
|
seam.setAngle(seam.angle()+90);
|
|
|
|
|
seam.setLength(p.GetSAAfter(width));
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(seam.p2(), p.CurvePoint(), p.TurnPoint()));
|
2019-09-06 10:12:01 +02:00
|
|
|
|
}
|
2019-01-07 17:20:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
|
|
|
|
return points;
|
2016-11-03 19:15:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 10:23:04 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto SingleParallelPoint(const QPointF &p1, const QPointF &p2, qreal angle, qreal width) -> QPointF
|
2016-11-13 10:23:04 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
QLineF pLine(p1, p2);
|
|
|
|
|
pLine.setAngle( pLine.angle() + angle );
|
|
|
|
|
pLine.setLength( width );
|
|
|
|
|
return pLine.p2();
|
2016-11-13 10:23:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto SimpleParallelLine(const QPointF &p1, const QPointF &p2, qreal width) -> QLineF
|
2016-11-13 10:23:04 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
const QLineF paralel = QLineF(SingleParallelPoint(p1, p2, 90, width),
|
|
|
|
|
SingleParallelPoint(p2, p1, -90, width));
|
|
|
|
|
return paralel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto BisectorLine(const QPointF &p1, const QPointF &p2, const QPointF &p3) -> QLineF
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
|
|
|
|
QLineF line1(p2, p1);
|
|
|
|
|
QLineF line2(p2, p3);
|
|
|
|
|
QLineF bLine;
|
|
|
|
|
|
|
|
|
|
const qreal angle1 = line1.angleTo(line2);
|
|
|
|
|
const qreal angle2 = line2.angleTo(line1);
|
|
|
|
|
|
|
|
|
|
if (angle1 <= angle2)
|
2016-11-13 10:23:04 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
bLine = line1;
|
|
|
|
|
bLine.setAngle(bLine.angle() + angle1/2.0);
|
2016-11-13 10:23:04 +01:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
else
|
2016-11-13 10:23:04 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
bLine = line2;
|
|
|
|
|
bLine.setAngle(bLine.angle() + angle2/2.0);
|
2016-11-13 10:23:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return bLine;
|
2016-11-13 10:23:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-10 13:06:09 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto AngleBetweenBisectors(const QLineF &b1, const QLineF &b2) -> qreal
|
2016-11-10 13:06:09 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
const QLineF newB2 = b2.translated(-(b2.p1().x() - b1.p1().x()), -(b2.p1().y() - b1.p1().y()));
|
|
|
|
|
|
|
|
|
|
qreal angle1 = newB2.angleTo(b1);
|
|
|
|
|
if (VFuzzyComparePossibleNulls(angle1, 360))
|
|
|
|
|
{
|
|
|
|
|
angle1 = 0;
|
2016-11-10 13:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
qreal angle2 = b1.angleTo(newB2);
|
|
|
|
|
if (VFuzzyComparePossibleNulls(angle2, 360))
|
2016-11-10 13:06:09 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
angle2 = 0;
|
2016-11-10 13:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-19 14:16:29 +02:00
|
|
|
|
return qMin(angle1, angle2);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 16:06:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
template<class T>
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto CorrectPathDistortion(QVector<T> path) -> QVector<T>
|
2019-07-22 16:06:30 +02:00
|
|
|
|
{
|
|
|
|
|
if (path.size() < 3)
|
|
|
|
|
{
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int prev = -1;
|
|
|
|
|
for (qint32 i = 0; i < path.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (prev == -1)
|
|
|
|
|
{
|
|
|
|
|
i == 0 ? prev = path.size() - 1 : prev = i-1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int next = i+1;
|
|
|
|
|
if (i == path.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
next = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QPointF &iPoint = path.at(i);
|
|
|
|
|
const QPointF &prevPoint = path.at(prev);
|
|
|
|
|
const QPointF &nextPoint = path.at(next);
|
|
|
|
|
|
|
|
|
|
if (VGObject::IsPointOnLineSegment(iPoint, prevPoint, nextPoint))
|
|
|
|
|
{
|
|
|
|
|
const QPointF p = VGObject::CorrectDistortion(iPoint, prevPoint, nextPoint);
|
|
|
|
|
path[i].setX(p.x());
|
|
|
|
|
path[i].setY(p.y());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
2019-09-02 07:55:45 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto Rollback(QVector<VRawSAPoint> &points, const QLineF &edge) -> bool
|
2019-09-02 07:55:45 +02:00
|
|
|
|
{
|
|
|
|
|
bool success = false;
|
|
|
|
|
if (not points.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
points.removeLast();
|
|
|
|
|
points = VAbstractPiece::RollbackSeamAllowance(points, edge, &success);
|
|
|
|
|
|
|
|
|
|
if (not points.isEmpty())
|
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
|
if (ConstLast(points).toPoint() != ConstFirst(points).toPoint())
|
2019-09-02 07:55:45 +02:00
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
|
points.append(ConstFirst(points));// Should be always closed
|
2019-09-02 07:55:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-11-03 09:01:32 +01:00
|
|
|
|
void RollbackByLength(QVector<VRawSAPoint> &ekvPoints, const QVector<VSAPoint> &points, qreal width)
|
2019-09-02 07:55:45 +02:00
|
|
|
|
{
|
|
|
|
|
const QLineF bigLine1 = VAbstractPiece::ParallelLine(points.at(points.size()-2), points.at(0), width);
|
|
|
|
|
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = ekvPoints;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.insert(ekvPoints.size()-1, VRawSAPoint(bigLine1.p2(), points.at(0).CurvePoint(), points.at(0).TurnPoint()));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
bool success = Rollback(temp, VAbstractPiece::ParallelLine(points.at(0), points.at(1), width));
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
ekvPoints = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-11-03 09:01:32 +01:00
|
|
|
|
void RollbackBySecondEdgeSymmetry(QVector<VRawSAPoint> &ekvPoints, const QVector<VSAPoint> &points, qreal width)
|
2019-09-02 07:55:45 +02:00
|
|
|
|
{
|
|
|
|
|
const QLineF axis = QLineF(points.at(points.size()-1), points.at(1));
|
|
|
|
|
const QLineF bigLine1 = VAbstractPiece::ParallelLine(points.at(points.size()-2), points.at(0), width);
|
|
|
|
|
QLineF sEdge(VPointF::FlipPF(axis, bigLine1.p1()), VPointF::FlipPF(axis, bigLine1.p2()));
|
|
|
|
|
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = ekvPoints;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.insert(ekvPoints.size()-1, VRawSAPoint(bigLine1.p2(), points.at(0).CurvePoint(), points.at(0).TurnPoint()));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
bool success = Rollback(temp, sEdge);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
ekvPoints = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-11-03 09:01:32 +01:00
|
|
|
|
void RollbackByFirstEdgeSymmetry(QVector<VRawSAPoint> &ekvPoints, const QVector<VSAPoint> &points, qreal width)
|
2019-09-02 07:55:45 +02:00
|
|
|
|
{
|
|
|
|
|
const QLineF axis = QLineF(points.at(points.size()-2), points.at(points.size()-1));
|
|
|
|
|
const QLineF bigLine2 = VAbstractPiece::ParallelLine(points.at(points.size()-1), points.at(1), width);
|
|
|
|
|
QLineF sEdge(VPointF::FlipPF(axis, bigLine2.p1()), VPointF::FlipPF(axis, bigLine2.p2()));
|
|
|
|
|
const QLineF bigLine1 = VAbstractPiece::ParallelLine(points.at(points.size()-2), points.at(0), width);
|
|
|
|
|
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = ekvPoints;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.insert(ekvPoints.size()-1, VRawSAPoint(bigLine1.p2(), points.at(0).CurvePoint(), points.at(0).TurnPoint()));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
bool success = Rollback(temp, sEdge);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
ekvPoints = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-11-03 09:01:32 +01:00
|
|
|
|
void RollbackByPointsIntersection(QVector<VRawSAPoint> &ekvPoints, const QVector<VSAPoint> &points, qreal width)
|
2019-09-02 07:55:45 +02:00
|
|
|
|
{
|
|
|
|
|
const QLineF bigLine1 = VAbstractPiece::ParallelLine(points.at(points.size()-2), points.at(0), width);
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = ekvPoints;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.insert(ekvPoints.size()-1, VRawSAPoint(bigLine1.p2(), points.at(0).CurvePoint(), points.at(0).TurnPoint()));
|
2022-01-29 09:59:02 +01:00
|
|
|
|
bool success = Rollback(temp, QLineF(ConstLast(points), points.at(1)));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
ekvPoints = temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ekvPoints.size() > 2)
|
|
|
|
|
{ // Fix for the rule of main path
|
|
|
|
|
ekvPoints.removeAt(ekvPoints.size()-1);
|
|
|
|
|
ekvPoints.prepend(ekvPoints.at(ekvPoints.size()-1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-11-03 09:01:32 +01:00
|
|
|
|
void RollbackBySecondEdgeRightAngle(QVector<VRawSAPoint> &ekvPoints, const QVector<VSAPoint> &points, qreal width)
|
2019-09-02 07:55:45 +02:00
|
|
|
|
{
|
|
|
|
|
if (not ekvPoints.isEmpty())
|
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
|
const QLineF edge(ConstLast(points), points.at(1));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
const QLineF bigLine1 = VAbstractPiece::ParallelLine(points.at(points.size()-2), points.at(0), width);
|
|
|
|
|
|
|
|
|
|
QPointF px;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
Intersects(edge, bigLine1, &px);
|
2019-09-02 07:55:45 +02:00
|
|
|
|
|
|
|
|
|
ekvPoints.removeLast();
|
|
|
|
|
|
|
|
|
|
if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), px))
|
|
|
|
|
{
|
|
|
|
|
if (ekvPoints.size() > 3)
|
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
|
const QLineF edge1(ekvPoints.at(ekvPoints.size()-2), ConstLast(ekvPoints));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
const QLineF edge2(ekvPoints.at(0), ekvPoints.at(1));
|
|
|
|
|
|
|
|
|
|
QPointF crosPoint;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
const QLineF::IntersectType type = Intersects(edge1, edge2, &crosPoint );
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2019-09-02 07:55:45 +02:00
|
|
|
|
if (type == QLineF::BoundedIntersection)
|
|
|
|
|
{
|
|
|
|
|
ekvPoints.removeFirst();
|
|
|
|
|
ekvPoints.removeLast();
|
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
|
ekvPoints.append(VRawSAPoint(crosPoint, ekvPoints.at(0).CurvePoint(), ekvPoints.at(0).TurnPoint()));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bool success = false;
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> temp = ekvPoints;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
temp.append(VRawSAPoint(bigLine1.p2(), ekvPoints.at(0).CurvePoint(), ekvPoints.at(0).TurnPoint()));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
temp = VAbstractPiece::RollbackSeamAllowance(temp, edge, &success);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
ekvPoints = temp;
|
2022-01-29 09:59:02 +01:00
|
|
|
|
px = ConstLast(ekvPoints);
|
2019-09-02 07:55:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLineF seam(px, points.at(1));
|
|
|
|
|
seam.setAngle(seam.angle()+90);
|
|
|
|
|
seam.setLength(points.at(0).GetSAAfter(width));
|
2022-10-28 15:16:02 +02:00
|
|
|
|
ekvPoints.append(VRawSAPoint(seam.p2(), ekvPoints.at(0).CurvePoint(), ekvPoints.at(0).TurnPoint()));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
|
|
|
|
|
if (not ekvPoints.isEmpty())
|
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
|
ekvPoints.append(ConstFirst(ekvPoints));
|
2019-09-02 07:55:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not ekvPoints.isEmpty())
|
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
|
if (ConstLast(ekvPoints).toPoint() != ConstFirst(ekvPoints).toPoint())
|
2019-09-02 07:55:45 +02:00
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
|
ekvPoints.append(ConstFirst(ekvPoints));// Should be always closed
|
2019-09-02 07:55:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-12 17:50:13 +02:00
|
|
|
|
} // namespace
|
2018-09-13 15:46:04 +02:00
|
|
|
|
|
2019-07-01 11:26:08 +02:00
|
|
|
|
// Friend functions
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto operator<<(QDataStream &dataStream, const VAbstractPiece &piece) -> QDataStream &
|
2019-07-01 11:26:08 +02:00
|
|
|
|
{
|
|
|
|
|
dataStream << *piece.d;
|
|
|
|
|
return dataStream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto operator>>(QDataStream &dataStream, VAbstractPiece &piece) -> QDataStream &
|
2019-07-01 11:26:08 +02:00
|
|
|
|
{
|
|
|
|
|
dataStream >> *piece.d;
|
|
|
|
|
return dataStream;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
VAbstractPiece::VAbstractPiece()
|
|
|
|
|
: d(new VAbstractPieceData)
|
|
|
|
|
{}
|
2016-11-10 13:06:09 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
VAbstractPiece::VAbstractPiece(const VAbstractPiece &piece)
|
|
|
|
|
:d (piece.d)
|
|
|
|
|
{}
|
2016-11-10 13:06:09 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::operator=(const VAbstractPiece &piece) -> VAbstractPiece &
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
|
|
|
|
if ( &piece == this )
|
|
|
|
|
{
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
d = piece.d;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2016-11-13 20:13:55 +01:00
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
VAbstractPiece::VAbstractPiece(VAbstractPiece &&piece) Q_DECL_NOTHROW
|
|
|
|
|
:d (std::move(piece.d))
|
2019-12-30 16:13:18 +01:00
|
|
|
|
{}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::operator=(VAbstractPiece &&piece) Q_DECL_NOTHROW -> VAbstractPiece &
|
2019-12-30 12:00:57 +01:00
|
|
|
|
{
|
|
|
|
|
std::swap(d, piece.d);
|
2019-12-30 16:13:18 +01:00
|
|
|
|
return *this;
|
2019-12-30 12:00:57 +01:00
|
|
|
|
}
|
2019-12-30 16:13:18 +01:00
|
|
|
|
#endif
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
VAbstractPiece::~VAbstractPiece()
|
|
|
|
|
{}
|
2016-11-17 10:00:04 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::GetName() const -> QString
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_name;
|
2016-11-10 13:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-19 14:29:54 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-09-13 16:16:40 +02:00
|
|
|
|
void VAbstractPiece::SetName(const QString &value)
|
2016-11-19 14:29:54 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
d->m_name = value;
|
2016-11-19 14:29:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-19 17:27:06 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsForbidFlipping() const -> bool
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return d->m_forbidFlipping;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetForbidFlipping(bool value)
|
|
|
|
|
{
|
|
|
|
|
d->m_forbidFlipping = value;
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (value)
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
SetForceFlipping(not value);
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsForceFlipping() const -> bool
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_forceFlipping;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetForceFlipping(bool value)
|
|
|
|
|
{
|
|
|
|
|
d->m_forceFlipping = value;
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (value)
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
SetForbidFlipping(not value);
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsSeamAllowance() const -> bool
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return d->m_seamAllowance;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetSeamAllowance(bool value)
|
|
|
|
|
{
|
|
|
|
|
d->m_seamAllowance = value;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsSeamAllowanceBuiltIn() const -> bool
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_seamAllowanceBuiltIn;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetSeamAllowanceBuiltIn(bool value)
|
|
|
|
|
{
|
|
|
|
|
d->m_seamAllowanceBuiltIn = value;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsHideMainPath() const -> bool
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_hideMainPath;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetHideMainPath(bool value)
|
|
|
|
|
{
|
|
|
|
|
d->m_hideMainPath = value;
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::GetSAWidth() const -> qreal
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return d->m_width;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetSAWidth(qreal value)
|
|
|
|
|
{
|
|
|
|
|
value >= 0 ? d->m_width = value : d->m_width = 0;
|
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
|
auto VAbstractPiece::Equidistant(QVector<VSAPoint> points, qreal width, const QString &name) -> QVector<VLayoutPoint>
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
|
|
|
|
if (width < 0)
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
qDebug()<<"Width < 0.";
|
2022-07-15 16:21:56 +02:00
|
|
|
|
return {};
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
2019-11-03 08:30:36 +01:00
|
|
|
|
width = qMax(width, VSAPoint::minSAWidth);
|
2016-11-19 17:27:06 +01:00
|
|
|
|
|
2019-09-06 10:12:01 +02:00
|
|
|
|
// DumpVector(points, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data
|
2018-09-19 14:16:29 +02:00
|
|
|
|
|
2021-02-23 17:29:54 +01:00
|
|
|
|
// Fix distorsion. Must be done before the correction
|
|
|
|
|
points = CorrectPathDistortion(points);
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
points = CorrectEquidistantPoints(points);
|
|
|
|
|
if ( points.size() < 3 )
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2019-09-10 15:57:31 +02:00
|
|
|
|
const QString errorMsg = tr("Piece '%1'. Not enough points to build seam allowance.").arg(name);
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2022-07-15 16:21:56 +02:00
|
|
|
|
return {};
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 09:59:02 +01:00
|
|
|
|
if (ConstLast(points).toPoint() != ConstFirst(points).toPoint())
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
points.append(points.at(0));// Should be always closed
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
|
bool needRollback = false; // no need for rollback
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> ekvPoints;
|
2018-09-13 16:16:40 +02:00
|
|
|
|
for (qint32 i = 0; i < points.size(); ++i )
|
2018-09-13 15:46:04 +02:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if ( i == 0)
|
|
|
|
|
{//first point
|
|
|
|
|
ekvPoints = EkvPoint(ekvPoints, points.at(points.size()-2), points.at(points.size()-1), points.at(1),
|
2019-01-07 17:20:36 +01:00
|
|
|
|
points.at(0), width, &needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
continue;
|
2018-09-13 15:46:04 +02:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
|
|
|
|
if (i == points.size()-1)
|
|
|
|
|
{//last point
|
|
|
|
|
if (not ekvPoints.isEmpty())
|
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
|
ekvPoints.append(ConstFirst(ekvPoints));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//points in the middle of polyline
|
|
|
|
|
ekvPoints = EkvPoint(ekvPoints, points.at(i-1), points.at(i), points.at(i+1), points.at(i), width);
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
|
if (needRollback)
|
2019-01-07 17:20:36 +01:00
|
|
|
|
{
|
|
|
|
|
QT_WARNING_PUSH
|
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wswitch-default")
|
|
|
|
|
// This check helps to find missed angle types in the switch
|
|
|
|
|
Q_STATIC_ASSERT_X(static_cast<int>(PieceNodeAngle::LAST_ONE_DO_NOT_USE) == 7, "Not all types were handled.");
|
2022-01-29 09:59:02 +01:00
|
|
|
|
switch (ConstLast(points).GetAngleType())
|
2019-01-07 17:20:36 +01:00
|
|
|
|
{
|
|
|
|
|
case PieceNodeAngle::LAST_ONE_DO_NOT_USE:
|
|
|
|
|
case PieceNodeAngle::ByFirstEdgeRightAngle:
|
|
|
|
|
Q_UNREACHABLE(); //-V501
|
|
|
|
|
break;
|
|
|
|
|
case PieceNodeAngle::ByLength:
|
|
|
|
|
case PieceNodeAngle::ByLengthCurve:
|
2019-09-02 07:55:45 +02:00
|
|
|
|
RollbackByLength(ekvPoints, points, width);
|
2019-09-01 12:01:10 +02:00
|
|
|
|
break;
|
2019-01-07 17:20:36 +01:00
|
|
|
|
case PieceNodeAngle::ByFirstEdgeSymmetry:
|
2019-09-02 07:55:45 +02:00
|
|
|
|
RollbackByFirstEdgeSymmetry(ekvPoints, points, width);
|
2019-09-01 12:01:10 +02:00
|
|
|
|
break;
|
2019-01-07 17:20:36 +01:00
|
|
|
|
case PieceNodeAngle::BySecondEdgeSymmetry:
|
2019-09-02 07:55:45 +02:00
|
|
|
|
RollbackBySecondEdgeSymmetry(ekvPoints, points, width);
|
2019-01-07 17:20:36 +01:00
|
|
|
|
break;
|
|
|
|
|
case PieceNodeAngle::ByPointsIntersection:
|
2019-09-02 07:55:45 +02:00
|
|
|
|
RollbackByPointsIntersection(ekvPoints, points, width);
|
2019-01-07 17:20:36 +01:00
|
|
|
|
break;
|
|
|
|
|
case PieceNodeAngle::BySecondEdgeRightAngle:
|
2019-09-02 07:55:45 +02:00
|
|
|
|
RollbackBySecondEdgeRightAngle(ekvPoints, points, width);
|
2019-01-07 17:20:36 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
QT_WARNING_POP
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-03 09:01:32 +01:00
|
|
|
|
// Uncomment for debug
|
2022-10-28 15:16:02 +02:00
|
|
|
|
// QVector<VLayoutPoint> cleaned = CastTo<VLayoutPoint>(ekvPoints);
|
2019-11-03 09:01:32 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
const bool removeFirstAndLast = false;
|
2019-11-03 09:01:32 +01:00
|
|
|
|
ekvPoints = RemoveDublicates(ekvPoints, removeFirstAndLast);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
QVector<VLayoutPoint> cleaned = CastTo<VLayoutPoint>(CheckLoops(ekvPoints));//Result path can contain loops
|
2019-11-03 09:01:32 +01:00
|
|
|
|
cleaned = CorrectEquidistantPoints(cleaned, removeFirstAndLast);
|
|
|
|
|
cleaned = CorrectPathDistortion(cleaned);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
// DumpVector(CastTo<QPointF>(cleaned), QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data
|
2019-11-03 09:01:32 +01:00
|
|
|
|
return cleaned;
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::SumTrapezoids(const QVector<QPointF> &points) -> qreal
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
// Calculation a polygon area through the sum of the areas of trapezoids
|
|
|
|
|
qreal s, res = 0;
|
|
|
|
|
const int n = points.size();
|
2018-09-01 17:56:43 +02:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if(n > 2)
|
2016-11-19 17:27:06 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
for (int i = 0; i < n; ++i)
|
2018-09-13 15:46:04 +02:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
|
|
|
|
//if i == 0, then y[i-1] replace on y[n-1]
|
|
|
|
|
s = points.at(i).x()*(points.at(n-1).y() - points.at(i+1).y());
|
|
|
|
|
res += s;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (i == n-1)
|
|
|
|
|
{
|
|
|
|
|
// if i == n-1, then y[i+1] replace on y[0]
|
|
|
|
|
s = points.at(i).x()*(points.at(i-1).y() - points.at(0).y());
|
|
|
|
|
res += s;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s = points.at(i).x()*(points.at(i-1).y() - points.at(i+1).y());
|
|
|
|
|
res += s;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-13 15:46:04 +02:00
|
|
|
|
}
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return res;
|
2016-11-19 17:27:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 13:53:16 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-09-13 16:16:40 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief EkvPoint return seam aloowance points in place of intersection two edges. Last points of two edges should be
|
|
|
|
|
* equal.
|
|
|
|
|
* @param width global seam allowance width.
|
|
|
|
|
* @return seam aloowance points.
|
|
|
|
|
*/
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::EkvPoint(QVector<VRawSAPoint> points, const VSAPoint &p1Line1, const VSAPoint &p2Line1,
|
|
|
|
|
const VSAPoint &p1Line2, const VSAPoint &p2Line2, qreal width,
|
|
|
|
|
bool *needRollback) -> QVector<VRawSAPoint>
|
2017-01-11 13:53:16 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (width < 0)
|
|
|
|
|
{ // width can't be < 0
|
2022-08-12 17:50:13 +02:00
|
|
|
|
return {};
|
2017-01-11 13:53:16 +01:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
2019-11-03 08:30:36 +01:00
|
|
|
|
width = qMax(width, VSAPoint::minSAWidth);
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if (p2Line1 != p2Line2)
|
2017-01-11 13:53:16 +01:00
|
|
|
|
{
|
2018-09-13 16:16:40 +02:00
|
|
|
|
qDebug()<<"Last points of two lines must be equal.";
|
2022-08-12 17:50:13 +02:00
|
|
|
|
return {}; // Wrong edges
|
2017-01-11 13:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 15:54:06 +02:00
|
|
|
|
const QLineF bigLine1 = ParallelLine(p1Line1, p2Line1, width );
|
|
|
|
|
const QLineF bigLine2 = ParallelLine(p2Line2, p1Line2, width );
|
2018-10-17 17:12:39 +02:00
|
|
|
|
|
2018-10-19 15:54:06 +02:00
|
|
|
|
if (VFuzzyComparePoints(bigLine1.p2(), bigLine2.p1()))
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(bigLine1.p2(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2018-10-19 15:54:06 +02:00
|
|
|
|
return points;
|
2018-10-17 17:12:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 17:13:46 +02:00
|
|
|
|
QLineF edge1(p2Line2, p1Line2);
|
|
|
|
|
QLineF edge2(p2Line1, p1Line1);
|
|
|
|
|
qreal a = edge2.angleTo(edge1);
|
|
|
|
|
|
|
|
|
|
if (a >= 175 && a <= 185 && not VFuzzyComparePossibleNulls(p2Line1.GetSABefore(width), p2Line1.GetSAAfter(width)))
|
|
|
|
|
{
|
|
|
|
|
QLineF ray = edge2;
|
|
|
|
|
ray.setAngle(ray.angle() - a/2);
|
|
|
|
|
ray.setLength(width*2);
|
|
|
|
|
|
|
|
|
|
QPointF crosPoint;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
QLineF::IntersectType type = Intersects(ray, bigLine1, &crosPoint);
|
2022-08-29 17:13:46 +02:00
|
|
|
|
if (type != QLineF::NoIntersection)
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(crosPoint, p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2022-08-29 17:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type = Intersects(ray, bigLine2, &crosPoint );
|
|
|
|
|
if (type != QLineF::NoIntersection)
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(crosPoint, p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2022-08-29 17:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
return points;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
QPointF crosPoint;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
const QLineF::IntersectType type = Intersects(bigLine1, bigLine2, &crosPoint );
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
switch (type)
|
|
|
|
|
{// There are at least three big cases
|
|
|
|
|
case (QLineF::BoundedIntersection):
|
|
|
|
|
// The easiest, real intersection
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(crosPoint, p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return points;
|
|
|
|
|
case (QLineF::UnboundedIntersection):
|
|
|
|
|
{ // Most common case
|
|
|
|
|
/* Case when a path has point on line (both segments lie on the same line) and seam allowance creates
|
|
|
|
|
* prong. */
|
2019-09-03 16:46:09 +02:00
|
|
|
|
auto IsOnLine = [](const QPointF &base, const QPointF &sp1, const QPointF &sp2, qreal accuracy)
|
2018-10-19 15:54:06 +02:00
|
|
|
|
{
|
|
|
|
|
if (not VFuzzyComparePoints(base, sp1))
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return VGObject::IsPointOnLineviaPDP(sp2, base, sp1, accuracy);
|
2018-10-19 15:54:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not VFuzzyComparePoints(base, sp2))
|
|
|
|
|
{
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return VGObject::IsPointOnLineviaPDP(sp1, base, sp2, accuracy);
|
2018-10-19 15:54:06 +02:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
};
|
2019-11-03 09:13:02 +01:00
|
|
|
|
if (VGObject::IsPointOnLineSegment(p2Line1, p1Line1, p1Line2, ToPixel(0.5, Unit::Mm)) &&
|
|
|
|
|
IsOnLine(p2Line1, bigLine1.p2(), bigLine2.p1(), ToPixel(0.5, Unit::Mm)))
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(bigLine1.p2(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
|
|
|
|
points.append(VRawSAPoint(bigLine2.p1(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return points;
|
|
|
|
|
}
|
2017-01-11 13:53:16 +01:00
|
|
|
|
|
2018-09-13 16:31:14 +02:00
|
|
|
|
const qreal localWidth = p2Line1.MaxLocalSA(width);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
QLineF line( p2Line1, crosPoint );
|
2017-01-11 13:53:16 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
// Checking two subcases
|
|
|
|
|
const QLineF b1 = BisectorLine(p1Line1, p2Line1, p1Line2);
|
|
|
|
|
const QLineF b2 = BisectorLine(bigLine1.p1(), crosPoint, bigLine2.p2());
|
2017-01-11 13:53:16 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
const qreal angle = AngleBetweenBisectors(b1, b2);
|
2017-01-11 13:53:16 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
// Comparison bisector angles helps to find direction
|
2019-01-07 17:20:36 +01:00
|
|
|
|
if (angle < 135
|
|
|
|
|
|| VFuzzyComparePossibleNulls(angle, 135.0))// Go in a same direction
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{//Regular equdistant case
|
|
|
|
|
QT_WARNING_PUSH
|
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wswitch-default")
|
2018-09-19 14:16:29 +02:00
|
|
|
|
// This check helps to find missed angle types in the switch
|
2018-10-17 17:12:39 +02:00
|
|
|
|
Q_STATIC_ASSERT_X(static_cast<int>(PieceNodeAngle::LAST_ONE_DO_NOT_USE) == 7,
|
2018-09-19 14:16:29 +02:00
|
|
|
|
"Not all types were handled.");
|
2018-09-13 16:16:40 +02:00
|
|
|
|
switch (p2Line1.GetAngleType())
|
|
|
|
|
{
|
2018-09-19 14:16:29 +02:00
|
|
|
|
case PieceNodeAngle::LAST_ONE_DO_NOT_USE:
|
|
|
|
|
Q_UNREACHABLE(); //-V501
|
|
|
|
|
break;
|
2018-09-13 16:16:40 +02:00
|
|
|
|
case PieceNodeAngle::ByLength:
|
2018-10-17 17:12:39 +02:00
|
|
|
|
case PieceNodeAngle::ByLengthCurve:
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByLength(points, p1Line1, p2Line1, p1Line2, bigLine1, crosPoint, bigLine2, p2Line1,
|
|
|
|
|
width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
case PieceNodeAngle::ByPointsIntersection:
|
|
|
|
|
return AngleByIntersection(points, p1Line1, p2Line1, p1Line2, bigLine1, crosPoint, bigLine2,
|
2019-01-07 17:20:36 +01:00
|
|
|
|
p2Line1, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
case PieceNodeAngle::ByFirstEdgeSymmetry:
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByFirstSymmetry(points, p1Line1, p2Line1, p1Line2, bigLine1, crosPoint, bigLine2,
|
2019-01-07 17:20:36 +01:00
|
|
|
|
p2Line1, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
case PieceNodeAngle::BySecondEdgeSymmetry:
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleBySecondSymmetry(points, p1Line1, p2Line1, p1Line2, bigLine1, crosPoint, bigLine2,
|
2019-01-07 17:20:36 +01:00
|
|
|
|
p2Line1, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
case PieceNodeAngle::ByFirstEdgeRightAngle:
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleByFirstRightAngle(points, p1Line1, p2Line1, p1Line2, bigLine1, crosPoint, bigLine2,
|
2019-02-12 13:51:21 +01:00
|
|
|
|
p2Line1, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
case PieceNodeAngle::BySecondEdgeRightAngle:
|
2019-09-03 16:46:09 +02:00
|
|
|
|
return AngleBySecondRightAngle(points, p1Line1, p2Line1, p1Line2, bigLine1, crosPoint, bigLine2,
|
2019-01-07 17:20:36 +01:00
|
|
|
|
p2Line1, width, needRollback);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
QT_WARNING_POP
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // Different directions
|
|
|
|
|
QLineF bisector(p2Line1, p1Line1);
|
|
|
|
|
bisector.setAngle(b1.angle());
|
2017-01-11 13:53:16 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
const qreal result1 = PointPosition(bisector.p2(), QLineF(p1Line1, p2Line1));
|
|
|
|
|
const qreal result2 = PointPosition(bisector.p2(), QLineF(p2Line2, p1Line2));
|
2017-01-11 13:53:16 +01:00
|
|
|
|
|
2018-09-13 16:16:40 +02:00
|
|
|
|
if ((result1 < 0 || qFuzzyIsNull(result1)) && (result2 < 0 || qFuzzyIsNull(result2)))
|
2019-11-03 09:13:02 +01:00
|
|
|
|
{// Dart case. A bisector watches outside.
|
|
|
|
|
QLineF edge1(p1Line1, p2Line1);
|
|
|
|
|
QLineF edge2(p1Line2, p2Line2);
|
2018-09-13 16:16:40 +02:00
|
|
|
|
|
2019-11-03 09:13:02 +01:00
|
|
|
|
if (qAbs(edge1.length() - edge2.length()) <= qMax(edge1.length(), edge2.length())*0.2)
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
2019-11-03 09:13:02 +01:00
|
|
|
|
// Classic dart must be symmetrical.
|
|
|
|
|
// In some cases a point still valid, but ignore if going outside of an equdistant.
|
|
|
|
|
|
|
|
|
|
const QLineF bigEdge = ParallelLine(p1Line1, p1Line2, localWidth );
|
|
|
|
|
QPointF px;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
const QLineF::IntersectType type = Intersects(bigEdge, line, &px);
|
2019-11-03 09:13:02 +01:00
|
|
|
|
if (type != QLineF::BoundedIntersection && line.length() < QLineF(p2Line1, px).length())
|
2018-09-13 16:16:40 +02:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(crosPoint, p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return points;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-03 09:13:02 +01:00
|
|
|
|
else
|
|
|
|
|
{ // Just an acute angle with big seam allowance
|
|
|
|
|
if (IsSameDirection(bigLine2.p1(), bigLine2.p2(), crosPoint))
|
|
|
|
|
{
|
|
|
|
|
QLineF loop(crosPoint, bigLine1.p1());
|
|
|
|
|
loop.setAngle(loop.angle() + 180);
|
|
|
|
|
loop.setLength(accuracyPointOnLine*2.);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(loop.p2(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
|
|
|
|
points.append(VRawSAPoint(crosPoint, p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2019-11-03 09:13:02 +01:00
|
|
|
|
|
|
|
|
|
loop = QLineF(crosPoint, bigLine1.p1());
|
|
|
|
|
loop.setLength(loop.length() + localWidth*2.);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(loop.p2(), p2Line1.CurvePoint(), p2Line1.TurnPoint(), true));
|
2019-11-03 09:13:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return points;
|
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // New subcase. This is not a dart. An angle is acute and bisector watch inside.
|
|
|
|
|
const qreal result1 = PointPosition(crosPoint, QLineF(p1Line1, p2Line1));
|
|
|
|
|
const qreal result2 = PointPosition(crosPoint, QLineF(p2Line2, p1Line2));
|
|
|
|
|
|
|
|
|
|
if ((result1 < 0 || qFuzzyIsNull(result1)) && (result2 < 0 || qFuzzyIsNull(result2)))
|
|
|
|
|
{// The cross point is still outside of a piece
|
|
|
|
|
if (line.length() >= localWidth)
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(crosPoint, p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return points;
|
|
|
|
|
}
|
2022-08-12 17:50:13 +02:00
|
|
|
|
|
|
|
|
|
// but not enough far, fix it
|
|
|
|
|
line.setLength(localWidth);
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(line.p2(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return points;
|
|
|
|
|
}
|
2022-08-12 17:50:13 +02:00
|
|
|
|
|
|
|
|
|
// Wrong cross point, probably inside of a piece. Manually creating correct seam allowance
|
|
|
|
|
const QLineF bigEdge = SimpleParallelLine(bigLine1.p2(), bigLine2.p1(), localWidth );
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(bigEdge.p1(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
|
|
|
|
points.append(VRawSAPoint(bigEdge.p2(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2022-08-12 17:50:13 +02:00
|
|
|
|
return points;
|
2018-09-13 16:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case (QLineF::NoIntersection):
|
|
|
|
|
/*If we have correct lines this means lines lie on a line or parallel.*/
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(bigLine1.p2(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
|
|
|
|
// Second point for parallel line
|
|
|
|
|
points.append(VRawSAPoint(bigLine2.p1(), p2Line1.CurvePoint(), p2Line1.TurnPoint()));
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return points;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2017-01-11 13:53:16 +01:00
|
|
|
|
}
|
2018-09-13 16:16:40 +02:00
|
|
|
|
return points;
|
2017-01-11 13:53:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width) -> QLineF
|
2017-01-11 13:53:16 +01:00
|
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
|
return {SingleParallelPoint(p1, p2, 90, p1.GetSAAfter(width)),
|
|
|
|
|
SingleParallelPoint(p2, p1, -90, p2.GetSABefore(width))};
|
2017-01-11 13:53:16 +01:00
|
|
|
|
}
|
2017-03-30 10:06:47 +02:00
|
|
|
|
|
2019-02-23 17:43:06 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsAllowanceValid(const QVector<QPointF> &base, const QVector<QPointF> &allowance) -> bool
|
2019-02-23 17:43:06 +01:00
|
|
|
|
{
|
|
|
|
|
if (base.size() < 3 || allowance.size() < 3)
|
|
|
|
|
{
|
|
|
|
|
return false; // Not enough data
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 15:21:44 +02:00
|
|
|
|
// DumpVector(base, QStringLiteral("base.json.XXXXXX")); // Uncomment for dumping test data
|
|
|
|
|
// DumpVector(allowance, QStringLiteral("allowance.json.XXXXXX")); // Uncomment for dumping test data
|
2019-02-27 19:33:59 +01:00
|
|
|
|
|
2020-06-04 12:45:32 +02:00
|
|
|
|
// First check direction
|
2019-02-23 17:43:06 +01:00
|
|
|
|
const qreal baseDirection = VPiece::SumTrapezoids(base);
|
|
|
|
|
const qreal allowanceDirection = VPiece::SumTrapezoids(allowance);
|
|
|
|
|
|
|
|
|
|
if (baseDirection >= 0 || allowanceDirection >= 0)
|
|
|
|
|
{
|
|
|
|
|
return false; // Wrong direction
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-01 10:55:56 +02:00
|
|
|
|
return IsInsidePolygon(base, allowance);
|
2019-02-23 17:43:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-30 10:06:47 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsEkvPointOnLine(const QPointF &iPoint, const QPointF &prevPoint, const QPointF &nextPoint) -> bool
|
2017-03-30 10:06:47 +02:00
|
|
|
|
{
|
2020-02-10 15:34:50 +01:00
|
|
|
|
return VGObject::IsPointOnLineviaPDP(iPoint, prevPoint, nextPoint, accuracyPointOnLine/4.);
|
2017-03-30 10:06:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsEkvPointOnLine(const VSAPoint &iPoint, const VSAPoint &prevPoint,
|
|
|
|
|
const VSAPoint &nextPoint) -> bool
|
2017-03-30 10:06:47 +02:00
|
|
|
|
{
|
2017-04-27 15:37:10 +02:00
|
|
|
|
// See bug #671
|
|
|
|
|
const qreal tmpWidth = 10;
|
|
|
|
|
const QLineF bigLine1 = ParallelLine(prevPoint, iPoint, tmpWidth );
|
|
|
|
|
const QLineF bigLine2 = ParallelLine(iPoint, nextPoint, tmpWidth );
|
|
|
|
|
|
2019-09-12 19:57:26 +02:00
|
|
|
|
bool seamOnLine = VGObject::IsPointOnLineviaPDP(iPoint, prevPoint, nextPoint);
|
|
|
|
|
bool sa1OnLine = VGObject::IsPointOnLineviaPDP(bigLine1.p2(), bigLine1.p1(), bigLine2.p2());
|
|
|
|
|
bool sa2OnLine = VGObject::IsPointOnLineviaPDP(bigLine2.p1(), bigLine1.p1(), bigLine2.p2());
|
|
|
|
|
bool saDiff = qAbs(prevPoint.GetSAAfter(tmpWidth) - nextPoint.GetSABefore(tmpWidth)) < accuracyPointOnLine;
|
|
|
|
|
|
|
|
|
|
// left point that splits a curve
|
|
|
|
|
bool curve = (prevPoint.GetAngleType() == PieceNodeAngle::ByLengthCurve &&
|
|
|
|
|
iPoint.GetAngleType() == PieceNodeAngle::ByLengthCurve) ||
|
|
|
|
|
(nextPoint.GetAngleType() == PieceNodeAngle::ByLengthCurve &&
|
|
|
|
|
iPoint.GetAngleType() == PieceNodeAngle::ByLengthCurve);
|
|
|
|
|
|
|
|
|
|
return seamOnLine && sa1OnLine && sa2OnLine && saDiff && not curve;
|
2017-03-30 10:06:47 +02:00
|
|
|
|
}
|
2017-04-25 10:42:08 +02:00
|
|
|
|
|
2017-07-09 21:27:54 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::GetMx() const -> qreal
|
2017-07-09 21:27:54 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_mx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetMx(qreal value)
|
|
|
|
|
{
|
|
|
|
|
d->m_mx = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::GetMy() const -> qreal
|
2017-07-09 21:27:54 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_my;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetMy(qreal value)
|
|
|
|
|
{
|
|
|
|
|
d->m_my = value;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::GetPriority() const -> uint
|
2019-07-19 09:45:57 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_priority;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetPriority(uint value)
|
|
|
|
|
{
|
|
|
|
|
d->m_priority = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 13:32:25 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::GetUUID() const -> QUuid
|
2020-04-22 13:32:25 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_uuid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetUUID(const QUuid &uuid)
|
|
|
|
|
{
|
|
|
|
|
d->m_uuid = uuid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VAbstractPiece::SetUUID(const QString &uuid)
|
|
|
|
|
{
|
|
|
|
|
const QUuid temp = QUuid(uuid);
|
|
|
|
|
d->m_uuid = temp.isNull() ? QUuid::createUuid() : temp;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-31 11:07:26 +02:00
|
|
|
|
auto VAbstractPiece::GetUniqueID() const -> QString
|
2021-08-18 19:33:47 +02:00
|
|
|
|
{
|
|
|
|
|
return d->m_uuid.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 16:53:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VSAPoint::toJson() const -> QJsonObject
|
2019-08-07 16:53:18 +02:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
QJsonObject pointObject = VLayoutPoint::toJson();
|
2019-08-07 16:53:18 +02:00
|
|
|
|
pointObject[QLatin1String("type")] = "VSAPoint";
|
|
|
|
|
|
|
|
|
|
if (not VFuzzyComparePossibleNulls(m_before, -1))
|
|
|
|
|
{
|
|
|
|
|
pointObject[QLatin1String("saBefore")] = m_before;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not VFuzzyComparePossibleNulls(m_after, -1))
|
|
|
|
|
{
|
|
|
|
|
pointObject[QLatin1String("saAfter")] = m_after;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_angle != PieceNodeAngle::ByLength)
|
|
|
|
|
{
|
|
|
|
|
pointObject[QLatin1String("angle")] = static_cast<int>(m_angle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pointObject;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
// Because artificial loop can lead to wrong clipping we must rollback current seam allowance points
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::RollbackSeamAllowance(QVector<VRawSAPoint> points, const QLineF &cuttingEdge,
|
|
|
|
|
bool *success) -> QVector<VRawSAPoint>
|
2019-01-09 16:46:02 +01:00
|
|
|
|
{
|
|
|
|
|
*success = false;
|
2019-11-03 09:01:32 +01:00
|
|
|
|
QVector<VRawSAPoint> clipped;
|
2019-01-09 16:46:02 +01:00
|
|
|
|
clipped.reserve(points.count()+1);
|
|
|
|
|
for (int i = points.count()-1; i > 0; --i)
|
|
|
|
|
{
|
|
|
|
|
QLineF segment(points.at(i), points.at(i-1));
|
|
|
|
|
QPointF crosPoint;
|
2020-01-16 16:34:08 +01:00
|
|
|
|
const QLineF::IntersectType type = Intersects(cuttingEdge, segment, &crosPoint);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
|
if (type != QLineF::NoIntersection
|
|
|
|
|
&& VGObject::IsPointOnLineSegment(crosPoint, segment.p1(), segment.p2())
|
2019-09-01 12:01:10 +02:00
|
|
|
|
&& IsSameDirection(cuttingEdge.p2(), cuttingEdge.p1(), crosPoint))
|
2019-01-09 16:46:02 +01:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
clipped.append(VRawSAPoint(crosPoint, points.at(i).CurvePoint(), points.at(i).TurnPoint()));
|
2019-01-09 16:46:02 +01:00
|
|
|
|
for (int j=i-1; j>=0; --j)
|
|
|
|
|
{
|
|
|
|
|
clipped.append(points.at(j));
|
|
|
|
|
}
|
2020-07-13 15:28:13 +02:00
|
|
|
|
points = Reverse(clipped);
|
2019-01-09 16:46:02 +01:00
|
|
|
|
*success = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not *success && points.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
QPointF crosPoint;
|
|
|
|
|
QLineF secondLast(points.at(points.size()-2), points.at(points.size()-1));
|
2020-01-16 16:34:08 +01:00
|
|
|
|
QLineF::IntersectType type = Intersects(secondLast, cuttingEdge, &crosPoint);
|
2020-01-06 17:34:35 +01:00
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
|
if (type != QLineF::NoIntersection && IsOutsidePoint(secondLast.p1(), secondLast.p2(), crosPoint))
|
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
points.append(VRawSAPoint(crosPoint, points.at(points.size()-1).CurvePoint(),
|
|
|
|
|
points.at(points.size()-1).TurnPoint()));
|
2019-01-09 16:46:02 +01:00
|
|
|
|
*success = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return points;
|
|
|
|
|
}
|
2019-01-28 19:35:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::IsItemContained(const QRectF &parentBoundingRect, const QVector<QPointF> &shape, qreal &dX,
|
|
|
|
|
qreal &dY) -> bool
|
2019-01-28 19:35:10 +01:00
|
|
|
|
{
|
|
|
|
|
dX = 0;
|
|
|
|
|
dY = 0;
|
|
|
|
|
// single point differences
|
|
|
|
|
bool bInside = true;
|
|
|
|
|
|
|
|
|
|
for (auto p : shape)
|
|
|
|
|
{
|
|
|
|
|
qreal dPtX = 0;
|
|
|
|
|
qreal dPtY = 0;
|
|
|
|
|
if (not parentBoundingRect.contains(p))
|
|
|
|
|
{
|
|
|
|
|
if (p.x() < parentBoundingRect.left())
|
|
|
|
|
{
|
|
|
|
|
dPtX = parentBoundingRect.left() - p.x();
|
|
|
|
|
}
|
|
|
|
|
else if (p.x() > parentBoundingRect.right())
|
|
|
|
|
{
|
|
|
|
|
dPtX = parentBoundingRect.right() - p.x();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p.y() < parentBoundingRect.top())
|
|
|
|
|
{
|
|
|
|
|
dPtY = parentBoundingRect.top() - p.y();
|
|
|
|
|
}
|
|
|
|
|
else if (p.y() > parentBoundingRect.bottom())
|
|
|
|
|
{
|
|
|
|
|
dPtY = parentBoundingRect.bottom() - p.y();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (qAbs(dPtX) > qAbs(dX))
|
|
|
|
|
{
|
|
|
|
|
dX = dPtX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (qAbs(dPtY) > qAbs(dY))
|
|
|
|
|
{
|
|
|
|
|
dY = dPtY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bInside = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bInside;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::CorrectPosition(const QRectF &parentBoundingRect, QVector<QPointF> points) -> QVector<QPointF>
|
2019-01-28 19:35:10 +01:00
|
|
|
|
{
|
|
|
|
|
qreal dX = 0;
|
|
|
|
|
qreal dY = 0;
|
|
|
|
|
if (not IsItemContained(parentBoundingRect, points, dX, dY))
|
|
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
|
for (auto & point : points)
|
2019-01-28 19:35:10 +01:00
|
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
|
point = QPointF(point.x() + dX, point.y() + dY);
|
2019-01-28 19:35:10 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return points;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::FindGrainlineGeometry(const VGrainlineData& geom, const VContainer *pattern, qreal &length,
|
|
|
|
|
qreal &rotationAngle, QPointF &pos) -> bool
|
2019-01-28 19:35:10 +01:00
|
|
|
|
{
|
|
|
|
|
SCASSERT(pattern != nullptr)
|
|
|
|
|
|
|
|
|
|
const quint32 topPin = geom.TopPin();
|
|
|
|
|
const quint32 bottomPin = geom.BottomPin();
|
|
|
|
|
|
|
|
|
|
if (topPin != NULL_ID && bottomPin != NULL_ID)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const auto topPinPoint = pattern->GeometricObject<VPointF>(topPin);
|
|
|
|
|
const auto bottomPinPoint = pattern->GeometricObject<VPointF>(bottomPin);
|
|
|
|
|
|
|
|
|
|
QLineF grainline(static_cast<QPointF>(*bottomPinPoint), static_cast<QPointF>(*topPinPoint));
|
|
|
|
|
length = grainline.length();
|
|
|
|
|
rotationAngle = grainline.angle();
|
|
|
|
|
|
|
|
|
|
if (not VFuzzyComparePossibleNulls(rotationAngle, 0))
|
|
|
|
|
{
|
|
|
|
|
grainline.setAngle(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos = grainline.p1();
|
|
|
|
|
rotationAngle = qDegreesToRadians(rotationAngle);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &)
|
|
|
|
|
{
|
|
|
|
|
// do nothing.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Calculator cal1;
|
|
|
|
|
rotationAngle = cal1.EvalFormula(pattern->DataVariables(), geom.GetRotation());
|
|
|
|
|
rotationAngle = qDegreesToRadians(rotationAngle);
|
|
|
|
|
|
|
|
|
|
Calculator cal2;
|
|
|
|
|
length = cal2.EvalFormula(pattern->DataVariables(), geom.GetLength());
|
|
|
|
|
length = ToPixel(length, *pattern->GetPatternUnit());
|
|
|
|
|
}
|
|
|
|
|
catch(qmu::QmuParserError &e)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const quint32 centerPin = geom.CenterPin();
|
|
|
|
|
if (centerPin != NULL_ID)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const auto centerPinPoint = pattern->GeometricObject<VPointF>(centerPin);
|
|
|
|
|
|
|
|
|
|
QLineF grainline(centerPinPoint->x(), centerPinPoint->y(),
|
|
|
|
|
centerPinPoint->x() + length / 2.0, centerPinPoint->y());
|
|
|
|
|
|
|
|
|
|
grainline.setAngle(qRadiansToDegrees(rotationAngle));
|
|
|
|
|
grainline = QLineF(grainline.p2(), grainline.p1());
|
|
|
|
|
grainline.setLength(length);
|
|
|
|
|
|
|
|
|
|
pos = grainline.p2();
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &)
|
|
|
|
|
{
|
|
|
|
|
pos = geom.GetPos();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pos = geom.GetPos();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
|
auto VAbstractPiece::GrainlinePoints(const VGrainlineData &geom, const VContainer *pattern, const QRectF &boundingRect,
|
|
|
|
|
qreal &dAng) -> QVector<QPointF>
|
2019-01-28 19:35:10 +01:00
|
|
|
|
{
|
|
|
|
|
SCASSERT(pattern != nullptr)
|
|
|
|
|
|
|
|
|
|
QPointF pt1;
|
|
|
|
|
qreal dLen = 0;
|
|
|
|
|
if ( not FindGrainlineGeometry(geom, pattern, dLen, dAng, pt1))
|
|
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
|
return {};
|
2019-01-28 19:35:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qreal rotation = dAng;
|
|
|
|
|
|
|
|
|
|
QPointF pt2(pt1.x() + dLen * qCos(rotation), pt1.y() - dLen * qSin(rotation));
|
|
|
|
|
|
|
|
|
|
const qreal dArrowLen = ToPixel(0.5, *pattern->GetPatternUnit());
|
|
|
|
|
const qreal dArrowAng = M_PI/9;
|
|
|
|
|
|
|
|
|
|
QVector<QPointF> v;
|
|
|
|
|
v << pt1;
|
|
|
|
|
|
2020-01-07 12:54:23 +01:00
|
|
|
|
if (geom.GetArrowType() != GrainlineArrowDirection::atFront)
|
2019-01-28 19:35:10 +01:00
|
|
|
|
{
|
|
|
|
|
v << QPointF(pt1.x() + dArrowLen * qCos(rotation + dArrowAng),
|
|
|
|
|
pt1.y() - dArrowLen * qSin(rotation + dArrowAng));
|
|
|
|
|
v << QPointF(pt1.x() + dArrowLen * qCos(rotation - dArrowAng),
|
|
|
|
|
pt1.y() - dArrowLen * qSin(rotation - dArrowAng));
|
|
|
|
|
v << pt1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v << pt2;
|
|
|
|
|
|
2020-01-07 12:54:23 +01:00
|
|
|
|
if (geom.GetArrowType() != GrainlineArrowDirection::atRear)
|
2019-01-28 19:35:10 +01:00
|
|
|
|
{
|
|
|
|
|
rotation += M_PI;
|
|
|
|
|
|
|
|
|
|
v << QPointF(pt2.x() + dArrowLen * qCos(rotation + dArrowAng),
|
|
|
|
|
pt2.y() - dArrowLen * qSin(rotation + dArrowAng));
|
|
|
|
|
v << QPointF(pt2.x() + dArrowLen * qCos(rotation - dArrowAng),
|
|
|
|
|
pt2.y() - dArrowLen * qSin(rotation - dArrowAng));
|
|
|
|
|
v << pt2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CorrectPosition(boundingRect, v);
|
|
|
|
|
}
|
2021-01-23 14:24:44 +01:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
|
auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLabelImg
|
2021-01-23 14:24:44 +01:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
auto LayoutPoint = [label](QPointF p, bool turnPoint = false, bool curvePoint = false)
|
|
|
|
|
{
|
|
|
|
|
VLayoutPoint point(label.RotationMatrix().map(p));
|
|
|
|
|
point.SetTurnPoint(turnPoint);
|
|
|
|
|
point.SetCurvePoint(curvePoint);
|
|
|
|
|
return point;
|
|
|
|
|
};
|
2021-01-23 14:24:44 +01:00
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
|
const QPointF pos = label.Center();
|
|
|
|
|
const QRectF box = label.Box();
|
|
|
|
|
|
|
|
|
|
auto SegmentShape = [pos, box, LayoutPoint]()
|
2021-01-23 14:24:44 +01:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
QVector<VLayoutPoint> shape
|
2021-03-30 17:21:02 +02:00
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y() - box.height()/2.0), true),
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y() + box.height()/2.0), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto RectangleShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
QRectF rect(QPointF(pos.x() - box.width()/2.0, pos.y() - box.height()/2.0),
|
|
|
|
|
QPointF(pos.x() + box.width()/2.0, pos.y() + box.height()/2.0));
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(rect.topLeft(), true),
|
|
|
|
|
LayoutPoint(rect.topRight(), true),
|
|
|
|
|
LayoutPoint(rect.bottomRight(), true),
|
|
|
|
|
LayoutPoint(rect.bottomLeft(), true),
|
|
|
|
|
LayoutPoint(rect.topLeft(), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto CrossShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
QVector<VLayoutPoint> shape1
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y() - box.height()/2.0), true),
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y() + box.height()/2.0), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape2
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(pos.x() - box.width()/2.0, pos.y()), true),
|
|
|
|
|
LayoutPoint(QPointF(pos.x() + box.width()/2.0, pos.y()), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape1, shape2};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto TshapedShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
QPointF center2(pos.x(), pos.y() + box.height()/2.0);
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape1
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y()), true),
|
|
|
|
|
LayoutPoint(center2, true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape2
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(center2.x() - box.width()/2.0, center2.y()), true),
|
|
|
|
|
LayoutPoint(QPointF(center2.x() + box.width()/2.0, center2.y()), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape1, shape2};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto DoubletreeShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
QRectF rect(QPointF(pos.x() - box.width()/2.0, pos.y() - box.height()/2.0),
|
|
|
|
|
QPointF(pos.x() + box.width()/2.0, pos.y() + box.height()/2.0));
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape1
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(rect.topLeft(), true),
|
|
|
|
|
LayoutPoint(rect.bottomRight(), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape2
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(rect.topRight(), true),
|
|
|
|
|
LayoutPoint(rect.bottomLeft(), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape1, shape2};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto CornerShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
QVector<VLayoutPoint> shape1
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y()), true),
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y() + box.height()/2.0), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape2
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(pos.x() - box.width()/2.0, pos.y()), true),
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y()), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape1, shape2};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto TriangleShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
QRectF rect(QPointF(pos.x() - box.width()/2.0, pos.y() - box.height()/2.0),
|
|
|
|
|
QPointF(pos.x() + box.width()/2.0, pos.y() + box.height()/2.0));
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(rect.topLeft(), true),
|
|
|
|
|
LayoutPoint(rect.topRight(), true),
|
|
|
|
|
LayoutPoint(rect.bottomRight(), true),
|
|
|
|
|
LayoutPoint(rect.topLeft(), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto HshapedShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
const QPointF center1 (pos.x(), pos.y() - box.height()/2.0);
|
|
|
|
|
const QPointF center2 (pos.x(), pos.y() + box.height()/2.0);
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape1
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(center1, true),
|
|
|
|
|
LayoutPoint(center2, true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape2
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(center1.x() - box.width()/2.0, center1.y()), true),
|
|
|
|
|
LayoutPoint(QPointF(center1.x() + box.width()/2.0, center1.y()), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape3
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(center2.x() - box.width()/2.0, center2.y()), true),
|
|
|
|
|
LayoutPoint(QPointF(center2.x() + box.width()/2.0, center2.y()), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape1, shape2, shape3};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto ButtonShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
const qreal radius = qMin(box.width()/2.0, box.height()/2.0);
|
|
|
|
|
QVector<VLayoutPoint> shape1
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y() - radius), true),
|
|
|
|
|
LayoutPoint(QPointF(pos.x(), pos.y() + radius), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape2
|
|
|
|
|
{
|
|
|
|
|
LayoutPoint(QPointF(pos.x() - radius, pos.y()), true),
|
|
|
|
|
LayoutPoint(QPointF(pos.x() + radius, pos.y()), true)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const qreal circleSize = 0.85;
|
|
|
|
|
VArc arc(VPointF(pos), radius*circleSize, 0, 360);
|
|
|
|
|
arc.SetApproximationScale(10);
|
|
|
|
|
|
|
|
|
|
QVector<QPointF> points = arc.GetPoints();
|
|
|
|
|
if (not points.isEmpty() && ConstFirst(points) != ConstLast(points))
|
|
|
|
|
{
|
|
|
|
|
points.append(ConstFirst(points));
|
2021-03-30 17:21:02 +02:00
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> shape3;
|
|
|
|
|
for (int i=0; i < points.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
bool turnPoint = false;
|
|
|
|
|
if (i == 0 || i == points.size() -1)
|
|
|
|
|
{
|
|
|
|
|
turnPoint = true;
|
|
|
|
|
}
|
|
|
|
|
shape3.append(LayoutPoint(points.at(i), turnPoint, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{shape1, shape2, shape3};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto CircleShape = [pos, box, LayoutPoint]()
|
|
|
|
|
{
|
|
|
|
|
const qreal radius = qMin(box.width()/2.0, box.height()/2.0);
|
|
|
|
|
VArc arc(VPointF(pos), radius, 0, 360);
|
|
|
|
|
arc.SetApproximationScale(10);
|
|
|
|
|
|
|
|
|
|
QVector<QPointF> points = arc.GetPoints();
|
|
|
|
|
if (not points.isEmpty() && ConstFirst(points) != ConstLast(points))
|
|
|
|
|
{
|
|
|
|
|
points.append(ConstFirst(points));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> circle;
|
|
|
|
|
for (int i=0; i < points.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
bool turnPoint = false;
|
|
|
|
|
if (i == 0 || i == points.size() -1)
|
|
|
|
|
{
|
|
|
|
|
turnPoint = true;
|
|
|
|
|
}
|
|
|
|
|
circle.append(LayoutPoint(points.at(i), turnPoint, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return PlaceLabelImg{circle};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch(label.Type())
|
|
|
|
|
{
|
|
|
|
|
case PlaceLabelType::Segment:
|
|
|
|
|
return SegmentShape();
|
|
|
|
|
case PlaceLabelType::Rectangle:
|
|
|
|
|
return RectangleShape();
|
|
|
|
|
case PlaceLabelType::Cross:
|
|
|
|
|
return CrossShape();
|
|
|
|
|
case PlaceLabelType::Tshaped:
|
|
|
|
|
return TshapedShape();
|
|
|
|
|
case PlaceLabelType::Doubletree:
|
|
|
|
|
return DoubletreeShape();
|
|
|
|
|
case PlaceLabelType::Corner:
|
|
|
|
|
return CornerShape();
|
|
|
|
|
case PlaceLabelType::Triangle:
|
|
|
|
|
return TriangleShape();
|
|
|
|
|
case PlaceLabelType::Hshaped:
|
|
|
|
|
return HshapedShape();
|
|
|
|
|
case PlaceLabelType::Button:
|
|
|
|
|
return ButtonShape();
|
|
|
|
|
case PlaceLabelType::Circle:
|
|
|
|
|
return CircleShape();
|
|
|
|
|
default:
|
|
|
|
|
return {};
|
2021-01-23 14:24:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
auto VAbstractPiece::LabelShapePath(const VLayoutPlaceLabel &label) -> QPainterPath
|
|
|
|
|
{
|
|
|
|
|
return LabelShapePath(PlaceLabelShape(label));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
auto VAbstractPiece::LabelShapePath(const PlaceLabelImg &shape) -> QPainterPath
|
|
|
|
|
{
|
|
|
|
|
QPainterPath path;
|
|
|
|
|
for (const auto &p : shape)
|
|
|
|
|
{
|
|
|
|
|
if (not p.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
path.moveTo(ConstFirst<QPointF>(p));
|
|
|
|
|
path.addPolygon(CastTo<QPointF>(p));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-23 14:24:44 +01:00
|
|
|
|
return path;
|
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
template <class T>
|
|
|
|
|
auto VAbstractPiece::ComparePoints(QVector<T> &points, const T &p1, const T &p2, qreal accuracy) -> bool
|
|
|
|
|
{
|
|
|
|
|
if (not VFuzzyComparePoints(p1, p2, accuracy))
|
|
|
|
|
{
|
|
|
|
|
points.append(p2);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not points.isEmpty() && p2.TurnPoint())
|
|
|
|
|
{
|
|
|
|
|
points.last().SetTurnPoint(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not points.isEmpty() && p2.CurvePoint())
|
|
|
|
|
{
|
|
|
|
|
points.last().SetCurvePoint(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
template <>
|
|
|
|
|
auto VAbstractPiece::ComparePoints<QPointF>(QVector<QPointF> &points, const QPointF &p1, const QPointF &p2,
|
|
|
|
|
qreal accuracy) -> bool
|
|
|
|
|
{
|
|
|
|
|
if (not VFuzzyComparePoints(p1, p2, accuracy))
|
|
|
|
|
{
|
|
|
|
|
points.append(p2);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
template <class T>
|
|
|
|
|
auto VAbstractPiece::CompareFirstAndLastPoints(QVector<T> &points, qreal accuracy) -> void
|
|
|
|
|
{
|
|
|
|
|
if (VFuzzyComparePoints(ConstFirst(points), ConstLast(points), accuracy))
|
|
|
|
|
{
|
|
|
|
|
const T& l = ConstLast(points);
|
|
|
|
|
points.removeLast();
|
|
|
|
|
|
|
|
|
|
if (not points.isEmpty() && l.TurnPoint())
|
|
|
|
|
{
|
|
|
|
|
points.last().SetTurnPoint(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not points.isEmpty() && l.CurvePoint())
|
|
|
|
|
{
|
|
|
|
|
points.last().SetCurvePoint(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
template <>
|
|
|
|
|
auto VAbstractPiece::CompareFirstAndLastPoints<QPointF>(QVector<QPointF> &points, qreal accuracy) -> void
|
|
|
|
|
{
|
|
|
|
|
if (VFuzzyComparePoints(ConstFirst(points), ConstLast(points), accuracy))
|
|
|
|
|
{
|
|
|
|
|
points.removeLast();
|
|
|
|
|
}
|
|
|
|
|
}
|