ENH: CLI: add logic to save metadata into 3mf from CLI

JIRA: no jira
Change-Id: I7f96c2ab9671ec1c0115e90f6d64230b8170eb38
(cherry picked from commit 3d2d6e23ba318a2b331a62e320f8ca199168f1f5)
This commit is contained in:
lane.wei 2024-06-17 20:21:13 +08:00
parent 168d088e45
commit 179acd12d1
5 changed files with 50 additions and 2 deletions

View File

@ -1223,6 +1223,15 @@ int CLI::run(int argc, char **argv)
DynamicPrintConfig load_process_config, load_machine_config; DynamicPrintConfig load_process_config, load_machine_config;
bool new_process_config_is_system = true, new_printer_config_is_system = true; bool new_process_config_is_system = true, new_printer_config_is_system = true;
std::string pipe_name, makerlab_name, makerlab_version, different_process_setting; std::string pipe_name, makerlab_name, makerlab_version, different_process_setting;
const std::vector<std::string> &metadata_name = m_config.option<ConfigOptionStrings>("metadata_name", true)->values;
const std::vector<std::string> &metadata_value = m_config.option<ConfigOptionStrings>("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. // Read input file(s) if any.
BOOST_LOG_TRIVIAL(info) << "Will start to read model file now, file count :" << m_input_files.size() << "\n"; 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; model.mk_version = makerlab_version;
BOOST_LOG_TRIVIAL(info) << boost::format("mk_name %1%, mk_version %2%")%makerlab_name %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, 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)) calibration_thumbnails, plate_bboxes, &m_print_config, minimum_save, plate_to_slice - 1))
{ {

View File

@ -6250,6 +6250,13 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
metadata_item_map[BBL_MAKERLAB_VERSION_TAG] = xml_escape(model.mk_version); metadata_item_map[BBL_MAKERLAB_VERSION_TAG] = xml_escape(model.mk_version);
BOOST_LOG_TRIVIAL(info) << "saved mk_version " << 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 // store metadata info
for (auto item : metadata_item_map) { for (auto item : metadata_item_map) {

View File

@ -92,6 +92,8 @@ Model& Model::assign_copy(const Model &rhs)
this->mk_name = rhs.mk_name; this->mk_name = rhs.mk_name;
this->mk_version = rhs.mk_version; this->mk_version = rhs.mk_version;
this->md_name = rhs.md_name;
this->md_value = rhs.md_value;
return *this; return *this;
} }
@ -124,6 +126,8 @@ Model& Model::assign_copy(Model &&rhs)
this->stl_design_country = rhs.stl_design_country; this->stl_design_country = rhs.stl_design_country;
this->mk_name = rhs.mk_name; this->mk_name = rhs.mk_name;
this->mk_version = rhs.mk_version; 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->backup_path = std::move(rhs.backup_path);
this->object_backup_id_map = std::move(rhs.object_backup_id_map); this->object_backup_id_map = std::move(rhs.object_backup_id_map);
this->next_object_backup_id = rhs.next_object_backup_id; 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; profile_info = model.profile_info;
mk_name = model.mk_name; mk_name = model.mk_name;
mk_version = model.mk_version; mk_version = model.mk_version;
md_name = model.md_name;
md_value = model.md_value;
model.design_info.reset(); model.design_info.reset();
model.model_info.reset(); model.model_info.reset();
model.profile_info.reset(); model.profile_info.reset();

View File

@ -1525,6 +1525,8 @@ public:
//makerlab information //makerlab information
std::string mk_name; std::string mk_name;
std::string mk_version; std::string mk_version;
std::vector<std::string> md_name;
std::vector<std::string> md_value;
void SetDesigner(std::string designer, std::string designer_user_id) { void SetDesigner(std::string designer, std::string designer_user_id) {
if (design_info == nullptr) { if (design_info == nullptr) {

View File

@ -5803,6 +5803,18 @@ CLIMiscConfigDef::CLIMiscConfigDef()
def->cli_params = "version"; def->cli_params = "version";
def->set_default_value(new ConfigOptionString()); 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 = this->add("allow_newer_file", coBool);
def->label = "Allow 3mf with newer version to be sliced"; def->label = "Allow 3mf with newer version to be sliced";
def->tooltip = "Allow 3mf with newer version to be sliced"; def->tooltip = "Allow 3mf with newer version to be sliced";