From 49828889e21e201c4e8ba062b36696b8c03b9a18 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 22 Mar 2020 16:22:03 +0200 Subject: [PATCH] New layout generator option: Prefer one sheet solution. --- ChangeLog.txt | 1 + dist/OBS_debian/debian.valentina.1 | 8 +++++--- dist/debian/valentina.1 | 8 +++++--- src/app/valentina/core/vcmdexport.cpp | 3 +++ .../dialogs/dialoglayoutsettings.cpp | 16 +++++++++++++++ .../valentina/dialogs/dialoglayoutsettings.h | 3 +++ .../valentina/dialogs/dialoglayoutsettings.ui | 12 ++++++++++- src/app/valentina/mainwindowsnogui.cpp | 8 ++++++-- src/libs/vlayout/vlayoutgenerator.cpp | 12 +++++++++++ src/libs/vlayout/vlayoutgenerator.h | 4 ++++ src/libs/vmisc/commandoptions.cpp | 4 +++- src/libs/vmisc/commandoptions.h | 1 + src/libs/vmisc/vsettings.cpp | 20 +++++++++++++++++++ src/libs/vmisc/vsettings.h | 4 ++++ 14 files changed, 94 insertions(+), 10 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 5eedaf2d4..193cfe0d0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -45,6 +45,7 @@ - Export pattern to DXF-ASTM. - [smart-pattern/valentina#18] Auto-created Visibility Group for group operation. - Setting scale factor for export and print. +- New layout generator option: Prefer one sheet solution. # Version 0.6.2 (unreleased) - [#903] Bug in tool Cut Spline path. diff --git a/dist/OBS_debian/debian.valentina.1 b/dist/OBS_debian/debian.valentina.1 index 5e9da11b5..48c841dd1 100644 --- a/dist/OBS_debian/debian.valentina.1 +++ b/dist/OBS_debian/debian.valentina.1 @@ -1,6 +1,6 @@ .\" Manpage for valentina. .\" Contact dismine@gmail.com to correct errors. -.TH valentina 1 "21 March, 2020" "valentina man page" +.TH valentina 1 "22 March, 2020" "valentina man page" .SH NAME Valentina \- Pattern making program. .SH SYNOPSIS @@ -218,9 +218,9 @@ The path to output destination folder. By default the directory at which the app .IP "--yscale " .RB "Set vertical scale factor from 0.01 to 3.0 (default = 1.0, " "export mode" ")." .IP "--followGrainline" -.RB "Order detail to follow grainline direction (" "export mode" "). +.RB "Order detail to follow grainline direction (" "export mode" ")." .IP "--manualPriority" -.RB "Follow manual priority over priority by square (" "export mode" "). +.RB "Follow manual priority over priority by square (" "export mode" ")." .IP "--nestQuantity" .RB "Nest quantity copies of each piece (" "export mode" "). .IP "-c, --crop" @@ -229,6 +229,8 @@ The path to output destination folder. By default the directory at which the app .RB "Auto crop unused width (" "export mode" ")." .IP "-u, --unite" .RB "Unite pages if possible (" "export mode" "). Maximum value limited by QImage that supports only a maximum of " "32768x32768 px" " images." +.IP "--preferOneSheetSolution" +.RB "Prefer one sheet layout solution (" "export mode" ")." .IP "-S, --savelen" .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 " diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index 5e9da11b5..48c841dd1 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -1,6 +1,6 @@ .\" Manpage for valentina. .\" Contact dismine@gmail.com to correct errors. -.TH valentina 1 "21 March, 2020" "valentina man page" +.TH valentina 1 "22 March, 2020" "valentina man page" .SH NAME Valentina \- Pattern making program. .SH SYNOPSIS @@ -218,9 +218,9 @@ The path to output destination folder. By default the directory at which the app .IP "--yscale " .RB "Set vertical scale factor from 0.01 to 3.0 (default = 1.0, " "export mode" ")." .IP "--followGrainline" -.RB "Order detail to follow grainline direction (" "export mode" "). +.RB "Order detail to follow grainline direction (" "export mode" ")." .IP "--manualPriority" -.RB "Follow manual priority over priority by square (" "export mode" "). +.RB "Follow manual priority over priority by square (" "export mode" ")." .IP "--nestQuantity" .RB "Nest quantity copies of each piece (" "export mode" "). .IP "-c, --crop" @@ -229,6 +229,8 @@ The path to output destination folder. By default the directory at which the app .RB "Auto crop unused width (" "export mode" ")." .IP "-u, --unite" .RB "Unite pages if possible (" "export mode" "). Maximum value limited by QImage that supports only a maximum of " "32768x32768 px" " images." +.IP "--preferOneSheetSolution" +.RB "Prefer one sheet layout solution (" "export mode" ")." .IP "-S, --savelen" .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 " diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 84a6956b0..e608db6c7 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -204,6 +204,7 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const diag.SetAutoCropWidth(IsOptionSet(LONG_OPTION_CROP_WIDTH)); diag.SetUnitePages(IsOptionSet(LONG_OPTION_UNITE)); diag.SetSaveLength(IsOptionSet(LONG_OPTION_SAVELENGTH)); + diag.SetPreferOneSheetSolution(IsOptionSet(LONG_OPTION_PREFER_ONE_SHEET_SOLUTION)); diag.SetGroup(OptGroup()); if (IsOptionSet(LONG_OPTION_IGNORE_MARGINS)) @@ -706,6 +707,8 @@ void VCommandLine::InitCommandLineOptions() {{SINGLE_OPTION_UNITE, LONG_OPTION_UNITE}, translate("VCommandLine", "Unite pages if possible (export mode). Maximum value limited by QImage that " "supports only a maximum of 32768x32768 px images.")}, + {LONG_OPTION_PREFER_ONE_SHEET_SOLUTION, + translate("VCommandLine", "Prefer one sheet layout solution (export mode).")}, //================================================================================================================= {{SINGLE_OPTION_SAVELENGTH, LONG_OPTION_SAVELENGTH}, translate("VCommandLine", "Save length of the sheet if set (export mode). The option tells the program to use " diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index 1847c4286..04549ef52 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -292,6 +292,18 @@ void DialogLayoutSettings::SetSaveLength(bool save) ui->checkBoxSaveLength->setChecked(save); } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogLayoutSettings::IsPreferOneSheetSolution() const +{ + return ui->checkBoxOneSheetSolution->isChecked(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::SetPreferOneSheetSolution(bool prefer) +{ + ui->checkBoxOneSheetSolution->setChecked(prefer); +} + //--------------------------------------------------------------------------------------------------------------------- bool DialogLayoutSettings::IsUnitePages() const { @@ -600,6 +612,7 @@ void DialogLayoutSettings::DialogAccepted() generator->SetAutoCropLength(GetAutoCropLength()); generator->SetAutoCropWidth(GetAutoCropWidth()); generator->SetSaveLength(IsSaveLength()); + generator->SetPreferOneSheetSolution(IsPreferOneSheetSolution()); generator->SetUnitePages(IsUnitePages()); generator->SetStripOptimization(IsStripOptimization()); generator->SetMultiplier(GetMultiplier()); @@ -695,6 +708,7 @@ void DialogLayoutSettings::RestoreDefaults() SetNestingTime(VSettings::GetDefNestingTime()); SetEfficiencyCoefficient(VSettings::GetDefEfficiencyCoefficient()); SetNestQuantity(VSettings::GetDefLayoutNestQuantity()); + SetPreferOneSheetSolution(VSettings::GetDefLayoutPreferOneSheetSolution()); CorrectMaxFileds(); IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked()); @@ -1019,6 +1033,7 @@ void DialogLayoutSettings::ReadSettings() SetAutoCropLength(settings->GetLayoutAutoCropLength()); SetAutoCropWidth(settings->GetLayoutAutoCropWidth()); SetSaveLength(settings->GetLayoutSaveLength()); + SetPreferOneSheetSolution(settings->GetLayoutPreferOneSheetSolution()); SetUnitePages(settings->GetLayoutUnitePages()); SetFields(settings->GetFields(GetDefPrinterFields())); SetIgnoreAllFields(settings->GetIgnoreAllFields()); @@ -1046,6 +1061,7 @@ void DialogLayoutSettings::WriteSettings() const settings->SetLayoutAutoCropLength(GetAutoCropLength()); settings->SetLayoutAutoCropWidth(GetAutoCropWidth()); settings->SetLayoutSaveLength(IsSaveLength()); + settings->SetLayoutPreferOneSheetSolution(IsPreferOneSheetSolution()); settings->SetLayoutUnitePages(IsUnitePages()); settings->SetFields(GetFields()); settings->SetIgnoreAllFields(IsIgnoreAllFields()); diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index 778014b2b..bf6c9d8c7 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -85,6 +85,9 @@ public: bool IsSaveLength() const; void SetSaveLength(bool save); + bool IsPreferOneSheetSolution() const; + void SetPreferOneSheetSolution(bool prefer); + bool IsUnitePages() const; void SetUnitePages(bool save); diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.ui b/src/app/valentina/dialogs/dialoglayoutsettings.ui index 648e09b5a..94f63d258 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.ui +++ b/src/app/valentina/dialogs/dialoglayoutsettings.ui @@ -7,7 +7,7 @@ 0 0 601 - 600 + 645 @@ -448,6 +448,16 @@ + + + + Enable this option to prefer getting one sheet solutions. + + + Prefer one sheet solution + + + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index beba50d7b..3f1c61887 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -313,7 +313,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator) if (lGenerator.PapersCount() <= papersCount) { const qreal layoutEfficiency = lGenerator.LayoutEfficiency(); - if (efficiency < layoutEfficiency) + if (efficiency < layoutEfficiency || lGenerator.PapersCount() < papersCount) { efficiency = layoutEfficiency; if (VApplication::IsGUIMode()) @@ -404,7 +404,11 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator) || (nestingState == LayoutErrors::NoError && not qFuzzyIsNull(lGenerator.GetEfficiencyCoefficient()) && efficiency >= lGenerator.GetEfficiencyCoefficient())) { - break; + if (not lGenerator.IsPreferOneSheetSolution() + || (lGenerator.IsPreferOneSheetSolution() && lGenerator.PapersCount() == 1)) + { + break; + } } if (IsTimeout()) diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index db19d5bd8..61709a112 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -680,6 +680,18 @@ void VLayoutGenerator::SetSaveLength(bool value) saveLength = value; } +//--------------------------------------------------------------------------------------------------------------------- +bool VLayoutGenerator::IsPreferOneSheetSolution() const +{ + return preferOneSheetSolution; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::SetPreferOneSheetSolution(bool value) +{ + preferOneSheetSolution = value; +} + //--------------------------------------------------------------------------------------------------------------------- bool VLayoutGenerator::GetAutoCropLength() const { diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 2115140da..38b8edb80 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -117,6 +117,9 @@ public: bool IsSaveLength() const; void SetSaveLength(bool value); + bool IsPreferOneSheetSolution() const; + void SetPreferOneSheetSolution(bool value); + bool IsUnitePages() const; void SetUnitePages(bool value); @@ -154,6 +157,7 @@ private: bool autoCropLength; bool autoCropWidth; bool saveLength; + bool preferOneSheetSolution{false}; bool unitePages; bool stripOptimizationEnabled; quint8 multiplier; diff --git a/src/libs/vmisc/commandoptions.cpp b/src/libs/vmisc/commandoptions.cpp index 47e637f5b..6499f46d5 100644 --- a/src/libs/vmisc/commandoptions.cpp +++ b/src/libs/vmisc/commandoptions.cpp @@ -136,6 +136,7 @@ const QString LONG_OPTION_MANUAL_PRIORITY = QStringLiteral("manualPriority"); const QString LONG_OPTION_LANDSCAPE_ORIENTATION = QStringLiteral("landscapeOrientation"); const QString LONG_OPTION_NEST_QUANTITY = QStringLiteral("nestQuantity"); +const QString LONG_OPTION_PREFER_ONE_SHEET_SOLUTION = QStringLiteral("preferOneSheetSolution"); //--------------------------------------------------------------------------------------------------------------------- /** @@ -193,6 +194,7 @@ QStringList AllKeys() LONG_OPTION_FOLLOW_GRAINLINE, LONG_OPTION_MANUAL_PRIORITY, LONG_OPTION_LANDSCAPE_ORIENTATION, - LONG_OPTION_NEST_QUANTITY + LONG_OPTION_NEST_QUANTITY, + LONG_OPTION_PREFER_ONE_SHEET_SOLUTION }; } diff --git a/src/libs/vmisc/commandoptions.h b/src/libs/vmisc/commandoptions.h index 1f4758455..a4737440e 100644 --- a/src/libs/vmisc/commandoptions.h +++ b/src/libs/vmisc/commandoptions.h @@ -130,6 +130,7 @@ extern const QString LONG_OPTION_FOLLOW_GRAINLINE; extern const QString LONG_OPTION_MANUAL_PRIORITY; extern const QString LONG_OPTION_LANDSCAPE_ORIENTATION; extern const QString LONG_OPTION_NEST_QUANTITY; +extern const QString LONG_OPTION_PREFER_ONE_SHEET_SOLUTION; QStringList AllKeys(); diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index a7633b90b..dbe6ff220 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -91,6 +91,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutNestQuantity, (QLatin1Stri Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutAutoCropLength, (QLatin1String("layout/autoCropLength"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutAutoCropWidth, (QLatin1String("layout/autoCropWidth"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSaveLength, (QLatin1String("layout/saveLength"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPreferOneSheetSolution, + (QLatin1String("layout/preferOneSheetSolution"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutUnitePages, (QLatin1String("layout/unitePages"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFields, (QLatin1String("layout/fields"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingIgnoreFields, (QLatin1String("layout/ignoreFields"))) @@ -426,6 +428,24 @@ void VSettings::SetLayoutSaveLength(bool value) setValue(*settingLayoutSaveLength, value); } +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetLayoutPreferOneSheetSolution() const +{ + return value(*settingLayoutPreferOneSheetSolution, GetDefLayoutPreferOneSheetSolution()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetDefLayoutPreferOneSheetSolution() +{ + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSettings::SetLayoutPreferOneSheetSolution(bool value) +{ + setValue(*settingLayoutPreferOneSheetSolution, value); +} + //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetLayoutUnitePages() const { diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index 95f6eb8a2..8b6d0aacd 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -110,6 +110,10 @@ public: static bool GetDefLayoutSaveLength(); void SetLayoutSaveLength(bool value); + bool GetLayoutPreferOneSheetSolution() const; + static bool GetDefLayoutPreferOneSheetSolution(); + void SetLayoutPreferOneSheetSolution(bool value); + bool GetLayoutUnitePages() const; static bool GetDefLayoutUnitePages(); void SetLayoutUnitePages(bool value);