Skip to content

Commit 1215df6

Browse files
Merge pull request #10035 from mpaperno/mp/enh_fit_view_shortcut
ENH: Add "Fit camera to scene or selection" function from 3D navigator as a global shortcut.
2 parents dda76b6 + 9c8fabc commit 1215df6

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
@@ -2339,6 +2339,23 @@ void GLCanvas3D::zoom_to_plate(int plate_idx)
23392339
}
23402340
}
23412341

2342+
void GLCanvas3D::zoom_to_fit()
2343+
{
2344+
if (!can_show_3d_navigator())
2345+
return;
2346+
2347+
select_view("plate");
2348+
if (m_selection.is_empty()) {
2349+
if (m_canvas_type == ECanvasType::CanvasAssembleView)
2350+
zoom_to_volumes();
2351+
else
2352+
zoom_to_bed();
2353+
}
2354+
else {
2355+
zoom_to_selection();
2356+
}
2357+
}
2358+
23422359
void GLCanvas3D::select_view(const std::string& direction)
23432360
{
23442361
get_active_camera().select_view(direction);
@@ -4304,18 +4321,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
43044321
break;
43054322
}
43064323
#endif // ENABLE_RENDER_PICKING_PASS
4307-
//case 'Z':
4308-
//case 'z': {
4309-
// if (!m_selection.is_empty())
4310-
// zoom_to_selection();
4311-
// else {
4312-
// if (!m_volumes.empty())
4313-
// zoom_to_volumes();
4314-
// else
4315-
// _zoom_to_box(m_gcode_viewer.get_paths_bounding_box());
4316-
// }
4317-
// break;
4318-
//}
43194324
default: { evt.Skip(); break; }
43204325
}
43214326
}
@@ -9544,18 +9549,7 @@ void GLCanvas3D::_render_fit_camera_toolbar()
95449549

95459550
if (ImGui::ImageButton3(normal_id, hover_id, button_icon_size, ImVec2(0, 0), ImVec2(1, 1), -1,
95469551
ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1), ImVec2(10, 0))) {
9547-
select_view("plate");
9548-
if (m_selection.is_empty()) {
9549-
if (m_canvas_type == ECanvasType::CanvasAssembleView) {
9550-
zoom_to_volumes();
9551-
}
9552-
else {
9553-
zoom_to_bed();
9554-
}
9555-
}
9556-
else {
9557-
zoom_to_selection();
9558-
}
9552+
zoom_to_fit();
95599553
}
95609554
if (ImGui::IsItemHovered()) {
95619555
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
@@ -947,6 +947,7 @@ class GLCanvas3D
947947
void zoom_to_gcode();
948948
//BBS -1 for current plate
949949
void zoom_to_plate(int plate_idx = -1);
950+
void zoom_to_fit();
950951
void select_view(const std::string& direction);
951952
//BBS: add part plate related logic
952953
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 by Layer")},
255256
{L("Shift+E"), L("Show Labels by Object")},

src/slic3r/GUI/MainFrame.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,12 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
717717
if (m_plater) { m_plater->add_file(); }
718718
return;
719719
}
720+
721+
if (!evt.HasAnyModifiers() && evt.GetKeyCode() == 'Z') {
722+
view_zoom_to_fit();
723+
return;
724+
}
725+
720726
evt.Skip();
721727
});
722728

@@ -2677,6 +2683,8 @@ static void add_common_view_menu_items(wxMenu* view_menu, MainFrame* mainFrame,
26772683
append_menu_item(view_menu, wxID_ANY, _CTX(L_CONTEXT("Isometric", "Camera"), "Camera") + " 3", _L("Isometric View") + " 3",
26782684
[mainFrame](wxCommandEvent &) { mainFrame->select_view("iso_3"); }, "", nullptr, [can_change_view]() { return can_change_view(); }, mainFrame);
26792685
#endif
2686+
append_menu_item(view_menu, wxID_ANY, _L("Fit Camera") + "\t" "Z", _L("Fit camera to scene or selected object."),
2687+
[mainFrame](wxCommandEvent &) { mainFrame->view_zoom_to_fit(); }, "", nullptr, [can_change_view]() { return can_change_view(); }, mainFrame);
26802688
}
26812689

26822690
void MainFrame::init_menubar_as_editor()
@@ -3997,6 +4005,12 @@ void MainFrame::select_view(const std::string& direction)
39974005
m_plater->select_view(direction);
39984006
}
39994007

4008+
void MainFrame::view_zoom_to_fit() const
4009+
{
4010+
if (GLCanvas3D *canvas = m_plater ? m_plater->canvas3D() : nullptr)
4011+
canvas->zoom_to_fit();
4012+
}
4013+
40004014
// #ys_FIXME_to_delete
40014015
void MainFrame::on_presets_changed(SimpleEvent &event)
40024016
{

src/slic3r/GUI/MainFrame.hpp

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

0 commit comments

Comments
 (0)