2018-09-20 06:40:22 +00:00
|
|
|
#include "MainFrame.hpp"
|
|
|
|
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/notebook.h>
|
|
|
|
#include <wx/icon.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/progdlg.h>
|
2018-09-21 13:42:31 +00:00
|
|
|
#include <wx/tooltip.h>
|
2018-10-03 14:27:02 +00:00
|
|
|
#include <wx/debug.h>
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
#include "Tab.hpp"
|
|
|
|
#include "PresetBundle.hpp"
|
2018-09-21 10:54:40 +00:00
|
|
|
#include "../AppController.hpp"
|
2018-09-20 06:40:22 +00:00
|
|
|
#include "ProgressStatusBar.hpp"
|
|
|
|
#include "3DScene.hpp"
|
|
|
|
#include "Print.hpp"
|
|
|
|
#include "Polygon.hpp"
|
|
|
|
#include "AppConfig.hpp"
|
2018-10-17 10:17:25 +00:00
|
|
|
#include "wxExtensions.hpp"
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
2018-09-20 23:33:41 +00:00
|
|
|
#include "GUI_App.hpp"
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
2018-09-20 23:33:41 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2018-09-20 06:40:22 +00:00
|
|
|
MainFrame::MainFrame(const bool no_plater, const bool loaded) :
|
2018-09-24 11:07:50 +00:00
|
|
|
wxFrame(NULL, wxID_ANY, SLIC3R_BUILD, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE),
|
2018-09-20 06:40:22 +00:00
|
|
|
m_no_plater(no_plater),
|
|
|
|
m_loaded(loaded)
|
|
|
|
{
|
2018-09-20 23:33:41 +00:00
|
|
|
m_appController = new Slic3r::AppController();
|
2018-09-20 06:40:22 +00:00
|
|
|
|
2018-09-24 12:27:03 +00:00
|
|
|
// Load the icon either from the exe, or from the ico file.
|
|
|
|
#if _WIN32
|
|
|
|
{
|
|
|
|
TCHAR szExeFileName[MAX_PATH];
|
|
|
|
GetModuleFileName(nullptr, szExeFileName, MAX_PATH);
|
|
|
|
SetIcon(wxIcon(szExeFileName, wxBITMAP_TYPE_ICO));
|
|
|
|
}
|
|
|
|
#else
|
2018-09-20 23:33:41 +00:00
|
|
|
SetIcon(wxIcon(Slic3r::var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG));
|
2018-09-24 12:27:03 +00:00
|
|
|
#endif // _WIN32
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
// initialize tabpanel and menubar
|
2018-09-20 23:33:41 +00:00
|
|
|
init_tabpanel();
|
|
|
|
init_menubar();
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
// set default tooltip timer in msec
|
|
|
|
// SetAutoPop supposedly accepts long integers but some bug doesn't allow for larger values
|
|
|
|
// (SetAutoPop is not available on GTK.)
|
2018-09-20 23:33:41 +00:00
|
|
|
wxToolTip::SetAutoPop(32767);
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
// initialize status bar
|
2018-10-02 11:23:38 +00:00
|
|
|
m_statusbar = new ProgressStatusBar(this);
|
2018-09-20 23:33:41 +00:00
|
|
|
m_statusbar->embed(this);
|
2018-09-24 11:07:50 +00:00
|
|
|
m_statusbar->set_status_text(_(L("Version ")) +
|
|
|
|
SLIC3R_VERSION +
|
2018-09-20 23:33:41 +00:00
|
|
|
_(L(" - Remember to check for updates at http://github.com/prusa3d/slic3r/releases")));
|
2018-09-20 06:40:22 +00:00
|
|
|
|
2018-10-11 11:22:36 +00:00
|
|
|
m_appController->set_model(&m_plater->model());
|
|
|
|
m_appController->set_print(&m_plater->print());
|
|
|
|
|
2018-09-21 09:40:32 +00:00
|
|
|
GUI::set_gui_appctl();
|
|
|
|
|
|
|
|
// Make the global status bar and its progress indicator available in C++
|
|
|
|
m_appController->set_global_progress_indicator(m_statusbar);
|
2018-09-20 06:40:22 +00:00
|
|
|
|
2018-09-20 23:33:41 +00:00
|
|
|
m_loaded = true;
|
|
|
|
|
|
|
|
// initialize layout
|
|
|
|
auto sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
if (m_tabpanel)
|
|
|
|
sizer->Add(m_tabpanel, 1, wxEXPAND);
|
|
|
|
sizer->SetSizeHints(this);
|
|
|
|
SetSizer(sizer);
|
|
|
|
Fit();
|
|
|
|
SetMinSize(wxSize(760, 490));
|
|
|
|
SetSize(GetMinSize());
|
|
|
|
Layout();
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
// declare events
|
2018-09-20 23:33:41 +00:00
|
|
|
Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event){
|
|
|
|
if (event.CanVeto() && !wxGetApp().check_unsaved_changes()) {
|
|
|
|
event.Veto();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// save window size
|
2018-10-17 12:01:10 +00:00
|
|
|
wxGetApp().window_pos_save(this, "mainframe");
|
2018-09-20 23:33:41 +00:00
|
|
|
// Save the slic3r.ini.Usually the ini file is saved from "on idle" callback,
|
|
|
|
// but in rare cases it may not have been called yet.
|
|
|
|
wxGetApp().app_config->save();
|
2018-09-20 06:40:22 +00:00
|
|
|
// if (m_plater)
|
|
|
|
// m_plater->print = undef;
|
2018-09-20 23:33:41 +00:00
|
|
|
_3DScene::remove_all_canvases();
|
2018-09-20 06:40:22 +00:00
|
|
|
// Slic3r::GUI::deregister_on_request_update_callback();
|
2018-09-20 23:33:41 +00:00
|
|
|
// propagate event
|
|
|
|
event.Skip();
|
|
|
|
});
|
2018-09-20 06:40:22 +00:00
|
|
|
|
2018-10-17 12:01:10 +00:00
|
|
|
// NB: Restoring the window position is done in a two-phase manner here,
|
|
|
|
// first the saved position is restored as-is and validation is done after the window is shown
|
|
|
|
// and initial round of events is complete, because on some platforms that is the only way
|
|
|
|
// to get an accurate window position & size.
|
|
|
|
wxGetApp().window_pos_restore(this, "mainframe");
|
|
|
|
Bind(wxEVT_SHOW, [this](wxShowEvent&) {
|
|
|
|
CallAfter([this]() {
|
|
|
|
wxGetApp().window_pos_sanitize(this);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-02 11:23:38 +00:00
|
|
|
update_ui_from_settings();
|
2018-09-20 06:40:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::init_tabpanel()
|
|
|
|
{
|
|
|
|
m_tabpanel = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL);
|
|
|
|
|
2018-09-20 23:33:41 +00:00
|
|
|
m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxEvent&){
|
|
|
|
auto panel = m_tabpanel->GetCurrentPage();
|
|
|
|
// panel->OnActivate(); if panel->can('OnActivate');
|
|
|
|
|
2018-10-02 11:23:38 +00:00
|
|
|
if (panel == nullptr)
|
2018-09-17 10:15:11 +00:00
|
|
|
return;
|
|
|
|
|
2018-09-24 09:53:05 +00:00
|
|
|
for (auto& tab_name : { "print", "filament", "printer" }) {
|
|
|
|
if (tab_name == panel->GetName()) {
|
|
|
|
// On GTK, the wxEVT_NOTEBOOK_PAGE_CHANGED event is triggered
|
|
|
|
// before the MainFrame is fully set up.
|
|
|
|
auto it = m_options_tabs.find(tab_name);
|
|
|
|
assert(it != m_options_tabs.end());
|
|
|
|
if (it != m_options_tabs.end())
|
|
|
|
it->second->OnActivate();
|
|
|
|
}
|
2018-09-20 23:33:41 +00:00
|
|
|
}
|
|
|
|
});
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
if (!m_no_plater) {
|
2018-09-17 10:15:11 +00:00
|
|
|
m_plater = new Slic3r::GUI::Plater(m_tabpanel, this);
|
|
|
|
m_tabpanel->AddPage(m_plater, _(L("Plater")));
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 10:41:05 +00:00
|
|
|
// The following event is emited by Tab implementation on config value change.
|
|
|
|
Bind(EVT_TAB_VALUE_CHANGED, &MainFrame::on_value_changed, this);
|
2018-09-20 06:40:22 +00:00
|
|
|
|
2018-10-03 14:27:02 +00:00
|
|
|
// The following event is emited by Tab on preset selection,
|
2018-09-20 06:40:22 +00:00
|
|
|
// or when the preset's "modified" status changes.
|
2018-10-03 14:27:02 +00:00
|
|
|
Bind(EVT_TAB_PRESETS_CHANGED, &MainFrame::on_presets_changed, this);
|
|
|
|
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
// The following event is emited by the C++ Tab implementation on object selection change.
|
|
|
|
// EVT_COMMAND($self, -1, $OBJECT_SELECTION_CHANGED_EVENT, sub {
|
|
|
|
// auto obj_idx = event->GetId();
|
|
|
|
// // my $child = $event->GetInt == 1 ? 1 : undef;
|
|
|
|
// // $self->{plater}->select_object($obj_idx < 0 ? undef : $obj_idx, $child);
|
|
|
|
// // $self->{plater}->item_changed_selection($obj_idx);
|
|
|
|
//
|
|
|
|
// auto vol_idx = event->GetInt();
|
|
|
|
// m_plater->select_object_from_cpp(obj_idx < 0 ? undef : obj_idx, vol_idx < 0 ? -1 : vol_idx);
|
|
|
|
// });
|
|
|
|
|
2018-09-20 23:33:41 +00:00
|
|
|
create_preset_tabs();
|
2018-09-20 06:40:22 +00:00
|
|
|
std::vector<std::string> tab_names = { "print", "filament", "sla_material", "printer" };
|
2018-09-20 23:33:41 +00:00
|
|
|
for (auto tab_name : tab_names)
|
|
|
|
m_options_tabs[tab_name] = get_preset_tab(tab_name.c_str());
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
if (m_plater) {
|
|
|
|
// load initial config
|
2018-09-20 23:33:41 +00:00
|
|
|
auto full_config = wxGetApp().preset_bundle->full_config();
|
2018-10-17 09:12:38 +00:00
|
|
|
m_plater->on_config_change(full_config);
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
// Show a correct number of filament fields.
|
2018-10-10 11:53:45 +00:00
|
|
|
// nozzle_diameter is undefined when SLA printer is selected
|
|
|
|
if (full_config.has("nozzle_diameter")){
|
|
|
|
m_plater->on_extruders_change(full_config.option<ConfigOptionFloats>("nozzle_diameter")->values.size());
|
|
|
|
}
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
std::vector<PresetTab> preset_tabs = {
|
|
|
|
{ "print", nullptr, ptFFF },
|
|
|
|
{ "filament", nullptr, ptFFF },
|
|
|
|
{ "sla_material", nullptr, ptSLA }
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<PresetTab>& MainFrame::get_preset_tabs() {
|
|
|
|
return preset_tabs;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tab* MainFrame::get_tab(const std::string& name)
|
|
|
|
{
|
|
|
|
std::vector<PresetTab>::iterator it = std::find_if(preset_tabs.begin(), preset_tabs.end(),
|
|
|
|
[name](PresetTab& tab){ return name == tab.name; });
|
|
|
|
return it != preset_tabs.end() ? it->panel : nullptr;
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:33:41 +00:00
|
|
|
Tab* MainFrame::get_preset_tab(const std::string& name)
|
|
|
|
{
|
|
|
|
Tab* tab = get_tab(name);
|
|
|
|
if (tab) return tab;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < m_tabpanel->GetPageCount(); ++i) {
|
|
|
|
tab = dynamic_cast<Tab*>(m_tabpanel->GetPage(i));
|
|
|
|
if (!tab)
|
|
|
|
continue;
|
|
|
|
if (tab->name() == name) {
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::create_preset_tabs()
|
|
|
|
{
|
2018-10-01 13:09:31 +00:00
|
|
|
wxGetApp().update_label_colours_from_appconfig();
|
2018-09-20 23:33:41 +00:00
|
|
|
add_created_tab(new TabPrint(m_tabpanel));
|
|
|
|
add_created_tab(new TabFilament(m_tabpanel));
|
|
|
|
add_created_tab(new TabSLAMaterial(m_tabpanel));
|
|
|
|
add_created_tab(new TabPrinter(m_tabpanel));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::add_created_tab(Tab* panel)
|
|
|
|
{
|
2018-10-04 14:43:10 +00:00
|
|
|
panel->create_preset_tab();
|
2018-09-20 23:33:41 +00:00
|
|
|
|
|
|
|
// Load the currently selected preset into the GUI, update the preset selection box.
|
|
|
|
panel->load_current_preset();
|
|
|
|
|
|
|
|
const wxString& tab_name = panel->GetName();
|
|
|
|
bool add_panel = true;
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
auto it = std::find_if(preset_tabs.begin(), preset_tabs.end(),
|
2018-09-20 23:33:41 +00:00
|
|
|
[tab_name](PresetTab& tab){return tab.name == tab_name; });
|
2018-10-05 21:29:15 +00:00
|
|
|
if (it != preset_tabs.end()) {
|
2018-09-20 23:33:41 +00:00
|
|
|
it->panel = panel;
|
|
|
|
add_panel = it->technology == wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add_panel)
|
|
|
|
m_tabpanel->AddPage(panel, panel->title());
|
|
|
|
}
|
|
|
|
|
2018-09-20 06:40:22 +00:00
|
|
|
void MainFrame::init_menubar()
|
|
|
|
{
|
|
|
|
// File menu
|
2018-09-20 23:33:41 +00:00
|
|
|
wxMenu* fileMenu = new wxMenu;
|
2018-09-20 06:40:22 +00:00
|
|
|
{
|
2018-10-17 10:17:25 +00:00
|
|
|
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");
|
2018-09-20 23:33:41 +00:00
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("&Load Config…\tCtrl+L")), _(L("Load exported configuration file")),
|
2018-09-20 06:40:22 +00:00
|
|
|
[this](wxCommandEvent&){ load_config_file(); }, "plugin_add.png");
|
2018-09-20 23:33:41 +00:00
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("&Export Config…\tCtrl+E")), _(L("Export current configuration to file")),
|
2018-09-20 06:40:22 +00:00
|
|
|
[this](wxCommandEvent&){ export_config(); }, "plugin_go.png");
|
2018-09-20 23:33:41 +00:00
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("&Load Config Bundle…")), _(L("Load presets from a bundle")),
|
2018-09-20 06:40:22 +00:00
|
|
|
[this](wxCommandEvent&){ load_configbundle(); }, "lorry_add.png");
|
2018-09-20 23:33:41 +00:00
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("&Export Config Bundle…")), _(L("Export all presets to file")),
|
2018-09-20 06:40:22 +00:00
|
|
|
[this](wxCommandEvent&){ export_configbundle(); }, "lorry_go.png");
|
|
|
|
fileMenu->AppendSeparator();
|
|
|
|
wxMenuItem* repeat = nullptr;
|
2018-09-20 23:33:41 +00:00
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("Q&uick Slice…\tCtrl+U")), _(L("Slice a file into a G-code")),
|
2018-09-20 06:40:22 +00:00
|
|
|
[this, repeat](wxCommandEvent&){
|
|
|
|
wxTheApp->CallAfter([this, repeat](){
|
|
|
|
quick_slice();
|
2018-09-20 23:33:41 +00:00
|
|
|
repeat->Enable(is_last_input_file());
|
2018-09-20 06:40:22 +00:00
|
|
|
}); }, "cog_go.png");
|
2018-09-20 23:33:41 +00:00
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("Quick Slice and Save &As…\tCtrl+Alt+U")), _(L("Slice a file into a G-code, save as")),
|
2018-09-20 06:40:22 +00:00
|
|
|
[this, repeat](wxCommandEvent&){
|
|
|
|
wxTheApp->CallAfter([this, repeat](){
|
2018-09-20 23:33:41 +00:00
|
|
|
quick_slice(qsSaveAs);
|
|
|
|
repeat->Enable(is_last_input_file());
|
2018-09-20 06:40:22 +00:00
|
|
|
}); }, "cog_go.png");
|
|
|
|
repeat = append_menu_item(fileMenu, wxID_ANY, _(L("&Repeat Last Quick Slice\tCtrl+Shift+U")), _(L("Repeat last quick slice")),
|
|
|
|
[this](wxCommandEvent&){
|
|
|
|
wxTheApp->CallAfter([this](){
|
2018-09-20 23:33:41 +00:00
|
|
|
quick_slice(qsReslice);
|
2018-09-20 06:40:22 +00:00
|
|
|
}); }, "cog_go.png");
|
|
|
|
repeat->Enable(0);
|
|
|
|
fileMenu->AppendSeparator();
|
2018-09-20 23:33:41 +00:00
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("Slice to SV&G…\tCtrl+G")), _(L("Slice file to a multi-layer SVG")),
|
|
|
|
[this](wxCommandEvent&){ quick_slice(qsSaveAs | qsExportSVG); }, "shape_handles.png");
|
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("Slice to PNG…")), _(L("Slice file to a set of PNG files")),
|
2018-09-20 06:40:22 +00:00
|
|
|
[this](wxCommandEvent&){ slice_to_png(); /*$self->quick_slice(save_as = > 0, export_png = > 1);*/ }, "shape_handles.png");
|
|
|
|
m_menu_item_reslice_now = append_menu_item(fileMenu, wxID_ANY, _(L("(&Re)Slice Now\tCtrl+S")), _(L("Start new slicing process")),
|
|
|
|
[this](wxCommandEvent&){ reslice_now(); }, "shape_handles.png");
|
|
|
|
fileMenu->AppendSeparator();
|
2018-09-20 23:33:41 +00:00
|
|
|
append_menu_item(fileMenu, wxID_ANY, _(L("Repair STL file…")), _(L("Automatically repair an STL file")),
|
2018-09-20 06:40:22 +00:00
|
|
|
[this](wxCommandEvent&){ repair_stl(); }, "wrench.png");
|
|
|
|
fileMenu->AppendSeparator();
|
|
|
|
append_menu_item(fileMenu, wxID_EXIT, _(L("&Quit")), _(L("Quit Slic3r")),
|
|
|
|
[this](wxCommandEvent&){ Close(false); } );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plater menu
|
2018-10-17 10:17:25 +00:00
|
|
|
if (m_plater) {
|
|
|
|
m_plater_menu = new wxMenu();
|
|
|
|
append_menu_item(m_plater_menu, wxID_ANY, _(L("Export G-code...")), _(L("Export current plate as G-code")),
|
2018-10-19 14:52:41 +00:00
|
|
|
[this](wxCommandEvent&){ m_plater->export_gcode(); }, "cog_go.png");
|
2018-10-17 10:17:25 +00:00
|
|
|
append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as STL...")), _(L("Export current plate as STL")),
|
2018-10-19 14:52:41 +00:00
|
|
|
[this](wxCommandEvent&){ m_plater->export_stl(); }, "brick_go.png");
|
2018-10-17 10:17:25 +00:00
|
|
|
append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as AMF...")), _(L("Export current plate as AMF")),
|
2018-10-22 09:45:03 +00:00
|
|
|
[this](wxCommandEvent&){ m_plater->export_amf(); }, "brick_go.png");
|
2018-10-17 10:17:25 +00:00
|
|
|
append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as 3MF...")), _(L("Export current plate as 3MF")),
|
2018-10-19 13:27:19 +00:00
|
|
|
[this](wxCommandEvent&){ m_plater->export_3mf(); }, "brick_go.png");
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Window menu
|
|
|
|
auto windowMenu = new wxMenu();
|
|
|
|
{
|
|
|
|
size_t tab_offset = 0;
|
|
|
|
if (m_plater) {
|
|
|
|
append_menu_item(windowMenu, wxID_ANY, L("Select &Plater Tab\tCtrl+1"), L("Show the plater"),
|
|
|
|
[this](wxCommandEvent&){ select_tab(0); }, "application_view_tile.png");
|
|
|
|
tab_offset += 1;
|
|
|
|
}
|
|
|
|
if (tab_offset > 0) {
|
|
|
|
windowMenu->AppendSeparator();
|
|
|
|
}
|
|
|
|
append_menu_item(windowMenu, wxID_ANY, L("Select P&rint Settings Tab\tCtrl+2"), L("Show the print settings"),
|
|
|
|
[this, tab_offset](wxCommandEvent&){ select_tab(tab_offset + 0); }, "cog.png");
|
|
|
|
append_menu_item(windowMenu, wxID_ANY, L("Select &Filament Settings Tab\tCtrl+3"), L("Show the filament settings"),
|
|
|
|
[this, tab_offset](wxCommandEvent&){ select_tab(tab_offset + 1); }, "spool.png");
|
|
|
|
append_menu_item(windowMenu, wxID_ANY, L("Select Print&er Settings Tab\tCtrl+4"), L("Show the printer settings"),
|
|
|
|
[this, tab_offset](wxCommandEvent&){ select_tab(tab_offset + 2); }, "printer_empty.png");
|
|
|
|
}
|
|
|
|
|
|
|
|
// View menu
|
|
|
|
if (m_plater) {
|
|
|
|
m_viewMenu = new wxMenu();
|
2018-10-24 08:46:18 +00:00
|
|
|
// \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(m_viewMenu, wxID_ANY, _(L("Iso")) + "\t\xA0" + "0", _(L("Iso View")), [this](wxCommandEvent&){ select_view("iso"); });
|
2018-10-17 10:59:58 +00:00
|
|
|
m_viewMenu->AppendSeparator();
|
2018-10-24 08:46:18 +00:00
|
|
|
append_menu_item(m_viewMenu, wxID_ANY, _(L("Top")) + "\t\xA0" + "1", _(L("Top View")), [this](wxCommandEvent&){ select_view("top"); });
|
|
|
|
append_menu_item(m_viewMenu, wxID_ANY, _(L("Bottom")) + "\t\xA0" + "2", _(L("Bottom View")), [this](wxCommandEvent&){ select_view("bottom"); });
|
|
|
|
append_menu_item(m_viewMenu, wxID_ANY, _(L("Front")) + "\t\xA0" + "3", _(L("Front View")), [this](wxCommandEvent&){ select_view("front"); });
|
|
|
|
append_menu_item(m_viewMenu, wxID_ANY, _(L("Rear")) + "\t\xA0" + "4", _(L("Rear View")), [this](wxCommandEvent&){ select_view("rear"); });
|
|
|
|
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"); });
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Help menu
|
|
|
|
auto helpMenu = new wxMenu();
|
|
|
|
{
|
|
|
|
append_menu_item(helpMenu, wxID_ANY, _(L("Prusa 3D Drivers")), _(L("Open the Prusa3D drivers download page in your browser")),
|
|
|
|
[this](wxCommandEvent&){ wxLaunchDefaultBrowser("http://www.prusa3d.com/drivers/"); });
|
|
|
|
append_menu_item(helpMenu, wxID_ANY, _(L("Prusa Edition Releases")), _(L("Open the Prusa Edition releases page in your browser")),
|
|
|
|
[this](wxCommandEvent&){ wxLaunchDefaultBrowser("http://github.com/prusa3d/slic3r/releases"); });
|
|
|
|
//# my $versioncheck = $self->_append_menu_item($helpMenu, "Check for &Updates...", "Check for new Slic3r versions", sub{
|
|
|
|
//# wxTheApp->check_version(1);
|
|
|
|
//# });
|
|
|
|
//# $versioncheck->Enable(wxTheApp->have_version_check);
|
|
|
|
append_menu_item(helpMenu, wxID_ANY, _(L("Slic3r &Website")), _(L("Open the Slic3r website in your browser")),
|
|
|
|
[this](wxCommandEvent&){ wxLaunchDefaultBrowser("http://slic3r.org/"); });
|
|
|
|
append_menu_item(helpMenu, wxID_ANY, _(L("Slic3r &Manual")), _(L("Open the Slic3r manual in your browser")),
|
|
|
|
[this](wxCommandEvent&){ wxLaunchDefaultBrowser("http://manual.slic3r.org/"); });
|
|
|
|
helpMenu->AppendSeparator();
|
|
|
|
append_menu_item(helpMenu, wxID_ANY, _(L("System Info")), _(L("Show system information")),
|
2018-09-20 23:33:41 +00:00
|
|
|
[this](wxCommandEvent&){ wxGetApp().system_info(); });
|
2018-09-20 06:40:22 +00:00
|
|
|
append_menu_item(helpMenu, wxID_ANY, _(L("Show &Configuration Folder")), _(L("Show user configuration folder (datadir)")),
|
|
|
|
[this](wxCommandEvent&){ Slic3r::GUI::desktop_open_datadir_folder(); });
|
|
|
|
append_menu_item(helpMenu, wxID_ANY, _(L("Report an Issue")), _(L("Report an issue on the Slic3r Prusa Edition")),
|
|
|
|
[this](wxCommandEvent&){ wxLaunchDefaultBrowser("http://github.com/prusa3d/slic3r/issues/new"); });
|
|
|
|
append_menu_item(helpMenu, wxID_ANY, _(L("&About Slic3r")), _(L("Show about dialog")),
|
|
|
|
[this](wxCommandEvent&){ Slic3r::GUI::about(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
// menubar
|
|
|
|
// assign menubar to frame after appending items, otherwise special items
|
|
|
|
// will not be handled correctly
|
|
|
|
{
|
|
|
|
auto menubar = new wxMenuBar();
|
|
|
|
menubar->Append(fileMenu, L("&File"));
|
|
|
|
if (m_plater_menu) menubar->Append(m_plater_menu, L("&Plater")) ;
|
|
|
|
menubar->Append(windowMenu, L("&Window"));
|
|
|
|
if (m_viewMenu) menubar->Append(m_viewMenu, L("&View"));
|
|
|
|
// Add additional menus from C++
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().add_config_menu(menubar);
|
2018-09-20 06:40:22 +00:00
|
|
|
menubar->Append(helpMenu, L("&Help"));
|
|
|
|
SetMenuBar(menubar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::slice_to_png(){
|
|
|
|
// m_plater->stop_background_process();
|
|
|
|
// m_plater->async_apply_config();
|
|
|
|
m_appController->print_ctl()->slice_to_png();
|
|
|
|
}
|
|
|
|
|
|
|
|
// To perform the "Quck Slice", "Quick Slice and Save As", "Repeat last Quick Slice" and "Slice to SVG".
|
2018-09-20 23:33:41 +00:00
|
|
|
void MainFrame::quick_slice(const int qs){
|
2018-09-20 06:40:22 +00:00
|
|
|
// my $progress_dialog;
|
|
|
|
wxString input_file;
|
|
|
|
// eval
|
|
|
|
// {
|
|
|
|
// validate configuration
|
2018-09-20 23:33:41 +00:00
|
|
|
auto config = wxGetApp().preset_bundle->full_config();
|
2018-09-20 06:40:22 +00:00
|
|
|
config.validate();
|
|
|
|
|
|
|
|
// select input file
|
2018-09-20 23:33:41 +00:00
|
|
|
if (!(qs & qsReslice)) {
|
2018-09-20 06:40:22 +00:00
|
|
|
auto dlg = new wxFileDialog(this, _(L("Choose a file to slice (STL/OBJ/AMF/3MF/PRUSA):")),
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().app_config->get_last_dir(), "",
|
2018-10-04 09:12:55 +00:00
|
|
|
file_wildcards[FT_MODEL], wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
2018-09-20 06:40:22 +00:00
|
|
|
if (dlg->ShowModal() != wxID_OK) {
|
|
|
|
dlg->Destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
input_file = dlg->GetPath();
|
|
|
|
dlg->Destroy();
|
2018-09-20 23:33:41 +00:00
|
|
|
if (!(qs & qsExportSVG))
|
2018-09-20 06:40:22 +00:00
|
|
|
m_qs_last_input_file = input_file;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (m_qs_last_input_file.IsEmpty()) {
|
|
|
|
auto dlg = new wxMessageDialog(this, _(L("No previously sliced file.")),
|
|
|
|
_(L("Error")), wxICON_ERROR | wxOK);
|
|
|
|
dlg->ShowModal();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (std::ifstream(m_qs_last_input_file.char_str())) {
|
|
|
|
auto dlg = new wxMessageDialog(this, _(L("Previously sliced file ("))+m_qs_last_input_file+_(L(") not found.")),
|
|
|
|
_(L("File Not Found")), wxICON_ERROR | wxOK);
|
|
|
|
dlg->ShowModal();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
input_file = m_qs_last_input_file;
|
|
|
|
}
|
|
|
|
auto input_file_basename = get_base_name(input_file);
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().app_config->update_skein_dir(get_dir_name(input_file));
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
auto bed_shape = Slic3r::Polygon::new_scale(config.option<ConfigOptionPoints>("bed_shape")->values);
|
|
|
|
// auto print_center = Slic3r::Pointf->new_unscale(bed_shape.bounding_box().center());
|
|
|
|
//
|
|
|
|
// auto sprint = new Slic3r::Print::Simple(
|
|
|
|
// print_center = > print_center,
|
|
|
|
// status_cb = > [](int percent, const wxString& msg){
|
2018-09-20 23:33:41 +00:00
|
|
|
// m_progress_dialog->Update(percent, msg+"…");
|
2018-09-20 06:40:22 +00:00
|
|
|
// });
|
|
|
|
|
|
|
|
// keep model around
|
|
|
|
auto model = Slic3r::Model::read_from_file(input_file.ToStdString());
|
|
|
|
|
|
|
|
// sprint->apply_config(config);
|
|
|
|
// sprint->set_model(model);
|
|
|
|
|
|
|
|
// Copy the names of active presets into the placeholder parser.
|
2018-09-20 23:33:41 +00:00
|
|
|
// wxGetApp().preset_bundle->export_selections(sprint->placeholder_parser);
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
// select output file
|
|
|
|
wxString output_file;
|
2018-09-20 23:33:41 +00:00
|
|
|
if (qs & qsReslice) {
|
2018-09-20 06:40:22 +00:00
|
|
|
if (!m_qs_last_output_file.IsEmpty())
|
|
|
|
output_file = m_qs_last_output_file;
|
|
|
|
}
|
2018-09-20 23:33:41 +00:00
|
|
|
else if (qs & qsSaveAs) {
|
2018-09-20 06:40:22 +00:00
|
|
|
// The following line may die if the output_filename_format template substitution fails.
|
|
|
|
// output_file = sprint->output_filepath;
|
|
|
|
// if (export_svg)
|
|
|
|
// output_file = ~s / \.[gG][cC][oO][dD][eE]$ / .svg /;
|
2018-09-20 23:33:41 +00:00
|
|
|
auto dlg = new wxFileDialog(this, _(L("Save ")) + (qs & qsExportSVG ? _(L("SVG")) : _(L("G-code"))) + _(L(" file as:")),
|
|
|
|
wxGetApp().app_config->get_last_output_dir(get_dir_name(output_file)), get_base_name(input_file),
|
2018-10-04 09:12:55 +00:00
|
|
|
qs & qsExportSVG ? file_wildcards[FT_SVG] : file_wildcards[FT_GCODE],
|
2018-09-20 06:40:22 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
|
|
|
if (dlg->ShowModal() != wxID_OK) {
|
|
|
|
dlg->Destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
output_file = dlg->GetPath();
|
|
|
|
dlg->Destroy();
|
2018-09-20 23:33:41 +00:00
|
|
|
if (!(qs & qsExportSVG))
|
2018-09-20 06:40:22 +00:00
|
|
|
m_qs_last_output_file = output_file;
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().app_config->update_last_output_dir(get_dir_name(output_file));
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
2018-09-20 23:33:41 +00:00
|
|
|
else if (qs & qsExportPNG) {
|
2018-09-20 06:40:22 +00:00
|
|
|
// output_file = sprint->output_filepath;
|
|
|
|
// output_file = ~s / \.[gG][cC][oO][dD][eE]$ / .zip / ;
|
|
|
|
auto dlg = new wxFileDialog(this, _(L("Save zip file as:")),
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().app_config->get_last_output_dir(get_dir_name(output_file)),
|
2018-09-20 06:40:22 +00:00
|
|
|
get_base_name(output_file), "*.zip", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
|
|
|
if (dlg->ShowModal() != wxID_OK) {
|
|
|
|
dlg->Destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
output_file = dlg->GetPath();
|
|
|
|
dlg->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// show processbar dialog
|
2018-09-20 23:33:41 +00:00
|
|
|
m_progress_dialog = new wxProgressDialog(_(L("Slicing…")), _(L("Processing ")) + input_file_basename + "…",
|
2018-09-20 06:40:22 +00:00
|
|
|
100, this, 4);
|
|
|
|
m_progress_dialog->Pulse();
|
|
|
|
{
|
|
|
|
// my @warnings = ();
|
|
|
|
// local $SIG{ __WARN__ } = sub{ push @warnings, $_[0] };
|
|
|
|
|
|
|
|
// sprint->output_file(output_file);
|
|
|
|
// if (export_svg) {
|
|
|
|
// sprint->export_svg();
|
|
|
|
// }
|
|
|
|
// else if(export_png) {
|
|
|
|
// sprint->export_png();
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// sprint->export_gcode();
|
|
|
|
// }
|
|
|
|
// sprint->status_cb(undef);
|
|
|
|
// Slic3r::GUI::warning_catcher($self)->($_) for @warnings;
|
|
|
|
}
|
|
|
|
m_progress_dialog->Destroy();
|
|
|
|
m_progress_dialog = nullptr;
|
|
|
|
|
|
|
|
auto message = input_file_basename + _(L(" was successfully sliced."));
|
|
|
|
// wxTheApp->notify(message);
|
|
|
|
wxMessageDialog(this, message, _(L("Slicing Done!")), wxOK | wxICON_INFORMATION).ShowModal();
|
|
|
|
// };
|
|
|
|
// Slic3r::GUI::catch_error(this, [](){ if (m_progress_dialog) m_progress_dialog->Destroy(); });
|
|
|
|
}
|
|
|
|
|
2018-10-17 09:12:38 +00:00
|
|
|
void MainFrame::reslice_now()
|
|
|
|
{
|
|
|
|
if (m_plater)
|
|
|
|
m_plater->reslice();
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::repair_stl()
|
|
|
|
{
|
|
|
|
wxString input_file;
|
|
|
|
{
|
|
|
|
auto dlg = new wxFileDialog(this, _(L("Select the STL file to repair:")),
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().app_config->get_last_dir(), "",
|
2018-10-04 09:12:55 +00:00
|
|
|
file_wildcards[FT_STL], wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
2018-09-20 06:40:22 +00:00
|
|
|
if (dlg->ShowModal() != wxID_OK) {
|
|
|
|
dlg->Destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
input_file = dlg->GetPath();
|
|
|
|
dlg->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto output_file = input_file;
|
|
|
|
{
|
|
|
|
// output_file = ~s / \.[sS][tT][lL]$ / _fixed.obj / ;
|
|
|
|
auto dlg = new wxFileDialog( this, L("Save OBJ file (less prone to coordinate errors than STL) as:"),
|
|
|
|
get_dir_name(output_file), get_base_name(output_file),
|
2018-10-04 09:12:55 +00:00
|
|
|
file_wildcards[FT_OBJ], wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
2018-09-20 06:40:22 +00:00
|
|
|
if (dlg->ShowModal() != wxID_OK) {
|
|
|
|
dlg->Destroy();
|
|
|
|
return /*undef*/;
|
|
|
|
}
|
|
|
|
output_file = dlg->GetPath();
|
|
|
|
dlg->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto tmesh = new Slic3r::TriangleMesh();
|
|
|
|
tmesh->ReadSTLFile(input_file.char_str());
|
|
|
|
tmesh->repair();
|
|
|
|
tmesh->WriteOBJFile(output_file.char_str());
|
|
|
|
Slic3r::GUI::show_info(this, L("Your file was repaired."), L("Repair"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::export_config()
|
|
|
|
{
|
|
|
|
// Generate a cummulative configuration for the selected print, filaments and printer.
|
2018-09-20 23:33:41 +00:00
|
|
|
auto config = wxGetApp().preset_bundle->full_config();
|
2018-09-20 06:40:22 +00:00
|
|
|
// Validate the cummulative configuration.
|
|
|
|
auto valid = config.validate();
|
|
|
|
if (!valid.empty()) {
|
|
|
|
// Slic3r::GUI::catch_error(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Ask user for the file name for the config file.
|
|
|
|
auto dlg = new wxFileDialog(this, _(L("Save configuration as:")),
|
2018-09-20 23:33:41 +00:00
|
|
|
!m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
|
2018-09-20 06:40:22 +00:00
|
|
|
!m_last_config.IsEmpty() ? get_base_name(m_last_config) : "config.ini",
|
2018-10-04 09:12:55 +00:00
|
|
|
file_wildcards[FT_INI], wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
2018-09-21 13:42:31 +00:00
|
|
|
wxString file;
|
|
|
|
if (dlg->ShowModal() == wxID_OK)
|
|
|
|
file = dlg->GetPath();
|
2018-09-20 06:40:22 +00:00
|
|
|
dlg->Destroy();
|
|
|
|
if (!file.IsEmpty()) {
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().app_config->update_config_dir(get_dir_name(file));
|
2018-09-20 06:40:22 +00:00
|
|
|
m_last_config = file;
|
|
|
|
config.save(file.ToStdString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load a config file containing a Print, Filament & Printer preset.
|
|
|
|
void MainFrame::load_config_file(wxString file/* = wxEmptyString*/)
|
|
|
|
{
|
|
|
|
if (file.IsEmpty()) {
|
2018-09-20 23:33:41 +00:00
|
|
|
if (!wxGetApp().check_unsaved_changes())
|
2018-09-20 06:40:22 +00:00
|
|
|
return;
|
|
|
|
auto dlg = new wxFileDialog(this, _(L("Select configuration to load:")),
|
2018-09-20 23:33:41 +00:00
|
|
|
!m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
|
2018-09-20 06:40:22 +00:00
|
|
|
"config.ini", "INI files (*.ini, *.gcode)|*.ini;*.INI;*.gcode;*.g", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
|
|
|
if (dlg->ShowModal() != wxID_OK)
|
|
|
|
return;
|
|
|
|
file = dlg->GetPath();
|
|
|
|
dlg->Destroy();
|
|
|
|
}
|
2018-10-17 09:12:38 +00:00
|
|
|
try {
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().preset_bundle->load_config_file(file.ToStdString());
|
2018-10-17 09:12:38 +00:00
|
|
|
} catch (std::exception & /* ex */) {
|
|
|
|
// Dont proceed further if the config file cannot be loaded.
|
|
|
|
// if (Slic3r::GUI::catch_error(this))
|
|
|
|
// return;
|
|
|
|
}
|
2018-09-20 06:40:22 +00:00
|
|
|
for (auto tab : m_options_tabs )
|
|
|
|
tab.second->load_current_preset();
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().app_config->update_config_dir(get_dir_name(file));
|
2018-09-20 06:40:22 +00:00
|
|
|
m_last_config = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::export_configbundle()
|
|
|
|
{
|
2018-09-20 23:33:41 +00:00
|
|
|
if (!wxGetApp().check_unsaved_changes())
|
2018-09-20 06:40:22 +00:00
|
|
|
return;
|
|
|
|
// validate current configuration in case it's dirty
|
2018-09-20 23:33:41 +00:00
|
|
|
auto valid = wxGetApp().preset_bundle->full_config().validate();
|
2018-09-20 06:40:22 +00:00
|
|
|
if (!valid.empty()) {
|
|
|
|
// Slic3r::GUI::catch_error(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Ask user for a file name.
|
|
|
|
auto dlg = new wxFileDialog(this, _(L("Save presets bundle as:")),
|
2018-09-20 23:33:41 +00:00
|
|
|
!m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
|
2018-09-20 06:40:22 +00:00
|
|
|
"Slic3r_config_bundle.ini",
|
2018-10-04 09:12:55 +00:00
|
|
|
file_wildcards[FT_INI], wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
2018-09-21 13:42:31 +00:00
|
|
|
wxString file;
|
|
|
|
if (dlg->ShowModal() == wxID_OK)
|
|
|
|
file = dlg->GetPath();
|
2018-09-20 06:40:22 +00:00
|
|
|
dlg->Destroy();
|
|
|
|
if (!file.IsEmpty()) {
|
|
|
|
// Export the config bundle.
|
2018-10-17 09:12:38 +00:00
|
|
|
wxGetApp().app_config->update_config_dir(get_dir_name(file));
|
|
|
|
try {
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().preset_bundle->export_configbundle(file.ToStdString());
|
2018-10-17 09:12:38 +00:00
|
|
|
} catch (std::exception & /* ex */) {
|
2018-09-20 06:40:22 +00:00
|
|
|
// Slic3r::GUI::catch_error(this);
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loading a config bundle with an external file name used to be used
|
|
|
|
// to auto - install a config bundle on a fresh user account,
|
|
|
|
// but that behavior was not documented and likely buggy.
|
2018-10-17 09:12:38 +00:00
|
|
|
void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool reset_user_profile*/)
|
|
|
|
{
|
2018-09-20 23:33:41 +00:00
|
|
|
if (!wxGetApp().check_unsaved_changes())
|
2018-09-20 06:40:22 +00:00
|
|
|
return;
|
|
|
|
if (file.IsEmpty()) {
|
|
|
|
auto dlg = new wxFileDialog(this, _(L("Select configuration to load:")),
|
2018-09-20 23:33:41 +00:00
|
|
|
!m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
|
2018-10-04 09:12:55 +00:00
|
|
|
"config.ini", file_wildcards[FT_INI], wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
2018-09-20 06:40:22 +00:00
|
|
|
if (dlg->ShowModal() != wxID_OK)
|
|
|
|
return;
|
|
|
|
file = dlg->GetPath();
|
|
|
|
dlg->Destroy();
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:33:41 +00:00
|
|
|
wxGetApp().app_config->update_config_dir(get_dir_name(file));
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
auto presets_imported = 0;
|
2018-10-17 09:12:38 +00:00
|
|
|
try {
|
2018-09-20 23:33:41 +00:00
|
|
|
presets_imported = wxGetApp().preset_bundle->load_configbundle(file.ToStdString());
|
2018-10-17 09:12:38 +00:00
|
|
|
} catch (std::exception & /* ex */) {
|
2018-09-20 06:40:22 +00:00
|
|
|
// Slic3r::GUI::catch_error(this) and return;
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
2018-09-20 06:40:22 +00:00
|
|
|
|
|
|
|
// Load the currently selected preset into the GUI, update the preset selection box.
|
|
|
|
for (auto tab : m_options_tabs)
|
|
|
|
tab.second->load_current_preset();
|
|
|
|
|
|
|
|
const auto message = wxString::Format(_(L("%d presets successfully imported.")), presets_imported);
|
|
|
|
Slic3r::GUI::show_info(this, message, "Info");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load a provied DynamicConfig into the Print / Filament / Printer tabs, thus modifying the active preset.
|
|
|
|
// Also update the platter with the new presets.
|
2018-10-17 09:12:38 +00:00
|
|
|
void MainFrame::load_config(const DynamicPrintConfig& config)
|
|
|
|
{
|
2018-09-20 06:40:22 +00:00
|
|
|
for (auto tab : m_options_tabs)
|
|
|
|
tab.second->load_config(config);
|
2018-10-17 09:12:38 +00:00
|
|
|
if (m_plater)
|
|
|
|
m_plater->on_config_change(config);
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 09:12:38 +00:00
|
|
|
void MainFrame::select_tab(size_t tab) const
|
|
|
|
{
|
2018-09-20 06:40:22 +00:00
|
|
|
m_tabpanel->SetSelection(tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a camera direction, zoom to all objects.
|
2018-10-17 09:12:38 +00:00
|
|
|
void MainFrame::select_view(const std::string& direction)
|
|
|
|
{
|
2018-10-17 10:59:58 +00:00
|
|
|
if (m_plater)
|
|
|
|
m_plater->select_view(direction);
|
2018-09-20 06:40:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 14:27:02 +00:00
|
|
|
void MainFrame::on_presets_changed(SimpleEvent &event)
|
|
|
|
{
|
|
|
|
auto *tab = dynamic_cast<Tab*>(event.GetEventObject());
|
|
|
|
wxASSERT(tab != nullptr);
|
|
|
|
if (tab == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update preset combo boxes(Print settings, Filament, Material, Printer) from their respective tabs.
|
|
|
|
auto presets = tab->get_presets();
|
2018-10-04 09:12:55 +00:00
|
|
|
if (m_plater != nullptr && presets != nullptr) {
|
2018-10-03 14:27:02 +00:00
|
|
|
auto reload_dependent_tabs = tab->get_dependent_tabs();
|
|
|
|
|
|
|
|
// FIXME: The preset type really should be a property of Tab instead
|
2018-10-09 10:41:05 +00:00
|
|
|
Slic3r::Preset::Type preset_type = tab->type();
|
|
|
|
if (preset_type == Slic3r::Preset::TYPE_INVALID){
|
2018-10-03 14:27:02 +00:00
|
|
|
wxASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_plater->sidebar().update_presets(preset_type);
|
|
|
|
|
|
|
|
if (preset_type == Slic3r::Preset::TYPE_PRINTER) {
|
|
|
|
// Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors.
|
|
|
|
// XXX: Do this in a more C++ way
|
2018-10-17 09:12:38 +00:00
|
|
|
for (const auto tab_name_other : { "print", "filament", "sla_material" }) {
|
2018-10-03 14:27:02 +00:00
|
|
|
Tab* cur_tab = m_options_tabs[tab_name_other];
|
|
|
|
// If the printer tells us that the print or filament preset has been switched or invalidated,
|
|
|
|
// refresh the print or filament tab page.Otherwise just refresh the combo box.
|
|
|
|
if (reload_dependent_tabs.empty() ||
|
|
|
|
find(reload_dependent_tabs.begin(), reload_dependent_tabs.end(), tab_name_other) ==
|
|
|
|
reload_dependent_tabs.end() )
|
|
|
|
cur_tab->update_tab_ui();
|
|
|
|
else
|
|
|
|
cur_tab->load_current_preset();
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 09:12:38 +00:00
|
|
|
m_plater->on_config_change(*tab->get_config());
|
2018-10-03 14:27:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 11:53:45 +00:00
|
|
|
void MainFrame::on_value_changed(wxCommandEvent& event)
|
2018-10-09 10:41:05 +00:00
|
|
|
{
|
2018-10-10 11:53:45 +00:00
|
|
|
auto *tab = dynamic_cast<Tab*>(event.GetEventObject());
|
|
|
|
wxASSERT(tab != nullptr);
|
|
|
|
if (tab == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto opt_key = event.GetString();
|
|
|
|
if (m_plater) {
|
2018-10-17 09:12:38 +00:00
|
|
|
m_plater->on_config_change(*tab->get_config()); // propagate config change events to the plater
|
|
|
|
if (opt_key == "extruders_count"){
|
|
|
|
auto value = event.GetInt();
|
|
|
|
m_plater->on_extruders_change(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Don't save while loading for the first time.
|
|
|
|
if (m_loaded) {
|
|
|
|
AppConfig &cfg = *wxGetApp().app_config;
|
|
|
|
if (cfg.get("autosave") == "1")
|
|
|
|
cfg.save();
|
2018-10-10 11:53:45 +00:00
|
|
|
}
|
2018-10-09 10:41:05 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 06:40:22 +00:00
|
|
|
// Called after the Preferences dialog is closed and the program settings are saved.
|
|
|
|
// Update the UI based on the current preferences.
|
|
|
|
void MainFrame::update_ui_from_settings()
|
|
|
|
{
|
2018-09-20 23:33:41 +00:00
|
|
|
m_menu_item_reslice_now->Enable(wxGetApp().app_config->get("background_processing") == "1");
|
2018-09-20 06:40:22 +00:00
|
|
|
// if (m_plater) m_plater->update_ui_from_settings();
|
|
|
|
std::vector<std::string> tab_names = { "print", "filament", "printer" };
|
|
|
|
for (auto tab_name: tab_names)
|
|
|
|
m_options_tabs[tab_name]->update_ui_from_settings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string MainFrame::get_base_name(const wxString full_name) const
|
|
|
|
{
|
|
|
|
return boost::filesystem::path(full_name).filename().string();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string MainFrame::get_dir_name(const wxString full_name) const
|
|
|
|
{
|
|
|
|
return boost::filesystem::path(full_name).parent_path().string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // GUI
|
2018-09-20 23:33:41 +00:00
|
|
|
} // Slic3r
|