From 7d15ee8fd943c23fef059d204adbe504d618430b Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 12 Apr 2019 15:31:33 +0200 Subject: [PATCH] Offset used to place newly added volumes and instances proportional to the bed max size --- src/slic3r/GUI/GLCanvas3D.cpp | 5 +++++ src/slic3r/GUI/GLCanvas3D.hpp | 2 ++ src/slic3r/GUI/GUI_ObjectList.cpp | 4 +--- src/slic3r/GUI/Plater.cpp | 5 +++-- src/slic3r/GUI/Selection.cpp | 6 ++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 19ce28bed..edfeb0f57 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3140,6 +3140,11 @@ Linef3 GLCanvas3D::mouse_ray(const Point& mouse_pos) return Linef3(_mouse_to_3d(mouse_pos, &z0), _mouse_to_3d(mouse_pos, &z1)); } +double GLCanvas3D::get_size_proportional_to_max_bed_size(double factor) const +{ + return factor * m_bed.get_bounding_box().max_size(); +} + bool GLCanvas3D::_is_shown_on_screen() const { return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 2486753e7..bea6b3e3b 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -583,6 +583,8 @@ public: void refresh_camera_scene_box() { m_camera.set_scene_box(scene_bounding_box()); } bool is_mouse_dragging() const { return m_mouse.dragging; } + double get_size_proportional_to_max_bed_size(double factor) const; + private: bool _is_shown_on_screen() const; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 2a1d328e1..a1adb5511 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1437,9 +1437,7 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode const wxString name = _(L("Generic")) + "-" + _(type_name); TriangleMesh mesh; - auto& bed_shape = printer_config().option("bed_shape")->values; - const auto& sz = BoundingBoxf(bed_shape).size(); - const auto side = 0.1 * std::max(sz(0), sz(1)); + double side = wxGetApp().plater()->canvas3D()->get_size_proportional_to_max_bed_size(0.1); if (type_name == "Box") // Sitting on the print bed, left front front corner at (0, 0). diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 001f7bb6d..0b501b81e 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3225,8 +3225,9 @@ void Plater::increase_instances(size_t num) bool was_one_instance = model_object->instances.size()==1; - float offset = 10.0; - for (size_t i = 0; i < num; i++, offset += 10.0) { + double offset_base = canvas3D()->get_size_proportional_to_max_bed_size(0.05); + double offset = offset_base; + for (size_t i = 0; i < num; i++, offset += offset_base) { Vec3d offset_vec = model_instance->get_offset() + Vec3d(offset, offset, 0.0); model_object->add_instance(offset_vec, model_instance->get_scaling_factor(), model_instance->get_rotation(), model_instance->get_mirror()); // p->print.get_object(obj_idx)->add_copy(Slic3r::to_2d(offset_vec)); diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 8ee449a21..8b80310da 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -1778,7 +1778,8 @@ void Selection::paste_volumes_from_clipboard() ModelVolume* dst_volume = dst_object->add_volume(*src_volume); dst_volume->config = src_volume->config; dst_volume->set_new_unique_id(); - dst_volume->translate(10.0, 10.0, 0.0); + double offset = wxGetApp().plater()->canvas3D()->get_size_proportional_to_max_bed_size(0.05); + dst_volume->translate(offset, offset, 0.0); volumes.push_back(dst_volume); } wxGetApp().obj_list()->paste_volumes_into_list(obj_idx, volumes); @@ -1792,7 +1793,8 @@ void Selection::paste_objects_from_clipboard() for (const ModelObject* src_object : src_objects) { ModelObject* dst_object = m_model->add_object(*src_object); - dst_object->translate(10.0, 10.0, 0.0); + double offset = wxGetApp().plater()->canvas3D()->get_size_proportional_to_max_bed_size(0.05); + dst_object->translate(offset, offset, 0.0); object_idxs.push_back(m_model->objects.size() - 1); }