2020-06-09 08:37:24 +02:00
#include "libslic3r/libslic3r.h"
2018-12-19 13:06:24 +01:00
#include "KBShortcutsDialog.hpp"
#include "I18N.hpp"
2018-12-19 14:01:13 +01:00
#include "libslic3r/Utils.hpp"
2018-12-19 13:06:24 +01:00
#include "GUI.hpp"
#include <wx/scrolwin.h>
2019-08-23 13:57:49 +02:00
#include <wx/display.h>
2018-12-20 12:52:16 +01:00
#include "GUI_App.hpp"
2019-02-11 14:14:35 +01:00
#include "wxExtensions.hpp"
2020-08-21 11:50:05 +02:00
#include "MainFrame.hpp"
2020-02-11 14:27:44 +01:00
#include <wx/notebook.h>
2019-08-06 16:53:17 +02:00
namespace Slic3r {
2018-12-19 13:06:24 +01:00
namespace GUI {
KBShortcutsDialog :: KBShortcutsDialog ()
2020-11-26 13:45:30 +01:00
: DPIDialog ( static_cast < wxWindow *> ( wxGetApp (). mainframe ), wxID_ANY , wxString ( wxGetApp (). is_editor () ? SLIC3R_APP_NAME : GCODEVIEWER_APP_NAME ) + " - " + _L ( "Keyboard Shortcuts" ),
2020-02-12 11:25:36 +01:00
wxDefaultPosition , wxDefaultSize , wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
2018-12-19 13:06:24 +01:00
{
2019-08-06 16:53:17 +02:00
SetBackgroundColour ( wxSystemSettings :: GetColour ( wxSYS_COLOUR_WINDOW ));
2018-12-19 13:06:24 +01:00
// fonts
2019-04-18 15:05:17 +02:00
const wxFont & font = wxGetApp (). normal_font ();
2019-08-06 16:53:17 +02:00
const wxFont & bold_font = wxGetApp (). bold_font ();
2019-04-18 15:05:17 +02:00
SetFont ( font );
2020-02-11 14:27:44 +01:00
auto main_sizer = new wxBoxSizer ( wxVERTICAL );
main_sizer -> Add ( create_header ( this , bold_font ), 0 , wxEXPAND | wxALL , 10 );
wxNotebook * book = new wxNotebook ( this , wxID_ANY , wxDefaultPosition , wxDefaultSize , wxNB_TOP );
2020-12-09 14:03:30 +01:00
main_sizer -> Add ( book , 1 , wxEXPAND | wxALL , 10 );
2018-12-20 12:52:16 +01:00
2018-12-19 13:06:24 +01:00
fill_shortcuts ();
2020-10-13 11:31:12 +02:00
for ( size_t i = 0 ; i < m_full_shortcuts . size (); ++ i ) {
2020-02-12 11:25:36 +01:00
wxPanel * page = create_page ( book , m_full_shortcuts [ i ], font , bold_font );
m_pages . push_back ( page );
2020-12-09 14:03:30 +01:00
book -> AddPage ( page , m_full_shortcuts [ i ]. first . first , i == 0 );
2018-12-19 13:06:24 +01:00
}
2019-08-06 16:53:17 +02:00
2018-12-19 13:06:24 +01:00
wxStdDialogButtonSizer * buttons = this -> CreateStdDialogButtonSizer ( wxOK );
2018-12-20 12:52:16 +01:00
this -> SetEscapeId ( wxID_OK );
2020-02-12 11:25:36 +01:00
main_sizer -> Add ( buttons , 0 , wxEXPAND | wxALL , 5 );
2018-12-19 13:06:24 +01:00
2019-08-06 16:53:17 +02:00
SetSizer ( main_sizer );
main_sizer -> SetSizeHints ( this );
2020-12-09 14:03:30 +01:00
this -> CenterOnParent ();
2018-12-19 13:06:24 +01:00
}
2020-02-11 14:27:44 +01:00
void KBShortcutsDialog :: on_dpi_changed ( const wxRect & suggested_rect )
2019-04-18 02:03:40 +02:00
{
2019-04-25 01:45:00 +02:00
m_logo_bmp . msw_rescale ();
2020-02-12 08:49:56 +01:00
m_header_bitmap -> SetBitmap ( m_logo_bmp . bmp ());
msw_buttons_rescale ( this , em_unit (), { wxID_OK });
2019-04-25 15:06:44 +02:00
2020-02-11 14:27:44 +01:00
Layout ();
2019-04-25 15:06:44 +02:00
Fit ();
2019-04-18 02:03:40 +02:00
Refresh ();
2018-12-19 13:06:24 +01:00
}
2020-02-11 14:27:44 +01:00
void KBShortcutsDialog :: fill_shortcuts ()
2018-12-19 13:06:24 +01:00
{
2020-02-11 14:27:44 +01:00
const std :: string & ctrl = GUI :: shortkey_ctrl_prefix ();
const std :: string & alt = GUI :: shortkey_alt_prefix ();
2020-09-08 11:40:06 +02:00
if ( wxGetApp (). is_editor ()) {
2020-08-21 11:50:05 +02:00
Shortcuts commands_shortcuts = {
// File
{ ctrl + "N" , L ( "New project, clear plater" ) },
{ ctrl + "O" , L ( "Open project STL/OBJ/AMF/3MF with config, clear plater" ) },
{ ctrl + "S" , L ( "Save project (3mf)" ) },
{ ctrl + alt + "S" , L ( "Save project as (3mf)" ) },
{ ctrl + "R" , L ( "(Re)slice" ) },
// File>Import
{ ctrl + "I" , L ( "Import STL/OBJ/AMF/3MF without config, keep plater" ) },
{ ctrl + "L" , L ( "Import Config from ini/amf/3mf/gcode" ) },
{ ctrl + alt + "L" , L ( "Load Config from ini/amf/3mf/gcode and merge" ) },
// File>Export
{ ctrl + "G" , L ( "Export G-code" ) },
{ ctrl + "Shift+" + "G" , L ( "Send G-code" ) },
{ ctrl + "E" , L ( "Export config" ) },
{ ctrl + "U" , L ( "Export to SD card / Flash drive" ) },
{ ctrl + "T" , L ( "Eject SD card / Flash drive" ) },
// Edit
{ ctrl + "A" , L ( "Select all objects" ) },
{ "Esc" , L ( "Deselect all" ) },
{ "Del" , L ( "Delete selected" ) },
{ ctrl + "Del" , L ( "Delete all" ) },
{ ctrl + "Z" , L ( "Undo" ) },
{ ctrl + "Y" , L ( "Redo" ) },
{ ctrl + "C" , L ( "Copy to clipboard" ) },
{ ctrl + "V" , L ( "Paste from clipboard" ) },
2020-12-07 08:39:43 +01:00
#ifdef __APPLE__
{ ctrl + "Shift+" + "R" , L ( "Reload plater from disk" ) },
#else
2020-08-21 11:50:05 +02:00
{ "F5" , L ( "Reload plater from disk" ) },
2020-12-07 08:39:43 +01:00
#endif // __APPLE__
2020-08-21 11:50:05 +02:00
{ ctrl + "F" , L ( "Search" ) },
// Window
{ ctrl + "1" , L ( "Select Plater Tab" ) },
{ ctrl + "2" , L ( "Select Print Settings Tab" ) },
{ ctrl + "3" , L ( "Select Filament Settings Tab" ) },
{ ctrl + "4" , L ( "Select Printer Settings Tab" ) },
{ ctrl + "5" , L ( "Switch to 3D" ) },
{ ctrl + "6" , L ( "Switch to Preview" ) },
{ ctrl + "J" , L ( "Print host upload queue" ) },
2020-09-11 18:32:19 +02:00
{ ctrl + "Shift+" + "I" , L ( "Open new instance" ) },
2020-08-21 11:50:05 +02:00
// View
{ "0-6" , L ( "Camera view" ) },
{ "E" , L ( "Show/Hide object/instance labels" ) },
// Configuration
2021-05-11 11:02:12 +02:00
#ifdef __APPLE__
{ ctrl + "," , L ( "Preferences" ) },
#else
2020-08-21 11:50:05 +02:00
{ ctrl + "P" , L ( "Preferences" ) },
2021-05-11 11:02:12 +02:00
#endif
2020-08-21 11:50:05 +02:00
// Help
{ "?" , L ( "Show keyboard shortcuts list" ) }
};
2020-02-11 14:27:44 +01:00
2020-12-09 14:03:30 +01:00
m_full_shortcuts . push_back ({ { _L ( "Commands" ), "" }, commands_shortcuts });
2020-02-11 14:27:44 +01:00
2020-08-21 11:50:05 +02:00
Shortcuts plater_shortcuts = {
{ "A" , L ( "Arrange" ) },
{ "Shift+A" , L ( "Arrange selection" ) },
{ "+" , L ( "Add Instance of the selected object" ) },
{ "-" , L ( "Remove Instance of the selected object" ) },
{ ctrl , L ( "Press to select multiple objects \n or move multiple objects with mouse" ) },
{ "Shift+" , L ( "Press to activate selection rectangle" ) },
{ alt , L ( "Press to activate deselection rectangle" ) },
{ L ( "Arrow Up" ), L ( "Move selection 10 mm in positive Y direction" ) },
{ L ( "Arrow Down" ), L ( "Move selection 10 mm in negative Y direction" ) },
{ L ( "Arrow Left" ), L ( "Move selection 10 mm in negative X direction" ) },
{ L ( "Arrow Right" ), L ( "Move selection 10 mm in positive X direction" ) },
{ std :: string ( "Shift+" ) + L ( "Any arrow" ), L ( "Movement step set to 1 mm" ) },
{ ctrl + L ( "Any arrow" ), L ( "Movement in camera space" ) },
{ L ( "Page Up" ), L ( "Rotate selection 45 degrees CCW" ) },
{ L ( "Page Down" ), L ( "Rotate selection 45 degrees CW" ) },
{ "M" , L ( "Gizmo move" ) },
{ "S" , L ( "Gizmo scale" ) },
{ "R" , L ( "Gizmo rotate" ) },
{ "C" , L ( "Gizmo cut" ) },
{ "F" , L ( "Gizmo Place face on bed" ) },
{ "H" , L ( "Gizmo SLA hollow" ) },
{ "L" , L ( "Gizmo SLA support points" ) },
{ "Esc" , L ( "Unselect gizmo or clear selection" ) },
{ "K" , L ( "Change camera type (perspective, orthographic)" ) },
{ "B" , L ( "Zoom to Bed" ) },
{ "Z" , L ( "Zoom to selected object \n or all objects in scene, if none selected" ) },
{ "I" , L ( "Zoom in" ) },
{ "O" , L ( "Zoom out" ) },
2020-10-13 11:31:12 +02:00
{ "Tab" , L ( "Switch between Editor/Preview" ) },
{ "Shift+Tab" , L ( "Collapse/Expand the sidebar" ) },
2020-11-26 11:00:24 +01:00
#ifdef _WIN32
{ ctrl + "M" , L ( "Show/Hide 3Dconnexion devices settings dialog, if enabled" ) },
2021-05-11 11:02:12 +02:00
#else
#ifdef __APPLE__
{ ctrl + "Shift+M" , L ( "Show/Hide 3Dconnexion devices settings dialog" ) },
{ ctrl + "M" , L ( "Minimize application" ) },
2020-11-26 11:00:24 +01:00
#else
2020-11-03 08:41:04 +01:00
{ ctrl + "M" , L ( "Show/Hide 3Dconnexion devices settings dialog" ) },
2021-05-11 11:02:12 +02:00
#endif // __APPLE__
2020-11-26 11:00:24 +01:00
#endif // _WIN32
2020-02-11 14:27:44 +01:00
#if ENABLE_RENDER_PICKING_PASS
2020-08-21 11:50:05 +02:00
// Don't localize debugging texts.
{ "P" , "Toggle picking pass texture rendering on/off" },
2020-02-11 14:27:44 +01:00
#endif // ENABLE_RENDER_PICKING_PASS
2020-08-21 11:50:05 +02:00
};
2020-02-11 14:27:44 +01:00
2020-12-09 14:03:30 +01:00
m_full_shortcuts . push_back ({ { _L ( "Plater" ), "" }, plater_shortcuts });
2020-02-11 14:27:44 +01:00
2020-08-21 11:50:05 +02:00
Shortcuts gizmos_shortcuts = {
2020-11-06 11:47:28 +01:00
{ ctrl , L ( "All gizmos: Rotate - left mouse button; Pan - right mouse button" ) },
2020-10-22 10:08:16 +02:00
{ "Shift+" , L ( "Gizmo move: Press to snap by 1mm" ) },
{ "Shift+" , L ( "Gizmo scale: Press to snap by 5%" ) },
{ "F" , L ( "Gizmo scale: Scale selection to fit print volume" ) },
{ ctrl , L ( "Gizmo scale: Press to activate one direction scaling" ) },
{ alt , L ( "Gizmo scale: Press to scale selected objects around their own center" ) },
{ alt , L ( "Gizmo rotate: Press to rotate selected objects around their own center" ) },
2020-08-21 11:50:05 +02:00
};
2020-02-11 14:27:44 +01:00
2020-12-09 14:03:30 +01:00
m_full_shortcuts . push_back ({ { _L ( "Gizmos" ), _L ( "The following shortcuts are applicable when the specified gizmo is active" ) }, gizmos_shortcuts });
2021-05-11 11:02:12 +02:00
Shortcuts object_list_shortcuts = {
{ "P" , L ( "Set selected items as Ptrintable/Unprintable" ) },
{ "0" , L ( "Set default extruder for the selected items" ) },
{ "1-9" , L ( "Set extruder number for the selected items" ) },
};
m_full_shortcuts . push_back ({ { _L ( "Objects List" ), "" }, object_list_shortcuts });
2020-08-21 11:50:05 +02:00
}
2020-12-07 08:39:43 +01:00
else {
Shortcuts commands_shortcuts = {
{ ctrl + "O" , L ( "Open a G-code file" ) },
#ifdef __APPLE__
{ ctrl + "Shift+" + "R" , L ( "Reload the plater from disk" ) },
#else
{ "F5" , L ( "Reload plater from disk" ) },
#endif // __APPLE__
};
2020-12-09 14:03:30 +01:00
m_full_shortcuts . push_back ({ { _L ( "Commands" ), "" }, commands_shortcuts });
2020-12-07 08:39:43 +01:00
}
2020-02-11 14:27:44 +01:00
Shortcuts preview_shortcuts = {
2020-12-04 13:08:20 +01:00
{ L ( "Arrow Up" ), L ( "Vertical slider - Move active thumb Up" ) },
{ L ( "Arrow Down" ), L ( "Vertical slider - Move active thumb Down" ) },
{ L ( "Arrow Left" ), L ( "Horizontal slider - Move active thumb Left" ) },
{ L ( "Arrow Right" ), L ( "Horizontal slider - Move active thumb Right" ) },
{ "W" , L ( "Vertical slider - Move active thumb Up" ) },
{ "S" , L ( "Vertical slider - Move active thumb Down" ) },
{ "A" , L ( "Horizontal slider - Move active thumb Left" ) },
{ "D" , L ( "Horizontal slider - Move active thumb Right" ) },
{ "X" , L ( "On/Off one layer mode of the vertical slider" ) },
2020-12-01 08:33:06 +01:00
{ "L" , L ( "Show/Hide Legend and Estimated printing time" ) },
2021-03-02 10:01:06 +01:00
#if ENABLE_GCODE_WINDOW
{ "C" , L ( "Show/Hide G-code window" ) },
#endif // ENABLE_GCODE_WINDOW
2020-02-11 14:27:44 +01:00
};
2020-12-09 14:03:30 +01:00
m_full_shortcuts . push_back ({ { _L ( "Preview" ), "" }, preview_shortcuts });
2020-02-11 14:27:44 +01:00
Shortcuts layers_slider_shortcuts = {
2020-12-09 14:03:30 +01:00
{ L ( "Arrow Up" ), L ( "Move active thumb Up" ) },
{ L ( "Arrow Down" ), L ( "Move active thumb Down" ) },
{ L ( "Arrow Left" ), L ( "Set upper thumb as active" ) },
{ L ( "Arrow Right" ), L ( "Set lower thumb as active" ) },
{ "+" , L ( "Add color change marker for current layer" ) },
{ "-" , L ( "Delete color change marker for current layer" ) },
2020-06-09 08:37:24 +02:00
{ "Shift+" , L ( "Press to speed up 5 times while moving thumb \n with arrow keys or mouse wheel" ) },
{ ctrl , L ( "Press to speed up 5 times while moving thumb \n with arrow keys or mouse wheel" ) },
2020-02-11 14:27:44 +01:00
};
2020-12-12 09:11:10 +01:00
m_full_shortcuts . push_back ({ { _L ( "Vertical Slider" ), _L ( "The following shortcuts are applicable in G-code preview when the vertical slider is active" ) }, layers_slider_shortcuts });
2020-06-09 08:37:24 +02:00
Shortcuts sequential_slider_shortcuts = {
2020-12-09 14:03:30 +01:00
{ L ( "Arrow Left" ), L ( "Move active thumb Left" ) },
{ L ( "Arrow Right" ), L ( "Move active thumb Right" ) },
{ L ( "Arrow Up" ), L ( "Set left thumb as active" ) },
{ L ( "Arrow Down" ), L ( "Set right thumb as active" ) },
2020-06-09 08:37:24 +02:00
{ "Shift+" , L ( "Press to speed up 5 times while moving thumb \n with arrow keys or mouse wheel" ) },
{ ctrl , L ( "Press to speed up 5 times while moving thumb \n with arrow keys or mouse wheel" ) },
};
2020-12-12 09:11:10 +01:00
m_full_shortcuts . push_back ({ { _L ( "Horizontal Slider" ), _L ( "The following shortcuts are applicable in G-code preview when the horizontal slider is active" ) }, sequential_slider_shortcuts });
2018-12-19 13:06:24 +01:00
}
2020-02-11 14:27:44 +01:00
wxPanel * KBShortcutsDialog :: create_header ( wxWindow * parent , const wxFont & bold_font )
2019-08-23 13:21:56 +02:00
{
2020-02-11 14:27:44 +01:00
wxPanel * panel = new wxPanel ( parent );
wxBoxSizer * sizer = new wxBoxSizer ( wxHORIZONTAL );
wxFont header_font = bold_font ;
#ifdef __WXOSX__
header_font . SetPointSize ( 14 );
#else
header_font . SetPointSize ( bold_font . GetPointSize () + 2 );
#endif // __WXOSX__
sizer -> AddStretchSpacer ();
// logo
2020-10-21 13:49:39 +02:00
m_logo_bmp = ScalableBitmap ( this , wxGetApp (). is_editor () ? "PrusaSlicer_32px.png" : "PrusaSlicer-gcodeviewer_32px.png" , 32 );
2020-02-12 08:49:56 +01:00
m_header_bitmap = new wxStaticBitmap ( panel , wxID_ANY , m_logo_bmp . bmp ());
sizer -> Add ( m_header_bitmap , 0 , wxEXPAND | wxLEFT | wxRIGHT , 10 );
2020-02-11 14:27:44 +01:00
// text
2020-06-09 08:37:24 +02:00
wxStaticText * text = new wxStaticText ( panel , wxID_ANY , _L ( "Keyboard shortcuts" ));
2020-02-11 14:27:44 +01:00
text -> SetFont ( header_font );
sizer -> Add ( text , 0 , wxALIGN_CENTER_VERTICAL );
sizer -> AddStretchSpacer ();
panel -> SetSizer ( sizer );
return panel ;
}
2020-12-09 14:03:30 +01:00
wxPanel * KBShortcutsDialog :: create_page ( wxWindow * parent , const ShortcutsItem & shortcuts , const wxFont & font , const wxFont & bold_font )
2020-02-11 14:27:44 +01:00
{
2020-12-09 14:03:30 +01:00
wxPanel * main_page = new wxPanel ( parent );
wxBoxSizer * main_sizer = new wxBoxSizer ( wxVERTICAL );
if ( ! shortcuts . first . second . empty ()) {
main_sizer -> AddSpacer ( 10 );
wxBoxSizer * info_sizer = new wxBoxSizer ( wxHORIZONTAL );
info_sizer -> AddStretchSpacer ();
info_sizer -> Add ( new wxStaticText ( main_page , wxID_ANY , shortcuts . first . second ), 0 );
info_sizer -> AddStretchSpacer ();
main_sizer -> Add ( info_sizer , 0 , wxEXPAND );
main_sizer -> AddSpacer ( 10 );
}
2020-02-11 14:27:44 +01:00
static const int max_items_per_column = 20 ;
2020-12-09 14:03:30 +01:00
int columns_count = 1 + static_cast < int > ( shortcuts . second . size ()) / max_items_per_column ;
2020-02-11 14:27:44 +01:00
2020-12-09 14:03:30 +01:00
wxScrolledWindow * scrollable_panel = new wxScrolledWindow ( main_page );
scrollable_panel -> SetScrollbars ( 20 , 20 , 50 , 50 );
scrollable_panel -> SetInitialSize ( wxSize ( 850 , 450 ));
2020-02-11 14:27:44 +01:00
2020-12-09 14:03:30 +01:00
wxBoxSizer * scrollable_panel_sizer = new wxBoxSizer ( wxVERTICAL );
2020-02-12 08:49:56 +01:00
wxFlexGridSizer * grid_sizer = new wxFlexGridSizer ( 2 * columns_count , 5 , 15 );
2020-02-11 14:27:44 +01:00
2020-02-12 08:49:56 +01:00
int items_count = ( int ) shortcuts . second . size ();
2020-10-13 11:31:12 +02:00
for ( int i = 0 ; i < max_items_per_column ; ++ i ) {
for ( int j = 0 ; j < columns_count ; ++ j ) {
2020-02-12 08:49:56 +01:00
int id = j * max_items_per_column + i ;
2020-10-13 11:31:12 +02:00
if ( id < items_count ) {
const auto & [ shortcut , description ] = shortcuts . second [ id ];
2020-12-09 14:03:30 +01:00
auto key = new wxStaticText ( scrollable_panel , wxID_ANY , _ ( shortcut ));
2020-10-13 11:31:12 +02:00
key -> SetFont ( bold_font );
grid_sizer -> Add ( key , 0 , wxALIGN_CENTRE_VERTICAL );
2020-02-11 14:27:44 +01:00
2020-12-09 14:03:30 +01:00
auto desc = new wxStaticText ( scrollable_panel , wxID_ANY , _ ( description ));
2020-10-13 11:31:12 +02:00
desc -> SetFont ( font );
grid_sizer -> Add ( desc , 0 , wxALIGN_CENTRE_VERTICAL );
}
else {
2020-12-09 14:03:30 +01:00
if ( columns_count > 1 ) {
grid_sizer -> Add ( new wxStaticText ( scrollable_panel , wxID_ANY , "" ), 0 , wxALIGN_CENTRE_VERTICAL );
grid_sizer -> Add ( new wxStaticText ( scrollable_panel , wxID_ANY , "" ), 0 , wxALIGN_CENTRE_VERTICAL );
}
2020-10-13 11:31:12 +02:00
}
2020-02-12 08:49:56 +01:00
}
2019-08-23 13:21:56 +02:00
}
2020-12-09 14:03:30 +01:00
scrollable_panel_sizer -> Add ( grid_sizer , 1 , wxEXPAND | wxALL , 10 );
scrollable_panel -> SetSizer ( scrollable_panel_sizer );
2020-02-12 11:25:36 +01:00
2020-12-09 14:03:30 +01:00
main_sizer -> Add ( scrollable_panel , 1 , wxEXPAND );
main_page -> SetSizer ( main_sizer );
return main_page ;
2019-08-23 13:21:56 +02:00
}
2018-12-19 13:06:24 +01:00
} // namespace GUI
} // namespace Slic3r