diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 020edd70f..44100db8c 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -49,7 +49,6 @@ use Slic3r::Model; use Slic3r::Point; use Slic3r::Polygon; use Slic3r::Polyline; -use Slic3r::Print; use Slic3r::Print::Object; use Slic3r::Print::Simple; use Slic3r::Surface; diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 01143aeee..216be3441 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -33,7 +33,6 @@ use constant MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(known stl obj amf # Datadir provided on the command line. our $datadir; -# If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. our $no_plater; our @cb; @@ -103,8 +102,6 @@ sub OnInit { print STDERR "Creating main frame...\n"; Wx::Image::FindHandlerType(wxBITMAP_TYPE_PNG) || Wx::Image::AddHandler(Wx::PNGHandler->new); $self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new( - # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. - no_controller => $self->{app_config}->get('no_controller'), no_plater => $no_plater, lang_ch_event => $LANGUAGE_CHANGE_EVENT, preferences_event => $PREFERENCES_EVENT, @@ -170,8 +167,6 @@ sub recreate_GUI{ my ($self) = @_; my $topwindow = $self->GetTopWindow(); $self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new( - # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. - no_controller => $self->{app_config}->get('no_controller'), no_plater => $no_plater, lang_ch_event => $LANGUAGE_CHANGE_EVENT, preferences_event => $PREFERENCES_EVENT, diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 554beba68..3f023c06f 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -57,8 +57,6 @@ sub new { } # store input params - # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. - $self->{no_controller} = $params{no_controller}; $self->{no_plater} = $params{no_plater}; $self->{loaded} = 0; $self->{lang_ch_event} = $params{lang_ch_event}; @@ -199,8 +197,6 @@ sub _init_tabpanel { ? 'load_current_preset' : 'update_tab_ui'; $self->{options_tabs}{$tab_name_other}->$update_action; } - # Update the controller printers. - $self->{controller}->update_presets($presets) if $self->{controller}; } $self->{plater}->on_config_change($tab->get_config); } @@ -239,8 +235,7 @@ sub _init_tabpanel { $self->{plater}->update(); }); - - Slic3r::GUI::create_preset_tabs($self->{no_controller}, $VALUE_CHANGE_EVENT, $PRESETS_CHANGED_EVENT); + Slic3r::GUI::create_preset_tabs($VALUE_CHANGE_EVENT, $PRESETS_CHANGED_EVENT); $self->{options_tabs} = {}; for my $tab_name (qw(print filament sla_material printer)) { $self->{options_tabs}{$tab_name} = Slic3r::GUI::get_preset_tab("$tab_name"); diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm deleted file mode 100644 index 79bc41ca3..000000000 --- a/lib/Slic3r/Print.pm +++ /dev/null @@ -1,69 +0,0 @@ -# The slicing work horse. -# Extends C++ class Slic3r::Print -package Slic3r::Print; -use strict; -use warnings; - -use File::Basename qw(basename fileparse); -use File::Spec; -use List::Util qw(min max first sum); -use Slic3r::ExtrusionLoop ':roles'; -use Slic3r::ExtrusionPath ':roles'; -use Slic3r::Flow ':roles'; -use Slic3r::Geometry qw(X Y unscale); -use Slic3r::Geometry::Clipper qw(diff_ex union_ex intersection_ex intersection offset - union JT_ROUND JT_SQUARE); -use Slic3r::Print::State ':steps'; - -sub size { - my $self = shift; - return $self->bounding_box->size; -} - -sub run_post_process_scripts { - my ($self, $output_file) = @_; - # run post-processing scripts - if (@{$self->config->post_process}) { -# $self->set_status(95, "Running post-processing scripts"); - $self->config->setenv; - for my $script (@{$self->config->post_process}) { - # Ignore empty post processing script lines. - next if $script =~ /^\s*$/; - Slic3r::debugf " '%s' '%s'\n", $script, $output_file; - # -x doesn't return true on Windows except for .exe files - if (($^O eq 'MSWin32') ? !(-e $script) : !(-x $script)) { - die "The configured post-processing script is not executable: check permissions. ($script)\n"; - } - if ($^O eq 'MSWin32' && $script =~ /\.[pP][lL]/) { - # The current process (^X) may be slic3r.exe or slic3r-console.exe. - # Replace it with the current perl interpreter. - my($filename, $directories, $suffix) = fileparse($^X); - $filename =~ s/^slic3r.*$/perl5\.24\.0\.exe/; - my $interpreter = $directories . $filename; - system($interpreter, $script, $output_file); - } else { - system($script, $output_file); - } - } - } -} - -sub export_png { - my $self = shift; - my %params = @_; - - my @sobjects = @{$self->objects}; - my $objnum = scalar @sobjects; - for(my $oi = 0; $oi < $objnum; $oi++) - { - $sobjects[$oi]->slice; - $self->set_status(($oi + 1)*100/$objnum - 1, "Slicing..."); - } - - my $fh = $params{output_file}; - $self->set_status(90, "Exporting zipped archive..."); - $self->print_to_png($fh); - $self->set_status(100, "Done."); -} - -1; diff --git a/slic3r.pl b/slic3r.pl index 4bf687cf5..38c10a900 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -38,7 +38,6 @@ my %cli_options = (); 'load=s@' => \$opt{load}, 'autosave=s' => \$opt{autosave}, 'ignore-nonexistent-config' => \$opt{ignore_nonexistent_config}, - 'no-controller' => \$opt{no_controller}, 'no-plater' => \$opt{no_plater}, 'gui-mode=s' => \$opt{obsolete_ignore_this_option_gui_mode}, 'datadir=s' => \$opt{datadir}, @@ -107,7 +106,6 @@ if ((!@ARGV || $opt{gui}) && !$opt{no_gui} && !$opt{save} && eval "require Slic3 { no warnings 'once'; $Slic3r::GUI::datadir = Slic3r::decode_path($opt{datadir} // ''); - $Slic3r::GUI::no_controller = $opt{no_controller}; $Slic3r::GUI::no_plater = $opt{no_plater}; $Slic3r::GUI::autosave = $opt{autosave}; } diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt index 7e35a27b1..a442530db 100644 --- a/xs/CMakeLists.txt +++ b/xs/CMakeLists.txt @@ -105,6 +105,8 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/GCode/Analyzer.hpp ${LIBDIR}/libslic3r/GCode/CoolingBuffer.cpp ${LIBDIR}/libslic3r/GCode/CoolingBuffer.hpp + ${LIBDIR}/libslic3r/GCode/PostProcessor.cpp + ${LIBDIR}/libslic3r/GCode/PostProcessor.hpp ${LIBDIR}/libslic3r/GCode/PressureEqualizer.cpp ${LIBDIR}/libslic3r/GCode/PressureEqualizer.hpp ${LIBDIR}/libslic3r/GCode/PreviewData.cpp diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 91c9d6b0f..ac09db4bd 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -418,14 +419,9 @@ void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_ { PROFILE_CLEAR(); - if (print->is_step_done(psGCodeExport)) { - // Does the file exist? If so, we hope that it is still valid. - FILE *f = boost::nowide::fopen(path, "r"); - if (f != nullptr) { - ::fclose(f); - return; - } - } + // Does the file exist? If so, we hope that it is still valid. + if (print->is_step_done(psGCodeExport) && boost::filesystem::exists(boost::filesystem::path(path))) + return; print->set_started(psGCodeExport); diff --git a/xs/src/libslic3r/GCode/PostProcessor.cpp b/xs/src/libslic3r/GCode/PostProcessor.cpp new file mode 100644 index 000000000..f3b28f398 --- /dev/null +++ b/xs/src/libslic3r/GCode/PostProcessor.cpp @@ -0,0 +1,55 @@ +#include "PostProcessor.hpp" + +namespace Slic3r { + +#ifdef WIN32 + +//FIXME Ignore until we include boost::process +void run_post_process_scripts(const std::string &path, const PrintConfig &config) +{ +} + +#else + +#include + +void run_post_process_scripts(const std::string &path, const PrintConfig &config) +{ + if (config.post_process.values.empty()) + return; + config.setenv_(); + for (std::string script: config.post_process.values) { + // Ignore empty post processing script lines. + boost::trim(script); + if (script.empty()) + continue; + BOOST_LOG_TRIVIAL(info) << "Executing script " << script << " on file " << path; + if (! boost::filesystem::exists(boost::filesystem::path(path))) + throw std::runtime_exception(std::string("The configured post-processing script does not exist: ") + path); +#ifndef WIN32 + file_status fs = boost::filesystem::status(path); + //FIXME test if executible by the effective UID / GID. + // throw std::runtime_exception(std::string("The configured post-processing script is not executable: check permissions. ") + path)); +#endif + int result = 0; +#ifdef WIN32 + if (boost::iends_with(file, ".gcode")) { + // The current process may be slic3r.exe or slic3r-console.exe. + // Find the path of the process: + wchar_t wpath_exe[_MAX_PATH + 1]; + ::GetModuleFileNameW(nullptr, wpath_exe, _MAX_PATH); + boost::filesystem::path path_exe(wpath_exe); + // Replace it with the current perl interpreter. + result = boost::process::system((path_exe.parent_path() / "perl5.24.0.exe").string(), script, output_file); + } else +#else + result = boost::process::system(script, output_file); +#endif + if (result < 0) + BOOST_LOG_TRIVIAL(error) << "Script " << script << " on file " << path << " failed. Negative error code returned."; + } +} + +#endif + +} // namespace Slic3r diff --git a/xs/src/libslic3r/GCode/PostProcessor.hpp b/xs/src/libslic3r/GCode/PostProcessor.hpp new file mode 100644 index 000000000..ce47374cb --- /dev/null +++ b/xs/src/libslic3r/GCode/PostProcessor.hpp @@ -0,0 +1,15 @@ +#ifndef slic3r_GCode_PostProcessor_hpp_ +#define slic3r_GCode_PostProcessor_hpp_ + +#include + +#include "../libslic3r.h" +#include "../PrintConfig.hpp" + +namespace Slic3r { + +extern void run_post_process_scripts(const std::string &path, const PrintConfig &config); + +} // namespace Slic3r + +#endif /* slic3r_GCode_PostProcessor_hpp_ */ diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 651513c62..03034cfdc 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -1331,8 +1331,15 @@ std::string Print::output_filepath(const std::string &path) const return path; } -void Print::print_to_png(const std::string &dirpath) +void Print::export_png(const std::string &dirpath) { + size_t idx = 0; + for (PrintObject *obj : m_objects) { + obj->slice(); + this->set_status(int(floor(idx * 100. / m_objects.size() + 0.5)), "Slicing..."); + ++ idx; + } + this->set_status(90, "Exporting zipped archive..."); print_to(*this, dirpath, float(m_config.bed_size_x.value), @@ -1341,6 +1348,7 @@ void Print::print_to_png(const std::string &dirpath) int(m_config.pixel_height.value), float(m_config.exp_time.value), float(m_config.exp_time_first.value)); + this->set_status(100, "Done."); } // Returns extruder this eec should be printed with, according to PrintRegion config diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 106640c4d..8999f27d7 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -368,7 +368,7 @@ public: void process(); void export_gcode(const std::string &path_template, GCodePreviewData *preview_data); // SLA export, temporary. - void print_to_png(const std::string &dirpath); + void export_png(const std::string &dirpath); // methods for handling state bool is_step_done(PrintStep step) const { return m_state.is_done(step); } diff --git a/xs/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/xs/src/slic3r/GUI/BackgroundSlicingProcess.cpp index 2f88b25ca..338db3010 100644 --- a/xs/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/xs/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -7,6 +7,7 @@ // Print now includes tbb, and tbb includes Windows. This breaks compilation of wxWidgets if included before wx. #include "../../libslic3r/Print.hpp" +#include "../../libslic3r/GCode/PostProcessor.hpp" //#undef NDEBUG #include @@ -59,9 +60,12 @@ void BackgroundSlicingProcess::thread_proc() if (! m_print->canceled()) { wxQueueEvent(GUI::g_wxPlater, new wxCommandEvent(m_event_sliced_id)); m_print->export_gcode(m_temp_output_path, m_gcode_preview_data); - if (! m_print->canceled() && ! m_output_path.empty() && - copy_file(m_temp_output_path, m_output_path) != 0) - throw std::runtime_error("Copying of the temporary G-code to the output G-code failed"); + if (! m_print->canceled() && ! m_output_path.empty()) { + if (copy_file(m_temp_output_path, m_output_path) != 0) + throw std::runtime_error("Copying of the temporary G-code to the output G-code failed"); + m_print->set_status(95, "Running post-processing scripts"); + run_post_process_scripts(m_output_path, m_print->config()); + } } } catch (CanceledException &ex) { // Canceled, this is all right. diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index e5ab22e8e..7ce858aec 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -611,13 +611,13 @@ void open_preferences_dialog(int event_preferences) dlg->ShowModal(); } -void create_preset_tabs(bool no_controller, int event_value_change, int event_presets_changed) +void create_preset_tabs(int event_value_change, int event_presets_changed) { update_label_colours_from_appconfig(); - add_created_tab(new TabPrint (g_wxTabPanel, no_controller), event_value_change, event_presets_changed); - add_created_tab(new TabFilament (g_wxTabPanel, no_controller), event_value_change, event_presets_changed); - add_created_tab(new TabSLAMaterial (g_wxTabPanel, no_controller), event_value_change, event_presets_changed); - add_created_tab(new TabPrinter (g_wxTabPanel, no_controller), event_value_change, event_presets_changed); + add_created_tab(new TabPrint (g_wxTabPanel), event_value_change, event_presets_changed); + add_created_tab(new TabFilament (g_wxTabPanel), event_value_change, event_presets_changed); + add_created_tab(new TabSLAMaterial (g_wxTabPanel), event_value_change, event_presets_changed); + add_created_tab(new TabPrinter (g_wxTabPanel), event_value_change, event_presets_changed); } std::vector preset_tabs = { diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 7105b8b4e..05ed580a3 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -165,7 +165,7 @@ extern void config_wizard(int run_reason); extern void open_preferences_dialog(int event_preferences); // Create a new preset tab (print, filament and printer), -void create_preset_tabs(bool no_controller, int event_value_change, int event_presets_changed); +void create_preset_tabs(int event_value_change, int event_presets_changed); TabIface* get_preset_tab_iface(char *name); // add it at the end of the tab panel. diff --git a/xs/src/slic3r/GUI/Preferences.cpp b/xs/src/slic3r/GUI/Preferences.cpp index 2500afa13..89a8ead92 100644 --- a/xs/src/slic3r/GUI/Preferences.cpp +++ b/xs/src/slic3r/GUI/Preferences.cpp @@ -71,14 +71,6 @@ void PreferencesDialog::build() option = Option (def, "preset_update"); m_optgroup->append_single_option_line(option); - def.label = L("Disable USB/serial connection"); - def.type = coBool; - def.tooltip = L("Disable communication with the printer over a serial / USB cable. " - "This simplifies the user interface in case the printer is never attached to the computer."); - def.default_value = new ConfigOptionBool{ app_config->get("no_controller")[0] == '1' }; // 1; - option = Option (def,"no_controller"); - m_optgroup->append_single_option_line(option); - def.label = L("Suppress \" - default - \" presets"); def.type = coBool; def.tooltip = L("Suppress \" - default - \" presets in the Print / Filament / Printer " @@ -118,8 +110,7 @@ void PreferencesDialog::build() void PreferencesDialog::accept() { - if (m_values.find("no_controller") != m_values.end()|| - m_values.find("no_defaults") != m_values.end()|| + if (m_values.find("no_defaults") != m_values.end()|| m_values.find("use_legacy_opengl")!= m_values.end()) { warning_catcher(this, _(L("You need to restart Slic3r to make the changes effective."))); } diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 5daf2784d..83b834219 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -1528,6 +1528,7 @@ void TabPrinter::build_fff() }; +#if 0 if (!m_no_controller) { optgroup = page->new_optgroup(_(L("USB/Serial connection"))); @@ -1572,6 +1573,7 @@ void TabPrinter::build_fff() line.append_widget(serial_test); optgroup->append_line(line); } +#endif optgroup = page->new_optgroup(_(L("Printer Host upload"))); @@ -1745,8 +1747,10 @@ void TabPrinter::build_fff() build_extruder_pages(); +#if 0 if (!m_no_controller) update_serial_ports(); +#endif } void TabPrinter::build_sla() diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index a1214465e..e4e37d4eb 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -170,7 +170,6 @@ protected: std::vector m_pages; bool m_disable_tree_sel_changed_event; bool m_show_incompatible_presets; - bool m_no_controller; std::vector m_reload_dependent_tabs = {}; enum OptStatus { osSystemValue = 1, osInitValue = 2 }; @@ -199,8 +198,8 @@ public: public: Tab() {} - Tab(wxNotebook* parent, const wxString& title, const char* name, bool no_controller) : - m_parent(parent), m_title(title), m_name(name), m_no_controller(no_controller) { + Tab(wxNotebook* parent, const wxString& title, const char* name) : + m_parent(parent), m_title(title), m_name(name) { Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL, name); get_tabs_list().push_back(this); } @@ -282,8 +281,8 @@ class TabPrint : public Tab { public: TabPrint() {} - TabPrint(wxNotebook* parent, bool no_controller) : - Tab(parent, _(L("Print Settings")), "print", no_controller) {} + TabPrint(wxNotebook* parent) : + Tab(parent, _(L("Print Settings")), "print") {} ~TabPrint(){} ogStaticText* m_recommended_thin_wall_thickness_description_line; @@ -302,8 +301,8 @@ class TabFilament : public Tab ogStaticText* m_cooling_description_line; public: TabFilament() {} - TabFilament(wxNotebook* parent, bool no_controller) : - Tab(parent, _(L("Filament Settings")), "filament", no_controller) {} + TabFilament(wxNotebook* parent) : + Tab(parent, _(L("Filament Settings")), "filament") {} ~TabFilament(){} void build() override; @@ -335,7 +334,7 @@ public: PrinterTechnology m_printer_technology = ptFFF; TabPrinter() {} - TabPrinter(wxNotebook* parent, bool no_controller) : Tab(parent, _(L("Printer Settings")), "printer", no_controller) {} + TabPrinter(wxNotebook* parent) : Tab(parent, _(L("Printer Settings")), "printer") {} ~TabPrinter(){} void build() override; @@ -357,8 +356,8 @@ class TabSLAMaterial : public Tab { public: TabSLAMaterial() {} - TabSLAMaterial(wxNotebook* parent, bool no_controller) : - Tab(parent, _(L("SLA Material Settings")), "sla_material", no_controller) {} + TabSLAMaterial(wxNotebook* parent) : + Tab(parent, _(L("SLA Material Settings")), "sla_material") {} ~TabSLAMaterial(){} void build() override; diff --git a/xs/xsp/GUI.xsp b/xs/xsp/GUI.xsp index 3aee4035e..6700a4765 100644 --- a/xs/xsp/GUI.xsp +++ b/xs/xsp/GUI.xsp @@ -50,8 +50,8 @@ void set_plater(SV *ui) void add_menus(SV *ui, int event_preferences_changed, int event_language_change) %code%{ Slic3r::GUI::add_menus((wxMenuBar*)wxPli_sv_2_object(aTHX_ ui, "Wx::MenuBar"), event_preferences_changed, event_language_change); %}; -void create_preset_tabs(bool no_controller, int event_value_change, int event_presets_changed) - %code%{ Slic3r::GUI::create_preset_tabs(no_controller, event_value_change, event_presets_changed); %}; +void create_preset_tabs(int event_value_change, int event_presets_changed) + %code%{ Slic3r::GUI::create_preset_tabs(event_value_change, event_presets_changed); %}; void show_error_id(int id, std::string msg) %code%{ Slic3r::GUI::show_error_id(id, msg); %}; diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 3212d6538..f29cb52fc 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -151,8 +151,6 @@ _constant() } %}; - void print_to_png(std::string dirpath); - void add_model_object(ModelObject* model_object, int idx = -1); bool apply_config(DynamicPrintConfig* config) %code%{ RETVAL = THIS->apply_config(*config); %}; @@ -166,6 +164,7 @@ _constant() %}; Clone bounding_box(); Clone total_bounding_box(); + Clone size() %code%{ RETVAL = THIS->bounding_box().size(); %}; void set_callback_event(int evt) %code%{ %}; @@ -196,4 +195,11 @@ _constant() } %}; + void export_png(char *path) %code%{ + try { + THIS->export_png(path); + } catch (std::exception& e) { + croak(e.what()); + } + %}; };