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:
tamasmeszaros 2018-08-30 15:21:41 +02:00
commit 4f53fc2a5f
21 changed files with 375 additions and 729 deletions

View file

@ -4,7 +4,7 @@
#include <future>
#include <slic3r/GUI/GUI.hpp>
#include <slic3r/GUI/PngExportDialog.hpp>
#include <slic3r/GUI/ProgressStatusBar.hpp>
#include <wx/app.h>
#include <wx/filedlg.h>
@ -105,10 +105,10 @@ namespace {
* the main thread as well.
*/
class GuiProgressIndicator:
public IProgressIndicator, public wxEvtHandler {
public ProgressIndicator, public wxEvtHandler {
wxProgressDialog gauge_;
using Base = IProgressIndicator;
using Base = ProgressIndicator;
wxString message_;
int range_; wxString title_;
bool is_asynch_ = false;
@ -154,7 +154,7 @@ public:
virtual void cancel() override {
update(max(), "Abort");
IProgressIndicator::cancel();
ProgressIndicator::cancel();
}
virtual void state(float val) override {
@ -211,31 +211,21 @@ AppControllerBoilerplate::create_progress_indicator(unsigned statenum,
namespace {
// A wrapper progress indicator class around the statusbar created in perl.
class Wrapper: public IProgressIndicator, public wxEvtHandler {
wxGauge *gauge_;
wxStatusBar *stbar_;
using Base = IProgressIndicator;
class Wrapper: public ProgressIndicator, public wxEvtHandler {
ProgressStatusBar *sbar_;
using Base = ProgressIndicator;
std::string message_;
AppControllerBoilerplate& ctl_;
void showProgress(bool show = true) {
gauge_->Show(show);
sbar_->show_progress(show);
}
void _state(unsigned st) {
if( st <= IProgressIndicator::max() ) {
if( st <= ProgressIndicator::max() ) {
Base::state(st);
if(!gauge_->IsShown()) showProgress(true);
stbar_->SetStatusText(message_);
if(static_cast<long>(st) == gauge_->GetRange()) {
gauge_->SetValue(0);
showProgress(false);
} else {
gauge_->SetValue(static_cast<int>(st));
}
sbar_->set_status_text(message_);
sbar_->set_progress(st);
}
}
@ -248,12 +238,12 @@ class Wrapper: public IProgressIndicator, public wxEvtHandler {
public:
inline Wrapper(wxGauge *gauge, wxStatusBar *stbar,
inline Wrapper(ProgressStatusBar *sbar,
AppControllerBoilerplate& ctl):
gauge_(gauge), stbar_(stbar), ctl_(ctl)
sbar_(sbar), ctl_(ctl)
{
Base::max(static_cast<float>(gauge->GetRange()));
Base::states(static_cast<unsigned>(gauge->GetRange()));
Base::max(static_cast<float>(sbar_->get_range()));
Base::states(static_cast<unsigned>(sbar_->get_range()));
Bind(PROGRESS_STATUS_UPDATE_EVENT,
&Wrapper::_state,
@ -266,8 +256,8 @@ public:
virtual void max(float val) override {
if(val > 1.0) {
gauge_->SetRange(static_cast<int>(val));
IProgressIndicator::max(val);
sbar_->set_range(static_cast<int>(val));
ProgressIndicator::max(val);
}
}
@ -294,135 +284,19 @@ public:
virtual void title(const string & /*title*/) override {}
virtual void on_cancel(CancelFn fn) override {
sbar_->set_cancel_callback(fn);
Base::on_cancel(fn);
}
};
}
void AppController::set_global_progress_indicator(
unsigned gid,
unsigned sid)
void AppController::set_global_progress_indicator(ProgressStatusBar *prsb)
{
wxGauge* gauge = dynamic_cast<wxGauge*>(wxWindow::FindWindowById(gid));
wxStatusBar* sb = dynamic_cast<wxStatusBar*>(wxWindow::FindWindowById(sid));
if(gauge && sb) {
global_progress_indicator(std::make_shared<Wrapper>(gauge, sb, *this));
if(prsb) {
global_progress_indicator(std::make_shared<Wrapper>(prsb, *this));
}
}
//PrintController::PngExportData PrintController::collect_png_export_data()
//{
// // Implement the logic of the PngExportDialog
// class PngExportView: public PngExportDialog {
// double ratio_, bs_ratio_;
// PrintController& ctl_;
// public:
// PngExportView(PrintController& ctl):
// PngExportDialog(wxTheApp->GetTopWindow()), ctl_(ctl)
// {
// ratio_ = double(spin_reso_width_->GetValue()) /
// spin_reso_height_->GetValue();
// bs_ratio_ = bed_width_spin_->GetValue() /
// bed_height_spin_->GetValue();
// }
// PngExportData export_data() const {
// PrintController::PngExportData ret;
// ret.zippath = filepick_ctl_->GetPath();
// ret.width_px = spin_reso_width_->GetValue();
// ret.height_px = spin_reso_height_->GetValue();
// ret.width_mm = bed_width_spin_->GetValue();
// ret.height_mm = bed_height_spin_->GetValue();
// ret.exp_time_s = exptime_spin_->GetValue();
// ret.exp_time_first_s = exptime_first_spin_->GetValue();
// ret.corr_x = corr_spin_x_->GetValue();
// ret.corr_y = corr_spin_y_->GetValue();
// ret.corr_z = corr_spin_z_->GetValue();
// return ret;
// }
// void prefill(const PngExportData& data) {
// filepick_ctl_->SetPath(data.zippath);
// spin_reso_width_->SetValue(data.width_px);
// spin_reso_height_->SetValue(data.height_px);
// bed_width_spin_->SetValue(data.width_mm);
// bed_height_spin_->SetValue(data.height_mm);
// exptime_spin_->SetValue(data.exp_time_s);
// exptime_first_spin_->SetValue(data.exp_time_first_s);
// corr_spin_x_->SetValue(data.corr_x);
// corr_spin_y_->SetValue(data.corr_y);
// corr_spin_z_->SetValue(data.corr_z);
// if(data.zippath.empty()) export_btn_->Disable();
// else export_btn_->Enable();
// }
// virtual void ResoLock( wxCommandEvent& /*event*/ ) override {
// ratio_ = double(spin_reso_width_->GetValue()) /
// double(spin_reso_height_->GetValue());
// }
// virtual void BedsizeLock( wxCommandEvent& /*event*/ ) override {
// bs_ratio_ = bed_width_spin_->GetValue() /
// bed_height_spin_->GetValue();
// }
// virtual void EvalResoSpin( wxCommandEvent& event ) override {
// if(reso_lock_btn_->GetValue()) {
// if(event.GetId() == spin_reso_width_->GetId()) {
// spin_reso_height_->SetValue(
// std::round(spin_reso_width_->GetValue()/ratio_));
// spin_reso_height_->Update();
// } else {
// spin_reso_width_->SetValue(
// std::round(spin_reso_height_->GetValue()*ratio_));
// spin_reso_width_->Update();
// }
// }
// }
// virtual void EvalBedSpin( wxCommandEvent& event ) override {
// if(bedsize_lock_btn_->GetValue()) {
// if(event.GetId() == bed_width_spin_->GetId()) {
// bed_height_spin_->SetValue(
// std::round(bed_width_spin_->GetValue()/bs_ratio_));
// bed_height_spin_->Update();
// } else {
// bed_width_spin_->SetValue(
// std::round(bed_height_spin_->GetValue()*bs_ratio_));
// bed_width_spin_->Update();
// }
// }
// }
// virtual void onFileChanged( wxFileDirPickerEvent& event ) {
// if(filepick_ctl_->GetPath().IsEmpty()) export_btn_->Disable();
// else export_btn_->Enable();
// }
// virtual void Close( wxCommandEvent& /*event*/ ) {
// auto ret = wxID_OK;
// if(wxFileName(filepick_ctl_->GetPath()).Exists())
// if(!ctl_.report_issue(PrintController::IssueType::WARN_Q,
// _(L("File already exists. Overwrite?")),
// _(L("Warning")))) ret = wxID_CANCEL;
// EndModal(ret);
// }
// };
// PngExportView exdlg(*this);
// exdlg.prefill(prev_expdata_);
// auto r = exdlg.ShowModal();
// auto ret = exdlg.export_data();
// prev_expdata_ = ret;
// if(r != wxID_OK) ret.zippath.clear();
// return ret;
//}
}