From 179acd12d1420792bbfcfabc02d22150af38704c Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Mon, 17 Jun 2024 20:21:13 +0800 Subject: [PATCH] ENH: CLI: add logic to save metadata into 3mf from CLI JIRA: no jira Change-Id: I7f96c2ab9671ec1c0115e90f6d64230b8170eb38 (cherry picked from commit 3d2d6e23ba318a2b331a62e320f8ca199168f1f5) --- src/BambuStudio.cpp | 21 +++++++++++++++++++++ src/libslic3r/Format/bbs_3mf.cpp | 7 +++++++ src/libslic3r/Model.cpp | 8 +++++++- src/libslic3r/Model.hpp | 4 +++- src/libslic3r/PrintConfig.cpp | 12 ++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index 0b0ac8223..7558048d0 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -1223,6 +1223,15 @@ int CLI::run(int argc, char **argv) DynamicPrintConfig load_process_config, load_machine_config; bool new_process_config_is_system = true, new_printer_config_is_system = true; std::string pipe_name, makerlab_name, makerlab_version, different_process_setting; + const std::vector &metadata_name = m_config.option("metadata_name", true)->values; + const std::vector &metadata_value = m_config.option("metadata_value", true)->values; + + if (metadata_name.size() != metadata_value.size()) + { + BOOST_LOG_TRIVIAL(error) << boost::format("metadata_name should be the same size with metadata_value"); + record_exit_reson(outfile_dir, CLI_INVALID_PARAMS, 0, cli_errors[CLI_INVALID_PARAMS], sliced_info); + flush_and_exit(CLI_INVALID_PARAMS); + } // Read input file(s) if any. BOOST_LOG_TRIVIAL(info) << "Will start to read model file now, file count :" << m_input_files.size() << "\n"; @@ -5863,6 +5872,18 @@ int CLI::run(int argc, char **argv) model.mk_version = makerlab_version; BOOST_LOG_TRIVIAL(info) << boost::format("mk_name %1%, mk_version %2%")%makerlab_name %makerlab_version; } + + if (!metadata_name.empty()) { + Model &model = m_models[0]; + + model.md_value = metadata_value; + model.md_name = metadata_name; + for (unsigned int i = 0; i < metadata_name.size(); i++) + { + BOOST_LOG_TRIVIAL(info) << boost::format("index %1% metadata_name %2%, metadata_value %3%")%i %metadata_name[i] %metadata_value[i]; + } + } + if (!this->export_project(&m_models[0], export_3mf_file, plate_data_list, project_presets, thumbnails, no_light_thumbnails, top_thumbnails, pick_thumbnails, calibration_thumbnails, plate_bboxes, &m_print_config, minimum_save, plate_to_slice - 1)) { diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index e7269b019..ca2043e1f 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -6250,6 +6250,13 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) metadata_item_map[BBL_MAKERLAB_VERSION_TAG] = xml_escape(model.mk_version); BOOST_LOG_TRIVIAL(info) << "saved mk_version " << model.mk_version; } + if (!model.md_name.empty()) { + for (unsigned int i = 0; i < model.md_name.size(); i++) + { + BOOST_LOG_TRIVIAL(info) << boost::format("saved metadata_name %1%, metadata_value %2%") %model.md_name[i] %model.md_value[i]; + metadata_item_map[model.md_name[i]] = xml_escape(model.md_value[i]); + } + } // store metadata info for (auto item : metadata_item_map) { diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index eb376e6fc..be893e040 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -92,6 +92,8 @@ Model& Model::assign_copy(const Model &rhs) this->mk_name = rhs.mk_name; this->mk_version = rhs.mk_version; + this->md_name = rhs.md_name; + this->md_value = rhs.md_value; return *this; } @@ -124,6 +126,8 @@ Model& Model::assign_copy(Model &&rhs) this->stl_design_country = rhs.stl_design_country; this->mk_name = rhs.mk_name; this->mk_version = rhs.mk_version; + this->md_name = rhs.md_name; + this->md_value = rhs.md_value; this->backup_path = std::move(rhs.backup_path); this->object_backup_id_map = std::move(rhs.object_backup_id_map); this->next_object_backup_id = rhs.next_object_backup_id; @@ -962,6 +966,8 @@ void Model::load_from(Model& model) profile_info = model.profile_info; mk_name = model.mk_name; mk_version = model.mk_version; + md_name = model.md_name; + md_value = model.md_value; model.design_info.reset(); model.model_info.reset(); model.profile_info.reset(); @@ -3497,7 +3503,7 @@ bool Model::obj_import_vertex_color_deal(const std::vector &verte case _3_SAME_COLOR: { std::string result; get_real_filament_id(filament_id0, result); - volume->mmu_segmentation_facets.set_triangle_from_string(i, result); + volume->mmu_segmentation_facets.set_triangle_from_string(i, result); break; } case _3_DIFF_COLOR: { diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index e484fb024..02dbdce8c 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -413,7 +413,7 @@ public: bool is_mm_painted() const; // This object may have a varying layer height by painting or by a table. // Even if true is returned, the layer height profile may be "flat" with no difference to default layering. - bool has_custom_layering() const + bool has_custom_layering() const { return ! this->layer_config_ranges.empty() || ! this->layer_height_profile.empty(); } ModelInstance* add_instance(); @@ -1525,6 +1525,8 @@ public: //makerlab information std::string mk_name; std::string mk_version; + std::vector md_name; + std::vector md_value; void SetDesigner(std::string designer, std::string designer_user_id) { if (design_info == nullptr) { diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index adb4aa3cd..425fda941 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -5803,6 +5803,18 @@ CLIMiscConfigDef::CLIMiscConfigDef() def->cli_params = "version"; def->set_default_value(new ConfigOptionString()); + def = this->add("metadata_name", coStrings); + def->label = "metadata name list"; + def->tooltip = "matadata name list added into 3mf"; + def->cli_params = "\"name1;name2;...\""; + def->set_default_value(new ConfigOptionStrings()); + + def = this->add("metadata_value", coStrings); + def->label = "metadata value list"; + def->tooltip = "matadata value list added into 3mf"; + def->cli_params = "\"value1;value2;...\""; + def->set_default_value(new ConfigOptionStrings()); + def = this->add("allow_newer_file", coBool); def->label = "Allow 3mf with newer version to be sliced"; def->tooltip = "Allow 3mf with newer version to be sliced";