diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 12302a5dc1..a410f3ad8d 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/slic3r/GUI/AppConfig.cpp @@ -78,6 +78,9 @@ void AppConfig::set_defaults() if (get("remember_output_path").empty()) set("remember_output_path", "1"); + if (get("remember_output_path_removable").empty()) + set("remember_output_path_removable", "1"); + if (get("use_custom_toolbar_size").empty()) set("use_custom_toolbar_size", "0"); @@ -388,7 +391,7 @@ void AppConfig::update_skein_dir(const std::string &dir) { this->set("recent", "skein_directory", dir); } - +/* std::string AppConfig::get_last_output_dir(const std::string &alt) const { @@ -406,6 +409,26 @@ void AppConfig::update_last_output_dir(const std::string &dir) { this->set("", "last_output_path", dir); } +*/ +std::string AppConfig::get_last_output_dir(const std::string& alt, const bool removable) const +{ + std::string s1 = (removable ? "last_output_path_removable" : "last_output_path"); + std::string s2 = (removable ? "remember_output_path_removable" : "remember_output_path"); + const auto it = m_storage.find(""); + if (it != m_storage.end()) { + const auto it2 = it->second.find(s1); + const auto it3 = it->second.find(s2); + if (it2 != it->second.end() && it3 != it->second.end() && !it2->second.empty() && it3->second == "1") + return it2->second; + } + return alt; +} + +void AppConfig::update_last_output_dir(const std::string& dir, const bool removable) +{ + this->set("", (removable ? "last_output_path_removable" : "last_output_path"), dir); +} + void AppConfig::reset_selections() { diff --git a/src/slic3r/GUI/AppConfig.hpp b/src/slic3r/GUI/AppConfig.hpp index b432367b66..32f1c32c85 100644 --- a/src/slic3r/GUI/AppConfig.hpp +++ b/src/slic3r/GUI/AppConfig.hpp @@ -102,8 +102,10 @@ public: void update_config_dir(const std::string &dir); void update_skein_dir(const std::string &dir); - std::string get_last_output_dir(const std::string &alt) const; - void update_last_output_dir(const std::string &dir); + //std::string get_last_output_dir(const std::string &alt) const; + //void update_last_output_dir(const std::string &dir); + std::string get_last_output_dir(const std::string& alt, const bool removable = false) const; + void update_last_output_dir(const std::string &dir, const bool removable = false); // reset the current print / filament / printer selections, so that // the PresetBundle::load_selections(const AppConfig &config) call will select diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 80a3646f09..c7f374085a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -701,6 +701,7 @@ struct Sidebar::priv wxButton *btn_reslice; ScalableButton *btn_send_gcode; ScalableButton *btn_remove_device; + ScalableButton* btn_export_gcode_removable; //exports to NON-removable drives (but appears only if removable drive is connected) priv(Plater *plater) : plater(plater) {} ~priv(); @@ -866,6 +867,7 @@ Sidebar::Sidebar(Plater *parent) init_scalable_btn(&p->btn_send_gcode , "export_gcode", _(L("Send to printer"))); init_scalable_btn(&p->btn_remove_device, "cross" , _(L("Remove device"))); + init_scalable_btn(&p->btn_export_gcode_removable, "export_gcode", _(L("Export to hard drive"))); // regular buttons "Slice now" and "Export G-code" @@ -887,6 +889,7 @@ Sidebar::Sidebar(Plater *parent) complect_btns_sizer->Add(p->btn_export_gcode, 1, wxEXPAND); complect_btns_sizer->Add(p->btn_send_gcode); complect_btns_sizer->Add(p->btn_remove_device); + complect_btns_sizer->Add(p->btn_export_gcode_removable); btns_sizer->Add(p->btn_reslice, 0, wxEXPAND | wxTOP, margin_5); btns_sizer->Add(complect_btns_sizer, 0, wxEXPAND | wxTOP, margin_5); @@ -897,7 +900,7 @@ Sidebar::Sidebar(Plater *parent) SetSizer(sizer); // Events - p->btn_export_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->export_gcode(); }); + p->btn_export_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->export_gcode(true); }); p->btn_reslice->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { const bool export_gcode_after_slicing = wxGetKeyState(WXK_SHIFT); @@ -909,6 +912,7 @@ Sidebar::Sidebar(Plater *parent) }); p->btn_send_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->send_gcode(); }); p->btn_remove_device->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->eject_drive(); }); + p->btn_export_gcode_removable->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->export_gcode(false); }); } Sidebar::~Sidebar() {} @@ -1056,6 +1060,7 @@ void Sidebar::msw_rescale() p->btn_send_gcode->msw_rescale(); p->btn_remove_device->msw_rescale(); + p->btn_export_gcode_removable->msw_rescale(); const int scaled_height = p->btn_remove_device->GetBitmap().GetHeight() + 4; p->btn_export_gcode->SetMinSize(wxSize(-1, scaled_height)); p->btn_reslice ->SetMinSize(wxSize(-1, scaled_height)); @@ -1289,12 +1294,14 @@ void Sidebar::enable_buttons(bool enable) p->btn_export_gcode->Enable(enable); p->btn_send_gcode->Enable(enable); p->btn_remove_device->Enable(enable); + p->btn_export_gcode_removable->Enable(enable); } -bool Sidebar::show_reslice(bool show) const { return p->btn_reslice->Show(show); } -bool Sidebar::show_export(bool show) const { return p->btn_export_gcode->Show(show); } -bool Sidebar::show_send(bool show) const { return p->btn_send_gcode->Show(show); } -bool Sidebar::show_disconnect(bool show)const { return p->btn_remove_device->Show(show); } +bool Sidebar::show_reslice(bool show) const { return p->btn_reslice->Show(show); } +bool Sidebar::show_export(bool show) const { return p->btn_export_gcode->Show(show); } +bool Sidebar::show_send(bool show) const { return p->btn_send_gcode->Show(show); } +bool Sidebar::show_disconnect(bool show) const { return p->btn_remove_device->Show(show); } +bool Sidebar::show_export_removable(bool show)const { return p->btn_export_gcode_removable->Show(show); } bool Sidebar::is_multifilament() { @@ -3596,12 +3603,8 @@ void Plater::priv::on_process_completed(wxCommandEvent &evt) if(!canceled && RemovableDriveManager::get_instance().get_is_writing()) { - //if (!RemovableDriveManager::get_instance().is_last_drive_removed()) - //{ - RemovableDriveManager::get_instance().set_is_writing(false); - show_action_buttons(false); - //} - + RemovableDriveManager::get_instance().set_is_writing(false); + show_action_buttons(false); } } @@ -4160,14 +4163,16 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const const auto prin_host_opt = config->option("print_host"); const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty(); - bool disconnect_shown = !RemovableDriveManager::get_instance().is_last_drive_removed() ; // #dk_FIXME + bool disconnect_shown = !RemovableDriveManager::get_instance().is_last_drive_removed(); + bool export_removable_shown = RemovableDriveManager::get_instance().get_drives_count() > 0; // when a background processing is ON, export_btn and/or send_btn are showing if (wxGetApp().app_config->get("background_processing") == "1") { - if (sidebar->show_reslice(false) | - sidebar->show_export(true) | - sidebar->show_send(send_gcode_shown) | - sidebar->show_disconnect(disconnect_shown)) + if (sidebar->show_reslice(false) | + sidebar->show_export(true) | + sidebar->show_send(send_gcode_shown) | + sidebar->show_disconnect(disconnect_shown) | + sidebar->show_export_removable(export_removable_shown)) sidebar->Layout(); } else @@ -4175,7 +4180,8 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const if (sidebar->show_reslice(is_ready_to_slice) | sidebar->show_export(!is_ready_to_slice) | sidebar->show_send(send_gcode_shown && !is_ready_to_slice) | - sidebar->show_disconnect(disconnect_shown && !is_ready_to_slice)) + sidebar->show_disconnect(disconnect_shown && !is_ready_to_slice) | + sidebar->show_export_removable(export_removable_shown && !is_ready_to_slice)) sidebar->Layout(); } } @@ -4684,7 +4690,7 @@ void Plater::cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_uppe } } -void Plater::export_gcode() +void Plater::export_gcode(bool prefer_removable) { if (p->model.objects.empty()) return; @@ -4706,11 +4712,19 @@ void Plater::export_gcode() } default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string())); auto start_dir = wxGetApp().app_config->get_last_output_dir(default_output_file.parent_path().string()); - if (GUI::RemovableDriveManager::get_instance().update()) + bool removable_drives_connected = GUI::RemovableDriveManager::get_instance().update(); + if(prefer_removable) { - if (!RemovableDriveManager::get_instance().is_path_on_removable_drive(start_dir)) + if(removable_drives_connected) { - start_dir = RemovableDriveManager::get_instance().get_drive_path(); + auto start_dir_removable = wxGetApp().app_config->get_last_output_dir(default_output_file.parent_path().string(), true); + if (RemovableDriveManager::get_instance().is_path_on_removable_drive(start_dir_removable)) + { + start_dir = start_dir_removable; + }else + { + start_dir = RemovableDriveManager::get_instance().get_drive_path(); + } } } wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _(L("Save G-code file as:")) : _(L("Save SL1 file as:")), @@ -4723,7 +4737,7 @@ void Plater::export_gcode() fs::path output_path; if (dlg.ShowModal() == wxID_OK) { fs::path path = into_path(dlg.GetPath()); - wxGetApp().app_config->update_last_output_dir(path.parent_path().string()); + wxGetApp().app_config->update_last_output_dir(path.parent_path().string(), RemovableDriveManager::get_instance().is_path_on_removable_drive(path.parent_path().string())); output_path = std::move(path); } if (! output_path.empty()) @@ -4739,7 +4753,7 @@ void Plater::export_gcode() { RemovableDriveManager::get_instance().set_is_writing(true); RemovableDriveManager::get_instance().erase_callbacks(); - RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); + RemovableDriveManager::get_instance().add_remove_callback(std::bind(&Plater::drive_ejected_callback, this)); } } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 1bea077956..f9891a252e 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -120,6 +120,7 @@ public: bool show_export(bool show) const; bool show_send(bool show) const; bool show_disconnect(bool show)const; + bool show_export_removable(bool show) const; bool is_multifilament(); void update_mode(); @@ -186,7 +187,7 @@ public: void cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper = true, bool keep_lower = true, bool rotate_lower = false); - void export_gcode(); + void export_gcode(bool prefer_removable = true); void export_stl(bool extended = false, bool selection_only = false); void export_amf(); void export_3mf(const boost::filesystem::path& output_path = boost::filesystem::path()); diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 5041e21205..99da30ed84 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -503,7 +503,7 @@ void RemovableDriveManager::check_and_notify() } } } -void RemovableDriveManager::add_callback(std::function callback) +void RemovableDriveManager::add_remove_callback(std::function callback) { m_callbacks.push_back(callback); } @@ -587,4 +587,8 @@ void RemovableDriveManager::set_did_eject(const bool b) { m_did_eject = b; } +size_t RemovableDriveManager::get_drives_count() +{ + return m_current_drives.size(); +} }}//namespace Slicer::Gui diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 1767490d10..b5b5c0952b 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -45,7 +45,7 @@ public: std::vector get_all_drives(); bool is_path_on_removable_drive(const std::string &path); // callback will notify only if device with last save path was removed - void add_callback(std::function callback); + void add_remove_callback(std::function callback); // erases all callbacks added by add_callback() void erase_callbacks(); // marks one of the eveices in vector as last used @@ -59,6 +59,7 @@ public: bool get_did_eject(); void set_did_eject(const bool b); std::string get_drive_name(const std::string& path); + size_t get_drives_count(); private: RemovableDriveManager(); void search_for_drives();