diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 27c64000b..bced1a123 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -1,6 +1,7 @@ #include "slic3r.hpp" #include "Geometry.hpp" #include "IO.hpp" +#include "Log.hpp" #include "SLAPrint.hpp" #include "Print.hpp" #include "SimplePrint.hpp" @@ -43,59 +44,53 @@ int CLI::run(int argc, char **argv) { this->config_def.merge(cli_misc_config_def); this->config_def.merge(print_config_def); this->config.def = &this->config_def; - std::cerr<<"Configs merged"<config.read_cli(argc, argv, &this->input_files, &opt_order)) { this->print_help(); - return 1; + exit(EXIT_FAILURE); } // parse actions and transform options for (auto const &opt_key : opt_order) { if (cli_actions_config_def.has(opt_key)) this->actions.push_back(opt_key); if (cli_transform_config_def.has(opt_key)) this->transforms.push_back(opt_key); } - try{ // load config files supplied via --load for (auto const &file : config.getStrings("load")) { - if (!boost::filesystem::exists(file)) { - if (config.getBool("ignore_nonexistent_file", false)) { - continue; - } else { - boost::nowide::cerr << "No such file: " << file << std::endl; - exit(1); + try{ + if (!boost::filesystem::exists(file)) { + if (config.getBool("ignore_nonexistent_file", false)) { + continue; + } else { + throw std::invalid_argument("No such file"); + } } - } - - DynamicPrintConfig c; - try { + DynamicPrintConfig c; c.load(file); - } catch (std::exception &e) { - boost::nowide::cerr << "Error while reading config file: " << e.what() << std::endl; - exit(1); - } - c.normalize(); - this->print_config.apply(c); - } - }catch (...){ - std::cerr<<"Exception in 'load' processing "<print_config.apply(c); + } catch (std::exception &e){ + Slic3r::Log::error("CLI") << "Error with the config file '" << file << "': " << e.what() <print_config.apply(config, true); this->print_config.normalize(); - std::cerr<<"Print_config normalized" << std::endl; + Slic3r::Log::debug("CLI") << "Print config normalized" << std::endl; // create a static (full) print config to be used in our logic this->full_print_config.apply(this->print_config); - std::cerr<<"Full_print_config created"<full_print_config.validate(); - } catch (InvalidOptionException &e) { - boost::nowide::cerr << e.what() << std::endl; - return 1; + } catch (std::exception &e) { + Slic3r::Log::error("CLI") << "Config validation error: "<< e.what() << std::endl; + exit(EXIT_FAILURE); } - std::cerr<<"Config validated"<models.push_back(model); } @@ -197,8 +190,8 @@ int CLI::run(int argc, char **argv) { } else if (opt_key == "scale_to_fit") { const auto opt = config.opt(opt_key); if (!opt->is_positive_volume()) { - boost::nowide::cerr << "--scale-to-fit requires a positive volume" << std::endl; - return 1; + Slic3r::Log::error("CLI") << "--scale-to-fit requires a positive volume" << std::endl; + exit(EXIT_FAILURE); } for (auto &model : this->models) for (auto &o : model.objects) @@ -264,8 +257,8 @@ int CLI::run(int argc, char **argv) { for (auto &model : this->models) model.repair(); } else { - boost::nowide::cerr << "error: option not implemented yet: " << opt_key << std::endl; - return 1; + Slic3r::Log::error("CLI") << " option not implemented yet: " << opt_key << std::endl; + exit(EXIT_FAILURE); } } @@ -300,7 +293,7 @@ int CLI::run(int argc, char **argv) { } else if (opt_key == "export_3mf") { this->export_models(IO::TMF); } else if (opt_key == "export_sla") { - boost::nowide::cerr << "--export-sla is not implemented yet" << std::endl; + Slic3r::Log::error("CLI") << "--export-sla is not implemented yet" << std::endl; } else if (opt_key == "export_sla_svg") { for (const Model &model : this->models) { SLAPrint print(&model); // initialize print with model @@ -325,7 +318,7 @@ int CLI::run(int argc, char **argv) { print.center = !this->config.has("center") && !this->config.has("align_xy") && !this->config.getBool("dont_arrange"); - std::cerr<<"Arrange: "<(clock_::now() - t0).count() }; @@ -353,8 +346,8 @@ int CLI::run(int argc, char **argv) { << " (" << print.total_extruded_volume()/1000 << "cm3)" << std::endl; } } else { - boost::nowide::cerr << "error: option not supported yet: " << opt_key << std::endl; - return 1; + Slic3r::Log::error("CLI") << "error: option not supported yet: " << opt_key << std::endl; + exit(EXIT_FAILURE); } } @@ -366,7 +359,7 @@ int CLI::run(int argc, char **argv) { GUI::App::SetInstance(gui); wxEntry(argc, argv); #else - std::cout << "GUI support has not been built." << "\n"; + Slic3r::Log::error("CLI") << "GUI support has not been built." << "\n"; #endif } diff --git a/xs/src/libslic3r/ConfigBase.cpp b/xs/src/libslic3r/ConfigBase.cpp index 44655873f..705575882 100644 --- a/xs/src/libslic3r/ConfigBase.cpp +++ b/xs/src/libslic3r/ConfigBase.cpp @@ -372,33 +372,31 @@ void ConfigBase::apply_only(const ConfigBase &other, const t_config_option_keys &opt_keys, bool ignore_nonexistent, bool default_nonexistent) { // loop through options and apply them for (const t_config_option_key &opt_key : opt_keys) { - try{ - ConfigOption* my_opt = this->option(opt_key, true); - if (opt_key.size() == 0) continue; - if (my_opt == NULL) { - if (ignore_nonexistent == false) throw UnknownOptionException(opt_key); - continue; - } - if (default_nonexistent && !other.has(opt_key)) { - auto* def_opt = this->def->get(opt_key).default_value->clone(); - // not the most efficient way, but easier than casting pointers to subclasses - bool res = my_opt->deserialize( def_opt->serialize() ); - if (!res) { - std::string error = "Unexpected failure when deserializing serialized value for " + opt_key; - CONFESS(error.c_str()); - } - continue; - } - - // not the most efficient way, but easier than casting pointers to subclasses - bool res = my_opt->deserialize( other.option(opt_key)->serialize() ); - if (!res) { - std::string error = "Unexpected failure when deserializing serialized value for " + opt_key; - CONFESS(error.c_str()); - } + try{ + ConfigOption* my_opt = this->option(opt_key, true); + if (opt_key.size() == 0) continue; + if (my_opt == NULL) { + if (ignore_nonexistent == false) throw UnknownOptionException(opt_key); + continue; + } + if (default_nonexistent && !other.has(opt_key)) { + auto* def_opt = this->def->get(opt_key).default_value->clone(); + // not the most efficient way, but easier than casting pointers to subclasses + bool res = my_opt->deserialize( def_opt->serialize() ); + if (!res) { + std::string error = "Unexpected failure when deserializing serialized value for " + opt_key; + CONFESS(error.c_str()); + } + continue; + } + // not the most efficient way, but easier than casting pointers to subclasses + bool res = my_opt->deserialize( other.option(opt_key)->serialize() ); + if (!res) { + std::string error = "Unexpected failure when deserializing serialized value for " + opt_key; + CONFESS(error.c_str()); + } } catch ( UnknownOptionException & e ){ - - // std::cerr<value.x = boost::lexical_cast(tokens[0]); this->value.y = boost::lexical_cast(tokens[1]); } catch (boost::bad_lexical_cast &e){ - std::cout << "Config option deserialisation error of ["<value.y = boost::lexical_cast(tokens[1]); this->value.z = boost::lexical_cast(tokens[2]); } catch (boost::bad_lexical_cast &e){ - std::cout << "Config option deserialisation error of ["<values.push_back(point); } } catch (boost::bad_lexical_cast &e) { - printf("%s\n", e.what()); + Slic3r::Log::error("Config") << "Deserialisation error of [" << str << "] " << e.what() << " (expected list of points) "; return false; } - return true; } diff --git a/xs/src/libslic3r/ConfigBase.hpp b/xs/src/libslic3r/ConfigBase.hpp index df9497f56..e07b8d52c 100644 --- a/xs/src/libslic3r/ConfigBase.hpp +++ b/xs/src/libslic3r/ConfigBase.hpp @@ -1,9 +1,6 @@ #ifndef slic3r_ConfigBase_hpp_ #define slic3r_ConfigBase_hpp_ -#include -#include - #include #include #include @@ -43,16 +40,22 @@ class ConfigOptionException : public std::exception { s += this->opt_key; return s.c_str(); } - }; + class UnknownOptionException : public ConfigOptionException { using ConfigOptionException::ConfigOptionException; }; + class InvalidOptionException : public ConfigOptionException { using ConfigOptionException::ConfigOptionException; - + public: + virtual const char* what() const noexcept { + std::string s("Invalid value for option: "); + s += this->opt_key; + return s.c_str(); + } }; /// Specialization of std::exception to indicate that an unsupported accessor was called on a config option. diff --git a/xs/src/libslic3r/PrintGCode.cpp b/xs/src/libslic3r/PrintGCode.cpp index 9adfadcb5..daad3a610 100644 --- a/xs/src/libslic3r/PrintGCode.cpp +++ b/xs/src/libslic3r/PrintGCode.cpp @@ -1,6 +1,6 @@ #include "PrintGCode.hpp" #include "PrintConfig.hpp" - +#include "Log.hpp" #include #include @@ -406,7 +406,10 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) for (auto region_id = 0U; region_id < _print.regions.size(); ++region_id) { const PrintRegion* region = _print.get_region(region_id); if( region_id >= layer->region_count() ){ - std::cerr<<"Layer #"<id()<<" doesn't have region "<region_count()<<" regions."<id() + << " doesn't have region " << region_id << ". " + << " The layer has " << layer->region_count() << " regions." + << std::endl; break; } const LayerRegion* layerm = layer->get_region(region_id); diff --git a/xs/src/libslic3r/SupportMaterial.cpp b/xs/src/libslic3r/SupportMaterial.cpp index 9c3912f76..6d40c6176 100644 --- a/xs/src/libslic3r/SupportMaterial.cpp +++ b/xs/src/libslic3r/SupportMaterial.cpp @@ -1,4 +1,5 @@ #include "SupportMaterial.hpp" +#include "Log.hpp" namespace Slic3r { @@ -71,7 +72,8 @@ SupportMaterial::generate(PrintObject *object) //bugfix: do not try to generate overhang if there is no contact area if( contact.empty() ){ - std::cerr<<"Empty contact_areas of SupportMaterial for object ["<model_object()->name<<"]"<model_object()->name << "]" << std::endl; return; }