From fb402f84b75606a364327652f3749f76e6c85467 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 9 Mar 2017 13:10:46 +0200 Subject: [PATCH 01/29] Dialog get/set grainline center pin point. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 3 + src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.4.3.xsd | 861 ++++++++++++++++++ src/libs/ifc/xml/vpatternconverter.cpp | 23 +- src/libs/ifc/xml/vpatternconverter.h | 5 +- .../floatItemData/vgrainlinedata.cpp | 12 + .../vpatterndb/floatItemData/vgrainlinedata.h | 3 + .../floatItemData/vgrainlinedata_p.h | 4 + .../dialogs/tools/dialogseamallowance.cpp | 3 + .../dialogs/tools/dialogseamallowance.ui | 75 +- src/libs/vtools/tools/vtoolseamallowance.cpp | 12 +- src/libs/vtools/tools/vtoolseamallowance.h | 1 + 12 files changed, 974 insertions(+), 29 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.4.3.xsd diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b38fe5a81..c463c78a9 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -889,6 +889,9 @@ void VPattern::ParsePieceGrainline(const QDomElement &domElement, VPiece &detail ArrowType eAT = static_cast(GetParametrUInt(domElement, AttrArrows, "0")); detail.GetGrainlineGeometry().SetArrowType(eAT); + const quint32 centerPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR); + detail.GetGrainlineGeometry().SetCenterPin(centerPin); + const quint32 topPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopPin, NULL_ID_STR); detail.GetGrainlineGeometry().SetTopPin(topPin); diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 95b4fe6f2..1056de83e 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -26,6 +26,7 @@ schema/pattern/v0.4.0.xsd schema/pattern/v0.4.1.xsd schema/pattern/v0.4.2.xsd + schema/pattern/v0.4.3.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.4.3.xsd b/src/libs/ifc/schema/pattern/v0.4.3.xsd new file mode 100644 index 000000000..39205474a --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.4.3.xsd @@ -0,0 +1,861 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 4b8f40465..64fc3c4e6 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.2"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.2.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.3"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.3.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -202,6 +202,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000401): return QStringLiteral("://schema/pattern/v0.4.1.xsd"); case (0x000402): + return QStringLiteral("://schema/pattern/v0.4.2.xsd"); + case (0x000403): return CurrentSchema; default: InvalidVersion(ver); @@ -315,6 +317,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000402), m_convertedFileName); V_FALLTHROUGH case (0x000402): + ToV0_4_3(); + ValidateXML(XSDSchema(0x000403), m_convertedFileName); + V_FALLTHROUGH + case (0x000403): break; default: InvalidVersion(m_ver); @@ -333,7 +339,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 4, 2), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 4, 3), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -638,6 +644,17 @@ void VPatternConverter::ToV0_4_2() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_4_3() +{ + // TODO. Delete if minimal supported version is 0.4.3 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 3), + "Time to refactor the code."); + + SetVersion(QStringLiteral("0.4.3")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 82636f2b5..73310c676 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -55,10 +55,10 @@ public: // GCC 4.6 doesn't allow constexpr and const together #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406 static Q_DECL_CONSTEXPR int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 2); + static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 3); #else static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 2); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 3); #endif protected: @@ -103,6 +103,7 @@ private: void ToV0_4_0(); void ToV0_4_1(); void ToV0_4_2(); + void ToV0_4_3(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp b/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp index de189c075..a0ed3eecf 100644 --- a/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp @@ -95,6 +95,18 @@ void VGrainlineData::SetArrowType(ArrowType eAT) d->m_eArrowType = eAT; } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VGrainlineData::CenterPin() const +{ + return d->m_centerPin; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineData::SetCenterPin(quint32 centerPin) +{ + d->m_centerPin = centerPin; +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VGrainlineData::TopPin() const { diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata.h b/src/libs/vpatterndb/floatItemData/vgrainlinedata.h index dc259bf0e..97c247a37 100644 --- a/src/libs/vpatterndb/floatItemData/vgrainlinedata.h +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata.h @@ -59,6 +59,9 @@ public: ArrowType GetArrowType() const; void SetArrowType(ArrowType eAT); + quint32 CenterPin() const; + void SetCenterPin(quint32 centerPin); + quint32 TopPin() const; void SetTopPin(quint32 topPin); diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h b/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h index cb85be652..5f336dfad 100644 --- a/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h @@ -46,6 +46,7 @@ public: : m_qsLength(), m_dRotation(), m_eArrowType(ArrowType::atBoth), + m_centerPin(NULL_ID), m_topPin(NULL_ID), m_bottomPin(NULL_ID) {} @@ -55,6 +56,7 @@ public: m_qsLength(data.m_qsLength), m_dRotation(data.m_dRotation), m_eArrowType(data.m_eArrowType), + m_centerPin(data.m_centerPin), m_topPin(data.m_topPin), m_bottomPin(data.m_bottomPin) {} @@ -67,6 +69,8 @@ public: QString m_dRotation; /** @brief m_eArrowType type of arrow on the grainline */ ArrowType m_eArrowType; + /** @brief m_centerPin center pin id */ + quint32 m_centerPin; /** @brief m_topPin top pin id */ quint32 m_topPin; /** @brief m_bottomPin bottom pin id */ diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 01924a406..08c66d379 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -226,6 +226,7 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) ChangeCurrentData(ui->comboBoxPatternLabelBottomRightPin, m_oldGeom.BottomRightPin()); m_oldGrainline = piece.GetGrainlineGeometry(); + ChangeCurrentData(ui->comboBoxGrainlineCenterPin, m_oldGrainline.CenterPin()); ChangeCurrentData(ui->comboBoxGrainlineTopPin, m_oldGrainline.TopPin()); ChangeCurrentData(ui->comboBoxGrainlineBottomPin, m_oldGrainline.BottomPin()); @@ -1410,6 +1411,7 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.GetGrainlineGeometry().SetRotation(GetFormulaFromUser(ui->lineEditRotFormula)); piece.GetGrainlineGeometry().SetLength(GetFormulaFromUser(ui->lineEditLenFormula)); piece.GetGrainlineGeometry().SetArrowType(static_cast(ui->comboBoxArrow->currentIndex())); + piece.GetGrainlineGeometry().SetCenterPin(getCurrentObjectId(ui->comboBoxGrainlineCenterPin)); piece.GetGrainlineGeometry().SetTopPin(getCurrentObjectId(ui->comboBoxGrainlineTopPin)); piece.GetGrainlineGeometry().SetBottomPin(getCurrentObjectId(ui->comboBoxGrainlineBottomPin)); @@ -1882,6 +1884,7 @@ void DialogSeamAllowance::InitGrainlineTab() m_iRotBaseHeight = ui->lineEditRotFormula->height(); m_iLenBaseHeight = ui->lineEditLenFormula->height(); + InitPinPoint(ui->comboBoxGrainlineCenterPin); InitPinPoint(ui->comboBoxGrainlineTopPin); InitPinPoint(ui->comboBoxGrainlineBottomPin); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index d9637e9e7..3ed545f5e 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -1522,10 +1522,59 @@ - - - QFormLayout::ExpandingFieldsGrow + + + + + Center pin: + + + + + + + + + + + + Qt::Horizontal + + + + + + + + Top pin: + + + + + + + + + + Bottom pin: + + + + + + + + + + + + Qt::Horizontal + + + + + @@ -1542,26 +1591,6 @@ - - - - Top pin: - - - - - - - Bottom pin: - - - - - - - - - diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index f7576d5ab..369847097 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -62,7 +62,7 @@ #include #include -// Current version of seam allowance tag nned for backward compatibility +// Current version of seam allowance tag need for backward compatibility const quint8 VToolSeamAllowance::pieceVersion = 2; const QString VToolSeamAllowance::TagCSA = QStringLiteral("csa"); @@ -78,6 +78,7 @@ const QString VToolSeamAllowance::AttrUnited = QStringLiteral("united"); const QString VToolSeamAllowance::AttrFont = QStringLiteral("fontSize"); const QString VToolSeamAllowance::AttrTopLeftPin = QStringLiteral("topLeftPin"); const QString VToolSeamAllowance::AttrBottomRightPin = QStringLiteral("bottomRightPin"); +const QString VToolSeamAllowance::AttrCenterPin = QStringLiteral("centerPin"); const QString VToolSeamAllowance::AttrTopPin = QStringLiteral("topPin"); const QString VToolSeamAllowance::AttrBottomPin = QStringLiteral("bottomPin"); @@ -338,6 +339,15 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle doc->SetAttribute(domData, VAbstractPattern::AttrRotation, glGeom.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType())); + if (glGeom.CenterPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrCenterPin, glGeom.CenterPin()); + } + else + { + domData.removeAttribute(AttrCenterPin); + } + if (glGeom.TopPin() > NULL_ID) { doc->SetAttribute(domData, AttrTopPin, glGeom.TopPin()); diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index f402721dc..82b7c5498 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -68,6 +68,7 @@ public: static const QString AttrFont; static const QString AttrTopLeftPin; static const QString AttrBottomRightPin; + static const QString AttrCenterPin; static const QString AttrTopPin; static const QString AttrBottomPin; From af3735ea23c8ed93bd269e91ddea752d2136d790 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 10 Mar 2017 16:22:19 +0200 Subject: [PATCH 02/29] Grainline now can be controlled by center pin point. --HG-- branch : feature --- .../dialogs/tools/dialogseamallowance.cpp | 1 + .../dialogs/tools/dialogseamallowance.ui | 9 ++ src/libs/vtools/tools/vtoolseamallowance.cpp | 65 +++++---- src/libs/vtools/tools/vtoolseamallowance.h | 8 +- src/libs/vwidgets/vgrainlineitem.cpp | 137 ++++++++++++------ src/libs/vwidgets/vgrainlineitem.h | 4 + src/libs/vwidgets/vpieceitem.cpp | 4 +- src/libs/vwidgets/vpieceitem.h | 27 +++- src/libs/vwidgets/vtextgraphicsitem.cpp | 4 +- 9 files changed, 176 insertions(+), 83 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 08c66d379..8265dab82 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -1907,6 +1907,7 @@ void DialogSeamAllowance::InitPinsTab() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitAllPinComboboxes() { + InitPinPoint(ui->comboBoxGrainlineCenterPin); InitPinPoint(ui->comboBoxGrainlineTopPin); InitPinPoint(ui->comboBoxGrainlineBottomPin); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index 3ed545f5e..bee0149c9 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -1523,6 +1523,9 @@ + + QFormLayout::ExpandingFieldsGrow + @@ -1544,6 +1547,9 @@ + + QFormLayout::ExpandingFieldsGrow + @@ -1575,6 +1581,9 @@ + + QFormLayout::ExpandingFieldsGrow + diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 369847097..6618fc8db 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -495,7 +495,7 @@ void VToolSeamAllowance::UpdateLabel() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveType type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos); + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos); m_dataLabel->SetMoveType(type); QFont fnt = qApp->font(); @@ -544,7 +544,7 @@ void VToolSeamAllowance::UpdatePatternInfo() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveType type = FindLabelGeometry(geom, labelWidth, labelHeight, pos); + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(geom, labelWidth, labelHeight, pos); m_patternInfo->SetMoveType(type); QFont fnt = qApp->font(); @@ -596,8 +596,8 @@ void VToolSeamAllowance::UpdateGrainline() qreal dRotation = 0; qreal dLength = 0; - const VGrainlineItem::MoveType type = FindGrainlineGeometry(geom, dLength, dRotation, pos); - if (type == VGrainlineItem::Error) + const VGrainlineItem::MoveTypes type = FindGrainlineGeometry(geom, dLength, dRotation, pos); + if (type & VGrainlineItem::Error) { m_grainLine->hide(); return; @@ -1167,7 +1167,7 @@ void VToolSeamAllowance::SaveDialogChange() } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, +VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, qreal &labelHeight, QPointF &pos) { const quint32 topLeftPin = labelData.TopLeftPin(); @@ -1186,7 +1186,7 @@ VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelDa pos = labelRect.topLeft(); - return VTextGraphicsItem::OnlyRotatable; + return VTextGraphicsItem::IsRotatable; } catch(const VExceptionBadId &) { @@ -1201,7 +1201,7 @@ VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelDa } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, +VPieceItem::MoveTypes VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, qreal &rotationAngle, QPointF &pos) { const quint32 topPin = geom.TopPin(); @@ -1233,16 +1233,21 @@ VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineD } } - bool isResizable = false; - bool isRotatable = false; + VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications; try { - isRotatable = qmu::QmuTokenParser::IsSingle(geom.GetRotation()); + if (not qmu::QmuTokenParser::IsSingle(geom.GetRotation())) + { + restrictions &= ~ VPieceItem::IsRotatable; + } Calculator cal1; rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetRotation()); - isResizable = qmu::QmuTokenParser::IsSingle(geom.GetLength()); + if (not qmu::QmuTokenParser::IsSingle(geom.GetLength())) + { + restrictions &= ~ VPieceItem::IsResizable; + } Calculator cal2; length = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetLength()); @@ -1253,25 +1258,35 @@ VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineD return VPieceItem::Error; } - pos = geom.GetPos(); - - if (isResizable && isRotatable) + const quint32 centerPin = geom.CenterPin(); + if (centerPin != NULL_ID) { - return VPieceItem::AllModifications; + try + { + const auto centerPinPoint = VAbstractTool::data.GeometricObject(centerPin); + + const qreal cLength = ToPixel(length, *VDataTool::data.GetPatternUnit()); + QLineF grainline(centerPinPoint->x(), centerPinPoint->y(), + centerPinPoint->x() + cLength / 2.0, centerPinPoint->y()); + + grainline.setAngle(rotationAngle); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(cLength); + + pos = grainline.p2(); + restrictions &= ~ VPieceItem::IsMovable; + } + catch(const VExceptionBadId &) + { + pos = geom.GetPos(); + } } else { - if (isResizable) - { - return VPieceItem::OnlyResizable; - } - - if (isRotatable) - { - return VPieceItem::OnlyRotatable; - } + pos = geom.GetPos(); } - return VPieceItem::OnlyMovable; + + return restrictions; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 82b7c5498..ab77960d9 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -152,10 +152,10 @@ private: void RefreshGeometry(); void SaveDialogChange(); - VPieceItem::MoveType FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, - QPointF &pos); - VPieceItem::MoveType FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, - QPointF &pos); + VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, + QPointF &pos); + VPieceItem::MoveTypes FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, + QPointF &pos); void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); void InitCSAPaths(const VPiece &detail); diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 124093cd3..b09599902 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -292,51 +292,66 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) m_dAngle = GetAngle(mapToParent(pME->pos())); m_ptRotCenter = m_ptCenter; - if (m_moveType == OnlyRotatable) + if ((m_moveType & AllModifications ) == AllModifications) { - if (m_eMode != mRotate) + AllUserModifications(pME->pos()); + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsRotatable) + { + if (m_moveType & IsResizable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserRotateAndMove(); + } + else + { + m_eMode = mRotate; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsResizable) + { + if (m_moveType & IsRotatable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserMoveAndResize(pME->pos()); + } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsMovable) + { + if (m_moveType & IsRotatable) + { + UserRotateAndMove(); + } + else if (m_moveType & IsResizable) + { + UserMoveAndResize(pME->pos()); + } + else { m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } - else - { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } setZValue(ACTIVE_Z); Update(); } - else if (m_moveType == OnlyMovable) + else { - m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - - setZValue(ACTIVE_Z); - Update(); - } - else // All modifications - { - if (m_eMode != mRotate) - { - if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true) - { - m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); - } - else - { - m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - } - else - { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - - setZValue(ACTIVE_Z); - Update(); + pME->ignore(); + return; } } } @@ -351,7 +366,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) QPointF ptDiff = pME->scenePos() - m_ptStartMove; qreal dX; qreal dY; - if (m_eMode == mMove) + if (m_eMode == mMove && m_moveType & IsMovable) { QPointF pt = m_ptStartPos + ptDiff; if (IsContained(pt, m_dRotation, dX, dY) == false) @@ -362,7 +377,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) setPos(pt); Update(); } - else if (m_eMode == mResize) + else if (m_eMode == mResize && m_moveType & IsResizable) { qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); qreal dAng = qAtan2(-ptDiff.y(), ptDiff.x()); @@ -379,7 +394,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) UpdateRectangle(); Update(); } - else if (m_eMode == mRotate) + else if (m_eMode == mRotate && m_moveType & IsRotatable) { // prevent strange angle changes due to singularities qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); @@ -433,7 +448,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (bShort == true) { - if (m_bReleased == true && m_moveType != OnlyResizable && m_moveType != OnlyMovable) + if (m_bReleased == true && m_moveType & IsRotatable) { m_eMode = mRotate; Update(); @@ -441,11 +456,11 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } else { - if (m_eMode == mMove) + if (m_eMode == mMove && m_moveType & IsMovable) { emit SignalMoved(pos()); } - else + else if (m_moveType & IsResizable) { emit SignalResized(m_dLength); } @@ -458,7 +473,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { m_eMode = mMove; } - else + else if (m_moveType & IsRotatable) { emit SignalRotated(m_dRotation, m_ptStart); } @@ -687,3 +702,41 @@ QPainterPath VGrainlineItem::MainShape() const } return path; } + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::AllUserModifications(const QPointF &pos) +{ + if (m_eMode != mRotate) + { + UserMoveAndResize(pos); + } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UserRotateAndMove() +{ + if (m_eMode != mRotate) + { + m_eMode = mMove; + } + SetOverrideCursor(cursorArrowCloseHand, 1, 1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UserMoveAndResize(const QPointF &pos) +{ + if (m_polyResize.containsPoint(pos, Qt::OddEvenFill) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + m_eMode = mMove; // block later if need + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index e0fd31fe2..565719f03 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -89,6 +89,10 @@ private: QPolygonF SecondArrow(qreal dArrLen) const; QPainterPath MainShape() const; + + void AllUserModifications(const QPointF &pos); + void UserRotateAndMove(); + void UserMoveAndResize(const QPointF &pos); }; #endif // VGRAINLINEITEM_H diff --git a/src/libs/vwidgets/vpieceitem.cpp b/src/libs/vwidgets/vpieceitem.cpp index 5117b8c8c..375f5be9c 100644 --- a/src/libs/vwidgets/vpieceitem.cpp +++ b/src/libs/vwidgets/vpieceitem.cpp @@ -108,13 +108,13 @@ double VPieceItem::GetAngle(const QPointF &pt) const } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VPieceItem::GetMoveType() const +VPieceItem::MoveTypes VPieceItem::GetMoveType() const { return m_moveType; } //--------------------------------------------------------------------------------------------------------------------- -void VPieceItem::SetMoveType(const MoveType &moveType) +void VPieceItem::SetMoveType(const VPieceItem::MoveTypes &moveType) { m_moveType = moveType; setAcceptHoverEvents(m_moveType != NotMovable); diff --git a/src/libs/vwidgets/vpieceitem.h b/src/libs/vwidgets/vpieceitem.h index b97a95fb3..103158d6e 100644 --- a/src/libs/vwidgets/vpieceitem.h +++ b/src/libs/vwidgets/vpieceitem.h @@ -36,7 +36,16 @@ class VPieceItem : public QGraphicsObject { Q_OBJECT public: - enum MoveType {AllModifications, OnlyResizable, OnlyRotatable, OnlyMovable, NotMovable, Error}; + enum MoveType + { + NotMovable = 0x0, + IsRotatable = 0x1, // 0001 + IsResizable = 0x2, // 0010 + IsMovable = 0x4, // 0100 + AllModifications = IsRotatable | IsResizable | IsMovable, + Error = 0x8 // 1000 + }; + Q_DECLARE_FLAGS(MoveTypes, MoveType) explicit VPieceItem(QGraphicsItem* pParent = nullptr); virtual ~VPieceItem(); @@ -48,8 +57,8 @@ public: void Reset(); bool IsIdle() const; - MoveType GetMoveType() const; - void SetMoveType(const MoveType &moveType); + VPieceItem::MoveTypes GetMoveType() const; + void SetMoveType(const VPieceItem::MoveTypes &moveType); signals: void SignalMoved(const QPointF &ptPos); @@ -62,11 +71,11 @@ protected: mResize, mRotate }; - QRectF m_rectBoundingBox; - Mode m_eMode; - bool m_bReleased; - QPointF m_ptRotCenter; - MoveType m_moveType; + QRectF m_rectBoundingBox; + Mode m_eMode; + bool m_bReleased; + QPointF m_ptRotCenter; + VPieceItem::MoveTypes m_moveType; qreal m_inactiveZ; @@ -76,4 +85,6 @@ private: Q_DISABLE_COPY(VPieceItem) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(VPieceItem::MoveTypes) + #endif // VPIECEITEM_H diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 150562ddf..be206cbe8 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -414,7 +414,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) // in rotation mode, do not do any changes here, because user might want to // rotate the label more. - if (m_moveType == OnlyRotatable) + if (m_moveType & IsRotatable) { if (m_eMode != mRotate) { @@ -572,7 +572,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { // in rotate mode, if user did just press/release, switch to move mode if (bShort == true) { - if (m_moveType != OnlyRotatable) + if (not (m_moveType & IsRotatable)) { m_eMode = mMove; } From 4bec2bb815cbe36dc26f1efe34aa90be377d9d0a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 10 Mar 2017 16:27:56 +0200 Subject: [PATCH 03/29] Do not warn a user about wrong configuration if top and bottom pin points are not selected. --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogseamallowance.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 8265dab82..a21408d52 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -1288,7 +1288,8 @@ void DialogSeamAllowance::GrainlinePinPointChanged() QColor color = okColor; const quint32 topPinId = getCurrentObjectId(ui->comboBoxGrainlineTopPin); const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxGrainlineBottomPin); - if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId) + if ((topPinId == NULL_ID && bottomPinId == NULL_ID) || + (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) { flagGPin = true; color = okColor; From bf409006f5522e243a932aa3b8b489218271a4e5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 10 Mar 2017 16:45:41 +0200 Subject: [PATCH 04/29] Fix grainline's resize rectangle position. --HG-- branch : feature --- src/libs/vwidgets/vgrainlineitem.cpp | 40 +++++++++++----------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index b09599902..5c1b64e4f 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -513,48 +513,40 @@ void VGrainlineItem::Update() */ void VGrainlineItem::UpdateRectangle() { - m_polyBound.clear(); QPointF pt1(0, 0); - QPointF pt2; - - pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); - pt2.setY(pt1.y() - m_dLength * sin(m_dRotation)); + QPointF pt2(pt1.x() + m_dLength * cos(m_dRotation), pt1.y() - m_dLength * sin(m_dRotation)); m_ptStart = mapToParent(pt1); m_ptFinish = mapToParent(pt2); m_ptCenter = (m_ptStart + m_ptFinish)/2; - QPointF ptA; - ptA.setX(pt1.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2)); - ptA.setY(pt1.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); - m_polyBound << ptA; - ptA.setX(pt1.x() + RECT_WIDTH*cos(m_dRotation - M_PI/2)); - ptA.setY(pt1.y() - RECT_WIDTH*sin(m_dRotation - M_PI/2)); - m_polyBound << ptA; - ptA.setX(pt2.x() + RECT_WIDTH*cos(m_dRotation - M_PI/2)); - ptA.setY(pt2.y() - RECT_WIDTH*sin(m_dRotation - M_PI/2)); - m_polyBound << ptA; - ptA.setX(pt2.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2)); - ptA.setY(pt2.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); - m_polyBound << ptA; + m_polyBound.clear(); + m_polyBound << QPointF(pt1.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2), + pt1.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); + m_polyBound << QPointF(pt1.x() + RECT_WIDTH*cos(m_dRotation - M_PI/2), + pt1.y() - RECT_WIDTH*sin(m_dRotation - M_PI/2)); + m_polyBound << QPointF(pt2.x() + RECT_WIDTH*cos(m_dRotation - M_PI/2), + pt2.y() - RECT_WIDTH*sin(m_dRotation - M_PI/2)); + m_polyBound << QPointF(pt2.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2), + pt2.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); m_rectBoundingBox = m_polyBound.boundingRect(); setTransformOriginPoint(m_rectBoundingBox.center()); m_polyResize.clear(); - ptA = m_polyBound.at(2); + QPointF ptA = m_polyBound.at(3); m_polyResize << ptA; - double dSize = m_dScale * RESIZE_RECT_SIZE; + const double dSize = m_dScale * RESIZE_RECT_SIZE; - ptA.setX(ptA.x() + dSize*cos(m_dRotation + M_PI/2)); - ptA.setY(ptA.y() - dSize*sin(m_dRotation + M_PI/2)); + ptA.setX(ptA.x() + dSize*cos(m_dRotation - M_PI/2)); + ptA.setY(ptA.y() - dSize*sin(m_dRotation - M_PI/2)); m_polyResize << ptA; ptA.setX(ptA.x() - dSize*cos(m_dRotation)); ptA.setY(ptA.y() + dSize*sin(m_dRotation)); m_polyResize << ptA; - ptA.setX(ptA.x() + dSize*cos(m_dRotation - M_PI/2)); - ptA.setY(ptA.y() - dSize*sin(m_dRotation - M_PI/2)); + ptA.setX(ptA.x() + dSize*cos(m_dRotation + M_PI/2)); + ptA.setY(ptA.y() - dSize*sin(m_dRotation + M_PI/2)); m_polyResize << ptA; prepareGeometryChange(); From eb675f49cef5d4540f9bd8727f07c52f3af3960a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 10 Mar 2017 17:07:23 +0200 Subject: [PATCH 05/29] If selected center pin point resize by extending both sides. --HG-- branch : feature --- src/libs/vwidgets/vgrainlineitem.cpp | 33 +++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 5c1b64e4f..458b4609e 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -384,13 +384,44 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) dLen = dLen*qCos(dAng - m_dRotation); qreal dPrevLen = m_dLength; // try with new length + if (not (m_moveType & IsMovable)) + { + dLen *= 2; + } m_dLength = m_dStartLength + dLen; + + QPointF pos; + + if (m_moveType & IsMovable) + { + pos = m_ptStartPos; + } + else + { + QLineF grainline(m_ptCenter.x(), m_ptCenter.y(), + m_ptCenter.x() + m_dLength / 2.0, m_ptCenter.y()); + + grainline.setAngle(qRadiansToDegrees(m_dRotation)); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(m_dLength); + + pos = grainline.p2(); + } + qreal dX; qreal dY; - if (IsContained(m_ptStartPos, m_dRotation, dX, dY) == false) + if (IsContained(pos, m_dRotation, dX, dY) == false) { m_dLength = dPrevLen; } + else + { + if (not (m_moveType & IsMovable)) + { + setPos(pos); + } + } + UpdateRectangle(); Update(); } From 3442da18eeb24829cbbc10ed7e3b6b0932993faa Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 10 Mar 2017 19:14:14 +0200 Subject: [PATCH 06/29] Fix pattern format version after the merge. --HG-- branch : feature --- src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.4.4.xsd | 872 +++++++++++++++++++++++++ src/libs/ifc/xml/vpatternconverter.cpp | 23 +- src/libs/ifc/xml/vpatternconverter.h | 5 +- 4 files changed, 896 insertions(+), 5 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.4.4.xsd diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 12129b994..36ee8e5e6 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -27,6 +27,7 @@ schema/pattern/v0.4.1.xsd schema/pattern/v0.4.2.xsd schema/pattern/v0.4.3.xsd + schema/pattern/v0.4.4.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.4.4.xsd b/src/libs/ifc/schema/pattern/v0.4.4.xsd new file mode 100644 index 000000000..f1eabfd95 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.4.4.xsd @@ -0,0 +1,872 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 64fc3c4e6..a9182536b 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.3"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.3.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.4"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.4.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -204,6 +204,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000402): return QStringLiteral("://schema/pattern/v0.4.2.xsd"); case (0x000403): + return QStringLiteral("://schema/pattern/v0.4.3.xsd"); + case (0x000404): return CurrentSchema; default: InvalidVersion(ver); @@ -321,6 +323,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000403), m_convertedFileName); V_FALLTHROUGH case (0x000403): + ToV0_4_4(); + ValidateXML(XSDSchema(0x000404), m_convertedFileName); + V_FALLTHROUGH + case (0x000404): break; default: InvalidVersion(m_ver); @@ -339,7 +345,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 4, 3), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 4, 4), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -655,6 +661,17 @@ void VPatternConverter::ToV0_4_3() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_4_4() +{ + // TODO. Delete if minimal supported version is 0.4.4 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 4), + "Time to refactor the code."); + + SetVersion(QStringLiteral("0.4.4")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 73310c676..fedceebae 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -55,10 +55,10 @@ public: // GCC 4.6 doesn't allow constexpr and const together #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406 static Q_DECL_CONSTEXPR int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 3); + static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 4); #else static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 3); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 4); #endif protected: @@ -104,6 +104,7 @@ private: void ToV0_4_1(); void ToV0_4_2(); void ToV0_4_3(); + void ToV0_4_4(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); From 367c78936a7264b2a94219eb0cf234f0f8550f75 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 10 Mar 2017 19:31:48 +0200 Subject: [PATCH 07/29] Rename tab. --HG-- branch : feature --- .../vtools/dialogs/tools/dialogseamallowance.cpp | 12 ++++++------ src/libs/vtools/dialogs/tools/dialogseamallowance.ui | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index a21408d52..553633394 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -137,7 +137,7 @@ void DialogSeamAllowance::EnableApply(bool enable) applyAllowed = enable; ui->tabSeamAllowance->setEnabled(applyAllowed); ui->tabInternalPaths->setEnabled(applyAllowed); - ui->tabPatternPieceData->setEnabled(applyAllowed); + ui->tabPieceLabelData->setEnabled(applyAllowed); ui->tabGrainline->setEnabled(applyAllowed); ui->tabPins->setEnabled(applyAllowed); } @@ -920,7 +920,7 @@ void DialogSeamAllowance::TabChanged(int index) { if (index == ui->tabWidget->indexOf(ui->tabPins) || index == ui->tabWidget->indexOf(ui->tabGrainline) - || index == ui->tabWidget->indexOf(ui->tabPatternPieceData)) + || index == ui->tabWidget->indexOf(ui->tabPieceLabelData)) { if (m_visPins.isNull()) { @@ -1326,7 +1326,7 @@ void DialogSeamAllowance::DetailPinPointChanged() if (flagPPin) { - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), QIcon()); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPieceLabelData), QIcon()); } } else @@ -1335,7 +1335,7 @@ void DialogSeamAllowance::DetailPinPointChanged() color = errorColor; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), icon); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPieceLabelData), icon); } ChangeColor(ui->labelDetailLabelTopLeftPin, color); ChangeColor(ui->labelDetailLabelBottomRightPin, color); @@ -1356,7 +1356,7 @@ void DialogSeamAllowance::PatternPinPointChanged() if (flagDPin) { - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), QIcon()); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPieceLabelData), QIcon()); } } else @@ -1365,7 +1365,7 @@ void DialogSeamAllowance::PatternPinPointChanged() color = errorColor; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), icon); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPieceLabelData), icon); } ChangeColor(ui->labelPatternLabelTopLeftPin, color); ChangeColor(ui->labelPatternLabelBottomRightPin, color); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index bee0149c9..7105a1b4b 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -21,7 +21,7 @@ - 4 + 3 @@ -896,9 +896,9 @@ - + - Pattern piece data + Piece label data From 08d712ffb647728b714200b42c0d27e1bd1bf3a8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 11 Mar 2017 11:41:25 +0200 Subject: [PATCH 08/29] Show warning icon and pin points for tab Labels. --HG-- branch : feature --- .../dialogs/tools/dialogseamallowance.cpp | 11 +- .../dialogs/tools/dialogseamallowance.ui | 195 ++++++++++-------- 2 files changed, 115 insertions(+), 91 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 553633394..1fd14657f 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -138,6 +138,7 @@ void DialogSeamAllowance::EnableApply(bool enable) ui->tabSeamAllowance->setEnabled(applyAllowed); ui->tabInternalPaths->setEnabled(applyAllowed); ui->tabPieceLabelData->setEnabled(applyAllowed); + ui->tabLabels->setEnabled(applyAllowed); ui->tabGrainline->setEnabled(applyAllowed); ui->tabPins->setEnabled(applyAllowed); } @@ -920,7 +921,7 @@ void DialogSeamAllowance::TabChanged(int index) { if (index == ui->tabWidget->indexOf(ui->tabPins) || index == ui->tabWidget->indexOf(ui->tabGrainline) - || index == ui->tabWidget->indexOf(ui->tabPieceLabelData)) + || index == ui->tabWidget->indexOf(ui->tabLabels)) { if (m_visPins.isNull()) { @@ -1326,7 +1327,7 @@ void DialogSeamAllowance::DetailPinPointChanged() if (flagPPin) { - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPieceLabelData), QIcon()); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), QIcon()); } } else @@ -1335,7 +1336,7 @@ void DialogSeamAllowance::DetailPinPointChanged() color = errorColor; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPieceLabelData), icon); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); } ChangeColor(ui->labelDetailLabelTopLeftPin, color); ChangeColor(ui->labelDetailLabelBottomRightPin, color); @@ -1356,7 +1357,7 @@ void DialogSeamAllowance::PatternPinPointChanged() if (flagDPin) { - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPieceLabelData), QIcon()); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), QIcon()); } } else @@ -1365,7 +1366,7 @@ void DialogSeamAllowance::PatternPinPointChanged() color = errorColor; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPieceLabelData), icon); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); } ChangeColor(ui->labelPatternLabelTopLeftPin, color); ChangeColor(ui->labelPatternLabelBottomRightPin, color); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index 7105a1b4b..649d9382a 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -6,8 +6,8 @@ 0 0 - 521 - 611 + 639 + 680 @@ -20,9 +20,6 @@ - - 3 - Main path @@ -1027,87 +1024,17 @@ - - - - - Detail label visible - - - true - - - true - - - false - - - - QFormLayout::ExpandingFieldsGrow - - - - - Top left pin: - - - - - - - - - - Bottom right pin: - - - - - - - - - - - - - Pattern label visible - - - true - - - false - - - - QFormLayout::ExpandingFieldsGrow - - - - - Top left pin: - - - - - - - - - - Bottom right pin: - - - - - - - - - - + + + Qt::Vertical + + + + 20 + 40 + + + @@ -1126,6 +1053,102 @@ + + + Labels + + + + + 30 + 40 + 234 + 96 + + + + Detail label visible + + + true + + + true + + + false + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top left pin: + + + + + + + + + + Bottom right pin: + + + + + + + + + + + + 30 + 240 + 234 + 198 + + + + Pattern label visible + + + true + + + false + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top left pin: + + + + + + + + + + Bottom right pin: + + + + + + + + + Grainline From 38409f747faf5e8dae8506334e33b0bab694556b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 11 Mar 2017 15:25:21 +0200 Subject: [PATCH 09/29] Successful build. --HG-- branch : feature --- .../floatItemData/vpatternlabeldata.cpp | 12 + .../floatItemData/vpatternlabeldata.h | 3 + .../floatItemData/vpatternlabeldata_p.h | 4 + .../dialogs/tools/dialogseamallowance.cpp | 704 +++++++- .../dialogs/tools/dialogseamallowance.h | 56 +- .../dialogs/tools/dialogseamallowance.ui | 1512 ++++++++++++++++- 6 files changed, 2121 insertions(+), 170 deletions(-) diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp index e87f06ddd..a6015cee8 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp @@ -106,6 +106,18 @@ void VPatternLabelData::SetRotation(qreal dRot) d->m_dRotation = dRot; } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VPatternLabelData::CenterPin() const +{ + return d->m_centerPin; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternLabelData::SetCenterPin(const quint32 ¢erPin) +{ + d->m_centerPin = centerPin; +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VPatternLabelData::TopLeftPin() const { diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h index 29cdeffc3..efbc7624e 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h @@ -59,6 +59,9 @@ public: qreal GetRotation() const; void SetRotation(qreal dRot); + quint32 CenterPin() const; + void SetCenterPin(const quint32 ¢erPin); + quint32 TopLeftPin() const; void SetTopLeftPin(const quint32 &topLeftPin); diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h index 783addb83..2ec73a71b 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h @@ -46,6 +46,7 @@ public: m_dLabelHeight(0), m_iFontSize(0), m_dRotation(0), + m_centerPin(NULL_ID), m_topLeftPin(NULL_ID), m_bottomRightPin(NULL_ID) {} @@ -56,6 +57,7 @@ public: m_dLabelHeight(data.m_dLabelHeight), m_iFontSize(data.m_iFontSize), m_dRotation(data.m_dRotation), + m_centerPin(data.m_centerPin), m_topLeftPin(data.m_topLeftPin), m_bottomRightPin(data.m_bottomRightPin) {} @@ -70,6 +72,8 @@ public: int m_iFontSize; /** @brief m_dRotation label rotation */ qreal m_dRotation; + /** @brief m_centerPin center pin id */ + quint32 m_centerPin; /** @brief m_topLeftPin top left corner pin id */ quint32 m_topLeftPin; /** @brief m_bottomRightPin bottom right corner pin id */ diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 1fd14657f..4c7cb7619 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -74,6 +74,10 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & flagDPin(true), flagPPin(true), flagGFormulas(false), + flagDLAngle(false), + flagDLFormulas(false), + flagPLAngle(false), + flagPLFormulas(false), m_bAddMode(true), m_mx(0), m_my(0), @@ -87,6 +91,12 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & m_oldGrainline(), m_iRotBaseHeight(0), m_iLenBaseHeight(0), + m_DLWidthBaseHeight(0), + m_DLHeightBaseHeight(0), + m_DLAngleBaseHeight(0), + m_PLWidthBaseHeight(0), + m_PLHeightBaseHeight(0), + m_PLAngleBaseHeight(0), m_formulaBaseWidth(0), m_formulaBaseWidthBefore(0), m_formulaBaseWidthAfter(0), @@ -104,6 +114,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & InitSeamAllowanceTab(); InitInternalPathsTab(); InitPatternPieceDataTab(); + InitLabelsTab(); InitGrainlineTab(); InitPinsTab(); @@ -214,17 +225,19 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) UpdateList(); ui->groupBoxGrainline->setChecked(piece.GetGrainlineGeometry().IsVisible()); - SetGrainlineAngle(piece.GetGrainlineGeometry()); - SetGrainlineLength(piece.GetGrainlineGeometry()); + SetGrainlineAngle(piece.GetGrainlineGeometry().GetRotation()); + SetGrainlineLength(piece.GetGrainlineGeometry().GetLength()); ui->comboBoxArrow->setCurrentIndex(int(piece.GetGrainlineGeometry().GetArrowType())); m_oldData = piece.GetPatternPieceData(); - ChangeCurrentData(ui->comboBoxDetailLabelTopLeftPin, m_oldData.TopLeftPin()); - ChangeCurrentData(ui->comboBoxDetailLabelBottomRightPin, m_oldData.BottomRightPin()); + ChangeCurrentData(ui->comboBoxDLCenterPin, m_oldData.CenterPin()); + ChangeCurrentData(ui->comboBoxDLTopLeftPin, m_oldData.TopLeftPin()); + ChangeCurrentData(ui->comboBoxDLBottomRightPin, m_oldData.BottomRightPin()); m_oldGeom = piece.GetPatternInfo(); - ChangeCurrentData(ui->comboBoxPatternLabelTopLeftPin, m_oldGeom.TopLeftPin()); - ChangeCurrentData(ui->comboBoxPatternLabelBottomRightPin, m_oldGeom.BottomRightPin()); + ChangeCurrentData(ui->comboBoxPLCenterPin, m_oldGeom.CenterPin()); + ChangeCurrentData(ui->comboBoxPLTopLeftPin, m_oldGeom.TopLeftPin()); + ChangeCurrentData(ui->comboBoxPLBottomRightPin, m_oldGeom.BottomRightPin()); m_oldGrainline = piece.GetGrainlineGeometry(); ChangeCurrentData(ui->comboBoxGrainlineCenterPin, m_oldGrainline.CenterPin()); @@ -232,7 +245,9 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) ChangeCurrentData(ui->comboBoxGrainlineBottomPin, m_oldGrainline.BottomPin()); ValidObjects(MainPathIsValid()); - EnableGrainlineRotation(); + EnabledGrainline(); + EnabledDetailLabel(); + EnabledPatternLabel(); ListChanged(); } @@ -348,7 +363,8 @@ void DialogSeamAllowance::SaveData() void DialogSeamAllowance::CheckState() { SCASSERT(bOk != nullptr); - bOk->setEnabled(flagName && flagError && flagFormula && flagDPin && flagPPin && (flagGFormulas || flagGPin)); + bOk->setEnabled(flagName && flagError && flagFormula && flagDPin && flagPPin && (flagGFormulas || flagGPin) + && flagDLAngle && (flagDLFormulas || flagGPin) && flagPLAngle && (flagPLFormulas || flagPPin)); // In case dialog hasn't apply button if ( bApply != nullptr && applyAllowed) { @@ -949,7 +965,7 @@ void DialogSeamAllowance::TabChanged(int index) } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::UpdateValues() +void DialogSeamAllowance::UpdateGrainlineValues() { QPlainTextEdit* apleSender[2]; apleSender[0] = ui->lineEditRotFormula; @@ -1021,7 +1037,195 @@ void DialogSeamAllowance::UpdateValues() } else { - ResetWarning(); + ResetGrainlineWarning(); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::UpdateDetailLabelValues() +{ + QPlainTextEdit* apleSender[3]; + apleSender[0] = ui->lineEditDLWidthFormula; + apleSender[1] = ui->lineEditDLHeightFormula; + apleSender[2] = ui->lineEditDLAngleFormula; + bool bFormulasOK = true; + bool angleFormulaOk = true; + + for (int i = 0; i < 3; ++i) + { + QLabel* plbVal; + QLabel* plbText; + QString qsUnit; + if (i == 0) + { + plbVal = ui->labelDLWidth; + plbText = ui->labelEditDLWidth; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else if (i == 1) + { + plbVal = ui->labelDLHeight; + plbText = ui->labelEditDLHeight; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else + { + plbVal = ui->labelDLAngle; + plbText = ui->labelEditDLAngle; + qsUnit = degreeSymbol; + } + + plbVal->setToolTip(tr("Value")); + + QString qsFormula = apleSender[i]->toPlainText().simplified(); + QString qsVal; + try + { + qsFormula.replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal; + qreal dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); + if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + { + throw qmu::QmuParserError(tr("Infinite/undefined result")); + } + else if ((i == 0 || i == 1) && dVal <= 0.0) + { + throw qmu::QmuParserError(tr("Length should be positive")); + } + else + { + qsVal.setNum(dVal, 'f', 2); + ChangeColor(plbText, okColor); + } + } + catch (qmu::QmuParserError &e) + { + qsVal.clear(); + ChangeColor(plbText, Qt::red); + if (i == 3) + { + angleFormulaOk = false; + } + else + { + bFormulasOK = false; + } + plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); + } + + if (qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + plbVal->setText(qsVal); + } + + flagDLAngle = angleFormulaOk; + flagDLFormulas = bFormulasOK; + if (not flagDLAngle && not flagDLFormulas && not flagDPin && not flagPLAngle && not flagPLFormulas && not flagPPin) + { + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); + } + else + { + ResetLabelsWarning(); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::UpdatePatternLabelValues() +{ + QPlainTextEdit* apleSender[3]; + apleSender[0] = ui->lineEditPLWidthFormula; + apleSender[1] = ui->lineEditPLHeightFormula; + apleSender[2] = ui->lineEditPLAngleFormula; + bool bFormulasOK = true; + bool angleFormulaOk = true; + + for (int i = 0; i < 3; ++i) + { + QLabel* plbVal; + QLabel* plbText; + QString qsUnit; + if (i == 0) + { + plbVal = ui->labelPLWidth; + plbText = ui->labelEditPLWidth; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else if (i == 1) + { + plbVal = ui->labelPLHeight; + plbText = ui->labelEditPLHeight; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else + { + plbVal = ui->labelPLAngle; + plbText = ui->labelEditPLAngle; + qsUnit = degreeSymbol; + } + + plbVal->setToolTip(tr("Value")); + + QString qsFormula = apleSender[i]->toPlainText().simplified(); + QString qsVal; + try + { + qsFormula.replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal; + qreal dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); + if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + { + throw qmu::QmuParserError(tr("Infinite/undefined result")); + } + else if ((i == 0 || i == 1) && dVal <= 0.0) + { + throw qmu::QmuParserError(tr("Length should be positive")); + } + else + { + qsVal.setNum(dVal, 'f', 2); + ChangeColor(plbText, okColor); + } + } + catch (qmu::QmuParserError &e) + { + qsVal.clear(); + ChangeColor(plbText, Qt::red); + if (i == 3) + { + angleFormulaOk = false; + } + else + { + bFormulasOK = false; + } + plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); + } + + if (qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + plbVal->setText(qsVal); + } + + flagPLAngle = angleFormulaOk; + flagPLFormulas = bFormulasOK; + if (not flagDLAngle && not flagDLFormulas && not flagDPin && not flagPLAngle && not flagPLFormulas && not flagPPin) + { + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); + } + else + { + ResetLabelsWarning(); } CheckState(); } @@ -1074,35 +1278,70 @@ void DialogSeamAllowance::SetEditMode() } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::EnableGrainlineRotation() +void DialogSeamAllowance::EnabledGrainline() { if (ui->groupBoxGrainline->isChecked() == true) { - UpdateValues(); + UpdateGrainlineValues(); GrainlinePinPointChanged(); } else { flagGFormulas = true; - ResetWarning(); + ResetGrainlineWarning(); } } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::EditFormula() +void DialogSeamAllowance::EnabledDetailLabel() +{ + if (ui->groupBoxDetailLabel->isChecked() == true) + { + UpdateDetailLabelValues(); + DetailPinPointChanged(); + } + else + { + flagDLAngle = true; + flagDLFormulas = true; + ResetLabelsWarning(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EnabledPatternLabel() +{ + if (ui->groupBoxPatternLabel->isChecked() == true) + { + UpdatePatternLabelValues(); + PatternPinPointChanged(); + } + else + { + flagPLAngle = true; + flagPLFormulas = true; + ResetLabelsWarning(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EditGrainlineFormula() { QPlainTextEdit* pleFormula; bool bCheckZero; + QString title; if (sender() == ui->pushButtonLen) { pleFormula = ui->lineEditLenFormula; bCheckZero = true; + title = tr("Edit length"); } else if (sender() == ui->pushButtonRot) { pleFormula = ui->lineEditRotFormula; bCheckZero = false; + title = tr("Edit angle"); } else { @@ -1111,31 +1350,201 @@ void DialogSeamAllowance::EditFormula() } DialogEditWrongFormula dlg(data, NULL_ID, this); - dlg.SetFormula(pleFormula->toPlainText()); + dlg.setWindowTitle(title); + dlg.SetFormula(qApp->TrVars()->TryFormulaFromUser(pleFormula->toPlainText(), qApp->Settings()->GetOsSeparator())); dlg.setCheckZero(bCheckZero); if (dlg.exec() == QDialog::Accepted) { QString qsFormula = dlg.GetFormula(); qsFormula.replace("\n", " "); - pleFormula->setPlainText(qsFormula); - UpdateValues(); + + if (sender() == ui->pushButtonLen) + { + SetGrainlineLength(qsFormula); + } + else if (sender() == ui->pushButtonRot) + { + SetGrainlineAngle(qsFormula); + } + else + { + // should not get here! + pleFormula->setPlainText(qsFormula); + } + UpdateGrainlineValues(); } } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::DeployRotation() +void DialogSeamAllowance::EditDLFormula() +{ + QPlainTextEdit* pleFormula; + bool bCheckZero; + QString title; + + if (sender() == ui->pushButtonDLHeight) + { + pleFormula = ui->lineEditDLHeightFormula; + bCheckZero = true; + title = tr("Edit height"); + } + else if (sender() == ui->pushButtonDLWidth) + { + pleFormula = ui->lineEditDLWidthFormula; + bCheckZero = true; + title = tr("Edit width"); + } + else if (sender() == ui->pushButtonDLAngle) + { + pleFormula = ui->lineEditDLAngleFormula; + bCheckZero = false; + title = tr("Edit angle"); + } + else + { + // should not get here! + return; + } + + DialogEditWrongFormula dlg(data, NULL_ID, this); + dlg.setWindowTitle(title); + dlg.SetFormula(qApp->TrVars()->TryFormulaFromUser(pleFormula->toPlainText(), qApp->Settings()->GetOsSeparator())); + dlg.setCheckZero(bCheckZero); + if (dlg.exec() == QDialog::Accepted) + { + QString qsFormula = dlg.GetFormula(); + qsFormula.replace("\n", " "); + if (sender() == ui->pushButtonDLHeight) + { + SetDLHeight(qsFormula); + } + else if (sender() == ui->pushButtonDLWidth) + { + SetDLWidth(qsFormula); + } + else if (sender() == ui->pushButtonDLAngle) + { + SetDLAngle(qsFormula); + } + else + { + // should not get here! + pleFormula->setPlainText(qsFormula); + } + UpdateDetailLabelValues(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EditPLFormula() +{ + QPlainTextEdit* pleFormula; + bool bCheckZero; + QString title; + + if (sender() == ui->pushButtonPLHeight) + { + pleFormula = ui->lineEditPLHeightFormula; + bCheckZero = true; + title = tr("Edit height"); + } + else if (sender() == ui->pushButtonPLWidth) + { + pleFormula = ui->lineEditPLWidthFormula; + bCheckZero = true; + title = tr("Edit width"); + } + else if (sender() == ui->pushButtonPLAngle) + { + pleFormula = ui->lineEditPLAngleFormula; + bCheckZero = false; + title = tr("Edit angle"); + } + else + { + // should not get here! + return; + } + + DialogEditWrongFormula dlg(data, NULL_ID, this); + dlg.setWindowTitle(title); + dlg.SetFormula(qApp->TrVars()->TryFormulaFromUser(pleFormula->toPlainText(), qApp->Settings()->GetOsSeparator())); + dlg.setCheckZero(bCheckZero); + if (dlg.exec() == QDialog::Accepted) + { + QString qsFormula = dlg.GetFormula(); + qsFormula.replace("\n", " "); + if (sender() == ui->pushButtonPLHeight) + { + SetPLHeight(qsFormula); + } + else if (sender() == ui->pushButtonPLWidth) + { + SetPLWidth(qsFormula); + } + else if (sender() == ui->pushButtonPLAngle) + { + SetPLAngle(qsFormula); + } + else + { + // should not get here! + pleFormula->setPlainText(qsFormula); + } + UpdatePatternLabelValues(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployGrainlineRotation() { DeployFormula(ui->lineEditRotFormula, ui->pushButtonShowRot, m_iRotBaseHeight); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::DeployLength() +void DialogSeamAllowance::DeployGrainlineLength() { DeployFormula(ui->lineEditLenFormula, ui->pushButtonShowLen, m_iLenBaseHeight); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::ResetWarning() +void DialogSeamAllowance::DeployDLWidth() +{ + DeployFormula(ui->lineEditDLWidthFormula, ui->pushButtonShowDLWidth, m_DLWidthBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployDLHeight() +{ + DeployFormula(ui->lineEditDLHeightFormula, ui->pushButtonShowDLHeight, m_DLHeightBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployDLAngle() +{ + DeployFormula(ui->lineEditDLAngleFormula, ui->pushButtonShowDLAngle, m_DLAngleBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployPLWidth() +{ + DeployFormula(ui->lineEditPLWidthFormula, ui->pushButtonShowPLWidth, m_PLWidthBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployPLHeight() +{ + DeployFormula(ui->lineEditPLHeightFormula, ui->pushButtonShowPLHeight, m_PLHeightBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployPLAngle() +{ + DeployFormula(ui->lineEditPLAngleFormula, ui->pushButtonShowPLAngle, m_PLAngleBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ResetGrainlineWarning() { if (flagGFormulas || flagGPin) { @@ -1143,6 +1552,15 @@ void DialogSeamAllowance::ResetWarning() } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ResetLabelsWarning() +{ + if (flagDLAngle && (flagDLFormulas || flagDPin) && flagPLAngle && (flagPLFormulas || flagPPin)) + { + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), QIcon()); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::EvalWidth() { @@ -1295,7 +1713,7 @@ void DialogSeamAllowance::GrainlinePinPointChanged() flagGPin = true; color = okColor; - ResetWarning(); + ResetGrainlineWarning(); } else { @@ -1317,8 +1735,8 @@ void DialogSeamAllowance::GrainlinePinPointChanged() void DialogSeamAllowance::DetailPinPointChanged() { QColor color = okColor; - const quint32 topPinId = getCurrentObjectId(ui->comboBoxDetailLabelTopLeftPin); - const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxDetailLabelBottomRightPin); + const quint32 topPinId = getCurrentObjectId(ui->comboBoxDLTopLeftPin); + const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxDLBottomRightPin); if ((topPinId == NULL_ID && bottomPinId == NULL_ID) || (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) { @@ -1338,8 +1756,8 @@ void DialogSeamAllowance::DetailPinPointChanged() QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); } - ChangeColor(ui->labelDetailLabelTopLeftPin, color); - ChangeColor(ui->labelDetailLabelBottomRightPin, color); + ChangeColor(ui->labelDLTopLeftPin, color); + ChangeColor(ui->labelDLBottomRightPin, color); CheckState(); } @@ -1347,8 +1765,8 @@ void DialogSeamAllowance::DetailPinPointChanged() void DialogSeamAllowance::PatternPinPointChanged() { QColor color = okColor; - const quint32 topPinId = getCurrentObjectId(ui->comboBoxPatternLabelTopLeftPin); - const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxPatternLabelBottomRightPin); + const quint32 topPinId = getCurrentObjectId(ui->comboBoxPLTopLeftPin); + const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxPLBottomRightPin); if ((topPinId == NULL_ID && bottomPinId == NULL_ID) || (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) { @@ -1368,8 +1786,8 @@ void DialogSeamAllowance::PatternPinPointChanged() QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); } - ChangeColor(ui->labelPatternLabelTopLeftPin, color); - ChangeColor(ui->labelPatternLabelBottomRightPin, color); + ChangeColor(ui->labelPLTopLeftPin, color); + ChangeColor(ui->labelPLBottomRightPin, color); CheckState(); } @@ -1400,13 +1818,15 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.GetPatternPieceData().SetFontSize(m_oldData.GetFontSize()); piece.GetPatternPieceData().SetRotation(m_oldData.GetRotation()); piece.GetPatternPieceData().SetVisible(ui->groupBoxDetailLabel->isChecked()); - piece.GetPatternPieceData().SetTopLeftPin(getCurrentObjectId(ui->comboBoxDetailLabelTopLeftPin)); - piece.GetPatternPieceData().SetBottomRightPin(getCurrentObjectId(ui->comboBoxDetailLabelBottomRightPin)); + piece.GetPatternPieceData().SetCenterPin(getCurrentObjectId(ui->comboBoxDLCenterPin)); + piece.GetPatternPieceData().SetTopLeftPin(getCurrentObjectId(ui->comboBoxDLTopLeftPin)); + piece.GetPatternPieceData().SetBottomRightPin(getCurrentObjectId(ui->comboBoxDLBottomRightPin)); piece.GetPatternInfo() = m_oldGeom; piece.GetPatternInfo().SetVisible(ui->groupBoxPatternLabel->isChecked()); - piece.GetPatternInfo().SetTopLeftPin(getCurrentObjectId(ui->comboBoxPatternLabelTopLeftPin)); - piece.GetPatternInfo().SetBottomRightPin(getCurrentObjectId(ui->comboBoxPatternLabelBottomRightPin)); + piece.GetPatternInfo().SetCenterPin(getCurrentObjectId(ui->comboBoxPLCenterPin)); + piece.GetPatternInfo().SetTopLeftPin(getCurrentObjectId(ui->comboBoxPLTopLeftPin)); + piece.GetPatternInfo().SetBottomRightPin(getCurrentObjectId(ui->comboBoxPLBottomRightPin)); piece.GetGrainlineGeometry() = m_oldGrainline; piece.GetGrainlineGeometry().SetVisible(ui->groupBoxGrainline->isChecked()); @@ -1814,26 +2234,6 @@ void DialogSeamAllowance::InitPatternPieceDataTab() ui->lineEditLetter->setClearButtonEnabled(true); #endif - InitPinPoint(ui->comboBoxDetailLabelTopLeftPin); - InitPinPoint(ui->comboBoxDetailLabelBottomRightPin); - - connect(ui->comboBoxDetailLabelTopLeftPin, - static_cast(&QComboBox::currentIndexChanged), - this, &DialogSeamAllowance::DetailPinPointChanged); - connect(ui->comboBoxDetailLabelBottomRightPin, - static_cast(&QComboBox::currentIndexChanged), - this, &DialogSeamAllowance::DetailPinPointChanged); - - InitPinPoint(ui->comboBoxPatternLabelTopLeftPin); - InitPinPoint(ui->comboBoxPatternLabelBottomRightPin); - - connect(ui->comboBoxPatternLabelTopLeftPin, - static_cast(&QComboBox::currentIndexChanged), - this, &DialogSeamAllowance::PatternPinPointChanged); - connect(ui->comboBoxPatternLabelBottomRightPin, - static_cast(&QComboBox::currentIndexChanged), - this, &DialogSeamAllowance::PatternPinPointChanged); - connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSeamAllowance::NameDetailChanged); m_qslMaterials << QApplication::translate("Detail", "Fabric", 0) @@ -1854,30 +2254,99 @@ void DialogSeamAllowance::InitPatternPieceDataTab() m_qslPlacements << tr("None") << tr("Cut on fold"); ui->comboBoxPlacement->addItems(m_qslPlacements); - ui->pushButtonRot->setIcon(QIcon("://icon/16x16/fx.png")); - ui->pushButtonLen->setIcon(QIcon("://icon/16x16/fx.png")); connect(ui->pushButtonAdd, &QPushButton::clicked, this, &DialogSeamAllowance::AddUpdate); connect(ui->pushButtonCancel, &QPushButton::clicked, this, &DialogSeamAllowance::Cancel); connect(ui->pushButtonRemove, &QPushButton::clicked, this, &DialogSeamAllowance::Remove); connect(ui->listWidgetMCP, &QListWidget::itemClicked, this, &DialogSeamAllowance::SetEditMode); connect(ui->comboBoxMaterial, &QComboBox::currentTextChanged, this, &DialogSeamAllowance::MaterialChanged); + + SetAddMode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitLabelsTab() +{ + m_DLWidthBaseHeight = ui->lineEditDLWidthFormula->height(); + m_DLHeightBaseHeight = ui->lineEditDLHeightFormula->height(); + m_DLAngleBaseHeight = ui->lineEditDLAngleFormula->height(); + + connect(ui->groupBoxDetailLabel, &QGroupBox::toggled, this, &DialogSeamAllowance::EnabledDetailLabel); + InitPinPoint(ui->comboBoxDLCenterPin); + InitPinPoint(ui->comboBoxDLTopLeftPin); + InitPinPoint(ui->comboBoxDLBottomRightPin); + + connect(ui->comboBoxDLTopLeftPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::DetailPinPointChanged); + connect(ui->comboBoxDLBottomRightPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::DetailPinPointChanged); + + connect(ui->pushButtonDLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula); + connect(ui->pushButtonDLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula); + connect(ui->pushButtonDLAngle, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula); + + connect(ui->lineEditDLWidthFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdateDetailLabelValues); + connect(ui->lineEditDLHeightFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdateDetailLabelValues); + connect(ui->lineEditDLAngleFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdateDetailLabelValues); + + connect(ui->pushButtonShowDLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::DeployDLWidth); + connect(ui->pushButtonShowDLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::DeployDLHeight); + connect(ui->pushButtonShowDLAngle, &QPushButton::clicked, this, &DialogSeamAllowance::DeployDLAngle); + + EnabledDetailLabel(); + + m_PLWidthBaseHeight = ui->lineEditPLWidthFormula->height(); + m_PLHeightBaseHeight = ui->lineEditPLHeightFormula->height(); + m_PLAngleBaseHeight = ui->lineEditPLAngleFormula->height(); + + connect(ui->groupBoxPatternLabel, &QGroupBox::toggled, this, &DialogSeamAllowance::EnabledPatternLabel); + InitPinPoint(ui->comboBoxPLCenterPin); + InitPinPoint(ui->comboBoxPLTopLeftPin); + InitPinPoint(ui->comboBoxPLBottomRightPin); + + connect(ui->comboBoxPLTopLeftPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::PatternPinPointChanged); + connect(ui->comboBoxPLBottomRightPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::PatternPinPointChanged); + + connect(ui->pushButtonPLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula); + connect(ui->pushButtonPLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula); + connect(ui->pushButtonPLAngle, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula); + + connect(ui->lineEditPLWidthFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdatePatternLabelValues); + connect(ui->lineEditPLHeightFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdatePatternLabelValues); + connect(ui->lineEditPLAngleFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdatePatternLabelValues); + + connect(ui->pushButtonShowPLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::DeployPLWidth); + connect(ui->pushButtonShowPLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::DeployPLHeight); + connect(ui->pushButtonShowPLAngle, &QPushButton::clicked, this, &DialogSeamAllowance::DeployPLAngle); + + EnabledPatternLabel(); } //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitGrainlineTab() { - connect(ui->groupBoxGrainline, &QGroupBox::toggled, this, &DialogSeamAllowance::EnableGrainlineRotation); - connect(ui->pushButtonRot, &QPushButton::clicked, this, &DialogSeamAllowance::EditFormula); - connect(ui->pushButtonLen, &QPushButton::clicked, this, &DialogSeamAllowance::EditFormula); - connect(ui->lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateValues); - connect(ui->lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateValues); + connect(ui->groupBoxGrainline, &QGroupBox::toggled, this, &DialogSeamAllowance::EnabledGrainline); + connect(ui->pushButtonRot, &QPushButton::clicked, this, &DialogSeamAllowance::EditGrainlineFormula); + connect(ui->pushButtonLen, &QPushButton::clicked, this, &DialogSeamAllowance::EditGrainlineFormula); + connect(ui->lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateGrainlineValues); + connect(ui->lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateGrainlineValues); - connect(ui->pushButtonShowRot, &QPushButton::clicked, this, &DialogSeamAllowance::DeployRotation); - connect(ui->pushButtonShowLen, &QPushButton::clicked, this, &DialogSeamAllowance::DeployLength); + connect(ui->pushButtonShowRot, &QPushButton::clicked, this, &DialogSeamAllowance::DeployGrainlineRotation); + connect(ui->pushButtonShowLen, &QPushButton::clicked, this, &DialogSeamAllowance::DeployGrainlineLength); - SetAddMode(); - EnableGrainlineRotation(); + EnabledGrainline(); ui->comboBoxArrow->addItem(tr("Both")); ui->comboBoxArrow->addItem(tr("Just front")); @@ -1913,10 +2382,13 @@ void DialogSeamAllowance::InitAllPinComboboxes() InitPinPoint(ui->comboBoxGrainlineTopPin); InitPinPoint(ui->comboBoxGrainlineBottomPin); - InitPinPoint(ui->comboBoxDetailLabelTopLeftPin); - InitPinPoint(ui->comboBoxDetailLabelBottomRightPin); - InitPinPoint(ui->comboBoxPatternLabelTopLeftPin); - InitPinPoint(ui->comboBoxPatternLabelBottomRightPin); + InitPinPoint(ui->comboBoxDLCenterPin); + InitPinPoint(ui->comboBoxDLTopLeftPin); + InitPinPoint(ui->comboBoxDLBottomRightPin); + + InitPinPoint(ui->comboBoxPLCenterPin); + InitPinPoint(ui->comboBoxPLTopLeftPin); + InitPinPoint(ui->comboBoxPLBottomRightPin); } //--------------------------------------------------------------------------------------------------------------------- @@ -1999,13 +2471,13 @@ QVector DialogSeamAllowance::GetPieceInternals(const QListWidget *list) const } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetGrainlineAngle(const VGrainlineData &data) +void DialogSeamAllowance::SetGrainlineAngle(const QString &angleFormula) { - const QString formula = qApp->TrVars()->FormulaToUser(data.GetRotation(), qApp->Settings()->GetOsSeparator()); + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { - this->DeployRotation(); + this->DeployGrainlineRotation(); } ui->lineEditRotFormula->setPlainText(formula); @@ -2013,15 +2485,99 @@ void DialogSeamAllowance::SetGrainlineAngle(const VGrainlineData &data) } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetGrainlineLength(const VGrainlineData &data) +void DialogSeamAllowance::SetGrainlineLength(const QString &lengthFormula) { - const QString formula = qApp->TrVars()->FormulaToUser(data.GetLength(), qApp->Settings()->GetOsSeparator()); + const QString formula = qApp->TrVars()->FormulaToUser(lengthFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { - this->DeployLength(); + this->DeployGrainlineLength(); } ui->lineEditLenFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditLenFormula); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetDLWidth(const QString &widthFormula) +{ + const QString formula = qApp->TrVars()->FormulaToUser(widthFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployDLWidth(); + } + ui->lineEditDLWidthFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditDLWidthFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetDLHeight(const QString &heightFormula) +{ + const QString formula = qApp->TrVars()->FormulaToUser(heightFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployDLHeight(); + } + ui->lineEditDLHeightFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditDLHeightFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetDLAngle(const QString &angleFormula) +{ + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployDLAngle(); + } + ui->lineEditDLAngleFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditDLAngleFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetPLWidth(const QString &widthFormula) +{ + const QString formula = qApp->TrVars()->FormulaToUser(widthFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployPLWidth(); + } + ui->lineEditPLWidthFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditPLWidthFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetPLHeight(const QString &heightFormula) +{ + const QString formula = qApp->TrVars()->FormulaToUser(heightFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployPLHeight(); + } + ui->lineEditPLHeightFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditPLHeightFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetPLAngle(const QString &angleFormula) +{ + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployPLAngle(); + } + ui->lineEditPLAngleFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditPLAngleFormula); +} diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index 0bcb47371..14302ff5f 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -94,14 +94,34 @@ private slots: void PathDialogClosed(int result); void TabChanged(int index); - void UpdateValues(); + void UpdateGrainlineValues(); + void UpdateDetailLabelValues(); + void UpdatePatternLabelValues(); + void SetAddMode(); void SetEditMode(); - void EnableGrainlineRotation(); - void EditFormula(); - void DeployRotation(); - void DeployLength(); - void ResetWarning(); + + void EditGrainlineFormula(); + void EditDLFormula(); + void EditPLFormula(); + + void DeployGrainlineRotation(); + void DeployGrainlineLength(); + + void DeployDLWidth(); + void DeployDLHeight(); + void DeployDLAngle(); + + void DeployPLWidth(); + void DeployPLHeight(); + void DeployPLAngle(); + + void ResetGrainlineWarning(); + void ResetLabelsWarning(); + + void EnabledGrainline(); + void EnabledDetailLabel(); + void EnabledPatternLabel(); void EvalWidth(); void EvalWidthBefore(); @@ -132,6 +152,10 @@ private: bool flagDPin; bool flagPPin; bool flagGFormulas; + bool flagDLAngle; + bool flagDLFormulas; + bool flagPLAngle; + bool flagPLFormulas; bool m_bAddMode; qreal m_mx; qreal m_my; @@ -149,6 +173,12 @@ private: VGrainlineData m_oldGrainline; int m_iRotBaseHeight; int m_iLenBaseHeight; + int m_DLWidthBaseHeight; + int m_DLHeightBaseHeight; + int m_DLAngleBaseHeight; + int m_PLWidthBaseHeight; + int m_PLHeightBaseHeight; + int m_PLAngleBaseHeight; int m_formulaBaseWidth; int m_formulaBaseWidthBefore; int m_formulaBaseWidthAfter; @@ -190,6 +220,7 @@ private: void InitSAIncludeType(); void InitInternalPathsTab(); void InitPatternPieceDataTab(); + void InitLabelsTab(); void InitGrainlineTab(); void InitPinsTab(); void InitAllPinComboboxes(); @@ -198,8 +229,17 @@ private: template QVector GetPieceInternals(const QListWidget *list) const; - void SetGrainlineAngle(const VGrainlineData &data); - void SetGrainlineLength(const VGrainlineData &data); + + void SetGrainlineAngle(const QString &angleFormula); + void SetGrainlineLength(const QString &lengthFormula); + + void SetDLWidth(const QString &widthFormula); + void SetDLHeight(const QString &heightFormula); + void SetDLAngle(const QString &angleFormula); + + void SetPLWidth(const QString &widthFormula); + void SetPLHeight(const QString &heightFormula); + void SetPLAngle(const QString &angleFormula); }; #endif // DIALOGSEAMALLOWANCE_H diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index 649d9382a..c558d46ab 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -6,8 +6,8 @@ 0 0 - 639 - 680 + 532 + 611 @@ -20,6 +20,9 @@ + + 4 + Main path @@ -1057,97 +1060,1430 @@ Labels - - - - 30 - 40 - 234 - 96 - - - - Detail label visible - - - true - - - true - - - false - - - - QFormLayout::ExpandingFieldsGrow - - - - - Top left pin: + + + + + Qt::Horizontal + + + + true - - - - - - - - - Bottom right pin: + + Detail label visible - - - - - - - - - - - 30 - 240 - 234 - 198 - - - - Pattern label visible - - - true - - - false - - - - QFormLayout::ExpandingFieldsGrow - - - - - Top left pin: + + true - - - - - - - - - Bottom right pin: + + true + + false + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Width: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 1 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Height: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 1 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Center pin: + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top left pin: + + + + + + + + + + Bottom right pin: + + + + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 0 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - - - - - - + + + true + + + Pattern label visible + + + true + + + false + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Width: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 1 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Height: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 1 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Center pin: + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top left pin: + + + + + + + + + + Bottom right pin: + + + + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 0 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + From c5f7eef8b4df03dc4440b8b4ad900e386f61c357 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 11 Mar 2017 15:56:39 +0200 Subject: [PATCH 10/29] Fix showing warning for grainline. --HG-- branch : feature --- .../dialogs/tools/dialogseamallowance.cpp | 73 +++++++++++++++---- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 4c7cb7619..3c5952a08 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -1016,13 +1016,20 @@ void DialogSeamAllowance::UpdateGrainlineValues() } catch (qmu::QmuParserError &e) { - qsVal.clear(); - ChangeColor(plbText, Qt::red); + qsVal = tr("Error"); + if (not flagGPin) + { + ChangeColor(plbText, Qt::red); + } + else + { + ChangeColor(plbText, okColor); + } bFormulasOK = false; plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); } - if (qsVal.isEmpty() == false) + if (bFormulasOK && qsVal.isEmpty() == false) { qsVal += qsUnit; } @@ -1102,8 +1109,16 @@ void DialogSeamAllowance::UpdateDetailLabelValues() } catch (qmu::QmuParserError &e) { - qsVal.clear(); - ChangeColor(plbText, Qt::red); + qsVal = tr("Error"); + if (not flagDPin) + { + ChangeColor(plbText, Qt::red); + } + else + { + ChangeColor(plbText, okColor); + } + if (i == 3) { angleFormulaOk = false; @@ -1115,9 +1130,19 @@ void DialogSeamAllowance::UpdateDetailLabelValues() plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); } - if (qsVal.isEmpty() == false) + if (i == 3) { - qsVal += qsUnit; + if (angleFormulaOk && qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + } + else + { + if (bFormulasOK && qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } } plbVal->setText(qsVal); } @@ -1196,8 +1221,16 @@ void DialogSeamAllowance::UpdatePatternLabelValues() } catch (qmu::QmuParserError &e) { - qsVal.clear(); - ChangeColor(plbText, Qt::red); + qsVal = tr("Error"); + if (not flagPPin) + { + ChangeColor(plbText, Qt::red); + } + else + { + ChangeColor(plbText, okColor); + } + if (i == 3) { angleFormulaOk = false; @@ -1209,9 +1242,19 @@ void DialogSeamAllowance::UpdatePatternLabelValues() plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); } - if (qsVal.isEmpty() == false) + if (i == 3) { - qsVal += qsUnit; + if (angleFormulaOk && qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + } + else + { + if (bFormulasOK && qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } } plbVal->setText(qsVal); } @@ -1707,8 +1750,7 @@ void DialogSeamAllowance::GrainlinePinPointChanged() QColor color = okColor; const quint32 topPinId = getCurrentObjectId(ui->comboBoxGrainlineTopPin); const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxGrainlineBottomPin); - if ((topPinId == NULL_ID && bottomPinId == NULL_ID) || - (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) + if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId) { flagGPin = true; color = okColor; @@ -1718,7 +1760,7 @@ void DialogSeamAllowance::GrainlinePinPointChanged() else { flagGPin = false; - color = errorColor; + topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor; if (not flagGFormulas && not flagGPin) { @@ -1726,6 +1768,7 @@ void DialogSeamAllowance::GrainlinePinPointChanged() ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), icon); } } + UpdateGrainlineValues(); ChangeColor(ui->labelGrainlineTopPin, color); ChangeColor(ui->labelGrainlineBottomPin, color); CheckState(); @@ -1756,6 +1799,7 @@ void DialogSeamAllowance::DetailPinPointChanged() QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); } + UpdateDetailLabelValues(); ChangeColor(ui->labelDLTopLeftPin, color); ChangeColor(ui->labelDLBottomRightPin, color); CheckState(); @@ -1786,6 +1830,7 @@ void DialogSeamAllowance::PatternPinPointChanged() QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); } + UpdatePatternLabelValues(); ChangeColor(ui->labelPLTopLeftPin, color); ChangeColor(ui->labelPLBottomRightPin, color); CheckState(); From 728b0e79d4ff5d0b359cfebe9890b850fb602542 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 11 Mar 2017 15:57:57 +0200 Subject: [PATCH 11/29] Set default values for grainline length and angle. --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogseamallowance.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index c558d46ab..b59cf9ca6 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -21,7 +21,7 @@ - 4 + 5 @@ -2650,7 +2650,7 @@ true - + 1 @@ -2839,7 +2839,7 @@ true - + 90 From 988da5fd199607de808e1469e37d4e12c8a342ec Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 11 Mar 2017 16:39:04 +0200 Subject: [PATCH 12/29] Fix showing warning for labels. --HG-- branch : feature --- .../dialogs/tools/dialogseamallowance.cpp | 144 +++++------------- 1 file changed, 40 insertions(+), 104 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 3c5952a08..1874856be 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -73,11 +73,11 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & flagGPin(true), flagDPin(true), flagPPin(true), - flagGFormulas(false), - flagDLAngle(false), - flagDLFormulas(false), - flagPLAngle(false), - flagPLFormulas(false), + flagGFormulas(true), + flagDLAngle(true), + flagDLFormulas(true), + flagPLAngle(true), + flagPLFormulas(true), m_bAddMode(true), m_mx(0), m_my(0), @@ -363,8 +363,8 @@ void DialogSeamAllowance::SaveData() void DialogSeamAllowance::CheckState() { SCASSERT(bOk != nullptr); - bOk->setEnabled(flagName && flagError && flagFormula && flagDPin && flagPPin && (flagGFormulas || flagGPin) - && flagDLAngle && (flagDLFormulas || flagGPin) && flagPLAngle && (flagPLFormulas || flagPPin)); + bOk->setEnabled(flagName && flagError && flagFormula && (flagGFormulas || flagGPin) + && flagDLAngle && (flagDLFormulas || flagDPin) && flagPLAngle && (flagPLFormulas || flagPPin)); // In case dialog hasn't apply button if ( bApply != nullptr && applyAllowed) { @@ -967,10 +967,8 @@ void DialogSeamAllowance::TabChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::UpdateGrainlineValues() { - QPlainTextEdit* apleSender[2]; - apleSender[0] = ui->lineEditRotFormula; - apleSender[1] = ui->lineEditLenFormula; - bool bFormulasOK = true; + QPlainTextEdit* apleSender[2] = {ui->lineEditRotFormula, ui->lineEditLenFormula}; + bool bFormulasOK[2] = {true, true}; for (int i = 0; i < 2; ++i) { @@ -1017,26 +1015,19 @@ void DialogSeamAllowance::UpdateGrainlineValues() catch (qmu::QmuParserError &e) { qsVal = tr("Error"); - if (not flagGPin) - { - ChangeColor(plbText, Qt::red); - } - else - { - ChangeColor(plbText, okColor); - } - bFormulasOK = false; + not flagGPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor); + bFormulasOK[i] = false; plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); } - if (bFormulasOK && qsVal.isEmpty() == false) + if (bFormulasOK[i] && qsVal.isEmpty() == false) { qsVal += qsUnit; } plbVal->setText(qsVal); } - flagGFormulas = bFormulasOK; + flagGFormulas = bFormulasOK[0] && bFormulasOK[1]; if (not flagGFormulas && not flagGPin) { QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); @@ -1052,12 +1043,9 @@ void DialogSeamAllowance::UpdateGrainlineValues() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::UpdateDetailLabelValues() { - QPlainTextEdit* apleSender[3]; - apleSender[0] = ui->lineEditDLWidthFormula; - apleSender[1] = ui->lineEditDLHeightFormula; - apleSender[2] = ui->lineEditDLAngleFormula; - bool bFormulasOK = true; - bool angleFormulaOk = true; + QPlainTextEdit* apleSender[3] = {ui->lineEditDLWidthFormula, ui->lineEditDLHeightFormula, + ui->lineEditDLAngleFormula}; + bool bFormulasOK[3] = {true, true, true}; for (int i = 0; i < 3; ++i) { @@ -1110,46 +1098,21 @@ void DialogSeamAllowance::UpdateDetailLabelValues() catch (qmu::QmuParserError &e) { qsVal = tr("Error"); - if (not flagDPin) - { - ChangeColor(plbText, Qt::red); - } - else - { - ChangeColor(plbText, okColor); - } - - if (i == 3) - { - angleFormulaOk = false; - } - else - { - bFormulasOK = false; - } + not flagDPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor); + bFormulasOK[i] = false; plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); } - if (i == 3) + if (bFormulasOK[i] && qsVal.isEmpty() == false) { - if (angleFormulaOk && qsVal.isEmpty() == false) - { - qsVal += qsUnit; - } - } - else - { - if (bFormulasOK && qsVal.isEmpty() == false) - { - qsVal += qsUnit; - } + qsVal += qsUnit; } plbVal->setText(qsVal); } - flagDLAngle = angleFormulaOk; - flagDLFormulas = bFormulasOK; - if (not flagDLAngle && not flagDLFormulas && not flagDPin && not flagPLAngle && not flagPLFormulas && not flagPPin) + flagDLAngle = bFormulasOK[2]; + flagDLFormulas = bFormulasOK[0] && bFormulasOK[1]; + if (not flagDLAngle && not (flagDLFormulas || flagDPin) && not flagPLAngle && not (flagPLFormulas || flagPPin)) { QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); @@ -1164,12 +1127,9 @@ void DialogSeamAllowance::UpdateDetailLabelValues() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::UpdatePatternLabelValues() { - QPlainTextEdit* apleSender[3]; - apleSender[0] = ui->lineEditPLWidthFormula; - apleSender[1] = ui->lineEditPLHeightFormula; - apleSender[2] = ui->lineEditPLAngleFormula; - bool bFormulasOK = true; - bool angleFormulaOk = true; + QPlainTextEdit* apleSender[3] = {ui->lineEditPLWidthFormula, ui->lineEditPLHeightFormula, + ui->lineEditPLAngleFormula}; + bool bFormulasOK[3] = {true, true, true}; for (int i = 0; i < 3; ++i) { @@ -1222,46 +1182,21 @@ void DialogSeamAllowance::UpdatePatternLabelValues() catch (qmu::QmuParserError &e) { qsVal = tr("Error"); - if (not flagPPin) - { - ChangeColor(plbText, Qt::red); - } - else - { - ChangeColor(plbText, okColor); - } - - if (i == 3) - { - angleFormulaOk = false; - } - else - { - bFormulasOK = false; - } + not flagPPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor); + bFormulasOK[i] = false; plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); } - if (i == 3) + if (bFormulasOK[i] && qsVal.isEmpty() == false) { - if (angleFormulaOk && qsVal.isEmpty() == false) - { - qsVal += qsUnit; - } - } - else - { - if (bFormulasOK && qsVal.isEmpty() == false) - { - qsVal += qsUnit; - } + qsVal += qsUnit; } plbVal->setText(qsVal); } - flagPLAngle = angleFormulaOk; - flagPLFormulas = bFormulasOK; - if (not flagDLAngle && not flagDLFormulas && not flagDPin && not flagPLAngle && not flagPLFormulas && not flagPPin) + flagPLAngle = bFormulasOK[2]; + flagPLFormulas = bFormulasOK[0] && bFormulasOK[1]; + if (not flagDLAngle && not (flagDLFormulas || flagDPin) && not flagPLAngle && not (flagPLFormulas || flagPPin)) { QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); @@ -1332,6 +1267,7 @@ void DialogSeamAllowance::EnabledGrainline() { flagGFormulas = true; ResetGrainlineWarning(); + CheckState(); } } @@ -1348,6 +1284,7 @@ void DialogSeamAllowance::EnabledDetailLabel() flagDLAngle = true; flagDLFormulas = true; ResetLabelsWarning(); + CheckState(); } } @@ -1364,6 +1301,7 @@ void DialogSeamAllowance::EnabledPatternLabel() flagPLAngle = true; flagPLFormulas = true; ResetLabelsWarning(); + CheckState(); } } @@ -1780,8 +1718,7 @@ void DialogSeamAllowance::DetailPinPointChanged() QColor color = okColor; const quint32 topPinId = getCurrentObjectId(ui->comboBoxDLTopLeftPin); const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxDLBottomRightPin); - if ((topPinId == NULL_ID && bottomPinId == NULL_ID) - || (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) + if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId) { flagDPin = true; color = okColor; @@ -1794,7 +1731,7 @@ void DialogSeamAllowance::DetailPinPointChanged() else { flagDPin = false; - color = errorColor; + topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); @@ -1811,8 +1748,7 @@ void DialogSeamAllowance::PatternPinPointChanged() QColor color = okColor; const quint32 topPinId = getCurrentObjectId(ui->comboBoxPLTopLeftPin); const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxPLBottomRightPin); - if ((topPinId == NULL_ID && bottomPinId == NULL_ID) - || (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) + if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId) { flagPPin = true; color = okColor; @@ -1825,7 +1761,7 @@ void DialogSeamAllowance::PatternPinPointChanged() else { flagPPin = false; - color = errorColor; + topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); From 1ab541236df3939b9b6e0c78acc947e98355993d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 13 Mar 2017 14:27:29 +0200 Subject: [PATCH 13/29] Successful build. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 91 ++++------- src/libs/ifc/schema/pattern/v0.4.4.xsd | 12 +- src/libs/vlayout/vlayoutpiece.cpp | 79 ++++++++-- .../floatItemData/vpatternlabeldata.cpp | 16 +- .../floatItemData/vpatternlabeldata.h | 12 +- .../floatItemData/vpatternlabeldata_p.h | 20 +-- .../dialogs/tools/dialogseamallowance.cpp | 25 ++- src/libs/vtools/tools/vtoolseamallowance.cpp | 147 +++++++++++++----- src/libs/vtools/tools/vtoolseamallowance.h | 4 +- 9 files changed, 258 insertions(+), 148 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index c463c78a9..6f415651e 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -804,35 +804,25 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail, q //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const { - detail.GetPatternPieceData().SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); + VPieceLabelData &ppData = detail.GetPatternPieceData(); + ppData.SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); try { QString qsLetter = GetParametrString(domElement, AttrLetter, ""); - detail.GetPatternPieceData().SetLetter(qsLetter); + ppData.SetLetter(qsLetter); } catch(const VExceptionEmptyParameter &e) { Q_UNUSED(e) - detail.GetPatternPieceData().SetLetter(""); + ppData.SetLetter(""); } - QPointF ptPos; - ptPos.setX(GetParametrDouble(domElement, AttrMx, "0")); - ptPos.setY(GetParametrDouble(domElement, AttrMy, "0")); - detail.GetPatternPieceData().SetPos(ptPos); - qreal dLW = GetParametrDouble(domElement, AttrWidth, "0"); - detail.GetPatternPieceData().SetLabelWidth(dLW); - qreal dLH = GetParametrDouble(domElement, VToolSeamAllowance::AttrHeight, "0"); - detail.GetPatternPieceData().SetLabelHeight(dLH); - int iFS = static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0")); - detail.GetPatternPieceData().SetFontSize(iFS); - qreal dRot = GetParametrDouble(domElement, AttrRotation, "0"); - detail.GetPatternPieceData().SetRotation(dRot); - - const quint32 topLeftPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR); - detail.GetPatternPieceData().SetTopLeftPin(topLeftPin); - - const quint32 bottomRightPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR); - detail.GetPatternPieceData().SetBottomRightPin(bottomRightPin); + ppData.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); + ppData.SetLabelWidth(GetParametrString(domElement, AttrWidth, "1")); + ppData.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); + ppData.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"))); + ppData.SetRotation(GetParametrString(domElement, AttrRotation, "0")); + ppData.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); + ppData.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); QDomNodeList nodeListMCP = domElement.childNodes(); for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP) @@ -846,57 +836,36 @@ void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) } mcp.m_iCutNumber = static_cast(GetParametrUInt(domMCP, AttrCutNumber, 0)); mcp.m_ePlacement = PlacementType(GetParametrUInt(domMCP, AttrPlacement, 0)); - detail.GetPatternPieceData().Append(mcp); + ppData.Append(mcp); } } //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParsePiecePatternInfo(const QDomElement &domElement, VPiece &detail) const { - detail.GetPatternInfo().SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); - QPointF ptPos; - ptPos.setX(GetParametrDouble(domElement, AttrMx, "0")); - ptPos.setY(GetParametrDouble(domElement, AttrMy, "0")); - detail.GetPatternInfo().SetPos(ptPos); - qreal dLW = GetParametrDouble(domElement, AttrWidth, "0"); - detail.GetPatternInfo().SetLabelWidth(dLW); - qreal dLH = GetParametrDouble(domElement, VToolSeamAllowance::AttrHeight, "0"); - detail.GetPatternInfo().SetLabelHeight(dLH); - int iFS = static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0")); - detail.GetPatternInfo().SetFontSize(iFS); - qreal dRot = GetParametrDouble(domElement, AttrRotation, "0"); - detail.GetPatternInfo().SetRotation(dRot); - - const quint32 topLeftPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR); - detail.GetPatternInfo().SetTopLeftPin(topLeftPin); - - const quint32 bottomRightPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR); - detail.GetPatternInfo().SetBottomRightPin(bottomRightPin); + VPatternLabelData &patternInfo = detail.GetPatternInfo(); + patternInfo.SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); + patternInfo.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); + patternInfo.SetLabelWidth(GetParametrString(domElement, AttrWidth, "1")); + patternInfo.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); + patternInfo.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"))); + patternInfo.SetRotation(GetParametrString(domElement, AttrRotation, "0")); + patternInfo.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); + patternInfo.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); } //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParsePieceGrainline(const QDomElement &domElement, VPiece &detail) const { - detail.GetGrainlineGeometry().SetVisible(GetParametrBool(domElement, AttrVisible, falseStr)); - QPointF ptPos; - ptPos.setX(GetParametrDouble(domElement, AttrMx, "0")); - ptPos.setY(GetParametrDouble(domElement, AttrMy, "0")); - detail.GetGrainlineGeometry().SetPos(ptPos); - QString qsLength = GetParametrString(domElement, AttrLength, "0"); - detail.GetGrainlineGeometry().SetLength(qsLength); - QString qsRot = GetParametrString(domElement, AttrRotation, "90"); - detail.GetGrainlineGeometry().SetRotation(qsRot); - ArrowType eAT = static_cast(GetParametrUInt(domElement, AttrArrows, "0")); - detail.GetGrainlineGeometry().SetArrowType(eAT); - - const quint32 centerPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR); - detail.GetGrainlineGeometry().SetCenterPin(centerPin); - - const quint32 topPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopPin, NULL_ID_STR); - detail.GetGrainlineGeometry().SetTopPin(topPin); - - const quint32 bottomPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomPin, NULL_ID_STR); - detail.GetGrainlineGeometry().SetBottomPin(bottomPin); + VGrainlineData &gGeometry = detail.GetGrainlineGeometry(); + gGeometry.SetVisible(GetParametrBool(domElement, AttrVisible, falseStr)); + gGeometry.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); + gGeometry.SetLength(GetParametrString(domElement, AttrLength, "1")); + gGeometry.SetRotation(GetParametrString(domElement, AttrRotation, "90")); + gGeometry.SetArrowType(static_cast(GetParametrUInt(domElement, AttrArrows, "0"))); + gGeometry.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); + gGeometry.SetTopPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopPin, NULL_ID_STR)); + gGeometry.SetBottomPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomPin, NULL_ID_STR)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/schema/pattern/v0.4.4.xsd b/src/libs/ifc/schema/pattern/v0.4.4.xsd index f1eabfd95..04528e713 100644 --- a/src/libs/ifc/schema/pattern/v0.4.4.xsd +++ b/src/libs/ifc/schema/pattern/v0.4.4.xsd @@ -492,9 +492,9 @@ - - - + + + @@ -505,9 +505,9 @@ - - - + + + diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 93463eed8..372d43870 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -75,11 +75,22 @@ QVector ConvertInternalPaths(const VPiece &piece, const VConta } //--------------------------------------------------------------------------------------------------------------------- -void FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pattern, qreal &labelWidth, - qreal &labelHeight, QPointF &pos) +bool FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pattern, qreal &rotationAngle, + qreal &labelWidth, qreal &labelHeight, QPointF &pos) { SCASSERT(pattern != nullptr) + try + { + Calculator cal1; + rotationAngle = cal1.EvalFormula(pattern->PlainVariables(), labelData.GetRotation()); + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return false; + } + const quint32 topLeftPin = labelData.TopLeftPin(); const quint32 bottomRightPin = labelData.BottomRightPin(); @@ -96,7 +107,7 @@ void FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat pos = labelRect.topLeft(); - return; + return true; } catch(const VExceptionBadId &) { @@ -104,9 +115,43 @@ void FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat } } - labelWidth = labelData.GetLabelWidth(); - labelHeight = labelData.GetLabelHeight(); - pos = labelData.GetPos(); + try + { + Calculator cal1; + labelWidth = cal1.EvalFormula(pattern->PlainVariables(), labelData.GetLabelWidth()); + + Calculator cal2; + labelHeight = cal2.EvalFormula(pattern->PlainVariables(), labelData.GetLabelHeight()); + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return false; + } + + const quint32 centerPin = labelData.CenterPin(); + if (centerPin != NULL_ID) + { + try + { + const auto centerPinPoint = pattern->GeometricObject(centerPin); + + const qreal lWidth = ToPixel(labelWidth, *pattern->GetPatternUnit()); + const qreal lHeight = ToPixel(labelHeight, *pattern->GetPatternUnit()); + + pos = *centerPinPoint - QRectF(0, 0, lWidth, lHeight).center(); + } + catch(const VExceptionBadId &) + { + pos = labelData.GetPos(); + } + } + else + { + pos = labelData.GetPos(); + } + + return true; } //--------------------------------------------------------------------------------------------------------------------- @@ -401,7 +446,14 @@ void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, QPointF ptPos; qreal labelWidth = 0; qreal labelHeight = 0; - FindLabelGeometry(data, pattern, labelWidth, labelHeight, ptPos); + qreal labelAngle = 0; + if (not FindLabelGeometry(data, pattern, labelAngle, labelWidth, labelHeight, ptPos)) + { + return; + } + + labelWidth = ToPixel(labelWidth, *pattern->GetPatternUnit()); + labelHeight = ToPixel(labelHeight, *pattern->GetPatternUnit()); QVector v; v << ptPos @@ -409,7 +461,7 @@ void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, << QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight) << QPointF(ptPos.x(), ptPos.y() + labelHeight); - const qreal dAng = qDegreesToRadians(data.GetRotation()); + const qreal dAng = qDegreesToRadians(labelAngle); const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); for (int i = 0; i < v.count(); ++i) { @@ -435,7 +487,14 @@ void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLa QPointF ptPos; qreal labelWidth = 0; qreal labelHeight = 0; - FindLabelGeometry(geom, pattern, labelWidth, labelHeight, ptPos); + qreal labelAngle = 0; + if (not FindLabelGeometry(geom, pattern, labelAngle, labelWidth, labelHeight, ptPos)) + { + return; + } + + labelWidth = ToPixel(labelWidth, *pattern->GetPatternUnit()); + labelHeight = ToPixel(labelHeight, *pattern->GetPatternUnit()); QVector v; v << ptPos @@ -443,7 +502,7 @@ void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLa << QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight) << QPointF(ptPos.x(), ptPos.y() + labelHeight); - const qreal dAng = qDegreesToRadians(geom.GetRotation()); + const qreal dAng = qDegreesToRadians(labelAngle); const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); for (int i = 0; i < v.count(); ++i) { diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp index a6015cee8..efe939c73 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp @@ -59,25 +59,25 @@ VPatternLabelData::~VPatternLabelData() {} //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternLabelData::GetLabelWidth() const +QString VPatternLabelData::GetLabelWidth() const { return d->m_dLabelWidth; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternLabelData::SetLabelWidth(qreal dLabelW) +void VPatternLabelData::SetLabelWidth(const QString &dLabelW) { d->m_dLabelWidth = dLabelW; } //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternLabelData::GetLabelHeight() const +QString VPatternLabelData::GetLabelHeight() const { return d->m_dLabelHeight; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternLabelData::SetLabelHeight(qreal dLabelH) +void VPatternLabelData::SetLabelHeight(const QString &dLabelH) { d->m_dLabelHeight = dLabelH; } @@ -95,15 +95,15 @@ void VPatternLabelData::SetFontSize(int iSize) } //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternLabelData::GetRotation() const +QString VPatternLabelData::GetRotation() const { - return d->m_dRotation; + return d->m_dLabelAngle; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternLabelData::SetRotation(qreal dRot) +void VPatternLabelData::SetRotation(const QString &dRot) { - d->m_dRotation = dRot; + d->m_dLabelAngle = dRot; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h index efbc7624e..aa9160dab 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h @@ -47,17 +47,17 @@ public: virtual ~VPatternLabelData(); // methods, which set up label parameters - qreal GetLabelWidth() const; - void SetLabelWidth(qreal dLabelW); + QString GetLabelWidth() const; + void SetLabelWidth(const QString &dLabelW); - qreal GetLabelHeight() const; - void SetLabelHeight(qreal dLabelH); + QString GetLabelHeight() const; + void SetLabelHeight(const QString &dLabelH); int GetFontSize() const; void SetFontSize(int iSize); - qreal GetRotation() const; - void SetRotation(qreal dRot); + QString GetRotation() const; + void SetRotation(const QString &dRot); quint32 CenterPin() const; void SetCenterPin(const quint32 ¢erPin); diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h index 2ec73a71b..17859d696 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h @@ -42,10 +42,10 @@ class VPatternLabelDataPrivate : public QSharedData { public: VPatternLabelDataPrivate() - : m_dLabelWidth(0), - m_dLabelHeight(0), + : m_dLabelWidth(), + m_dLabelHeight(), + m_dLabelAngle(), m_iFontSize(0), - m_dRotation(0), m_centerPin(NULL_ID), m_topLeftPin(NULL_ID), m_bottomRightPin(NULL_ID) @@ -55,8 +55,8 @@ public: : QSharedData(data), m_dLabelWidth(data.m_dLabelWidth), m_dLabelHeight(data.m_dLabelHeight), + m_dLabelAngle(data.m_dLabelAngle), m_iFontSize(data.m_iFontSize), - m_dRotation(data.m_dRotation), m_centerPin(data.m_centerPin), m_topLeftPin(data.m_topLeftPin), m_bottomRightPin(data.m_bottomRightPin) @@ -64,14 +64,14 @@ public: ~VPatternLabelDataPrivate(); - /** @brief m_dLabelWidth label width */ - qreal m_dLabelWidth; - /** @brief m_dLabelHeight label height */ - qreal m_dLabelHeight; + /** @brief m_dLabelWidth formula to calculate the width of label */ + QString m_dLabelWidth; + /** @brief m_dLabelHeight formula to calculate the height of label */ + QString m_dLabelHeight; + /** @brief m_dLabelAngle formula to calculate the rotation angle of label */ + QString m_dLabelAngle; /** @brief m_iFontSize label text base font size */ int m_iFontSize; - /** @brief m_dRotation label rotation */ - qreal m_dRotation; /** @brief m_centerPin center pin id */ quint32 m_centerPin; /** @brief m_topLeftPin top left corner pin id */ diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 1874856be..d995ac8a2 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -213,8 +213,6 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) m_my = piece.GetMy(); ui->lineEditLetter->setText(piece.GetPatternPieceData().GetLetter()); - ui->groupBoxDetailLabel->setChecked(piece.GetPatternPieceData().IsVisible()); - ui->groupBoxPatternLabel->setChecked(piece.GetPatternInfo().IsVisible()); m_conMCP.clear(); for (int i = 0; i < piece.GetPatternPieceData().GetMCPCount(); ++i) @@ -224,25 +222,33 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) UpdateList(); - ui->groupBoxGrainline->setChecked(piece.GetGrainlineGeometry().IsVisible()); - SetGrainlineAngle(piece.GetGrainlineGeometry().GetRotation()); - SetGrainlineLength(piece.GetGrainlineGeometry().GetLength()); ui->comboBoxArrow->setCurrentIndex(int(piece.GetGrainlineGeometry().GetArrowType())); m_oldData = piece.GetPatternPieceData(); + ui->groupBoxDetailLabel->setChecked(m_oldData.IsVisible()); ChangeCurrentData(ui->comboBoxDLCenterPin, m_oldData.CenterPin()); ChangeCurrentData(ui->comboBoxDLTopLeftPin, m_oldData.TopLeftPin()); ChangeCurrentData(ui->comboBoxDLBottomRightPin, m_oldData.BottomRightPin()); + SetDLWidth(m_oldData.GetLabelWidth()); + SetDLHeight(m_oldData.GetLabelHeight()); + SetDLHeight(m_oldData.GetRotation()); m_oldGeom = piece.GetPatternInfo(); + ui->groupBoxPatternLabel->setChecked(m_oldGeom.IsVisible()); ChangeCurrentData(ui->comboBoxPLCenterPin, m_oldGeom.CenterPin()); ChangeCurrentData(ui->comboBoxPLTopLeftPin, m_oldGeom.TopLeftPin()); ChangeCurrentData(ui->comboBoxPLBottomRightPin, m_oldGeom.BottomRightPin()); + SetPLWidth(m_oldGeom.GetLabelWidth()); + SetPLHeight(m_oldGeom.GetLabelHeight()); + SetPLHeight(m_oldGeom.GetRotation()); m_oldGrainline = piece.GetGrainlineGeometry(); + ui->groupBoxGrainline->setChecked(m_oldGrainline.IsVisible()); ChangeCurrentData(ui->comboBoxGrainlineCenterPin, m_oldGrainline.CenterPin()); ChangeCurrentData(ui->comboBoxGrainlineTopPin, m_oldGrainline.TopPin()); ChangeCurrentData(ui->comboBoxGrainlineBottomPin, m_oldGrainline.BottomPin()); + SetGrainlineAngle(m_oldGrainline.GetRotation()); + SetGrainlineLength(m_oldGrainline.GetLength()); ValidObjects(MainPathIsValid()); EnabledGrainline(); @@ -1794,10 +1800,10 @@ VPiece DialogSeamAllowance::CreatePiece() const } piece.GetPatternPieceData().SetPos(m_oldData.GetPos()); - piece.GetPatternPieceData().SetLabelWidth(m_oldData.GetLabelWidth()); - piece.GetPatternPieceData().SetLabelHeight(m_oldData.GetLabelHeight()); + piece.GetPatternPieceData().SetLabelWidth(GetFormulaFromUser(ui->lineEditDLWidthFormula)); + piece.GetPatternPieceData().SetLabelHeight(GetFormulaFromUser(ui->lineEditDLHeightFormula)); piece.GetPatternPieceData().SetFontSize(m_oldData.GetFontSize()); - piece.GetPatternPieceData().SetRotation(m_oldData.GetRotation()); + piece.GetPatternPieceData().SetRotation(GetFormulaFromUser(ui->lineEditDLAngleFormula)); piece.GetPatternPieceData().SetVisible(ui->groupBoxDetailLabel->isChecked()); piece.GetPatternPieceData().SetCenterPin(getCurrentObjectId(ui->comboBoxDLCenterPin)); piece.GetPatternPieceData().SetTopLeftPin(getCurrentObjectId(ui->comboBoxDLTopLeftPin)); @@ -1808,6 +1814,9 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.GetPatternInfo().SetCenterPin(getCurrentObjectId(ui->comboBoxPLCenterPin)); piece.GetPatternInfo().SetTopLeftPin(getCurrentObjectId(ui->comboBoxPLTopLeftPin)); piece.GetPatternInfo().SetBottomRightPin(getCurrentObjectId(ui->comboBoxPLBottomRightPin)); + piece.GetPatternInfo().SetLabelWidth(GetFormulaFromUser(ui->lineEditPLWidthFormula)); + piece.GetPatternInfo().SetLabelHeight(GetFormulaFromUser(ui->lineEditPLHeightFormula)); + piece.GetPatternInfo().SetRotation(GetFormulaFromUser(ui->lineEditPLAngleFormula)); piece.GetGrainlineGeometry() = m_oldGrainline; piece.GetGrainlineGeometry().SetVisible(ui->groupBoxGrainline->isChecked()); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 6618fc8db..58187c3f3 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -495,7 +495,14 @@ void VToolSeamAllowance::UpdateLabel() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos); + qreal labelAngle = 0; + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelAngle, labelWidth, labelHeight, + pos); + if (type & VGrainlineItem::Error) + { + m_dataLabel->hide(); + return; + } m_dataLabel->SetMoveType(type); QFont fnt = qApp->font(); @@ -504,7 +511,8 @@ void VToolSeamAllowance::UpdateLabel() iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS); } m_dataLabel->SetFont(fnt); - m_dataLabel->SetSize(labelWidth, labelHeight); + m_dataLabel->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()), + ToPixel(labelHeight, *VDataTool::data.GetPatternUnit())); m_dataLabel->UpdateData(detail.GetName(), labelData); QRectF rectBB; @@ -513,14 +521,14 @@ void VToolSeamAllowance::UpdateLabel() rectBB.setHeight(m_dataLabel->boundingRect().height()); qreal dX; qreal dY; - if (m_dataLabel->IsContained(rectBB, labelData.GetRotation(), dX, dY) == false) + if (m_dataLabel->IsContained(rectBB, labelAngle, dX, dY) == false) { pos.setX(pos.x() + dX); pos.setY(pos.y() + dY); } m_dataLabel->setPos(pos); - m_dataLabel->setRotation(labelData.GetRotation()); + m_dataLabel->setRotation(labelAngle); m_dataLabel->Update(); m_dataLabel->show(); } @@ -544,7 +552,13 @@ void VToolSeamAllowance::UpdatePatternInfo() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(geom, labelWidth, labelHeight, pos); + qreal labelAngle = 0; + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(geom, labelAngle, labelWidth, labelHeight, pos); + if (type & VGrainlineItem::Error) + { + m_dataLabel->hide(); + return; + } m_patternInfo->SetMoveType(type); QFont fnt = qApp->font(); @@ -555,7 +569,8 @@ void VToolSeamAllowance::UpdatePatternInfo() } fnt.setPixelSize(iFS); m_patternInfo->SetFont(fnt); - m_patternInfo->SetSize(labelWidth, labelHeight); + m_patternInfo->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()), + ToPixel(labelHeight, *VDataTool::data.GetPatternUnit())); m_patternInfo->UpdateData(doc, getData()->size(), getData()->height()); QRectF rectBB; @@ -564,14 +579,14 @@ void VToolSeamAllowance::UpdatePatternInfo() rectBB.setHeight(m_patternInfo->boundingRect().height()); qreal dX; qreal dY; - if (m_patternInfo->IsContained(rectBB, geom.GetRotation(), dX, dY) == false) + if (m_patternInfo->IsContained(rectBB, labelAngle, dX, dY) == false) { pos.setX(pos.x() + dX); pos.setY(pos.y() + dY); } m_patternInfo->setPos(pos); - m_patternInfo->setRotation(geom.GetRotation()); + m_patternInfo->setRotation(labelAngle); m_patternInfo->Update(); m_patternInfo->GetTextLines() > 0 ? m_patternInfo->show() : m_patternInfo->hide(); } @@ -623,10 +638,6 @@ void VToolSeamAllowance::SaveMoveDetail(const QPointF& ptPos) VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; newDet.GetPatternPieceData().SetPos(ptPos); - newDet.GetPatternPieceData().SetLabelWidth(m_dataLabel->boundingRect().width()); - newDet.GetPatternPieceData().SetLabelHeight(m_dataLabel->boundingRect().height()); - newDet.GetPatternPieceData().SetFontSize(m_dataLabel->GetFontSize()); - newDet.GetPatternPieceData().SetRotation(m_dataLabel->rotation()); SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, id); moveCommand->setText(tr("move pattern piece label")); @@ -642,10 +653,13 @@ void VToolSeamAllowance::SaveResizeDetail(qreal dLabelW, int iFontSize) { VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; - newDet.GetPatternPieceData().SetLabelWidth(dLabelW); - newDet.GetPatternPieceData().SetLabelHeight(m_dataLabel->boundingRect().height()); + + dLabelW = FromPixel(dLabelW, *VDataTool::data.GetPatternUnit()); + newDet.GetPatternPieceData().SetLabelWidth(QString().setNum(dLabelW)); + const qreal height = FromPixel(m_dataLabel->boundingRect().height(), *VDataTool::data.GetPatternUnit()); + newDet.GetPatternPieceData().SetLabelHeight(QString().setNum(height)); newDet.GetPatternPieceData().SetFontSize(iFontSize); - newDet.GetPatternPieceData().SetRotation(m_dataLabel->rotation()); + SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id); resizeCommand->setText(tr("resize pattern piece label")); connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -661,10 +675,8 @@ void VToolSeamAllowance::SaveRotationDetail(qreal dRot) VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; newDet.GetPatternPieceData().SetPos(m_dataLabel->pos()); - newDet.GetPatternPieceData().SetLabelWidth(m_dataLabel->boundingRect().width()); - newDet.GetPatternPieceData().SetLabelHeight(m_dataLabel->boundingRect().height()); newDet.GetPatternPieceData().SetFontSize(m_dataLabel->GetFontSize()); - newDet.GetPatternPieceData().SetRotation(dRot); + newDet.GetPatternPieceData().SetRotation(QString().setNum(dRot)); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate pattern piece label")); @@ -682,10 +694,6 @@ void VToolSeamAllowance::SaveMovePattern(const QPointF &ptPos) VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; newDet.GetPatternInfo().SetPos(ptPos); - newDet.GetPatternInfo().SetLabelWidth(m_patternInfo->boundingRect().width()); - newDet.GetPatternInfo().SetLabelHeight(m_patternInfo->boundingRect().height()); - newDet.GetPatternInfo().SetFontSize(m_patternInfo->GetFontSize()); - newDet.GetPatternInfo().SetRotation(m_patternInfo->rotation()); SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, id); moveCommand->setText(tr("move pattern info label")); @@ -701,10 +709,13 @@ void VToolSeamAllowance::SaveResizePattern(qreal dLabelW, int iFontSize) { VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; - newDet.GetPatternInfo().SetLabelWidth(dLabelW); - newDet.GetPatternInfo().SetLabelHeight(m_patternInfo->boundingRect().height()); + + dLabelW = FromPixel(dLabelW, *VDataTool::data.GetPatternUnit()); + newDet.GetPatternInfo().SetLabelWidth(QString().setNum(dLabelW)); + qreal height = FromPixel(m_patternInfo->boundingRect().height(), *VDataTool::data.GetPatternUnit()); + newDet.GetPatternInfo().SetLabelHeight(QString().setNum(height)); newDet.GetPatternInfo().SetFontSize(iFontSize); - newDet.GetPatternInfo().SetRotation(m_patternInfo->rotation()); + SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id); resizeCommand->setText(tr("resize pattern info label")); connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -716,11 +727,10 @@ void VToolSeamAllowance::SaveRotationPattern(qreal dRot) { VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; + newDet.GetPatternInfo().SetPos(m_patternInfo->pos()); - newDet.GetPatternInfo().SetLabelWidth(m_patternInfo->boundingRect().width()); - newDet.GetPatternInfo().SetLabelHeight(m_patternInfo->boundingRect().height()); newDet.GetPatternInfo().SetFontSize(m_patternInfo->GetFontSize()); - newDet.GetPatternInfo().SetRotation(dRot); + newDet.GetPatternInfo().SetRotation(QString().setNum(dRot)); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate pattern info label")); @@ -763,8 +773,7 @@ void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; - dRot = qRadiansToDegrees(dRot); - newDet.GetGrainlineGeometry().SetRotation(QString().setNum(dRot)); + newDet.GetGrainlineGeometry().SetRotation(QString().setNum(qRadiansToDegrees(dRot))); newDet.GetGrainlineGeometry().SetPos(ptPos); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate grainline")); @@ -1167,9 +1176,27 @@ void VToolSeamAllowance::SaveDialogChange() } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, - qreal &labelHeight, QPointF &pos) +VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &rotationAngle, + qreal &labelWidth, qreal &labelHeight, QPointF &pos) { + + VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications; + try + { + if (not qmu::QmuTokenParser::IsSingle(labelData.GetRotation())) + { + restrictions &= ~ VPieceItem::IsRotatable; + } + + Calculator cal1; + rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetRotation()); + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return VPieceItem::Error; + } + const quint32 topLeftPin = labelData.TopLeftPin(); const quint32 bottomRightPin = labelData.BottomRightPin(); @@ -1186,7 +1213,10 @@ VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelD pos = labelRect.topLeft(); - return VTextGraphicsItem::IsRotatable; + restrictions &= ~ VPieceItem::IsMovable; + restrictions &= ~ VPieceItem::IsResizable; + + return restrictions; } catch(const VExceptionBadId &) { @@ -1194,10 +1224,53 @@ VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelD } } - labelWidth = labelData.GetLabelWidth(); - labelHeight = labelData.GetLabelHeight(); - pos = labelData.GetPos(); - return VTextGraphicsItem::AllModifications; + try + { + const bool widthIsSingle = qmu::QmuTokenParser::IsSingle(labelData.GetLabelWidth()); + + Calculator cal1; + labelWidth = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetLabelWidth()); + + const bool heightIsSingle = qmu::QmuTokenParser::IsSingle(labelData.GetLabelHeight()); + + Calculator cal2; + labelHeight = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetLabelHeight()); + + if (not widthIsSingle || not heightIsSingle) + { + restrictions &= ~ VPieceItem::IsResizable; + } + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return VPieceItem::Error; + } + + const quint32 centerPin = labelData.CenterPin(); + if (centerPin != NULL_ID) + { + try + { + const auto centerPinPoint = VAbstractTool::data.GeometricObject(centerPin); + + const qreal lWidth = ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()); + const qreal lHeight = ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()); + + pos = *centerPinPoint - QRectF(0, 0, lWidth, lHeight).center(); + restrictions &= ~ VPieceItem::IsMovable; + } + catch(const VExceptionBadId &) + { + pos = labelData.GetPos(); + } + } + else + { + pos = labelData.GetPos(); + } + + return restrictions; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index ab77960d9..08d70bf99 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -152,8 +152,8 @@ private: void RefreshGeometry(); void SaveDialogChange(); - VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, - QPointF &pos); + 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); From c6d19c3b9bea3c7fc9fc2a7fa9543d2ffea4f4d7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 13 Mar 2017 14:33:04 +0200 Subject: [PATCH 14/29] Grainline obey center pin point on layout. --HG-- branch : feature --- src/libs/vlayout/vlayoutpiece.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 372d43870..7d9595a60 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -206,7 +206,32 @@ bool FindGrainlineGeometry(const VGrainlineData& geom, const VContainer *pattern return false; } - pos = geom.GetPos(); + const quint32 centerPin = geom.CenterPin(); + if (centerPin != NULL_ID) + { + try + { + const auto centerPinPoint = pattern->GeometricObject(centerPin); + + const qreal cLength = ToPixel(length, *pattern->GetPatternUnit()); + QLineF grainline(centerPinPoint->x(), centerPinPoint->y(), + centerPinPoint->x() + cLength / 2.0, centerPinPoint->y()); + + grainline.setAngle(rotationAngle); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(cLength); + + pos = grainline.p2(); + } + catch(const VExceptionBadId &) + { + pos = geom.GetPos(); + } + } + else + { + pos = geom.GetPos(); + } return true; } From ce1c96528e81ffbb977812bac815d4218306bff9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 13 Mar 2017 15:00:32 +0200 Subject: [PATCH 15/29] If formula is empty set to default value. --HG-- branch : feature --- .../dialogs/tools/dialogseamallowance.cpp | 63 ++++++++++++++++--- .../dialogs/tools/dialogseamallowance.h | 16 ++--- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index d995ac8a2..af2fad36e 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -2461,8 +2461,13 @@ QVector DialogSeamAllowance::GetPieceInternals(const QListWidget *list) const } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetGrainlineAngle(const QString &angleFormula) +void DialogSeamAllowance::SetGrainlineAngle(QString angleFormula) { + if (angleFormula.isEmpty()) + { + angleFormula = QString("0"); + } + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) @@ -2475,98 +2480,140 @@ void DialogSeamAllowance::SetGrainlineAngle(const QString &angleFormula) } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetGrainlineLength(const QString &lengthFormula) +void DialogSeamAllowance::SetGrainlineLength(QString lengthFormula) { + if (lengthFormula.isEmpty()) + { + lengthFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + const QString formula = qApp->TrVars()->FormulaToUser(lengthFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { this->DeployGrainlineLength(); } + ui->lineEditLenFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditLenFormula); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetDLWidth(const QString &widthFormula) +void DialogSeamAllowance::SetDLWidth(QString widthFormula) { + if (widthFormula.isEmpty()) + { + widthFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + const QString formula = qApp->TrVars()->FormulaToUser(widthFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { this->DeployDLWidth(); } + ui->lineEditDLWidthFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditDLWidthFormula); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetDLHeight(const QString &heightFormula) +void DialogSeamAllowance::SetDLHeight(QString heightFormula) { + if (heightFormula.isEmpty()) + { + heightFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + const QString formula = qApp->TrVars()->FormulaToUser(heightFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { this->DeployDLHeight(); } + ui->lineEditDLHeightFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditDLHeightFormula); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetDLAngle(const QString &angleFormula) +void DialogSeamAllowance::SetDLAngle(QString angleFormula) { + if (angleFormula.isEmpty()) + { + angleFormula = QString("0"); + } + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { this->DeployDLAngle(); } + ui->lineEditDLAngleFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditDLAngleFormula); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetPLWidth(const QString &widthFormula) +void DialogSeamAllowance::SetPLWidth(QString widthFormula) { + if (widthFormula.isEmpty()) + { + widthFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + const QString formula = qApp->TrVars()->FormulaToUser(widthFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { this->DeployPLWidth(); } + ui->lineEditPLWidthFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditPLWidthFormula); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetPLHeight(const QString &heightFormula) +void DialogSeamAllowance::SetPLHeight(QString heightFormula) { + if (heightFormula.isEmpty()) + { + heightFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + const QString formula = qApp->TrVars()->FormulaToUser(heightFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { this->DeployPLHeight(); } + ui->lineEditPLHeightFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditPLHeightFormula); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetPLAngle(const QString &angleFormula) +void DialogSeamAllowance::SetPLAngle(QString angleFormula) { + if (angleFormula.isEmpty()) + { + angleFormula = QString("0"); + } + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { this->DeployPLAngle(); } + ui->lineEditPLAngleFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditPLAngleFormula); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index 14302ff5f..c3c2237d7 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -230,16 +230,16 @@ private: template QVector GetPieceInternals(const QListWidget *list) const; - void SetGrainlineAngle(const QString &angleFormula); - void SetGrainlineLength(const QString &lengthFormula); + void SetGrainlineAngle(QString angleFormula); + void SetGrainlineLength(QString lengthFormula); - void SetDLWidth(const QString &widthFormula); - void SetDLHeight(const QString &heightFormula); - void SetDLAngle(const QString &angleFormula); + void SetDLWidth(QString widthFormula); + void SetDLHeight(QString heightFormula); + void SetDLAngle(QString angleFormula); - void SetPLWidth(const QString &widthFormula); - void SetPLHeight(const QString &heightFormula); - void SetPLAngle(const QString &angleFormula); + void SetPLWidth(QString widthFormula); + void SetPLHeight(QString heightFormula); + void SetPLAngle(QString angleFormula); }; #endif // DIALOGSEAMALLOWANCE_H From 65b3c6d3aa324e8eaee4384ca5331547fb73a98c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 13 Mar 2017 15:00:44 +0200 Subject: [PATCH 16/29] Fix typo. --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogseamallowance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index af2fad36e..6a085a49d 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -231,7 +231,7 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) ChangeCurrentData(ui->comboBoxDLBottomRightPin, m_oldData.BottomRightPin()); SetDLWidth(m_oldData.GetLabelWidth()); SetDLHeight(m_oldData.GetLabelHeight()); - SetDLHeight(m_oldData.GetRotation()); + SetDLAngle(m_oldData.GetRotation()); m_oldGeom = piece.GetPatternInfo(); ui->groupBoxPatternLabel->setChecked(m_oldGeom.IsVisible()); @@ -240,7 +240,7 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) ChangeCurrentData(ui->comboBoxPLBottomRightPin, m_oldGeom.BottomRightPin()); SetPLWidth(m_oldGeom.GetLabelWidth()); SetPLHeight(m_oldGeom.GetLabelHeight()); - SetPLHeight(m_oldGeom.GetRotation()); + SetPLAngle(m_oldGeom.GetRotation()); m_oldGrainline = piece.GetGrainlineGeometry(); ui->groupBoxGrainline->setChecked(m_oldGrainline.IsVisible()); From 94ec43d85e0a2379ed70474afcbd399b285a8957 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 13 Mar 2017 15:54:38 +0200 Subject: [PATCH 17/29] Fix moving label according to restrictions. --HG-- branch : feature --- src/libs/vwidgets/vtextgraphicsitem.cpp | 157 ++++++++++++++++++------ src/libs/vwidgets/vtextgraphicsitem.h | 4 + 2 files changed, 122 insertions(+), 39 deletions(-) diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index be206cbe8..9f2e728ad 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -403,6 +403,12 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick) { + if (m_moveType == NotMovable) + { + pME->ignore(); + return; + } + // record the parameters of the mouse press. Specially record the position // of the press as the origin for the following operations m_ptStartPos = pos(); @@ -414,45 +420,66 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) // in rotation mode, do not do any changes here, because user might want to // rotate the label more. - if (m_moveType & IsRotatable) + if ((m_moveType & AllModifications ) == AllModifications) { - if (m_eMode != mRotate) + AllUserModifications(pME->pos()); + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsRotatable) + { + if (m_moveType & IsResizable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserRotateAndMove(); + } + else { m_eMode = mRotate; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsResizable) + { + if (m_moveType & IsRotatable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserMoveAndResize(pME->pos()); + } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsMovable) + { + if (m_moveType & IsRotatable) + { + UserRotateAndMove(); + } + else if (m_moveType & IsResizable) + { + UserMoveAndResize(pME->pos()); + } else { + m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } setZValue(ACTIVE_Z); Update(); } - else // All modifications + else { - if (m_eMode != mRotate) - { - // if user pressed the button inside the resize square, switch to resize mode - if (m_rectResize.contains(pME->pos()) == true) - { - m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); - } - else - { - // if user pressed the button outside the resize square, switch to move mode - m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - } - else - { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - // raise the label and redraw it - setZValue(ACTIVE_Z); - UpdateBox(); + pME->ignore(); + return; } } } @@ -468,7 +495,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) qreal dY; QRectF rectBB; const QPointF ptDiff = pME->scenePos() - m_ptStart; - if (m_eMode == mMove) + if (m_eMode == mMove && m_moveType & IsMovable) { // in move mode move the label along the mouse move from the origin QPointF pt = m_ptStartPos + ptDiff; @@ -484,10 +511,21 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) setPos(pt); UpdateBox(); } - else if (m_eMode == mResize) + else if (m_eMode == mResize && m_moveType & IsResizable) { // in resize mode, resize the label along the mouse move from the origin - QPointF pt = m_ptStartPos; + QPointF pt; + +// if (m_moveType & IsMovable) +// { + pt = m_ptStartPos; +// } +// else +// { +// pt = m_ptRotCenter - QRectF(0, 0, m_szStart.width() + ptDiff.x(), +// m_szStart.height() + ptDiff.y()).center(); +// } + rectBB.setTopLeft(pt); QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); rectBB.setSize(sz); @@ -496,12 +534,19 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { sz = QSizeF(sz.width()+dX, sz.height()+dY); } +// else +// { +// if (not (m_moveType & IsMovable)) +// { +// setPos(pt); +// } +// } SetSize(sz.width(), sz.height()); Update(); emit SignalShrink(); } - else if (m_eMode == mRotate) + else if (m_eMode == mRotate && m_moveType & IsRotatable) { // if the angle from the original position is small (0.5 degrees), just remeber the new angle // new angle will be the starting angle for rotation @@ -551,18 +596,18 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) // but if user did some operation (move/resize), emit the proper signal and update the label if (bShort == true) { - if (m_bReleased == true) + if (m_bReleased == true && m_moveType & IsRotatable) { m_eMode = mRotate; UpdateBox(); } } - else if (m_eMode == mMove) + else if (m_eMode == mMove && m_moveType & IsMovable) { emit SignalMoved(pos()); UpdateBox(); } - else + else if (m_moveType & IsResizable) { emit SignalResized(m_rectBoundingBox.width(), m_tm.GetFont().pixelSize()); Update(); @@ -572,18 +617,14 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { // in rotate mode, if user did just press/release, switch to move mode if (bShort == true) { - if (not (m_moveType & IsRotatable)) - { - m_eMode = mMove; - } - UpdateBox(); + m_eMode = mMove; } - else + else if (m_moveType & IsRotatable) { // if user rotated the item, emit proper signal and update the label emit SignalRotated(rotation()); - UpdateBox(); } + UpdateBox(); } m_bReleased = true; } @@ -649,3 +690,41 @@ void VTextGraphicsItem::CorrectLabel() m_tm.FitFontSize(m_rectBoundingBox.width(), m_rectBoundingBox.height()); UpdateBox(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::AllUserModifications(const QPointF &pos) +{ + if (m_eMode != mRotate) + { + UserMoveAndResize(pos); + } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::UserRotateAndMove() +{ + if (m_eMode != mRotate) + { + m_eMode = mMove; + } + SetOverrideCursor(cursorArrowCloseHand, 1, 1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::UserMoveAndResize(const QPointF &pos) +{ + if (m_rectResize.contains(pos) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + m_eMode = mMove; // block later if need + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} diff --git a/src/libs/vwidgets/vtextgraphicsitem.h b/src/libs/vwidgets/vtextgraphicsitem.h index 7c5d99bad..c453d520f 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.h +++ b/src/libs/vwidgets/vtextgraphicsitem.h @@ -92,6 +92,10 @@ private: double m_dAngle; QRectF m_rectResize; VTextManager m_tm; + + void AllUserModifications(const QPointF &pos); + void UserRotateAndMove(); + void UserMoveAndResize(const QPointF &pos); }; #endif // VTEXTGRAPHICSITEM_H From 6802c6f154cfd256391846a41d39a83bd97ff38f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 13 Mar 2017 16:10:25 +0200 Subject: [PATCH 18/29] Write/read label center pin point. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 2 ++ src/libs/ifc/schema/pattern/v0.4.4.xsd | 2 ++ src/libs/vtools/tools/vtoolseamallowance.cpp | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 6f415651e..e4a95f52d 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -821,6 +821,7 @@ void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) ppData.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); ppData.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"))); ppData.SetRotation(GetParametrString(domElement, AttrRotation, "0")); + ppData.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); ppData.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); ppData.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); @@ -850,6 +851,7 @@ void VPattern::ParsePiecePatternInfo(const QDomElement &domElement, VPiece &deta patternInfo.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); patternInfo.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"))); patternInfo.SetRotation(GetParametrString(domElement, AttrRotation, "0")); + patternInfo.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); patternInfo.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); patternInfo.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); } diff --git a/src/libs/ifc/schema/pattern/v0.4.4.xsd b/src/libs/ifc/schema/pattern/v0.4.4.xsd index 04528e713..a92a2a950 100644 --- a/src/libs/ifc/schema/pattern/v0.4.4.xsd +++ b/src/libs/ifc/schema/pattern/v0.4.4.xsd @@ -495,6 +495,7 @@ + @@ -508,6 +509,7 @@ + diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 58187c3f3..ac90a4801 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -258,6 +258,15 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement doc->SetAttribute(domData, AttrFont, data.GetFontSize()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation()); + if (data.CenterPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrCenterPin, data.CenterPin()); + } + else + { + domData.removeAttribute(AttrCenterPin); + } + if (data.TopLeftPin() > NULL_ID) { doc->SetAttribute(domData, AttrTopLeftPin, data.TopLeftPin()); @@ -305,6 +314,15 @@ void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domE doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation()); + if (geom.CenterPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrCenterPin, geom.CenterPin()); + } + else + { + domData.removeAttribute(AttrCenterPin); + } + if (geom.TopLeftPin() > NULL_ID) { doc->SetAttribute(domData, AttrTopLeftPin, geom.TopLeftPin()); From 698eaa7736d0fde69a90662512e5405539318a88 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 13 Mar 2017 16:20:58 +0200 Subject: [PATCH 19/29] Don't change position when restricted by center pin point. --HG-- branch : feature --- src/libs/vwidgets/vtextgraphicsitem.cpp | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 9f2e728ad..041aa8c84 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -516,15 +516,15 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) // in resize mode, resize the label along the mouse move from the origin QPointF pt; -// if (m_moveType & IsMovable) -// { + if (m_moveType & IsMovable) + { pt = m_ptStartPos; -// } -// else -// { -// pt = m_ptRotCenter - QRectF(0, 0, m_szStart.width() + ptDiff.x(), -// m_szStart.height() + ptDiff.y()).center(); -// } + } + else + { + pt = m_ptRotCenter - QRectF(0, 0, m_szStart.width() + ptDiff.x(), + m_szStart.height() + ptDiff.y()).center(); + } rectBB.setTopLeft(pt); QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); @@ -534,13 +534,13 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { sz = QSizeF(sz.width()+dX, sz.height()+dY); } -// else -// { -// if (not (m_moveType & IsMovable)) -// { -// setPos(pt); -// } -// } + else + { + if (not (m_moveType & IsMovable)) + { + setPos(pt); + } + } SetSize(sz.width(), sz.height()); Update(); From 011f0eaec05ea2fa528a5b6e1a9710ed00edea26 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 13 Mar 2017 16:57:54 +0200 Subject: [PATCH 20/29] Label item on scene has clockwise angle direction, we work with counter clockwise. --HG-- branch : feature --- src/libs/vtools/tools/vtoolseamallowance.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index ac90a4801..46df2a5ab 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -546,7 +546,7 @@ void VToolSeamAllowance::UpdateLabel() } m_dataLabel->setPos(pos); - m_dataLabel->setRotation(labelAngle); + m_dataLabel->setRotation(-labelAngle); m_dataLabel->Update(); m_dataLabel->show(); } @@ -694,7 +694,11 @@ void VToolSeamAllowance::SaveRotationDetail(qreal dRot) VPiece newDet = oldDet; newDet.GetPatternPieceData().SetPos(m_dataLabel->pos()); newDet.GetPatternPieceData().SetFontSize(m_dataLabel->GetFontSize()); - newDet.GetPatternPieceData().SetRotation(QString().setNum(dRot)); + + // Tranform angle to anticlockwise + QLineF line(0, 0, 100, 0); + line.setAngle(-dRot); + newDet.GetPatternPieceData().SetRotation(QString().setNum(line.angle())); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate pattern piece label")); @@ -748,6 +752,10 @@ void VToolSeamAllowance::SaveRotationPattern(qreal dRot) newDet.GetPatternInfo().SetPos(m_patternInfo->pos()); newDet.GetPatternInfo().SetFontSize(m_patternInfo->GetFontSize()); + + // Tranform angle to anticlockwise + QLineF line(0, 0, 100, 0); + line.setAngle(-dRot); newDet.GetPatternInfo().SetRotation(QString().setNum(dRot)); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); From de6e3d7213fe9a74492adbdf5eb85bbdb3c378b9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 11:11:35 +0200 Subject: [PATCH 21/29] Fix issue with angle direction of grainline. --HG-- branch : feature --- src/libs/vtools/tools/vtoolseamallowance.cpp | 2 +- src/libs/vwidgets/vgrainlineitem.cpp | 26 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 46df2a5ab..95c2a334d 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -756,7 +756,7 @@ void VToolSeamAllowance::SaveRotationPattern(qreal dRot) // Tranform angle to anticlockwise QLineF line(0, 0, 100, 0); line.setAngle(-dRot); - newDet.GetPatternInfo().SetRotation(QString().setNum(dRot)); + newDet.GetPatternInfo().SetRotation(QString().setNum(line.angle())); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate pattern info label")); diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 458b4609e..87b0ce2d8 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -666,19 +666,6 @@ QLineF VGrainlineItem::MainLine() const //--------------------------------------------------------------------------------------------------------------------- QPolygonF VGrainlineItem::FirstArrow(qreal dArrLen) const -{ - const QPointF pt1 = MainLine().p1(); - QPolygonF poly; - poly << pt1; - poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation + ARROW_ANGLE), - pt1.y() - dArrLen*sin(m_dRotation + ARROW_ANGLE)); - poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation - ARROW_ANGLE), - pt1.y() - dArrLen*sin(m_dRotation - ARROW_ANGLE)); - return poly; -} - -//--------------------------------------------------------------------------------------------------------------------- -QPolygonF VGrainlineItem::SecondArrow(qreal dArrLen) const { const QPointF pt2 = MainLine().p2(); QPolygonF poly; @@ -690,6 +677,19 @@ QPolygonF VGrainlineItem::SecondArrow(qreal dArrLen) const return poly; } +//--------------------------------------------------------------------------------------------------------------------- +QPolygonF VGrainlineItem::SecondArrow(qreal dArrLen) const +{ + const QPointF pt1 = MainLine().p1(); + QPolygonF poly; + poly << pt1; + poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation + ARROW_ANGLE), + pt1.y() - dArrLen*sin(m_dRotation + ARROW_ANGLE)); + poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation - ARROW_ANGLE), + pt1.y() - dArrLen*sin(m_dRotation - ARROW_ANGLE)); + return poly; +} + //--------------------------------------------------------------------------------------------------------------------- QPainterPath VGrainlineItem::MainShape() const { From c271a81b1d098c0cf380f0ea7fd59edf65ccf584 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 11:20:06 +0200 Subject: [PATCH 22/29] Fix bug with width and height restricted by pin points. --HG-- branch : feature --- src/libs/vtools/tools/vtoolseamallowance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 95c2a334d..d2b0da730 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1234,8 +1234,8 @@ VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelD const auto bottomRightPinPoint = VAbstractTool::data.GeometricObject(bottomRightPin); const QRectF labelRect = QRectF(*topLeftPinPoint, *bottomRightPinPoint); - labelWidth = qAbs(labelRect.width()); - labelHeight = qAbs(labelRect.height()); + labelWidth = FromPixel(qAbs(labelRect.width()), *VDataTool::data.GetPatternUnit()); + labelHeight = FromPixel(qAbs(labelRect.height()), *VDataTool::data.GetPatternUnit()); pos = labelRect.topLeft(); From 2eac3e0643239728cf78c4a0dbd178c756d14d6e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 11:24:36 +0200 Subject: [PATCH 23/29] Fix bug with rotation mode. --HG-- branch : feature --- src/libs/vwidgets/vtextgraphicsitem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 041aa8c84..b5be9b83b 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -596,7 +596,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) // but if user did some operation (move/resize), emit the proper signal and update the label if (bShort == true) { - if (m_bReleased == true && m_moveType & IsRotatable) + if (m_bReleased == true && m_moveType & IsRotatable) { m_eMode = mRotate; UpdateBox(); @@ -615,7 +615,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } else { // in rotate mode, if user did just press/release, switch to move mode - if (bShort == true) + if (bShort == true && (m_moveType & IsMovable || m_moveType & IsResizable)) { m_eMode = mMove; } From 76748f76888e4e08b523add07a268878071553ad Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 11:56:41 +0200 Subject: [PATCH 24/29] Fix grainline's resize rectangle position. --HG-- branch : feature --- src/libs/vwidgets/vgrainlineitem.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 87b0ce2d8..0a138bb5f 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -564,20 +564,20 @@ void VGrainlineItem::UpdateRectangle() setTransformOriginPoint(m_rectBoundingBox.center()); m_polyResize.clear(); - QPointF ptA = m_polyBound.at(3); + QPointF ptA = m_polyBound.at(1); m_polyResize << ptA; const double dSize = m_dScale * RESIZE_RECT_SIZE; - ptA.setX(ptA.x() + dSize*cos(m_dRotation - M_PI/2)); - ptA.setY(ptA.y() - dSize*sin(m_dRotation - M_PI/2)); + ptA.setX(ptA.x() - dSize*cos(m_dRotation - M_PI/2)); + ptA.setY(ptA.y() + dSize*sin(m_dRotation - M_PI/2)); m_polyResize << ptA; - ptA.setX(ptA.x() - dSize*cos(m_dRotation)); - ptA.setY(ptA.y() + dSize*sin(m_dRotation)); + ptA.setX(ptA.x() + dSize*cos(m_dRotation)); + ptA.setY(ptA.y() - dSize*sin(m_dRotation)); m_polyResize << ptA; - ptA.setX(ptA.x() + dSize*cos(m_dRotation + M_PI/2)); - ptA.setY(ptA.y() - dSize*sin(m_dRotation + M_PI/2)); + ptA.setX(ptA.x() - dSize*cos(m_dRotation + M_PI/2)); + ptA.setY(ptA.y() + dSize*sin(m_dRotation + M_PI/2)); m_polyResize << ptA; prepareGeometryChange(); From 88b56f54537990552789abf2caec1f9d2c25c5f1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 12:24:59 +0200 Subject: [PATCH 25/29] Fix bug with resizing free grainline. --HG-- branch : feature --- src/libs/vtools/tools/vtoolseamallowance.cpp | 1 + src/libs/vwidgets/vgrainlineitem.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index d2b0da730..4bce8e9e2 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -786,6 +786,7 @@ void VToolSeamAllowance::SaveResizeGrainline(qreal dLength) VPiece newDet = oldDet; dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit()); + newDet.GetGrainlineGeometry().SetPos(m_grainLine->pos()); newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength)); SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id); resizeCommand->setText(tr("resize grainline")); diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 0a138bb5f..9b6264115 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -381,7 +381,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); qreal dAng = qAtan2(-ptDiff.y(), ptDiff.x()); - dLen = dLen*qCos(dAng - m_dRotation); + dLen = -dLen*qCos(dAng - m_dRotation); qreal dPrevLen = m_dLength; // try with new length if (not (m_moveType & IsMovable)) @@ -394,7 +394,12 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) if (m_moveType & IsMovable) { - pos = m_ptStartPos; + QLineF grainline(this->pos().x(), this->pos().y(), + this->pos().x() + dPrevLen, this->pos().y()); + grainline.setAngle(qRadiansToDegrees(m_dRotation)); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(m_dLength); + pos = grainline.p2(); } else { @@ -416,10 +421,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) } else { - if (not (m_moveType & IsMovable)) - { - setPos(pos); - } + setPos(pos); } UpdateRectangle(); From 74ee767a316cadd695aaf078ba5655703c6e2feb Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 12:39:03 +0200 Subject: [PATCH 26/29] Fix bug with warning icon. --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogseamallowance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 6a085a49d..5d1b63e6f 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -1118,7 +1118,7 @@ void DialogSeamAllowance::UpdateDetailLabelValues() flagDLAngle = bFormulasOK[2]; flagDLFormulas = bFormulasOK[0] && bFormulasOK[1]; - if (not flagDLAngle && not (flagDLFormulas || flagDPin) && not flagPLAngle && not (flagPLFormulas || flagPPin)) + if (not flagDLAngle || not (flagDLFormulas || flagDPin) || not flagPLAngle || not (flagPLFormulas || flagPPin)) { QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); @@ -1202,7 +1202,7 @@ void DialogSeamAllowance::UpdatePatternLabelValues() flagPLAngle = bFormulasOK[2]; flagPLFormulas = bFormulasOK[0] && bFormulasOK[1]; - if (not flagDLAngle && not (flagDLFormulas || flagDPin) && not flagPLAngle && not (flagPLFormulas || flagPPin)) + if (not flagDLAngle || not (flagDLFormulas || flagDPin) || not flagPLAngle || not (flagPLFormulas || flagPPin)) { QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); From cf47ab8aa94452ac290d28ce985ac1cb6e714c3f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 12:53:35 +0200 Subject: [PATCH 27/29] Fix bug with resize cursor. --HG-- branch : feature --- src/libs/vwidgets/vtextgraphicsitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index b5be9b83b..014282088 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -637,7 +637,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) */ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) { - if (m_eMode == mMove || m_eMode == mResize) + if (m_eMode == mResize && m_moveType & IsResizable) { if (m_rectResize.contains(pHE->pos()) == true) { From f48325cc52b6599422775d18ba03a8ea8ea81a23 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 13:19:34 +0200 Subject: [PATCH 28/29] Fix bug with resize rectangle. Wrong scale factor. --HG-- branch : feature --- src/libs/vwidgets/vgrainlineitem.cpp | 40 ++++++++++++++++------------ src/libs/vwidgets/vgrainlineitem.h | 2 ++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 9b6264115..c272a7445 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -145,6 +145,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption if (m_eMode != mRotate) { pP->setBrush(clr); + UpdatePolyResize(); pP->drawPolygon(m_polyResize); } @@ -565,23 +566,7 @@ void VGrainlineItem::UpdateRectangle() m_rectBoundingBox = m_polyBound.boundingRect(); setTransformOriginPoint(m_rectBoundingBox.center()); - m_polyResize.clear(); - QPointF ptA = m_polyBound.at(1); - m_polyResize << ptA; - const double dSize = m_dScale * RESIZE_RECT_SIZE; - - ptA.setX(ptA.x() - dSize*cos(m_dRotation - M_PI/2)); - ptA.setY(ptA.y() + dSize*sin(m_dRotation - M_PI/2)); - m_polyResize << ptA; - - ptA.setX(ptA.x() + dSize*cos(m_dRotation)); - ptA.setY(ptA.y() - dSize*sin(m_dRotation)); - m_polyResize << ptA; - - ptA.setX(ptA.x() - dSize*cos(m_dRotation + M_PI/2)); - ptA.setY(ptA.y() + dSize*sin(m_dRotation + M_PI/2)); - m_polyResize << ptA; - + UpdatePolyResize(); prepareGeometryChange(); } @@ -765,3 +750,24 @@ void VGrainlineItem::UserMoveAndResize(const QPointF &pos) SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UpdatePolyResize() +{ + m_polyResize.clear(); + QPointF ptA = m_polyBound.at(1); + m_polyResize << ptA; + const double dSize = m_dScale * RESIZE_RECT_SIZE; + + ptA.setX(ptA.x() - dSize*cos(m_dRotation - M_PI/2)); + ptA.setY(ptA.y() + dSize*sin(m_dRotation - M_PI/2)); + m_polyResize << ptA; + + ptA.setX(ptA.x() + dSize*cos(m_dRotation)); + ptA.setY(ptA.y() - dSize*sin(m_dRotation)); + m_polyResize << ptA; + + ptA.setX(ptA.x() - dSize*cos(m_dRotation + M_PI/2)); + ptA.setY(ptA.y() + dSize*sin(m_dRotation + M_PI/2)); + m_polyResize << ptA; +} diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index 565719f03..27ddbab53 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -93,6 +93,8 @@ private: void AllUserModifications(const QPointF &pos); void UserRotateAndMove(); void UserMoveAndResize(const QPointF &pos); + + void UpdatePolyResize(); }; #endif // VGRAINLINEITEM_H From 4f38a31f252e7d24091f90bcc3f4e13d50f55ea9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Mar 2017 13:54:15 +0200 Subject: [PATCH 29/29] Convert label width and height to pattern units. --HG-- branch : feature --- src/libs/ifc/xml/vpatternconverter.cpp | 55 ++++++++++++++++++++++++++ src/libs/ifc/xml/vpatternconverter.h | 2 + 2 files changed, 57 insertions(+) diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index a9182536b..ff1c45e6d 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -119,6 +119,7 @@ static const QString strDetail = QStringLiteral("detail"); static const QString strSupplement = QStringLiteral("supplement"); static const QString strClosed = QStringLiteral("closed"); static const QString strWidth = QStringLiteral("width"); +static const QString strHeight = QStringLiteral("height"); static const QString strNode = QStringLiteral("node"); static const QString strNodes = QStringLiteral("nodes"); static const QString strData = QStringLiteral("data"); @@ -669,6 +670,8 @@ void VPatternConverter::ToV0_4_4() "Time to refactor the code."); SetVersion(QStringLiteral("0.4.4")); + LabelTagToV0_4_4(strData); + LabelTagToV0_4_4(strPatternInfo); Save(); } @@ -1944,6 +1947,58 @@ QDomElement VPatternConverter::GetUnionChildrenNodesV0_4_0(const QDomElement &de return tagNodes; } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::LabelTagToV0_4_4(const QString &tagName) +{ + // TODO. Delete if minimal supported version is 0.4.4 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 4), + "Time to refactor the code."); + + Unit unit = Unit::Cm; + const QStringList units = QStringList() << "mm" << "cm" << "inch"; + switch (units.indexOf(UniqueTagText(strUnit))) + { + case 0:// mm + unit = Unit::Mm; + break; + case 1:// cm + unit = Unit::Cm; + break; + case 2:// in + unit = Unit::Inch; + break; + default: + break; + } + + auto ConvertData = [unit](QDomElement &dom, const QString &attribute) + { + if (dom.hasAttribute(attribute)) + { + QString valStr = dom.attribute(attribute, "1"); + bool ok = false; + qreal val = valStr.toDouble(&ok); + if (not ok) + { + val = 1; + } + dom.setAttribute(attribute, QString().setNum(FromPixel(val, unit))); + } + }; + + const QDomNodeList list = elementsByTagName(tagName); + for (int i=0; i < list.size(); ++i) + { + QDomElement dom = list.at(i).toElement(); + + if (not dom.isNull()) + { + ConvertData(dom, strWidth); + ConvertData(dom, strHeight); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnionDetailsToV0_4_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index fedceebae..70df5445e 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -146,6 +146,8 @@ private: void TagUnionDetailsToV0_4_0(); QDomElement GetUnionDetailNodesV0_4_0(const QDomElement &detail); QDomElement GetUnionChildrenNodesV0_4_0(const QDomElement &detail); + + void LabelTagToV0_4_4(const QString &tagName); }; //---------------------------------------------------------------------------------------------------------------------