Help for the FFF / SLA command line parameters.

Removed the cli parameter from most options as it is derived
from the option key. Options without CLI parameter are now marked
with cli = nocli.
This commit is contained in:
bubnikv 2019-03-13 19:17:26 +01:00
parent 2c779746dd
commit c7ba650097
6 changed files with 185 additions and 376 deletions

View file

@ -3,6 +3,7 @@
#include <assert.h>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <exception> // std::runtime_error
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
@ -190,16 +191,26 @@ bool unescape_strings_cstyle(const std::string &str, std::vector<std::string> &o
}
}
std::vector<std::string> ConfigOptionDef::cli_args() const
std::vector<std::string> ConfigOptionDef::cli_args(const std::string &key) const
{
std::string cli = this->cli.substr(0, this->cli.find("="));
boost::trim_right_if(cli, boost::is_any_of("!"));
std::vector<std::string> args;
boost::split(args, cli, boost::is_any_of("|"));
std::vector<std::string> args;
if (this->cli != ConfigOptionDef::nocli) {
std::string cli = this->cli.substr(0, this->cli.find("="));
boost::trim_right_if(cli, boost::is_any_of("!"));
if (cli.empty()) {
// Add the key
std::string opt = key;
boost::replace_all(opt, "_", "-");
args.emplace_back(std::move(opt));
} else
boost::split(args, cli, boost::is_any_of("|"));
}
return args;
}
std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults) const
std::string ConfigOptionDef::nocli = "~~~noCLI";
std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults, std::function<bool(const ConfigOptionDef &)> filter) const
{
// prepare a function for wrapping text
auto wrap = [](std::string text, size_t line_length) -> std::string {
@ -227,7 +238,8 @@ std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults) c
std::set<std::string> categories;
for (const auto& opt : this->options) {
const ConfigOptionDef& def = opt.second;
categories.insert(def.category);
if (filter(def))
categories.insert(def.category);
}
for (auto category : categories) {
@ -239,55 +251,57 @@ std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults) c
for (const auto& opt : this->options) {
const ConfigOptionDef& def = opt.second;
if (def.category != category) continue;
if (def.category != category || def.cli == ConfigOptionDef::nocli || !filter(def))
continue;
if (!def.cli.empty()) {
// get all possible variations: --foo, --foobar, -f...
auto cli_args = def.cli_args();
for (auto& arg : cli_args) {
arg.insert(0, (arg.size() == 1) ? "-" : "--");
if (def.type == coFloat || def.type == coInt || def.type == coFloatOrPercent
|| def.type == coFloats || def.type == coInts) {
arg += " N";
} else if (def.type == coPoint) {
arg += " X,Y";
} else if (def.type == coPoint3) {
arg += " X,Y,Z";
} else if (def.type == coString || def.type == coStrings) {
arg += " ABCD";
}
// get all possible variations: --foo, --foobar, -f...
std::vector<std::string> cli_args = def.cli_args(opt.first);
if (cli_args.empty())
continue;
for (auto& arg : cli_args) {
arg.insert(0, (arg.size() == 1) ? "-" : "--");
if (def.type == coFloat || def.type == coInt || def.type == coFloatOrPercent
|| def.type == coFloats || def.type == coInts) {
arg += " N";
} else if (def.type == coPoint) {
arg += " X,Y";
} else if (def.type == coPoint3) {
arg += " X,Y,Z";
} else if (def.type == coString || def.type == coStrings) {
arg += " ABCD";
}
}
// left: command line options
const std::string cli = boost::algorithm::join(cli_args, ", ");
out << " " << std::left << std::setw(20) << cli;
// left: command line options
const std::string cli = boost::algorithm::join(cli_args, ", ");
out << " " << std::left << std::setw(20) << cli;
// right: option description
std::string descr = def.tooltip;
if (show_defaults && def.default_value != nullptr && def.type != coBool
&& (def.type != coString || !def.default_value->serialize().empty())) {
descr += " (";
if (!def.sidetext.empty()) {
descr += def.sidetext + ", ";
} else if (!def.enum_values.empty()) {
descr += boost::algorithm::join(def.enum_values, ", ") + "; ";
}
descr += "default: " + def.default_value->serialize() + ")";
// right: option description
std::string descr = def.tooltip;
if (show_defaults && def.default_value != nullptr && def.type != coBool
&& (def.type != coString || !def.default_value->serialize().empty())) {
descr += " (";
if (!def.sidetext.empty()) {
descr += def.sidetext + ", ";
} else if (!def.enum_values.empty()) {
descr += boost::algorithm::join(def.enum_values, ", ") + "; ";
}
descr += "default: " + def.default_value->serialize() + ")";
}
// wrap lines of description
descr = wrap(descr, 80);
std::vector<std::string> lines;
boost::split(lines, descr, boost::is_any_of("\n"));
// wrap lines of description
descr = wrap(descr, 80);
std::vector<std::string> lines;
boost::split(lines, descr, boost::is_any_of("\n"));
// if command line options are too long, print description in new line
for (size_t i = 0; i < lines.size(); ++i) {
if (i == 0 && cli.size() > 19)
out << std::endl;
if (i > 0 || cli.size() > 19)
out << std::string(21, ' ');
out << lines[i] << std::endl;
}
// if command line options are too long, print description in new line
for (size_t i = 0; i < lines.size(); ++i) {
if (i == 0 && cli.size() > 19)
out << std::endl;
if (i > 0 || cli.size() > 19)
out << std::string(21, ' ');
out << lines[i] << std::endl;
}
}
}
@ -657,7 +671,7 @@ bool DynamicConfig::read_cli(int argc, char** argv, t_config_option_keys* extra,
// cache the CLI option => opt_key mapping
std::map<std::string,std::string> opts;
for (const auto &oit : this->def()->options)
for (auto t : oit.second.cli_args())
for (auto t : oit.second.cli_args(oit.first))
opts[t] = oit.first;
bool parse_options = true;

View file

@ -6,6 +6,7 @@
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <stdexcept>
#include <string>
@ -88,6 +89,18 @@ enum ConfigOptionMode {
comExpert
};
enum PrinterTechnology
{
// Fused Filament Fabrication
ptFFF,
// Stereolitography
ptSLA,
// Unknown, useful for command line processing
ptUnknown,
// Any technology, useful for parameters compatible with both ptFFF and ptSLA
ptAny
};
// A generic value of a configuration option.
class ConfigOption {
public:
@ -1014,6 +1027,8 @@ public:
// The full label is shown, when adding an override parameter for an object or a modified object.
std::string label;
std::string full_label;
// With which printer technology is this configuration valid?
PrinterTechnology printer_technology = ptUnknown;
// Category of a configuration field, from the GUI perspective.
// One of: "Layers and Perimeters", "Infill", "Support material", "Speed", "Extruders", "Advanced", "Extrusion Width"
std::string category;
@ -1065,8 +1080,12 @@ public:
return false;
}
/// Returns the alternative CLI arguments for the given option.
std::vector<std::string> cli_args() const;
// Returns the alternative CLI arguments for the given option.
// If there are no cli arguments defined, use the key and replace underscores with dashes.
std::vector<std::string> cli_args(const std::string &key) const;
// Assign this key to cli to disable CLI for this option.
static std::string nocli;
};
// Map from a config option name to its definition.
@ -1102,7 +1121,9 @@ public:
}
/// Iterate through all of the CLI options and write them to a stream.
std::ostream& print_cli_help(std::ostream& out, bool show_defaults) const;
std::ostream& print_cli_help(
std::ostream& out, bool show_defaults,
std::function<bool(const ConfigOptionDef &)> filter = [](const ConfigOptionDef &){ return true; }) const;
protected:
ConfigOptionDef* add(const t_config_option_key &opt_key, ConfigOptionType type) {

File diff suppressed because it is too large Load diff

View file

@ -24,16 +24,6 @@
namespace Slic3r {
enum PrinterTechnology
{
// Fused Filament Fabrication
ptFFF,
// Stereolitography
ptSLA,
// Unknown, useful for command line processing
ptUnknown,
};
enum GCodeFlavor {
gcfRepRap, gcfRepetier, gcfTeacup, gcfMakerWare, gcfMarlin, gcfSailfish, gcfMach3, gcfMachinekit,
gcfSmoothie, gcfNoExtrusion,

View file

@ -309,7 +309,11 @@ int CLI::run(int argc, char **argv)
if (opt_key == "help") {
this->print_help();
} else if (opt_key == "help_options") {
this->print_help(true);
this->print_help(true, ptAny);
} else if (opt_key == "help_fff") {
this->print_help(true, ptFFF);
} else if (opt_key == "help_sla") {
this->print_help(true, ptSLA);
} else if (opt_key == "save") {
//FIXME check for mixing the FFF / SLA parameters.
// or better save fff_print_config vs. sla_print_config
@ -546,7 +550,7 @@ bool CLI::setup(int argc, char **argv)
return true;
}
void CLI::print_help(bool include_print_options) const
void CLI::print_help(bool include_print_options, PrinterTechnology printer_technology) const
{
boost::nowide::cout
<< "Slic3r Prusa Edition " << SLIC3R_BUILD << std::endl
@ -568,11 +572,12 @@ void CLI::print_help(bool include_print_options) const
if (include_print_options) {
boost::nowide::cout << std::endl;
print_config_def.print_cli_help(boost::nowide::cout, true);
print_config_def.print_cli_help(boost::nowide::cout, true, [printer_technology](const ConfigOptionDef &def)
{ return printer_technology == ptAny || def.printer_technology == ptAny || printer_technology == def.printer_technology; });
} else {
boost::nowide::cout
<< std::endl
<< "Run --help-options to see the full listing of print/G-code options." << std::endl;
<< "Run --help-options / --help-fff / --help-sla to see the full listing of print options." << std::endl;
}
}

View file

@ -33,7 +33,7 @@ private:
bool setup(int argc, char **argv);
/// Prints usage of the CLI.
void print_help(bool include_print_options = false) const;
void print_help(bool include_print_options = false, PrinterTechnology printer_technology = ptAny) const;
/// Exports loaded models to a file of the specified format, according to the options affecting output filename.
bool export_models(IO::ExportFormat format);