Browse Source

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".

bubnikv 6 years ago
parent
commit
d934b63424

+ 0 - 1
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;

+ 0 - 5
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,

+ 1 - 6
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");

+ 0 - 69
lib/Slic3r/Print.pm

@@ -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;

+ 0 - 2
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};
     }

+ 2 - 0
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

+ 4 - 8
xs/src/libslic3r/GCode.cpp

@@ -13,6 +13,7 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/algorithm/string/find.hpp>
 #include <boost/foreach.hpp>
+#include <boost/filesystem.hpp>
 #include <boost/log/trivial.hpp>
 
 #include <boost/nowide/iostream.hpp>
@@ -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);
 

+ 55 - 0
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 <boost/process/system.hpp>
+
+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

+ 15 - 0
xs/src/libslic3r/GCode/PostProcessor.hpp

@@ -0,0 +1,15 @@
+#ifndef slic3r_GCode_PostProcessor_hpp_
+#define slic3r_GCode_PostProcessor_hpp_
+
+#include <string>
+
+#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_ */

+ 9 - 1
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<FilePrinterFormat::PNG>(*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

Some files were not shown because too many files changed in this diff