From b08788cf96de313a2702ae0f3ef0298a8ade226e Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 2 Jan 2020 11:42:48 +0100 Subject: [PATCH 1/7] typo at Unmounting successful message --- src/slic3r/GUI/Plater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index b388ad1d2..80a3646f0 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5051,7 +5051,7 @@ void Plater::drive_ejected_callback() if (RemovableDriveManager::get_instance().get_did_eject()) { RemovableDriveManager::get_instance().set_did_eject(false); - wxString message = "Unmounting succesesful. The device " + RemovableDriveManager::get_instance().get_last_save_name() + "(" + RemovableDriveManager::get_instance().get_last_save_path() + ")" + " can now be safely removed from the computer."; + wxString message = "Unmounting successful. The device " + RemovableDriveManager::get_instance().get_last_save_name() + "(" + RemovableDriveManager::get_instance().get_last_save_path() + ")" + " can now be safely removed from the computer."; wxMessageBox(message); } p->show_action_buttons(false); From 7e97576e564a32ac00d9432ca5df71c503458f4e Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 2 Jan 2020 16:30:28 +0100 Subject: [PATCH 2/7] button for exporting gcode to harddrive --- src/slic3r/GUI/AppConfig.cpp | 25 +++++++++- src/slic3r/GUI/AppConfig.hpp | 6 ++- src/slic3r/GUI/Plater.cpp | 60 +++++++++++++++--------- src/slic3r/GUI/Plater.hpp | 3 +- src/slic3r/GUI/RemovableDriveManager.cpp | 6 ++- src/slic3r/GUI/RemovableDriveManager.hpp | 3 +- 6 files changed, 74 insertions(+), 29 deletions(-) diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 12302a5dc..a410f3ad8 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 b432367b6..32f1c32c8 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 80a3646f0..c7f374085 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 1bea07795..f9891a252 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 5041e2120..99da30ed8 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 1767490d1..b5b5c0952 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(); From 53f04b4bfdddb6fbc533ffe9cfcafeda1243aea7 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 3 Jan 2020 10:33:44 +0100 Subject: [PATCH 3/7] callback for showing action buttons when device is connected/disconnected --- src/slic3r/GUI/Plater.cpp | 4 ++++ src/slic3r/GUI/RemovableDriveManager.cpp | 17 +++++++++++++++-- src/slic3r/GUI/RemovableDriveManager.hpp | 8 +++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c7f374085..d54083e36 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2199,6 +2199,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) // Initialize the Undo / Redo stack with a first snapshot. this->take_snapshot(_(L("New Project"))); + + //void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const + RemovableDriveManager::get_instance().set_drive_count_changed_callback(std::bind(&Plater::priv::show_action_buttons, this, std::placeholders::_1)); } Plater::priv::~priv() @@ -4159,6 +4162,7 @@ void Plater::priv::update_object_menu() void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const { + RemovableDriveManager::get_instance().set_plater_ready_to_slice(is_ready_to_slice); wxWindowUpdateLocker noUpdater(sidebar); const auto prin_host_opt = config->option("print_host"); const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty(); diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 99da30ed8..74197d677 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -414,7 +414,8 @@ RemovableDriveManager::RemovableDriveManager(): m_last_save_name(""), m_last_save_path_verified(false), m_is_writing(false), - m_did_eject(false) + m_did_eject(false), + m_plater_ready_to_slice(true) #if __APPLE__ , m_rdmmm(new RDMMMWrapper()) #endif @@ -495,6 +496,10 @@ std::vector RemovableDriveManager::get_all_drives() } void RemovableDriveManager::check_and_notify() { + if(m_drive_count_changed_callback) + { + m_drive_count_changed_callback(m_plater_ready_to_slice); + } if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path_verified && !is_drive_mounted(m_last_save_path)) { for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) @@ -507,10 +512,18 @@ void RemovableDriveManager::add_remove_callback(std::function callback) { m_callbacks.push_back(callback); } -void RemovableDriveManager::erase_callbacks() +void RemovableDriveManager::erase_callbacks() { m_callbacks.clear(); } +void RemovableDriveManager::set_drive_count_changed_callback(std::function callback) +{ + m_drive_count_changed_callback = callback; +} +void RemovableDriveManager::set_plater_ready_to_slice(bool b) +{ + m_plater_ready_to_slice = b; +} void RemovableDriveManager::set_last_save_path(const std::string& path) { m_last_save_path_verified = false; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index b5b5c0952..8ba2bc64d 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -46,8 +46,12 @@ public: bool is_path_on_removable_drive(const std::string &path); // callback will notify only if device with last save path was removed void add_remove_callback(std::function callback); - // erases all callbacks added by add_callback() + // erases all remove callbacks added by add_remove_callback() void erase_callbacks(); + //drive_count_changed callback is called on every added or removed device + void set_drive_count_changed_callback(std::function callback); + //thi serves to set correct value for drive_count_changed callback + void set_plater_ready_to_slice(bool b); // marks one of the eveices in vector as last used void set_last_save_path(const std::string &path); void verify_last_save_path(); @@ -71,6 +75,7 @@ private: std::vector m_current_drives; std::vector> m_callbacks; + std::function m_drive_count_changed_callback; size_t m_drives_count; long m_last_update; std::string m_last_save_path; @@ -78,6 +83,7 @@ private: std::string m_last_save_name; bool m_is_writing;//on device bool m_did_eject; + bool m_plater_ready_to_slice; #if _WIN32 //registers for notifications by creating invisible window void register_window(); From 787a6264b1738cf55ed8045afa9d1c9100c65bb5 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 10 Jan 2020 16:25:32 +0100 Subject: [PATCH 4/7] changed button usage: save to hd is now save to sd card --- src/slic3r/GUI/Plater.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index d54083e36..7fd272d0a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -701,7 +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) + ScalableButton* btn_export_gcode_removable; //exports to removable drives (appears only if removable drive is connected) priv(Plater *plater) : plater(plater) {} ~priv(); @@ -867,7 +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"))); + init_scalable_btn(&p->btn_export_gcode_removable, "export_gcode", _(L("Export to SD card/ USB thumb drive"))); // regular buttons "Slice now" and "Export G-code" @@ -888,8 +888,9 @@ Sidebar::Sidebar(Plater *parent) auto* complect_btns_sizer = new wxBoxSizer(wxHORIZONTAL); 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); + complect_btns_sizer->Add(p->btn_remove_device); + btns_sizer->Add(p->btn_reslice, 0, wxEXPAND | wxTOP, margin_5); btns_sizer->Add(complect_btns_sizer, 0, wxEXPAND | wxTOP, margin_5); @@ -900,7 +901,7 @@ Sidebar::Sidebar(Plater *parent) SetSizer(sizer); // Events - p->btn_export_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->export_gcode(true); }); + p->btn_export_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->export_gcode(false); }); p->btn_reslice->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { const bool export_gcode_after_slicing = wxGetKeyState(WXK_SHIFT); @@ -912,7 +913,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); }); + p->btn_export_gcode_removable->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->export_gcode(true); }); } Sidebar::~Sidebar() {} @@ -4175,8 +4176,8 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const 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->show_export_removable(export_removable_shown) | + sidebar->show_disconnect(disconnect_shown)) sidebar->Layout(); } else @@ -4184,8 +4185,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_export_removable(export_removable_shown && !is_ready_to_slice)) + sidebar->show_export_removable(export_removable_shown && !is_ready_to_slice) | + sidebar->show_disconnect(disconnect_shown && !is_ready_to_slice)) sidebar->Layout(); } } From 2c1bedf50365e44578cb2861f0965b88062c6260 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 20 Jan 2020 16:39:59 +0100 Subject: [PATCH 5/7] new graphics for export button --- resources/icons/export_to_sd.svg | 145 +++++++++++++++++++++++++++++++ src/slic3r/GUI/Plater.cpp | 2 +- 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 resources/icons/export_to_sd.svg diff --git a/resources/icons/export_to_sd.svg b/resources/icons/export_to_sd.svg new file mode 100644 index 000000000..c836b00a1 --- /dev/null +++ b/resources/icons/export_to_sd.svg @@ -0,0 +1,145 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7fd272d0a..6906614f8 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -867,7 +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 SD card/ USB thumb drive"))); + init_scalable_btn(&p->btn_export_gcode_removable, "export_to_sd", _(L("Export to SD card/ USB thumb drive"))); // regular buttons "Slice now" and "Export G-code" From 8cf2a978076cad1a1cecb8b62e3d1df55586df78 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 21 Jan 2020 10:23:50 +0100 Subject: [PATCH 6/7] removable drive manager bug fixes --- src/slic3r/GUI/Plater.cpp | 6 ++-- src/slic3r/GUI/RemovableDriveManager.cpp | 38 ++++++++++++++++++++---- src/slic3r/GUI/RemovableDriveManager.hpp | 4 +++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 6906614f8..15820c68a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5060,8 +5060,8 @@ void Plater::send_gcode() void Plater::eject_drive() { RemovableDriveManager::get_instance().update(0, true); - //RemovableDriveManager::get_instance().erase_callbacks(); - //RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); + RemovableDriveManager::get_instance().erase_callbacks(); + RemovableDriveManager::get_instance().add_remove_callback(std::bind(&Plater::drive_ejected_callback, this)); RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_save_path()); } @@ -5070,7 +5070,7 @@ void Plater::drive_ejected_callback() if (RemovableDriveManager::get_instance().get_did_eject()) { RemovableDriveManager::get_instance().set_did_eject(false); - wxString message = "Unmounting successful. The device " + RemovableDriveManager::get_instance().get_last_save_name() + "(" + RemovableDriveManager::get_instance().get_last_save_path() + ")" + " can now be safely removed from the computer."; + wxString message = "Unmounting successful. The device " + RemovableDriveManager::get_instance().get_ejected_name() + "(" + RemovableDriveManager::get_instance().get_ejected_path() + ")" + " can now be safely removed from the computer."; wxMessageBox(message); } p->show_action_buttons(false); diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 74197d677..76e028994 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -109,6 +109,8 @@ void RemovableDriveManager::eject_drive(const std::string &path) CloseHandle(handle); m_did_eject = true; m_current_drives.erase(it); + m_ejected_path = m_last_save_path; + m_ejected_name = m_last_save_name; break; } } @@ -373,7 +375,8 @@ void RemovableDriveManager::eject_drive(const std::string &path) m_did_eject = true; m_current_drives.erase(it); - + m_ejected_path = m_last_save_path; + m_ejected_name = m_last_save_name; break; } @@ -415,7 +418,9 @@ RemovableDriveManager::RemovableDriveManager(): m_last_save_path_verified(false), m_is_writing(false), m_did_eject(false), - m_plater_ready_to_slice(true) + m_plater_ready_to_slice(true), + m_ejected_path(""), + m_ejected_name("") #if __APPLE__ , m_rdmmm(new RDMMMWrapper()) #endif @@ -452,7 +457,10 @@ bool RemovableDriveManager::update(const long time,const bool check) search_for_drives(); if (m_drives_count != m_current_drives.size()) { - if (check)check_and_notify(); + if (check) + { + check_and_notify(); + } m_drives_count = m_current_drives.size(); } return !m_current_drives.empty(); @@ -500,7 +508,8 @@ void RemovableDriveManager::check_and_notify() { m_drive_count_changed_callback(m_plater_ready_to_slice); } - if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path_verified && !is_drive_mounted(m_last_save_path)) + std::cout << m_callbacks.size() << m_last_save_path_verified << !is_drive_mounted(m_last_save_path) << std::endl; + if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() /*&& m_last_save_path_verified */&& !is_drive_mounted(m_last_save_path)) { for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) { @@ -526,8 +535,17 @@ void RemovableDriveManager::set_plater_ready_to_slice(bool b) } void RemovableDriveManager::set_last_save_path(const std::string& path) { - m_last_save_path_verified = false; - m_last_save_path = path; + if(m_last_save_path_verified)// if old path is on drive + { + if(get_drive_from_path(path) != "") //and new is too, rewrite the path + { + m_last_save_path_verified = false; + m_last_save_path = path; + }//else do nothing + }else + { + m_last_save_path = path; + } } void RemovableDriveManager::verify_last_save_path() { @@ -604,4 +622,12 @@ size_t RemovableDriveManager::get_drives_count() { return m_current_drives.size(); } +std::string RemovableDriveManager::get_ejected_path() +{ + return m_ejected_path; +} +std::string RemovableDriveManager::get_ejected_name() +{ + return m_ejected_name; +} }}//namespace Slicer::Gui diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 8ba2bc64d..6bd90e98c 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -64,6 +64,8 @@ public: void set_did_eject(const bool b); std::string get_drive_name(const std::string& path); size_t get_drives_count(); + std::string get_ejected_path(); + std::string get_ejected_name(); private: RemovableDriveManager(); void search_for_drives(); @@ -84,6 +86,8 @@ private: bool m_is_writing;//on device bool m_did_eject; bool m_plater_ready_to_slice; + std::string m_ejected_path; + std::string m_ejected_name; #if _WIN32 //registers for notifications by creating invisible window void register_window(); From 4c46bece96e7dc84768084213a8a14154ac025b8 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 21 Jan 2020 13:06:10 +0100 Subject: [PATCH 7/7] removable drive manager bug fixes linux --- src/slic3r/GUI/RemovableDriveManager.cpp | 42 ++++-------------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 76e028994..4ed6d36a4 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -241,35 +241,10 @@ void RemovableDriveManager::search_for_drives() //search /media/* folder search_path("/media/*", "/media"); - //search /Volumes/* folder (OSX) //search_path("/Volumes/*", "/Volumes"); std::string path(std::getenv("USER")); std::string pp(path); - //std::cout << "user: "<< path << "\n"; - //if program is run with sudo, we have to search for all users - // but do we want that? - /* - if(path == "root"){ - while (true) { - passwd* entry = getpwent(); - if (!entry) { - break; - } - path = entry->pw_name; - pp = path; - //search /media/USERNAME/* folder - pp = "/media/"+pp; - path = "/media/" + path + "/*"; - search_path(path, pp); - //search /run/media/USERNAME/* folder - path = "/run" + path; - pp = "/run"+pp; - search_path(path, pp); - } - endpwent(); - }else - */ { //search /media/USERNAME/* folder pp = "/media/"+pp; @@ -312,7 +287,6 @@ void RemovableDriveManager::inspect_file(const std::string &path, const std::str { //free space boost::filesystem::space_info si = boost::filesystem::space(path); - //std::cout << "Free space: " << fs_si.free << "Available space: " << fs_si.available << " " << path << '\n'; if(si.available != 0) { //user id @@ -355,7 +329,7 @@ void RemovableDriveManager::eject_drive(const std::string &path) i++; } } - std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<<"\n"; + //std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<<"\n"; // there is no usable command in c++ so terminal command is used instead // but neither triggers "succesful safe removal messege" std::string command = ""; @@ -388,7 +362,7 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) if (m_current_drives.empty()) return false; std::size_t found = path.find_last_of("/"); - std::string new_path = path.substr(0,found); + std::string new_path = found == path.size() - 1 ? path.substr(0, found) : path; for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) { if(compare_filesystem_id(new_path, (*it).path)) @@ -399,7 +373,7 @@ bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path) std::string RemovableDriveManager::get_drive_from_path(const std::string& path) { std::size_t found = path.find_last_of("/"); - std::string new_path = path.substr(0, found); + std::string new_path = found == path.size() - 1 ? path.substr(0, found) : path; //check if same filesystem for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it) { @@ -508,7 +482,6 @@ void RemovableDriveManager::check_and_notify() { m_drive_count_changed_callback(m_plater_ready_to_slice); } - std::cout << m_callbacks.size() << m_last_save_path_verified << !is_drive_mounted(m_last_save_path) << std::endl; if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() /*&& m_last_save_path_verified */&& !is_drive_mounted(m_last_save_path)) { for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) @@ -575,16 +548,15 @@ std::string RemovableDriveManager::get_drive_name(const std::string& path) } bool RemovableDriveManager::is_last_drive_removed() { - //std::cout<<"is last: "<