Resurrected --dont-arrange command line parameter,

fixed command line print parameter validation.
This commit is contained in:
bubnikv 2018-09-25 09:55:15 +02:00
parent a9f52955a0
commit c3dc562ab0
4 changed files with 49 additions and 21 deletions

View File

@ -812,6 +812,14 @@ public:
bool operator==(const ConfigOptionEnum<T> &rhs) const { return this->value == rhs.value; } bool operator==(const ConfigOptionEnum<T> &rhs) const { return this->value == rhs.value; }
int getInt() const override { return (int)this->value; } int getInt() const override { return (int)this->value; }
bool operator==(const ConfigOption &rhs) const override
{
if (rhs.type() != this->type())
throw std::runtime_error("ConfigOptionEnum<T>: Comparing incompatible types");
// rhs could be of the following type: ConfigOptionEnumGeneric or ConfigOptionEnum<T>
return this->value == (T)rhs.getInt();
}
void set(const ConfigOption *rhs) override { void set(const ConfigOption *rhs) override {
if (rhs->type() != this->type()) if (rhs->type() != this->type())
throw std::runtime_error("ConfigOptionEnum<T>: Assigning an incompatible type"); throw std::runtime_error("ConfigOptionEnum<T>: Assigning an incompatible type");
@ -887,6 +895,14 @@ public:
ConfigOptionEnumGeneric& operator=(const ConfigOption *opt) { this->set(opt); return *this; } ConfigOptionEnumGeneric& operator=(const ConfigOption *opt) { this->set(opt); return *this; }
bool operator==(const ConfigOptionEnumGeneric &rhs) const { return this->value == rhs.value; } bool operator==(const ConfigOptionEnumGeneric &rhs) const { return this->value == rhs.value; }
bool operator==(const ConfigOption &rhs) const override
{
if (rhs.type() != this->type())
throw std::runtime_error("ConfigOptionEnumGeneric: Comparing incompatible types");
// rhs could be of the following type: ConfigOptionEnumGeneric or ConfigOptionEnum<T>
return this->value == rhs.getInt();
}
void set(const ConfigOption *rhs) override { void set(const ConfigOption *rhs) override {
if (rhs->type() != this->type()) if (rhs->type() != this->type())
throw std::runtime_error("ConfigOptionEnumGeneric: Assigning an incompatible type"); throw std::runtime_error("ConfigOptionEnumGeneric: Assigning an incompatible type");

View File

@ -2612,6 +2612,13 @@ CLIConfigDef::CLIConfigDef()
def->cli = "cut"; def->cli = "cut";
def->default_value = new ConfigOptionFloat(0); def->default_value = new ConfigOptionFloat(0);
def = this->add("dont_arrange", coBool);
def->label = L("Dont arrange");
def->tooltip = L("Don't arrange the objects on the build plate. The model coordinates "
"define the absolute positions on the build plate. "
"The option --center will be ignored.");
def->default_value = new ConfigOptionBool(false);
def = this->add("datadir", coString); def = this->add("datadir", coString);
def->label = L("User data directory"); def->label = L("User data directory");
def->tooltip = L("Load and store settings at the given directory. " def->tooltip = L("Load and store settings at the given directory. "
@ -2707,10 +2714,10 @@ CLIConfigDef::CLIConfigDef()
def->default_value = new ConfigOptionPoint3(Pointf3(0,0,0)); def->default_value = new ConfigOptionPoint3(Pointf3(0,0,0));
*/ */
def = this->add("center", coPoint); def = this->add("print_center", coPoint);
def->label = L("Center"); def->label = L("Print center");
def->tooltip = L("Center the print around the given center (default: 100, 100)."); def->tooltip = L("Center the print around the given center (default: 100, 100).");
def->cli = "center"; def->cli = "print-center";
def->default_value = new ConfigOptionPoint(Vec2d(100,100)); def->default_value = new ConfigOptionPoint(Vec2d(100,100));
} }

View File

@ -983,6 +983,7 @@ class CLIConfig : public virtual ConfigBase, public StaticConfig
public: public:
ConfigOptionFloat cut; ConfigOptionFloat cut;
ConfigOptionString datadir; ConfigOptionString datadir;
ConfigOptionBool dont_arrange;
ConfigOptionBool export_3mf; ConfigOptionBool export_3mf;
ConfigOptionBool gui; ConfigOptionBool gui;
ConfigOptionBool info; ConfigOptionBool info;
@ -990,13 +991,13 @@ public:
ConfigOptionStrings load; ConfigOptionStrings load;
ConfigOptionBool no_gui; ConfigOptionBool no_gui;
ConfigOptionString output; ConfigOptionString output;
ConfigOptionPoint print_center;
ConfigOptionFloat rotate; ConfigOptionFloat rotate;
ConfigOptionFloat rotate_x; ConfigOptionFloat rotate_x;
ConfigOptionFloat rotate_y; ConfigOptionFloat rotate_y;
ConfigOptionString save; ConfigOptionString save;
ConfigOptionFloat scale; ConfigOptionFloat scale;
// ConfigOptionPoint3 scale_to_fit; // ConfigOptionPoint3 scale_to_fit;
ConfigOptionPoint center;
ConfigOptionBool slice; ConfigOptionBool slice;
CLIConfig() : ConfigBase(), StaticConfig() CLIConfig() : ConfigBase(), StaticConfig()
@ -1011,6 +1012,7 @@ public:
{ {
OPT_PTR(cut); OPT_PTR(cut);
OPT_PTR(datadir); OPT_PTR(datadir);
OPT_PTR(dont_arrange);
OPT_PTR(export_3mf); OPT_PTR(export_3mf);
OPT_PTR(gui); OPT_PTR(gui);
OPT_PTR(help); OPT_PTR(help);
@ -1018,6 +1020,7 @@ public:
OPT_PTR(load); OPT_PTR(load);
OPT_PTR(no_gui); OPT_PTR(no_gui);
OPT_PTR(output); OPT_PTR(output);
OPT_PTR(print_center);
OPT_PTR(rotate); OPT_PTR(rotate);
OPT_PTR(rotate_x); OPT_PTR(rotate_x);
OPT_PTR(rotate_y); OPT_PTR(rotate_y);

View File

@ -139,6 +139,11 @@ int main(int argc, char **argv)
if (! cli_config.save.value.empty()) if (! cli_config.save.value.empty())
print_config.save(cli_config.save.value); print_config.save(cli_config.save.value);
if (cli_config.help) {
printUsage();
return 0;
}
// read input file(s) if any // read input file(s) if any
std::vector<Model> models; std::vector<Model> models;
for (const t_config_option_key &file : input_files) { for (const t_config_option_key &file : input_files) {
@ -146,7 +151,6 @@ int main(int argc, char **argv)
boost::nowide::cerr << "No such file: " << file << std::endl; boost::nowide::cerr << "No such file: " << file << std::endl;
exit(1); exit(1);
} }
Model model; Model model;
try { try {
model = Model::read_from_file(file); model = Model::read_from_file(file);
@ -154,14 +158,11 @@ int main(int argc, char **argv)
boost::nowide::cerr << file << ": " << e.what() << std::endl; boost::nowide::cerr << file << ": " << e.what() << std::endl;
exit(1); exit(1);
} }
if (model.objects.empty()) { if (model.objects.empty()) {
boost::nowide::cerr << "Error: file is empty: " << file << std::endl; boost::nowide::cerr << "Error: file is empty: " << file << std::endl;
continue; continue;
} }
model.add_default_instances(); model.add_default_instances();
// apply command line transform options // apply command line transform options
for (ModelObject* o : model.objects) { for (ModelObject* o : model.objects) {
/* /*
@ -174,14 +175,9 @@ int main(int argc, char **argv)
o->rotate(Geometry::deg2rad(cli_config.rotate_y.value), Y); o->rotate(Geometry::deg2rad(cli_config.rotate_y.value), Y);
o->rotate(Geometry::deg2rad(cli_config.rotate.value), Z); o->rotate(Geometry::deg2rad(cli_config.rotate.value), Z);
} }
// TODO: handle --merge // TODO: handle --merge
models.push_back(model); models.push_back(model);
} }
if (cli_config.help) {
printUsage();
return 0;
}
for (Model &model : models) { for (Model &model : models) {
if (cli_config.info) { if (cli_config.info) {
@ -220,16 +216,22 @@ int main(int argc, char **argv)
} else if (cli_config.slice) { } else if (cli_config.slice) {
std::string outfile = cli_config.output.value; std::string outfile = cli_config.output.value;
Print print; Print print;
model.arrange_objects(print.config().min_object_distance()); if (! cli_config.dont_arrange) {
model.center_instances_around_point(cli_config.center); model.arrange_objects(print.config().min_object_distance());
if (outfile.empty()) outfile = model.objects.front()->input_file + ".gcode"; model.center_instances_around_point(cli_config.print_center);
print.apply_config(print_config); }
if (outfile.empty())
outfile = model.objects.front()->input_file + ".gcode";
for (auto* mo : model.objects) { for (auto* mo : model.objects) {
print.auto_assign_extruders(mo); print.auto_assign_extruders(mo);
print.add_model_object(mo); print.add_model_object(mo);
} }
print.validate(); print.apply_config(print_config);
print.export_gcode(outfile, nullptr); std::string err = print.validate();
if (err.empty())
print.export_gcode(outfile, nullptr);
else
std::cerr << err << "\n";
} else { } else {
boost::nowide::cerr << "error: command not supported" << std::endl; boost::nowide::cerr << "error: command not supported" << std::endl;
return 1; return 1;