Patch from Lubomír Bláha applied. Polished comments and PngExportDialog.

This commit is contained in:
tamasmeszaros 2018-06-27 10:28:44 +02:00
parent c28b602465
commit 8eb8d4f0c5
5 changed files with 49 additions and 18 deletions

View File

@ -128,6 +128,7 @@ The author of the Silk icon set is Mark James.
--post-process Generated G-code will be processed with the supplied script; --post-process Generated G-code will be processed with the supplied script;
call this more than once to process through multiple scripts. call this more than once to process through multiple scripts.
--export-svg Export a SVG file containing slices instead of G-code. --export-svg Export a SVG file containing slices instead of G-code.
--export-png Export zipped PNG files containing slices instead of G-code.
-m, --merge If multiple files are supplied, they will be composed into a single -m, --merge If multiple files are supplied, they will be composed into a single
print rather than processed individually. print rather than processed individually.

View File

@ -43,6 +43,7 @@ my %cli_options = ();
'gui-mode=s' => \$opt{obsolete_ignore_this_option_gui_mode}, 'gui-mode=s' => \$opt{obsolete_ignore_this_option_gui_mode},
'datadir=s' => \$opt{datadir}, 'datadir=s' => \$opt{datadir},
'export-svg' => \$opt{export_svg}, 'export-svg' => \$opt{export_svg},
'export-png' => \$opt{export_png},
'merge|m' => \$opt{merge}, 'merge|m' => \$opt{merge},
'repair' => \$opt{repair}, 'repair' => \$opt{repair},
'cut=f' => \$opt{cut}, 'cut=f' => \$opt{cut},
@ -217,6 +218,8 @@ if (@ARGV) { # slicing from command line
if ($opt{export_svg}) { if ($opt{export_svg}) {
$sprint->export_svg; $sprint->export_svg;
} elsif ($opt{export_png}) {
$sprint->export_png;
} else { } else {
my $t0 = [gettimeofday]; my $t0 = [gettimeofday];
# The following call may die if the output_filename_format template substitution fails, # The following call may die if the output_filename_format template substitution fails,
@ -282,6 +285,7 @@ Usage: slic3r.pl [ OPTIONS ] [ file.stl ] [ file2.stl ] ...
--post-process Generated G-code will be processed with the supplied script; --post-process Generated G-code will be processed with the supplied script;
call this more than once to process through multiple scripts. call this more than once to process through multiple scripts.
--export-svg Export a SVG file containing slices instead of G-code. --export-svg Export a SVG file containing slices instead of G-code.
--export-png Export zipped PNG files containing slices instead of G-code.
-m, --merge If multiple files are supplied, they will be composed into a single -m, --merge If multiple files are supplied, they will be composed into a single
print rather than processed individually. print rather than processed individually.

View File

@ -17,14 +17,15 @@ class PrintObject;
/** /**
* @brief A boilerplate class for creating application logic. It should provide * @brief A boilerplate class for creating application logic. It should provide
* features as issue reporting, gauge and progress indication, etc... * features as issue reporting and progress indication, etc...
* *
* The lower lever UI independent classes should be manipulated with a subclass * The lower lever UI independent classes can be manipulated with a subclass
* of this controller class. We can also catch any exceptions that lower level * of this controller class. We can also catch any exceptions that lower level
* methods could throw and display appropriate errors and warnings. * methods could throw and display appropriate errors and warnings.
* *
* Note that even the inner interface of this class free from any UI toolkit. * Note that the outer and the inner interface of this class is free from any
* We can implement it with any UI framework or make it a cli client. * UI toolkit dependencies. We can implement it with any UI framework or make it
* a cli client.
*/ */
class AppControllerBoilerplate { class AppControllerBoilerplate {
class PriMap; // Some structure to store progress indication data class PriMap; // Some structure to store progress indication data
@ -73,7 +74,7 @@ public:
const std::string& title) const; const std::string& title) const;
/** /**
* @brief Same as query_destination_path but returns only one path. * @brief Same as query_destination_paths but returns only one path.
*/ */
Path query_destination_path( Path query_destination_path(
const std::string& title, const std::string& title,
@ -124,7 +125,7 @@ public:
* created the AppConroller object itself. This probably means that the * created the AppConroller object itself. This probably means that the
* execution is in the UI thread. Otherwise it returns false meaning that * execution is in the UI thread. Otherwise it returns false meaning that
* some worker thread called this function. * some worker thread called this function.
* @return Return true if for the same caller thread that created this * @return Return true for the same caller thread that created this
* object and false for every other. * object and false for every other.
*/ */
bool is_main_thread() const; bool is_main_thread() const;
@ -132,7 +133,7 @@ public:
protected: protected:
/** /**
* @brief Create a new progress indicator and retirn a smart pointer to it. * @brief Create a new progress indicator and return a smart pointer to it.
* @param statenum The number of states for the given procedure. * @param statenum The number of states for the given procedure.
* @param title The title of the procedure. * @param title The title of the procedure.
* @param firstmsg The message for the first subtask to be displayed. * @param firstmsg The message for the first subtask to be displayed.
@ -143,7 +144,8 @@ protected:
const std::string& title, const std::string& title,
const std::string& firstmsg = "") const; const std::string& firstmsg = "") const;
// This is a global // This is a global progress indicator placeholder. In the Slic3r UI it can
// contain the progress indicator on the statusbar.
ProgresIndicatorPtr global_progressind_; ProgresIndicatorPtr global_progressind_;
}; };
@ -162,16 +164,19 @@ protected:
void infill(PrintObject *pobj); void infill(PrintObject *pobj);
void gen_support_material(PrintObject *pobj); void gen_support_material(PrintObject *pobj);
// Data structure with the png export input data
struct PngExportData { struct PngExportData {
std::string zippath; std::string zippath; // output zip file
unsigned long width_px = 1440; unsigned long width_px = 1440; // resolution - rows
unsigned long height_px = 2560; unsigned long height_px = 2560; // resolution columns
double width_mm = 68.0, height_mm = 120.0; double width_mm = 68.0, height_mm = 120.0; // dimensions in mm
double corr = 1.0; double corr = 1.0; // multiplies the dimensions
}; };
// Should display a dialog with the input fields for printing to png
PngExportData query_png_export_data(); PngExportData query_png_export_data();
// The previous export data, to pre-populate the dialog
PngExportData prev_expdata_; PngExportData prev_expdata_;
public: public:

View File

@ -13,6 +13,11 @@
#include <wx/statusbr.h> #include <wx/statusbr.h>
#include <wx/event.h> #include <wx/event.h>
// This source file implements the UI dependent methods of the AppControllers.
// It will be clear what is needed to be reimplemented in case of a UI framework
// change or a CLI client creation. In this particular case we use wxWidgets to
// implement everything.
namespace Slic3r { namespace Slic3r {
AppControllerBoilerplate::PathList AppControllerBoilerplate::PathList
@ -73,6 +78,11 @@ void AppControllerBoilerplate::report_issue(IssueType issuetype,
wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent); wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
namespace { namespace {
/*
* A simple thread safe progress dialog implementation that can be used from
* the main thread as well.
*/
class GuiProgressIndicator: class GuiProgressIndicator:
public IProgressIndicator, public wxEvtHandler { public IProgressIndicator, public wxEvtHandler {
@ -91,6 +101,7 @@ class GuiProgressIndicator:
_state(st); _state(st);
} }
// Status update implementation
void _state( unsigned st) { void _state( unsigned st) {
if(st < max()) { if(st < max()) {
if(!gauge_) gauge_ = std::make_shared<wxProgressDialog>( if(!gauge_) gauge_ = std::make_shared<wxProgressDialog>(
@ -114,7 +125,10 @@ class GuiProgressIndicator:
public: public:
/// Setting whether it will be used from the UI thread or some worker thread
inline void asynch(bool is) { is_asynch_ = is; } inline void asynch(bool is) { is_asynch_ = is; }
/// Get the mode of parallel operation.
inline bool asynch() const { return is_asynch_; } inline bool asynch() const { return is_asynch_; }
inline GuiProgressIndicator(int range, const std::string& title, inline GuiProgressIndicator(int range, const std::string& title,
@ -167,12 +181,16 @@ AppControllerBoilerplate::create_progress_indicator(
auto pri = auto pri =
std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg); std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg);
// We set up the mode of operation depending of the creator thread's
// identity
pri->asynch(!is_main_thread()); pri->asynch(!is_main_thread());
return pri; return pri;
} }
namespace { namespace {
// A wrapper progress indicator class around the statusbar created in perl.
class Wrapper: public IProgressIndicator, public wxEvtHandler { class Wrapper: public IProgressIndicator, public wxEvtHandler {
wxGauge *gauge_; wxGauge *gauge_;
wxStatusBar *stbar_; wxStatusBar *stbar_;
@ -264,6 +282,7 @@ void AppController::set_global_progress_indicator(
PrintController::PngExportData PrintController::query_png_export_data() PrintController::PngExportData PrintController::query_png_export_data()
{ {
// Implement the logic of the PngExportDialog
class PngExportView: public PngExportDialog { class PngExportView: public PngExportDialog {
double ratio_, bs_ratio_; double ratio_, bs_ratio_;
public: public:
@ -308,26 +327,28 @@ PrintController::PngExportData PrintController::query_png_export_data()
virtual void EvalResoSpin( wxCommandEvent& event ) override { virtual void EvalResoSpin( wxCommandEvent& event ) override {
if(reso_lock_btn_->GetValue()) { if(reso_lock_btn_->GetValue()) {
if(event.GetId() == spin_reso_width_->GetId()) { if(event.GetId() == spin_reso_width_->GetId()) {
spin_reso_height_->SetValue( spin_reso_height_->SetValue(
std::round(spin_reso_width_->GetValue()/ratio_)); std::round(spin_reso_width_->GetValue()/ratio_));
spin_reso_height_->Update();
} else { } else {
spin_reso_width_->SetValue( spin_reso_width_->SetValue(
std::round(spin_reso_height_->GetValue()*ratio_)); std::round(spin_reso_height_->GetValue()*ratio_));
spin_reso_width_->Update();
} }
} }
} }
virtual void EvalBedSpin( wxCommandEvent& event ) override { virtual void EvalBedSpin( wxCommandEvent& event ) override {
if(bedsize_lock_btn_->GetValue()) { if(bedsize_lock_btn_->GetValue()) {
if(event.GetId() == bed_width_spin_->GetId()) { if(event.GetId() == bed_width_spin_->GetId()) {
bed_height_spin_->SetValue( bed_height_spin_->SetValue(
std::round(bed_width_spin_->GetValue()/bs_ratio_)); std::round(bed_width_spin_->GetValue()/bs_ratio_));
bed_height_spin_->Update();
} else { } else {
bed_width_spin_->SetValue( bed_width_spin_->SetValue(
std::round(bed_height_spin_->GetValue()*bs_ratio_)); std::round(bed_height_spin_->GetValue()*bs_ratio_));
bed_width_spin_->Update();
} }
} }
} }

View File

@ -73,7 +73,7 @@ PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id, const wxStrin
reso_lock_btn_ = new wxToggleButton( this, wxID_ANY, _("Lock"), wxDefaultPosition, wxDefaultSize, 0 ); reso_lock_btn_ = new wxToggleButton( this, wxID_ANY, _("Lock"), wxDefaultPosition, wxDefaultSize, 0 );
reso_lock_btn_->SetValue(true); reso_lock_btn_->SetValue(true);
resolution_spins_layout_->Add( reso_lock_btn_, 0, wxALL, 5 ); resolution_spins_layout_->Add( reso_lock_btn_, 0, wxALIGN_CENTER|wxALL, 5 );
resolution_layout_->Add( resolution_spins_layout_, 1, wxEXPAND, 5 ); resolution_layout_->Add( resolution_spins_layout_, 1, wxEXPAND, 5 );
@ -95,7 +95,7 @@ PngExportDialog::PngExportDialog( wxWindow* parent, wxWindowID id, const wxStrin
bedsize_lock_btn_ = new wxToggleButton( this, wxID_ANY, _("Lock"), wxDefaultPosition, wxDefaultSize, 0 ); bedsize_lock_btn_ = new wxToggleButton( this, wxID_ANY, _("Lock"), wxDefaultPosition, wxDefaultSize, 0 );
bedsize_lock_btn_->SetValue(true); bedsize_lock_btn_->SetValue(true);
bedsize_spins_layout_->Add( bedsize_lock_btn_, 0, wxALL, 5 ); bedsize_spins_layout_->Add( bedsize_lock_btn_, 0, wxALIGN_CENTER|wxALL, 5 );
bedsize_layout_->Add( bedsize_spins_layout_, 1, wxEXPAND, 5 ); bedsize_layout_->Add( bedsize_spins_layout_, 1, wxEXPAND, 5 );