diff --git a/resources/profiles/BBL/cli_config.json b/resources/profiles/BBL/cli_config.json new file mode 100644 index 000000000..8fd179ecc --- /dev/null +++ b/resources/profiles/BBL/cli_config.json @@ -0,0 +1,21 @@ +{ + "printer": { + "Bambu Lab A1": { + "cli_safe_acceleration_e": "0,0", + "cli_safe_acceleration_extruding": "0,0", + "cli_safe_acceleration_retracting": "0,0", + "cli_safe_acceleration_travel":"6000,6000", + "cli_safe_acceleration_x": "6000,6000", + "cli_safe_acceleration_y": "6000,6000", + "cli_safe_acceleration_z": "0,0", + "cli_safe_jerk_e": "0,0", + "cli_safe_jerk_x": "0,0", + "cli_safe_jerk_y": "0,0", + "cli_safe_jerk_z": "0,0", + "cli_safe_speed_e": "0,0", + "cli_safe_speed_x": "0,0", + "cli_safe_speed_y": "0,0", + "cli_safe_speed_z": "0,0" + } + } +} diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index 2556fbf23..427fd1cd2 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -1053,7 +1053,7 @@ int CLI::run(int argc, char **argv) Semver file_version; std::map orients_requirement; std::vector project_presets; - std::string new_printer_name, current_printer_name, new_process_name, current_process_name, current_printer_system_name, current_process_system_name, new_process_system_name, new_printer_system_name, printer_model_id;//, printer_inherits, print_inherits; + std::string new_printer_name, current_printer_name, new_process_name, current_process_name, current_printer_system_name, current_process_system_name, new_process_system_name, new_printer_system_name, printer_model_id, printer_model;//, printer_inherits, print_inherits; std::vector upward_compatible_printers, new_print_compatible_printers, current_print_compatible_printers, current_different_settings; std::vector current_filaments_name, current_filaments_system_name, current_inherits_group; DynamicPrintConfig load_process_config, load_machine_config; @@ -1584,7 +1584,7 @@ int CLI::run(int argc, char **argv) config.set("printer_settings_id", new_printer_name, true); //get printer_model_id - std::string printer_model = config.option("printer_model", true)->value; + printer_model = config.option("printer_model", true)->value; if (!printer_model.empty()) { std::string printer_model_path = resources_dir() + "/profiles/BBL/machine_full/"+printer_model+".json"; if (boost::filesystem::exists(printer_model_path)) @@ -1779,7 +1779,7 @@ int CLI::run(int argc, char **argv) config.set("printer_settings_id", config_name, true); //get printer_model_id - std::string printer_model = config.option("printer_model", true)->value; + printer_model = config.option("printer_model", true)->value; if (!printer_model.empty()) { std::string printer_model_path = resources_dir() + "/profiles/BBL/machine_full/"+printer_model+".json"; if (boost::filesystem::exists(printer_model_path)) @@ -1860,7 +1860,7 @@ int CLI::run(int argc, char **argv) config.set("printer_settings_id", config_name, true); //get printer_model_id - std::string printer_model = config.option("printer_model", true)->value; + printer_model = config.option("printer_model", true)->value; if (!printer_model.empty()) { std::string printer_model_path = resources_dir() + "/profiles/BBL/machine_full/"+printer_model+".json"; if (boost::filesystem::exists(printer_model_path)) @@ -2259,6 +2259,70 @@ int CLI::run(int argc, char **argv) else { ret = update_full_config(m_print_config, load_machine_config, different_keys_set, true); BOOST_LOG_TRIVIAL(info) << boost::format("load a new printer, update all the keys, different_settings: %1%")%different_settings[filament_count+1]; + if (new_printer_name != current_printer_name) + { + //printer safe check + BOOST_LOG_TRIVIAL(info) << boost::format("check printer cli safe params, current_printer_name %1%, new_printer_name %2%, printer_model %3%")%current_printer_name %new_printer_name %printer_model; + std::map printer_params; + std::string cli_config_file = resources_dir() + "/profiles/BBL/cli_config.json"; + boost::filesystem::path directory_path(cli_config_file); + + BOOST_LOG_TRIVIAL(info) << boost::format("line %1% , will parse file %2%")%__LINE__ % cli_config_file; + if (!fs::exists(directory_path)) { + BOOST_LOG_TRIVIAL(warning) << boost::format("file %1% not exist.")%cli_config_file; + } + else { + try { + json root_json; + boost::nowide::ifstream ifs(cli_config_file); + ifs >> root_json; + ifs.close(); + + if (root_json.contains("printer")) { + json printer_json = root_json["printer"]; + if (!printer_model.empty() && printer_json.contains(printer_model)) { + json new_printer_json = printer_json[printer_model]; + printer_params = new_printer_json.get>(); + + for (auto param_iter = printer_params.begin(); param_iter != printer_params.end(); param_iter++) + { + std::string key = param_iter->first; + //replace "cli_safe" with "machine_max" + key.replace(0, 8, "machine_max"); + + ConfigOptionFloats* option = m_print_config.option(key); + if (option) { + //de-serialize the values from param_iter->second, and do the compare here + unsigned int array_count = option->size(); + ConfigOptionFloats new_option; + new_option.deserialize(param_iter->second); + unsigned int new_array_count = new_option.size(); + for (unsigned int index = 0; index < array_count; index++) + { + if ((index < new_array_count) && new_option.values[index] != 0.f && (new_option.values[index] < option->values[index])) + { + BOOST_LOG_TRIVIAL(info) << boost::format("set key %1% index %2%, from %3% to %4%") % key %index %option->values[index] % new_option.values[index]; + option->values[index] = new_option.values[index]; + } + } + } + else + BOOST_LOG_TRIVIAL(warning) << boost::format("can not find key %1% in config") %key; + } + } + else { + BOOST_LOG_TRIVIAL(info) << boost::format("can not find key %1% in the file")%printer_model; + } + } + else { + BOOST_LOG_TRIVIAL(warning) << boost::format("can not find key printer in the file"); + } + } + catch (std::exception &err) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse file "<(m_print_config.option("wipe_tower_x"))->get_at(plate_to_slice-1); - float y = dynamic_cast(m_print_config.option("wipe_tower_y"))->get_at(plate_to_slice-1); + float x; + float y; + if (duplicate_count > 0) { + auto printer_structure_opt = m_print_config.option>("printer_structure"); + x = WIPE_TOWER_DEFAULT_X_POS; + y = WIPE_TOWER_DEFAULT_Y_POS; + if (printer_structure_opt && printer_structure_opt->value == PrinterStructure::psI3) { + x = I3_WIPE_TOWER_DEFAULT_X_POS; + y = I3_WIPE_TOWER_DEFAULT_Y_POS; + } + } + else { + //keep the original + x = dynamic_cast(m_print_config.option("wipe_tower_x"))->get_at(plate_to_slice-1); + y = dynamic_cast(m_print_config.option("wipe_tower_y"))->get_at(plate_to_slice-1); + } float w = dynamic_cast(m_print_config.option("prime_tower_width"))->value; float a = dynamic_cast(m_print_config.option("wipe_tower_rotation_angle"))->value; float v = dynamic_cast(m_print_config.option("prime_volume"))->value; @@ -3684,6 +3776,20 @@ int CLI::run(int argc, char **argv) x = (float)plate_width - w - margin - wp_brim_width; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("arrange wipe_tower: exceeds the border, change x to %1%, plate_width=%2%")%y %plate_width; } + if (x < margin) { + x = margin; + } + if (y < margin) { + y = margin; + } + //update wipe_tower_x and wipe_tower_y + ConfigOptionFloat wt_x_opt(x); + ConfigOptionFloat wt_y_opt(y); + ConfigOptionFloats* wipe_x_option = m_print_config.option("wipe_tower_x", true); + ConfigOptionFloats* wipe_y_option = m_print_config.option("wipe_tower_y", true); + + wipe_x_option->set_at(&wt_x_opt, plate_to_slice-1, 0); + wipe_y_option->set_at(&wt_y_opt, plate_to_slice-1, 0); ArrangePolygon wipe_tower_ap;