New variable: Piece seam line area. #193
This commit is contained in:
parent
a547822af1
commit
6e98acd13a
|
@ -532,7 +532,7 @@ void VPattern::LiteParseIncrements()
|
|||
|
||||
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::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<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,
|
||||
VarType::LineLength,
|
||||
VarType::CurveLength,
|
||||
VarType::CurveCLength,
|
||||
VarType::ArcRadius,
|
||||
VarType::CurveAngle,
|
||||
VarType::PieceArea};
|
||||
VarType::PieceExternalArea,
|
||||
VarType::PieceSeamLineArea};
|
||||
if (parse == Document::FullLiteParse)
|
||||
{
|
||||
types.append(VarType::Increment);
|
||||
|
|
|
@ -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_
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
#include <QSharedData>
|
||||
|
||||
#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<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,
|
||||
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)
|
||||
|
|
|
@ -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<VInternalVariableData> d;
|
||||
};
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
if (type == PieceAreaType::External)
|
||||
{
|
||||
SetType(VarType::PieceExternalArea);
|
||||
SetName(pieceArea_ + shortName);
|
||||
VInternalVariable::SetValue(FromPixel2(piece.Area(data), unit));
|
||||
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));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -392,7 +392,7 @@ void VContainer::ClearForFullParse()
|
|||
|
||||
d->pieces->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,
|
||||
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<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;
|
||||
}
|
||||
}
|
||||
|
@ -658,7 +660,12 @@ const QMap<QString, QSharedPointer<VCurveAngle> > VContainer::DataAnglesCurves()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
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, 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<QPointF> shape;
|
||||
CastTo(MainPathPoints(data), shape);
|
||||
return Area(shape, data);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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<VPieceData> d;
|
||||
|
||||
|
@ -174,6 +175,8 @@ private:
|
|||
|
||||
void TestInternalPathCuttingPathIntersection(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
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user