diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index e200b7edb..5744a7076 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -85,7 +85,13 @@ template void fill_config(PConf& pcfg, const ArrangeParams ¶ms) { // Align the arranged pile into the center of the bin - pcfg.alignment = PConf::Alignment::CENTER; + switch (params.alignment) { + case Pivots::Center: pcfg.alignment = PConf::Alignment::CENTER; break; + case Pivots::BottomLeft: pcfg.alignment = PConf::Alignment::BOTTOM_LEFT; break; + case Pivots::BottomRight: pcfg.alignment = PConf::Alignment::BOTTOM_RIGHT; break; + case Pivots::TopLeft: pcfg.alignment = PConf::Alignment::TOP_LEFT; break; + case Pivots::TopRight: pcfg.alignment = PConf::Alignment::TOP_RIGHT; break; + } // Start placing the items from the center of the print bed pcfg.starting_point = PConf::Alignment::CENTER; diff --git a/src/libslic3r/Arrange.hpp b/src/libslic3r/Arrange.hpp index 02d05e3e4..1d2e3fe88 100644 --- a/src/libslic3r/Arrange.hpp +++ b/src/libslic3r/Arrange.hpp @@ -75,6 +75,10 @@ struct ArrangePolygon { using ArrangePolygons = std::vector; +enum class Pivots { + Center, TopLeft, BottomLeft, BottomRight, TopRight +}; + struct ArrangeParams { /// The minimum distance which is allowed for any @@ -93,6 +97,12 @@ struct ArrangeParams { bool allow_rotations = false; + /// Final alignment of the merged pile after arrangement + Pivots alignment = Pivots::Center; + + /// Starting position hint for the arrangement + Pivots starting_point = Pivots::Center; + /// Progress indicator callback called when an object gets packed. /// The unsigned argument is the number of items remaining to pack. std::function progressind; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 7df8f5b32..dfbd66428 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4145,6 +4145,7 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x) std::string dist_key = "min_object_distance"; std::string dist_bed_key = "min_bed_distance"; std::string rot_key = "enable_rotation"; + std::string align_key = "alignment"; std::string postfix; if (ptech == ptSLA) { @@ -4163,6 +4164,7 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x) dist_key += postfix; dist_bed_key += postfix; rot_key += postfix; + align_key += postfix; imgui->text(GUI::format_wxstr(_L("Press %1%left mouse button to enter the exact value"), shortkey_ctrl_prefix())); @@ -4186,6 +4188,12 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x) settings_changed = true; } + if (imgui->combo(_("Alignment"), {"Center", "Top left", "Bottom left", "Bottom right", "Top right", "Random"}, settings.alignment)) { + settings_out.alignment = settings.alignment; + appcfg->set("arrange", align_key.c_str(), std::to_string(settings_out.alignment)); + settings_changed = true; + } + ImGui::Separator(); if (imgui->button(_L("Reset"))) { diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index f8f5a0efc..55b403c9f 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -463,6 +463,7 @@ public: // float distance_sla = 6.; float accuracy = 0.65f; // Unused currently bool enable_rotation = false; + int alignment = 0; }; private: diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index 7873af758..dd133260e 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -298,6 +298,21 @@ arrangement::ArrangeParams get_arrange_params(Plater *p) params.min_obj_distance = scaled(settings.distance); params.min_bed_distance = scaled(settings.distance_from_bed); + arrangement::Pivots pivot = arrangement::Pivots::Center; + + int pivot_max = static_cast(arrangement::Pivots::TopRight); + if (settings.alignment > pivot_max) { + // means it should be random + std::random_device rd{}; + std::mt19937 rng(rd()); + std::uniform_int_distribution dist(0, pivot_max); + pivot = static_cast(dist(rng)); + } else { + pivot = static_cast(settings.alignment); + } + + params.alignment = pivot; + return params; }