diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index e8323525f7..2286a12478 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -75,6 +75,54 @@ using namespace Slic3r; +/*typedef struct _error_message{ + int code; + std::string message; +}error_message;*/ + +#define CLI_SUCCESS 0 +#define CLI_ENVIRONMENT_ERROR -1 +#define CLI_INVALID_PARAMS -2 +#define CLI_FILE_NOTFOUND -3 +#define CLI_FILELIST_INVALID_ORDER -4 +#define CLI_CONFIG_FILE_ERROR -5 +#define CLI_DATA_FILE_ERROR -6 +#define CLI_INVALID_PRINTER_TECH -7 +#define CLI_UNSUPPORTED_OPERATION -8 + +#define CLI_COPY_OBJECTS_ERROR -9 +#define CLI_SCALE_TO_FIT_ERROR -10 +#define CLI_EXPORT_STL_ERROR -11 +#define CLI_EXPORT_OBJ_ERROR -12 +#define CLI_EXPORT_3MF_ERROR -13 + +#define CLI_NO_SUITABLE_OBJECTS -50 +#define CLI_VALIDATE_ERROR -51 +#define CLI_SLICING_ERROR -100 + + + +std::map cli_errors = { + {CLI_SUCCESS, "Success"}, + {CLI_ENVIRONMENT_ERROR, "Environment setup failed"}, + {CLI_INVALID_PARAMS, "Input param invalid"}, + {CLI_FILE_NOTFOUND, "Input file not found"}, + {CLI_FILELIST_INVALID_ORDER, "File list order invalid(please make sure 3mf in the first place)"}, + {CLI_CONFIG_FILE_ERROR, "Invalid config file, could not be parsed"}, + {CLI_DATA_FILE_ERROR, "Invalid model file, could not be loaded"}, + {CLI_INVALID_PRINTER_TECH, "Invalid printer technoledge"}, + {CLI_UNSUPPORTED_OPERATION, "Unsupported operation"}, + {CLI_COPY_OBJECTS_ERROR, "Copy objects error"}, + {CLI_SCALE_TO_FIT_ERROR, "Scale to fit error"}, + {CLI_EXPORT_STL_ERROR, "Export stl error"}, + {CLI_EXPORT_OBJ_ERROR, "Export obj error"}, + {CLI_EXPORT_3MF_ERROR, "Export 3mf error"}, + {CLI_NO_SUITABLE_OBJECTS, "Found no objects in print volume to slice"}, + {CLI_VALIDATE_ERROR, "Validate print error"}, + {CLI_SLICING_ERROR, "Slice error"} +}; + + static PrinterTechnology get_printer_technology(const DynamicConfig &config) { const ConfigOptionEnum *opt = config.option>("printer_technology"); @@ -85,7 +133,7 @@ static PrinterTechnology get_printer_technology(const DynamicConfig &config) #define flush_and_exit(ret) { boost::nowide::cout << __FUNCTION__ << " found error, exit" << std::endl;\ boost::nowide::cout.flush();\ boost::nowide::cerr.flush();\ - exit(ret);} + return(ret);} static void glfw_callback(int error_code, const char* description) { @@ -117,7 +165,7 @@ int CLI::run(int argc, char **argv) MessageBoxA(NULL, text.c_str(), caption.c_str(), MB_OK | MB_ICONERROR); #endif boost::nowide::cerr << text.c_str() << std::endl; - return 1; + return CLI_ENVIRONMENT_ERROR; } BOOST_LOG_TRIVIAL(info) << "Current BambuStudio Version "<< SLIC3R_VERSION << std::endl; @@ -140,7 +188,7 @@ int CLI::run(int argc, char **argv) if (!this->setup(argc, argv)) { boost::nowide::cerr << "setup params error" << std::endl; - return 1; + return CLI_INVALID_PARAMS; } BOOST_LOG_TRIVIAL(info) << "finished setup params, argc="<< argc << std::endl; std::string temp_path = wxFileName::GetTempDir().utf8_str().data(); @@ -227,7 +275,7 @@ int CLI::run(int argc, char **argv) for (auto const &file : load_configs) { if (! boost::filesystem::exists(file)) { boost::nowide::cerr << "can not find setting file: " << file << std::endl; - flush_and_exit(1); + flush_and_exit(CLI_FILE_NOTFOUND); } DynamicPrintConfig config; ConfigSubstitutions config_substitutions; @@ -239,12 +287,12 @@ int CLI::run(int argc, char **argv) config_substitutions = config.load_from_json(file, config_substitution_rule, key_values, reason); if (!reason.empty()) { BOOST_LOG_TRIVIAL(error) << "Can not load config from file "<serialize() << std::endl; } catch (std::exception &ex) { boost::nowide::cerr << "Loading setting file \"" << file << "\" failed: " << ex.what() << std::endl; - flush_and_exit(1); + flush_and_exit(CLI_CONFIG_FILE_ERROR); } if (! config_substitutions.empty()) { BOOST_LOG_TRIVIAL(info) << "Found legacy configuration values, substituted when loading " << file << ":\n"; @@ -262,7 +310,7 @@ int CLI::run(int argc, char **argv) if ((printer_technology != other_printer_technology)&&(other_printer_technology != ptUnknown)){ boost::nowide::cerr << "invalid printer_technology " <serialize() << std::endl; } catch (std::exception &ex) { boost::nowide::cerr << "Loading filament file \"" << file << "\" failed: " << ex.what() << std::endl; - flush_and_exit(1); + flush_and_exit(CLI_CONFIG_FILE_ERROR); } if (! config_substitutions.empty()) { BOOST_LOG_TRIVIAL(info) << "Found legacy configuration values, substituted when loading " << file << ":\n"; @@ -307,7 +355,7 @@ int CLI::run(int argc, char **argv) if ((printer_technology != other_printer_technology) && (other_printer_technology != ptUnknown)) { boost::nowide::cerr << "invalid printer_technology " < (m_print_config.option("filament_settings_id", true)); ConfigOptionStrings *opt_filament_settings_src = static_cast(config.option("filament_settings_id", false)); @@ -339,7 +387,7 @@ int CLI::run(int argc, char **argv) if (source_opt == nullptr) { // The key was not found in the source config, therefore it will not be initialized! boost::nowide::cerr << "can not found option " <def(). // This is only possible if other is of DynamicConfig type. boost::nowide::cerr << "can not create option " <(opt); const ConfigOptionVectorBase* opt_vec_src = static_cast(source_opt); @@ -426,7 +474,7 @@ int CLI::run(int argc, char **argv) for (const std::string& file : m_input_files) { if (!boost::filesystem::exists(file)) { boost::nowide::cerr << "No such file: " << file << std::endl; - flush_and_exit(1); + flush_and_exit(CLI_FILE_NOTFOUND); } Model model; //BBS: add plate related logic @@ -455,7 +503,7 @@ int CLI::run(int argc, char **argv) if (!first_file) { BOOST_LOG_TRIVIAL(info) << "The BBL 3mf file should be placed at the first position, filename=" << file << "\n"; - flush_and_exit(1); + flush_and_exit(CLI_FILELIST_INVALID_ORDER); } BOOST_LOG_TRIVIAL(info) << "the first file is a 3mf, got plate count:" << plate_data.size() << "\n"; need_arrange = false; @@ -490,7 +538,7 @@ int CLI::run(int argc, char **argv) } if ((printer_technology != other_printer_technology) && (other_printer_technology != ptUnknown)) { boost::nowide::cerr << "invalid printer_technology " <(opt_key)->value; if (opt.x() <= 0 || opt.y() <= 0 || opt.z() <= 0) { boost::nowide::cerr << "--scale-to-fit requires a positive volume" << std::endl; - flush_and_exit(1); + flush_and_exit(CLI_SCALE_TO_FIT_ERROR); } for (auto &model : m_models) for (auto &o : model.objects) @@ -836,7 +884,7 @@ int CLI::run(int argc, char **argv) // model.repair(); } else { boost::nowide::cerr << "error: option not implemented yet: " << opt_key << std::endl; - flush_and_exit(1); + flush_and_exit(CLI_UNSUPPORTED_OPERATION); } } @@ -1017,12 +1065,12 @@ int CLI::run(int argc, char **argv) for (auto &model : m_models) model.add_default_instances(); if (! this->export_models(IO::STL)) - flush_and_exit(1); - } else if (opt_key == "export_obj") { + flush_and_exit(CLI_EXPORT_STL_ERROR); + } else if (opt_key == "expor1t_obj") { for (auto &model : m_models) model.add_default_instances(); if (! this->export_models(IO::OBJ)) - flush_and_exit(1); + flush_and_exit(CLI_EXPORT_OBJ_ERROR); }/* else if (opt_key == "export_amf") { if (! this->export_models(IO::AMF)) return 1; @@ -1136,8 +1184,8 @@ int CLI::run(int argc, char **argv) BOOST_LOG_TRIVIAL(info) << "got warnings: "<< warning.string << std::endl; if (print->empty()) { - BOOST_LOG_TRIVIAL(info) << "Nothing to print for " << outfile << " . Either the print is empty or no object is fully inside the print volume." << std::endl; - flush_and_exit(1); + BOOST_LOG_TRIVIAL(error) << "Nothing to be sliced, Either the print is empty or no object is fully inside the print volume." << std::endl; + flush_and_exit(CLI_NO_SUITABLE_OBJECTS); } else try { @@ -1180,7 +1228,7 @@ int CLI::run(int argc, char **argv) BOOST_LOG_TRIVIAL(info) << "found slicing or export error for partplate "<export_project(&m_models[0], export_3mf_file, plate_data_list, project_presets, thumbnails, calibration_thumbnails, plate_bboxes, &m_print_config)) { release_PlateData_list(plate_data_list); - flush_and_exit(1); + flush_and_exit(CLI_EXPORT_3MF_ERROR); } release_PlateData_list(plate_data_list); for (unsigned int i = 0; i < thumbnails.size(); i++)