Merge with feature

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-04-02 15:34:14 +03:00
commit de39309f5a
34 changed files with 903 additions and 844 deletions

View File

@ -12,6 +12,7 @@
- [#932] 2nd version V passmarks.
- [#936] Improve list of predefined paper size formats for layout export. Added format Tabloid.
- Extend Label language to support Czech alphabet.
- [#916] Improve layout generation.
# Version 0.6.2 (unreleased)
- [#903] Bug in tool Cut Spline path.

View File

@ -1,6 +1,6 @@
.\" Manpage for valentina.
.\" Contact dismine@gmail.com to correct errors.
.TH valentina 1 "27 December, 2018" "valentina man page"
.TH valentina 1 "30 March, 2019" "valentina man page"
.SH NAME
Valentina \- Pattern making program.
.SH SYNOPSIS
@ -23,6 +23,10 @@ Displays version information.
The path to output destination folder. By default the directory at which the application was started. The path must exists and be reachable for the program.
.IP "-m, --mfile <The measure file>"
.RB "Path to custom measure file (" "export mode" ")."
.IP "-n, --time <Time>"
.RB "<Time> in minutes given for the algorithm to find best layout (" "export mode" "). Time must be in range from 1 minute to 60 minutes. Default value 1 minute."
.IP "--сoefficient <Coefficient>"
.RB "Set layout efficiency coefficient (" "export mode" "). Layout efficiency coefficient is the ratio of the area occupied by the pieces to the bounding rect of all pieces. If nesting reaches required level the process stops. If value is 0 no check will be made. Сoefficient must be in range from 0 to 100. Default value 0."
.IP "-f, --format <Format number>"
.RB "Number corresponding to output format (default = 0, " "export mode" "):"
.RS
@ -182,8 +186,6 @@ The path to output destination folder. By default the directory at which the app
.RB "Page top 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 "-B, --bmargin <The bottom margin>"
.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>"
.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"
@ -194,8 +196,6 @@ The path to output destination folder. By default the directory at which the app
.RB "Save length of the sheet if set (" "export mode" "). The option tells the program to use as much as possible width of sheet. Quality of a layout can be worse when this option was used."
.IP "-l, --layounits <The unit>"
.RB "Layout units (as paper's one except px, " "export mode" ")."
.IP "-s, --shiftlen <Shift length>"
.RB "Shift layout length measured in layout units (" "export mode" "). The option show how many points along edge will be used in creating a layout."
.IP "-G, --gapwidth <The gap width>"
.RB "The layout gap width x2, measured in layout units (" "export mode" "). Set distance between details and a detail and a sheet."
.IP "-g, --groups <Grouping type>"

View File

@ -1,6 +1,6 @@
.\" Manpage for valentina.
.\" Contact dismine@gmail.com to correct errors.
.TH valentina 1 "27 December, 2018" "valentina man page"
.TH valentina 1 "30 March, 2019" "valentina man page"
.SH NAME
Valentina \- Pattern making program.
.SH SYNOPSIS
@ -23,6 +23,10 @@ Displays version information.
The path to output destination folder. By default the directory at which the application was started. The path must exists and be reachable for the program.
.IP "-m, --mfile <The measure file>"
.RB "Path to custom measure file (" "export mode" ")."
.IP "-n, --time <Time>"
.RB "<Time> in minutes given for the algorithm to find best layout (" "export mode" "). Time must be in range from 1 minute to 60 minutes. Default value 1 minute."
.IP "--сoefficient <Coefficient>"
.RB "Set layout efficiency coefficient (" "export mode" "). Layout efficiency coefficient is the ratio of the area occupied by the pieces to the bounding rect of all pieces. If nesting reaches required level the process stops. If value is 0 no check will be made. Сoefficient must be in range from 0 to 100. Default value 0."
.IP "-f, --format <Format number>"
.RB "Number corresponding to output format (default = 0, " "export mode" "):"
.RS
@ -182,8 +186,6 @@ The path to output destination folder. By default the directory at which the app
.RB "Page top 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 "-B, --bmargin <The bottom margin>"
.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>"
.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"
@ -194,8 +196,6 @@ The path to output destination folder. By default the directory at which the app
.RB "Save length of the sheet if set (" "export mode" "). The option tells the program to use as much as possible width of sheet. Quality of a layout can be worse when this option was used."
.IP "-l, --layounits <The unit>"
.RB "Layout units (as paper's one except px, " "export mode" ")."
.IP "-s, --shiftlen <Shift length>"
.RB "Shift layout length measured in layout units (" "export mode" "). The option show how many points along edge will be used in creating a layout."
.IP "-G, --gapwidth <The gap width>"
.RB "The layout gap width x2, measured in layout units (" "export mode" "). Set distance between details and a detail and a sheet."
.IP "-g, --groups <Grouping type>"

View File

@ -110,19 +110,6 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
}
{
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool a = IsOptionSet(LONG_OPTION_SHIFTLENGTH);
bool b = IsOptionSet(LONG_OPTION_SHIFTUNITS);
if ((a || b) && !(a && b))
{
qCritical() << translate("VCommandLine", "Shift/Offset length must be used together with shift units.")
<< "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
{
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool a = IsOptionSet(LONG_OPTION_GAPWIDTH);
@ -163,19 +150,6 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
CheckKey(LONG_OPTION_TILED_PDF_BOTTOM_MARGIN,
translate("VCommandLine", "Tiled bottom margin must be used together with page units."));
const int rotateDegree = OptRotation();
diag.SetRotate(rotateDegree != 0 ); // 0 disable rotation
if (rotateDegree != VSettings::GetDefLayoutRotationIncrease())//Value by default
{
if (not diag.SetIncrease(rotateDegree))
{
qCritical() << translate("VCommandLine", "Invalid rotation value. That must be one of predefined values.")
<< "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
// if present units MUST be set before any other to keep conversions correct
if (!diag.SelectTemplate(OptPaperSize()))
{
@ -212,11 +186,6 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
}
}
if (IsOptionSet(LONG_OPTION_SHIFTLENGTH))
{
diag.SetShift(Lo2Px(OptionValue(LONG_OPTION_SHIFTLENGTH), diag));
}
if (IsOptionSet(LONG_OPTION_GAPWIDTH))
{
diag.SetLayoutWidth(Lo2Px(OptionValue(LONG_OPTION_GAPWIDTH), diag));
@ -256,6 +225,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
diag.SetFields(margins);
diag.SetFollowGrainline(IsOptionSet(LONG_OPTION_FOLLOW_GRAINLINE));
diag.SetNestingTime(OptNestingTime());
diag.SetEfficiencyCoefficient(OptEfficiencyCoefficient());
diag.DialogAccepted(); // filling VLayoutGenerator
@ -340,24 +311,6 @@ VAbstractLayoutDialog::PaperSizeTemplate VCommandLine::OptPaperSize() const
return FormatSize(LONG_OPTION_PAGETEMPLATE);
}
//------------------------------------------------------------------------------------------------------
int VCommandLine::OptRotation() const
{
int rotate = VSettings::GetDefLayoutRotationIncrease();
if (IsOptionSet(LONG_OPTION_ROTATE))
{
bool ok = false;
rotate = OptionValue(LONG_OPTION_ROTATE).toInt(&ok);
if (not ok)
{
rotate = VSettings::GetDefLayoutRotationIncrease();
}
}
return rotate;
}
//------------------------------------------------------------------------------------------------------
Cases VCommandLine::OptGroup() const
{
@ -635,6 +588,25 @@ void VCommandLine::InitCommandLineOptions()
optionsUsed.insert(LONG_OPTION_MEASUREFILE, option);
parser.addOption(option);
option = VCommandLineOption(QStringList({SINGLE_OPTION_NESTING_TIME, LONG_OPTION_NESTING_TIME}),
translate("VCommandLine", "<Time> in minutes given for the algorithm to find best "
"layout. Time must be in range from 1 minute to 60 "
"minutes. Default value 1 minute."),
translate("VCommandLine", "Time"));
optionsUsed.insert(LONG_OPTION_NESTING_TIME, option);
parser.addOption(option);
option = VCommandLineOption(LONG_OPTION_EFFICIENCY_COEFFICIENT,
translate("VCommandLine", "Set layout efficiency <coefficient>. Layout efficiency "
"coefficient is the ratio of the area occupied by the pieces "
"to the bounding rect of all pieces. If nesting reaches "
"required level the process stops. If value is 0 no check "
"will be made. Сoefficient must be in range from 0 to 100. "
"Default value 0."),
translate("VCommandLine", "Coefficient"));
optionsUsed.insert(LONG_OPTION_EFFICIENCY_COEFFICIENT, option);
parser.addOption(option);
option = VCommandLineOption(QStringList({SINGLE_OPTION_EXP2FORMAT, LONG_OPTION_EXP2FORMAT}),
translate("VCommandLine", "Number corresponding to output format (default = 0, "
"export mode):") +
@ -773,18 +745,6 @@ void VCommandLine::InitCommandLineOptions()
parser.addOption(option);
//=================================================================================================================
option = VCommandLineOption(QStringList({SINGLE_OPTION_ROTATE, LONG_OPTION_ROTATE}),
translate("VCommandLine", "Rotation in degrees (one of predefined, export mode). "
"Default value is 180. 0 is no-rotate. Valid values: "
"%1. Each value show how many times details will be "
"rotated. For example 180 mean two times (360/180=2) "
"by 180 degree.")
.arg("0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, "
"180"),
translate("VCommandLine", "Angle"));
optionsUsed.insert(LONG_OPTION_ROTATE, option);
parser.addOption(option);
option = VCommandLineOption(LONG_OPTION_FOLLOW_GRAINLINE,
translate("VCommandLine", "Order detail to follow grainline direction (export mode)."));
optionsUsed.insert(LONG_OPTION_FOLLOW_GRAINLINE, option);
@ -817,14 +777,6 @@ void VCommandLine::InitCommandLineOptions()
optionsUsed.insert(LONG_OPTION_SHIFTUNITS, option);
parser.addOption(option);
option = VCommandLineOption(QStringList({SINGLE_OPTION_SHIFTLENGTH, LONG_OPTION_SHIFTLENGTH}),
translate("VCommandLine", "Shift/Offset layout length measured in layout units "
"(export mode). The option show how many points along "
"edge will be used in creating a layout."),
translate("VCommandLine", "Shift/Offset length"));
optionsUsed.insert(LONG_OPTION_SHIFTLENGTH, option);
parser.addOption(option);
option = VCommandLineOption(QStringList({SINGLE_OPTION_GAPWIDTH, LONG_OPTION_GAPWIDTH}),
translate("VCommandLine", "The layout gap width x2, measured in layout units "
"(export mode). Set distance between details and a "
@ -973,4 +925,44 @@ QStringList VCommandLine::OptionValues(const QString &option) const
return parser.values(optionsUsed.value(option));
}
//---------------------------------------------------------------------------------------------------------------------
int VCommandLine::OptNestingTime() const
{
int time = VSettings::GetDefNestingTime();
if (IsOptionSet(LONG_OPTION_NESTING_TIME))
{
bool ok = false;
time = OptionValue(LONG_OPTION_NESTING_TIME).toInt(&ok);
if (not ok || time < 1 || time > 60)
{
qCritical() << translate("VCommandLine", "Time must be in range from 1 minute to 60 minutes.")
<< "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
return time;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VCommandLine::OptEfficiencyCoefficient() const
{
qreal coefficient = VSettings::GetDefEfficiencyCoefficient();
if (IsOptionSet(LONG_OPTION_EFFICIENCY_COEFFICIENT))
{
bool ok = false;
coefficient = OptionValue(LONG_OPTION_EFFICIENCY_COEFFICIENT).toDouble(&ok);
if (not ok || coefficient < 0 || coefficient > 100)
{
qCritical() << translate("VCommandLine", "Сoefficient must be in range from 0 to 100.")
<< "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
return coefficient;
}
#undef translate

View File

@ -150,8 +150,6 @@ protected:
//@brief returns VAbstractLayoutDialog::PaperSizeTemplate
VAbstractLayoutDialog::PaperSizeTemplate OptPaperSize() const;
//@brief returns rotation in degrees or 0 if not set
int OptRotation() const;
Cases OptGroup() const;
@ -175,6 +173,9 @@ private:
bool IsOptionSet(const QString &option) const;
QString OptionValue(const QString &option) const;
QStringList OptionValues(const QString &option) const;
int OptNestingTime() const;
qreal OptEfficiencyCoefficient() const;
};
#endif // VCMDEXPORT_H

View File

@ -35,23 +35,26 @@
#include <QPushButton>
#include <QMovie>
#include <QtDebug>
#include <QTime>
//---------------------------------------------------------------------------------------------------------------------
DialogLayoutProgress::DialogLayoutProgress(int count, QWidget *parent)
:QDialog(parent), ui(new Ui::DialogLayoutProgress), maxCount(count), movie(nullptr), isInitialized(false)
DialogLayoutProgress::DialogLayoutProgress(QElapsedTimer timer, qint64 timeout, QWidget *parent)
: QDialog(parent),
ui(new Ui::DialogLayoutProgress),
m_movie(new QMovie(QStringLiteral("://icon/16x16/progress.gif"))),
m_timer(timer),
m_timeout(timeout),
progressTimer(new QTimer(this))
{
ui->setupUi(this);
qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
ui->progressBar->setMaximum(maxCount);
ui->progressBar->setMaximum(static_cast<int>(timeout/1000));
ui->progressBar->setValue(0);
ui->labelMessage->setText(tr("Arranged workpieces: %1 from %2").arg(0).arg(count));
movie = new QMovie("://icon/16x16/progress.gif");
ui->labelProgress->setMovie (movie);
movie->start ();
ui->labelProgress->setMovie(m_movie);
m_movie->start();
QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
SCASSERT(bCancel != nullptr)
@ -59,13 +62,30 @@ DialogLayoutProgress::DialogLayoutProgress(int count, QWidget *parent)
setModal(true);
this->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
connect(progressTimer, &QTimer::timeout, this, [this]()
{
const qint64 elapsed = m_timer.elapsed();
const int timeout = static_cast<int>(m_timeout - elapsed);
QTime t(0, 0);
t = t.addMSecs(timeout);
ui->labelTimeLeft->setText(tr("Time left: %1").arg(t.toString()));
ui->progressBar->setValue(static_cast<int>(elapsed/1000));
if (timeout <= 1000)
{
emit Timeout();
progressTimer->stop();
}
});
progressTimer->start(1000);
}
//---------------------------------------------------------------------------------------------------------------------
DialogLayoutProgress::~DialogLayoutProgress()
{
delete m_movie;
delete ui;
delete movie;
}
//---------------------------------------------------------------------------------------------------------------------
@ -74,41 +94,19 @@ void DialogLayoutProgress::Start()
show();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutProgress::Arranged(int count)
{
ui->progressBar->setValue(count);
ui->labelMessage->setText(tr("Arranged workpieces: %1 from %2").arg(count).arg(maxCount));
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutProgress::Error(const LayoutErrors &state)
{
switch (state)
{
case LayoutErrors::NoError:
return;
case LayoutErrors::PrepareLayoutError:
qCritical() << tr("Couldn't prepare data for creation layout");
break;
case LayoutErrors::EmptyPaperError:
qCritical() << tr("One or more pattern pieces are bigger than the paper format you selected. Please, "
"select a bigger paper format.");
break;
case LayoutErrors::ProcessStoped:
default:
break;
}
done(QDialog::Rejected);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutProgress::Finished()
{
progressTimer->stop();
done(QDialog::Accepted);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutProgress::Efficiency(qreal value)
{
ui->labelMessage->setText(tr("Efficiency coefficient: %1%").arg(qRound(value * 10.) / 10.));
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutProgress::showEvent(QShowEvent *event)
{

View File

@ -30,6 +30,8 @@
#define DIALOGLAYOUTPROGRESS_H
#include <QDialog>
#include <QElapsedTimer>
#include <QTimer>
#include "../vlayout/vlayoutdef.h"
@ -43,17 +45,17 @@ class DialogLayoutProgress : public QDialog
Q_OBJECT
public:
explicit DialogLayoutProgress(int count, QWidget *parent = nullptr);
explicit DialogLayoutProgress(QElapsedTimer timer, qint64 timeout, QWidget *parent = nullptr);
~DialogLayoutProgress();
signals:
void Abort();
void Timeout();
public slots:
void Start();
void Arranged(int count);
void Error(const LayoutErrors &state);
void Finished();
void Efficiency(qreal value);
protected:
virtual void showEvent(QShowEvent *event) override;
@ -61,9 +63,11 @@ protected:
private:
Q_DISABLE_COPY(DialogLayoutProgress)
Ui::DialogLayoutProgress *ui;
const int maxCount;
QMovie *movie;
bool isInitialized;
QMovie *m_movie;
QElapsedTimer m_timer;
qint64 m_timeout;
bool isInitialized{false};
QTimer *progressTimer;
};
#endif // DIALOGLAYOUTPROGRESS_H

View File

@ -33,7 +33,7 @@
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Finding best position for workpieces. Please, wait.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Nesting. Please, wait.</string>
</property>
</widget>
</item>
@ -48,6 +48,15 @@
<property name="value">
<number>24</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
<property name="textDirection">
<enum>QProgressBar::TopToBottom</enum>
</property>
<property name="format">
<string notr="true">%p%</string>
</property>
</widget>
</item>
<item>
@ -62,7 +71,14 @@
<item>
<widget class="QLabel" name="labelMessage">
<property name="text">
<string notr="true">Arranged:</string>
<string notr="true">Efficiency coefficient: -</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelTimeLeft">
<property name="text">
<string>Time left:</string>
</property>
</widget>
</item>

View File

@ -141,15 +141,27 @@ void DialogLayoutSettings::SetPaperWidth(qreal value)
}
//---------------------------------------------------------------------------------------------------------------------
qreal DialogLayoutSettings::GetShift() const
int DialogLayoutSettings::GetNestingTime() const
{
return UnitConvertor(ui->doubleSpinBoxShift->value(), oldLayoutUnit, Unit::Px);
return ui->spinBoxNestingTime->value();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetShift(qreal value)
void DialogLayoutSettings::SetNestingTime(int value)
{
ui->doubleSpinBoxShift->setValue(UnitConvertor(value, Unit::Px, LayoutUnit()));
ui->spinBoxNestingTime->setValue(value);
}
//---------------------------------------------------------------------------------------------------------------------
qreal DialogLayoutSettings::GetEfficiencyCoefficient() const
{
return ui->doubleSpinBoxEfficiency->value();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetEfficiencyCoefficient(qreal ration)
{
ui->doubleSpinBoxEfficiency->setValue(ration);
}
//---------------------------------------------------------------------------------------------------------------------
@ -220,18 +232,6 @@ void DialogLayoutSettings::SetGroup(const Cases &value)
}
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::GetRotate() const
{
return ui->groupBoxRotate->isChecked();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetRotate(bool state)
{
ui->groupBoxRotate->setChecked(state);
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::GetFollowGrainline() const
{
@ -244,28 +244,6 @@ void DialogLayoutSettings::SetFollowGrainline(bool state)
ui->checkBoxFollowGrainline->setChecked(state);
}
//---------------------------------------------------------------------------------------------------------------------
int DialogLayoutSettings::GetIncrease() const
{
return ui->comboBoxIncrease->currentText().toInt();
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
bool DialogLayoutSettings::SetIncrease(int increase)
{
int index = ui->comboBoxIncrease->findText(QString::number(increase));
bool failed = (index == -1);
if (failed)
{
const QString def = QString::number(VSettings::GetDefLayoutRotationIncrease());// Value by default
index = ui->comboBoxIncrease->findText(def);
}
ui->comboBoxIncrease->setCurrentIndex(index);
return failed;
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::GetAutoCrop() const
{
@ -512,20 +490,16 @@ void DialogLayoutSettings::ConvertLayoutSize()
{
const Unit unit = LayoutUnit();
const qreal layoutWidth = ui->doubleSpinBoxLayoutWidth->value();
const qreal shift = ui->doubleSpinBoxShift->value();
ui->doubleSpinBoxLayoutWidth->setMaximum(FromPixel(QIMAGE_MAX, unit));
ui->doubleSpinBoxShift->setMaximum(FromPixel(QIMAGE_MAX, unit));
const qreal newLayoutWidth = UnitConvertor(layoutWidth, oldLayoutUnit, unit);
const qreal newShift = UnitConvertor(shift, oldLayoutUnit, unit);
oldLayoutUnit = unit;
CorrectLayoutDecimals();
MinimumLayoutSize();
ui->doubleSpinBoxLayoutWidth->setValue(newLayoutWidth);
ui->doubleSpinBoxShift->setValue(newShift);
}
//---------------------------------------------------------------------------------------------------------------------
@ -583,10 +557,9 @@ void DialogLayoutSettings::DialogAccepted()
generator->SetCaseType(GetGroup());
generator->SetPaperHeight(GetPaperHeight());
generator->SetPaperWidth(GetPaperWidth());
generator->SetShift(static_cast<quint32>(qFloor(GetShift())));
generator->SetRotate(GetRotate());
generator->SetNestingTime(GetNestingTime());
generator->SetEfficiencyCoefficient(GetEfficiencyCoefficient());
generator->SetFollowGrainline(GetFollowGrainline());
generator->SetRotationIncrease(GetIncrease());
generator->SetAutoCrop(GetAutoCrop());
generator->SetSaveLength(IsSaveLength());
generator->SetUnitePages(IsUnitePages());
@ -674,14 +647,13 @@ void DialogLayoutSettings::RestoreDefaults()
ui->comboBoxPrinter->blockSignals(false);
SetLayoutWidth(VSettings::GetDefLayoutWidth());
SetShift(VSettings::GetDefLayoutShift());
SetGroup(VSettings::GetDefLayoutGroup());
SetRotate(VSettings::GetDefLayoutRotate());
SetFollowGrainline(VSettings::GetDefLayoutFollowGrainline());
SetIncrease(VSettings::GetDefLayoutRotationIncrease());
SetFields(GetDefPrinterFields());
SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields());
SetMultiplier(VSettings::GetDefMultiplier());
SetNestingTime(VSettings::GetDefNestingTime());
SetEfficiencyCoefficient(VSettings::GetDefEfficiencyCoefficient());
CorrectMaxFileds();
IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked());
@ -990,11 +962,9 @@ void DialogLayoutSettings::CorrectLayoutDecimals()
case Unit::Mm:
case Unit::Px:
ui->doubleSpinBoxLayoutWidth->setDecimals(2);
ui->doubleSpinBoxShift->setDecimals(2);
break;
case Unit::Inch:
ui->doubleSpinBoxLayoutWidth->setDecimals(5);
ui->doubleSpinBoxShift->setDecimals(5);
break;
default:
break;
@ -1021,15 +991,14 @@ void DialogLayoutSettings::ReadSettings()
{
const VSettings *settings = qApp->ValentinaSettings();
SetLayoutWidth(settings->GetLayoutWidth());
SetShift(settings->GetLayoutShift());
SetNestingTime(settings->GetNestingTime());
SetEfficiencyCoefficient(settings->GetEfficiencyCoefficient());
const qreal width = UnitConvertor(settings->GetLayoutPaperWidth(), Unit::Px, LayoutUnit());
const qreal height = UnitConvertor(settings->GetLayoutPaperHeight(), Unit::Px, LayoutUnit());
SheetSize(QSizeF(width, height));
SetGroup(settings->GetLayoutGroup());
SetFollowGrainline(settings->GetLayoutFollowGrainline());
SetRotate(settings->GetLayoutRotate());
SetIncrease(settings->GetLayoutRotationIncrease());
SetAutoCrop(settings->GetLayoutAutoCrop());
SetSaveLength(settings->GetLayoutSaveLength());
SetUnitePages(settings->GetLayoutUnitePages());
@ -1053,10 +1022,7 @@ void DialogLayoutSettings::WriteSettings() const
settings->SetLayoutGroup(GetGroup());
settings->SetLayoutPaperHeight(GetPaperHeight());
settings->SetLayoutPaperWidth(GetPaperWidth());
settings->SetLayoutShift(GetShift());
settings->SetLayoutRotate(GetRotate());
settings->SetLayoutFollowGrainline(GetFollowGrainline());
settings->SetLayoutRotationIncrease(GetIncrease());
settings->SetLayoutAutoCrop(GetAutoCrop());
settings->SetLayoutSaveLength(IsSaveLength());
settings->SetLayoutUnitePages(IsUnitePages());
@ -1065,6 +1031,8 @@ void DialogLayoutSettings::WriteSettings() const
settings->SetStripOptimization(IsStripOptimization());
settings->SetMultiplier(GetMultiplier());
settings->SetTextAsPaths(IsTextAsPaths());
settings->SetNestingTime(GetNestingTime());
settings->SetEfficiencyCoefficient(GetEfficiencyCoefficient());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -61,8 +61,11 @@ public:
qreal GetPaperWidth() const;
void SetPaperWidth(qreal value);
qreal GetShift() const;
void SetShift(qreal value);
int GetNestingTime() const;
void SetNestingTime(int value);
qreal GetEfficiencyCoefficient() const;
void SetEfficiencyCoefficient(qreal ration);
qreal GetLayoutWidth() const;
void SetLayoutWidth(qreal value);
@ -73,15 +76,9 @@ public:
Cases GetGroup() const;
void SetGroup(const Cases &value);
bool GetRotate() const;
void SetRotate(bool state);
bool GetFollowGrainline() const;
void SetFollowGrainline(bool state);
int GetIncrease() const;
bool SetIncrease(int increase);
bool GetAutoCrop() const;
void SetAutoCrop(bool autoCrop);

View File

@ -361,6 +361,39 @@
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QComboBox" name="comboBoxLayoutUnit"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelLayoutWidth">
<property name="text">
<string>Gap width:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxNestingTime">
<property name="toolTip">
<string>Time given for the algorithm to find best layout.</string>
</property>
<property name="suffix">
<string> min</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>60</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutWidth">
<property name="minimumSize">
@ -369,6 +402,9 @@
<height>0</height>
</size>
</property>
<property name="suffix">
<string notr="true"> ×2</string>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
@ -380,43 +416,26 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelLayoutWidth">
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Gap width:</string>
<string>Efficiency:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelShiftLength">
<property name="text">
<string>Shift/Offset length:</string>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxEfficiency">
<property name="toolTip">
<string>Set layout efficiency coefficient. Layout efficiency coefficientt is the ratio of the area occupied by the pieces to the bounding rect of all pieces. If nesting reaches required level the process stops. If value is 0 no check will be made. </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxShift">
<property name="minimumSize">
<size>
<width>94</width>
<height>0</height>
</size>
<property name="suffix">
<string>%</string>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
<property name="decimals">
<number>1</number>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="comboBoxLayoutUnit"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string notr="true">×2</string>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
@ -443,165 +462,6 @@
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxRotate">
<property name="title">
<string>Rotate workpiece</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Rotate by</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxIncrease">
<property name="currentIndex">
<number>21</number>
</property>
<item>
<property name="text">
<string notr="true">1</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">2</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">3</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">4</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">5</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">6</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">8</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">9</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">10</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">12</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">15</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">18</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">20</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">24</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">30</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">36</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">40</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">45</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">60</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">72</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">90</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">180</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>degree</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">

View File

@ -5283,7 +5283,7 @@ bool MainWindow::DoExport(const VCommandLinePtr &expParams)
auto settings = expParams->DefaultGenerator();
settings->SetTextAsPaths(expParams->IsTextAsPaths());
if (LayoutSettings(*settings.get()))
if (GenerateLayout(*settings.get()))
{
try
{

View File

@ -194,7 +194,7 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked)
return;
}
layoutPrinterName = layout.SelectedPrinter();
LayoutSettings(lGenerator);
GenerateLayout(lGenerator);
tButton->setChecked(false);
}
else
@ -204,77 +204,182 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked)
}
//---------------------------------------------------------------------------------------------------------------------
bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator)
bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
{
lGenerator.SetDetails(listDetails);
DialogLayoutProgress progress(listDetails.count(), this);
QElapsedTimer timer;
timer.start();
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
QTimer *progressTimer = nullptr;
#endif
QScopedPointer<DialogLayoutProgress> progress(new DialogLayoutProgress(timer, lGenerator.GetNestingTime()*60000,
this));
if (VApplication::IsGUIMode())
{
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
m_taskbarProgress->setVisible(true);
m_taskbarProgress->setValue(0);
m_taskbarProgress->setMaximum(listDetails.count());
connect(&lGenerator, &VLayoutGenerator::Arranged, m_taskbarProgress, &QWinTaskbarProgress::setValue);
m_taskbarProgress->setMaximum(lGenerator.GetNestingTime());
progressTimer = new QTimer(this);
connect(progressTimer, &QTimer::timeout, this, [timer, &lGenerator]()
{
m_taskbarProgress->setValue(static_cast<int>(timer.elapsed()/60000));
});
progressTimer->start(1000);
#endif
connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start);
connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged);
connect(&lGenerator, &VLayoutGenerator::Error, &progress, &DialogLayoutProgress::Error);
connect(&lGenerator, &VLayoutGenerator::Finished, &progress, &DialogLayoutProgress::Finished);
connect(&progress, &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
connect(progress.data(), &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
connect(progress.data(), &DialogLayoutProgress::Timeout, &lGenerator, &VLayoutGenerator::Timeout);
}
else
progress->Start();
LayoutErrors nestingState = LayoutErrors::NoError;
auto IsTimeout = [&progress, &lGenerator, timer, &nestingState]()
{
connect(&lGenerator, &VLayoutGenerator::Error, this, &MainWindowsNoGUI::ErrorConsoleMode);
if (timer.hasExpired(lGenerator.GetNestingTime() * 60000))
{
if (nestingState != LayoutErrors::EmptyPaperError)
{
nestingState = LayoutErrors::Timeout;
}
progress->Finished();
return true;
}
return false;
};
bool rotationUsed = false;
int rotatate = 1;
lGenerator.SetShift(-1); // Trigger first shift calulation
lGenerator.SetRotate(false);
int papersCount = INT_MAX;
qreal efficiency = 0;
QCoreApplication::processEvents();
forever
{
if (IsTimeout())
{
break;
}
lGenerator.Generate(timer, lGenerator.GetNestingTime()*60000);
if (IsTimeout())
{
break;
}
switch (lGenerator.State())
{
case LayoutErrors::NoError:
if (lGenerator.PapersCount() <= papersCount)
{
const qreal layoutEfficiency = lGenerator.LayoutEfficiency();
if (efficiency < layoutEfficiency)
{
efficiency = layoutEfficiency;
progress->Efficiency(efficiency);
CleanLayout();
papers = lGenerator.GetPapersItems();// Blank sheets
details = lGenerator.GetAllDetailsItems();// All details items
detailsOnLayout = lGenerator.GetAllDetails();// All details items
shadows = CreateShadows(papers);
scenes = CreateScenes(papers, shadows, details);
//Uncomment to debug, shows global contour
// gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging
// InsertGlobalContours(scenes, gcontours); // uncomment for debugging
PrepareSceneList();
ignorePrinterFields = not lGenerator.IsUsePrinterFields();
margins = lGenerator.GetPrinterFields();
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
isAutoCrop = lGenerator.GetAutoCrop();
isUnitePages = lGenerator.IsUnitePages();
isLayoutStale = false;
}
}
lGenerator.SetShift(lGenerator.GetShift()/2.0);
break;
case LayoutErrors::EmptyPaperError:
if (lGenerator.IsRotationNeeded())
{
if (not rotationUsed)
{
lGenerator.SetRotate(true);
lGenerator.SetRotationNumber(++rotatate);
rotationUsed = true;
}
else
{
lGenerator.SetShift(lGenerator.GetShift()/2.0);
rotationUsed = false;
}
}
else
{
lGenerator.SetShift(lGenerator.GetShift()/2.0);
}
break;
case LayoutErrors::Timeout:
case LayoutErrors::PrepareLayoutError:
case LayoutErrors::ProcessStoped:
default:
break;
}
nestingState = lGenerator.State();
if (nestingState == LayoutErrors::PrepareLayoutError || nestingState == LayoutErrors::ProcessStoped
|| (nestingState == LayoutErrors::NoError && not qFuzzyIsNull(lGenerator.GetEfficiencyCoefficient())
&& efficiency >= lGenerator.GetEfficiencyCoefficient()))
{
break;
}
if (IsTimeout())
{
break;
}
}
lGenerator.Generate();
progress->Finished();
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (VApplication::IsGUIMode())
{
progressTimer->stop();
m_taskbarProgress->setVisible(false);
}
#endif
switch (lGenerator.State())
if (VApplication::IsGUIMode())
{
case LayoutErrors::NoError:
CleanLayout();
papers = lGenerator.GetPapersItems();// Blank sheets
details = lGenerator.GetAllDetailsItems();// All details items
detailsOnLayout = lGenerator.GetAllDetails();// All details items
shadows = CreateShadows(papers);
scenes = CreateScenes(papers, shadows, details);
//Uncomment to debug, shows global contour
// gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging
// InsertGlobalContours(scenes, gcontours); // uncomment for debugging
PrepareSceneList();
ignorePrinterFields = not lGenerator.IsUsePrinterFields();
margins = lGenerator.GetPrinterFields();
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
isAutoCrop = lGenerator.GetAutoCrop();
isUnitePages = lGenerator.IsUnitePages();
isLayoutStale = false;
if (VApplication::IsGUIMode())
{
QApplication::alert(this);
}
break;
case LayoutErrors::ProcessStoped:
case LayoutErrors::PrepareLayoutError:
case LayoutErrors::EmptyPaperError:
if (VApplication::IsGUIMode())
{
QApplication::alert(this);
}
return false;
default:
break;
QApplication::alert(this);
}
if (not papers.isEmpty() && nestingState != LayoutErrors::ProcessStoped)
{
return true;
}
else
{
ShowLayoutError(nestingState);
if (not VApplication::IsGUIMode())
{
qApp->exit(V_EX_DATAERR);
}
return false;
}
return true;
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state)
void MainWindowsNoGUI::ShowLayoutError(const LayoutErrors &state)
{
switch (state)
{
@ -287,12 +392,13 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state)
qCritical() << tr("One or more pattern pieces are bigger than the paper format you selected. Please, "
"select a bigger paper format.");
break;
case LayoutErrors::Timeout:
qCritical() << tr("Timeout.");
break;
case LayoutErrors::ProcessStoped:
default:
break;
}
qApp->exit(V_EX_DATAERR);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -133,7 +133,7 @@ protected:
virtual void CleanLayout()=0;
virtual void PrepareSceneList()=0;
QIcon ScenePreview(int i) const;
bool LayoutSettings(VLayoutGenerator& lGenerator);
bool GenerateLayout(VLayoutGenerator& lGenerator);
int ContinueIfLayoutStale();
QString FileName() const;
void SetSizeHeightForIndividualM() const;
@ -146,7 +146,6 @@ protected:
void CheckRequiredMeasurements(const VMeasurements *m) const;
private slots:
void PrintPages (QPrinter *printer);
void ErrorConsoleMode(const LayoutErrors &state);
private:
Q_DISABLE_COPY(MainWindowsNoGUI)
@ -212,6 +211,8 @@ private:
bool ignorePrinterFields, const QMarginsF &margins);
void ExportDetailsAsFlatLayout(const QVector<VLayoutPiece> &listDetails);
void ShowLayoutError(const LayoutErrors &state);
};
#endif // MAINWINDOWSNOGUI_H

View File

@ -176,7 +176,29 @@ void VBank::NotArranged(int i)
}
//---------------------------------------------------------------------------------------------------------------------
bool VBank::Prepare()
bool VBank::PrepareUnsorted()
{
for (int i=0; i < details.size(); ++i)
{
const qint64 square = details.at(i).Square();
if (square <= 0)
{
qCCritical(lBank, "Preparing data for layout error: Detail '%s' square <= 0",
qUtf8Printable(details.at(i).GetName()));
prepare = false;
return prepare;
}
unsorted.insert(i, square);
}
PrepareGroup();
prepare = true;
return prepare;
}
//---------------------------------------------------------------------------------------------------------------------
bool VBank::PrepareDetails()
{
if (layoutWidth <= 0)
{
@ -193,10 +215,12 @@ bool VBank::Prepare()
}
diagonal = 0;
for (int i=0; i < details.size(); ++i)
{
details[i].SetLayoutWidth(layoutWidth);
details[i].SetLayoutAllowancePoints();
if (not details.at(i).IsLayoutAllowanceValid())
{
const QString errorMsg = QObject::tr("Piece '%1' has invalid layout allowance. Please, check seam allowance"
@ -209,20 +233,8 @@ bool VBank::Prepare()
{
diagonal = d;
}
const qint64 square = details.at(i).Square();
if (square <= 0)
{
qCCritical(lBank, "Preparing data for layout error: Detail '%s' square <= 0",
qUtf8Printable(details.at(i).GetName()));
prepare = false;
return prepare;
}
unsorted.insert(i, square);
}
PrepareGroup();
prepare = true;
return prepare;
}
@ -436,6 +448,35 @@ void VBank::SqMaxMin(qint64 &sMax, qint64 &sMin) const
}
//---------------------------------------------------------------------------------------------------------------------
qreal VBank::DetailsBiggestEdge() const
{
qreal edge = 0;
for(auto &piece : details)
{
const qreal pieceEdge = piece.BiggestEdge();
if (pieceEdge > edge)
{
edge = pieceEdge;
}
}
return edge;
}
//---------------------------------------------------------------------------------------------------------------------
bool VBank::IsRotationNeeded() const
{
for(auto &piece : details)
{
if (not piece.IsGrainlineEnabled())
{
return true;
}
}
return false;
}
#if defined (Q_OS_WIN) && defined (Q_CC_MSVC)
#pragma pop_macro("small")
#endif

View File

@ -54,6 +54,7 @@ public:
qreal GetLayoutWidth() const;
void SetLayoutWidth(qreal value);
void SetDetails(const QVector<VLayoutPiece> &details);
int GetNext();
VLayoutPiece GetDetail(int i) const;
@ -61,7 +62,8 @@ public:
void Arranged(int i);
void NotArranged(int i);
bool Prepare();
bool PrepareUnsorted();
bool PrepareDetails();
void Reset();
void SetCaseType(Cases caseType);
@ -70,6 +72,9 @@ public:
int ArrangedCount() const;
qreal GetBiggestDiagonal() const;
qreal DetailsBiggestEdge() const;
bool IsRotationNeeded() const;
private:
Q_DISABLE_COPY(VBank)

View File

@ -96,6 +96,8 @@ void VContour::CeateEmptySheetContour()
{
d->globalContour = CutEmptySheetEdge();
d->globalContour.append(d->globalContour.first()); // Close path
ResetAttributes();
}
}
@ -103,6 +105,8 @@ void VContour::CeateEmptySheetContour()
void VContour::SetContour(const QVector<QPointF> &contour)
{
d->globalContour = contour;
ResetAttributes();
}
//---------------------------------------------------------------------------------------------------------------------
@ -112,15 +116,17 @@ QVector<QPointF> VContour::GetContour() const
}
//---------------------------------------------------------------------------------------------------------------------
quint32 VContour::GetShift() const
qreal VContour::GetShift() const
{
return d->shift;
}
//---------------------------------------------------------------------------------------------------------------------
void VContour::SetShift(quint32 shift)
void VContour::SetShift(qreal shift)
{
d->shift = shift;
ResetAttributes();
}
//---------------------------------------------------------------------------------------------------------------------
@ -200,17 +206,7 @@ QVector<QPointF> VContour::UniteWithContour(const VLayoutPiece &detail, int glob
//---------------------------------------------------------------------------------------------------------------------
int VContour::GlobalEdgesCount() const
{
int count = 0;
if (not d->globalContour.isEmpty())
{
count = d->globalContour.count();
}
else
{
const qreal shift = d->shift == 0 ? ToPixel(0.5, Unit::Cm) : d->shift;
count = qFloor(EmptySheetEdge().length()/shift);
}
return count;
return d->m_emptySheetEdgesCount;
}
//---------------------------------------------------------------------------------------------------------------------
@ -251,7 +247,7 @@ QLineF VContour::GlobalEdge(int i) const
QVector<QPointF> VContour::CutEdge(const QLineF &edge) const
{
QVector<QPointF> points;
if (d->shift == 0)
if (qFuzzyIsNull(d->shift))
{
points.append(edge.p1());
points.append(edge.p2());
@ -267,6 +263,7 @@ QVector<QPointF> VContour::CutEdge(const QLineF &edge) const
}
else
{
points.reserve(n);
const qreal nShift = edge.length()/n;
for (int i = 1; i <= n+1; ++i)
{
@ -302,30 +299,13 @@ const QPointF &VContour::at(int i) const
//---------------------------------------------------------------------------------------------------------------------
QRectF VContour::BoundingRect() const
{
QVector<QPointF> points = GetContour();
if (points.isEmpty())
{
return QRectF();
}
points.append(points.first());
return QPolygonF(points).boundingRect();
return d->m_boundingRect;
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VContour::ContourPath() const
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
const QVector<QPointF> points = GetContour();
path.moveTo(points.at(0));
for (qint32 i = 1; i < points.count(); ++i)
{
path.lineTo(points.at(i));
}
path.lineTo(points.at(0));
return path;
return d->m_contourPath;
}
//---------------------------------------------------------------------------------------------------------------------
@ -375,6 +355,55 @@ void VContour::InsertDetail(QVector<QPointF> &contour, const VLayoutPiece &detai
while (processedEdges <= nD);
}
//---------------------------------------------------------------------------------------------------------------------
void VContour::ResetAttributes()
{
if (not d->globalContour.isEmpty())
{
// Bounding rect
{
QVector<QPointF> points = d->globalContour;
if (points.isEmpty())
{
d->m_boundingRect = QRectF();
}
else
{
points.append(points.first());
d->m_boundingRect = QPolygonF(points).boundingRect();
}
}
{
// Countour path
QPainterPath path;
path.setFillRule(Qt::WindingFill);
const QVector<QPointF> points = d->globalContour;
path.moveTo(points.at(0));
for (qint32 i = 1; i < points.count(); ++i)
{
path.lineTo(points.at(i));
}
path.lineTo(points.at(0));
d->m_contourPath = path;
}
d->m_emptySheetEdgesCount = d->globalContour.count(); // Edges count
}
else
{
d->m_emptySheetEdgesCount = EmptySheetEdgesCount(); // Edges count
}
}
//---------------------------------------------------------------------------------------------------------------------
int VContour::EmptySheetEdgesCount() const
{
const qreal shift = qFuzzyIsNull(d->shift) ? ToPixel(0.5, Unit::Cm) : d->shift;
return qFloor(EmptySheetEdge().length()/shift);
}
//---------------------------------------------------------------------------------------------------------------------
bool VContour::IsPortrait() const
{

View File

@ -66,8 +66,8 @@ public:
void SetContour(const QVector<QPointF> &contour);
QVector<QPointF> GetContour() const;
quint32 GetShift() const;
void SetShift(quint32 shift);
qreal GetShift() const;
void SetShift(qreal shift);
int GetHeight() const;
void SetHeight(int height);
@ -98,6 +98,10 @@ private:
void AppendWhole(QVector<QPointF> &contour, const VLayoutPiece &detail, int detJ) const;
void InsertDetail(QVector<QPointF> &contour, const VLayoutPiece &detail, int detJ) const;
void ResetAttributes();
int EmptySheetEdgesCount() const;
};
Q_DECLARE_TYPEINFO(VContour, Q_MOVABLE_TYPE);

View File

@ -32,6 +32,8 @@
#include <QSharedData>
#include <QPointF>
#include <QVector>
#include <QRectF>
#include <QPainterPath>
#include "../vmisc/diagnostic.h"
@ -57,7 +59,10 @@ public:
paperHeight(contour.paperHeight),
paperWidth(contour.paperWidth),
shift(contour.shift),
layoutWidth(contour.layoutWidth)
layoutWidth(contour.layoutWidth),
m_boundingRect(contour.m_boundingRect),
m_contourPath(contour.m_contourPath),
m_emptySheetEdgesCount(contour.m_emptySheetEdgesCount)
{}
~VContourData() {}
@ -71,10 +76,15 @@ public:
/** @brief paperWidth width of paper in pixels*/
int paperWidth{0};
quint32 shift{0};
qreal shift{0};
qreal layoutWidth{0};
QRectF m_boundingRect{};
QPainterPath m_contourPath{};
int m_emptySheetEdgesCount{0};
private:
VContourData &operator=(const VContourData &) Q_DECL_EQ_DELETE;
};

View File

@ -40,7 +40,8 @@ enum class LayoutErrors : char
NoError,
PrepareLayoutError,
ProcessStoped,
EmptyPaperError
EmptyPaperError,
Timeout
};
enum class BestFrom : char

View File

@ -28,6 +28,7 @@
#include "vlayoutgenerator.h"
#include <QElapsedTimer>
#include <QGraphicsRectItem>
#include <QRectF>
#include <QThreadPool>
@ -56,7 +57,7 @@ VLayoutGenerator::VLayoutGenerator(QObject *parent)
shift(0),
rotate(true),
followGrainline(false),
rotationIncrease(180),
rotationNumber(2),
autoCrop(false),
saveLength(false),
unitePages(false),
@ -98,23 +99,25 @@ int VLayoutGenerator::DetailsCount()
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::Generate()
void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
{
stopGeneration.store(false);
papers.clear();
bank->Reset();
state = LayoutErrors::NoError;
#ifdef LAYOUT_DEBUG
const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug");
QDir debugDir(path);
debugDir.removeRecursively();
debugDir.mkpath(path);
#endif
emit Start();
if (bank->Prepare())
if (VFuzzyComparePossibleNulls(shift, -1))
{
if (bank->PrepareDetails())
{
SetShift(bank->DetailsBiggestEdge() + 1);
}
else
{
state = LayoutErrors::PrepareLayoutError;
return;
}
int width = PageWidth();
int height = PageHeight();
@ -133,20 +136,48 @@ void VLayoutGenerator::Generate()
IsPortrait() ? SetStrip(height) : SetStrip(width);
}
}
if (timer.hasExpired(timeout))
{
state = LayoutErrors::Timeout;
return;
}
#ifdef LAYOUT_DEBUG
const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug");
QDir debugDir(path);
debugDir.removeRecursively();
debugDir.mkpath(path);
#endif
if (bank->PrepareUnsorted())
{
if (timer.hasExpired(timeout))
{
state = LayoutErrors::Timeout;
return;
}
while (bank->AllDetailsCount() > 0)
{
if (stopGeneration.load())
{
break;
return;
}
VLayoutPaper paper(height, width, bank->GetLayoutWidth());
if (timer.hasExpired(timeout))
{
state = LayoutErrors::Timeout;
return;
}
VLayoutPaper paper(PageHeight(), PageWidth(), bank->GetLayoutWidth());
paper.SetShift(shift);
paper.SetPaperIndex(static_cast<quint32>(papers.count()));
paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline);
paper.SetRotationIncrease(rotationIncrease);
paper.SetRotationNumber(rotationNumber);
paper.SetSaveLength(saveLength);
do
{
@ -154,22 +185,35 @@ void VLayoutGenerator::Generate()
if (paper.ArrangeDetail(bank->GetDetail(index), stopGeneration))
{
bank->Arranged(index);
emit Arranged(bank->ArrangedCount());
}
else
{
bank->NotArranged(index);
}
QCoreApplication::processEvents();
if (stopGeneration.load())
{
break;
}
if (timer.hasExpired(timeout))
{
state = LayoutErrors::Timeout;
return;
}
} while(bank->LeftToArrange() > 0);
if (stopGeneration.load())
{
break;
return;
}
if (timer.hasExpired(timeout))
{
state = LayoutErrors::Timeout;
return;
}
if (paper.Count() > 0)
@ -179,7 +223,6 @@ void VLayoutGenerator::Generate()
else
{
state = LayoutErrors::EmptyPaperError;
emit Error(state);
return;
}
}
@ -187,7 +230,12 @@ void VLayoutGenerator::Generate()
else
{
state = LayoutErrors::PrepareLayoutError;
emit Error(state);
return;
}
if (timer.hasExpired(timeout))
{
state = LayoutErrors::Timeout;
return;
}
@ -200,8 +248,22 @@ void VLayoutGenerator::Generate()
{
UnitePages();
}
}
emit Finished();
//---------------------------------------------------------------------------------------------------------------------
qreal VLayoutGenerator::LayoutEfficiency() const
{
qreal efficiency = 0;
if (not papers.isEmpty())
{
for(auto &paper : papers)
{
efficiency += paper.Efficiency();
}
efficiency /= papers.size();
}
return efficiency;
}
//---------------------------------------------------------------------------------------------------------------------
@ -262,6 +324,14 @@ void VLayoutGenerator::Abort()
QThreadPool::globalInstance()->clear();
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::Timeout()
{
stopGeneration.store(true);
state = LayoutErrors::Timeout;
QThreadPool::globalInstance()->clear();
}
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::IsStripOptimization() const
{
@ -286,6 +356,19 @@ void VLayoutGenerator::SetTextAsPaths(bool value)
textAsPaths = value;
}
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::IsRotationNeeded() const
{
if (followGrainline)
{
return bank->IsRotationNeeded();
}
else
{
return true;
}
}
//---------------------------------------------------------------------------------------------------------------------
quint8 VLayoutGenerator::GetMultiplier() const
{
@ -395,7 +478,7 @@ void VLayoutGenerator::GatherPages()
paper.SetPaperIndex(static_cast<quint32>(i));
paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline);
paper.SetRotationIncrease(rotationIncrease);
paper.SetRotationNumber(rotationNumber);
paper.SetSaveLength(saveLength);
paper.SetDetails(nDetails.at(i));
@ -498,7 +581,7 @@ void VLayoutGenerator::UnitePages()
paper.SetPaperIndex(static_cast<quint32>(i));
paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline);
paper.SetRotationIncrease(rotationIncrease);
paper.SetRotationNumber(rotationNumber);
paper.SetSaveLength(saveLength);
paper.SetDetails(nDetails.at(i));
@ -591,19 +674,19 @@ void VLayoutGenerator::SetAutoCrop(bool value)
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
int VLayoutGenerator::GetRotationIncrease() const
int VLayoutGenerator::GetRotationNumber() const
{
return rotationIncrease;
return rotationNumber;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetRotationIncrease(int value)
void VLayoutGenerator::SetRotationNumber(int value)
{
rotationIncrease = value;
rotationNumber = value;
if (not (rotationIncrease >= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0))
if (rotationNumber > 360 || rotationNumber < 1)
{
rotationIncrease = 180;
rotationNumber = 2;
}
}
@ -643,6 +726,30 @@ void VLayoutGenerator::SetPaperWidth(qreal value)
paperWidth = value;
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::GetNestingTime() const
{
return nestingTime;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetNestingTime(int value)
{
nestingTime = value;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VLayoutGenerator::GetEfficiencyCoefficient() const
{
return efficiencyCoefficient;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetEfficiencyCoefficient(qreal coefficient)
{
efficiencyCoefficient = coefficient;
}
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::IsUsePrinterFields() const
{
@ -663,13 +770,13 @@ void VLayoutGenerator::SetPrinterFields(bool usePrinterFields, const QMarginsF &
}
//---------------------------------------------------------------------------------------------------------------------
quint32 VLayoutGenerator::GetShift() const
qreal VLayoutGenerator::GetShift() const
{
return shift;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetShift(quint32 shift)
void VLayoutGenerator::SetShift(qreal shift)
{
this->shift = shift;
}

View File

@ -52,6 +52,7 @@ class QMarginsF;
class QGraphicsItem;
class VLayoutPaper;
class QElapsedTimer;
class VLayoutGenerator :public QObject
{
@ -71,17 +72,27 @@ public:
qreal GetPaperWidth() const;
void SetPaperWidth(qreal value);
int GetNestingTime() const;
void SetNestingTime(int value);
qreal GetEfficiencyCoefficient() const;
void SetEfficiencyCoefficient(qreal coefficient);
bool IsUsePrinterFields() const;
QMarginsF GetPrinterFields() const;
void SetPrinterFields(bool usePrinterFields, const QMarginsF &value);
quint32 GetShift() const;
void SetShift(quint32 shift);
qreal GetShift() const;
void SetShift(qreal shift);
void Generate();
void Generate(QElapsedTimer timer, qint64 timeout);
qreal LayoutEfficiency() const;
LayoutErrors State() const;
int PapersCount() const {return papers.size();}
Q_REQUIRED_RESULT QList<QGraphicsItem *> GetPapersItems() const;
Q_REQUIRED_RESULT QList<QGraphicsItem *> GetGlobalContours() const;
Q_REQUIRED_RESULT QList<QList<QGraphicsItem *>> GetAllDetailsItems() const;
@ -94,8 +105,8 @@ public:
bool GetFollowGrainline() const;
void SetFollowGrainline(bool value);
int GetRotationIncrease() const;
void SetRotationIncrease(int value);
int GetRotationNumber() const;
void SetRotationNumber(int value);
bool GetAutoCrop() const;
void SetAutoCrop(bool value);
@ -115,14 +126,11 @@ public:
bool IsTestAsPaths() const;
void SetTextAsPaths(bool value);
signals:
void Start();
void Arranged(int count);
void Error(const LayoutErrors &state);
void Finished();
bool IsRotationNeeded() const;
public slots:
void Abort();
void Timeout();
private:
Q_DISABLE_COPY(VLayoutGenerator)
@ -134,10 +142,10 @@ private:
bool usePrinterFields;
std::atomic_bool stopGeneration;
LayoutErrors state;
quint32 shift;
qreal shift;
bool rotate;
bool followGrainline;
int rotationIncrease;
int rotationNumber;
bool autoCrop;
bool saveLength;
bool unitePages;
@ -145,6 +153,8 @@ private:
quint8 multiplier;
bool stripOptimization;
bool textAsPaths;
int nestingTime{1};
qreal efficiencyCoefficient{0.0};
int PageHeight() const;
int PageWidth() const;

View File

@ -119,13 +119,13 @@ void VLayoutPaper::SetLayoutWidth(qreal width)
}
//---------------------------------------------------------------------------------------------------------------------
quint32 VLayoutPaper::GetShift() const
qreal VLayoutPaper::GetShift() const
{
return d->globalContour.GetShift();
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPaper::SetShift(quint32 shift)
void VLayoutPaper::SetShift(qreal shift)
{
d->globalContour.SetShift(shift);
}
@ -156,24 +156,22 @@ void VLayoutPaper::SetFollowGrainline(bool value)
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutPaper::GetRotationIncrease() const
int VLayoutPaper::GetRotationNumber() const
{
return d->globalRotationIncrease;
return d->globalRotationNumber;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPaper::SetRotationIncrease(int value)
void VLayoutPaper::SetRotationNumber(int value)
{
d->globalRotationIncrease = value;
d->globalRotationNumber = value;
if (not (d->globalRotationIncrease >= 1
&& d->globalRotationIncrease <= 180
&& 360 % d->globalRotationIncrease == 0))
if (d->globalRotationNumber > 360 || d->globalRotationNumber < 1)
{
d->globalRotationIncrease = 180;
d->globalRotationNumber = 2;
}
d->localRotationIncrease = d->globalRotationIncrease;
d->localRotationNumber = d->globalRotationNumber;
}
//---------------------------------------------------------------------------------------------------------------------
@ -211,12 +209,12 @@ bool VLayoutPaper::ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &s
if ((detail.IsForceFlipping() || detail.IsForbidFlipping()) && not d->globalRotate)
{ // Compensate forbidden flipping by rotating. 180 degree will be enough.
d->localRotate = true;
d->localRotationIncrease = 180;
d->localRotationNumber = 2;
}
else
{ // Return to global values if was changed
d->localRotate = d->globalRotate;
d->localRotationIncrease = d->globalRotationIncrease;
d->localRotationNumber = d->globalRotationNumber;
}
d->frame = 0;
@ -242,6 +240,8 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop
for (int j=1; j <= d->globalContour.GlobalEdgesCount(); ++j)
{
QCoreApplication::processEvents();
for (int i=1; i<= detailEdgesCount; ++i)
{
VPositionData data;
@ -250,7 +250,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop
data.i = i;
data.j = j;
data.rotate = d->localRotate;
data.rotationIncrease = d->localRotationIncrease;
data.rotationNumber = d->localRotationNumber;
data.followGrainline = d->followGrainline;
auto *thread = new VPosition(data, &stop, d->saveLength);
@ -426,3 +426,17 @@ QRectF VLayoutPaper::DetailsBoundingRect() const
return rec;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VLayoutPaper::Efficiency() const
{
qreal efficiency = 0;
for(auto &detail : d->details)
{
efficiency += static_cast<qreal>(detail.Square());
}
const QRectF boundingRect = DetailsBoundingRect();
return efficiency / (boundingRect.width() * boundingRect.height()) * 100.0;
}

View File

@ -73,8 +73,8 @@ public:
qreal GetLayoutWidth() const;
void SetLayoutWidth(qreal width);
quint32 GetShift() const;
void SetShift(quint32 shift);
qreal GetShift() const;
void SetShift(qreal shift);
bool GetRotate() const;
void SetRotate(bool value);
@ -82,8 +82,8 @@ public:
bool GetFollowGrainline() const;
void SetFollowGrainline(bool value);
int GetRotationIncrease() const;
void SetRotationIncrease(int value);
int GetRotationNumber() const;
void SetRotationNumber(int value);
bool IsSaveLength() const;
void SetSaveLength(bool value);
@ -101,6 +101,8 @@ public:
QRectF DetailsBoundingRect() const;
qreal Efficiency() const;
private:
QSharedDataPointer<VLayoutPaperData> d;

View File

@ -60,8 +60,8 @@ public:
layoutWidth(paper.layoutWidth),
globalRotate(paper.globalRotate),
localRotate(paper.localRotate),
globalRotationIncrease(paper.globalRotationIncrease),
localRotationIncrease(paper.localRotationIncrease),
globalRotationNumber(paper.globalRotationNumber),
localRotationNumber(paper.localRotationNumber),
saveLength(paper.saveLength),
followGrainline(paper.followGrainline)
{}
@ -79,8 +79,8 @@ public:
qreal layoutWidth{0};
bool globalRotate{true};
bool localRotate{true};
int globalRotationIncrease{180};
int localRotationIncrease{180};
int globalRotationNumber{2};
int localRotationNumber{2};
bool saveLength{false};
bool followGrainline{false};

View File

@ -314,45 +314,36 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern
//---------------------------------------------------------------------------------------------------------------------
template <class T>
QVector<T> VLayoutPiece::Map(const QVector<T> &points) const
QVector<T> VLayoutPiece::Map(QVector<T> points) const
{
QVector<T> p;
for (auto point : points)
for (int i = 0; i < points.size(); ++i)
{
p.append(d->matrix.map(point));
points[i] = d->matrix.map(points.at(i));
}
if (d->mirror)
{
QList<T> list = p.toList();
QList<T> list = points.toList();
for (int k=0, s=list.size(), max=(s/2); k<max; k++)
{
list.swap(k, s-(1+k));
}
p = list.toVector();
points = list.toVector();
}
return p;
return points;
}
//---------------------------------------------------------------------------------------------------------------------
template <>
QVector<VLayoutPlaceLabel> VLayoutPiece::Map<VLayoutPlaceLabel>(const QVector<VLayoutPlaceLabel> &points) const
QVector<VLayoutPlaceLabel> VLayoutPiece::Map<VLayoutPlaceLabel>(QVector<VLayoutPlaceLabel> points) const
{
QVector<VLayoutPlaceLabel> p;
p.reserve(points.size());
for (auto &label : points)
for (int i = 0; i < points.size(); ++i)
{
VLayoutPlaceLabel mappedLabel;
mappedLabel.type = label.type;
mappedLabel.center = d->matrix.map(label.center);
for (const auto &p : label.shape)
{
mappedLabel.shape.append(d->matrix.map(p));
}
p.append(mappedLabel);
points[i].center = d->matrix.map(points.at(i).center);
points[i].shape = Map(points.at(i).shape);
}
return p;
return points;
}
//---------------------------------------------------------------------------------------------------------------------
@ -742,15 +733,7 @@ bool VLayoutPiece::isNull() const
//---------------------------------------------------------------------------------------------------------------------
qint64 VLayoutPiece::Square() const
{
if (d->layoutAllowance.isEmpty()) //-V807
{
return 0;
}
const qreal res = SumTrapezoids(d->layoutAllowance);
const qint64 sq = qFloor(qAbs(res/2.0));
return sq;
return d->m_square;
}
//---------------------------------------------------------------------------------------------------------------------
@ -779,6 +762,13 @@ void VLayoutPiece::SetLayoutAllowancePoints()
{
d->layoutAllowance.clear();
}
if (d->layoutAllowance.isEmpty()) //-V807
{
d->m_square = 0;
}
d->m_square = qFloor(qAbs(SumTrapezoids(d->layoutAllowance)/2.0));
}
//---------------------------------------------------------------------------------------------------------------------
@ -945,6 +935,28 @@ bool VLayoutPiece::IsLayoutAllowanceValid() const
return VAbstractPiece::IsAllowanceValid(base, d->layoutAllowance);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VLayoutPiece::BiggestEdge() const
{
qreal edge = 0;
if (d->layoutAllowance.size() < 2)
{
return edge;
}
for (int i = 1; i < d->layoutAllowance.size() - 1; ++i)
{
const qreal length = QLineF(d->layoutAllowance.at(i-1), d->layoutAllowance.at(i)).length();
if (length > edge)
{
edge = length;
}
}
return edge;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPointF> &labelShape,
const VTextManager &tm, bool textAsPaths) const

View File

@ -144,6 +144,8 @@ public:
bool IsLayoutAllowanceValid() const;
qreal BiggestEdge() const;
private:
QSharedDataPointer<VLayoutPieceData> d;
@ -157,7 +159,7 @@ private:
void CreateGrainlineItem(QGraphicsItem *parent) const;
template <class T>
QVector<T> Map(const QVector<T> &points) const;
QVector<T> Map(QVector<T> points) const;
QLineF Edge(const QVector<QPointF> &path, int i) const;
int EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1) const;

View File

@ -87,7 +87,8 @@ public:
grainlineEnabled(detail.grainlineEnabled),
m_tmDetail(detail.m_tmDetail),
m_tmPattern(detail.m_tmPattern),
m_placeLabels(detail.m_placeLabels)
m_placeLabels(detail.m_placeLabels),
m_square(detail.m_square)
{}
~VLayoutPieceData() {}
@ -137,6 +138,8 @@ public:
/** @brief m_placeLabels list of place labels. */
QVector<VLayoutPlaceLabel> m_placeLabels;
qint64 m_square{0};
private:
VLayoutPieceData &operator=(const VLayoutPieceData &) Q_DECL_EQ_DELETE;
};

View File

@ -147,9 +147,9 @@ VPosition::VPosition(const VPositionData &data, std::atomic_bool *stop, bool sav
stop(stop),
angle_between(0)
{
if (not (m_data.rotationIncrease >= 1 && m_data.rotationIncrease <= 180 && 360 % m_data.rotationIncrease == 0))
if (m_data.rotationNumber > 360 || m_data.rotationNumber < 1)
{
m_data.rotationIncrease = 180;
m_data.rotationNumber = 2;
}
}
@ -493,7 +493,7 @@ VPosition::CrossingType VPosition::Crossing(const VLayoutPiece &detail) const
const QPainterPath gPath = m_data.gContour.ContourPath();
CrossingType crossing = CrossingType::EdgeError;
if (not gPath.intersects(detail.LayoutAllowancePath()) && not gPath.contains(detail.ContourPath()))
if (not gPath.contains(detail.ContourPath()) && not gPath.intersects(detail.LayoutAllowancePath()))
{
crossing = CrossingType::NoIntersection;
}
@ -566,14 +566,15 @@ void VPosition::RotateEdges(VLayoutPiece &detail, const QLineF &globalEdge, int
}
//---------------------------------------------------------------------------------------------------------------------
void VPosition::Rotate(int increase)
void VPosition::Rotate(int number)
{
int startAngle = 0;
const qreal step = 360/number;
qreal startAngle = 0;
if (VFuzzyComparePossibleNulls(angle_between, 360))
{
startAngle = increase;
startAngle = step;
}
for (int angle = startAngle; angle < 360; angle = angle+increase)
for (qreal angle = startAngle; angle < 360; angle = angle+step)
{
if (stop->load())
{
@ -642,14 +643,7 @@ void VPosition::FindBestPosition()
if (m_data.rotate)
{
Rotate(m_data.rotationIncrease);
}
else
{
if (m_data.gContour.GetContour().isEmpty())
{
Rotate(m_data.rotationIncrease);
}
Rotate(m_data.rotationNumber);
}
}
else

View File

@ -47,7 +47,7 @@ struct VPositionData
int i{-1};
int j{-1};
bool rotate{false};
int rotationIncrease{0};
int rotationNumber{0};
bool followGrainline{false};
};
@ -124,7 +124,7 @@ private:
void CombineEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge);
void RotateEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge, qreal angle) const;
void Rotate(int increase);
void Rotate(int number);
void FollowGrainline();
QLineF FabricGrainline() const;

View File

@ -54,9 +54,6 @@ const QString LONG_OPTION_TEXT2PATHS = QStringLiteral("text2paths");
const QString LONG_OPTION_EXPORTONLYDETAILS = QStringLiteral("exportOnlyDetails");
const QString LONG_OPTION_EXPORTSUCHDETAILS = QStringLiteral("exportSuchDetails");
const QString LONG_OPTION_ROTATE = QStringLiteral("rotate");
const QString SINGLE_OPTION_ROTATE = QStringLiteral("r");
const QString LONG_OPTION_CROP = QStringLiteral("crop");
const QString SINGLE_OPTION_CROP = QStringLiteral("c");
@ -75,9 +72,6 @@ const QString SINGLE_OPTION_PAGEUNITS = QStringLiteral("U");
const QString LONG_OPTION_SAVELENGTH = QStringLiteral("savelen");
const QString SINGLE_OPTION_SAVELENGTH = QStringLiteral("S");
const QString LONG_OPTION_SHIFTLENGTH = QStringLiteral("shiftlen");
const QString SINGLE_OPTION_SHIFTLENGTH = QStringLiteral("s");
const QString LONG_OPTION_SHIFTUNITS = QStringLiteral("layounits");
const QString SINGLE_OPTION_SHIFTUNITS = QStringLiteral("l");
@ -115,6 +109,11 @@ const QString SINGLE_OPTION_TOP_MARGIN = QStringLiteral("T");
const QString LONG_OPTION_BOTTOM_MARGIN = QStringLiteral("bmargin");
const QString SINGLE_OPTION_BOTTOM_MARGIN = QStringLiteral("B");
const QString LONG_OPTION_NESTING_TIME = QStringLiteral("time");
const QString SINGLE_OPTION_NESTING_TIME = QStringLiteral("n");
const QString LONG_OPTION_EFFICIENCY_COEFFICIENT = QStringLiteral("сoefficient");
const QString LONG_OPTION_CSVWITHHEADER = QStringLiteral("csvWithHeader");
const QString LONG_OPTION_CSVCODEC = QStringLiteral("csvCodec");
const QString LONG_OPTION_CSVSEPARATOR = QStringLiteral("csvSeparator");
@ -138,50 +137,50 @@ const QString LONG_OPTION_LANDSCAPE_ORIENTATION = QStringLiteral("landscapeOrien
*/
QStringList AllKeys()
{
QStringList list;
list << LONG_OPTION_BASENAME << SINGLE_OPTION_BASENAME
<< LONG_OPTION_DESTINATION << SINGLE_OPTION_DESTINATION
<< LONG_OPTION_MEASUREFILE << SINGLE_OPTION_MEASUREFILE
<< LONG_OPTION_PAGETEMPLATE << SINGLE_OPTION_PAGETEMPLATE
<< LONG_OPTION_EXP2FORMAT << SINGLE_OPTION_EXP2FORMAT
<< LONG_OPTION_BINARYDXF
<< LONG_OPTION_TEXT2PATHS
<< LONG_OPTION_EXPORTONLYDETAILS
<< LONG_OPTION_EXPORTSUCHDETAILS
<< LONG_OPTION_ROTATE << SINGLE_OPTION_ROTATE
<< LONG_OPTION_CROP << SINGLE_OPTION_CROP
<< LONG_OPTION_UNITE << SINGLE_OPTION_UNITE
<< LONG_OPTION_PAGEW << SINGLE_OPTION_PAGEW
<< LONG_OPTION_PAGEH << SINGLE_OPTION_PAGEH
<< LONG_OPTION_PAGEUNITS << SINGLE_OPTION_PAGEUNITS
<< LONG_OPTION_SAVELENGTH << SINGLE_OPTION_SAVELENGTH
<< LONG_OPTION_SHIFTLENGTH << SINGLE_OPTION_SHIFTLENGTH
<< LONG_OPTION_SHIFTUNITS << SINGLE_OPTION_SHIFTUNITS
<< LONG_OPTION_GAPWIDTH << SINGLE_OPTION_GAPWIDTH
<< LONG_OPTION_GROUPPING << SINGLE_OPTION_GROUPPING
<< LONG_OPTION_TEST << SINGLE_OPTION_TEST
<< LONG_OPTION_PENDANTIC
<< LONG_OPTION_GRADATIONSIZE << SINGLE_OPTION_GRADATIONSIZE
<< LONG_OPTION_GRADATIONHEIGHT << SINGLE_OPTION_GRADATIONHEIGHT
<< LONG_OPTION_USER_MATERIAL
<< LONG_OPTION_IGNORE_MARGINS << SINGLE_OPTION_IGNORE_MARGINS
<< LONG_OPTION_LEFT_MARGIN << SINGLE_OPTION_LEFT_MARGIN
<< LONG_OPTION_RIGHT_MARGIN << SINGLE_OPTION_RIGHT_MARGIN
<< LONG_OPTION_TOP_MARGIN << SINGLE_OPTION_TOP_MARGIN
<< LONG_OPTION_BOTTOM_MARGIN << SINGLE_OPTION_BOTTOM_MARGIN
<< LONG_OPTION_NO_HDPI_SCALING
<< LONG_OPTION_CSVWITHHEADER
<< LONG_OPTION_CSVCODEC
<< LONG_OPTION_CSVSEPARATOR
<< LONG_OPTION_CSVEXPORTFM
<< LONG_OPTION_TILED_PDF_PAGE_TEMPLATE
<< LONG_OPTION_TILED_PDF_LEFT_MARGIN
<< LONG_OPTION_TILED_PDF_RIGHT_MARGIN
<< LONG_OPTION_TILED_PDF_TOP_MARGIN
<< LONG_OPTION_TILED_PDF_BOTTOM_MARGIN
<< LONG_OPTION_TILED_PDF_LANDSCAPE
<< LONG_OPTION_FOLLOW_GRAINLINE
<< LONG_OPTION_LANDSCAPE_ORIENTATION;
return list;
return QStringList
{
LONG_OPTION_BASENAME, SINGLE_OPTION_BASENAME,
LONG_OPTION_DESTINATION, SINGLE_OPTION_DESTINATION,
LONG_OPTION_MEASUREFILE, SINGLE_OPTION_MEASUREFILE,
LONG_OPTION_PAGETEMPLATE, SINGLE_OPTION_PAGETEMPLATE,
LONG_OPTION_EXP2FORMAT, SINGLE_OPTION_EXP2FORMAT,
LONG_OPTION_BINARYDXF,
LONG_OPTION_TEXT2PATHS,
LONG_OPTION_EXPORTONLYDETAILS,
LONG_OPTION_EXPORTSUCHDETAILS,
LONG_OPTION_CROP, SINGLE_OPTION_CROP,
LONG_OPTION_UNITE, SINGLE_OPTION_UNITE,
LONG_OPTION_PAGEW, SINGLE_OPTION_PAGEW,
LONG_OPTION_PAGEH, SINGLE_OPTION_PAGEH,
LONG_OPTION_PAGEUNITS, SINGLE_OPTION_PAGEUNITS,
LONG_OPTION_SAVELENGTH, SINGLE_OPTION_SAVELENGTH,
LONG_OPTION_SHIFTUNITS, SINGLE_OPTION_SHIFTUNITS,
LONG_OPTION_GAPWIDTH, SINGLE_OPTION_GAPWIDTH,
LONG_OPTION_GROUPPING, SINGLE_OPTION_GROUPPING,
LONG_OPTION_TEST, SINGLE_OPTION_TEST,
LONG_OPTION_PENDANTIC,
LONG_OPTION_GRADATIONSIZE, SINGLE_OPTION_GRADATIONSIZE,
LONG_OPTION_GRADATIONHEIGHT, SINGLE_OPTION_GRADATIONHEIGHT,
LONG_OPTION_USER_MATERIAL,
LONG_OPTION_IGNORE_MARGINS, SINGLE_OPTION_IGNORE_MARGINS,
LONG_OPTION_LEFT_MARGIN, SINGLE_OPTION_LEFT_MARGIN,
LONG_OPTION_RIGHT_MARGIN, SINGLE_OPTION_RIGHT_MARGIN,
LONG_OPTION_TOP_MARGIN, SINGLE_OPTION_TOP_MARGIN,
LONG_OPTION_BOTTOM_MARGIN, SINGLE_OPTION_BOTTOM_MARGIN,
LONG_OPTION_NESTING_TIME, SINGLE_OPTION_NESTING_TIME,
LONG_OPTION_EFFICIENCY_COEFFICIENT,
LONG_OPTION_NO_HDPI_SCALING,
LONG_OPTION_CSVWITHHEADER,
LONG_OPTION_CSVCODEC,
LONG_OPTION_CSVSEPARATOR,
LONG_OPTION_CSVEXPORTFM,
LONG_OPTION_TILED_PDF_PAGE_TEMPLATE,
LONG_OPTION_TILED_PDF_LEFT_MARGIN,
LONG_OPTION_TILED_PDF_RIGHT_MARGIN,
LONG_OPTION_TILED_PDF_TOP_MARGIN,
LONG_OPTION_TILED_PDF_BOTTOM_MARGIN,
LONG_OPTION_TILED_PDF_LANDSCAPE,
LONG_OPTION_FOLLOW_GRAINLINE,
LONG_OPTION_LANDSCAPE_ORIENTATION
};
}

View File

@ -51,9 +51,6 @@ extern const QString LONG_OPTION_TEXT2PATHS;
extern const QString LONG_OPTION_EXPORTONLYDETAILS;
extern const QString LONG_OPTION_EXPORTSUCHDETAILS;
extern const QString LONG_OPTION_ROTATE;
extern const QString SINGLE_OPTION_ROTATE;
extern const QString LONG_OPTION_CROP;
extern const QString SINGLE_OPTION_CROP;
@ -72,9 +69,6 @@ extern const QString SINGLE_OPTION_PAGEUNITS;
extern const QString LONG_OPTION_SAVELENGTH;
extern const QString SINGLE_OPTION_SAVELENGTH;
extern const QString LONG_OPTION_SHIFTLENGTH;
extern const QString SINGLE_OPTION_SHIFTLENGTH;
extern const QString LONG_OPTION_SHIFTUNITS;
extern const QString SINGLE_OPTION_SHIFTUNITS;
@ -112,6 +106,11 @@ extern const QString SINGLE_OPTION_TOP_MARGIN;
extern const QString LONG_OPTION_BOTTOM_MARGIN;
extern const QString SINGLE_OPTION_BOTTOM_MARGIN;
extern const QString LONG_OPTION_NESTING_TIME;
extern const QString SINGLE_OPTION_NESTING_TIME;
extern const QString LONG_OPTION_EFFICIENCY_COEFFICIENT;
extern const QString LONG_OPTION_CSVWITHHEADER;
extern const QString LONG_OPTION_CSVCODEC;
extern const QString LONG_OPTION_CSVSEPARATOR;

View File

@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
**
** @file vsettings.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
@ -82,10 +82,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutWidth, (QLatin1String("lay
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSorting, (QLatin1String("layout/sorting")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPaperHeight, (QLatin1String("layout/paperHeight")))
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, 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, settingLayoutAutoCrop, (QLatin1String("layout/autoCrop")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSaveLength, (QLatin1String("layout/saveLength")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutUnitePages, (QLatin1String("layout/unitePages")))
@ -94,6 +91,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingIgnoreFields, (QLatin1String("la
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingStripOptimization, (QLatin1String("layout/stripOptimization")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingMultiplier, (QLatin1String("layout/multiplier")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTextAsPaths, (QLatin1String("layout/textAsPaths")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingNestingTime, (QLatin1String("layout/time")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingEfficiencyCoefficient, (QLatin1String("layout/efficiencyCoefficient")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperHeight, (QLatin1String("tiledPDF/paperHeight")))
@ -182,17 +181,7 @@ void VSettings::SetOpenGLRender(bool value)
//---------------------------------------------------------------------------------------------------------------------
qreal VSettings::GetLayoutPaperHeight() const
{
const qreal def = UnitConvertor(1189/*A0*/, Unit::Mm, Unit::Px);
bool ok = false;
const qreal height = value(*settingLayoutPaperHeight, def).toDouble(&ok);
if (ok)
{
return height;
}
else
{
return def;
}
return ValueOrDef<qreal>(*settingLayoutPaperHeight, UnitConvertor(1189/*A0*/, Unit::Mm, Unit::Px));
}
//---------------------------------------------------------------------------------------------------------------------
@ -204,17 +193,7 @@ void VSettings::SetLayoutPaperHeight(qreal value)
//---------------------------------------------------------------------------------------------------------------------
qreal VSettings::GetLayoutPaperWidth() const
{
const qreal def = UnitConvertor(841/*A0*/, Unit::Mm, Unit::Px);
bool ok = false;
const qreal width = value(*settingLayoutPaperWidth, def).toDouble(&ok);
if (ok)
{
return width;
}
else
{
return def;
}
return ValueOrDef<qreal>(*settingLayoutPaperWidth, UnitConvertor(841/*A0*/, Unit::Mm, Unit::Px));
}
//---------------------------------------------------------------------------------------------------------------------
@ -223,48 +202,10 @@ void VSettings::SetLayoutPaperWidth(qreal value)
setValue(*settingLayoutPaperWidth, value);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VSettings::GetLayoutShift() const
{
const qreal def = GetDefLayoutShift();
bool ok = false;
const qreal shift = value(*settingLayoutShift, def).toDouble(&ok);
if (ok)
{
return shift;
}
else
{
return def;
}
}
//---------------------------------------------------------------------------------------------------------------------
qreal VSettings::GetDefLayoutShift()
{
return 0;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetLayoutShift(qreal value)
{
setValue(*settingLayoutShift, value);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VSettings::GetLayoutWidth() const
{
const qreal def = GetDefLayoutWidth();
bool ok = false;
const qreal lWidth = value(*settingLayoutWidth, def).toDouble(&ok);
if (ok)
{
return lWidth;
}
else
{
return def;
}
return ValueOrDef<qreal>(*settingLayoutWidth, GetDefLayoutWidth());
}
//---------------------------------------------------------------------------------------------------------------------
@ -279,15 +220,34 @@ void VSettings::SetLayoutWidth(qreal value)
setValue(*settingLayoutWidth, value);
}
//---------------------------------------------------------------------------------------------------------------------
int VSettings::GetNestingTime() const
{
return ValueOrDef<int>(*settingNestingTime, GetDefNestingTime());
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetNestingTime(int value)
{
setValue(*settingNestingTime, value);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VSettings::GetEfficiencyCoefficient() const
{
return ValueOrDef<qreal>(*settingEfficiencyCoefficient, GetDefEfficiencyCoefficient());
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetEfficiencyCoefficient(qreal value)
{
setValue(*settingEfficiencyCoefficient, value);
}
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VSettings::GetFields(const QMarginsF &def) const
{
const QVariant val = value(*settingFields, QVariant::fromValue(def));
if (val.canConvert<QMarginsF>())
{
return val.value<QMarginsF>();
}
return def;
return ValueOrDef<QMarginsF>(*settingFields, def);
}
//---------------------------------------------------------------------------------------------------------------------
@ -299,24 +259,7 @@ void VSettings::SetFields(const QMarginsF &value)
//---------------------------------------------------------------------------------------------------------------------
Cases VSettings::GetLayoutGroup() const
{
const Cases def = GetDefLayoutGroup();
bool ok = false;
const int g = value(*settingLayoutSorting, static_cast<int>(def)).toInt(&ok);
if (ok)
{
if (g >= static_cast<int>(Cases::UnknownCase))
{
return def;
}
else
{
return static_cast<Cases>(g);
}
}
else
{
return def;
}
return ValueOrDef<Cases>(*settingLayoutSorting, GetDefLayoutGroup());
}
//---------------------------------------------------------------------------------------------------------------------
@ -331,24 +274,6 @@ void VSettings::SetLayoutGroup(const Cases &value)
setValue(*settingLayoutSorting, static_cast<int>(value));
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutRotate() const
{
return value(*settingLayoutRotate, GetDefLayoutRotate()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefLayoutRotate()
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetLayoutRotate(bool value)
{
setValue(*settingLayoutRotate, value);
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutFollowGrainline() const
{
@ -367,41 +292,6 @@ void VSettings::SetLayoutFollowGrainline(bool value)
setValue(*settingLayoutFollowGrainline, value);
}
//---------------------------------------------------------------------------------------------------------------------
int VSettings::GetLayoutRotationIncrease() const
{
const int def = GetDefLayoutRotationIncrease();
bool ok = false;
const int r = value(*settingLayoutRotationIncrease, def).toInt(&ok);
if (ok)
{
if (not (r >= 1 && r <= 180 && 360 % r == 0))
{
return def;
}
else
{
return r;
}
}
else
{
return def;
}
}
//---------------------------------------------------------------------------------------------------------------------
int VSettings::GetDefLayoutRotationIncrease()
{
return 180;/*degree*/
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetLayoutRotationIncrease(int value)
{
setValue(*settingLayoutRotationIncrease, value);
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutAutoCrop() const
{
@ -564,15 +454,7 @@ void VSettings::SetRememberPatternMaterials(bool value)
QMarginsF VSettings::GetTiledPDFMargins(const Unit &unit) const
{
// default value is 10mm. We save the margins in mm in the setting.
const QMarginsF def = QMarginsF(10, 10, 10, 10);
const QVariant val = value(*settingTiledPDFMargins, QVariant::fromValue(def));
if (val.canConvert<QMarginsF>())
{
return UnitConvertor(val.value<QMarginsF>(), Unit::Mm, unit);
}
return UnitConvertor(def, Unit::Mm, unit);
return UnitConvertor(ValueOrDef<QMarginsF>(*settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, unit);
}
//---------------------------------------------------------------------------------------------------------------------
@ -596,17 +478,7 @@ void VSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit)
*/
qreal VSettings::GetTiledPDFPaperHeight(const Unit &unit) const
{
const qreal def = 297 /*A4*/;
bool ok = false;
const qreal height = value(*settingTiledPDFPaperHeight, def).toDouble(&ok);
if (ok)
{
return UnitConvertor(height, Unit::Mm, unit);
}
else
{
return UnitConvertor(def, Unit::Mm, unit);
}
return UnitConvertor(ValueOrDef<qreal>(*settingTiledPDFPaperHeight, 297 /*A4*/), Unit::Mm, unit);
}
//---------------------------------------------------------------------------------------------------------------------
@ -629,18 +501,7 @@ void VSettings::SetTiledPDFPaperHeight(qreal value, const Unit &unit)
*/
qreal VSettings::GetTiledPDFPaperWidth(const Unit &unit) const
{
const qreal def = 210 /*A4*/;
bool ok = false;
const qreal width = value(*settingTiledPDFPaperWidth, def).toDouble(&ok);
if (ok)
{
return UnitConvertor(width, Unit::Mm, unit);
}
else
{
return UnitConvertor(def, Unit::Mm, unit);
}
return UnitConvertor(ValueOrDef<qreal>(*settingTiledPDFPaperWidth, 210 /*A4*/), Unit::Mm, unit);
}
//---------------------------------------------------------------------------------------------------------------------
@ -744,8 +605,7 @@ T VSettings::GetCachedValue(T &cache, const QString &setting, T defValue, T valu
{
if (cache < 0)
{
const QVariant val = value(setting, defValue);
cache = val.canConvert<T>() ? qBound(valueMin, val.value<T>(), valueMax) : defValue;
cache = qBound(valueMin, ValueOrDef(setting, defValue), valueMax);
}
return cache;

View File

@ -74,14 +74,18 @@ public:
qreal GetLayoutPaperWidth() const;
void SetLayoutPaperWidth(qreal value);
qreal GetLayoutShift() const;
static qreal GetDefLayoutShift();
void SetLayoutShift(qreal value);
qreal GetLayoutWidth() const;
static qreal GetDefLayoutWidth();
void SetLayoutWidth(qreal value);
int GetNestingTime() const;
static int GetDefNestingTime(){return 1;}
void SetNestingTime(int value);
qreal GetEfficiencyCoefficient() const;
static qreal GetDefEfficiencyCoefficient(){return 0.0;}
void SetEfficiencyCoefficient(qreal value);
QMarginsF GetFields(const QMarginsF &def = QMarginsF()) const;
void SetFields(const QMarginsF &value);
@ -89,18 +93,10 @@ public:
static Cases GetDefLayoutGroup();
void SetLayoutGroup(const Cases &value);
bool GetLayoutRotate() const;
static bool GetDefLayoutRotate();
void SetLayoutRotate(bool value);
bool GetLayoutFollowGrainline() const;
static bool GetDefLayoutFollowGrainline();
void SetLayoutFollowGrainline(bool value);
int GetLayoutRotationIncrease() const;
static int GetDefLayoutRotationIncrease();
void SetLayoutRotationIncrease(int value);
bool GetLayoutAutoCrop() const;
static bool GetDefLayoutAutoCrop();
void SetLayoutAutoCrop(bool value);
@ -183,6 +179,33 @@ private:
template <typename T>
T GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const;
template <class T>
T ValueOrDef(const QString &setting, const T &defValue) const;
};
//---------------------------------------------------------------------------------------------------------------------
template <class T>
inline T VSettings::ValueOrDef(const QString &setting, const T &defValue) const
{
const QVariant val = value(setting, QVariant::fromValue(defValue));
return val.canConvert<T>() ? val.value<T>() : defValue;
}
//---------------------------------------------------------------------------------------------------------------------
template <>
inline Cases VSettings::ValueOrDef<Cases>(const QString &setting, const Cases &defValue) const
{
const QVariant val = value(setting, QVariant::fromValue(static_cast<int>(defValue)));
const int g = val.canConvert<int>() ? val.value<int>() : static_cast<int>(defValue);
if (g < static_cast<int>(Cases::CaseThreeGroup) || g >= static_cast<int>(Cases::UnknownCase))
{
return defValue;
}
else
{
return static_cast<Cases>(g);
}
}
#endif // VSETTINGS_H