eject button functionality
This commit is contained in:
parent
01f1bed060
commit
f5e3750d23
4 changed files with 34 additions and 17 deletions
|
@ -902,6 +902,7 @@ Sidebar::Sidebar(Plater *parent)
|
||||||
p->btn_send_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->send_gcode(); });
|
p->btn_send_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->send_gcode(); });
|
||||||
p->btn_disconnect->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
|
p->btn_disconnect->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
|
||||||
// #dk_FIXME
|
// #dk_FIXME
|
||||||
|
p->plater->eject_drive();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4149,7 +4150,7 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const
|
||||||
const auto prin_host_opt = config->option<ConfigOptionString>("print_host");
|
const auto prin_host_opt = config->option<ConfigOptionString>("print_host");
|
||||||
const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty();
|
const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty();
|
||||||
|
|
||||||
const bool disconnect_shown = true; // #dk_FIXME
|
const bool disconnect_shown = !(RemovableDriveManager::get_instance().is_last_drive_removed()); // #dk_FIXME
|
||||||
|
|
||||||
// when a background processing is ON, export_btn and/or send_btn are showing
|
// when a background processing is ON, export_btn and/or send_btn are showing
|
||||||
if (wxGetApp().app_config->get("background_processing") == "1")
|
if (wxGetApp().app_config->get("background_processing") == "1")
|
||||||
|
@ -4992,6 +4993,22 @@ void Plater::send_gcode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Plater::eject_drive()
|
||||||
|
{
|
||||||
|
if (GUI::RemovableDriveManager::get_instance().update())
|
||||||
|
{
|
||||||
|
RemovableDriveManager::get_instance().erase_callbacks();
|
||||||
|
RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this));
|
||||||
|
RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_drive_path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Plater::drive_ejected_callback()
|
||||||
|
{
|
||||||
|
p->show_action_buttons(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Plater::take_snapshot(const std::string &snapshot_name) { p->take_snapshot(snapshot_name); }
|
void Plater::take_snapshot(const std::string &snapshot_name) { p->take_snapshot(snapshot_name); }
|
||||||
void Plater::take_snapshot(const wxString &snapshot_name) { p->take_snapshot(snapshot_name); }
|
void Plater::take_snapshot(const wxString &snapshot_name) { p->take_snapshot(snapshot_name); }
|
||||||
void Plater::suppress_snapshots() { p->suppress_snapshots(); }
|
void Plater::suppress_snapshots() { p->suppress_snapshots(); }
|
||||||
|
|
|
@ -202,6 +202,8 @@ public:
|
||||||
void suppress_background_process(const bool stop_background_process) ;
|
void suppress_background_process(const bool stop_background_process) ;
|
||||||
void fix_through_netfabb(const int obj_idx, const int vol_idx = -1);
|
void fix_through_netfabb(const int obj_idx, const int vol_idx = -1);
|
||||||
void send_gcode();
|
void send_gcode();
|
||||||
|
void eject_drive();
|
||||||
|
void drive_ejected_callback();
|
||||||
|
|
||||||
void take_snapshot(const std::string &snapshot_name);
|
void take_snapshot(const std::string &snapshot_name);
|
||||||
void take_snapshot(const wxString &snapshot_name);
|
void take_snapshot(const wxString &snapshot_name);
|
||||||
|
|
|
@ -395,9 +395,9 @@ std::string RemovableDriveManager::get_drive_from_path(const std::string& path)
|
||||||
RemovableDriveManager::RemovableDriveManager():
|
RemovableDriveManager::RemovableDriveManager():
|
||||||
m_drives_count(0),
|
m_drives_count(0),
|
||||||
m_last_update(0),
|
m_last_update(0),
|
||||||
m_last_save_path(""),
|
m_last_save_path("")
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
m_rdmmm(new RDMMMWrapper())
|
, m_rdmmm(new RDMMMWrapper())
|
||||||
#endif
|
#endif
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ void RemovableDriveManager::init()
|
||||||
#endif
|
#endif
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
bool RemovableDriveManager::update(const long time)
|
bool RemovableDriveManager::update(const long time, bool check)
|
||||||
{
|
{
|
||||||
if(time != 0) //time = 0 is forced update
|
if(time != 0) //time = 0 is forced update
|
||||||
{
|
{
|
||||||
|
@ -425,7 +425,7 @@ bool RemovableDriveManager::update(const long time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
search_for_drives();
|
search_for_drives();
|
||||||
check_and_notify();
|
if(check)check_and_notify();
|
||||||
return !m_current_drives.empty();
|
return !m_current_drives.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,13 +444,7 @@ bool RemovableDriveManager::is_drive_mounted(const std::string &path)
|
||||||
|
|
||||||
std::string RemovableDriveManager::get_last_drive_path()
|
std::string RemovableDriveManager::get_last_drive_path()
|
||||||
{
|
{
|
||||||
if (!m_current_drives.empty())
|
return m_last_save_path;
|
||||||
{
|
|
||||||
if (m_last_save_path != "")
|
|
||||||
return m_last_save_path;
|
|
||||||
return m_current_drives.back().path;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
std::vector<DriveData> RemovableDriveManager::get_all_drives()
|
std::vector<DriveData> RemovableDriveManager::get_all_drives()
|
||||||
{
|
{
|
||||||
|
@ -495,11 +489,13 @@ bool RemovableDriveManager::is_last_drive_removed()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return !is_drive_mounted(m_last_save_path);
|
bool r = !is_drive_mounted(m_last_save_path);
|
||||||
|
if (r) reset_last_save_path();
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
bool RemovableDriveManager::is_last_drive_removed_with_update(const long time)
|
bool RemovableDriveManager::is_last_drive_removed_with_update(const long time)
|
||||||
{
|
{
|
||||||
update(time);
|
update(time, false);
|
||||||
return is_last_drive_removed();
|
return is_last_drive_removed();
|
||||||
}
|
}
|
||||||
void RemovableDriveManager::reset_last_save_path()
|
void RemovableDriveManager::reset_last_save_path()
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
|
|
||||||
//update() searches for removable devices, returns false if empty.
|
//update() searches for removable devices, returns false if empty.
|
||||||
void init();
|
void init();
|
||||||
bool update(const long time = 0); //time = 0 is forced update, time expects wxGetLocalTime()
|
bool update(const long time = 0, bool check = true); //time = 0 is forced update, time expects wxGetLocalTime()
|
||||||
bool is_drive_mounted(const std::string &path);
|
bool is_drive_mounted(const std::string &path);
|
||||||
void eject_drive(const std::string &path);
|
void eject_drive(const std::string &path);
|
||||||
std::string get_last_drive_path();
|
std::string get_last_drive_path();
|
||||||
|
@ -41,9 +41,8 @@ public:
|
||||||
void add_callback(std::function<void()> callback); // callback will notify only if device with last save path was removed
|
void add_callback(std::function<void()> callback); // callback will notify only if device with last save path was removed
|
||||||
void erase_callbacks(); // erases all callbacks added by add_callback()
|
void erase_callbacks(); // erases all callbacks added by add_callback()
|
||||||
void set_last_save_path(const std::string &path);
|
void set_last_save_path(const std::string &path);
|
||||||
bool is_last_drive_removed(); //if we dont need info about this drive, call reset_last_save_path();
|
bool is_last_drive_removed();
|
||||||
bool is_last_drive_removed_with_update(const long time = 0); // param as update()
|
bool is_last_drive_removed_with_update(const long time = 0); // param as update()
|
||||||
void reset_last_save_path();
|
|
||||||
void print();
|
void print();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -51,11 +50,14 @@ private:
|
||||||
void search_for_drives();
|
void search_for_drives();
|
||||||
void check_and_notify();
|
void check_and_notify();
|
||||||
std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string ""
|
std::string get_drive_from_path(const std::string& path);//returns drive path (same as path in DriveData) if exists otherwise empty string ""
|
||||||
|
void reset_last_save_path();
|
||||||
|
|
||||||
std::vector<DriveData> m_current_drives;
|
std::vector<DriveData> m_current_drives;
|
||||||
std::vector<std::function<void()>> m_callbacks;
|
std::vector<std::function<void()>> m_callbacks;
|
||||||
size_t m_drives_count;
|
size_t m_drives_count;
|
||||||
long m_last_update;
|
long m_last_update;
|
||||||
std::string m_last_save_path;
|
std::string m_last_save_path;
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
void register_window();
|
void register_window();
|
||||||
//INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
//INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
Loading…
Reference in a new issue