mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-01 03:52:04 +08:00
Added primitive --help that reads DynamicPrintConfig options directly.
Should slice and generate gcode for STL files now.
This commit is contained in:
parent
d0721cee2b
commit
e06d33180c
@ -3,6 +3,7 @@
|
||||
#include "IO.hpp"
|
||||
#include "Model.hpp"
|
||||
#include "SLAPrint.hpp"
|
||||
#include "Print.hpp"
|
||||
#include "TriangleMesh.hpp"
|
||||
#include "libslic3r.h"
|
||||
#include <cstdio>
|
||||
@ -44,10 +45,12 @@ main(int argc, char **argv)
|
||||
DynamicPrintConfig print_config;
|
||||
|
||||
#ifdef USE_WX
|
||||
GUI::App *gui = new GUI::App();
|
||||
if (cli_config.gui) {
|
||||
GUI::App *gui = new GUI::App();
|
||||
|
||||
GUI::App::SetInstance(gui);
|
||||
wxEntry(argc, argv);
|
||||
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 <aar@cpan.org> - 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;
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
@ -1943,6 +1944,24 @@ CLIConfigDef::CLIConfigDef()
|
||||
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";
|
||||
def->tooltip = "Write information about the model to the console.";
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user