Refactor and extensions to png export dialog.

This commit is contained in:
tamasmeszaros 2018-06-27 17:43:54 +02:00
parent 30e177d986
commit ac9d81cfa0
11 changed files with 492 additions and 341 deletions

View file

@ -11,6 +11,7 @@
#include <PrintConfig.hpp>
#include <Print.hpp>
#include <PrintExport.hpp>
#include <Model.hpp>
#include <Utils.hpp>
@ -172,7 +173,7 @@ void PrintController::slice(PrintObject *pobj)
if(pobj->layers.empty())
report_issue(IssueType::ERR,
"No layers were detected. You might want to repair your "
"STL file(s) or check their size or thickness and retry"
"STL file(s) or check their size or thickness and retry"
);
pobj->state.set_done(STEP_SLICE);
@ -268,8 +269,6 @@ void PrintController::slice()
void PrintController::slice_to_png()
{
assert(model_ != nullptr);
auto exd = query_png_export_data();
if(exd.zippath.empty()) return;
@ -287,8 +286,24 @@ void PrintController::slice_to_png()
print_->validate();
} catch(std::exception& e) {
report_issue(IssueType::ERR, e.what(), "Error");
return;
}
// TODO
/*bool correction = false;
if(exd.corr_x != 1.0 || exd.corr_y != 1.0 || exd.corr_z != 1.0) {
correction = true;
print_->invalidate_all_steps();
for(auto po : print_->objects) {
po->model_object()->scale(
Pointf3(exd.corr_x, exd.corr_y, exd.corr_z)
);
po->model_object()->invalidate_bounding_box();
po->reload_model_instances();
}
}*/
auto print_bb = print_->bounding_box();
// If the print does not fit into the print area we should cry about it.
@ -311,6 +326,7 @@ void PrintController::slice_to_png()
slice();
} catch (std::exception& e) {
report_issue(IssueType::ERR, e.what(), "Exception");
progress_indicator()->cancel();
return;
}
@ -318,12 +334,26 @@ void PrintController::slice_to_png()
print_->progressindicator = progress_indicator();
try {
print_->print_to_png(exd.zippath, exd.width_px, exd.height_px,
exd.width_mm, exd.height_mm);
print_to<FilePrinterFormat::PNG>( *print_, exd.zippath,
exd.width_mm, exd.height_mm,
exd.width_px, exd.height_px );
} catch (std::exception& e) {
report_issue(IssueType::ERR, e.what(), "Exception");
progress_indicator()->cancel();
}
/*if(correction) { // scale the model back
print_->invalidate_all_steps();
for(auto po : print_->objects) {
po->model_object()->scale(
Pointf3(1.0/exd.corr_x, 1.0/exd.corr_y, 1.0/exd.corr_z)
);
po->model_object()->invalidate_bounding_box();
po->reload_model_instances();
}
}*/
print_->progressindicator = pbak;
});
}

View file

@ -51,6 +51,7 @@ public:
enum class IssueType {
INFO,
WARN,
WARN_Q, // Warning with a question to continue
ERR,
FATAL
};
@ -91,7 +92,7 @@ public:
* @param brief A very brief description. Can be used for message dialog
* title.
*/
void report_issue(IssueType issuetype,
bool report_issue(IssueType issuetype,
const std::string& description,
const std::string& brief = "");
@ -170,7 +171,9 @@ protected:
unsigned long width_px = 1440; // resolution - rows
unsigned long height_px = 2560; // resolution columns
double width_mm = 68.0, height_mm = 120.0; // dimensions in mm
double corr = 1.0; // multiplies the dimensions
double corr_x = 1.0; // offsetting in x
double corr_y = 1.0; // offsetting in y
double corr_z = 1.0; // offsetting in y
};
// Should display a dialog with the input fields for printing to png
@ -208,6 +211,9 @@ public:
* @brief Slice the print into zipped png files.
*/
void slice_to_png();
void slice_to_png(std::string dirpath);
};
/**

View file

@ -60,19 +60,22 @@ AppControllerBoilerplate::query_destination_path(
return ret;
}
void AppControllerBoilerplate::report_issue(IssueType issuetype,
bool AppControllerBoilerplate::report_issue(IssueType issuetype,
const std::string &description,
const std::string &brief)
{
auto icon = wxICON_INFORMATION;
auto style = wxOK|wxCENTRE;
switch(issuetype) {
case IssueType::INFO: break;
case IssueType::WARN: icon = wxICON_WARNING; break;
case IssueType::WARN_Q: icon = wxICON_WARNING; style |= wxCANCEL; break;
case IssueType::ERR:
case IssueType::FATAL: icon = wxICON_ERROR;
}
wxMessageBox(description, brief, icon);
auto ret = wxMessageBox(description, brief, icon | style);
return ret != wxCANCEL;
}
wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
@ -143,6 +146,11 @@ public:
this, id_);
}
virtual void cancel() override {
update(max(), "Abort");
IProgressIndicator::cancel();
}
virtual void state(float val) override {
if( val >= 1.0) state(static_cast<unsigned>(val));
}
@ -285,9 +293,12 @@ PrintController::PngExportData PrintController::query_png_export_data()
// Implement the logic of the PngExportDialog
class PngExportView: public PngExportDialog {
double ratio_, bs_ratio_;
PrintController& ctl_;
public:
PngExportView(): PngExportDialog(wxTheApp->GetTopWindow()) {
PngExportView(PrintController& ctl):
PngExportDialog(wxTheApp->GetTopWindow()), ctl_(ctl)
{
ratio_ = double(spin_reso_width_->GetValue()) /
spin_reso_height_->GetValue();
@ -302,7 +313,9 @@ PrintController::PngExportData PrintController::query_png_export_data()
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();
ret.corr_x = corr_spin_x_->GetValue();
ret.corr_y = corr_spin_y_->GetValue();
ret.corr_z = corr_spin_z_->GetValue();
return ret;
}
@ -312,7 +325,11 @@ PrintController::PngExportData PrintController::query_png_export_data()
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);
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 {
@ -352,9 +369,24 @@ PrintController::PngExportData PrintController::query_png_export_data()
}
}
}
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,
"File already exists. Overwrite?",
"Warning")) ret = wxID_CANCEL;
EndModal(ret);
}
};
PngExportView exdlg;
PngExportView exdlg(*this);
exdlg.prefill(prev_expdata_);

View file

@ -23,12 +23,16 @@ PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id, const wxStrin
bSizer16 = new wxBoxSizer( wxVERTICAL );
wxGridSizer* gSizer2;
gSizer2 = new wxGridSizer( 4, 1, 0, 0 );
gSizer2 = new wxGridSizer( 5, 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 );
auto confpick_text = new wxStaticText( this, wxID_ANY, _("Config file (optional)"), wxDefaultPosition, wxDefaultSize, 0 );
confpick_text->Wrap( -1 );
gSizer2->Add( confpick_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 );
@ -37,7 +41,7 @@ PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id, const wxStrin
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_ = new wxStaticText( this, wxID_ANY, _("Scale (x, y, z)"), wxDefaultPosition, wxDefaultSize, 0 );
corr_text_->Wrap( -1 );
gSizer2->Add( corr_text_, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
@ -52,13 +56,16 @@ PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id, const wxStrin
wxBoxSizer* filepick_layout_;
filepick_layout_ = new wxBoxSizer( wxHORIZONTAL );
filepick_ctl_ = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, _("Select a file"), wxT("*.zip"), wxDefaultPosition, wxDefaultSize, wxFLP_USE_TEXTCTRL | wxFLP_SAVE | wxFLP_OVERWRITE_PROMPT, wxDefaultValidator, wxT("filepick_ctl") );
filepick_ctl_ = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, _("Select a file"), wxT("*.zip"), wxDefaultPosition, wxDefaultSize, wxFLP_USE_TEXTCTRL | wxFLP_SAVE, wxDefaultValidator, wxT("filepick_ctl") );
filepick_layout_->Add( filepick_ctl_, 2, wxALIGN_CENTER|wxALL, 5 );
bSizer18->Add( filepick_layout_, 1, wxEXPAND, 5 );
wxBoxSizer* confpick_layout_;
confpick_layout_ = 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_layout_ ->Add( confpick_ctl_, 2, wxALIGN_CENTER|wxALL, 5 );
bSizer18->Add( confpick_layout_ , 1, wxEXPAND, 5 );
wxBoxSizer* resolution_layout_;
resolution_layout_ = new wxBoxSizer( wxHORIZONTAL );
@ -104,9 +111,20 @@ PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id, const wxStrin
wxBoxSizer* corr_layout_;
corr_layout_ = new wxBoxSizer( wxHORIZONTAL );
corr_spin_ = new wxSpinCtrlDouble( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 100, 1, 0.1 );
corr_layout_->Add( corr_spin_, 0, wxALIGN_CENTER|wxALL, 5 );
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( 0, 0, 1, wxEXPAND, 5 );
@ -131,6 +149,7 @@ PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id, const wxStrin
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 );
@ -143,6 +162,7 @@ PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id, const wxStrin
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 );

View file

@ -41,16 +41,20 @@ class PngExportDialog : public wxDialog
wxStaticText* bed_size_text_;
wxStaticText* corr_text_;
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* corr_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(); }

View file

@ -15,7 +15,7 @@ public:
private:
float state_ = .0f, max_ = 1.f, step_;
std::function<void(void)> cancelfunc_ = [](){};
CancelFn cancelfunc_ = [](){};
unsigned proc_count_ = 1;
public:
@ -54,8 +54,11 @@ public:
/// Set up a cancel callback for the operation if feasible.
inline void on_cancel(CancelFn func) { cancelfunc_ = func; }
/// Call a previously specified cancel callback.
inline void on_cancel() { cancelfunc_(); }
/**
* Explicitly shut down the progress indicator and call the associated
* callback.
*/
virtual void cancel() { cancelfunc_(); }
/**
* \brief Set up how many subprocedures does the whole operation contain.