Skip to content

Commit ee03ea9

Browse files
committed
feat: add drop-to-bed action
(cherry picked from commit 55b727e)
1 parent 1dd4a5f commit ee03ea9

2 files changed

Lines changed: 54 additions & 14 deletions

File tree

src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,26 +275,23 @@ void GizmoObjectManipulation::update_reset_buttons_visibility()
275275
{
276276
const Selection& selection = m_glcanvas.get_selection();
277277

278+
m_show_drop_to_bed = false;
279+
278280
if (selection.is_single_full_instance() || selection.is_single_volume_or_modifier()) {
279-
const GLVolume * volume = selection.get_first_volume();
281+
const GLVolume* volume = selection.get_first_volume();
280282

281-
Vec3d rotation;
282-
Vec3d scale;
283-
double min_z = 0.;
283+
const Vec3d rotation = selection.is_single_full_instance()
284+
? volume->get_instance_rotation()
285+
: volume->get_volume_rotation();
286+
287+
const double min_z = selection.is_single_full_instance()
288+
? selection.get_scaled_instance_bounding_box().min.z()
289+
: get_volume_min_z(volume);
284290

285-
if (selection.is_single_full_instance()) {
286-
rotation = volume->get_instance_rotation();
287-
scale = volume->get_instance_scaling_factor();
288-
}
289-
else {
290-
rotation = volume->get_volume_rotation();
291-
scale = volume->get_volume_scaling_factor();
292-
min_z = get_volume_min_z(volume);
293-
}
294291
m_show_clear_rotation = !rotation.isApprox(m_init_rotation);
295292
m_show_reset_0_rotation = !rotation.isApprox(Vec3d::Zero());
296293
m_show_clear_scale = (m_cache.scale / 100.0f - Vec3d::Ones()).norm() > 0.001;
297-
m_show_drop_to_bed = (std::abs(min_z) > EPSILON);
294+
m_show_drop_to_bed = std::abs(min_z) > EPSILON;
298295
}
299296
}
300297

@@ -561,6 +558,42 @@ void GizmoObjectManipulation::reset_position_value()
561558
UpdateAndShow(true);
562559
}
563560

561+
void GizmoObjectManipulation::drop_to_bed()
562+
{
563+
Selection& selection = m_glcanvas.get_selection();
564+
565+
if (!selection.is_single_full_instance() &&
566+
!selection.is_single_volume_or_modifier())
567+
return;
568+
569+
const GLVolume* volume = selection.get_first_volume();
570+
if (volume == nullptr)
571+
return;
572+
573+
const double min_z = selection.is_single_full_instance()
574+
? selection.get_scaled_instance_bounding_box().min.z()
575+
: get_volume_min_z(volume);
576+
577+
if (std::abs(min_z) <= EPSILON)
578+
return;
579+
580+
selection.setup_cache();
581+
582+
TransformationType transformation_type;
583+
transformation_type.set_relative();
584+
585+
// Drop along the global Z axis regardless of the coordinate system shown
586+
// in the manipulation panel.
587+
selection.translate(-min_z * Vec3d::UnitZ(), transformation_type);
588+
589+
wxGetApp().plater()->take_snapshot(
590+
_u8L("Drop to bed"),
591+
UndoRedo::SnapshotType::GizmoAction);
592+
593+
m_glcanvas.do_move("");
594+
UpdateAndShow(true);
595+
}
596+
564597
void GizmoObjectManipulation::reset_rotation_value(bool reset_relative)
565598
{
566599
Selection &selection = m_glcanvas.get_selection();
@@ -971,6 +1004,12 @@ void GizmoObjectManipulation::set_init_rotation(const Geometry::Transformation &
9711004
m_buffered_position = display_position;
9721005
update(current_active_id, "position", original_position, m_buffered_position);
9731006
}
1007+
if (m_show_drop_to_bed) {
1008+
const std::string drop_to_bed_label = _u8L("Drop to bed");
1009+
if (ImGui::Button(drop_to_bed_label.c_str()))
1010+
drop_to_bed();
1011+
}
1012+
9741013
// the init position values are not zero, won't add reset button
9751014

9761015
// send focus to m_glcanvas

src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class GizmoObjectManipulation
182182
void change_size_value(int axis, double value);
183183
void do_scale(int axis, const Vec3d &scale) const;
184184
void reset_position_value();
185+
void drop_to_bed();
185186
void reset_rotation_value(bool reset_relative);
186187
void reset_scale_value();
187188

0 commit comments

Comments
 (0)