Modified menu for open/save/save as project (3mf) and import/export

This commit is contained in:
Enrico Turri 2018-11-15 15:27:39 +01:00
parent a82c07e8cc
commit 9bb04ff15a
8 changed files with 242 additions and 16 deletions
src/slic3r/GUI

View file

@ -217,11 +217,76 @@ void MainFrame::add_created_tab(Tab* panel)
m_tabpanel->AddPage(panel, panel->title());
}
#if ENABLE_NEW_MENU_LAYOUT
bool MainFrame::can_save() const
{
return (m_plater != nullptr) ? !m_plater->model().objects.empty() : false;
}
bool MainFrame::can_export_model() const
{
return (m_plater != nullptr) ? !m_plater->model().objects.empty() : false;
}
bool MainFrame::can_export_gcode() const
{
if (m_plater == nullptr)
return false;
if (m_plater->model().objects.empty())
return false;
if (m_plater->is_export_gcode_scheduled())
return false;
// TODO:: add other filters
return true;
}
#endif // ENABLE_NEW_MENU_LAYOUT
void MainFrame::init_menubar()
{
// File menu
wxMenu* fileMenu = new wxMenu;
{
#if ENABLE_NEW_MENU_LAYOUT
append_menu_item(fileMenu, wxID_ANY, _(L("Open…\tCtrl+O")), _(L("Open a project file")),
[this](wxCommandEvent&) { if (m_plater) m_plater->load_project(); }, "brick_add.png");
wxMenuItem* item_save = append_menu_item(fileMenu, wxID_ANY, _(L("Save\tCtrl+S")), _(L("Save current project file")),
[this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(m_plater->get_project_filename().wx_str()); }, "disk.png");
wxMenuItem* item_save_as = append_menu_item(fileMenu, wxID_ANY, _(L("Save as…\tCtrl+Alt+S")), _(L("Save current project file as")),
[this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(); }, "disk.png");
fileMenu->AppendSeparator();
wxMenu* import_menu = new wxMenu();
append_menu_item(import_menu, wxID_ANY, _(L("Import STL/OBJ/AMF/3MF…\tCtrl+I")), _(L("Load a model")),
[this](wxCommandEvent&) { if (m_plater) m_plater->add_model(); }, "brick_add.png");
import_menu->AppendSeparator();
append_menu_item(import_menu, wxID_ANY, _(L("Import Config…\tCtrl+L")), _(L("Load exported configuration file")),
[this](wxCommandEvent&) { load_config_file(); }, "plugin_add.png");
append_menu_item(import_menu, wxID_ANY, _(L("Import Config Bundle…")), _(L("Load presets from a bundle")),
[this](wxCommandEvent&) { load_configbundle(); }, "lorry_add.png");
append_submenu(fileMenu, import_menu, wxID_ANY, _(L("Import")), _(L("")));
wxMenu* export_menu = new wxMenu();
wxMenuItem* item_export_gcode = append_menu_item(export_menu, wxID_ANY, _(L("Export G-code…")), _(L("Export current plate as G-code")),
[this](wxCommandEvent&) { if (m_plater) m_plater->export_gcode(); }, "cog_go.png");
export_menu->AppendSeparator();
wxMenuItem* item_export_stl = append_menu_item(export_menu, wxID_ANY, _(L("Export plate as STL…")), _(L("Export current plate as STL")),
[this](wxCommandEvent&) { if (m_plater) m_plater->export_stl(); }, "brick_go.png");
wxMenuItem* item_export_amf = append_menu_item(export_menu, wxID_ANY, _(L("Export plate as AMF…")), _(L("Export current plate as AMF")),
[this](wxCommandEvent&) { if (m_plater) m_plater->export_amf(); }, "brick_go.png");
export_menu->AppendSeparator();
append_menu_item(export_menu, wxID_ANY, _(L("Export Config…\tCtrl+E")), _(L("Export current configuration to file")),
[this](wxCommandEvent&) { export_config(); }, "plugin_go.png");
append_menu_item(export_menu, wxID_ANY, _(L("Export Config Bundle…")), _(L("Export all presets to file")),
[this](wxCommandEvent&) { export_configbundle(); }, "lorry_go.png");
append_submenu(fileMenu, export_menu, wxID_ANY, _(L("Export")), _(L("")));
fileMenu->AppendSeparator();
#else
append_menu_item(fileMenu, wxID_ANY, _(L("Open STL/OBJ/AMF/3MF…\tCtrl+O")), _(L("Open a model")),
[this](wxCommandEvent&) { if (m_plater) m_plater->add(); }, "brick_add.png");
append_menu_item(fileMenu, wxID_ANY, _(L("&Load Config…\tCtrl+L")), _(L("Load exported configuration file")),
@ -233,6 +298,8 @@ void MainFrame::init_menubar()
append_menu_item(fileMenu, wxID_ANY, _(L("&Export Config Bundle…")), _(L("Export all presets to file")),
[this](wxCommandEvent&) { export_configbundle(); }, "lorry_go.png");
fileMenu->AppendSeparator();
#endif // ENABLE_NEW_MENU_LAYOUT
m_menu_item_repeat = nullptr;
append_menu_item(fileMenu, wxID_ANY, _(L("Q&uick Slice…\tCtrl+U")), _(L("Slice a file into a G-code")),
[this](wxCommandEvent&) {
@ -263,8 +330,17 @@ void MainFrame::init_menubar()
fileMenu->AppendSeparator();
append_menu_item(fileMenu, wxID_EXIT, _(L("&Quit")), _(L("Quit Slic3r")),
[this](wxCommandEvent&) { Close(false); } );
#if ENABLE_NEW_MENU_LAYOUT
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_save()); }, item_save->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_save()); }, item_save_as->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_export_gcode()); }, item_export_gcode->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_export_model()); }, item_export_stl->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_export_model()); }, item_export_amf->GetId());
#endif // ENABLE_NEW_MENU_LAYOUT
}
#if !ENABLE_NEW_MENU_LAYOUT
// Plater menu
if (m_plater) {
m_plater_menu = new wxMenu();
@ -277,6 +353,7 @@ void MainFrame::init_menubar()
append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as 3MF...")), _(L("Export current plate as 3MF")),
[this](wxCommandEvent&) { m_plater->export_3mf(); }, "brick_go.png");
}
#endif // !ENABLE_NEW_MENU_LAYOUT
// Window menu
auto windowMenu = new wxMenu();
@ -299,6 +376,23 @@ void MainFrame::init_menubar()
}
// View menu
#if ENABLE_NEW_MENU_LAYOUT
wxMenu* viewMenu = nullptr;
if (m_plater) {
viewMenu = new wxMenu();
// \xA0 is a non-breaing space. It is entered here to spoil the automatic accelerators,
// as the simple numeric accelerators spoil all numeric data entry.
// The camera control accelerators are captured by GLCanvas3D::on_char().
append_menu_item(viewMenu, wxID_ANY, _(L("Iso")) + "\t\xA0" + "0", _(L("Iso View")), [this](wxCommandEvent&) { select_view("iso"); });
viewMenu->AppendSeparator();
append_menu_item(viewMenu, wxID_ANY, _(L("Top")) + "\t\xA0" + "1", _(L("Top View")), [this](wxCommandEvent&) { select_view("top"); });
append_menu_item(viewMenu, wxID_ANY, _(L("Bottom")) + "\t\xA0" + "2", _(L("Bottom View")), [this](wxCommandEvent&) { select_view("bottom"); });
append_menu_item(viewMenu, wxID_ANY, _(L("Front")) + "\t\xA0" + "3", _(L("Front View")), [this](wxCommandEvent&) { select_view("front"); });
append_menu_item(viewMenu, wxID_ANY, _(L("Rear")) + "\t\xA0" + "4", _(L("Rear View")), [this](wxCommandEvent&) { select_view("rear"); });
append_menu_item(viewMenu, wxID_ANY, _(L("Left")) + "\t\xA0" + "5", _(L("Left View")), [this](wxCommandEvent&) { select_view("left"); });
append_menu_item(viewMenu, wxID_ANY, _(L("Right")) + "\t\xA0" + "6", _(L("Right View")), [this](wxCommandEvent&) { select_view("right"); });
}
#else
if (m_plater) {
m_viewMenu = new wxMenu();
// \xA0 is a non-breaing space. It is entered here to spoil the automatic accelerators,
@ -313,6 +407,7 @@ void MainFrame::init_menubar()
append_menu_item(m_viewMenu, wxID_ANY, _(L("Left")) + "\t\xA0" + "5", _(L("Left View")), [this](wxCommandEvent&) { select_view("left"); });
append_menu_item(m_viewMenu, wxID_ANY, _(L("Right")) + "\t\xA0" + "6", _(L("Right View")), [this](wxCommandEvent&) { select_view("right"); });
}
#endif // ENABLE_NEW_MENU_LAYOUT
// Help menu
auto helpMenu = new wxMenu();
@ -346,9 +441,15 @@ void MainFrame::init_menubar()
{
auto menubar = new wxMenuBar();
menubar->Append(fileMenu, L("&File"));
if (m_plater_menu) menubar->Append(m_plater_menu, L("&Plater")) ;
#if !ENABLE_NEW_MENU_LAYOUT
if (m_plater_menu) menubar->Append(m_plater_menu, L("&Plater"));
#endif // !ENABLE_NEW_MENU_LAYOUT
menubar->Append(windowMenu, L("&Window"));
#if ENABLE_NEW_MENU_LAYOUT
if (viewMenu) menubar->Append(viewMenu, L("&View"));
#else
if (m_viewMenu) menubar->Append(m_viewMenu, L("&View"));
#endif // !ENABLE_NEW_MENU_LAYOUT
// Add additional menus from C++
wxGetApp().add_config_menu(menubar);
menubar->Append(helpMenu, L("&Help"));