From b6d278a36f9917482a85e5786445cae49859cf95 Mon Sep 17 00:00:00 2001 From: remi durand Date: Sun, 25 Apr 2021 02:27:02 +0200 Subject: [PATCH] Add 'export to prusa' menu item An other way to transfert a config to prusa, with the .3mf file. It's more mandatory now that there is extrusion_spacing --- src/libslic3r/Config.cpp | 14 +++++++++++--- src/libslic3r/Config.hpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 8 ++++++-- src/slic3r/GUI/MainFrame.hpp | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 6d5baf69a..4c55087ac 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -814,13 +814,21 @@ size_t ConfigBase::load_from_gcode_string(const char* str) return num_key_value_pairs; } -void ConfigBase::save(const std::string &file) const +void ConfigBase::save(const std::string &file, bool to_prusa) const { boost::nowide::ofstream c; c.open(file, std::ios::out | std::ios::trunc); c << "# " << Slic3r::header_slic3r_generated() << std::endl; - for (const std::string &opt_key : this->keys()) - c << opt_key << " = " << this->opt_serialize(opt_key) << std::endl; + if (to_prusa) + for (std::string opt_key : this->keys()) { + std::string value = this->opt_serialize(opt_key); + this->to_prusa(opt_key, value); + if(!opt_key.empty()) + c << opt_key << " = " << value << std::endl; + } + else + for (const std::string &opt_key : this->keys()) + c << opt_key << " = " << this->opt_serialize(opt_key) << std::endl; c.close(); } diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 3481bcf48..0b0b785d0 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1923,7 +1923,7 @@ public: // Returns number of key/value pairs extracted. size_t load_from_gcode_string(const char* str); void load(const boost::property_tree::ptree &tree); - void save(const std::string &file) const; + void save(const std::string &file, bool to_prusa = false) const; // Set all the nullable values to nils. void null_nullables(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 524c9fd1a..ee1eec002 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1260,6 +1260,10 @@ void MainFrame::init_menubar_as_editor() append_menu_item(export_menu, wxID_ANY, _L("Export Config Bundle With Physical Printers") + dots, _L("Export all presets including physical printers to file"), [this](wxCommandEvent&) { export_configbundle(true); }, "export_config_bundle", nullptr, []() {return true; }, this); + export_menu->AppendSeparator(); + append_menu_item(export_menu, wxID_ANY, _L("Export to &Prusa Config") + dots, _L("Export current configuration to file, with only settings compatible with PrusaSlicer"), + [this](wxCommandEvent&) { export_config(true); }, "export_config", nullptr, + []() {return true; }, this); append_submenu(fileMenu, export_menu, wxID_ANY, _L("&Export"), ""); append_menu_item(fileMenu, wxID_ANY, _L("Ejec&t SD card / Flash drive") + dots + "\tCtrl+T", _L("Eject SD card / Flash drive after the G-code was exported to it."), @@ -1717,7 +1721,7 @@ void MainFrame::repair_stl() Slic3r::GUI::show_info(this, L("Your file was repaired."), L("Repair")); } -void MainFrame::export_config() +void MainFrame::export_config(bool to_prusa) { // Generate a cummulative configuration for the selected print, filaments and printer. auto config = wxGetApp().preset_bundle->full_config(); @@ -1738,7 +1742,7 @@ void MainFrame::export_config() if (!file.IsEmpty()) { wxGetApp().app_config->update_config_dir(get_dir_name(file)); m_last_config = file; - config.save(file.ToUTF8().data()); + config.save(file.ToUTF8().data(), to_prusa); } } diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 45813c1ed..cc965ce52 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -188,7 +188,7 @@ public: void quick_slice(const int qs = qsUndef); void reslice_now(); void repair_stl(); - void export_config(); + void export_config(bool to_prusa = false); // Query user for the config file and open it. void load_config_file(); // Open a config file. Return true if loaded.