Resolved issue #651. Improve feature: Layout orientation according to grainline.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-12-27 15:54:29 +02:00
parent 58dae6e9d9
commit 6016308d58
21 changed files with 263 additions and 52 deletions

View File

@ -3,6 +3,7 @@
- [#894] Quick way to disable a passmark. - [#894] Quick way to disable a passmark.
- [#895] Improve path validation. Do not allow repeat the same curve twice. - [#895] Improve path validation. Do not allow repeat the same curve twice.
- Improve UI. Make placeholder menu scrollable. - Improve UI. Make placeholder menu scrollable.
- [#651] Improve feature: Layout orientation according to grainline.
# Version 0.6.2 (unreleased) # Version 0.6.2 (unreleased)
- [#903] Bug in tool Cut Spline path. - [#903] Bug in tool Cut Spline path.

View File

@ -1,6 +1,6 @@
.\" Manpage for valentina. .\" Manpage for valentina.
.\" Contact dismine@gmail.com to correct errors. .\" Contact dismine@gmail.com to correct errors.
.TH valentina 1 "18 July, 2018" "valentina man page" .TH valentina 1 "27 December, 2018" "valentina man page"
.SH NAME .SH NAME
Valentina \- Pattern making program. Valentina \- Pattern making program.
.SH SYNOPSIS .SH SYNOPSIS
@ -179,6 +179,8 @@ The path to output destination folder. By default the directory at which the app
.RB "Page bottom margin in current units like 3.0 (" "export mode" "). If not set will be used value from default printer. Or 0 if none printers was found." .RB "Page bottom margin in current units like 3.0 (" "export mode" "). If not set will be used value from default printer. Or 0 if none printers was found."
.IP "-r, --rotate <Angle>" .IP "-r, --rotate <Angle>"
.RB "Rotation in degrees (one of predefined, " "export mode" "). Default value is " "180" ". 0 is no-rotate. Valid values: 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 180. Each value show how many times details will be rotated. For example 180 mean two times (360/180=2) by 180 degree." .RB "Rotation in degrees (one of predefined, " "export mode" "). Default value is " "180" ". 0 is no-rotate. Valid values: 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 180. Each value show how many times details will be rotated. For example 180 mean two times (360/180=2) by 180 degree."
.IP "--followGrainline"
.RB "Order detail to follow grainline direction (" "export mode" ").
.IP "-c, --crop" .IP "-c, --crop"
.RB "Auto crop unused length (" "export mode" ")." .RB "Auto crop unused length (" "export mode" ")."
.IP "-u, --unite" .IP "-u, --unite"

View File

@ -1,6 +1,6 @@
.\" Manpage for valentina. .\" Manpage for valentina.
.\" Contact dismine@gmail.com to correct errors. .\" Contact dismine@gmail.com to correct errors.
.TH valentina 1 "18 July, 2018" "valentina man page" .TH valentina 1 "27 December, 2018" "valentina man page"
.SH NAME .SH NAME
Valentina \- Pattern making program. Valentina \- Pattern making program.
.SH SYNOPSIS .SH SYNOPSIS
@ -179,6 +179,8 @@ The path to output destination folder. By default the directory at which the app
.RB "Page bottom margin in current units like 3.0 (" "export mode" "). If not set will be used value from default printer. Or 0 if none printers was found." .RB "Page bottom margin in current units like 3.0 (" "export mode" "). If not set will be used value from default printer. Or 0 if none printers was found."
.IP "-r, --rotate <Angle>" .IP "-r, --rotate <Angle>"
.RB "Rotation in degrees (one of predefined, " "export mode" "). Default value is " "180" ". 0 is no-rotate. Valid values: 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 180. Each value show how many times details will be rotated. For example 180 mean two times (360/180=2) by 180 degree." .RB "Rotation in degrees (one of predefined, " "export mode" "). Default value is " "180" ". 0 is no-rotate. Valid values: 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 180. Each value show how many times details will be rotated. For example 180 mean two times (360/180=2) by 180 degree."
.IP "--followGrainline"
.RB "Order detail to follow grainline direction (" "export mode" ").
.IP "-c, --crop" .IP "-c, --crop"
.RB "Auto crop unused length (" "export mode" ")." .RB "Auto crop unused length (" "export mode" ")."
.IP "-u, --unite" .IP "-u, --unite"

View File

@ -227,6 +227,11 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap<QString, int>
"60, 72, 90, 180"), "60, 72, 90, 180"),
translate("VCommandLine", "Angle"))); translate("VCommandLine", "Angle")));
optionsIndex.insert(LONG_OPTION_FOLLOW_GRAINLINE, index++);
options.append(new QCommandLineOption(QStringList() << LONG_OPTION_FOLLOW_GRAINLINE,
translate("VCommandLine",
"Order detail to follow grainline direction (export mode).")));
optionsIndex.insert(LONG_OPTION_CROP, index++); optionsIndex.insert(LONG_OPTION_CROP, index++);
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP,
translate("VCommandLine", "Auto crop unused length (export mode)."))); translate("VCommandLine", "Auto crop unused length (export mode).")));
@ -568,6 +573,7 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
} }
} }
diag.SetFields(margins); diag.SetFields(margins);
diag.SetFollowGrainline(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_FOLLOW_GRAINLINE))));
diag.DialogAccepted(); // filling VLayoutGenerator diag.DialogAccepted(); // filling VLayoutGenerator

View File

@ -232,6 +232,18 @@ void DialogLayoutSettings::SetRotate(bool state)
ui->groupBoxRotate->setChecked(state); ui->groupBoxRotate->setChecked(state);
} }
//---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::GetFollowGrainline() const
{
return ui->checkBoxFollowGrainline->isChecked();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetFollowGrainline(bool state)
{
ui->checkBoxFollowGrainline->setChecked(state);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int DialogLayoutSettings::GetIncrease() const int DialogLayoutSettings::GetIncrease() const
{ {
@ -564,6 +576,7 @@ void DialogLayoutSettings::DialogAccepted()
generator->SetPaperWidth(GetPaperWidth()); generator->SetPaperWidth(GetPaperWidth());
generator->SetShift(static_cast<quint32>(qFloor(GetShift()))); generator->SetShift(static_cast<quint32>(qFloor(GetShift())));
generator->SetRotate(GetRotate()); generator->SetRotate(GetRotate());
generator->SetFollowGrainline(GetFollowGrainline());
generator->SetRotationIncrease(GetIncrease()); generator->SetRotationIncrease(GetIncrease());
generator->SetAutoCrop(GetAutoCrop()); generator->SetAutoCrop(GetAutoCrop());
generator->SetSaveLength(IsSaveLength()); generator->SetSaveLength(IsSaveLength());
@ -655,6 +668,7 @@ void DialogLayoutSettings::RestoreDefaults()
SetShift(VSettings::GetDefLayoutShift()); SetShift(VSettings::GetDefLayoutShift());
SetGroup(VSettings::GetDefLayoutGroup()); SetGroup(VSettings::GetDefLayoutGroup());
SetRotate(VSettings::GetDefLayoutRotate()); SetRotate(VSettings::GetDefLayoutRotate());
SetFollowGrainline(VSettings::GetDefLayoutFollowGrainline());
SetIncrease(VSettings::GetDefLayoutRotationIncrease()); SetIncrease(VSettings::GetDefLayoutRotationIncrease());
SetFields(GetDefPrinterFields()); SetFields(GetDefPrinterFields());
SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields()); SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields());
@ -1004,6 +1018,7 @@ void DialogLayoutSettings::ReadSettings()
const qreal height = UnitConvertor(settings->GetLayoutPaperHeight(), Unit::Px, LayoutUnit()); const qreal height = UnitConvertor(settings->GetLayoutPaperHeight(), Unit::Px, LayoutUnit());
SheetSize(QSizeF(width, height)); SheetSize(QSizeF(width, height));
SetGroup(settings->GetLayoutGroup()); SetGroup(settings->GetLayoutGroup());
SetFollowGrainline(settings->GetLayoutFollowGrainline());
SetRotate(settings->GetLayoutRotate()); SetRotate(settings->GetLayoutRotate());
SetIncrease(settings->GetLayoutRotationIncrease()); SetIncrease(settings->GetLayoutRotationIncrease());
SetAutoCrop(settings->GetLayoutAutoCrop()); SetAutoCrop(settings->GetLayoutAutoCrop());
@ -1031,6 +1046,7 @@ void DialogLayoutSettings::WriteSettings() const
settings->SetLayoutPaperWidth(GetPaperWidth()); settings->SetLayoutPaperWidth(GetPaperWidth());
settings->SetLayoutShift(GetShift()); settings->SetLayoutShift(GetShift());
settings->SetLayoutRotate(GetRotate()); settings->SetLayoutRotate(GetRotate());
settings->SetLayoutFollowGrainline(GetFollowGrainline());
settings->SetLayoutRotationIncrease(GetIncrease()); settings->SetLayoutRotationIncrease(GetIncrease());
settings->SetLayoutAutoCrop(GetAutoCrop()); settings->SetLayoutAutoCrop(GetAutoCrop());
settings->SetLayoutSaveLength(IsSaveLength()); settings->SetLayoutSaveLength(IsSaveLength());

View File

@ -76,6 +76,9 @@ public:
bool GetRotate() const; bool GetRotate() const;
void SetRotate(bool state); void SetRotate(bool state);
bool GetFollowGrainline() const;
void SetFollowGrainline(bool state);
int GetIncrease() const; int GetIncrease() const;
bool SetIncrease(int increase); bool SetIncrease(int increase);

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>601</width>
<height>533</height> <height>600</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -326,6 +326,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -416,6 +429,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="Line" name="line_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxFollowGrainline">
<property name="text">
<string>Follow grainline</string>
</property>
</widget>
</item>
<item> <item>
<widget class="Line" name="line_3"> <widget class="Line" name="line_3">
<property name="orientation"> <property name="orientation">

View File

@ -55,6 +55,7 @@ VLayoutGenerator::VLayoutGenerator(QObject *parent)
state(LayoutErrors::NoError), state(LayoutErrors::NoError),
shift(0), shift(0),
rotate(true), rotate(true),
followGrainline(false),
rotationIncrease(180), rotationIncrease(180),
autoCrop(false), autoCrop(false),
saveLength(false), saveLength(false),
@ -140,6 +141,7 @@ void VLayoutGenerator::Generate()
paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(papers.count())); paper.SetPaperIndex(static_cast<quint32>(papers.count()));
paper.SetRotate(rotate); paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline);
paper.SetRotationIncrease(rotationIncrease); paper.SetRotationIncrease(rotationIncrease);
paper.SetSaveLength(saveLength); paper.SetSaveLength(saveLength);
do do
@ -347,6 +349,7 @@ void VLayoutGenerator::GatherPages()
paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(i)); paper.SetPaperIndex(static_cast<quint32>(i));
paper.SetRotate(rotate); paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline);
paper.SetRotationIncrease(rotationIncrease); paper.SetRotationIncrease(rotationIncrease);
paper.SetSaveLength(saveLength); paper.SetSaveLength(saveLength);
paper.SetDetails(nDetails.at(i)); paper.SetDetails(nDetails.at(i));
@ -412,6 +415,7 @@ void VLayoutGenerator::UnitePages()
paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(i)); paper.SetPaperIndex(static_cast<quint32>(i));
paper.SetRotate(rotate); paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline);
paper.SetRotationIncrease(rotationIncrease); paper.SetRotationIncrease(rotationIncrease);
paper.SetSaveLength(saveLength); paper.SetSaveLength(saveLength);
paper.SetDetails(nDetails.at(i)); paper.SetDetails(nDetails.at(i));
@ -533,6 +537,18 @@ void VLayoutGenerator::SetRotate(bool value)
rotate = value; rotate = value;
} }
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::GetFollowGrainline() const
{
return followGrainline;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetFollowGrainline(bool value)
{
followGrainline = value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VLayoutGenerator::GetPaperWidth() const qreal VLayoutGenerator::GetPaperWidth() const
{ {

View File

@ -90,6 +90,9 @@ public:
bool GetRotate() const; bool GetRotate() const;
void SetRotate(bool value); void SetRotate(bool value);
bool GetFollowGrainline() const;
void SetFollowGrainline(bool value);
int GetRotationIncrease() const; int GetRotationIncrease() const;
void SetRotationIncrease(int value); void SetRotationIncrease(int value);
@ -132,6 +135,7 @@ private:
LayoutErrors state; LayoutErrors state;
quint32 shift; quint32 shift;
bool rotate; bool rotate;
bool followGrainline;
int rotationIncrease; int rotationIncrease;
bool autoCrop; bool autoCrop;
bool saveLength; bool saveLength;

View File

@ -143,6 +143,18 @@ void VLayoutPaper::SetRotate(bool value)
d->localRotate = d->globalRotate; d->localRotate = d->globalRotate;
} }
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutPaper::GetFollowGrainline() const
{
return d->followGrainline;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPaper::SetFollowGrainline(bool value)
{
d->followGrainline = value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VLayoutPaper::GetRotationIncrease() const int VLayoutPaper::GetRotationIncrease() const
{ {
@ -242,8 +254,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop
for (int i=1; i<= detailEdgesCount; ++i) for (int i=1; i<= detailEdgesCount; ++i)
{ {
VPosition *thread = new VPosition(d->globalContour, j, detail, i, &stop, d->localRotate, VPosition *thread = new VPosition(d->globalContour, j, detail, i, &stop, d->localRotate,
d->localRotationIncrease, d->localRotationIncrease, d->saveLength, d->followGrainline);
d->saveLength);
//Info for debug //Info for debug
#ifdef LAYOUT_DEBUG #ifdef LAYOUT_DEBUG
thread->setPaperIndex(d->paperIndex); thread->setPaperIndex(d->paperIndex);

View File

@ -78,6 +78,9 @@ public:
bool GetRotate() const; bool GetRotate() const;
void SetRotate(bool value); void SetRotate(bool value);
bool GetFollowGrainline() const;
void SetFollowGrainline(bool value);
int GetRotationIncrease() const; int GetRotationIncrease() const;
void SetRotationIncrease(int value); void SetRotationIncrease(int value);

View File

@ -53,7 +53,8 @@ public:
localRotate(true), localRotate(true),
globalRotationIncrease(180), globalRotationIncrease(180),
localRotationIncrease(180), localRotationIncrease(180),
saveLength(false) saveLength(false),
followGrainline(false)
{} {}
VLayoutPaperData(int height, VLayoutPaperData(int height,
@ -67,7 +68,8 @@ public:
localRotate(true), localRotate(true),
globalRotationIncrease(180), globalRotationIncrease(180),
localRotationIncrease(180), localRotationIncrease(180),
saveLength(false) saveLength(false),
followGrainline(false)
{} {}
VLayoutPaperData(const VLayoutPaperData &paper) VLayoutPaperData(const VLayoutPaperData &paper)
@ -81,7 +83,8 @@ public:
localRotate(paper.localRotate), localRotate(paper.localRotate),
globalRotationIncrease(paper.globalRotationIncrease), globalRotationIncrease(paper.globalRotationIncrease),
localRotationIncrease(paper.localRotationIncrease), localRotationIncrease(paper.localRotationIncrease),
saveLength(paper.saveLength) saveLength(paper.saveLength),
followGrainline(paper.followGrainline)
{} {}
~VLayoutPaperData() {} ~VLayoutPaperData() {}
@ -100,6 +103,7 @@ public:
int globalRotationIncrease; int globalRotationIncrease;
int localRotationIncrease; int localRotationIncrease;
bool saveLength; bool saveLength;
bool followGrainline;
private: private:
VLayoutPaperData& operator=(const VLayoutPaperData&) Q_DECL_EQ_DELETE; VLayoutPaperData& operator=(const VLayoutPaperData&) Q_DECL_EQ_DELETE;

View File

@ -673,6 +673,10 @@ void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer* pa
return; return;
} }
d->grainlineEnabled = true;
d->grainlineArrowType = geom.GetArrowType();
d->grainlineAngle = qRadiansToDegrees(dAng);
QPointF pt2(pt1.x() + dLen * qCos(dAng), pt1.y() - dLen * qSin(dAng)); QPointF pt2(pt1.x() + dLen * qCos(dAng), pt1.y() - dLen * qSin(dAng));
const qreal dArrowLen = ToPixel(0.5, *pattern->GetPatternUnit()); const qreal dArrowLen = ToPixel(0.5, *pattern->GetPatternUnit());
@ -709,6 +713,24 @@ QVector<QPointF> VLayoutPiece::GetGrainline() const
return Map(d->grainlinePoints); return Map(d->grainlinePoints);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutPiece::IsGrainlineEnabled() const
{
return d->grainlineEnabled;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VLayoutPiece::GrainlineAngle() const
{
return d->grainlineAngle;
}
//---------------------------------------------------------------------------------------------------------------------
ArrowType VLayoutPiece::GrainlineArrowType() const
{
return d->grainlineArrowType;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QTransform VLayoutPiece::GetMatrix() const QTransform VLayoutPiece::GetMatrix() const
{ {
@ -1195,7 +1217,7 @@ void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const
{ {
SCASSERT(parent != nullptr) SCASSERT(parent != nullptr)
if (d->grainlinePoints.count() < 2) if (not d->grainlineEnabled || d->grainlinePoints.count() < 2)
{ {
return; return;
} }

View File

@ -104,6 +104,9 @@ public:
void SetGrainline(const VGrainlineData& geom, const VContainer *pattern); void SetGrainline(const VGrainlineData& geom, const VContainer *pattern);
QVector<QPointF> GetGrainline() const; QVector<QPointF> GetGrainline() const;
bool IsGrainlineEnabled() const;
qreal GrainlineAngle() const;
ArrowType GrainlineArrowType() const;
QTransform GetMatrix() const; QTransform GetMatrix() const;
void SetMatrix(const QTransform &matrix); void SetMatrix(const QTransform &matrix);

View File

@ -61,6 +61,9 @@ public:
detailLabel(), detailLabel(),
patternInfo(), patternInfo(),
grainlinePoints(), grainlinePoints(),
grainlineArrowType(ArrowType::atFront),
grainlineAngle(0),
grainlineEnabled(false),
m_tmDetail(), m_tmDetail(),
m_tmPattern(), m_tmPattern(),
m_placeLabels() m_placeLabels()
@ -79,6 +82,9 @@ public:
detailLabel(detail.detailLabel), detailLabel(detail.detailLabel),
patternInfo(detail.patternInfo), patternInfo(detail.patternInfo),
grainlinePoints(detail.grainlinePoints), grainlinePoints(detail.grainlinePoints),
grainlineArrowType(detail.grainlineArrowType),
grainlineAngle(detail.grainlineAngle),
grainlineEnabled(detail.grainlineEnabled),
m_tmDetail(detail.m_tmDetail), m_tmDetail(detail.m_tmDetail),
m_tmPattern(detail.m_tmPattern), m_tmPattern(detail.m_tmPattern),
m_placeLabels(detail.m_placeLabels) m_placeLabels(detail.m_placeLabels)
@ -118,6 +124,10 @@ public:
/** @brief grainlineInfo line */ /** @brief grainlineInfo line */
QVector<QPointF> grainlinePoints; QVector<QPointF> grainlinePoints;
ArrowType grainlineArrowType;
qreal grainlineAngle;
bool grainlineEnabled;
/** @brief m_tmDetail text manager for laying out detail info */ /** @brief m_tmDetail text manager for laying out detail info */
VTextManager m_tmDetail; VTextManager m_tmDetail;

View File

@ -51,7 +51,7 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPosition::VPosition(const VContour &gContour, int j, const VLayoutPiece &detail, int i, std::atomic_bool *stop, VPosition::VPosition(const VContour &gContour, int j, const VLayoutPiece &detail, int i, std::atomic_bool *stop,
bool rotate, int rotationIncrease, bool saveLength) bool rotate, int rotationIncrease, bool saveLength, bool followGainline)
: QRunnable(), : QRunnable(),
bestResult(VBestSquare(gContour.GetSize(), saveLength)), bestResult(VBestSquare(gContour.GetSize(), saveLength)),
gContour(gContour), gContour(gContour),
@ -65,7 +65,8 @@ VPosition::VPosition(const VContour &gContour, int j, const VLayoutPiece &detail
stop(stop), stop(stop),
rotate(rotate), rotate(rotate),
rotationIncrease(rotationIncrease), rotationIncrease(rotationIncrease),
angle_between(0) angle_between(0),
followGrainline(followGainline)
{ {
if ((rotationIncrease >= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0) == false) if ((rotationIncrease >= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0) == false)
{ {
@ -81,6 +82,8 @@ void VPosition::run()
return; return;
} }
if (not followGrainline || not detail.IsGrainlineEnabled())
{
// We should use copy of the detail. // We should use copy of the detail.
VLayoutPiece workDetail = detail; VLayoutPiece workDetail = detail;
@ -108,6 +111,11 @@ void VPosition::run()
Rotate(rotationIncrease); Rotate(rotationIncrease);
} }
} }
}
else
{
FollowGrainline();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -351,14 +359,14 @@ bool VPosition::CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPosition::CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, int angle) const bool VPosition::CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, qreal angle) const
{ {
const QLineF globalEdge = gContour.GlobalEdge(j); const QLineF globalEdge = gContour.GlobalEdge(j);
bool flagSquare = false; bool flagSquare = false;
if (detail.IsForceFlipping()) if (detail.IsForceFlipping())
{ {
detail.Mirror(globalEdge); detail.Mirror(not followGrainline ? globalEdge : QLineF(10, 10, 10, 100));
} }
RotateEdges(detail, globalEdge, dEdge, angle); RotateEdges(detail, globalEdge, dEdge, angle);
@ -391,6 +399,26 @@ bool VPosition::CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, int a
return flagSquare; return flagSquare;
} }
//---------------------------------------------------------------------------------------------------------------------
void VPosition::RotateOnAngle(qreal angle)
{
// We should use copy of the detail.
VLayoutPiece workDetail = detail;
if (CheckRotationEdges(workDetail, j, i, angle))
{
#ifdef LAYOUT_DEBUG
# ifdef SHOW_CANDIDATE_BEST
++frame;
DrawDebug(gContour, workDetail, frame, paperIndex, detailsCount, details);
# endif
#endif
SaveCandidate(bestResult, workDetail, j, i, BestFrom::Rotation);
}
++frame;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPosition::CrossingType VPosition::Crossing(const VLayoutPiece &detail) const VPosition::CrossingType VPosition::Crossing(const VLayoutPiece &detail) const
{ {
@ -449,7 +477,7 @@ void VPosition::CombineEdges(VLayoutPiece &detail, const QLineF &globalEdge, con
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPosition::RotateEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge, int angle) const void VPosition::RotateEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge, qreal angle) const
{ {
QLineF detailEdge; QLineF detailEdge;
if (gContour.GetContour().isEmpty()) if (gContour.GetContour().isEmpty())
@ -487,21 +515,31 @@ void VPosition::Rotate(int increase)
return; return;
} }
// We should use copy of the detail. RotateOnAngle(angle);
VLayoutPiece workDetail = detail;
if (CheckRotationEdges(workDetail, j, i, angle))
{
#ifdef LAYOUT_DEBUG
# ifdef SHOW_CANDIDATE_BEST
++frame;
DrawDebug(gContour, workDetail, frame, paperIndex, detailsCount, details);
# endif
#endif
SaveCandidate(bestResult, workDetail, j, i, BestFrom::Rotation);
} }
++frame; }
//---------------------------------------------------------------------------------------------------------------------
void VPosition::FollowGrainline()
{
if (stop->load())
{
return;
}
QLineF detailGrainline(10, 10, 100, 10);
detailGrainline.setAngle(detail.GrainlineAngle());
const qreal angle = detailGrainline.angleTo(FabricGrainline());
if (detail.GrainlineArrowType() == ArrowType::atFront)
{
RotateOnAngle(angle);
}
if (detail.GrainlineArrowType() == ArrowType::atRear)
{
RotateOnAngle(angle+180);
} }
} }

View File

@ -44,7 +44,7 @@ class VPosition : public QRunnable
{ {
public: public:
VPosition(const VContour &gContour, int j, const VLayoutPiece &detail, int i, std::atomic_bool *stop, bool rotate, VPosition(const VContour &gContour, int j, const VLayoutPiece &detail, int i, std::atomic_bool *stop, bool rotate,
int rotationIncrease, bool saveLength); int rotationIncrease, bool saveLength, bool followGainline);
virtual ~VPosition() override{} virtual ~VPosition() override{}
quint32 getPaperIndex() const; quint32 getPaperIndex() const;
@ -83,6 +83,7 @@ private:
* @brief angle_between keep angle between global edge and detail edge. Need for optimization rotation. * @brief angle_between keep angle between global edge and detail edge. Need for optimization rotation.
*/ */
qreal angle_between; qreal angle_between;
bool followGrainline;
enum class CrossingType : char enum class CrossingType : char
{ {
@ -103,19 +104,34 @@ private:
void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ, BestFrom type); void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ, BestFrom type);
bool CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge); bool CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge);
bool CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, int angle) const; bool CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, qreal angle) const;
void RotateOnAngle(qreal angle);
CrossingType Crossing(const VLayoutPiece &detail) const; CrossingType Crossing(const VLayoutPiece &detail) const;
bool SheetContains(const QRectF &rect) const; bool SheetContains(const QRectF &rect) const;
void CombineEdges(VLayoutPiece &detail, const QLineF &globalEdge, const int &dEdge); void CombineEdges(VLayoutPiece &detail, const QLineF &globalEdge, const int &dEdge);
void RotateEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge, int angle) const; void RotateEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge, qreal angle) const;
static QPainterPath ShowDirection(const QLineF &edge); static QPainterPath ShowDirection(const QLineF &edge);
static QPainterPath DrawContour(const QVector<QPointF> &points); static QPainterPath DrawContour(const QVector<QPointF> &points);
static QPainterPath DrawDetails(const QVector<VLayoutPiece> &details); static QPainterPath DrawDetails(const QVector<VLayoutPiece> &details);
void Rotate(int increase); void Rotate(int increase);
void FollowGrainline();
QLineF FabricGrainline() const;
}; };
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VPosition::FabricGrainline return fabric gainline accoding to paper orientation
* @return fabric gainline line
*/
inline QLineF VPosition::FabricGrainline() const
{
return gContour.GetHeight() >= gContour.GetWidth() ? QLineF(10, 10, 10, 100) : QLineF(10, 10, 100, 10);
}
#endif // VPOSITION_H #endif // VPOSITION_H

View File

@ -127,6 +127,8 @@ const QString LONG_OPTION_TILED_PDF_TOP_MARGIN = QStringLiteral("tiledtmargin
const QString LONG_OPTION_TILED_PDF_BOTTOM_MARGIN = QStringLiteral("tiledbmargin"); const QString LONG_OPTION_TILED_PDF_BOTTOM_MARGIN = QStringLiteral("tiledbmargin");
const QString LONG_OPTION_TILED_PDF_LANDSCAPE = QStringLiteral("tiledLandscape"); const QString LONG_OPTION_TILED_PDF_LANDSCAPE = QStringLiteral("tiledLandscape");
const QString LONG_OPTION_FOLLOW_GRAINLINE = QStringLiteral("followGrainline");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief AllKeys return list with all command line keys (short and long forms). Used for testing on conflicts. * @brief AllKeys return list with all command line keys (short and long forms). Used for testing on conflicts.
@ -175,7 +177,8 @@ QStringList AllKeys()
<< LONG_OPTION_TILED_PDF_RIGHT_MARGIN << LONG_OPTION_TILED_PDF_RIGHT_MARGIN
<< LONG_OPTION_TILED_PDF_TOP_MARGIN << LONG_OPTION_TILED_PDF_TOP_MARGIN
<< LONG_OPTION_TILED_PDF_BOTTOM_MARGIN << LONG_OPTION_TILED_PDF_BOTTOM_MARGIN
<< LONG_OPTION_TILED_PDF_LANDSCAPE; << LONG_OPTION_TILED_PDF_LANDSCAPE
<< LONG_OPTION_FOLLOW_GRAINLINE;
return list; return list;
} }

View File

@ -123,6 +123,7 @@ extern const QString LONG_OPTION_TILED_PDF_RIGHT_MARGIN;
extern const QString LONG_OPTION_TILED_PDF_TOP_MARGIN; extern const QString LONG_OPTION_TILED_PDF_TOP_MARGIN;
extern const QString LONG_OPTION_TILED_PDF_BOTTOM_MARGIN; extern const QString LONG_OPTION_TILED_PDF_BOTTOM_MARGIN;
extern const QString LONG_OPTION_TILED_PDF_LANDSCAPE; extern const QString LONG_OPTION_TILED_PDF_LANDSCAPE;
extern const QString LONG_OPTION_FOLLOW_GRAINLINE;
QStringList AllKeys(); QStringList AllKeys();

View File

@ -85,6 +85,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPaperHeight, (QLatin1Strin
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPaperWidth, (QLatin1String("layout/paperWidth"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPaperWidth, (QLatin1String("layout/paperWidth")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutShift, (QLatin1String("layout/shift"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutShift, (QLatin1String("layout/shift")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutRotate, (QLatin1String("layout/Rotate"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutRotate, (QLatin1String("layout/Rotate")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutFollowGrainline, (QLatin1String("layout/followGrainline")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutRotationIncrease, (QLatin1String("layout/rotationIncrease"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutRotationIncrease, (QLatin1String("layout/rotationIncrease")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutAutoCrop, (QLatin1String("layout/autoCrop"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutAutoCrop, (QLatin1String("layout/autoCrop")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSaveLength, (QLatin1String("layout/saveLength"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSaveLength, (QLatin1String("layout/saveLength")))
@ -370,6 +371,24 @@ void VSettings::SetLayoutRotate(bool value)
setValue(*settingLayoutRotate, value); setValue(*settingLayoutRotate, value);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutFollowGrainline() const
{
return value(*settingLayoutFollowGrainline, GetDefLayoutFollowGrainline()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefLayoutFollowGrainline()
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetLayoutFollowGrainline(bool value)
{
setValue(*settingLayoutFollowGrainline, value);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VSettings::GetLayoutRotationIncrease() const int VSettings::GetLayoutRotationIncrease() const
{ {

View File

@ -97,6 +97,10 @@ public:
static bool GetDefLayoutRotate(); static bool GetDefLayoutRotate();
void SetLayoutRotate(bool value); void SetLayoutRotate(bool value);
bool GetLayoutFollowGrainline() const;
static bool GetDefLayoutFollowGrainline();
void SetLayoutFollowGrainline(bool value);
int GetLayoutRotationIncrease() const; int GetLayoutRotationIncrease() const;
static int GetDefLayoutRotationIncrease(); static int GetDefLayoutRotationIncrease();
void SetLayoutRotationIncrease(int value); void SetLayoutRotationIncrease(int value);