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".
This commit is contained in:
bubnikv
2018-09-17 12:01:02 +02:00
parent bb7f504296
commit d934b63424
19 changed files with 124 additions and 126 deletions

View File

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

View File

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

View File

@@ -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_ */

View File

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

View File

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