MainFrame.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. #include "MainFrame.hpp"
  2. #include <wx/panel.h>
  3. #include <wx/notebook.h>
  4. #include <wx/icon.h>
  5. #include <wx/sizer.h>
  6. #include <wx/menu.h>
  7. #include <wx/progdlg.h>
  8. #include <wx/tooltip.h>
  9. #include <wx/glcanvas.h>
  10. #include <wx/debug.h>
  11. #include <boost/algorithm/string/predicate.hpp>
  12. #include "libslic3r/Print.hpp"
  13. #include "libslic3r/Polygon.hpp"
  14. #include "libslic3r/SLAPrint.hpp"
  15. #include "Tab.hpp"
  16. #include "PresetBundle.hpp"
  17. #include "ProgressStatusBar.hpp"
  18. #include "3DScene.hpp"
  19. #include "AppConfig.hpp"
  20. #include "PrintHostDialogs.hpp"
  21. #include "wxExtensions.hpp"
  22. #include "GUI_ObjectList.hpp"
  23. #include "I18N.hpp"
  24. #include <fstream>
  25. #include "GUI_App.hpp"
  26. namespace Slic3r {
  27. namespace GUI {
  28. MainFrame::MainFrame() :
  29. DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "mainframe"),
  30. m_printhost_queue_dlg(new PrintHostQueueDialog(this))
  31. {
  32. // Fonts were created by the DPIFrame constructor for the monitor, on which the window opened.
  33. wxGetApp().update_fonts(this);
  34. #ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
  35. this->SetFont(this->normal_font());
  36. #endif
  37. // Load the icon either from the exe, or from the ico file.
  38. #if _WIN32
  39. {
  40. TCHAR szExeFileName[MAX_PATH];
  41. GetModuleFileName(nullptr, szExeFileName, MAX_PATH);
  42. SetIcon(wxIcon(szExeFileName, wxBITMAP_TYPE_ICO));
  43. }
  44. #else
  45. SetIcon(wxIcon(Slic3r::var("PrusaSlicer_128px.png"), wxBITMAP_TYPE_PNG));
  46. #endif // _WIN32
  47. // initialize status bar
  48. m_statusbar = new ProgressStatusBar(this);
  49. m_statusbar->embed(this);
  50. m_statusbar->set_status_text(_(L("Version")) + " " +
  51. SLIC3R_VERSION +
  52. _(L(" - Remember to check for updates at http://github.com/prusa3d/PrusaSlicer/releases")));
  53. /* Load default preset bitmaps before a tabpanel initialization,
  54. * but after filling of an em_unit value
  55. */
  56. wxGetApp().preset_bundle->load_default_preset_bitmaps(this);
  57. // initialize tabpanel and menubar
  58. init_tabpanel();
  59. init_menubar();
  60. // set default tooltip timer in msec
  61. // SetAutoPop supposedly accepts long integers but some bug doesn't allow for larger values
  62. // (SetAutoPop is not available on GTK.)
  63. wxToolTip::SetAutoPop(32767);
  64. m_loaded = true;
  65. // initialize layout
  66. auto sizer = new wxBoxSizer(wxVERTICAL);
  67. if (m_tabpanel)
  68. sizer->Add(m_tabpanel, 1, wxEXPAND);
  69. sizer->SetSizeHints(this);
  70. SetSizer(sizer);
  71. Fit();
  72. const wxSize min_size = wxSize(76*wxGetApp().em_unit(), 49*wxGetApp().em_unit());
  73. #ifdef __APPLE__
  74. // Using SetMinSize() on Mac messes up the window position in some cases
  75. // cf. https://groups.google.com/forum/#!topic/wx-users/yUKPBBfXWO0
  76. SetSize(min_size/*wxSize(760, 490)*/);
  77. #else
  78. SetMinSize(min_size/*wxSize(760, 490)*/);
  79. SetSize(GetMinSize());
  80. #endif
  81. Layout();
  82. update_title();
  83. // declare events
  84. Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event) {
  85. if (event.CanVeto() && !wxGetApp().check_unsaved_changes()) {
  86. event.Veto();
  87. return;
  88. }
  89. // Weird things happen as the Paint messages are floating around the windows being destructed.
  90. // Avoid the Paint messages by hiding the main window.
  91. // Also the application closes much faster without these unnecessary screen refreshes.
  92. // In addition, there were some crashes due to the Paint events sent to already destructed windows.
  93. this->Show(false);
  94. // Save the slic3r.ini.Usually the ini file is saved from "on idle" callback,
  95. // but in rare cases it may not have been called yet.
  96. wxGetApp().app_config->save();
  97. // if (m_plater)
  98. // m_plater->print = undef;
  99. _3DScene::remove_all_canvases();
  100. // Slic3r::GUI::deregister_on_request_update_callback();
  101. // set to null tabs and a platter
  102. // to avoid any manipulations with them from App->wxEVT_IDLE after of the mainframe closing
  103. wxGetApp().tabs_list.clear();
  104. wxGetApp().plater_ = nullptr;
  105. // propagate event
  106. event.Skip();
  107. });
  108. Bind(wxEVT_ACTIVATE, [this](wxActivateEvent& event) {
  109. if (m_plater != nullptr && event.GetActive())
  110. m_plater->on_activate();
  111. event.Skip();
  112. });
  113. wxGetApp().persist_window_geometry(this, true);
  114. update_ui_from_settings(); // FIXME (?)
  115. }
  116. void MainFrame::update_title()
  117. {
  118. wxString title = wxEmptyString;
  119. if (m_plater != nullptr)
  120. {
  121. // m_plater->get_project_filename() produces file name including path, but excluding extension.
  122. // Don't try to remove the extension, it would remove part of the file name after the last dot!
  123. wxString project = from_path(into_path(m_plater->get_project_filename()).filename());
  124. if (!project.empty())
  125. title += (project + " - ");
  126. }
  127. title += (wxString(SLIC3R_BUILD_ID) + " " + _(L("based on Slic3r")));
  128. SetTitle(title);
  129. }
  130. void MainFrame::init_tabpanel()
  131. {
  132. // wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on Windows 10
  133. // with multiple high resolution displays connected.
  134. m_tabpanel = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME);
  135. #ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
  136. m_tabpanel->SetFont(Slic3r::GUI::wxGetApp().normal_font());
  137. #endif
  138. m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxEvent&) {
  139. auto panel = m_tabpanel->GetCurrentPage();
  140. if (panel == nullptr)
  141. return;
  142. auto& tabs_list = wxGetApp().tabs_list;
  143. if (find(tabs_list.begin(), tabs_list.end(), panel) != tabs_list.end()) {
  144. // On GTK, the wxEVT_NOTEBOOK_PAGE_CHANGED event is triggered
  145. // before the MainFrame is fully set up.
  146. static_cast<Tab*>(panel)->OnActivate();
  147. }
  148. });
  149. m_plater = new Slic3r::GUI::Plater(m_tabpanel, this);
  150. wxGetApp().plater_ = m_plater;
  151. m_tabpanel->AddPage(m_plater, _(L("Plater")));
  152. wxGetApp().obj_list()->create_popup_menus();
  153. // The following event is emited by Tab implementation on config value change.
  154. Bind(EVT_TAB_VALUE_CHANGED, &MainFrame::on_value_changed, this); // #ys_FIXME_to_delete
  155. // The following event is emited by Tab on preset selection,
  156. // or when the preset's "modified" status changes.
  157. Bind(EVT_TAB_PRESETS_CHANGED, &MainFrame::on_presets_changed, this); // #ys_FIXME_to_delete
  158. create_preset_tabs();
  159. if (m_plater) {
  160. // load initial config
  161. auto full_config = wxGetApp().preset_bundle->full_config();
  162. m_plater->on_config_change(full_config);
  163. // Show a correct number of filament fields.
  164. // nozzle_diameter is undefined when SLA printer is selected
  165. if (full_config.has("nozzle_diameter")) {
  166. m_plater->on_extruders_change(full_config.option<ConfigOptionFloats>("nozzle_diameter")->values.size());
  167. }
  168. }
  169. }
  170. void MainFrame::create_preset_tabs()
  171. {
  172. wxGetApp().update_label_colours_from_appconfig();
  173. add_created_tab(new TabPrint(m_tabpanel));
  174. add_created_tab(new TabFilament(m_tabpanel));
  175. add_created_tab(new TabSLAPrint(m_tabpanel));
  176. add_created_tab(new TabSLAMaterial(m_tabpanel));
  177. add_created_tab(new TabPrinter(m_tabpanel));
  178. }
  179. void MainFrame::add_created_tab(Tab* panel)
  180. {
  181. panel->create_preset_tab();
  182. const auto printer_tech = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology();
  183. if (panel->supports_printer_technology(printer_tech))
  184. m_tabpanel->AddPage(panel, panel->title());
  185. }
  186. bool MainFrame::can_start_new_project() const
  187. {
  188. return (m_plater != nullptr) && !m_plater->model().objects.empty();
  189. }
  190. bool MainFrame::can_save() const
  191. {
  192. return (m_plater != nullptr) && !m_plater->model().objects.empty();
  193. }
  194. bool MainFrame::can_export_model() const
  195. {
  196. return (m_plater != nullptr) && !m_plater->model().objects.empty();
  197. }
  198. bool MainFrame::can_export_supports() const
  199. {
  200. if ((m_plater == nullptr) || (m_plater->printer_technology() != ptSLA) || m_plater->model().objects.empty())
  201. return false;
  202. bool can_export = false;
  203. const PrintObjects& objects = m_plater->sla_print().objects();
  204. for (const SLAPrintObject* object : objects)
  205. {
  206. if (object->has_mesh(slaposBasePool) || object->has_mesh(slaposSupportTree))
  207. {
  208. can_export = true;
  209. break;
  210. }
  211. }
  212. return can_export;
  213. }
  214. bool MainFrame::can_export_gcode() const
  215. {
  216. if (m_plater == nullptr)
  217. return false;
  218. if (m_plater->model().objects.empty())
  219. return false;
  220. if (m_plater->is_export_gcode_scheduled())
  221. return false;
  222. // TODO:: add other filters
  223. return true;
  224. }
  225. bool MainFrame::can_slice() const
  226. {
  227. bool bg_proc = wxGetApp().app_config->get("background_processing") == "1";
  228. return (m_plater != nullptr) ? !m_plater->model().objects.empty() && !bg_proc : false;
  229. }
  230. bool MainFrame::can_change_view() const
  231. {
  232. int page_id = m_tabpanel->GetSelection();
  233. return page_id != wxNOT_FOUND && dynamic_cast<const Slic3r::GUI::Plater*>(m_tabpanel->GetPage((size_t)page_id)) != nullptr;
  234. }
  235. bool MainFrame::can_select() const
  236. {
  237. return (m_plater != nullptr) && !m_plater->model().objects.empty();
  238. }
  239. bool MainFrame::can_deselect() const
  240. {
  241. return (m_plater != nullptr) && !m_plater->is_selection_empty();
  242. }
  243. bool MainFrame::can_delete() const
  244. {
  245. return (m_plater != nullptr) && !m_plater->is_selection_empty();
  246. }
  247. bool MainFrame::can_delete_all() const
  248. {
  249. return (m_plater != nullptr) && !m_plater->model().objects.empty();
  250. }
  251. bool MainFrame::can_reslice() const
  252. {
  253. return (m_plater != nullptr) && !m_plater->model().objects.empty();
  254. }
  255. void MainFrame::on_dpi_changed(const wxRect &suggested_rect)
  256. {
  257. wxGetApp().update_fonts();
  258. this->SetFont(this->normal_font());
  259. /* Load default preset bitmaps before a tabpanel initialization,
  260. * but after filling of an em_unit value
  261. */
  262. wxGetApp().preset_bundle->load_default_preset_bitmaps(this);
  263. // update Plater
  264. wxGetApp().plater()->msw_rescale();
  265. // update Tabs
  266. for (auto tab : wxGetApp().tabs_list)
  267. tab->msw_rescale();
  268. wxMenuBar* menu_bar = this->GetMenuBar();
  269. for (size_t id = 0; id < menu_bar->GetMenuCount(); id++)
  270. msw_rescale_menu(menu_bar->GetMenu(id));
  271. // Workarounds for correct Window rendering after rescale
  272. /* Even if Window is maximized during moving,
  273. * first of all we should imitate Window resizing. So:
  274. * 1. cancel maximization, if it was set
  275. * 2. imitate resizing
  276. * 3. set maximization, if it was set
  277. */
  278. const bool is_maximized = this->IsMaximized();
  279. if (is_maximized)
  280. this->Maximize(false);
  281. /* To correct window rendering (especially redraw of a status bar)
  282. * we should imitate window resizing.
  283. */
  284. const wxSize& sz = this->GetSize();
  285. this->SetSize(sz.x + 1, sz.y + 1);
  286. this->SetSize(sz);
  287. this->Maximize(is_maximized);
  288. }
  289. static std::string menu_icon(const std::string& icon_name)
  290. {
  291. #ifdef __WXMSW__
  292. const std::string folder = "white\\";
  293. #else
  294. const std::string folder = "white/";
  295. #endif
  296. return wxGetApp().dark_mode_menus() ? folder+icon_name : icon_name;
  297. }
  298. void MainFrame::init_menubar()
  299. {
  300. #ifdef __APPLE__
  301. wxMenuBar::SetAutoWindowMenu(false);
  302. #endif
  303. // File menu
  304. wxMenu* fileMenu = new wxMenu;
  305. {
  306. append_menu_item(fileMenu, wxID_ANY, _(L("&New Project")) + "\tCtrl+N", _(L("Start a new project")),
  307. [this](wxCommandEvent&) { if (m_plater) m_plater->new_project(); }, "", nullptr,
  308. [this](){return m_plater != nullptr && can_start_new_project(); }, this);
  309. append_menu_item(fileMenu, wxID_ANY, _(L("&Open Project")) + dots + "\tCtrl+O", _(L("Open a project file")),
  310. [this](wxCommandEvent&) { if (m_plater) m_plater->load_project(); }, menu_icon("open"), nullptr,
  311. [this](){return m_plater != nullptr; }, this);
  312. append_menu_item(fileMenu, wxID_ANY, _(L("&Save Project")) + "\tCtrl+S", _(L("Save current project file")),
  313. [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(into_path(m_plater->get_project_filename(".3mf"))); }, menu_icon("save"), nullptr,
  314. [this](){return m_plater != nullptr && can_save(); }, this);
  315. #ifdef __APPLE__
  316. append_menu_item(fileMenu, wxID_ANY, _(L("Save Project &as")) + dots + "\tCtrl+Shift+S", _(L("Save current project file as")),
  317. #else
  318. append_menu_item(fileMenu, wxID_ANY, _(L("Save Project &as")) + dots + "\tCtrl+Alt+S", _(L("Save current project file as")),
  319. #endif // __APPLE__
  320. [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(); }, menu_icon("save"), nullptr,
  321. [this](){return m_plater != nullptr && can_save(); }, this);
  322. fileMenu->AppendSeparator();
  323. wxMenu* import_menu = new wxMenu();
  324. append_menu_item(import_menu, wxID_ANY, _(L("Import STL/OBJ/AM&F/3MF")) + dots + "\tCtrl+I", _(L("Load a model")),
  325. [this](wxCommandEvent&) { if (m_plater) m_plater->add_model(); }, menu_icon("import_plater"), nullptr,
  326. [this](){return m_plater != nullptr; }, this);
  327. import_menu->AppendSeparator();
  328. append_menu_item(import_menu, wxID_ANY, _(L("Import &Config")) + dots + "\tCtrl+L", _(L("Load exported configuration file")),
  329. [this](wxCommandEvent&) { load_config_file(); }, menu_icon("import_config"));
  330. append_menu_item(import_menu, wxID_ANY, _(L("Import Config from &project")) + dots +"\tCtrl+Alt+L", _(L("Load configuration from project file")),
  331. [this](wxCommandEvent&) { if (m_plater) m_plater->extract_config_from_project(); }, menu_icon("import_config"));
  332. import_menu->AppendSeparator();
  333. append_menu_item(import_menu, wxID_ANY, _(L("Import Config &Bundle")) + dots, _(L("Load presets from a bundle")),
  334. [this](wxCommandEvent&) { load_configbundle(); }, menu_icon("import_config_bundle"));
  335. append_submenu(fileMenu, import_menu, wxID_ANY, _(L("&Import")), "");
  336. wxMenu* export_menu = new wxMenu();
  337. wxMenuItem* item_export_gcode = append_menu_item(export_menu, wxID_ANY, _(L("Export &G-code")) + dots +"\tCtrl+G", _(L("Export current plate as G-code")),
  338. [this](wxCommandEvent&) { if (m_plater) m_plater->export_gcode(); }, menu_icon("export_gcode"), nullptr,
  339. [this](){return can_export_gcode(); }, this);
  340. m_changeable_menu_items.push_back(item_export_gcode);
  341. export_menu->AppendSeparator();
  342. append_menu_item(export_menu, wxID_ANY, _(L("Export plate as &STL")) + dots, _(L("Export current plate as STL")),
  343. [this](wxCommandEvent&) { if (m_plater) m_plater->export_stl(); }, menu_icon("export_plater"), nullptr,
  344. [this](){return can_export_model(); }, this);
  345. append_menu_item(export_menu, wxID_ANY, _(L("Export plate as STL including supports")) + dots, _(L("Export current plate as STL including supports")),
  346. [this](wxCommandEvent&) { if (m_plater) m_plater->export_stl(true); }, menu_icon("export_plater"), nullptr,
  347. [this](){return can_export_supports(); }, this);
  348. append_menu_item(export_menu, wxID_ANY, _(L("Export plate as &AMF")) + dots, _(L("Export current plate as AMF")),
  349. [this](wxCommandEvent&) { if (m_plater) m_plater->export_amf(); }, menu_icon("export_plater"), nullptr,
  350. [this](){return can_export_model(); }, this);
  351. export_menu->AppendSeparator();
  352. append_menu_item(export_menu, wxID_ANY, _(L("Export &Config")) +dots +"\tCtrl+E", _(L("Export current configuration to file")),
  353. [this](wxCommandEvent&) { export_config(); }, menu_icon("export_config"));
  354. append_menu_item(export_menu, wxID_ANY, _(L("Export Config &Bundle")) + dots, _(L("Export all presets to file")),
  355. [this](wxCommandEvent&) { export_configbundle(); }, menu_icon("export_config_bundle"));
  356. append_submenu(fileMenu, export_menu, wxID_ANY, _(L("&Export")), "");
  357. fileMenu->AppendSeparator();
  358. #if 0
  359. m_menu_item_repeat = nullptr;
  360. append_menu_item(fileMenu, wxID_ANY, _(L("Quick Slice")) +dots+ "\tCtrl+U", _(L("Slice a file into a G-code")),
  361. [this](wxCommandEvent&) {
  362. wxTheApp->CallAfter([this]() {
  363. quick_slice();
  364. m_menu_item_repeat->Enable(is_last_input_file());
  365. }); }, "cog_go.png");
  366. append_menu_item(fileMenu, wxID_ANY, _(L("Quick Slice and Save As")) +dots +"\tCtrl+Alt+U", _(L("Slice a file into a G-code, save as")),
  367. [this](wxCommandEvent&) {
  368. wxTheApp->CallAfter([this]() {
  369. quick_slice(qsSaveAs);
  370. m_menu_item_repeat->Enable(is_last_input_file());
  371. }); }, "cog_go.png");
  372. m_menu_item_repeat = append_menu_item(fileMenu, wxID_ANY, _(L("Repeat Last Quick Slice")) +"\tCtrl+Shift+U", _(L("Repeat last quick slice")),
  373. [this](wxCommandEvent&) {
  374. wxTheApp->CallAfter([this]() {
  375. quick_slice(qsReslice);
  376. }); }, "cog_go.png");
  377. m_menu_item_repeat->Enable(false);
  378. fileMenu->AppendSeparator();
  379. #endif
  380. m_menu_item_reslice_now = append_menu_item(fileMenu, wxID_ANY, _(L("(Re)Slice No&w")) + "\tCtrl+R", _(L("Start new slicing process")),
  381. [this](wxCommandEvent&) { reslice_now(); }, menu_icon("re_slice"), nullptr,
  382. [this](){return m_plater != nullptr && can_reslice(); }, this);
  383. fileMenu->AppendSeparator();
  384. append_menu_item(fileMenu, wxID_ANY, _(L("&Repair STL file")) + dots, _(L("Automatically repair an STL file")),
  385. [this](wxCommandEvent&) { repair_stl(); }, menu_icon("wrench"));
  386. fileMenu->AppendSeparator();
  387. append_menu_item(fileMenu, wxID_EXIT, _(L("&Quit")), wxString::Format(_(L("Quit %s")), SLIC3R_APP_NAME),
  388. [this](wxCommandEvent&) { Close(false); });
  389. }
  390. #ifdef _MSC_VER
  391. // \xA0 is a non-breaking space. It is entered here to spoil the automatic accelerators,
  392. // as the simple numeric accelerators spoil all numeric data entry.
  393. wxString sep = "\t\xA0";
  394. wxString sep_space = "\xA0";
  395. #else
  396. wxString sep = " - ";
  397. wxString sep_space = "";
  398. #endif
  399. // Edit menu
  400. wxMenu* editMenu = nullptr;
  401. if (m_plater != nullptr)
  402. {
  403. editMenu = new wxMenu();
  404. #ifdef __APPLE__
  405. // Backspace sign
  406. wxString hotkey_delete = "\u232b";
  407. #else
  408. wxString hotkey_delete = "Del";
  409. #endif
  410. append_menu_item(editMenu, wxID_ANY, _(L("&Select all")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + "A",
  411. _(L("Selects all objects")), [this](wxCommandEvent&) { if (m_plater != nullptr) m_plater->select_all(); },
  412. "", nullptr, [this](){return can_select(); }, this);
  413. append_menu_item(editMenu, wxID_ANY, _(L("D&eselect all")) + sep + "Esc",
  414. _(L("Deselects all objects")), [this](wxCommandEvent&) { if (m_plater != nullptr) m_plater->deselect_all(); },
  415. "", nullptr, [this](){return can_deselect(); }, this);
  416. editMenu->AppendSeparator();
  417. append_menu_item(editMenu, wxID_ANY, _(L("&Delete selected")) + sep + hotkey_delete,
  418. _(L("Deletes the current selection")),[this](wxCommandEvent&) { m_plater->remove_selected(); },
  419. menu_icon("remove_menu"), nullptr, [this](){return can_delete(); }, this);
  420. append_menu_item(editMenu, wxID_ANY, _(L("Delete &all")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + hotkey_delete,
  421. _(L("Deletes all objects")), [this](wxCommandEvent&) { m_plater->reset_with_confirm(); },
  422. menu_icon("delete_all_menu"), nullptr, [this](){return can_delete_all(); }, this);
  423. editMenu->AppendSeparator();
  424. append_menu_item(editMenu, wxID_ANY, _(L("&Copy")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + "C",
  425. _(L("Copy selection to clipboard")), [this](wxCommandEvent&) { m_plater->copy_selection_to_clipboard(); },
  426. menu_icon("copy_menu"), nullptr, [this](){return m_plater->can_copy(); }, this);
  427. append_menu_item(editMenu, wxID_ANY, _(L("&Paste")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + "V",
  428. _(L("Paste clipboard")), [this](wxCommandEvent&) { m_plater->paste_from_clipboard(); },
  429. menu_icon("paste_menu"), nullptr, [this](){return m_plater->can_paste(); }, this);
  430. }
  431. // Window menu
  432. auto windowMenu = new wxMenu();
  433. {
  434. size_t tab_offset = 0;
  435. if (m_plater) {
  436. append_menu_item(windowMenu, wxID_HIGHEST + 1, _(L("&Plater Tab")) + "\tCtrl+1", _(L("Show the plater")),
  437. [this](wxCommandEvent&) { select_tab(0); }, menu_icon("plater"));
  438. tab_offset += 1;
  439. }
  440. if (tab_offset > 0) {
  441. windowMenu->AppendSeparator();
  442. }
  443. append_menu_item(windowMenu, wxID_HIGHEST + 2, _(L("P&rint Settings Tab")) + "\tCtrl+2", _(L("Show the print settings")),
  444. [this, tab_offset](wxCommandEvent&) { select_tab(tab_offset + 0); }, menu_icon("cog"));
  445. wxMenuItem* item_material_tab = append_menu_item(windowMenu, wxID_HIGHEST + 3, _(L("&Filament Settings Tab")) + "\tCtrl+3", _(L("Show the filament settings")),
  446. [this, tab_offset](wxCommandEvent&) { select_tab(tab_offset + 1); }, menu_icon("spool"));
  447. m_changeable_menu_items.push_back(item_material_tab);
  448. append_menu_item(windowMenu, wxID_HIGHEST + 4, _(L("Print&er Settings Tab")) + "\tCtrl+4", _(L("Show the printer settings")),
  449. [this, tab_offset](wxCommandEvent&) { select_tab(tab_offset + 2); }, menu_icon("printer"));
  450. if (m_plater) {
  451. windowMenu->AppendSeparator();
  452. append_menu_item(windowMenu, wxID_HIGHEST + 5, _(L("3&D")) + "\tCtrl+5", _(L("Show the 3D editing view")),
  453. [this](wxCommandEvent&) { m_plater->select_view_3D("3D"); }, menu_icon("editor_menu"), nullptr,
  454. [this](){return can_change_view(); }, this);
  455. append_menu_item(windowMenu, wxID_HIGHEST + 6, _(L("Pre&view")) + "\tCtrl+6", _(L("Show the 3D slices preview")),
  456. [this](wxCommandEvent&) { m_plater->select_view_3D("Preview"); }, menu_icon("preview_menu"), nullptr,
  457. [this](){return can_change_view(); }, this);
  458. }
  459. #if _WIN32
  460. // This is needed on Windows to fake the CTRL+# of the window menu when using the numpad
  461. wxAcceleratorEntry entries[6];
  462. entries[0].Set(wxACCEL_CTRL, WXK_NUMPAD1, wxID_HIGHEST + 1);
  463. entries[1].Set(wxACCEL_CTRL, WXK_NUMPAD2, wxID_HIGHEST + 2);
  464. entries[2].Set(wxACCEL_CTRL, WXK_NUMPAD3, wxID_HIGHEST + 3);
  465. entries[3].Set(wxACCEL_CTRL, WXK_NUMPAD4, wxID_HIGHEST + 4);
  466. entries[4].Set(wxACCEL_CTRL, WXK_NUMPAD5, wxID_HIGHEST + 5);
  467. entries[5].Set(wxACCEL_CTRL, WXK_NUMPAD6, wxID_HIGHEST + 6);
  468. wxAcceleratorTable accel(6, entries);
  469. SetAcceleratorTable(accel);
  470. #endif // _WIN32
  471. windowMenu->AppendSeparator();
  472. append_menu_item(windowMenu, wxID_ANY, _(L("Print &Host Upload Queue")) + "\tCtrl+J", _(L("Display the Print Host Upload Queue window")),
  473. [this](wxCommandEvent&) { m_printhost_queue_dlg->Show(); }, menu_icon("upload_queue"));
  474. }
  475. // View menu
  476. wxMenu* viewMenu = nullptr;
  477. if (m_plater) {
  478. viewMenu = new wxMenu();
  479. // The camera control accelerators are captured by GLCanvas3D::on_char().
  480. append_menu_item(viewMenu, wxID_ANY, _(L("Iso")) + sep + "&0", _(L("Iso View")),[this](wxCommandEvent&) { select_view("iso"); },
  481. "", nullptr, [this](){return can_change_view(); }, this);
  482. viewMenu->AppendSeparator();
  483. //TRN To be shown in the main menu View->Top
  484. append_menu_item(viewMenu, wxID_ANY, _(L("Top")) + sep + "&1", _(L("Top View")), [this](wxCommandEvent&) { select_view("top"); },
  485. "", nullptr, [this](){return can_change_view(); }, this);
  486. //TRN To be shown in the main menu View->Bottom
  487. append_menu_item(viewMenu, wxID_ANY, _(L("Bottom")) + sep + "&2", _(L("Bottom View")), [this](wxCommandEvent&) { select_view("bottom"); },
  488. "", nullptr, [this](){return can_change_view(); }, this);
  489. append_menu_item(viewMenu, wxID_ANY, _(L("Front")) + sep + "&3", _(L("Front View")), [this](wxCommandEvent&) { select_view("front"); },
  490. "", nullptr, [this](){return can_change_view(); }, this);
  491. append_menu_item(viewMenu, wxID_ANY, _(L("Rear")) + sep + "&4", _(L("Rear View")), [this](wxCommandEvent&) { select_view("rear"); },
  492. "", nullptr, [this](){return can_change_view(); }, this);
  493. append_menu_item(viewMenu, wxID_ANY, _(L("Left")) + sep + "&5", _(L("Left View")), [this](wxCommandEvent&) { select_view("left"); },
  494. "", nullptr, [this](){return can_change_view(); }, this);
  495. append_menu_item(viewMenu, wxID_ANY, _(L("Right")) + sep + "&6", _(L("Right View")), [this](wxCommandEvent&) { select_view("right"); },
  496. "", nullptr, [this](){return can_change_view(); }, this);
  497. }
  498. // Help menu
  499. auto helpMenu = new wxMenu();
  500. {
  501. append_menu_item(helpMenu, wxID_ANY, _(L("Prusa 3D &Drivers")), _(L("Open the Prusa3D drivers download page in your browser")),
  502. [this](wxCommandEvent&) { wxGetApp().open_web_page_localized("https://www.prusa3d.com/downloads"); });
  503. append_menu_item(helpMenu, wxID_ANY, _(L("Software &Releases")), _(L("Open the software releases page in your browser")),
  504. [this](wxCommandEvent&) { wxLaunchDefaultBrowser("http://github.com/prusa3d/PrusaSlicer/releases"); });
  505. //# my $versioncheck = $self->_append_menu_item($helpMenu, "Check for &Updates...", "Check for new Slic3r versions", sub{
  506. //# wxTheApp->check_version(1);
  507. //# });
  508. //# $versioncheck->Enable(wxTheApp->have_version_check);
  509. append_menu_item(helpMenu, wxID_ANY, wxString::Format(_(L("%s &Website")), SLIC3R_APP_NAME),
  510. wxString::Format(_(L("Open the %s website in your browser")), SLIC3R_APP_NAME),
  511. [this](wxCommandEvent&) { wxGetApp().open_web_page_localized("https://www.prusa3d.com/slicerweb"); });
  512. // append_menu_item(helpMenu, wxID_ANY, wxString::Format(_(L("%s &Manual")), SLIC3R_APP_NAME),
  513. // wxString::Format(_(L("Open the %s manual in your browser")), SLIC3R_APP_NAME),
  514. // [this](wxCommandEvent&) { wxLaunchDefaultBrowser("http://manual.slic3r.org/"); });
  515. helpMenu->AppendSeparator();
  516. append_menu_item(helpMenu, wxID_ANY, _(L("System &Info")), _(L("Show system information")),
  517. [this](wxCommandEvent&) { wxGetApp().system_info(); });
  518. append_menu_item(helpMenu, wxID_ANY, _(L("Show &Configuration Folder")), _(L("Show user configuration folder (datadir)")),
  519. [this](wxCommandEvent&) { Slic3r::GUI::desktop_open_datadir_folder(); });
  520. append_menu_item(helpMenu, wxID_ANY, _(L("Report an I&ssue")), wxString::Format(_(L("Report an issue on %s")), SLIC3R_APP_NAME),
  521. [this](wxCommandEvent&) { wxLaunchDefaultBrowser("http://github.com/prusa3d/slic3r/issues/new"); });
  522. append_menu_item(helpMenu, wxID_ANY, wxString::Format(_(L("&About %s")), SLIC3R_APP_NAME), _(L("Show about dialog")),
  523. [this](wxCommandEvent&) { Slic3r::GUI::about(); });
  524. helpMenu->AppendSeparator();
  525. append_menu_item(helpMenu, wxID_ANY, _(L("Keyboard Shortcuts")) + sep + "&?", _(L("Show the list of the keyboard shortcuts")),
  526. [this](wxCommandEvent&) { wxGetApp().keyboard_shortcuts(); });
  527. }
  528. // menubar
  529. // assign menubar to frame after appending items, otherwise special items
  530. // will not be handled correctly
  531. auto menubar = new wxMenuBar();
  532. menubar->Append(fileMenu, _(L("&File")));
  533. if (editMenu) menubar->Append(editMenu, _(L("&Edit")));
  534. menubar->Append(windowMenu, _(L("&Window")));
  535. if (viewMenu) menubar->Append(viewMenu, _(L("&View")));
  536. // Add additional menus from C++
  537. wxGetApp().add_config_menu(menubar);
  538. menubar->Append(helpMenu, _(L("&Help")));
  539. SetMenuBar(menubar);
  540. #ifdef __APPLE__
  541. // This fixes a bug on Mac OS where the quit command doesn't emit window close events
  542. // wx bug: https://trac.wxwidgets.org/ticket/18328
  543. wxMenu *apple_menu = menubar->OSXGetAppleMenu();
  544. if (apple_menu != nullptr) {
  545. apple_menu->Bind(wxEVT_MENU, [this](wxCommandEvent &) {
  546. Close();
  547. }, wxID_EXIT);
  548. }
  549. #endif
  550. if (plater()->printer_technology() == ptSLA)
  551. update_menubar();
  552. }
  553. void MainFrame::update_menubar()
  554. {
  555. const bool is_fff = plater()->printer_technology() == ptFFF;
  556. m_changeable_menu_items[miExport] ->SetItemLabel((is_fff ? _(L("Export &G-code")) : _(L("Export")) ) + dots + "\tCtrl+G");
  557. m_changeable_menu_items[miMaterialTab] ->SetItemLabel((is_fff ? _(L("&Filament Settings Tab")) : _(L("Mate&rial Settings Tab"))) + "\tCtrl+3");
  558. m_changeable_menu_items[miMaterialTab] ->SetBitmap(create_scaled_bitmap(this, menu_icon(is_fff ? "spool": "resin")));
  559. }
  560. // To perform the "Quck Slice", "Quick Slice and Save As", "Repeat last Quick Slice" and "Slice to SVG".
  561. void MainFrame::quick_slice(const int qs)
  562. {
  563. // my $progress_dialog;
  564. wxString input_file;
  565. // eval
  566. // {
  567. // validate configuration
  568. auto config = wxGetApp().preset_bundle->full_config();
  569. auto valid = config.validate();
  570. if (! valid.empty()) {
  571. show_error(this, valid);
  572. return;
  573. }
  574. // select input file
  575. if (!(qs & qsReslice)) {
  576. auto dlg = new wxFileDialog(this, _(L("Choose a file to slice (STL/OBJ/AMF/3MF/PRUSA):")),
  577. wxGetApp().app_config->get_last_dir(), "",
  578. file_wildcards(FT_MODEL), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
  579. if (dlg->ShowModal() != wxID_OK) {
  580. dlg->Destroy();
  581. return;
  582. }
  583. input_file = dlg->GetPath();
  584. dlg->Destroy();
  585. if (!(qs & qsExportSVG))
  586. m_qs_last_input_file = input_file;
  587. }
  588. else {
  589. if (m_qs_last_input_file.IsEmpty()) {
  590. auto dlg = new wxMessageDialog(this, _(L("No previously sliced file.")),
  591. _(L("Error")), wxICON_ERROR | wxOK);
  592. dlg->ShowModal();
  593. return;
  594. }
  595. if (std::ifstream(m_qs_last_input_file.ToUTF8().data())) {
  596. auto dlg = new wxMessageDialog(this, _(L("Previously sliced file ("))+m_qs_last_input_file+_(L(") not found.")),
  597. _(L("File Not Found")), wxICON_ERROR | wxOK);
  598. dlg->ShowModal();
  599. return;
  600. }
  601. input_file = m_qs_last_input_file;
  602. }
  603. auto input_file_basename = get_base_name(input_file);
  604. wxGetApp().app_config->update_skein_dir(get_dir_name(input_file));
  605. auto bed_shape = Slic3r::Polygon::new_scale(config.option<ConfigOptionPoints>("bed_shape")->values);
  606. // auto print_center = Slic3r::Pointf->new_unscale(bed_shape.bounding_box().center());
  607. //
  608. // auto sprint = new Slic3r::Print::Simple(
  609. // print_center = > print_center,
  610. // status_cb = > [](int percent, const wxString& msg) {
  611. // m_progress_dialog->Update(percent, msg+"…");
  612. // });
  613. // keep model around
  614. auto model = Slic3r::Model::read_from_file(input_file.ToUTF8().data());
  615. // sprint->apply_config(config);
  616. // sprint->set_model(model);
  617. // Copy the names of active presets into the placeholder parser.
  618. // wxGetApp().preset_bundle->export_selections(sprint->placeholder_parser);
  619. // select output file
  620. wxString output_file;
  621. if (qs & qsReslice) {
  622. if (!m_qs_last_output_file.IsEmpty())
  623. output_file = m_qs_last_output_file;
  624. }
  625. else if (qs & qsSaveAs) {
  626. // The following line may die if the output_filename_format template substitution fails.
  627. auto dlg = new wxFileDialog(this, wxString::Format(_(L("Save %s file as:")) , qs & qsExportSVG ? _(L("SVG")) : _(L("G-code")) ),
  628. wxGetApp().app_config->get_last_output_dir(get_dir_name(output_file)), get_base_name(input_file),
  629. qs & qsExportSVG ? file_wildcards(FT_SVG) : file_wildcards(FT_GCODE),
  630. wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
  631. if (dlg->ShowModal() != wxID_OK) {
  632. dlg->Destroy();
  633. return;
  634. }
  635. output_file = dlg->GetPath();
  636. dlg->Destroy();
  637. if (!(qs & qsExportSVG))
  638. m_qs_last_output_file = output_file;
  639. wxGetApp().app_config->update_last_output_dir(get_dir_name(output_file));
  640. }
  641. else if (qs & qsExportPNG) {
  642. auto dlg = new wxFileDialog(this, _(L("Save zip file as:")),
  643. wxGetApp().app_config->get_last_output_dir(get_dir_name(output_file)),
  644. get_base_name(output_file), "*.sl1", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
  645. if (dlg->ShowModal() != wxID_OK) {
  646. dlg->Destroy();
  647. return;
  648. }
  649. output_file = dlg->GetPath();
  650. dlg->Destroy();
  651. }
  652. // show processbar dialog
  653. m_progress_dialog = new wxProgressDialog(_(L("Slicing")) + dots,
  654. // TRN "Processing input_file_basename"
  655. wxString::Format(_(L("Processing %s")), input_file_basename + dots),
  656. 100, this, 4);
  657. m_progress_dialog->Pulse();
  658. {
  659. // my @warnings = ();
  660. // local $SIG{ __WARN__ } = sub{ push @warnings, $_[0] };
  661. // sprint->output_file(output_file);
  662. // if (export_svg) {
  663. // sprint->export_svg();
  664. // }
  665. // else if(export_png) {
  666. // sprint->export_png();
  667. // }
  668. // else {
  669. // sprint->export_gcode();
  670. // }
  671. // sprint->status_cb(undef);
  672. // Slic3r::GUI::warning_catcher($self)->($_) for @warnings;
  673. }
  674. m_progress_dialog->Destroy();
  675. m_progress_dialog = nullptr;
  676. auto message = input_file_basename + _(L(" was successfully sliced."));
  677. // wxTheApp->notify(message);
  678. wxMessageDialog(this, message, _(L("Slicing Done!")), wxOK | wxICON_INFORMATION).ShowModal();
  679. // };
  680. // Slic3r::GUI::catch_error(this, []() { if (m_progress_dialog) m_progress_dialog->Destroy(); });
  681. }
  682. void MainFrame::reslice_now()
  683. {
  684. if (m_plater)
  685. m_plater->reslice();
  686. }
  687. void MainFrame::repair_stl()
  688. {
  689. wxString input_file;
  690. {
  691. auto dlg = new wxFileDialog(this, _(L("Select the STL file to repair:")),
  692. wxGetApp().app_config->get_last_dir(), "",
  693. file_wildcards(FT_STL), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
  694. if (dlg->ShowModal() != wxID_OK) {
  695. dlg->Destroy();
  696. return;
  697. }
  698. input_file = dlg->GetPath();
  699. dlg->Destroy();
  700. }
  701. wxString output_file = input_file;
  702. {
  703. auto dlg = new wxFileDialog( this, L("Save OBJ file (less prone to coordinate errors than STL) as:"),
  704. get_dir_name(output_file), get_base_name(output_file, ".obj"),
  705. file_wildcards(FT_OBJ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
  706. if (dlg->ShowModal() != wxID_OK) {
  707. dlg->Destroy();
  708. return;
  709. }
  710. output_file = dlg->GetPath();
  711. dlg->Destroy();
  712. }
  713. auto tmesh = new Slic3r::TriangleMesh();
  714. tmesh->ReadSTLFile(input_file.ToUTF8().data());
  715. tmesh->repair();
  716. tmesh->WriteOBJFile(output_file.ToUTF8().data());
  717. Slic3r::GUI::show_info(this, L("Your file was repaired."), L("Repair"));
  718. }
  719. void MainFrame::export_config()
  720. {
  721. // Generate a cummulative configuration for the selected print, filaments and printer.
  722. auto config = wxGetApp().preset_bundle->full_config();
  723. // Validate the cummulative configuration.
  724. auto valid = config.validate();
  725. if (! valid.empty()) {
  726. show_error(this, valid);
  727. return;
  728. }
  729. // Ask user for the file name for the config file.
  730. auto dlg = new wxFileDialog(this, _(L("Save configuration as:")),
  731. !m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
  732. !m_last_config.IsEmpty() ? get_base_name(m_last_config) : "config.ini",
  733. file_wildcards(FT_INI), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
  734. wxString file;
  735. if (dlg->ShowModal() == wxID_OK)
  736. file = dlg->GetPath();
  737. dlg->Destroy();
  738. if (!file.IsEmpty()) {
  739. wxGetApp().app_config->update_config_dir(get_dir_name(file));
  740. m_last_config = file;
  741. config.save(file.ToUTF8().data());
  742. }
  743. }
  744. // Load a config file containing a Print, Filament & Printer preset.
  745. void MainFrame::load_config_file()
  746. {
  747. if (!wxGetApp().check_unsaved_changes())
  748. return;
  749. auto dlg = new wxFileDialog(this, _(L("Select configuration to load:")),
  750. !m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
  751. "config.ini", "INI files (*.ini, *.gcode)|*.ini;*.INI;*.gcode;*.g", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
  752. wxString file;
  753. if (dlg->ShowModal() == wxID_OK)
  754. file = dlg->GetPath();
  755. dlg->Destroy();
  756. if (! file.IsEmpty() && this->load_config_file(file.ToUTF8().data())) {
  757. wxGetApp().app_config->update_config_dir(get_dir_name(file));
  758. m_last_config = file;
  759. }
  760. }
  761. // Load a config file containing a Print, Filament & Printer preset from command line.
  762. bool MainFrame::load_config_file(const std::string &path)
  763. {
  764. try {
  765. wxGetApp().preset_bundle->load_config_file(path);
  766. } catch (const std::exception &ex) {
  767. show_error(this, ex.what());
  768. return false;
  769. }
  770. wxGetApp().load_current_presets();
  771. return true;
  772. }
  773. void MainFrame::export_configbundle()
  774. {
  775. if (!wxGetApp().check_unsaved_changes())
  776. return;
  777. // validate current configuration in case it's dirty
  778. auto err = wxGetApp().preset_bundle->full_config().validate();
  779. if (! err.empty()) {
  780. show_error(this, err);
  781. return;
  782. }
  783. // Ask user for a file name.
  784. auto dlg = new wxFileDialog(this, _(L("Save presets bundle as:")),
  785. !m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
  786. SLIC3R_APP_KEY "_config_bundle.ini",
  787. file_wildcards(FT_INI), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
  788. wxString file;
  789. if (dlg->ShowModal() == wxID_OK)
  790. file = dlg->GetPath();
  791. dlg->Destroy();
  792. if (!file.IsEmpty()) {
  793. // Export the config bundle.
  794. wxGetApp().app_config->update_config_dir(get_dir_name(file));
  795. try {
  796. wxGetApp().preset_bundle->export_configbundle(file.ToUTF8().data());
  797. } catch (const std::exception &ex) {
  798. show_error(this, ex.what());
  799. }
  800. }
  801. }
  802. // Loading a config bundle with an external file name used to be used
  803. // to auto - install a config bundle on a fresh user account,
  804. // but that behavior was not documented and likely buggy.
  805. void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool reset_user_profile*/)
  806. {
  807. if (!wxGetApp().check_unsaved_changes())
  808. return;
  809. if (file.IsEmpty()) {
  810. auto dlg = new wxFileDialog(this, _(L("Select configuration to load:")),
  811. !m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
  812. "config.ini", file_wildcards(FT_INI), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
  813. if (dlg->ShowModal() != wxID_OK) {
  814. dlg->Destroy();
  815. return;
  816. }
  817. file = dlg->GetPath();
  818. dlg->Destroy();
  819. }
  820. wxGetApp().app_config->update_config_dir(get_dir_name(file));
  821. auto presets_imported = 0;
  822. try {
  823. presets_imported = wxGetApp().preset_bundle->load_configbundle(file.ToUTF8().data());
  824. } catch (const std::exception &ex) {
  825. show_error(this, ex.what());
  826. return;
  827. }
  828. // Load the currently selected preset into the GUI, update the preset selection box.
  829. wxGetApp().load_current_presets();
  830. const auto message = wxString::Format(_(L("%d presets successfully imported.")), presets_imported);
  831. Slic3r::GUI::show_info(this, message, "Info");
  832. }
  833. // Load a provied DynamicConfig into the Print / Filament / Printer tabs, thus modifying the active preset.
  834. // Also update the platter with the new presets.
  835. void MainFrame::load_config(const DynamicPrintConfig& config)
  836. {
  837. PrinterTechnology printer_technology = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology();
  838. const auto *opt_printer_technology = config.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
  839. if (opt_printer_technology != nullptr && opt_printer_technology->value != printer_technology) {
  840. printer_technology = opt_printer_technology->value;
  841. this->plater()->set_printer_technology(printer_technology);
  842. }
  843. #if 0
  844. for (auto tab : wxGetApp().tabs_list)
  845. if (tab->supports_printer_technology(printer_technology)) {
  846. if (tab->type() == Slic3r::Preset::TYPE_PRINTER)
  847. static_cast<TabPrinter*>(tab)->update_pages();
  848. tab->load_config(config);
  849. }
  850. if (m_plater)
  851. m_plater->on_config_change(config);
  852. #else
  853. // Load the currently selected preset into the GUI, update the preset selection box.
  854. //FIXME this is not quite safe for multi-extruder printers,
  855. // as the number of extruders is not adjusted for the vector values.
  856. // (see PresetBundle::update_multi_material_filament_presets())
  857. // Better to call PresetBundle::load_config() instead?
  858. for (auto tab : wxGetApp().tabs_list)
  859. if (tab->supports_printer_technology(printer_technology)) {
  860. // Only apply keys, which are present in the tab's config. Ignore the other keys.
  861. for (const std::string &opt_key : tab->get_config()->diff(config))
  862. // Ignore print_settings_id, printer_settings_id, filament_settings_id etc.
  863. if (! boost::algorithm::ends_with(opt_key, "_settings_id"))
  864. tab->get_config()->option(opt_key)->set(config.option(opt_key));
  865. }
  866. wxGetApp().load_current_presets();
  867. #endif
  868. }
  869. void MainFrame::select_tab(size_t tab) const
  870. {
  871. m_tabpanel->SetSelection(tab);
  872. }
  873. // Set a camera direction, zoom to all objects.
  874. void MainFrame::select_view(const std::string& direction)
  875. {
  876. if (m_plater)
  877. m_plater->select_view(direction);
  878. }
  879. // #ys_FIXME_to_delete
  880. void MainFrame::on_presets_changed(SimpleEvent &event)
  881. {
  882. auto *tab = dynamic_cast<Tab*>(event.GetEventObject());
  883. wxASSERT(tab != nullptr);
  884. if (tab == nullptr) {
  885. return;
  886. }
  887. // Update preset combo boxes(Print settings, Filament, Material, Printer) from their respective tabs.
  888. auto presets = tab->get_presets();
  889. if (m_plater != nullptr && presets != nullptr) {
  890. // FIXME: The preset type really should be a property of Tab instead
  891. Slic3r::Preset::Type preset_type = tab->type();
  892. if (preset_type == Slic3r::Preset::TYPE_INVALID) {
  893. wxASSERT(false);
  894. return;
  895. }
  896. m_plater->on_config_change(*tab->get_config());
  897. m_plater->sidebar().update_presets(preset_type);
  898. }
  899. }
  900. // #ys_FIXME_to_delete
  901. void MainFrame::on_value_changed(wxCommandEvent& event)
  902. {
  903. auto *tab = dynamic_cast<Tab*>(event.GetEventObject());
  904. wxASSERT(tab != nullptr);
  905. if (tab == nullptr)
  906. return;
  907. auto opt_key = event.GetString();
  908. if (m_plater) {
  909. m_plater->on_config_change(*tab->get_config()); // propagate config change events to the plater
  910. if (opt_key == "extruders_count") {
  911. auto value = event.GetInt();
  912. m_plater->on_extruders_change(value);
  913. }
  914. }
  915. }
  916. void MainFrame::on_config_changed(DynamicPrintConfig* config) const
  917. {
  918. if (m_plater)
  919. m_plater->on_config_change(*config); // propagate config change events to the plater
  920. }
  921. // Called after the Preferences dialog is closed and the program settings are saved.
  922. // Update the UI based on the current preferences.
  923. void MainFrame::update_ui_from_settings()
  924. {
  925. const bool bp_on = wxGetApp().app_config->get("background_processing") == "1";
  926. // m_menu_item_reslice_now->Enable(!bp_on);
  927. m_plater->sidebar().show_reslice(!bp_on);
  928. m_plater->sidebar().show_export(bp_on);
  929. m_plater->sidebar().Layout();
  930. if (m_plater)
  931. m_plater->update_ui_from_settings();
  932. for (auto tab: wxGetApp().tabs_list)
  933. tab->update_ui_from_settings();
  934. }
  935. std::string MainFrame::get_base_name(const wxString &full_name, const char *extension) const
  936. {
  937. boost::filesystem::path filename = boost::filesystem::path(full_name.wx_str()).filename();
  938. if (extension != nullptr)
  939. filename = filename.replace_extension(extension);
  940. return filename.string();
  941. }
  942. std::string MainFrame::get_dir_name(const wxString &full_name) const
  943. {
  944. return boost::filesystem::path(full_name.wx_str()).parent_path().string();
  945. }
  946. } // GUI
  947. } // Slic3r