From d871339f0d30c06364f86e6bf5ade30a4f3603ce Mon Sep 17 00:00:00 2001 From: tao wang Date: Sun, 4 Feb 2024 16:24:06 +0800 Subject: [PATCH] ENH:STL tracking restricted area jira:[STUDIO-6155] Change-Id: I289c8b8aa8f62f0e5cc7004fb60437aa3337ca85 --- src/admesh/stl.h | 2 +- src/admesh/stlinit.cpp | 13 +++++-- src/libslic3r/Model.cpp | 3 ++ src/libslic3r/Model.hpp | 1 + src/slic3r/GUI/Jobs/PrintJob.cpp | 39 ++++++++++++++++--- src/slic3r/GUI/Plater.cpp | 65 ++++++++++++++++++++++---------- 6 files changed, 94 insertions(+), 29 deletions(-) diff --git a/src/admesh/stl.h b/src/admesh/stl.h index 259377796..94bca3c96 100644 --- a/src/admesh/stl.h +++ b/src/admesh/stl.h @@ -45,7 +45,7 @@ typedef Eigen::Matrix stl_triangle_vertex_indices static_assert(sizeof(stl_vertex) == 12, "size of stl_vertex incorrect"); static_assert(sizeof(stl_normal) == 12, "size of stl_normal incorrect"); -typedef std::function ImportstlProgressFn; +typedef std::function ImportstlProgressFn; typedef enum { eNormal, // normal face diff --git a/src/admesh/stlinit.cpp b/src/admesh/stlinit.cpp index ec044f87e..6037be9f9 100644 --- a/src/admesh/stlinit.cpp +++ b/src/admesh/stlinit.cpp @@ -45,6 +45,7 @@ extern void stl_internal_reverse_quads(char *buf, size_t cnt); const int LOAD_STL_UNIT_NUM = 5; static std::string model_id = ""; +static std::string country_code = ""; static FILE* stl_open_count_facets(stl_file *stl, const char *file) { @@ -153,6 +154,8 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first, Impor { if (stl->stats.type == binary) { fseek(fp, HEADER_SIZE, SEEK_SET); + model_id = ""; + country_code = ""; } else { rewind(fp); @@ -165,18 +168,22 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first, Impor // Extract the value after "MW" char version_str[16]; char model_id_str[128]; - int num_values = sscanf(mw_position + 3, "%s %s", version_str, model_id_str); - if (num_values == 2) { + char country_code_str[16]; + int num_values = sscanf(mw_position + 3, "%s %s %s", version_str, model_id_str, country_code_str); + if (num_values == 3) { if (strcmp(version_str, "1.0") == 0) { model_id = model_id_str; + country_code = country_code_str; } } else { model_id = ""; + country_code = ""; } } else { model_id = ""; // No MW format found + country_code = ""; } } } @@ -195,7 +202,7 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first, Impor if ((i % unit) == 0) { bool cb_cancel = false; if (stlFn) { - stlFn(i, facets_num, cb_cancel, model_id); + stlFn(i, facets_num, cb_cancel, model_id, country_code); if (cb_cancel) return false; } diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 8977dd5c8..ca1b8abe3 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -87,6 +87,7 @@ Model& Model::assign_copy(const Model &rhs) this->design_info = rhs.design_info; this->model_info = rhs.model_info; this->stl_design_id = rhs.stl_design_id; + this->stl_design_country = rhs.stl_design_country; this->profile_info = rhs.profile_info; this->mk_name = rhs.mk_name; @@ -120,6 +121,7 @@ Model& Model::assign_copy(Model &&rhs) //BBS: add auxiliary path logic // BBS: backup, all in one temp dir this->stl_design_id = rhs.stl_design_id; + this->stl_design_country = rhs.stl_design_country; this->mk_name = rhs.mk_name; this->mk_version = rhs.mk_version; this->backup_path = std::move(rhs.backup_path); @@ -920,6 +922,7 @@ void Model::load_from(Model& model) next_object_backup_id = model.next_object_backup_id; design_info = model.design_info; stl_design_id = model.stl_design_id; + stl_design_country = model.stl_design_country; model_info = model.model_info; profile_info = model.profile_info; mk_name = model.mk_name; diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index a6449ad6d..62696f8c7 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1513,6 +1513,7 @@ public: // DesignInfo of Model std::string stl_design_id; + std::string stl_design_country; std::shared_ptr design_info = nullptr; std::shared_ptr model_info = nullptr; std::shared_ptr profile_info = nullptr; diff --git a/src/slic3r/GUI/Jobs/PrintJob.cpp b/src/slic3r/GUI/Jobs/PrintJob.cpp index 4340dd870..e347e5ad6 100644 --- a/src/slic3r/GUI/Jobs/PrintJob.cpp +++ b/src/slic3r/GUI/Jobs/PrintJob.cpp @@ -286,15 +286,42 @@ void PrintJob::process() } } + params.stl_design_id = 0; if (!wxGetApp().model().stl_design_id.empty()) { - int stl_design_id = 0; - try { - stl_design_id = std::stoi(wxGetApp().model().stl_design_id); + + auto country_code = wxGetApp().app_config->get_country_code(); + bool match_code = false; + + if (wxGetApp().model().stl_design_country == "DEV" && (country_code == "ENV_CN_DEV" || country_code == "NEW_ENV_DEV_HOST")) { + match_code = true; } - catch (const std::exception& e) { - stl_design_id = 0; + + if (wxGetApp().model().stl_design_country == "QA" && (country_code == "ENV_CN_QA" || country_code == "NEW_ENV_QAT_HOST")) { + match_code = true; + } + + if (wxGetApp().model().stl_design_country == "CN_PRE" && (country_code == "ENV_CN_PRE" || country_code == "NEW_ENV_PRE_HOST")) { + match_code = true; + } + + if (wxGetApp().model().stl_design_country == "US_PRE" && country_code == "ENV_US_PRE") { + match_code = true; + } + + if (country_code == wxGetApp().model().stl_design_country) { + match_code = true; + } + + if (match_code) { + int stl_design_id = 0; + try { + stl_design_id = std::stoi(wxGetApp().model().stl_design_id); + } + catch (const std::exception& e) { + stl_design_id = 0; + } + params.stl_design_id = stl_design_id; } - params.stl_design_id = stl_design_id; } if (params.preset_name.empty() && m_print_type == "from_normal") { params.preset_name = wxString::Format("%s_plate_%d", m_project_name, curr_plate_idx).ToStdString(); } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 3d1d3e6b7..f149570ea 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3309,53 +3309,70 @@ BoundingBox Plater::priv::scaled_bed_shape_bb() const return printable_area.bounding_box(); } -std::string read_binary_stl(const std::string& filename) { - std::string model_id; - std::ifstream file(filename, std::ios::binary); + +void read_binary_stl(const std::string& filename, std::string& model_id, std::string& code) { + std::ifstream file( encode_path(filename.c_str()), std::ios::binary); if (!file) { - return model_id; + return; } - try{ + try { // Read the first 80 bytes char data[80]; file.read(data, 80); if (!file) { file.close(); - return model_id; + return; } if (data[0] == '\0' || data[0] == ' ') { file.close(); - return model_id; + return; } char magic[2] = { data[0], data[1] }; if (magic[0] != 'M' || magic[1] != 'W') { file.close(); - return model_id; + return; } if (data[2] != ' ') { file.close(); - return model_id; + return; } char protocol_version[3] = { data[3], data[4], data[5] }; //version - if (protocol_version[0] == '1' && protocol_version[1] == '.' && protocol_version[2] == '0') { - model_id = std::string(&data[7], &data[80]); + if (protocol_version[0] != '1' || protocol_version[1] != '.' || protocol_version[2] != '0') { + file.close(); + return; } + std::vector tokens; + std::istringstream iss(data); + std::string token; + while (std::getline(iss, token, ' ')) { + char* tokenPtr = new char[token.length() + 1]; + std::strcpy(tokenPtr, token.c_str()); + tokens.push_back(tokenPtr); + } + + //model id + if (tokens.size() < 4) { + file.close(); + return; + } + + model_id = tokens[2]; + code = tokens[3]; file.close(); } - catch (...){ + catch (...) { } - return model_id; + return; } - // BBS: backup & restore std::vector Plater::priv::load_files(const std::vector& input_files, LoadStrategy strategy, bool ask_multi) { @@ -3394,6 +3411,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ std::vector obj_idxs; std::string designer_model_id; + std::string designer_country_code; int answer_convert_from_meters = wxOK_DEFAULT; int answer_convert_from_imperial_units = wxOK_DEFAULT; @@ -3837,9 +3855,11 @@ std::vector Plater::priv::load_files(const std::vector& input_ model = Slic3r::Model::read_from_file( path.string(), nullptr, nullptr, strategy, &plate_data, &project_presets, &is_xxx, &file_version, nullptr, - [this, &dlg, real_filename, &progress_percent, &file_percent, INPUT_FILES_RATIO, total_files, i, &designer_model_id](int current, int total, bool &cancel, std::string &mode_id) + [this, &dlg, real_filename, &progress_percent, &file_percent, INPUT_FILES_RATIO, total_files, i, &designer_model_id, &designer_country_code](int current, int total, bool &cancel, std::string &mode_id, std::string &code) { designer_model_id = mode_id; + designer_country_code = code; + bool cont = true; float percent_float = (100.0f * (float)i / (float)total_files) + INPUT_FILES_RATIO * 100.0f * ((float)current / (float)total) / (float)total_files; BOOST_LOG_TRIVIAL(trace) << "load_stl_file: percent(float)=" << percent_float << ", curr = " << current << ", total = " << total; @@ -3866,7 +3886,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (designer_model_id.empty() && boost::algorithm::iends_with(path.string(), ".stl")) { - designer_model_id = read_binary_stl(path.string()); + read_binary_stl(path.string(), designer_model_id, designer_country_code); } if (type_any_amf && is_xxx) imperial_units = true; @@ -4163,9 +4183,16 @@ std::vector Plater::priv::load_files(const std::vector& input_ obj_idxs, model.objects, *notification_manager); //set designer_model_id - if (!designer_model_id.empty() && q->model().stl_design_id.empty()) { - q->model().stl_design_id = designer_model_id; - } + q->model().stl_design_id = designer_model_id; + q->model().stl_design_country = designer_country_code; + //if (!designer_model_id.empty() && q->model().stl_design_id.empty() && !designer_country_code.empty()) { + // q->model().stl_design_id = designer_model_id; + // q->model().stl_design_country = designer_country_code; + //} + //else { + // q->model().stl_design_id = ""; + // q->model().stl_design_country = ""; + //} if (tolal_model_count <= 0 && !q->m_exported_file) { dlg.Hide();