2018-08-29 16:02:10 +00:00
|
|
|
#include "ProgressStatusBar.hpp"
|
|
|
|
|
|
|
|
#include <wx/timer.h>
|
|
|
|
#include <wx/gauge.h>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/statusbr.h>
|
|
|
|
#include <wx/frame.h>
|
|
|
|
#include "GUI.hpp"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
ProgressStatusBar::ProgressStatusBar(wxWindow *parent, int id):
|
|
|
|
self(new wxStatusBar(parent ? parent : GUI::get_main_frame(),
|
|
|
|
id == -1? wxID_ANY : id)),
|
2018-09-19 12:54:37 +00:00
|
|
|
m_timer(new wxTimer(self)),
|
|
|
|
m_prog (new wxGauge(self,
|
2018-08-29 16:02:10 +00:00
|
|
|
wxGA_HORIZONTAL,
|
|
|
|
100,
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize)),
|
2018-09-19 12:54:37 +00:00
|
|
|
m_cancelbutton(new wxButton(self,
|
2018-08-29 16:02:10 +00:00
|
|
|
-1,
|
|
|
|
"Cancel",
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize))
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
m_prog->Hide();
|
|
|
|
m_cancelbutton->Hide();
|
2018-08-29 16:02:10 +00:00
|
|
|
|
|
|
|
self->SetFieldsCount(3);
|
|
|
|
int w[] = {-1, 150, 155};
|
|
|
|
self->SetStatusWidths(3, w);
|
|
|
|
|
|
|
|
self->Bind(wxEVT_TIMER, [this](const wxTimerEvent&) {
|
2018-09-19 12:54:37 +00:00
|
|
|
if (m_prog->IsShown()) m_timer->Stop();
|
|
|
|
if(is_busy()) m_prog->Pulse();
|
2018-08-29 16:02:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
self->Bind(wxEVT_SIZE, [this](wxSizeEvent& event){
|
|
|
|
wxRect rect;
|
|
|
|
self->GetFieldRect(1, rect);
|
|
|
|
auto offset = 0;
|
2018-09-19 12:54:37 +00:00
|
|
|
m_cancelbutton->Move(rect.GetX() + offset, rect.GetY() + offset);
|
|
|
|
m_cancelbutton->SetSize(rect.GetWidth() - offset, rect.GetHeight());
|
2018-08-29 16:02:10 +00:00
|
|
|
|
|
|
|
self->GetFieldRect(2, rect);
|
2018-09-19 12:54:37 +00:00
|
|
|
m_prog->Move(rect.GetX() + offset, rect.GetY() + offset);
|
|
|
|
m_prog->SetSize(rect.GetWidth() - offset, rect.GetHeight());
|
2018-08-29 16:02:10 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
});
|
|
|
|
|
2018-09-19 12:54:37 +00:00
|
|
|
m_cancelbutton->Bind(wxEVT_BUTTON, [this](const wxCommandEvent&) {
|
|
|
|
if(m_cancel_cb) m_cancel_cb();
|
2018-09-14 08:59:50 +00:00
|
|
|
m_perl_cancel_callback.call();
|
2018-09-19 12:54:37 +00:00
|
|
|
m_cancelbutton->Hide();
|
2018-08-29 16:02:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressStatusBar::~ProgressStatusBar() {
|
2018-09-19 12:54:37 +00:00
|
|
|
if(m_timer->IsRunning()) m_timer->Stop();
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ProgressStatusBar::get_progress() const
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
return m_prog->GetValue();
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::set_progress(int val)
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
if(!m_prog->IsShown()) show_progress(true);
|
2018-08-29 16:02:10 +00:00
|
|
|
|
2018-09-19 12:54:37 +00:00
|
|
|
if(val == m_prog->GetRange()) {
|
|
|
|
m_prog->SetValue(0);
|
2018-08-29 16:02:10 +00:00
|
|
|
show_progress(false);
|
|
|
|
} else {
|
2018-09-19 12:54:37 +00:00
|
|
|
m_prog->SetValue(val);
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 09:40:06 +00:00
|
|
|
int ProgressStatusBar::get_range() const
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
return m_prog->GetRange();
|
2018-08-30 09:40:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 16:02:10 +00:00
|
|
|
void ProgressStatusBar::set_range(int val)
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
if(val != m_prog->GetRange()) {
|
|
|
|
m_prog->SetRange(val);
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::show_progress(bool show)
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
m_prog->Show(show);
|
|
|
|
m_prog->Pulse();
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::start_busy(int rate)
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
m_busy = true;
|
2018-08-29 16:02:10 +00:00
|
|
|
show_progress(true);
|
2018-09-19 12:54:37 +00:00
|
|
|
if (!m_timer->IsRunning()) {
|
|
|
|
m_timer->Start(rate);
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::stop_busy()
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
m_timer->Stop();
|
2018-08-29 16:02:10 +00:00
|
|
|
show_progress(false);
|
2018-09-19 12:54:37 +00:00
|
|
|
m_prog->SetValue(0);
|
|
|
|
m_busy = false;
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::set_cancel_callback(ProgressStatusBar::CancelFn ccb) {
|
2018-09-19 12:54:37 +00:00
|
|
|
m_cancel_cb = ccb;
|
|
|
|
if(ccb) m_cancelbutton->Show();
|
|
|
|
else m_cancelbutton->Hide();
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::run(int rate)
|
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
if(!m_timer->IsRunning()) {
|
|
|
|
m_timer->Start(rate);
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 09:40:06 +00:00
|
|
|
void ProgressStatusBar::embed(wxFrame *frame)
|
2018-08-29 16:02:10 +00:00
|
|
|
{
|
2018-09-20 23:33:41 +00:00
|
|
|
wxFrame* mf = frame ? frame : GUI::get_main_frame();
|
2018-08-29 16:02:10 +00:00
|
|
|
mf->SetStatusBar(self);
|
|
|
|
}
|
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
void ProgressStatusBar::set_status_text(const wxString& txt)
|
2018-08-29 16:02:10 +00:00
|
|
|
{
|
2018-09-12 11:17:47 +00:00
|
|
|
self->SetStatusText(wxString::FromUTF8(txt.c_str()));
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 09:40:06 +00:00
|
|
|
void ProgressStatusBar::show_cancel_button()
|
2018-08-29 16:02:10 +00:00
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
m_cancelbutton->Show();
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 09:40:06 +00:00
|
|
|
void ProgressStatusBar::hide_cancel_button()
|
2018-08-29 16:02:10 +00:00
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
m_cancelbutton->Hide();
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|