mirror of
https://gitlab.com/smart-pattern/valentina.git
synced 2024-09-08 01:54:37 +02:00
Recalculate seam allowance mirror line if it is not valid.
This commit is contained in:
parent
0e55c2f906
commit
1a2ba7233d
|
@ -927,9 +927,21 @@ void VPGraphicsPiece::PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece
|
|||
}
|
||||
else if (not piece->IsSeamAllowanceBuiltIn())
|
||||
{
|
||||
QLineF const seamAllowanceMirrorLine = piece->GetMappedSeamAllowanceMirrorLine();
|
||||
QLineF seamAllowanceMirrorLine = piece->GetMappedSeamAllowanceMirrorLine();
|
||||
if (!seamAllowanceMirrorLine.isNull() && piece->IsShowMirrorLine())
|
||||
{
|
||||
{ // Trying to correct a seam allowance mirror line based on seam mirror line
|
||||
QVector<QPointF> seamAllowance;
|
||||
CastTo(piece->GetMappedContourPoints(), seamAllowance);
|
||||
|
||||
if (!VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p1()) ||
|
||||
!VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p2()))
|
||||
{
|
||||
seamAllowanceMirrorLine =
|
||||
piece->SeamAllowanceMirrorLine(piece->GetMappedSeamMirrorLine(), seamAllowance);
|
||||
}
|
||||
}
|
||||
|
||||
QPainterPath mirrorPath;
|
||||
mirrorPath.moveTo(seamAllowanceMirrorLine.p1());
|
||||
mirrorPath.lineTo(seamAllowanceMirrorLine.p2());
|
||||
|
|
|
@ -2132,3 +2132,39 @@ auto VAbstractPiece::LabelShapePath(const PlaceLabelImg &shape) -> QPainterPath
|
|||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
auto VAbstractPiece::SeamAllowanceMirrorLine(const QLineF &seamMirrorLine,
|
||||
const QVector<QPointF> &seamAllowancePoints) const -> QLineF
|
||||
{
|
||||
if (!IsSeamAllowance() || (IsSeamAllowance() && IsSeamAllowanceBuiltIn()))
|
||||
{
|
||||
return seamMirrorLine;
|
||||
}
|
||||
|
||||
auto rec = QRectF(0, 0, INT_MAX, INT_MAX);
|
||||
rec.translate(-INT_MAX / 2.0, -INT_MAX / 2.0);
|
||||
|
||||
auto axis =
|
||||
QLineF(seamMirrorLine.center(), VGObject::BuildRay(seamMirrorLine.center(), seamMirrorLine.angle() + 180, rec));
|
||||
|
||||
QVector<QPointF> points = seamAllowancePoints;
|
||||
|
||||
QVector<QPointF> intersections = VAbstractCurve::CurveIntersectLine(points, axis);
|
||||
if (intersections.isEmpty())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const QPointF startPoint = intersections.constFirst();
|
||||
|
||||
std::reverse(points.begin(), points.end());
|
||||
axis = QLineF(seamMirrorLine.center(), VGObject::BuildRay(seamMirrorLine.center(), seamMirrorLine.angle(), rec));
|
||||
intersections = VAbstractCurve::CurveIntersectLine(points, axis);
|
||||
if (intersections.isEmpty())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return {startPoint, intersections.constFirst()};
|
||||
}
|
||||
|
|
|
@ -198,6 +198,9 @@ public:
|
|||
|
||||
template <typename T> static auto MapPoint(T obj, const QTransform &matrix) -> T;
|
||||
|
||||
auto SeamAllowanceMirrorLine(const QLineF &seamMirrorLine, const QVector<QPointF> &seamAllowancePoints) const
|
||||
-> QLineF;
|
||||
|
||||
protected:
|
||||
static auto IsEkvPointOnLine(const QPointF &iPoint, const QPointF &prevPoint, const QPointF &nextPoint) -> bool;
|
||||
static auto IsEkvPointOnLine(const VSAPoint &iPoint, const VSAPoint &prevPoint, const VSAPoint &nextPoint) -> bool;
|
||||
|
|
|
@ -834,7 +834,19 @@ auto VLayoutPiece::GetFullSeamAllowancePoints() const -> QVector<VLayoutPoint>
|
|||
points.reserve(d->m_seamAllowance.size());
|
||||
if (!d->m_seamAllowanceMirrorLine.isNull() && IsShowFullPiece())
|
||||
{
|
||||
points = VAbstractPiece::FullSeamAllowancePath(d->m_seamAllowance, d->m_seamAllowanceMirrorLine, GetName());
|
||||
QLineF seamAllowanceMirrorLine = d->m_seamAllowanceMirrorLine;
|
||||
{ // Trying to correct a seam allowance mirror line based on seam mirror line
|
||||
QVector<QPointF> seamAllowance;
|
||||
CastTo(d->m_seamAllowance, seamAllowance);
|
||||
|
||||
if (!VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p1()) ||
|
||||
!VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p2()))
|
||||
{
|
||||
seamAllowanceMirrorLine = SeamAllowanceMirrorLine(d->m_seamMirrorLine, seamAllowance);
|
||||
}
|
||||
}
|
||||
|
||||
points = VAbstractPiece::FullSeamAllowancePath(d->m_seamAllowance, seamAllowanceMirrorLine, GetName());
|
||||
points = CheckLoops(CorrectEquidistantPoints(points)); // A path can contains loops
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1670,37 +1670,10 @@ auto VPiece::SeamAllowanceMirrorLine(const VContainer *data) const -> QLineF
|
|||
{
|
||||
QLineF seamMirrorLine = SeamMirrorLine(data);
|
||||
|
||||
if (!IsSeamAllowance() || (IsSeamAllowance() && IsSeamAllowanceBuiltIn()))
|
||||
{
|
||||
return seamMirrorLine;
|
||||
}
|
||||
|
||||
auto rec = QRectF(0, 0, INT_MAX, INT_MAX);
|
||||
rec.translate(-INT_MAX / 2.0, -INT_MAX / 2.0);
|
||||
|
||||
auto axis =
|
||||
QLineF(seamMirrorLine.center(), VGObject::BuildRay(seamMirrorLine.center(), seamMirrorLine.angle() + 180, rec));
|
||||
|
||||
QVector<QPointF> points;
|
||||
CastTo(SeamAllowancePoints(data), points);
|
||||
|
||||
QVector<QPointF> intersections = VAbstractCurve::CurveIntersectLine(points, axis);
|
||||
if (intersections.isEmpty())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const QPointF startPoint = intersections.constFirst();
|
||||
|
||||
std::reverse(points.begin(), points.end());
|
||||
axis = QLineF(seamMirrorLine.center(), VGObject::BuildRay(seamMirrorLine.center(), seamMirrorLine.angle(), rec));
|
||||
intersections = VAbstractCurve::CurveIntersectLine(points, axis);
|
||||
if (intersections.isEmpty())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return {startPoint, intersections.constFirst()};
|
||||
return VAbstractPiece::SeamAllowanceMirrorLine(seamMirrorLine, points);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue