diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index bfdc95ba09..d74c1a1764 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -251,7 +251,7 @@ void MainFrame::init_menubar() wxMenu* fileMenu = new wxMenu; { #if ENABLE_NEW_MENU_LAYOUT - append_menu_item(fileMenu, wxID_ANY, _(L("Open…\tCtrl+O")), _(L("Open a project file")), + wxMenuItem* item_open = 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"); @@ -261,11 +261,14 @@ void MainFrame::init_menubar() 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")), + wxMenuItem* item_import_model = 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 from project…\tCtrl+Alt+L")), _(L("Load configuration from project file")), + [this](wxCommandEvent&) { if (m_plater) m_plater->extract_config_from_project(); }, "plugin_add.png"); + import_menu->AppendSeparator(); 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(""))); @@ -332,11 +335,13 @@ void MainFrame::init_menubar() [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()); + Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(m_plater != nullptr); }, item_open->GetId()); + Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_save()); }, item_save->GetId()); + Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_save()); }, item_save_as->GetId()); + Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(m_plater != nullptr); }, item_import_model->GetId()); + Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_export_gcode()); }, item_export_gcode->GetId()); + Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_export_model()); }, item_export_stl->GetId()); + Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_export_model()); }, item_export_amf->GetId()); #endif // ENABLE_NEW_MENU_LAYOUT } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a3f8637a6b..5aa9746baa 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -909,7 +909,11 @@ struct Plater::priv std::string get_config(const std::string &key) const; BoundingBoxf bed_shape_bb() const; BoundingBox scaled_bed_shape_bb() const; +#if ENABLE_NEW_MENU_LAYOUT + std::vector load_files(const std::vector& input_files, bool load_model, bool load_config); +#else std::vector load_files(const std::vector &input_files); +#endif // ENABLE_NEW_MENU_LAYOUT std::vector load_model_objects(const ModelObjectPtrs &model_objects); std::unique_ptr get_export_file(GUI::FileType file_type); @@ -1176,7 +1180,11 @@ BoundingBox Plater::priv::scaled_bed_shape_bb() const return bed_shape.bounding_box(); } +#if ENABLE_NEW_MENU_LAYOUT +std::vector Plater::priv::load_files(const std::vector& input_files, bool load_model, bool load_config) +#else std::vector Plater::priv::load_files(const std::vector &input_files) +#endif // ENABLE_NEW_MENU_LAYOUT { if (input_files.empty()) { return std::vector(); } @@ -1196,7 +1204,11 @@ std::vector Plater::priv::load_files(const std::vector &input_ wxProgressDialog dlg(loading, loading); dlg.Pulse(); +#if ENABLE_NEW_MENU_LAYOUT + auto *new_model = (!load_model || one_by_one) ? nullptr : new Slic3r::Model(); +#else auto *new_model = one_by_one ? nullptr : new Slic3r::Model(); +#endif // ENABLE_NEW_MENU_LAYOUT std::vector obj_idxs; for (size_t i = 0; i < input_files.size(); i++) { @@ -1215,23 +1227,35 @@ std::vector Plater::priv::load_files(const std::vector &input_ { DynamicPrintConfig config_loaded; model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, false); - if (! config_loaded.empty()) { - // Based on the printer technology field found in the loaded config, select the base for the config, - PrinterTechnology printer_technology = Preset::printer_technology(config_loaded); - config.apply(printer_technology == ptFFF ? +#if ENABLE_NEW_MENU_LAYOUT + if (load_config && !config_loaded.empty()) { +#else + if (!config_loaded.empty()) { +#endif // ENABLE_NEW_MENU_LAYOUT + // Based on the printer technology field found in the loaded config, select the base for the config, + PrinterTechnology printer_technology = Preset::printer_technology(config_loaded); + config.apply(printer_technology == ptFFF ? static_cast(FullPrintConfig::defaults()) : static_cast(SLAFullPrintConfig::defaults())); // and place the loaded config over the base. config += std::move(config_loaded); } } - if (! config.empty()) { - Preset::normalize(config); - wxGetApp().preset_bundle->load_config_model(filename.string(), std::move(config)); - wxGetApp().load_current_presets(); - } - wxGetApp().app_config->update_config_dir(path.parent_path().string()); - } else { +#if ENABLE_NEW_MENU_LAYOUT + if (load_config) + { +#endif // ENABLE_NEW_MENU_LAYOUT + if (!config.empty()) { + Preset::normalize(config); + wxGetApp().preset_bundle->load_config_model(filename.string(), std::move(config)); + wxGetApp().load_current_presets(); + } + wxGetApp().app_config->update_config_dir(path.parent_path().string()); +#if ENABLE_NEW_MENU_LAYOUT + } +#endif // ENABLE_NEW_MENU_LAYOUT + } + else { model = Slic3r::Model::read_from_file(path.string(), nullptr, false); for (auto obj : model.objects) if (obj->name.empty()) @@ -1243,35 +1267,42 @@ std::vector Plater::priv::load_files(const std::vector &input_ continue; } - // The model should now be initialized +#if ENABLE_NEW_MENU_LAYOUT + if (load_model) + { +#endif // ENABLE_NEW_MENU_LAYOUT + // The model should now be initialized - if (model.looks_like_multipart_object()) { - wxMessageDialog dlg(q, _(L( - "This file contains several objects positioned at multiple heights. " - "Instead of considering them as multiple objects, should I consider\n" - "this file as a single object having multiple parts?\n" - )), _(L("Multi-part object detected")), wxICON_WARNING | wxYES | wxNO); - if (dlg.ShowModal() == wxID_YES) { - model.convert_multipart_object(nozzle_dmrs->values.size()); + if (model.looks_like_multipart_object()) { + wxMessageDialog dlg(q, _(L( + "This file contains several objects positioned at multiple heights. " + "Instead of considering them as multiple objects, should I consider\n" + "this file as a single object having multiple parts?\n" + )), _(L("Multi-part object detected")), wxICON_WARNING | wxYES | wxNO); + if (dlg.ShowModal() == wxID_YES) { + model.convert_multipart_object(nozzle_dmrs->values.size()); + } } - } - if (type_3mf) { - for (ModelObject* model_object : model.objects) { - model_object->center_around_origin(); - model_object->ensure_on_bed(); + if (type_3mf) { + for (ModelObject* model_object : model.objects) { + model_object->center_around_origin(); + model_object->ensure_on_bed(); + } } - } - if (one_by_one) { - auto loaded_idxs = load_model_objects(model.objects); - obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end()); - } else { - // This must be an .stl or .obj file, which may contain a maximum of one volume. - for (const ModelObject* model_object : model.objects) { - new_model->add_object(*model_object); + if (one_by_one) { + auto loaded_idxs = load_model_objects(model.objects); + obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end()); + } else { + // This must be an .stl or .obj file, which may contain a maximum of one volume. + for (const ModelObject* model_object : model.objects) { + new_model->add_object(*model_object); + } } +#if ENABLE_NEW_MENU_LAYOUT } +#endif // ENABLE_NEW_MENU_LAYOUT } if (new_model != nullptr) { @@ -1288,9 +1319,16 @@ std::vector Plater::priv::load_files(const std::vector &input_ obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end()); } - wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().string()); - // XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames... - statusbar()->set_status_text(_(L("Loaded"))); +#if ENABLE_NEW_MENU_LAYOUT + if (load_model) + { +#endif // ENABLE_NEW_MENU_LAYOUT + wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().string()); + // XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames... + statusbar()->set_status_text(_(L("Loaded"))); +#if ENABLE_NEW_MENU_LAYOUT + } +#endif // ENABLE_NEW_MENU_LAYOUT return obj_idxs; } @@ -2160,10 +2198,33 @@ void Plater::add() for (const auto &file : input_files) { input_paths.push_back(file.wx_str()); } +#if ENABLE_NEW_MENU_LAYOUT + load_files(input_paths, true, false); +#else load_files(input_paths); +#endif // ENABLE_NEW_MENU_LAYOUT } +#if ENABLE_NEW_MENU_LAYOUT +void Plater::extract_config_from_project() +{ + wxString input_file; + wxGetApp().load_project(this, input_file); + + if (input_file.empty()) + return; + + std::vector input_paths; + input_paths.push_back(input_file.wx_str()); + load_files(input_paths, false, true); +} +#endif // ENABLE_NEW_MENU_LAYOUT + +#if ENABLE_NEW_MENU_LAYOUT +void Plater::load_files(const std::vector& input_files, bool load_model, bool load_config) { p->load_files(input_files, load_model, load_config); } +#else void Plater::load_files(const std::vector &input_files) { p->load_files(input_files); } +#endif // ENABLE_NEW_MENU_LAYOUT void Plater::update(bool force_autocenter) { p->update(force_autocenter); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 7982d504fe..f23fbe72f3 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -114,11 +114,16 @@ public: #if ENABLE_NEW_MENU_LAYOUT void load_project(); void add_model(); + void extract_config_from_project(); #else void add(); #endif // ENABLE_NEW_MENU_LAYOUT +#if ENABLE_NEW_MENU_LAYOUT + void load_files(const std::vector& input_files, bool load_model = true, bool load_config = true); +#else void load_files(const std::vector &input_files); +#endif // ENABLE_NEW_MENU_LAYOUT void update(bool force_autocenter = false); void select_view(const std::string& direction);