Merge remote-tracking branch 'origin/cpp_progress_status_bar' into dev
# Conflicts: # lib/Slic3r/GUI/MainFrame.pm # xs/src/slic3r/AppController.cpp # xs/src/slic3r/AppControllerWx.cpp # xs/src/slic3r/GUI/GUI.hpp
This commit is contained in:
@@ -202,6 +202,8 @@ void set_main_frame(wxFrame *main_frame)
|
||||
g_wxMainFrame = main_frame;
|
||||
}
|
||||
|
||||
wxFrame* get_main_frame() { return g_wxMainFrame; }
|
||||
|
||||
void set_tab_panel(wxNotebook *tab_panel)
|
||||
{
|
||||
g_wxTabPanel = tab_panel;
|
||||
@@ -856,10 +858,6 @@ wxWindow* get_right_panel(){
|
||||
return g_right_panel;
|
||||
}
|
||||
|
||||
wxFrame* get_main_frame() {
|
||||
return g_wxMainFrame;
|
||||
}
|
||||
|
||||
wxNotebook * get_tab_panel() {
|
||||
return g_wxTabPanel;
|
||||
}
|
||||
|
||||
@@ -1,286 +0,0 @@
|
||||
#include "PngExportDialog.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id,
|
||||
const wxString& title, const wxPoint& pos,
|
||||
const wxSize& size, long style ) :
|
||||
wxDialog( parent, id, title, pos, size, style )
|
||||
{
|
||||
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
||||
|
||||
auto top_layout = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Labels
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
auto labels_layout = new wxGridSizer(6, 1, 0, 0);
|
||||
|
||||
// Input File picker label
|
||||
auto filepick_text = new wxStaticText( this, wxID_ANY,
|
||||
_("Target zip file"),
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize, 0 );
|
||||
filepick_text->Wrap( -1 );
|
||||
labels_layout->Add( filepick_text, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||
|
||||
// Config file label
|
||||
auto confpick_text = new wxStaticText( this, wxID_ANY,
|
||||
_("Config file (optional)"),
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize, 0 );
|
||||
confpick_text->Wrap( -1 );
|
||||
labels_layout->Add( confpick_text, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||
confpick_text->Disable();
|
||||
|
||||
// Resolution layout
|
||||
auto resotext = new wxStaticText( this, wxID_ANY,
|
||||
_("Resolution (w, h) [px]"),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
resotext->Wrap( -1 );
|
||||
labels_layout->Add( resotext, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||
|
||||
// Bed size label
|
||||
auto bed_size_text = new wxStaticText( this, wxID_ANY,
|
||||
_("Bed size (w, h) [mm]"),
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize, 0 );
|
||||
bed_size_text->Wrap( -1 );
|
||||
labels_layout->Add( bed_size_text, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||
|
||||
// Correction label
|
||||
auto corr_text = new wxStaticText( this, wxID_ANY, _("Scale (x, y, z)"),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
corr_text->Wrap( -1 );
|
||||
labels_layout->Add( corr_text, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||
|
||||
// Exp time label
|
||||
auto exp_text = new wxStaticText( this, wxID_ANY,
|
||||
_("Exposure time [s]"),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
exp_text->Wrap( -1 );
|
||||
labels_layout->Add( exp_text, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||
|
||||
top_layout->Add( labels_layout, 0, wxEXPAND, 5 );
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Body
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
auto body_layout = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
// Input file picker
|
||||
auto fpicklayout = new wxBoxSizer(wxHORIZONTAL);
|
||||
filepick_ctl_ = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString,
|
||||
_("Select a file"), wxT("*.zip"),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxFLP_USE_TEXTCTRL | wxFLP_SAVE,
|
||||
wxDefaultValidator,
|
||||
wxT("filepick_ctl") );
|
||||
fpicklayout->Add( filepick_ctl_, 1, wxALL | wxALIGN_CENTER, 5);
|
||||
body_layout->Add( fpicklayout, 1, wxEXPAND, 5 );
|
||||
|
||||
auto ctlpicklayout = new wxBoxSizer(wxHORIZONTAL);
|
||||
confpick_ctl_ = new wxFilePickerCtrl(
|
||||
this, wxID_ANY, wxEmptyString, _("Select a file"),
|
||||
wxT("*.json"), wxDefaultPosition, wxDefaultSize,
|
||||
wxFLP_USE_TEXTCTRL | wxFLP_DEFAULT_STYLE, wxDefaultValidator,
|
||||
wxT("filepick_ctl") );
|
||||
confpick_ctl_->Disable();
|
||||
ctlpicklayout->Add( confpick_ctl_, 1, wxALL | wxALIGN_CENTER, 5);
|
||||
body_layout->Add( ctlpicklayout, 1, wxEXPAND, 5 );
|
||||
|
||||
|
||||
// Resolution controls /////////////////////////////////////////////////////
|
||||
|
||||
auto res_spins_layout = new wxBoxSizer( wxHORIZONTAL );
|
||||
spin_reso_width_ = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxSP_ARROW_KEYS, 0, 10000, 1440 );
|
||||
res_spins_layout->Add( spin_reso_width_, 1, wxALIGN_CENTER|wxALL, 5 );
|
||||
spin_reso_height_ = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxSP_ARROW_KEYS, 0, 10000, 2560 );
|
||||
res_spins_layout->Add( spin_reso_height_, 1, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
reso_lock_btn_ = new wxToggleButton( this, wxID_ANY, _("Lock"),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
reso_lock_btn_->SetValue(true);
|
||||
res_spins_layout->Add( reso_lock_btn_, 0, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
body_layout->Add( res_spins_layout, 1, wxEXPAND, 5 );
|
||||
|
||||
|
||||
// Bed size controls ///////////////////////////////////////////////////////
|
||||
|
||||
auto bed_spins_layout = new wxBoxSizer( wxHORIZONTAL );
|
||||
bed_width_spin_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxSP_ARROW_KEYS, 0, 1e6, 68.0 );
|
||||
|
||||
bed_spins_layout->Add( bed_width_spin_, 1, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
bed_height_spin_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxSP_ARROW_KEYS, 0, 1e6, 120.0 );
|
||||
bed_spins_layout->Add( bed_height_spin_, 1, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
bedsize_lock_btn_ = new wxToggleButton( this, wxID_ANY, _("Lock"),
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize, 0 );
|
||||
bedsize_lock_btn_->SetValue(true);
|
||||
bed_spins_layout->Add( bedsize_lock_btn_, 0, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
body_layout->Add( bed_spins_layout, 1, wxEXPAND, 5 );
|
||||
|
||||
|
||||
// Scale correction controls ///////////////////////////////////////////////
|
||||
|
||||
auto corr_layout = new wxBoxSizer( wxHORIZONTAL );
|
||||
corr_spin_x_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxSP_ARROW_KEYS, 0, 100, 1, 0.01 );
|
||||
corr_spin_x_->SetDigits(3);
|
||||
corr_spin_x_->SetMaxSize(wxSize(100, -1));
|
||||
corr_layout->Add( corr_spin_x_, 0, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
corr_spin_y_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxSP_ARROW_KEYS, 0, 100, 1, 0.01 );
|
||||
corr_spin_y_->SetDigits(3);
|
||||
corr_spin_y_->SetMaxSize(wxSize(100, -1));
|
||||
corr_layout->Add( corr_spin_y_, 0, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
corr_spin_z_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxSP_ARROW_KEYS, 0, 100, 1, 0.01 );
|
||||
corr_spin_z_->SetDigits(3);
|
||||
corr_spin_z_->SetMaxSize(wxSize(100, -1));
|
||||
corr_layout->Add( corr_spin_z_, 0, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
corr_layout->Add( bedsize_lock_btn_->GetSize().GetWidth(), 0, 1, wxEXPAND, 5 );
|
||||
|
||||
body_layout->Add( corr_layout, 1, wxEXPAND, 5 );
|
||||
|
||||
// Exposure time controls /////////////////////////////////////////////////
|
||||
|
||||
auto exp_layout = new wxBoxSizer( wxHORIZONTAL );
|
||||
exptime_spin_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxSP_ARROW_KEYS, 0, 100, 1, 0.01 );
|
||||
exptime_spin_->SetDigits(3);
|
||||
exptime_spin_->SetMaxSize(wxSize(100, -1));
|
||||
|
||||
auto first_txt = new wxStaticText( this, wxID_ANY,
|
||||
_("First exp. time"),
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize, wxALIGN_RIGHT );
|
||||
|
||||
exptime_first_spin_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize, wxSP_ARROW_KEYS,
|
||||
0, 100, 1, 0.01 );
|
||||
exptime_first_spin_->SetDigits(3);
|
||||
exptime_first_spin_->SetMaxSize(wxSize(100, -1));
|
||||
|
||||
exp_layout->Add( exptime_spin_, 1, wxALIGN_CENTER|wxALL, 5 );
|
||||
exp_layout->Add( first_txt, 1, wxALIGN_CENTER|wxALL, 5);
|
||||
exp_layout->Add( exptime_first_spin_, 1, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
export_btn_ = new wxButton( this, wxID_ANY, _("Export"), wxDefaultPosition,
|
||||
wxDefaultSize, 0, wxDefaultValidator,
|
||||
wxT("export_btn") );
|
||||
|
||||
exp_layout->Add( export_btn_, 0, wxALIGN_CENTER|wxALL, 5 );
|
||||
|
||||
body_layout->Add( exp_layout, 1, wxEXPAND, 5 );
|
||||
|
||||
top_layout->Add( body_layout, 0, wxEXPAND, 5 );
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Finalize
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
this->SetSizer(top_layout);
|
||||
this->Layout();
|
||||
|
||||
this->Fit();
|
||||
this->SetMinSize(this->GetSize());
|
||||
this->Centre( wxBOTH );
|
||||
|
||||
// Connect Events
|
||||
filepick_ctl_->Connect(
|
||||
wxEVT_COMMAND_FILEPICKER_CHANGED,
|
||||
wxFileDirPickerEventHandler( PngExportDialog::onFileChanged ),
|
||||
NULL, this );
|
||||
spin_reso_width_->Connect(
|
||||
wxEVT_COMMAND_TEXT_UPDATED,
|
||||
wxCommandEventHandler( PngExportDialog::EvalResoSpin ),
|
||||
NULL, this );
|
||||
spin_reso_height_->Connect(
|
||||
wxEVT_COMMAND_TEXT_UPDATED,
|
||||
wxCommandEventHandler( PngExportDialog::EvalResoSpin ),
|
||||
NULL, this );
|
||||
reso_lock_btn_->Connect(
|
||||
wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,
|
||||
wxCommandEventHandler( PngExportDialog::ResoLock ),
|
||||
NULL, this );
|
||||
bed_width_spin_->Connect(
|
||||
wxEVT_COMMAND_TEXT_UPDATED,
|
||||
wxCommandEventHandler( PngExportDialog::EvalBedSpin ),
|
||||
NULL, this );
|
||||
bed_height_spin_->Connect(
|
||||
wxEVT_COMMAND_TEXT_UPDATED,
|
||||
wxCommandEventHandler( PngExportDialog::EvalBedSpin ),
|
||||
NULL, this );
|
||||
bedsize_lock_btn_->Connect(
|
||||
wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,
|
||||
wxCommandEventHandler( PngExportDialog::BedsizeLock ),
|
||||
NULL, this );
|
||||
export_btn_->Connect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PngExportDialog::Close ), NULL, this );
|
||||
}
|
||||
|
||||
PngExportDialog::~PngExportDialog()
|
||||
{
|
||||
// Disconnect Events
|
||||
filepick_ctl_->Disconnect(
|
||||
wxEVT_COMMAND_FILEPICKER_CHANGED,
|
||||
wxFileDirPickerEventHandler( PngExportDialog::onFileChanged ),
|
||||
NULL, this );
|
||||
spin_reso_width_->Disconnect(
|
||||
wxEVT_COMMAND_TEXT_UPDATED,
|
||||
wxCommandEventHandler( PngExportDialog::EvalResoSpin ),
|
||||
NULL, this );
|
||||
spin_reso_height_->Disconnect(
|
||||
wxEVT_COMMAND_TEXT_UPDATED,
|
||||
wxCommandEventHandler( PngExportDialog::EvalResoSpin ),
|
||||
NULL, this );
|
||||
reso_lock_btn_->Disconnect(
|
||||
wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,
|
||||
wxCommandEventHandler( PngExportDialog::ResoLock ),
|
||||
NULL, this );
|
||||
bed_width_spin_->Disconnect(
|
||||
wxEVT_COMMAND_TEXT_UPDATED,
|
||||
wxCommandEventHandler( PngExportDialog::EvalBedSpin ),
|
||||
NULL, this );
|
||||
bed_height_spin_->Disconnect(
|
||||
wxEVT_COMMAND_TEXT_UPDATED,
|
||||
wxCommandEventHandler( PngExportDialog::EvalBedSpin ),
|
||||
NULL, this );
|
||||
bedsize_lock_btn_->Disconnect(
|
||||
wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,
|
||||
wxCommandEventHandler( PngExportDialog::BedsizeLock ),
|
||||
NULL, this );
|
||||
export_btn_->Disconnect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PngExportDialog::Close ), NULL, this );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
#ifndef PNG_EXPORT_DIALOG_HPP
|
||||
#define PNG_EXPORT_DIALOG_HPP
|
||||
|
||||
#include <wx/artprov.h>
|
||||
#include <wx/xrc/xmlres.h>
|
||||
#include <wx/intl.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/font.h>
|
||||
#include <wx/colour.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/filepicker.h>
|
||||
#include <wx/spinctrl.h>
|
||||
#include <wx/tglbtn.h>
|
||||
#include <wx/button.h>
|
||||
#include <wx/dialog.h>
|
||||
|
||||
#include "GUI.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// Class PngExportDialog
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class PngExportDialog : public wxDialog
|
||||
{
|
||||
private:
|
||||
|
||||
protected:
|
||||
wxFilePickerCtrl* filepick_ctl_;
|
||||
wxFilePickerCtrl* confpick_ctl_;
|
||||
wxSpinCtrl* spin_reso_width_;
|
||||
wxSpinCtrl* spin_reso_height_;
|
||||
wxToggleButton* reso_lock_btn_;
|
||||
wxSpinCtrlDouble* bed_width_spin_;
|
||||
wxSpinCtrlDouble* bed_height_spin_;
|
||||
wxToggleButton* bedsize_lock_btn_;
|
||||
wxSpinCtrlDouble* exptime_spin_;
|
||||
wxSpinCtrlDouble* exptime_first_spin_;
|
||||
wxSpinCtrlDouble* corr_spin_x_;
|
||||
wxSpinCtrlDouble* corr_spin_y_;
|
||||
wxSpinCtrlDouble* corr_spin_z_;
|
||||
wxButton* export_btn_;
|
||||
|
||||
// Virtual event handlers, overide them in your derived class
|
||||
virtual void onFileChanged( wxFileDirPickerEvent& event ) { event.Skip(); }
|
||||
virtual void EvalResoSpin( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void ResoLock( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void EvalBedSpin( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void BedsizeLock( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void Close( wxCommandEvent& /*event*/ ) { EndModal(wxID_OK); }
|
||||
|
||||
public:
|
||||
|
||||
PngExportDialog( wxWindow* parent, wxWindowID id = wxID_ANY,
|
||||
const wxString& title = L("Slice to zipped PNG files"),
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxSize( 452,170 ),
|
||||
long style = wxDEFAULT_DIALOG_STYLE );
|
||||
~PngExportDialog();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif //PNG_EXPORT_DIALOG_HPP
|
||||
151
xs/src/slic3r/GUI/ProgressStatusBar.cpp
Normal file
151
xs/src/slic3r/GUI/ProgressStatusBar.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
#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)),
|
||||
timer_(new wxTimer(self)),
|
||||
prog_ (new wxGauge(self,
|
||||
wxGA_HORIZONTAL,
|
||||
100,
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize)),
|
||||
cancelbutton_(new wxButton(self,
|
||||
-1,
|
||||
"Cancel",
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize))
|
||||
{
|
||||
prog_->Hide();
|
||||
cancelbutton_->Hide();
|
||||
|
||||
self->SetFieldsCount(3);
|
||||
int w[] = {-1, 150, 155};
|
||||
self->SetStatusWidths(3, w);
|
||||
|
||||
self->Bind(wxEVT_TIMER, [this](const wxTimerEvent&) {
|
||||
if (prog_->IsShown()) timer_->Stop();
|
||||
if(is_busy()) prog_->Pulse();
|
||||
});
|
||||
|
||||
self->Bind(wxEVT_SIZE, [this](wxSizeEvent& event){
|
||||
wxRect rect;
|
||||
self->GetFieldRect(1, rect);
|
||||
auto offset = 0;
|
||||
cancelbutton_->Move(rect.GetX() + offset, rect.GetY() + offset);
|
||||
cancelbutton_->SetSize(rect.GetWidth() - offset, rect.GetHeight());
|
||||
|
||||
self->GetFieldRect(2, rect);
|
||||
prog_->Move(rect.GetX() + offset, rect.GetY() + offset);
|
||||
prog_->SetSize(rect.GetWidth() - offset, rect.GetHeight());
|
||||
|
||||
event.Skip();
|
||||
});
|
||||
|
||||
cancelbutton_->Bind(wxEVT_BUTTON, [this](const wxCommandEvent&) {
|
||||
if(cancel_cb_) cancel_cb_();
|
||||
cancelbutton_->Hide();
|
||||
});
|
||||
}
|
||||
|
||||
ProgressStatusBar::~ProgressStatusBar() {
|
||||
if(timer_->IsRunning()) timer_->Stop();
|
||||
}
|
||||
|
||||
int ProgressStatusBar::get_progress() const
|
||||
{
|
||||
return prog_->GetValue();
|
||||
}
|
||||
|
||||
void ProgressStatusBar::set_progress(int val)
|
||||
{
|
||||
if(!prog_->IsShown()) show_progress(true);
|
||||
|
||||
if(val == prog_->GetRange()) {
|
||||
prog_->SetValue(0);
|
||||
show_progress(false);
|
||||
} else {
|
||||
prog_->SetValue(val);
|
||||
}
|
||||
}
|
||||
|
||||
int ProgressStatusBar::get_range() const
|
||||
{
|
||||
return prog_->GetRange();
|
||||
}
|
||||
|
||||
void ProgressStatusBar::set_range(int val)
|
||||
{
|
||||
if(val != prog_->GetRange()) {
|
||||
prog_->SetRange(val);
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressStatusBar::show_progress(bool show)
|
||||
{
|
||||
prog_->Show(show);
|
||||
prog_->Pulse();
|
||||
}
|
||||
|
||||
void ProgressStatusBar::start_busy(int rate)
|
||||
{
|
||||
busy_ = true;
|
||||
show_progress(true);
|
||||
if (!timer_->IsRunning()) {
|
||||
timer_->Start(rate);
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressStatusBar::stop_busy()
|
||||
{
|
||||
timer_->Stop();
|
||||
show_progress(false);
|
||||
prog_->SetValue(0);
|
||||
busy_ = false;
|
||||
}
|
||||
|
||||
void ProgressStatusBar::set_cancel_callback(ProgressStatusBar::CancelFn ccb) {
|
||||
cancel_cb_ = ccb;
|
||||
if(ccb) cancelbutton_->Show();
|
||||
else cancelbutton_->Hide();
|
||||
}
|
||||
|
||||
void ProgressStatusBar::run(int rate)
|
||||
{
|
||||
if(!timer_->IsRunning()) {
|
||||
timer_->Start(rate);
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressStatusBar::embed(wxFrame *frame)
|
||||
{
|
||||
wxFrame* mf = frame? frame : GUI::get_main_frame();
|
||||
mf->SetStatusBar(self);
|
||||
}
|
||||
|
||||
void ProgressStatusBar::set_status_text(const std::string& txt)
|
||||
{
|
||||
self->SetStatusText(txt);
|
||||
}
|
||||
|
||||
void ProgressStatusBar::show_cancel_button()
|
||||
{
|
||||
cancelbutton_->Show();
|
||||
}
|
||||
|
||||
void ProgressStatusBar::hide_cancel_button()
|
||||
{
|
||||
cancelbutton_->Hide();
|
||||
}
|
||||
|
||||
}
|
||||
64
xs/src/slic3r/GUI/ProgressStatusBar.hpp
Normal file
64
xs/src/slic3r/GUI/ProgressStatusBar.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef PROGRESSSTATUSBAR_HPP
|
||||
#define PROGRESSSTATUSBAR_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
class wxTimer;
|
||||
class wxGauge;
|
||||
class wxButton;
|
||||
class wxTimerEvent;
|
||||
class wxStatusBar;
|
||||
class wxWindow;
|
||||
class wxFrame;
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
/**
|
||||
* @brief The ProgressStatusBar class is the widgets occupying the lower area
|
||||
* of the Slicer main window. It consists of a message area to the left and a
|
||||
* progress indication area to the right with an optional cancel button.
|
||||
*/
|
||||
class ProgressStatusBar {
|
||||
wxStatusBar *self; // we cheat! It should be the base class but: perl!
|
||||
wxTimer *timer_;
|
||||
wxGauge *prog_;
|
||||
wxButton *cancelbutton_;
|
||||
public:
|
||||
|
||||
/// Cancel callback function type
|
||||
using CancelFn = std::function<void()>;
|
||||
|
||||
ProgressStatusBar(wxWindow *parent = nullptr, int id = -1);
|
||||
~ProgressStatusBar();
|
||||
|
||||
int get_progress() const;
|
||||
void set_progress(int);
|
||||
int get_range() const;
|
||||
void set_range(int = 100);
|
||||
void show_progress(bool);
|
||||
void start_busy(int = 100);
|
||||
void stop_busy();
|
||||
inline bool is_busy() const { return busy_; }
|
||||
void set_cancel_callback(CancelFn = CancelFn());
|
||||
inline void remove_cancel_callback() { set_cancel_callback(); }
|
||||
void run(int rate);
|
||||
void embed(wxFrame *frame = nullptr);
|
||||
void set_status_text(const std::string& txt);
|
||||
|
||||
// Temporary methods to satisfy Perl side
|
||||
void show_cancel_button();
|
||||
void hide_cancel_button();
|
||||
|
||||
private:
|
||||
bool busy_ = false;
|
||||
CancelFn cancel_cb_;
|
||||
};
|
||||
|
||||
namespace GUI {
|
||||
using Slic3r::ProgressStatusBar;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // PROGRESSSTATUSBAR_HPP
|
||||
Reference in New Issue
Block a user