From d934b63424ab76ddcd8a87f272838df611dfcd0c Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 17 Sep 2018 12:01:02 +0200 Subject: Removed Print.pm, ported execution of post processing scripts into C++ (WIP, waits for update of boost::system module on our build server) Removed other mention of the "Controller". --- xs/CMakeLists.txt | 2 + xs/src/libslic3r/GCode.cpp | 12 ++---- xs/src/libslic3r/GCode/PostProcessor.cpp | 55 ++++++++++++++++++++++++++ xs/src/libslic3r/GCode/PostProcessor.hpp | 15 +++++++ xs/src/libslic3r/Print.cpp | 10 ++++- xs/src/libslic3r/Print.hpp | 2 +- xs/src/slic3r/GUI/BackgroundSlicingProcess.cpp | 10 +++-- xs/src/slic3r/GUI/GUI.cpp | 10 ++--- xs/src/slic3r/GUI/GUI.hpp | 2 +- xs/src/slic3r/GUI/Preferences.cpp | 11 +----- xs/src/slic3r/GUI/Tab.cpp | 4 ++ xs/src/slic3r/GUI/Tab.hpp | 19 +++++---- xs/xsp/GUI.xsp | 4 +- xs/xsp/Print.xsp | 10 ++++- 14 files changed, 123 insertions(+), 43 deletions(-) create mode 100644 xs/src/libslic3r/GCode/PostProcessor.cpp create mode 100644 xs/src/libslic3r/GCode/PostProcessor.hpp (limited to 'xs') 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()); + } + %}; }; -- cgit v1.2.3