From 6e98acd13a9bd0314473a79d870ad0b9da059cd5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 31 Dec 2022 14:46:01 +0200 Subject: [PATCH] New variable: Piece seam line area. #193 --- src/app/valentina/xml/vpattern.cpp | 7 +- src/libs/ifc/ifcdef.cpp | 4 +- src/libs/ifc/ifcdef.h | 1 + src/libs/vmisc/def.h | 3 +- src/libs/vpatterndb/variables/vincrement_p.h | 6 +- .../vpatterndb/variables/vinternalvariable.h | 2 +- src/libs/vpatterndb/variables/vpiecearea.cpp | 27 +++++--- src/libs/vpatterndb/variables/vpiecearea.h | 4 +- src/libs/vpatterndb/vcontainer.cpp | 15 +++-- src/libs/vpatterndb/vpiece.cpp | 67 +++++++++++-------- src/libs/vpatterndb/vpiece.h | 5 +- src/libs/vpatterndb/vtranslatevars.cpp | 2 + .../TranslationsTest/tst_buitinregexp.cpp | 1 + 13 files changed, 94 insertions(+), 50 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 63ec5c778..06e5b999f 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -532,7 +532,7 @@ void VPattern::LiteParseIncrements() data->ClearUniqueIncrementNames(); - Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 11, "Check that you used all types"); + Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 12, "Check that you used all types"); data->ClearVariables(VarType::Increment); data->ClearVariables(VarType::IncrementSeparator); @@ -4447,14 +4447,15 @@ void VPattern::PrepareForParse(const Document &parse) } else if (parse == Document::LiteParse || parse == Document::FullLiteParse) { - Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 11, "Check that you used all types"); + Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 12, "Check that you used all types"); QVector types{VarType::LineAngle, VarType::LineLength, VarType::CurveLength, VarType::CurveCLength, VarType::ArcRadius, VarType::CurveAngle, - VarType::PieceArea}; + VarType::PieceExternalArea, + VarType::PieceSeamLineArea}; if (parse == Document::FullLiteParse) { types.append(VarType::Increment); diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index 1063320a2..56db11f4b 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -318,6 +318,7 @@ const QString currentSeamAllowance = QStringLiteral("CurrentSeamAllowance"); const QString rotation_V = QStringLiteral("Rotation"); const QString rotationElArc_ = rotation_V + elarc_; const QString pieceArea_ = QStringLiteral("PieceArea_"); +const QString pieceSeamLineArea_ = QStringLiteral("PieceSeamLineArea_"); const QStringList builInVariables { @@ -348,5 +349,6 @@ const QStringList builInVariables c1LengthSplPath, c2LengthSplPath, rotationElArc_, - pieceArea_ + pieceArea_, + pieceSeamLineArea_ }; diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 7ce66fbe9..03a02fcf5 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -243,6 +243,7 @@ extern const QString currentSeamAllowance; extern const QString rotation_V; extern const QString rotationElArc_; extern const QString pieceArea_; +extern const QString pieceSeamLineArea_; extern const QStringList builInVariables; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index ad48cb5b3..a6e28a5d9 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -275,7 +275,8 @@ enum class Vis : ToolVisHolderType }; enum class VarType : qint8 { Measurement, MeasurementSeparator, Increment, IncrementSeparator, LineLength, CurveLength, - CurveCLength, LineAngle, CurveAngle, ArcRadius, PieceArea, Unknown }; + CurveCLength, LineAngle, CurveAngle, ArcRadius, PieceExternalArea, PieceSeamLineArea, + Unknown }; enum class IncrementType : qint8 { Increment, Separator }; diff --git a/src/libs/vpatterndb/variables/vincrement_p.h b/src/libs/vpatterndb/variables/vincrement_p.h index b57746eb1..e939471a3 100644 --- a/src/libs/vpatterndb/variables/vincrement_p.h +++ b/src/libs/vpatterndb/variables/vincrement_p.h @@ -31,7 +31,6 @@ #include -#include "../ifc/ifcdef.h" #include "../vcontainer.h" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" @@ -54,7 +53,7 @@ public: { // When we create an increment in the dialog it will get neccesary data. Such data must be removed because will // confuse a user. Increment should not know nothing about internal variables. - Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 11, "Check that you used all types"); + Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 12, "Check that you used all types"); this->data->ClearVariables(QVector{VarType::LineAngle, VarType::LineLength, VarType::CurveLength, @@ -62,7 +61,8 @@ public: VarType::ArcRadius, VarType::CurveAngle, VarType::IncrementSeparator, - VarType::PieceArea}); + VarType::PieceExternalArea, + VarType::PieceSeamLineArea}); } VIncrementData(const VIncrementData &incr) diff --git a/src/libs/vpatterndb/variables/vinternalvariable.h b/src/libs/vpatterndb/variables/vinternalvariable.h index 330f2a253..869b3f785 100644 --- a/src/libs/vpatterndb/variables/vinternalvariable.h +++ b/src/libs/vpatterndb/variables/vinternalvariable.h @@ -63,7 +63,6 @@ public: void SetName(const QString &name); VarType GetType() const; - void SetType(const VarType &type); void SetAlias(const QString &alias); QString GetAlias() const; @@ -73,6 +72,7 @@ public: virtual bool IsNotUsed() const; protected: void SetValue(const qreal &value); + void SetType(const VarType &type); private: QSharedDataPointer d; }; diff --git a/src/libs/vpatterndb/variables/vpiecearea.cpp b/src/libs/vpatterndb/variables/vpiecearea.cpp index 75a7a1866..3806c9204 100644 --- a/src/libs/vpatterndb/variables/vpiecearea.cpp +++ b/src/libs/vpatterndb/variables/vpiecearea.cpp @@ -36,29 +36,38 @@ VPieceArea::VPieceArea() :d(new VPieceAreaData) { - SetType(VarType::PieceArea); + SetType(VarType::PieceExternalArea); } //--------------------------------------------------------------------------------------------------------------------- -VPieceArea::VPieceArea(quint32 pieceId, const VPiece &piece, const VContainer *data, Unit unit) +VPieceArea::VPieceArea(PieceAreaType type, quint32 pieceId, const VPiece &piece, const VContainer *data, Unit unit) :d(new VPieceAreaData(pieceId)) { // cppcheck-suppress unknownMacro SCASSERT(data != nullptr) - SetType(VarType::PieceArea); - QString shortName = piece.GetShortName(); if (shortName.isEmpty()) { shortName = piece.GetName().replace(QChar(QChar::Space), '_').left(25); if (shortName.isEmpty() || not QRegularExpression(VPiece::ShortNameRegExp()).match(shortName).hasMatch()) { - shortName = QObject::tr("Unknown"); + shortName = QObject::tr("Unknown", "piece area"); } } - SetName(pieceArea_ + shortName); - VInternalVariable::SetValue(FromPixel2(piece.Area(data), unit)); + + if (type == PieceAreaType::External) + { + SetType(VarType::PieceExternalArea); + SetName(pieceArea_ + shortName); + VInternalVariable::SetValue(FromPixel2(piece.ExternalArea(data), unit)); + } + else + { + SetType(VarType::PieceSeamLineArea); + SetName(pieceSeamLineArea_ + shortName); + VInternalVariable::SetValue(FromPixel2(piece.SeamLineArea(data), unit)); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -95,9 +104,11 @@ auto VPieceArea::operator=(VPieceArea &&var) Q_DECL_NOTHROW -> VPieceArea & //--------------------------------------------------------------------------------------------------------------------- void VPieceArea::SetValue(quint32 pieceId, const VPiece &piece, const VContainer *data, Unit unit) { + // cppcheck-suppress unknownMacro SCASSERT(data != nullptr) d->m_pieceId = pieceId; - VInternalVariable::SetValue(FromPixel(piece.Area(data), unit)); + VInternalVariable::SetValue(FromPixel2(GetType() == VarType::PieceExternalArea ? piece.ExternalArea(data) + : piece.SeamLineArea(data), unit)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/variables/vpiecearea.h b/src/libs/vpatterndb/variables/vpiecearea.h index d0bf0a97d..83f05e331 100644 --- a/src/libs/vpatterndb/variables/vpiecearea.h +++ b/src/libs/vpatterndb/variables/vpiecearea.h @@ -34,11 +34,13 @@ class VPiece; class VContainer; class VPieceAreaData; +enum class PieceAreaType : qint8 { External, SeamLine }; + class VPieceArea final :public VInternalVariable { public: VPieceArea(); - explicit VPieceArea(quint32 pieceId, const VPiece &piece, const VContainer *data, Unit unit); + explicit VPieceArea(PieceAreaType type, quint32 pieceId, const VPiece &piece, const VContainer *data, Unit unit); VPieceArea(const VPieceArea &var) = default; ~VPieceArea() override; diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index de03964af..d2600aa7c 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -392,7 +392,7 @@ void VContainer::ClearForFullParse() d->pieces->clear(); d->piecePaths->clear(); - Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 11, "Check that you used all types"); + Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 12, "Check that you used all types"); ClearVariables(QVector{VarType::Increment, VarType::IncrementSeparator, VarType::LineAngle, @@ -401,7 +401,8 @@ void VContainer::ClearForFullParse() VarType::CurveCLength, VarType::ArcRadius, VarType::CurveAngle, - VarType::PieceArea}); + VarType::PieceExternalArea, + VarType::PieceSeamLineArea}); ClearGObjects(); ClearUniqueNames(); } @@ -580,7 +581,8 @@ void VContainer::FillPiecesAreas(Unit unit) auto i = pieces->constBegin(); while (i != pieces->constEnd()) { - AddVariable(QSharedPointer::create(i.key(), i.value(), this, unit)); + AddVariable(QSharedPointer::create(PieceAreaType::External, i.key(), i.value(), this, unit)); + AddVariable(QSharedPointer::create(PieceAreaType::SeamLine, i.key(), i.value(), this, unit)); ++i; } } @@ -658,7 +660,12 @@ const QMap > VContainer::DataAnglesCurves() //--------------------------------------------------------------------------------------------------------------------- const QMap > VContainer::DataPieceArea() const { - return DataVar(VarType::PieceArea); + QMap > externalAreas = DataVar(VarType::PieceExternalArea); + QMap > seamLineAreas = DataVar(VarType::PieceSeamLineArea); + + Insert(externalAreas, seamLineAreas); + + return externalAreas; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 2c9e38404..f6222683d 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -1332,6 +1332,37 @@ void VPiece::TestInternalPathsIntersections(const VContainer *data) const } } +//--------------------------------------------------------------------------------------------------------------------- +qreal VPiece::Area(const QVector &shape, const VContainer *data) const +{ + SCASSERT(data != nullptr) + + const qreal mainArea = qAbs(VAbstractPiece::SumTrapezoids(shape))/2.0; + + qreal internalPathArea = 0; + const QVector pathsId = GetInternalPaths(); + for (auto id : pathsId) + { + const VPiecePath path = data->GetPiecePath(id); + if (path.GetType() != PiecePathType::InternalPath || not path.IsVisible(data->DataVariables()) || + not path.IsCutPath()) + { + continue; + } + + QVector points; + CastTo(path.PathPoints(data, shape), points); + if (points.isEmpty() || not VFuzzyComparePoints(ConstFirst(points), ConstLast(points))) + { + continue; + } + + internalPathArea += qAbs(VAbstractPiece::SumTrapezoids(points))/2.0; + } + + return mainArea - internalPathArea; +} + //--------------------------------------------------------------------------------------------------------------------- void VPiece::DumpPiece(const VPiece &piece, const VContainer *data, const QString &templateName) { @@ -1383,35 +1414,17 @@ void VPiece::TestInternalPaths(const VContainer *data) const } //--------------------------------------------------------------------------------------------------------------------- -auto VPiece::Area(const VContainer *data) const -> qreal +auto VPiece::ExternalArea(const VContainer *data) const -> qreal { - SCASSERT(data != nullptr) + return Area(CuttingPathPoints(data), data); +} - const QVector mainContour = CuttingPathPoints(data); - const qreal mainArea = qAbs(VAbstractPiece::SumTrapezoids(mainContour))/2.0; - - qreal internalPathArea = 0; - const QVector pathsId = GetInternalPaths(); - for (auto id : pathsId) - { - const VPiecePath path = data->GetPiecePath(id); - if (path.GetType() != PiecePathType::InternalPath || not path.IsVisible(data->DataVariables()) || - not path.IsCutPath()) - { - continue; - } - - QVector points; - CastTo(path.PathPoints(data, mainContour), points); - if (points.isEmpty() || not VFuzzyComparePoints(ConstFirst(points), ConstLast(points))) - { - continue; - } - - internalPathArea += qAbs(VAbstractPiece::SumTrapezoids(points))/2.0; - } - - return mainArea - internalPathArea; +//--------------------------------------------------------------------------------------------------------------------- +auto VPiece::SeamLineArea(const VContainer *data) const -> qreal +{ + QVector shape; + CastTo(MainPathPoints(data), shape); + return Area(shape, data); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 1fafabe79..e210018b1 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -145,7 +145,8 @@ public: void TestInternalPaths(const VContainer *data) const; static auto ShortNameRegExp() -> QString; - auto Area(const VContainer *data) const -> qreal; + auto ExternalArea(const VContainer *data) const -> qreal; + auto SeamLineArea(const VContainer *data) const -> qreal; private: QSharedDataPointer d; @@ -174,6 +175,8 @@ private: void TestInternalPathCuttingPathIntersection(const VContainer *data) const; void TestInternalPathsIntersections(const VContainer *data) const; + + auto Area(const QVector &shape, const VContainer *data) const -> qreal; }; Q_DECLARE_TYPEINFO(VPiece, Q_MOVABLE_TYPE); // NOLINT diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index fa700106e..51ebff020 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -394,6 +394,8 @@ void VTranslateVars::InitVariables() "Do not add symbol _ to the end of the name")); variables.insert(rotationElArc_, translate("VTranslateVars", "RotationElArc_", "Left symbol _ in the name")); variables.insert(pieceArea_, translate("VTranslateVars", "PieceArea_", "Left symbol _ in the name")); + variables.insert(pieceSeamLineArea_, translate("VTranslateVars", "PieceSeamLineArea_", + "Left symbol _ in the name")); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/test/TranslationsTest/tst_buitinregexp.cpp b/src/test/TranslationsTest/tst_buitinregexp.cpp index f3d9a3bd6..83d278ecb 100644 --- a/src/test/TranslationsTest/tst_buitinregexp.cpp +++ b/src/test/TranslationsTest/tst_buitinregexp.cpp @@ -171,6 +171,7 @@ void TST_BuitInRegExp::TestCheckUnderlineExists_data() data.insert(c2LengthSplPath, false); data.insert(rotationElArc_, true); data.insert(pieceArea_, true); + data.insert(pieceSeamLineArea_, true); //Catch case when new internal variable appears. QCOMPARE(data.size(), builInVariables.size());