diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index 28787a0df..6650c64ca 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -477,6 +477,43 @@ const float bed3d_ax3s_default_stem_length = 25.0f; const float bed3d_ax3s_default_tip_radius = 2.5f * bed3d_ax3s_default_stem_radius; const float bed3d_ax3s_default_tip_length = 5.0f; +static int load_key_values_from_json(const std::string &file, std::map& key_values) +{ + json j; + CNumericLocalesSetter locales_setter; + + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__<< ": begin to parse "<> j; + ifs.close(); + + //parse the json elements + for (auto it = j.begin(); it != j.end(); it++) { + if (boost::iequals(it.key(),BBL_JSON_KEY_MODEL_ID)) { + key_values.emplace(BBL_JSON_KEY_MODEL_ID, it.value()); + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) { + key_values.emplace(BBL_JSON_KEY_NAME, it.value()); + } + } + } + catch (const std::ifstream::failure &err) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "< 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_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_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; @@ -1025,9 +1062,26 @@ int CLI::run(int argc, char **argv) new_printer_config_is_system = false; } config.set("printer_settings_id", new_printer_name, true); + + //get printer_model_id + std::string 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)) + { + std::map key_values; + + load_key_values_from_json(printer_model_path, key_values); + if (key_values.find("model_id") != key_values.end()) { + printer_model_id = key_values["model_id"]; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(":%1%, load printer_model_id %2% from current printer model %3%")%__LINE__ %printer_model_id %printer_model; + } + } + } + //printer_inherits = config.option("inherits", true)->value; load_machine_config = std::move(config); - BOOST_LOG_TRIVIAL(info) << boost::format("loaded machine config %1%, type %2%, name %3%, inherits %4%")%file %config_name %config_from % new_printer_system_name; + BOOST_LOG_TRIVIAL(info) << boost::format("loaded machine config %1%, type %2%, name %3%, inherits %4%, printer_model_id %5%")%file %config_name %config_from % new_printer_system_name %printer_model_id; } else if (config_type == "process") { if (!new_process_name.empty()) { @@ -1191,6 +1245,23 @@ int CLI::run(int argc, char **argv) if (new_printer_name.empty() && !current_printer_system_name.empty()) { config.set("printer_settings_id", config_name, true); + + //get printer_model_id + std::string 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)) + { + std::map key_values; + + load_key_values_from_json(printer_model_path, key_values); + if (key_values.find("model_id") != key_values.end()) { + printer_model_id = key_values["model_id"]; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(":%1%, load printer_model_id %2% from current printer model %3%")%__LINE__ %printer_model_id %printer_model; + } + } + } + load_machine_config = std::move(config); } } @@ -1253,6 +1324,23 @@ int CLI::run(int argc, char **argv) } upward_compatible_printers = config.option("upward_compatible_machine", true)->values; config.set("printer_settings_id", config_name, true); + + //get printer_model_id + std::string 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)) + { + std::map key_values; + + load_key_values_from_json(printer_model_path, key_values); + if (key_values.find("model_id") != key_values.end()) { + printer_model_id = key_values["model_id"]; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(":%1%, load printer_model_id %2% from current printer model %3%")%__LINE__ %printer_model_id %printer_model; + } + } + } + load_machine_config = std::move(config); } } @@ -3542,12 +3630,20 @@ int CLI::run(int argc, char **argv) auto* filament_types = dynamic_cast(m_print_config.option("filament_type")); const ConfigOptionStrings* filament_color = dynamic_cast(m_print_config.option("filament_colour")); //auto* filament_id = dynamic_cast(m_print_config.option("filament_ids")); + const ConfigOptionFloats* nozzle_diameter_option = dynamic_cast(m_print_config.option("nozzle_diameter")); + std::string nozzle_diameter_str; + if (nozzle_diameter_option) + nozzle_diameter_str = nozzle_diameter_option->serialize(); for (int i = 0; i < plate_data_list.size(); i++) { PlateData *plate_data = plate_data_list[i]; bool skip_this_plate = ((plate_to_slice != 0) && (plate_to_slice != (i + 1)))?true:false; plate_data->skipped_objects = plate_skipped_objects[i]; + if (!printer_model_id.empty()) + plate_data->printer_model_id = printer_model_id; + if (!nozzle_diameter_str.empty()) + plate_data->nozzle_diameters = nozzle_diameter_str; for (auto it = plate_data->slice_filaments_info.begin(); it != plate_data->slice_filaments_info.end(); it++) { //it->filament_id = filament_id?filament_id->get_at(it->id):"unknown"; diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index 902bfe4fe..304d31ff5 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -284,6 +284,8 @@ static constexpr const char* IDENTIFYID_ATTR = "identify_id"; static constexpr const char* PLATERID_ATTR = "plater_id"; static constexpr const char* PLATER_NAME_ATTR = "plater_name"; static constexpr const char* PLATE_IDX_ATTR = "index"; +static constexpr const char* PRINTER_MODEL_ID_ATTR = "printer_model_id"; +static constexpr const char* NOZZLE_DIAMETERS_ATTR = "nozzle_diameters"; static constexpr const char* SLICE_PREDICTION_ATTR = "prediction"; static constexpr const char* SLICE_WEIGHT_ATTR = "weight"; static constexpr const char* TIMELAPSE_TYPE_ATTR = "timelapse_type"; @@ -7367,6 +7369,8 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) break; } } + stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << PRINTER_MODEL_ID_ATTR << "\" " << VALUE_ATTR << "=\"" << plate_data->printer_model_id << "\"/>\n"; + stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << NOZZLE_DIAMETERS_ATTR << "\" " << VALUE_ATTR << "=\"" << plate_data->nozzle_diameters << "\"/>\n"; stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << TIMELAPSE_TYPE_ATTR << "\" " << VALUE_ATTR << "=\"" << timelapse_type << "\"/>\n"; //stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << TIMELAPSE_ERROR_CODE_ATTR << "\" " << VALUE_ATTR << "=\"" << plate_data->timelapse_warning_code << "\"/>\n"; stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << SLICE_PREDICTION_ATTR << "\" " << VALUE_ATTR << "=\"" << plate_data->get_gcode_prediction_str() << "\"/>\n"; diff --git a/src/libslic3r/Format/bbs_3mf.hpp b/src/libslic3r/Format/bbs_3mf.hpp index ed7e440c9..af6994b77 100644 --- a/src/libslic3r/Format/bbs_3mf.hpp +++ b/src/libslic3r/Format/bbs_3mf.hpp @@ -69,6 +69,8 @@ struct PlateData int plate_index; std::vector> objects_and_instances; std::map> obj_inst_map; + std::string printer_model_id; + std::string nozzle_diameters; std::string gcode_file; std::string gcode_file_md5; std::string thumbnail_file; @@ -231,7 +233,7 @@ extern bool load_bbs_3mf(const char* path, DynamicPrintConfig* config, ConfigSub extern std::string bbs_3mf_get_thumbnail(const char * path); -extern bool load_gcode_3mf_from_stream(std::istream & data, DynamicPrintConfig* config, Model* model, PlateDataPtrs* plate_data_list, +extern bool load_gcode_3mf_from_stream(std::istream & data, DynamicPrintConfig* config, Model* model, PlateDataPtrs* plate_data_list, Semver* file_version); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 76f018e8a..c5670a10d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -10768,9 +10768,17 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy // get type and color for platedata auto* filament_color = dynamic_cast(cfg.option("filament_colour")); + auto* nozzle_diameter_option = dynamic_cast(cfg.option("nozzle_diameter")); + std::string nozzle_diameter_str; + if (nozzle_diameter_option) + nozzle_diameter_str = nozzle_diameter_option->serialize(); + + std::string printer_model_id = preset_bundle.printers.get_edited_preset().get_printer_type(&preset_bundle); for (int i = 0; i < plate_data_list.size(); i++) { PlateData *plate_data = plate_data_list[i]; + plate_data->printer_model_id = printer_model_id; + plate_data->nozzle_diameters = nozzle_diameter_str; for (auto it = plate_data->slice_filaments_info.begin(); it != plate_data->slice_filaments_info.end(); it++) { std::string display_filament_type; it->type = cfg.get_filament_type(display_filament_type, it->id);