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>
|
2019-03-20 10:12:37 +00:00
|
|
|
|
2018-10-02 11:23:38 +00:00
|
|
|
#include "GUI_App.hpp"
|
2018-08-29 16:02:10 +00:00
|
|
|
|
2019-03-20 10:12:37 +00:00
|
|
|
#include "I18N.hpp"
|
|
|
|
|
2018-08-29 16:02:10 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2019-07-30 15:52:05 +00:00
|
|
|
ProgressStatusBar::ProgressStatusBar(wxWindow *parent, int id)
|
|
|
|
: self{new wxStatusBar(parent ? parent : GUI::wxGetApp().mainframe,
|
|
|
|
id == -1 ? wxID_ANY : id)}
|
|
|
|
, m_prog{new wxGauge(self,
|
|
|
|
wxGA_HORIZONTAL,
|
|
|
|
100,
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize)}
|
|
|
|
, m_cancelbutton{new wxButton(self,
|
|
|
|
-1,
|
|
|
|
_(L("Cancel")),
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize)}
|
|
|
|
, m_timer{new wxTimer(self)}
|
2018-08-29 16:02:10 +00:00
|
|
|
{
|
2018-09-19 12:54:37 +00:00
|
|
|
m_prog->Hide();
|
|
|
|
m_cancelbutton->Hide();
|
2018-08-29 16:02:10 +00:00
|
|
|
|
2019-05-06 16:28:23 +00:00
|
|
|
self->SetFont(GUI::wxGetApp().normal_font());
|
2018-08-29 16:02:10 +00:00
|
|
|
self->SetFieldsCount(3);
|
|
|
|
int w[] = {-1, 150, 155};
|
|
|
|
self->SetStatusWidths(3, w);
|
|
|
|
|
2019-03-20 10:12:37 +00:00
|
|
|
wxSize s = m_cancelbutton->GetTextExtent(m_cancelbutton->GetLabel());
|
|
|
|
self->SetMinHeight(int(2 * self->GetBorderY() + 1.2 * s.GetHeight()));
|
|
|
|
|
2018-08-29 16:02:10 +00:00
|
|
|
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&) {
|
2018-10-23 13:27:31 +00:00
|
|
|
if (m_cancel_cb)
|
|
|
|
m_cancel_cb();
|
2018-09-19 12:54:37 +00:00
|
|
|
m_cancelbutton->Hide();
|
2018-08-29 16:02:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressStatusBar::~ProgressStatusBar() {
|
2019-05-13 08:20:37 +00:00
|
|
|
if(m_timer && m_timer->IsRunning()) m_timer->Stop();
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ProgressStatusBar::get_progress() const
|
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
return m_prog ? m_prog->GetValue() : 0;
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::set_progress(int val)
|
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(!m_prog) return;
|
|
|
|
|
2018-09-19 12:54:37 +00:00
|
|
|
if(!m_prog->IsShown()) show_progress(true);
|
2018-11-29 17:12:40 +00:00
|
|
|
if(val < 0) return;
|
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);
|
2018-11-29 09:57:06 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
return m_prog ? m_prog->GetRange() : 0;
|
2018-08-30 09:40:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 16:02:10 +00:00
|
|
|
void ProgressStatusBar::set_range(int val)
|
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(m_prog && val != m_prog->GetRange()) {
|
2018-09-19 12:54:37 +00:00
|
|
|
m_prog->SetRange(val);
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::show_progress(bool show)
|
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(m_prog) {
|
|
|
|
m_prog->Show(show);
|
|
|
|
m_prog->Pulse();
|
|
|
|
}
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::start_busy(int rate)
|
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(!m_prog) return;
|
|
|
|
|
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()
|
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(!m_timer || !m_prog) return;
|
|
|
|
|
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;
|
2019-05-13 08:20:37 +00:00
|
|
|
if(m_cancelbutton) {
|
|
|
|
if(ccb) m_cancelbutton->Show();
|
|
|
|
else m_cancelbutton->Hide();
|
|
|
|
}
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::run(int rate)
|
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(m_timer && !m_timer->IsRunning()) {
|
2018-09-19 12:54:37 +00:00
|
|
|
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-10-02 11:23:38 +00:00
|
|
|
wxFrame* mf = frame ? frame : GUI::wxGetApp().mainframe;
|
2019-05-13 08:20:37 +00:00
|
|
|
if(mf) mf->SetStatusBar(self);
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
void ProgressStatusBar::set_status_text(const wxString& txt)
|
2018-08-29 16:02:10 +00:00
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(self) self->SetStatusText(txt);
|
2018-10-23 13:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::set_status_text(const std::string& txt)
|
|
|
|
{
|
|
|
|
this->set_status_text(txt.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressStatusBar::set_status_text(const char *txt)
|
|
|
|
{
|
|
|
|
this->set_status_text(wxString::FromUTF8(txt));
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 16:58:56 +00:00
|
|
|
wxString ProgressStatusBar::get_status_text() const
|
|
|
|
{
|
|
|
|
return self->GetStatusText();
|
|
|
|
}
|
|
|
|
|
2018-08-30 09:40:06 +00:00
|
|
|
void ProgressStatusBar::show_cancel_button()
|
2018-08-29 16:02:10 +00:00
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(m_cancelbutton) 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
|
|
|
{
|
2019-05-13 08:20:37 +00:00
|
|
|
if(m_cancelbutton) m_cancelbutton->Hide();
|
2018-08-29 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|