From 0446a0653ca213eb565b131763f1e71316a9476d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 24 Feb 2019 06:58:35 +0200 Subject: [PATCH] Don't block moving piece label or grainline if pin id is not valid. --HG-- branch : develop --- src/libs/vtools/tools/vtoolseamallowance.cpp | 33 ++++++++++++-------- src/libs/vtools/tools/vtoolseamallowance.h | 12 +++---- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 00280049e..70e1b57bf 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -600,13 +600,14 @@ void VToolSeamAllowance::UpdateDetailLabel() { const VPiece detail = VAbstractTool::data.GetPiece(m_id); const VPieceLabelData& labelData = detail.GetPatternPieceData(); + const QVector &pins = detail.GetPins(); if (labelData.IsVisible() == true) { QPointF pos; qreal labelAngle = 0; - if (PrepareLabelData(labelData, m_dataLabel, pos, labelAngle)) + if (PrepareLabelData(labelData, pins, m_dataLabel, pos, labelAngle)) { m_dataLabel->UpdateData(detail.GetName(), labelData); UpdateLabelItem(m_dataLabel, pos, labelAngle); @@ -626,13 +627,14 @@ void VToolSeamAllowance::UpdatePatternInfo() { const VPiece detail = VAbstractTool::data.GetPiece(m_id); const VPatternLabelData& geom = detail.GetPatternInfo(); + const QVector &pins = detail.GetPins(); if (geom.IsVisible() == true) { QPointF pos; qreal labelAngle = 0; - if (PrepareLabelData(geom, m_patternInfo, pos, labelAngle)) + if (PrepareLabelData(geom, pins, m_patternInfo, pos, labelAngle)) { m_patternInfo->UpdateData(doc); UpdateLabelItem(m_patternInfo, pos, labelAngle); @@ -652,6 +654,7 @@ void VToolSeamAllowance::UpdateGrainline() { const VPiece detail = VAbstractTool::data.GetPiece(m_id); const VGrainlineData& geom = detail.GetGrainlineGeometry(); + const QVector &pins = detail.GetPins(); if (geom.IsVisible() == true) { @@ -659,7 +662,7 @@ void VToolSeamAllowance::UpdateGrainline() qreal dRotation = 0; qreal dLength = 0; - const VGrainlineItem::MoveTypes type = FindGrainlineGeometry(geom, dLength, dRotation, pos); + const VGrainlineItem::MoveTypes type = FindGrainlineGeometry(geom, pins, dLength, dRotation, pos); if (type & VGrainlineItem::Error) { m_grainLine->hide(); @@ -1518,7 +1521,8 @@ void VToolSeamAllowance::ToggleNodePointPassmark(quint32 id, bool toggle) } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &rotationAngle, +VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, + const QVector &pins, qreal &rotationAngle, qreal &labelWidth, qreal &labelHeight, QPointF &pos) { @@ -1542,7 +1546,8 @@ VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelD const quint32 topLeftPin = labelData.TopLeftPin(); const quint32 bottomRightPin = labelData.BottomRightPin(); - if (topLeftPin != NULL_ID && bottomRightPin != NULL_ID) + if (topLeftPin != NULL_ID && pins.contains(topLeftPin) && bottomRightPin != NULL_ID + && pins.contains(bottomRightPin)) { try { @@ -1591,7 +1596,7 @@ VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelD } const quint32 centerPin = labelData.CenterPin(); - if (centerPin != NULL_ID) + if (centerPin != NULL_ID && pins.contains(centerPin)) { try { @@ -1617,13 +1622,14 @@ VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelD } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveTypes VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, - qreal &rotationAngle, QPointF &pos) +VPieceItem::MoveTypes VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, + const QVector &pins, qreal &length, + qreal &rotationAngle, QPointF &pos) { const quint32 topPin = geom.TopPin(); const quint32 bottomPin = geom.BottomPin(); - if (topPin != NULL_ID && bottomPin != NULL_ID) + if (topPin != NULL_ID && pins.contains(topPin) && bottomPin != NULL_ID && pins.contains(bottomPin)) { try { @@ -1675,7 +1681,7 @@ VPieceItem::MoveTypes VToolSeamAllowance::FindGrainlineGeometry(const VGrainline } const quint32 centerPin = geom.CenterPin(); - if (centerPin != NULL_ID) + if (centerPin != NULL_ID && pins.contains(centerPin)) { try { @@ -1838,14 +1844,15 @@ void VToolSeamAllowance::ToolCreation(const Source &typeCreation) } //--------------------------------------------------------------------------------------------------------------------- -bool VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, VTextGraphicsItem *labelItem, - QPointF &pos, qreal &labelAngle) +bool VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, const QVector &pins, + VTextGraphicsItem *labelItem, QPointF &pos, qreal &labelAngle) { SCASSERT(labelItem != nullptr) qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelAngle, labelWidth, labelHeight, pos); + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, pins, labelAngle, labelWidth, labelHeight, + pos); if (type & VGrainlineItem::Error) { labelItem->hide(); diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 85d0bfb00..c102ab98f 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -193,10 +193,10 @@ private: void UpdateExcludeState(); void UpdateInternalPaths(); - VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &rotationAngle, qreal &labelWidth, - qreal &labelHeight, QPointF &pos); - VPieceItem::MoveTypes FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, - QPointF &pos); + VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, const QVector &pins, + qreal &rotationAngle, qreal &labelWidth, qreal &labelHeight, QPointF &pos); + VPieceItem::MoveTypes FindGrainlineGeometry(const VGrainlineData &geom, const QVector &pins, qreal &length, + qreal &rotationAngle, QPointF &pos); void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); static void InitNode(const VPieceNode &node, VMainGraphicsScene *scene, VContainer *data, VAbstractPattern *doc, @@ -205,8 +205,8 @@ private: void InitInternalPaths(const VPiece &detail); void InitSpecialPoints(const QVector &points) const; - bool PrepareLabelData(const VPatternLabelData &labelData, VTextGraphicsItem *labelItem, QPointF &pos, - qreal &labelAngle); + bool PrepareLabelData(const VPatternLabelData &labelData, const QVector &pins, + VTextGraphicsItem *labelItem, QPointF &pos, qreal &labelAngle); void UpdateLabelItem(VTextGraphicsItem *labelItem, QPointF pos, qreal labelAngle); QList SelectedTools() const;