From e06d33180c8fdd787b389cf492990a972b3b244c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 5 Aug 2018 20:44:46 -0500 Subject: [PATCH] Added primitive --help that reads DynamicPrintConfig options directly. Should slice and generate gcode for STL files now. --- src/slic3r.cpp | 36 ++++++++++++++++++++++++++---- xs/src/libslic3r/Print.cpp | 8 +++++++ xs/src/libslic3r/PrintConfig.cpp | 38 ++++++++++++++++++++++++++++++++ xs/src/libslic3r/PrintConfig.hpp | 9 ++++++++ 4 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 9fef04a6b..7f699d3c4 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -3,6 +3,7 @@ #include "IO.hpp" #include "Model.hpp" #include "SLAPrint.hpp" +#include "Print.hpp" #include "TriangleMesh.hpp" #include "libslic3r.h" #include @@ -44,10 +45,12 @@ main(int argc, char **argv) DynamicPrintConfig print_config; #ifdef USE_WX - GUI::App *gui = new GUI::App(); - - GUI::App::SetInstance(gui); - wxEntry(argc, argv); + if (cli_config.gui) { + GUI::App *gui = new GUI::App(); + + GUI::App::SetInstance(gui); + wxEntry(argc, argv); + } #endif // load config files supplied via --load for (const std::string &file : cli_config.load.values) { @@ -113,6 +116,14 @@ main(int argc, char **argv) // TODO: handle --merge models.push_back(model); } + if (cli_config.help) { + std::cout << "Slic3r " << SLIC3R_VERSION << " is a STL-to-GCODE translator for RepRap 3D printers" << "\n" + << "written by Alessandro Ranellucci - http://slic3r.org/ - https://github.com/slic3r/Slic3r" << "\n" + << "Git Version " << BUILD_COMMIT << "\n\n" + << "Usage: slic3r.pl [ OPTIONS ] [ file.stl ] [ file2.stl ] ..." << "\n"; + print_cli_options(boost::nowide::cout); + return 0; + } for (Model &model : models) { if (cli_config.info) { @@ -199,6 +210,23 @@ main(int argc, char **argv) IO::STL::write(*m, ss.str()); delete m; } + } else if (cli_config.slice) { + std::string outfile = cli_config.output.value; + Print print; + + model.arrange_objects(print.config.min_object_distance()); + model.center_instances_around_point(cli_config.center); + if (outfile.empty()) outfile = model.objects.front()->input_file + ".gcode"; + print.apply_config(print_config); + + for (auto* mo : model.objects) { + print.auto_assign_extruders(mo); + print.add_model_object(mo); + } + print.validate(); + + print.export_gcode(outfile); + } else { boost::nowide::cerr << "error: command not supported" << std::endl; return 1; diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 405962e70..5d997dfc6 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -717,6 +717,14 @@ Print::export_gcode(std::ostream& output, bool quiet) } +void +Print::export_gcode(const std::string& outfile, bool quiet) +{ + std::ofstream outstream(outfile); + this->export_gcode(outstream); +} + + bool Print::apply_config(config_ptr config) { // dereference the stored pointer and pass the resulting data to apply_config() diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index b170ce12b..860f24d38 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1605,6 +1605,7 @@ PrintConfigDef::PrintConfigDef() def->label = "Threads"; def->tooltip = "Threads are used to parallelize long-running tasks. Optimal threads number is slightly above the number of available cores/processors."; def->readonly = true; + def->cli = "threads=i"; def->min = 1; { unsigned int threads = boost::thread::hardware_concurrency(); @@ -1942,6 +1943,24 @@ CLIConfigDef::CLIConfigDef() def->tooltip = "Slice the model and export slices as 3MF."; def->cli = "export-3mf"; def->default_value = new ConfigOptionBool(false); + + def = this->add("slice", coBool); + def->label = "Slice"; + def->tooltip = "Slice the model and export gcode."; + def->cli = "slice"; + def->default_value = new ConfigOptionBool(false); + + def = this->add("help", coBool); + def->label = "Help"; + def->tooltip = "Show this help."; + def->cli = "help"; + def->default_value = new ConfigOptionBool(false); + + def = this->add("gui", coBool); + def->label = "Use GUI"; + def->tooltip = "Start the Slic3r GUI."; + def->cli = "gui"; + def->default_value = new ConfigOptionBool(false); def = this->add("info", coBool); def->label = "Output Model Info"; @@ -1996,8 +2015,27 @@ CLIConfigDef::CLIConfigDef() def->tooltip = "Scale to fit the given volume."; def->cli = "scale-to-fit"; def->default_value = new ConfigOptionPoint3(Pointf3(0,0,0)); + + def = this->add("center", coPoint3); + def->label = "Center"; + def->tooltip = "Center the print around the given center (default: 100, 100)."; + def->cli = "center"; + def->default_value = new ConfigOptionPoint(Pointf(100,100)); } const CLIConfigDef cli_config_def; +std::ostream& +print_cli_options(std::ostream& out) { + for (const auto& opt : print_config_def.options) { + out << "\t" << std::left << std::setw(40) << std::string("--") + opt.second.cli; + out << "\t" << opt.second.tooltip << "\n"; + if (opt.second.default_value != nullptr) + out << "\t" << std::setw(40) << " " << "\t" << " (default: " << opt.second.default_value->serialize() << ")"; + out << "\n"; + } + std::cerr << std::endl; + return out; +} + } diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index dac2a628a..5644bf3e5 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -659,7 +659,9 @@ class CLIConfig ConfigOptionBool export_pov; ConfigOptionBool export_svg; ConfigOptionBool export_3mf; + ConfigOptionBool gui; ConfigOptionBool info; + ConfigOptionBool help; ConfigOptionStrings load; ConfigOptionString output; ConfigOptionFloat rotate; @@ -668,6 +670,8 @@ class CLIConfig ConfigOptionString save; ConfigOptionFloat scale; ConfigOptionPoint3 scale_to_fit; + ConfigOptionPoint center; + ConfigOptionBool slice; ConfigOptionBool threads; CLIConfig() : ConfigBase(), StaticConfig() { @@ -684,6 +688,8 @@ class CLIConfig OPT_PTR(export_pov); OPT_PTR(export_svg); OPT_PTR(export_3mf); + OPT_PTR(gui); + OPT_PTR(help); OPT_PTR(info); OPT_PTR(load); OPT_PTR(output); @@ -693,12 +699,15 @@ class CLIConfig OPT_PTR(save); OPT_PTR(scale); OPT_PTR(scale_to_fit); + OPT_PTR(slice); OPT_PTR(threads); return NULL; }; }; +/// Iterate through all of the options and write them to a stream. +std::ostream& print_cli_options(std::ostream& out); } #endif