Skip to content

Commit 9c8fabc

Browse files
committed
ENH: Add "Fit camera to scene or selection" function from 3D navigator as a global shortcut (Z).
1 parent 5b5d36f commit 9c8fabc

5 files changed

Lines changed: 35 additions & 24 deletions

File tree

src/slic3r/GUI/GLCanvas3D.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,23 @@ void GLCanvas3D::zoom_to_plate(int plate_idx)
22542254
}
22552255
}
22562256

2257+
void GLCanvas3D::zoom_to_fit()
2258+
{
2259+
if (!can_show_3d_navigator())
2260+
return;
2261+
2262+
select_view("plate");
2263+
if (m_selection.is_empty()) {
2264+
if (m_canvas_type == ECanvasType::CanvasAssembleView)
2265+
zoom_to_volumes();
2266+
else
2267+
zoom_to_bed();
2268+
}
2269+
else {
2270+
zoom_to_selection();
2271+
}
2272+
}
2273+
22572274
void GLCanvas3D::select_view(const std::string& direction)
22582275
{
22592276
get_active_camera().select_view(direction);
@@ -4183,18 +4200,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
41834200
break;
41844201
}
41854202
#endif // ENABLE_RENDER_PICKING_PASS
4186-
//case 'Z':
4187-
//case 'z': {
4188-
// if (!m_selection.is_empty())
4189-
// zoom_to_selection();
4190-
// else {
4191-
// if (!m_volumes.empty())
4192-
// zoom_to_volumes();
4193-
// else
4194-
// _zoom_to_box(m_gcode_viewer.get_paths_bounding_box());
4195-
// }
4196-
// break;
4197-
//}
41984203
default: { evt.Skip(); break; }
41994204
}
42004205
}
@@ -8883,18 +8888,7 @@ void GLCanvas3D::_render_fit_camera_toolbar()
88838888

88848889
if (ImGui::ImageButton3(normal_id, hover_id, button_icon_size, ImVec2(0, 0), ImVec2(1, 1), -1,
88858890
ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1), ImVec2(10, 0))) {
8886-
select_view("plate");
8887-
if (m_selection.is_empty()) {
8888-
if (m_canvas_type == ECanvasType::CanvasAssembleView) {
8889-
zoom_to_volumes();
8890-
}
8891-
else {
8892-
zoom_to_bed();
8893-
}
8894-
}
8895-
else {
8896-
zoom_to_selection();
8897-
}
8891+
zoom_to_fit();
88988892
}
88998893
if (ImGui::IsItemHovered()) {
89008894
auto temp_tooltip = _L("Fit camera to scene or selected object.");

src/slic3r/GUI/GLCanvas3D.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ class GLCanvas3D
922922
void zoom_to_gcode();
923923
//BBS -1 for current plate
924924
void zoom_to_plate(int plate_idx = -1);
925+
void zoom_to_fit();
925926
void select_view(const std::string& direction);
926927
//BBS: add part plate related logic
927928
void select_plate();

src/slic3r/GUI/KBShortcutsDialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ void KBShortcutsDialog::fill_shortcuts()
250250
{ctrl + "5", L("Camera view - Left")},
251251
{ctrl + "6", L("Camera view - Right")},
252252
{ctrl + "7", L("Camera view - Isometric")},
253+
{ "Z", L("Camera view - Fit to scene or selection")},
253254
{ctrl + "W", L("Reset Window Layout")},
254255
{ctrl + "E", L("Show Labels")},
255256
{ctrl + "L", L("Show &Overhang")},

src/slic3r/GUI/MainFrame.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
707707
if (m_plater) { m_plater->add_file(); }
708708
return;
709709
}
710+
711+
if (!evt.HasAnyModifiers() && evt.GetKeyCode() == 'Z') {
712+
view_zoom_to_fit();
713+
return;
714+
}
715+
710716
evt.Skip();
711717
});
712718

@@ -2623,6 +2629,8 @@ static void add_common_view_menu_items(wxMenu* view_menu, MainFrame* mainFrame,
26232629
append_menu_item(view_menu, wxID_ANY, _CTX(L_CONTEXT("Isometric", "Camera"), "Camera") + " 3", _L("Isometric View") + " 3",
26242630
[mainFrame](wxCommandEvent &) { mainFrame->select_view("iso_3"); }, "", nullptr, [can_change_view]() { return can_change_view(); }, mainFrame);
26252631
#endif
2632+
append_menu_item(view_menu, wxID_ANY, _L("Fit Camera") + "\t" "Z", _L("Fit camera to scene or selected object."),
2633+
[mainFrame](wxCommandEvent &) { mainFrame->view_zoom_to_fit(); }, "", nullptr, [can_change_view]() { return can_change_view(); }, mainFrame);
26262634
}
26272635

26282636
void MainFrame::init_menubar_as_editor()
@@ -3922,6 +3930,12 @@ void MainFrame::select_view(const std::string& direction)
39223930
m_plater->select_view(direction);
39233931
}
39243932

3933+
void MainFrame::view_zoom_to_fit() const
3934+
{
3935+
if (GLCanvas3D *canvas = m_plater ? m_plater->canvas3D() : nullptr)
3936+
canvas->zoom_to_fit();
3937+
}
3938+
39253939
// #ys_FIXME_to_delete
39263940
void MainFrame::on_presets_changed(SimpleEvent &event)
39273941
{

src/slic3r/GUI/MainFrame.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ class MainFrame : public DPIFrame
329329
void request_select_tab(TabPosition pos);
330330
int get_calibration_curr_tab();
331331
void select_view(const std::string& direction);
332+
void view_zoom_to_fit() const;
332333
// Propagate changed configuration from the Tab to the Plater and save changes to the AppConfig
333334
void on_config_changed(DynamicPrintConfig* cfg) const ;
334335
void set_print_button_to_default(PrintSelectType select_type);

0 commit comments

Comments
 (0)