From 5eb8784cd4117394e008efe3d7759be1d4d0ff06 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 23 Jan 2021 15:24:44 +0200 Subject: [PATCH] New warning. Grainline is not valid. --- ChangeLog.txt | 1 + src/libs/vlayout/vabstractpiece.cpp | 16 +++++++++++++ src/libs/vlayout/vabstractpiece.h | 2 ++ src/libs/vlayout/vlayoutpaper.cpp | 2 +- src/libs/vlayout/vlayoutpiece.cpp | 16 ------------- src/libs/vlayout/vlayoutpiece.h | 2 -- src/libs/vlayout/vposition.cpp | 4 ++-- src/libs/vtools/tools/vtoolseamallowance.cpp | 25 ++++++++++++++++++++ src/libs/vtools/tools/vtoolseamallowance.h | 5 ++++ src/libs/vwidgets/vgrainlineitem.cpp | 6 +++++ src/libs/vwidgets/vgrainlineitem.h | 2 ++ 11 files changed, 60 insertions(+), 21 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index fba33b609..fb3747ffa 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ - Improve multisize measurements format. Allow decimal step 0.5. - Improve restrict dimension dialog. Disable not available combinations. - Improve multisize measurements format. Allow excluding combinations inside min/max range. +- New warning. Grainline is not valid. # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index 5415a4682..186967b2b 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -1919,3 +1919,19 @@ QVector VAbstractPiece::GrainlinePoints(const VGrainlineData &geom, con return CorrectPosition(boundingRect, v); } + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VAbstractPiece::PainterPath(const QVector &points) +{ + QPainterPath path; + path.setFillRule(Qt::WindingFill); + + path.moveTo(points.at(0)); + for (qint32 i = 1; i < points.count(); ++i) + { + path.lineTo(points.at(i)); + } + path.lineTo(points.at(0)); + + return path; +} diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index ef3386c8c..177efa4bd 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -114,6 +114,8 @@ public: static QVector GrainlinePoints(const VGrainlineData &geom, const VContainer *pattern, const QRectF &boundingRect, qreal &dAng); + static QPainterPath PainterPath(const QVector &points); + friend QDataStream& operator<< (QDataStream& dataStream, const VAbstractPiece& piece); friend QDataStream& operator>> (QDataStream& dataStream, VAbstractPiece& piece); diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 9a77ccd7b..c20b862ac 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -305,7 +305,7 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece VCachedPositions positionChache; QVector layoutPoints = workDetail.GetLayoutAllowancePoints(); positionChache.boundingRect = VLayoutPiece::BoundingRect(layoutPoints); - positionChache.layoutAllowancePath = VLayoutPiece::PainterPath(layoutPoints); + positionChache.layoutAllowancePath = VAbstractPiece::PainterPath(layoutPoints); d->positionsCache.append(positionChache); #ifdef LAYOUT_DEBUG diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index f92062db1..7248e2299 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -1140,22 +1140,6 @@ QPainterPath VLayoutPiece::LayoutAllowancePath() const return PainterPath(GetLayoutAllowancePoints()); } -//--------------------------------------------------------------------------------------------------------------------- -QPainterPath VLayoutPiece::PainterPath(const QVector &points) -{ - QPainterPath path; - path.setFillRule(Qt::WindingFill); - - path.moveTo(points.at(0)); - for (qint32 i = 1; i < points.count(); ++i) - { - path.lineTo(points.at(i)); - } - path.lineTo(points.at(0)); - - return path; -} - //--------------------------------------------------------------------------------------------------------------------- QGraphicsItem *VLayoutPiece::GetItem(bool textAsPaths) const { diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index 509bf18ac..77c5bc132 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -149,8 +149,6 @@ public: QPainterPath ContourPath() const; QPainterPath LayoutAllowancePath() const; - static QPainterPath PainterPath(const QVector &points); - Q_REQUIRED_RESULT QGraphicsItem *GetItem(bool textAsPaths) const; bool IsLayoutAllowanceValid() const; diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 4570d8ab0..6d4eb99be 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -471,12 +471,12 @@ VPosition::CrossingType VPosition::Crossing(const VLayoutPiece &detail) const const QVector layoutPoints = detail.GetLayoutAllowancePoints(); const QRectF layoutBoundingRect = VLayoutPiece::BoundingRect(layoutPoints); - const QPainterPath layoutAllowancePath = VLayoutPiece::PainterPath(layoutPoints); + const QPainterPath layoutAllowancePath = VAbstractPiece::PainterPath(layoutPoints); const QVector contourPoints = detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn() ? detail.GetMappedSeamAllowancePoints() : detail.GetMappedContourPoints(); const QRectF detailBoundingRect = VLayoutPiece::BoundingRect(contourPoints); - const QPainterPath contourPath = VLayoutPiece::PainterPath(contourPoints); + const QPainterPath contourPath = VAbstractPiece::PainterPath(contourPoints); for(auto &position : m_data.positionsCache) { diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index c20bb4cf0..83360b4fb 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -681,6 +681,14 @@ void VToolSeamAllowance::UpdateGrainline() m_grainLine->UpdateGeometry(pos, dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit()), geom.GetArrowType()); m_grainLine->show(); + + if (m_geometryIsReady && not IsGrainlinePositionValid()) + { + const QString errorMsg = QObject::tr("Piece '%1'. Grainline is not valid.") + .arg(detail.GetName()); + qApp->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } } else { @@ -1366,6 +1374,9 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren) m_passmarks->setPath(futurePassmarks.result()); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + + // Now we can start checking validity of the grainline + m_geometryIsReady = true; } //--------------------------------------------------------------------------------------------------------------------- @@ -1950,6 +1961,20 @@ QList VToolSeamAllowance::SelectedTools() const return tools; } +//--------------------------------------------------------------------------------------------------------------------- +auto VToolSeamAllowance::IsGrainlinePositionValid() const -> bool +{ + QLineF grainLine = m_grainLine->Grainline(); + QPainterPath grainLinePath = VAbstractPiece::PainterPath(QVector{grainLine.p1(), grainLine.p2()}); + + const VPiece detail = VAbstractTool::data.GetPiece(m_id); + const QVector contourPoints = detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn() ? + detail.SeamAllowancePoints(getData()) : detail.MainPathPoints(getData()); + const QPainterPath contourPath = VAbstractPiece::PainterPath(contourPoints); + + return contourPath.contains(grainLinePath); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::AddPointRecords(VAbstractPattern *doc, QDomElement &domElement, const QVector &records, const QString &tag) diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index bea05f8d6..ce8c86963 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -191,6 +191,9 @@ private: bool m_acceptHoverEvents; + /** @brief m_geometryIsReady is true when a piece's geometry is ready and checks for validity can be enabled. */ + bool m_geometryIsReady{false}; + VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr); void UpdateExcludeState(); @@ -213,6 +216,8 @@ private: QList SelectedTools() const; + bool IsGrainlinePositionValid() const; + static void AddPointRecords(VAbstractPattern *doc, QDomElement &domElement, const QVector &records, const QString &tag); diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index abd9de867..584abd700 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -264,6 +264,12 @@ bool VGrainlineItem::IsContained(const QPointF& pt, qreal dRot, qreal &dX, qreal return bInside; } +//--------------------------------------------------------------------------------------------------------------------- +QLineF VGrainlineItem::Grainline() const +{ + return {m_ptStart, m_ptFinish}; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGrainlineItem::mousePressEvent handles left button mouse press events diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index d9024247a..cbd05fe7d 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -50,6 +50,8 @@ public: bool IsContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const; + QLineF Grainline() const; + signals: void SignalResized(qreal dLength); void SignalRotated(qreal dRot, const QPointF& ptNewPos);