From ae682b9cd363dff030bcc9a9e1e187ec3342adfa Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 26 Jun 2018 15:51:47 +0200 Subject: [PATCH] Export dialog ready --- xs/CMakeLists.txt | 2 + xs/src/slic3r/AppController.cpp | 41 +- xs/src/slic3r/AppController.hpp | 19 +- xs/src/slic3r/AppControllerWx.cpp | 350 ++++++++++++++++++ xs/src/slic3r/GUI/PngExportDialog.cpp | 154 ++++++++ xs/src/slic3r/GUI/PngExportDialog.hpp | 67 ++++ ...ssindicator.hpp => IProgressIndicator.hpp} | 0 xs/src/slic3r/appcontrollerwx.cpp | 314 ---------------- 8 files changed, 621 insertions(+), 326 deletions(-) create mode 100644 xs/src/slic3r/AppControllerWx.cpp create mode 100644 xs/src/slic3r/GUI/PngExportDialog.cpp create mode 100644 xs/src/slic3r/GUI/PngExportDialog.hpp rename xs/src/slic3r/{iprogressindicator.hpp => IProgressIndicator.hpp} (100%) delete mode 100644 xs/src/slic3r/appcontrollerwx.cpp diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt index 45a4501d7..3b1fe2da2 100644 --- a/xs/CMakeLists.txt +++ b/xs/CMakeLists.txt @@ -262,6 +262,8 @@ add_library(libslic3r_gui STATIC ${LIBDIR}/slic3r/Utils/PresetUpdater.hpp ${LIBDIR}/slic3r/Utils/Time.cpp ${LIBDIR}/slic3r/Utils/Time.hpp + ${LIBDIR}/slic3r/GUI/PngExportDialog.hpp + ${LIBDIR}/slic3r/GUI/PngExportDialog.cpp ${LIBDIR}/slic3r/IProgressIndicator.hpp ${LIBDIR}/slic3r/AppController.hpp ${LIBDIR}/slic3r/AppController.cpp diff --git a/xs/src/slic3r/AppController.cpp b/xs/src/slic3r/AppController.cpp index d95853490..1ca6e8b3c 100644 --- a/xs/src/slic3r/AppController.cpp +++ b/xs/src/slic3r/AppController.cpp @@ -6,7 +6,7 @@ #include #include -//#include +#include #include #include @@ -270,10 +270,9 @@ void PrintController::slice_to_png() { assert(model_ != nullptr); - auto zipfilepath = query_destination_path( "Path to zip file...", - "*.zip"); + auto exd = query_png_export_data(); - if(zipfilepath.empty()) return; + if(exd.zippath.empty()) return; auto presetbundle = GUI::get_preset_bundle(); @@ -290,16 +289,42 @@ void PrintController::slice_to_png() report_issue(IssueType::ERR, e.what(), "Error"); } - std::async(std::launch::async, [this, zipfilepath]() { + auto print_bb = print_->bounding_box(); + + // If the print does not fit into the print area we should cry about it. + if(unscale(print_bb.size().x) > exd.width_mm || + unscale(print_bb.size().y) > exd.height_mm) { + std::stringstream ss; + + ss << _("Print will not fit and will be truncated!") << "\n" + << _("Width needed: ") << unscale(print_bb.size().x) << " mm\n" + << _("Height needed: ") << unscale(print_bb.size().y) << " mm\n"; + + report_issue(IssueType::WARN, ss.str(), "Warning"); + } + + std::async(std::launch::async, [this, exd]() { progress_indicator(100, "Slicing to zipped png files..."); progress_indicator()->procedure_count(3); - slice(); + + try { + slice(); + } catch (std::exception& e) { + report_issue(IssueType::ERR, e.what(), "Exception"); + return; + } auto pbak = print_->progressindicator; print_->progressindicator = progress_indicator(); - print_->print_to_png(zipfilepath); - print_->progressindicator = pbak; + try { + print_->print_to_png(exd.zippath, exd.width_px, exd.height_px, + exd.width_mm, exd.height_mm); + } catch (std::exception& e) { + report_issue(IssueType::ERR, e.what(), "Exception"); + } + + print_->progressindicator = pbak; }); } diff --git a/xs/src/slic3r/AppController.hpp b/xs/src/slic3r/AppController.hpp index 1b98560fc..6633cf2b6 100644 --- a/xs/src/slic3r/AppController.hpp +++ b/xs/src/slic3r/AppController.hpp @@ -58,11 +58,13 @@ public: void progress_indicator(ProgresIndicatorPtr progrind); void progress_indicator(unsigned statenum, - const std::string& title, - const std::string& firstmsg = ""); + const std::string& title, + const std::string& firstmsg = ""); ProgresIndicatorPtr progress_indicator(); + bool is_main_thread() const; + protected: ProgresIndicatorPtr create_progress_indicator( @@ -70,7 +72,6 @@ protected: const std::string& title, const std::string& firstmsg = "") const; - bool is_main_thread() const; ProgresIndicatorPtr global_progressind_; }; @@ -87,6 +88,16 @@ protected: void infill(PrintObject *pobj); void gen_support_material(PrintObject *pobj); + struct PngExportData { + std::string zippath; + unsigned long width_px = 1440; + unsigned long height_px = 2560; + double width_mm = 68.0, height_mm = 120.0; + double corr = 1.0; + } query_png_export_data(); + + PngExportData prev_expdata_; + public: using Ptr = std::unique_ptr; @@ -103,7 +114,7 @@ public: void slice_to_png(); }; -class AppController: protected AppControllerBoilerplate { +class AppController: public AppControllerBoilerplate { Model *model_ = nullptr; PrintController::Ptr printctl; public: diff --git a/xs/src/slic3r/AppControllerWx.cpp b/xs/src/slic3r/AppControllerWx.cpp new file mode 100644 index 000000000..f968f0828 --- /dev/null +++ b/xs/src/slic3r/AppControllerWx.cpp @@ -0,0 +1,350 @@ +#include "AppController.hpp" + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace Slic3r { + +AppControllerBoilerplate::PathList +AppControllerBoilerplate::query_destination_paths( + const std::string &title, + const std::string &extensions) const +{ + + wxFileDialog dlg(wxTheApp->GetTopWindow(), wxString(title) ); + dlg.SetWildcard(extensions); + + dlg.ShowModal(); + + wxArrayString paths; + dlg.GetPaths(paths); + + PathList ret(paths.size(), ""); + for(auto& p : paths) ret.push_back(p.ToStdString()); + + return ret; +} + +AppControllerBoilerplate::Path +AppControllerBoilerplate::query_destination_path( + const std::string &title, + const std::string &extensions, + const std::string& hint) const +{ + wxFileDialog dlg(wxTheApp->GetTopWindow(), title ); + dlg.SetWildcard(extensions); + + dlg.SetFilename(hint); + + Path ret; + + if(dlg.ShowModal() == wxID_OK) { + ret = Path(dlg.GetPath()); + } + + return ret; +} + +void AppControllerBoilerplate::report_issue(IssueType issuetype, + const std::string &description, + const std::string &brief) +{ + auto icon = wxICON_INFORMATION; + switch(issuetype) { + case IssueType::INFO: break; + case IssueType::WARN: icon = wxICON_WARNING; break; + case IssueType::ERR: + case IssueType::FATAL: icon = wxICON_ERROR; + } + + wxMessageBox(description, brief, icon); +} + +wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent); + +namespace { +class GuiProgressIndicator: + public IProgressIndicator, public wxEvtHandler { + + std::shared_ptr gauge_; + using Base = IProgressIndicator; + wxString message_; + int range_; wxString title_; + unsigned prc_ = 0; + bool is_asynch_ = false; + + const int id_ = wxWindow::NewControlId(); + + // status update handler + void _state( wxCommandEvent& evt) { + unsigned st = evt.GetInt(); + _state(st); + } + + void _state( unsigned st) { + if(st < max()) { + if(!gauge_) gauge_ = std::make_shared( + title_, message_, range_, wxTheApp->GetTopWindow(), + wxPD_APP_MODAL | wxPD_AUTO_HIDE + ); + + if(!gauge_->IsShown()) gauge_->ShowModal(); + Base::state(st); + gauge_->Update(static_cast(st), message_); + } + + if(st == max()) { + prc_++; + if(prc_ == Base::procedure_count()) { + gauge_.reset(); + prc_ = 0; + } + } + } + +public: + + inline void asynch(bool is) { is_asynch_ = is; } + inline bool asynch() const { return is_asynch_; } + + inline GuiProgressIndicator(int range, const std::string& title, + const std::string& firstmsg) : + range_(range), message_(_(firstmsg)), title_(_(title)) + { + Base::max(static_cast(range)); + Base::states(static_cast(range)); + + Bind(PROGRESS_STATUS_UPDATE_EVENT, + &GuiProgressIndicator::_state, + this, id_); + } + + virtual void state(float val) override { + if( val >= 1.0) state(static_cast(val)); + } + + virtual void state(unsigned st) override { + // send status update event + if(is_asynch_) { + auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT, id_); + evt->SetInt(st); + wxQueueEvent(this, evt); + } else _state(st); + } + + virtual void message(const std::string & msg) override { + message_ = _(msg); + } + + virtual void messageFmt(const std::string& fmt, ...) { + va_list arglist; + va_start(arglist, fmt); + message_ = wxString::Format(_(fmt), arglist); + va_end(arglist); + } + + virtual void title(const std::string & title) override { + title_ = _(title); + } +}; +} + +AppControllerBoilerplate::ProgresIndicatorPtr +AppControllerBoilerplate::create_progress_indicator( + unsigned statenum, const std::string& title, + const std::string& firstmsg) const +{ + auto pri = + std::make_shared(statenum, title, firstmsg); + + pri->asynch(!is_main_thread()); + + return pri; +} + +namespace { +class Wrapper: public IProgressIndicator, public wxEvtHandler { + wxGauge *gauge_; + wxStatusBar *stbar_; + using Base = IProgressIndicator; + std::string message_; + AppControllerBoilerplate& ctl_; + + void showProgress(bool show = true) { + gauge_->Show(show); + } + + void _state(unsigned st) { + if( st <= max() ) { + Base::state(st); + + if(!gauge_->IsShown()) showProgress(true); + + stbar_->SetStatusText(message_); + if(st == gauge_->GetRange()) { + gauge_->SetValue(0); + showProgress(false); + } else { + gauge_->SetValue(static_cast(st)); + } + } + } + + // status update handler + void _state( wxCommandEvent& evt) { + unsigned st = evt.GetInt(); _state(st); + } + + const int id_ = wxWindow::NewControlId(); + +public: + + inline Wrapper(wxGauge *gauge, wxStatusBar *stbar, + AppControllerBoilerplate& ctl): + gauge_(gauge), stbar_(stbar), ctl_(ctl) + { + Base::max(static_cast(gauge->GetRange())); + Base::states(static_cast(gauge->GetRange())); + + Bind(PROGRESS_STATUS_UPDATE_EVENT, + &Wrapper::_state, + this, id_); + } + + virtual void state(float val) override { + if(val >= 1.0) state(unsigned(val)); + } + + virtual void state(unsigned st) override { + if(!ctl_.is_main_thread()) { + auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT, id_); + evt->SetInt(st); + wxQueueEvent(this, evt); + } else _state(st); + } + + virtual void message(const std::string & msg) override { + message_ = msg; + } + + virtual void message_fmt(const std::string& fmt, ...) override { + va_list arglist; + va_start(arglist, fmt); + message_ = wxString::Format(_(fmt), arglist); + va_end(arglist); + } + + virtual void title(const std::string & /*title*/) override {} + +}; +} + +void AppController::set_global_progress_indicator_id( + unsigned gid, + unsigned sid) +{ + wxGauge* gauge = dynamic_cast(wxWindow::FindWindowById(gid)); + wxStatusBar* sb = dynamic_cast(wxWindow::FindWindowById(sid)); + + if(gauge && sb) { + global_progressind_ = std::make_shared(gauge, sb, *this); + } +} + +PrintController::PngExportData PrintController::query_png_export_data() +{ + + class PngExportView: public PngExportDialog { + double ratio_, bs_ratio_; + public: + + PngExportView(): PngExportDialog(wxTheApp->GetTopWindow()) { + 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.corr = corr_spin_->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); + corr_spin_->SetValue(data.corr); + } + + 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_)); + } else { + spin_reso_width_->SetValue( + std::round(spin_reso_height_->GetValue()*ratio_)); + } + } + } + + 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_)); + } else { + bed_width_spin_->SetValue( + std::round(bed_height_spin_->GetValue()*bs_ratio_)); + } + } + } + }; + + PngExportView exdlg; + + 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; +} + +} diff --git a/xs/src/slic3r/GUI/PngExportDialog.cpp b/xs/src/slic3r/GUI/PngExportDialog.cpp new file mode 100644 index 000000000..18ac418ea --- /dev/null +++ b/xs/src/slic3r/GUI/PngExportDialog.cpp @@ -0,0 +1,154 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jun 17 2015) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "PngExportDialog.hpp" + +/////////////////////////////////////////////////////////////////////////// + +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 ); + + wxBoxSizer* top_layout_; + top_layout_ = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* bSizer15; + bSizer15 = new wxBoxSizer( wxHORIZONTAL ); + + wxBoxSizer* bSizer16; + bSizer16 = new wxBoxSizer( wxVERTICAL ); + + wxGridSizer* gSizer2; + gSizer2 = new wxGridSizer( 4, 1, 0, 0 ); + + filepick_text_ = new wxStaticText( this, wxID_ANY, _("Target zip file"), wxDefaultPosition, wxDefaultSize, 0 ); + filepick_text_->Wrap( -1 ); + gSizer2->Add( filepick_text_, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + resotext_ = new wxStaticText( this, wxID_ANY, _("Resolution (w, h) [px]"), wxDefaultPosition, wxDefaultSize, 0 ); + resotext_->Wrap( -1 ); + gSizer2->Add( resotext_, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + bed_size_text_ = new wxStaticText( this, wxID_ANY, _("Bed size (w, h) [mm]"), wxDefaultPosition, wxDefaultSize, 0 ); + bed_size_text_->Wrap( -1 ); + gSizer2->Add( bed_size_text_, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + corr_text_ = new wxStaticText( this, wxID_ANY, _("Size correction"), wxDefaultPosition, wxDefaultSize, 0 ); + corr_text_->Wrap( -1 ); + gSizer2->Add( corr_text_, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + + bSizer16->Add( gSizer2, 1, wxEXPAND, 5 ); + + + bSizer15->Add( bSizer16, 1, wxEXPAND, 5 ); + + wxBoxSizer* bSizer18; + bSizer18 = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* filepick_layout_; + filepick_layout_ = new wxBoxSizer( wxHORIZONTAL ); + + filepick_ctl_ = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, _("Select a file"), wxT("*.zip"), wxDefaultPosition, wxSize( 308,-1 ), wxFLP_DEFAULT_STYLE, wxDefaultValidator, wxT("filepick_ctl") ); + filepick_layout_->Add( filepick_ctl_, 0, wxALIGN_CENTER|wxALIGN_LEFT|wxALL, 5 ); + + + bSizer18->Add( filepick_layout_, 1, wxEXPAND, 5 ); + + wxBoxSizer* resolution_layout_; + resolution_layout_ = new wxBoxSizer( wxHORIZONTAL ); + + wxBoxSizer* resolution_spins_layout_; + resolution_spins_layout_ = new wxBoxSizer( wxHORIZONTAL ); + + spin_reso_width_ = new wxSpinCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 100,-1 ), wxSP_ARROW_KEYS, 0, 10000, 1440 ); + resolution_spins_layout_->Add( spin_reso_width_, 0, wxALIGN_CENTER|wxALL, 5 ); + + spin_reso_height_ = new wxSpinCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 100,-1 ), wxSP_ARROW_KEYS, 0, 10000, 2560 ); + resolution_spins_layout_->Add( spin_reso_height_, 0, wxALIGN_CENTER|wxALL, 5 ); + + reso_lock_btn_ = new wxToggleButton( this, wxID_ANY, _("Lock"), wxDefaultPosition, wxDefaultSize, 0 ); + reso_lock_btn_->SetValue(true); + resolution_spins_layout_->Add( reso_lock_btn_, 0, wxALL, 5 ); + + + resolution_layout_->Add( resolution_spins_layout_, 1, wxEXPAND, 5 ); + + + bSizer18->Add( resolution_layout_, 1, wxEXPAND, 5 ); + + wxBoxSizer* bedsize_layout_; + bedsize_layout_ = new wxBoxSizer( wxHORIZONTAL ); + + wxBoxSizer* bedsize_spins_layout_; + bedsize_spins_layout_ = new wxBoxSizer( wxHORIZONTAL ); + + bed_width_spin_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 100,-1 ), wxSP_ARROW_KEYS, 0, 1e6, 68.0 ); + bedsize_spins_layout_->Add( bed_width_spin_, 0, wxALIGN_CENTER|wxALL, 5 ); + + bed_height_spin_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 100,-1 ), wxSP_ARROW_KEYS, 0, 1e6, 120.0 ); + bedsize_spins_layout_->Add( bed_height_spin_, 0, wxALIGN_CENTER|wxALL, 5 ); + + bedsize_lock_btn_ = new wxToggleButton( this, wxID_ANY, _("Lock"), wxDefaultPosition, wxDefaultSize, 0 ); + bedsize_lock_btn_->SetValue(true); + bedsize_spins_layout_->Add( bedsize_lock_btn_, 0, wxALL, 5 ); + + + bedsize_layout_->Add( bedsize_spins_layout_, 1, wxEXPAND, 5 ); + + + bSizer18->Add( bedsize_layout_, 1, wxEXPAND, 5 ); + + wxBoxSizer* corr_layout_; + corr_layout_ = new wxBoxSizer( wxHORIZONTAL ); + + corr_spin_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 100,-1 ), wxSP_ARROW_KEYS, 0, 100, 1, 0.1 ); + corr_layout_->Add( corr_spin_, 0, wxALIGN_CENTER|wxALL, 5 ); + + + corr_layout_->Add( 0, 0, 1, wxEXPAND, 5 ); + + export_btn_ = new wxButton( this, wxID_ANY, _("Export"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("export_btn") ); + corr_layout_->Add( export_btn_, 0, wxALL, 5 ); + + + bSizer18->Add( corr_layout_, 1, wxEXPAND, 5 ); + + + bSizer15->Add( bSizer18, 1, wxEXPAND, 5 ); + + + top_layout_->Add( bSizer15, 1, wxEXPAND, 5 ); + + + this->SetSizer( top_layout_ ); + this->Layout(); + + this->Centre( wxBOTH ); + + // Connect Events + 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 + 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 ); + +} diff --git a/xs/src/slic3r/GUI/PngExportDialog.hpp b/xs/src/slic3r/GUI/PngExportDialog.hpp new file mode 100644 index 000000000..bcba1d5b7 --- /dev/null +++ b/xs/src/slic3r/GUI/PngExportDialog.hpp @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jun 17 2015) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __NONAME_H__ +#define __NONAME_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "GUI.hpp" + +/////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +/// Class PngExportDialog +/////////////////////////////////////////////////////////////////////////////// +class PngExportDialog : public wxDialog +{ + private: + + protected: + wxStaticText* filepick_text_; + wxStaticText* resotext_; + wxStaticText* bed_size_text_; + wxStaticText* corr_text_; + wxFilePickerCtrl* filepick_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* corr_spin_; + wxButton* export_btn_; + + // Virtual event handlers, overide them in your derived class + 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 = _("Slice to zipped PNG files"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 452,170 ), long style = wxDEFAULT_DIALOG_STYLE ); + ~PngExportDialog(); + +}; + +#endif //__NONAME_H__ diff --git a/xs/src/slic3r/iprogressindicator.hpp b/xs/src/slic3r/IProgressIndicator.hpp similarity index 100% rename from xs/src/slic3r/iprogressindicator.hpp rename to xs/src/slic3r/IProgressIndicator.hpp diff --git a/xs/src/slic3r/appcontrollerwx.cpp b/xs/src/slic3r/appcontrollerwx.cpp deleted file mode 100644 index 2dd37a831..000000000 --- a/xs/src/slic3r/appcontrollerwx.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include "AppController.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace Slic3r { - -AppControllerBoilerplate::PathList -AppControllerBoilerplate::query_destination_paths( - const std::string &title, - const std::string &extensions) const -{ - - wxFileDialog dlg(wxTheApp->GetTopWindow(), wxString(title) ); - dlg.SetWildcard(extensions); - - dlg.ShowModal(); - - wxArrayString paths; - dlg.GetPaths(paths); - - PathList ret(paths.size(), ""); - for(auto& p : paths) ret.push_back(p.ToStdString()); - - return ret; -} - -AppControllerBoilerplate::Path -AppControllerBoilerplate::query_destination_path( - const std::string &title, - const std::string &extensions, - const std::string& hint) const -{ - wxFileDialog dlg(wxTheApp->GetTopWindow(), title ); - dlg.SetWildcard(extensions); - - dlg.SetFilename(hint); - - Path ret; - - if(dlg.ShowModal() == wxID_OK) { - ret = Path(dlg.GetPath()); - } - - return ret; -} - -void AppControllerBoilerplate::report_issue(IssueType issuetype, - const std::string &description, - const std::string &brief) -{ - auto icon = wxICON_INFORMATION; - switch(issuetype) { - case IssueType::INFO: break; - case IssueType::WARN: icon = wxICON_WARNING; break; - case IssueType::ERR: - case IssueType::FATAL: icon = wxICON_ERROR; - } - - wxString str = _("Proba szoveg"); - wxMessageBox(str + _(description), _(brief), icon); -} - -wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent); - -namespace { -class GuiProgressIndicator: - public IProgressIndicator, public wxEvtHandler { - - std::shared_ptr gauge_; - using Base = IProgressIndicator; - wxString message_; - int range_; wxString title_; - unsigned prc_ = 0; - bool is_asynch_ = false; - - // status update handler - void _state( wxCommandEvent& evt) { - unsigned st = evt.GetInt(); - _state(st); - } - - void _state( unsigned st) { - if(st < max()) { - if(!gauge_) gauge_ = std::make_shared( - title_, message_, range_, wxTheApp->GetTopWindow(), - wxPD_APP_MODAL | wxPD_AUTO_HIDE - ); - - if(!gauge_->IsShown()) gauge_->ShowModal(); - Base::state(st); - gauge_->Update(static_cast(st), message_); - } - - if(st == max()) { - prc_++; - if(prc_ == Base::procedure_count()) { - gauge_.reset(); - prc_ = 0; - } - } - } - -public: - - inline void asynch(bool is) { is_asynch_ = is; } - inline bool asynch() const { return is_asynch_; } - - inline GuiProgressIndicator(int range, const std::string& title, - const std::string& firstmsg) : - range_(range), message_(_(firstmsg)), title_(_(title)) - { - Base::max(static_cast(range)); - Base::states(static_cast(range)); - - Bind(PROGRESS_STATUS_UPDATE_EVENT, - &GuiProgressIndicator::_state, - this); - } - - virtual void state(float val) override { - if( val >= 1.0) state(static_cast(val)); - } - - virtual void state(unsigned st) override { - // send status update event - if(is_asynch_) { - auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT); - evt->SetInt(st); - wxQueueEvent(this, evt); - } else _state(st); - } - - virtual void message(const std::string & msg) override { - message_ = _(msg); - } - - virtual void messageFmt(const std::string& fmt, ...) { - va_list arglist; - va_start(arglist, fmt); - message_ = wxString::Format(_(fmt), arglist); - va_end(arglist); - } - - virtual void title(const std::string & title) override { - title_ = _(title); - } -}; -} - -AppControllerBoilerplate::ProgresIndicatorPtr -AppControllerBoilerplate::create_progress_indicator( - unsigned statenum, const std::string& title, - const std::string& firstmsg) const -{ - auto pri = - std::make_shared(statenum, title, firstmsg); - - pri->asynch(!is_main_thread()); - - return pri; -} - -//AppControllerBoilerplate::ProgresIndicatorPtr -//AppControllerBoilerplate::create_progress_indicator(unsigned statenum, -// const std::string& title, -// const std::string& firstmsg) const -//{ -// class GuiProgressIndicator: public IProgressIndicator, public wxEvtHandler { -// using Base = IProgressIndicator; -// wxString message_, title_; -// wxProgressDialog gauge_; - -// void _state( wxCommandEvent& evt) { -// unsigned st = evt.GetInt(); - -// if(title_.compare(gauge_.GetTitle())) -// gauge_.SetTitle(title_); - -// if(!gauge_.IsShown()) gauge_.ShowModal(); -// Base::state(st); -// gauge_.Update(static_cast(st), message_); - -// } -// public: - -// inline GuiProgressIndicator(int range, const std::string& title, -// const std::string& firstmsg): -// message_(_(firstmsg)), title_(_(title)), -// gauge_(title_, message_, range, wxTheApp->GetTopWindow()) -// { -// gauge_.Show(false); - -// Base::max(static_cast(range)); -// Base::states(static_cast(range)); - -// Bind(PROGRESS_STATUS_UPDATE_EVENT, -// &GuiProgressIndicator::_state, -// this); -// } - -// virtual void state(float val) override { -// if( val >= 1.0) state(static_cast(val)); -// } - -// virtual void state(unsigned st) override { -// // send status update event -// auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT); -// evt->SetInt(st); -// wxQueueEvent(this, evt); -// } - -// virtual void message(const std::string & msg) override { -// message_ = _(msg); -// } - -// virtual void message_fmt(const std::string& fmt, ...) override { -// va_list arglist; -// va_start(arglist, fmt); -// message_ = wxString::Format(_(fmt), arglist); -// va_end(arglist); -// } - -// virtual void title(const std::string & title) override { -// title_ = _(title); -// } -// }; - -// auto pri = -// std::make_shared(statenum, title, firstmsg); - -// return pri; -//} - -void AppController::set_global_progress_indicator_id( - unsigned gid, - unsigned sid) -{ - - class Wrapper: public IProgressIndicator { - wxGauge *gauge_; - wxStatusBar *stbar_; - using Base = IProgressIndicator; - std::string message_; - - void showProgress(bool show = true) { - gauge_->Show(show); - gauge_->Pulse(); - } - - public: - - inline Wrapper(wxGauge *gauge, wxStatusBar *stbar): - gauge_(gauge), stbar_(stbar) - { - Base::max(static_cast(gauge->GetRange())); - Base::states(static_cast(gauge->GetRange())); - } - - virtual void state(float val) override { - if( val <= max() && val >= 1.0) { - Base::state(val); - stbar_->SetStatusText(message_); - gauge_->SetValue(static_cast(val)); - } - } - - virtual void state(unsigned st) override { - if( st <= max() ) { - Base::state(st); - - if(!gauge_->IsShown()) showProgress(true); - - stbar_->SetStatusText(message_); - if(st == gauge_->GetRange()) { - gauge_->SetValue(0); - showProgress(false); - } else { - gauge_->SetValue(static_cast(st)); - } - } - } - - virtual void message(const std::string & msg) override { - message_ = msg; - } - - virtual void message_fmt(const std::string& fmt, ...) override { - va_list arglist; - va_start(arglist, fmt); - message_ = wxString::Format(_(fmt), arglist); - va_end(arglist); - } - - virtual void title(const std::string & /*title*/) override {} - - }; - - wxGauge* gauge = dynamic_cast(wxWindow::FindWindowById(gid)); - wxStatusBar* sb = dynamic_cast(wxWindow::FindWindowById(sid)); - - if(gauge && sb) { - global_progressind_ = std::make_shared(gauge, sb); - } -} - -}