New variable: Piece seam line area. #193

This commit is contained in:
Roman Telezhynskyi 2022-12-31 14:46:01 +02:00
parent a547822af1
commit 6e98acd13a
13 changed files with 94 additions and 50 deletions

View File

@ -532,7 +532,7 @@ void VPattern::LiteParseIncrements()
data->ClearUniqueIncrementNames(); data->ClearUniqueIncrementNames();
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 11, "Check that you used all types"); Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 12, "Check that you used all types");
data->ClearVariables(VarType::Increment); data->ClearVariables(VarType::Increment);
data->ClearVariables(VarType::IncrementSeparator); data->ClearVariables(VarType::IncrementSeparator);
@ -4447,14 +4447,15 @@ void VPattern::PrepareForParse(const Document &parse)
} }
else if (parse == Document::LiteParse || parse == Document::FullLiteParse) else if (parse == Document::LiteParse || parse == Document::FullLiteParse)
{ {
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 11, "Check that you used all types"); Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 12, "Check that you used all types");
QVector<VarType> types{VarType::LineAngle, QVector<VarType> types{VarType::LineAngle,
VarType::LineLength, VarType::LineLength,
VarType::CurveLength, VarType::CurveLength,
VarType::CurveCLength, VarType::CurveCLength,
VarType::ArcRadius, VarType::ArcRadius,
VarType::CurveAngle, VarType::CurveAngle,
VarType::PieceArea}; VarType::PieceExternalArea,
VarType::PieceSeamLineArea};
if (parse == Document::FullLiteParse) if (parse == Document::FullLiteParse)
{ {
types.append(VarType::Increment); types.append(VarType::Increment);

View File

@ -318,6 +318,7 @@ const QString currentSeamAllowance = QStringLiteral("CurrentSeamAllowance");
const QString rotation_V = QStringLiteral("Rotation"); const QString rotation_V = QStringLiteral("Rotation");
const QString rotationElArc_ = rotation_V + elarc_; const QString rotationElArc_ = rotation_V + elarc_;
const QString pieceArea_ = QStringLiteral("PieceArea_"); const QString pieceArea_ = QStringLiteral("PieceArea_");
const QString pieceSeamLineArea_ = QStringLiteral("PieceSeamLineArea_");
const QStringList builInVariables const QStringList builInVariables
{ {
@ -348,5 +349,6 @@ const QStringList builInVariables
c1LengthSplPath, c1LengthSplPath,
c2LengthSplPath, c2LengthSplPath,
rotationElArc_, rotationElArc_,
pieceArea_ pieceArea_,
pieceSeamLineArea_
}; };

View File

@ -243,6 +243,7 @@ extern const QString currentSeamAllowance;
extern const QString rotation_V; extern const QString rotation_V;
extern const QString rotationElArc_; extern const QString rotationElArc_;
extern const QString pieceArea_; extern const QString pieceArea_;
extern const QString pieceSeamLineArea_;
extern const QStringList builInVariables; extern const QStringList builInVariables;

View File

@ -275,7 +275,8 @@ enum class Vis : ToolVisHolderType
}; };
enum class VarType : qint8 { Measurement, MeasurementSeparator, Increment, IncrementSeparator, LineLength, CurveLength, 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 }; enum class IncrementType : qint8 { Increment, Separator };

View File

@ -31,7 +31,6 @@
#include <QSharedData> #include <QSharedData>
#include "../ifc/ifcdef.h"
#include "../vcontainer.h" #include "../vcontainer.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/diagnostic.h" #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 // 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. // confuse a user. Increment should not know nothing about internal variables.
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 11, "Check that you used all types"); Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 12, "Check that you used all types");
this->data->ClearVariables(QVector<VarType>{VarType::LineAngle, this->data->ClearVariables(QVector<VarType>{VarType::LineAngle,
VarType::LineLength, VarType::LineLength,
VarType::CurveLength, VarType::CurveLength,
@ -62,7 +61,8 @@ public:
VarType::ArcRadius, VarType::ArcRadius,
VarType::CurveAngle, VarType::CurveAngle,
VarType::IncrementSeparator, VarType::IncrementSeparator,
VarType::PieceArea}); VarType::PieceExternalArea,
VarType::PieceSeamLineArea});
} }
VIncrementData(const VIncrementData &incr) VIncrementData(const VIncrementData &incr)

View File

@ -63,7 +63,6 @@ public:
void SetName(const QString &name); void SetName(const QString &name);
VarType GetType() const; VarType GetType() const;
void SetType(const VarType &type);
void SetAlias(const QString &alias); void SetAlias(const QString &alias);
QString GetAlias() const; QString GetAlias() const;
@ -73,6 +72,7 @@ public:
virtual bool IsNotUsed() const; virtual bool IsNotUsed() const;
protected: protected:
void SetValue(const qreal &value); void SetValue(const qreal &value);
void SetType(const VarType &type);
private: private:
QSharedDataPointer<VInternalVariableData> d; QSharedDataPointer<VInternalVariableData> d;
}; };

View File

@ -36,29 +36,38 @@
VPieceArea::VPieceArea() VPieceArea::VPieceArea()
:d(new VPieceAreaData) :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)) :d(new VPieceAreaData(pieceId))
{ {
// cppcheck-suppress unknownMacro // cppcheck-suppress unknownMacro
SCASSERT(data != nullptr) SCASSERT(data != nullptr)
SetType(VarType::PieceArea);
QString shortName = piece.GetShortName(); QString shortName = piece.GetShortName();
if (shortName.isEmpty()) if (shortName.isEmpty())
{ {
shortName = piece.GetName().replace(QChar(QChar::Space), '_').left(25); shortName = piece.GetName().replace(QChar(QChar::Space), '_').left(25);
if (shortName.isEmpty() || not QRegularExpression(VPiece::ShortNameRegExp()).match(shortName).hasMatch()) 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) void VPieceArea::SetValue(quint32 pieceId, const VPiece &piece, const VContainer *data, Unit unit)
{ {
// cppcheck-suppress unknownMacro
SCASSERT(data != nullptr) SCASSERT(data != nullptr)
d->m_pieceId = pieceId; d->m_pieceId = pieceId;
VInternalVariable::SetValue(FromPixel(piece.Area(data), unit)); VInternalVariable::SetValue(FromPixel2(GetType() == VarType::PieceExternalArea ? piece.ExternalArea(data)
: piece.SeamLineArea(data), unit));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -34,11 +34,13 @@ class VPiece;
class VContainer; class VContainer;
class VPieceAreaData; class VPieceAreaData;
enum class PieceAreaType : qint8 { External, SeamLine };
class VPieceArea final :public VInternalVariable class VPieceArea final :public VInternalVariable
{ {
public: public:
VPieceArea(); 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(const VPieceArea &var) = default;
~VPieceArea() override; ~VPieceArea() override;

View File

@ -392,7 +392,7 @@ void VContainer::ClearForFullParse()
d->pieces->clear(); d->pieces->clear();
d->piecePaths->clear(); d->piecePaths->clear();
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 11, "Check that you used all types"); Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 12, "Check that you used all types");
ClearVariables(QVector<VarType>{VarType::Increment, ClearVariables(QVector<VarType>{VarType::Increment,
VarType::IncrementSeparator, VarType::IncrementSeparator,
VarType::LineAngle, VarType::LineAngle,
@ -401,7 +401,8 @@ void VContainer::ClearForFullParse()
VarType::CurveCLength, VarType::CurveCLength,
VarType::ArcRadius, VarType::ArcRadius,
VarType::CurveAngle, VarType::CurveAngle,
VarType::PieceArea}); VarType::PieceExternalArea,
VarType::PieceSeamLineArea});
ClearGObjects(); ClearGObjects();
ClearUniqueNames(); ClearUniqueNames();
} }
@ -580,7 +581,8 @@ void VContainer::FillPiecesAreas(Unit unit)
auto i = pieces->constBegin(); auto i = pieces->constBegin();
while (i != pieces->constEnd()) while (i != pieces->constEnd())
{ {
AddVariable(QSharedPointer<VPieceArea>::create(i.key(), i.value(), this, unit)); AddVariable(QSharedPointer<VPieceArea>::create(PieceAreaType::External, i.key(), i.value(), this, unit));
AddVariable(QSharedPointer<VPieceArea>::create(PieceAreaType::SeamLine, i.key(), i.value(), this, unit));
++i; ++i;
} }
} }
@ -658,7 +660,12 @@ const QMap<QString, QSharedPointer<VCurveAngle> > VContainer::DataAnglesCurves()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
const QMap<QString, QSharedPointer<VPieceArea> > VContainer::DataPieceArea() const const QMap<QString, QSharedPointer<VPieceArea> > VContainer::DataPieceArea() const
{ {
return DataVar<VPieceArea>(VarType::PieceArea); QMap<QString, QSharedPointer<VPieceArea> > externalAreas = DataVar<VPieceArea>(VarType::PieceExternalArea);
QMap<QString, QSharedPointer<VPieceArea> > seamLineAreas = DataVar<VPieceArea>(VarType::PieceSeamLineArea);
Insert(externalAreas, seamLineAreas);
return externalAreas;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -1332,6 +1332,37 @@ void VPiece::TestInternalPathsIntersections(const VContainer *data) const
} }
} }
//---------------------------------------------------------------------------------------------------------------------
qreal VPiece::Area(const QVector<QPointF> &shape, const VContainer *data) const
{
SCASSERT(data != nullptr)
const qreal mainArea = qAbs(VAbstractPiece::SumTrapezoids(shape))/2.0;
qreal internalPathArea = 0;
const QVector<quint32> 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<QPointF> 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) 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<QPointF> mainContour = CuttingPathPoints(data); //---------------------------------------------------------------------------------------------------------------------
const qreal mainArea = qAbs(VAbstractPiece::SumTrapezoids(mainContour))/2.0; auto VPiece::SeamLineArea(const VContainer *data) const -> qreal
{
qreal internalPathArea = 0; QVector<QPointF> shape;
const QVector<quint32> pathsId = GetInternalPaths(); CastTo(MainPathPoints(data), shape);
for (auto id : pathsId) return Area(shape, data);
{
const VPiecePath path = data->GetPiecePath(id);
if (path.GetType() != PiecePathType::InternalPath || not path.IsVisible(data->DataVariables()) ||
not path.IsCutPath())
{
continue;
}
QVector<QPointF> 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;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -145,7 +145,8 @@ public:
void TestInternalPaths(const VContainer *data) const; void TestInternalPaths(const VContainer *data) const;
static auto ShortNameRegExp() -> QString; 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: private:
QSharedDataPointer<VPieceData> d; QSharedDataPointer<VPieceData> d;
@ -174,6 +175,8 @@ private:
void TestInternalPathCuttingPathIntersection(const VContainer *data) const; void TestInternalPathCuttingPathIntersection(const VContainer *data) const;
void TestInternalPathsIntersections(const VContainer *data) const; void TestInternalPathsIntersections(const VContainer *data) const;
auto Area(const QVector<QPointF> &shape, const VContainer *data) const -> qreal;
}; };
Q_DECLARE_TYPEINFO(VPiece, Q_MOVABLE_TYPE); // NOLINT Q_DECLARE_TYPEINFO(VPiece, Q_MOVABLE_TYPE); // NOLINT

View File

@ -394,6 +394,8 @@ void VTranslateVars::InitVariables()
"Do not add symbol _ to the end of the name")); "Do not add symbol _ to the end of the name"));
variables.insert(rotationElArc_, translate("VTranslateVars", "RotationElArc_", "Left symbol _ in 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(pieceArea_, translate("VTranslateVars", "PieceArea_", "Left symbol _ in the name"));
variables.insert(pieceSeamLineArea_, translate("VTranslateVars", "PieceSeamLineArea_",
"Left symbol _ in the name"));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -171,6 +171,7 @@ void TST_BuitInRegExp::TestCheckUnderlineExists_data()
data.insert(c2LengthSplPath, false); data.insert(c2LengthSplPath, false);
data.insert(rotationElArc_, true); data.insert(rotationElArc_, true);
data.insert(pieceArea_, true); data.insert(pieceArea_, true);
data.insert(pieceSeamLineArea_, true);
//Catch case when new internal variable appears. //Catch case when new internal variable appears.
QCOMPARE(data.size(), builInVariables.size()); QCOMPARE(data.size(), builInVariables.size());