ENH:STL tracking restricted area
jira:[STUDIO-6155] Change-Id: I289c8b8aa8f62f0e5cc7004fb60437aa3337ca85
This commit is contained in:
parent
9787cdb5a3
commit
d871339f0d
|
@ -45,7 +45,7 @@ typedef Eigen::Matrix<int, 3, 1, Eigen::DontAlign> 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<void(int current, int total, bool& cancel, std::string& model_id)> ImportstlProgressFn;
|
||||
typedef std::function<void(int current, int total, bool& cancel, std::string& model_id, std::string& code)> ImportstlProgressFn;
|
||||
|
||||
typedef enum {
|
||||
eNormal, // normal face
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1513,6 +1513,7 @@ public:
|
|||
|
||||
// DesignInfo of Model
|
||||
std::string stl_design_id;
|
||||
std::string stl_design_country;
|
||||
std::shared_ptr<ModelDesignInfo> design_info = nullptr;
|
||||
std::shared_ptr<ModelInfo> model_info = nullptr;
|
||||
std::shared_ptr<ModelProfileInfo> profile_info = nullptr;
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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<char*> 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<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_files, LoadStrategy strategy, bool ask_multi)
|
||||
{
|
||||
|
@ -3394,6 +3411,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||
std::vector<size_t> 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<size_t> Plater::priv::load_files(const std::vector<fs::path>& 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<size_t> Plater::priv::load_files(const std::vector<fs::path>& 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<size_t> Plater::priv::load_files(const std::vector<fs::path>& 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();
|
||||
|
|
Loading…
Reference in New Issue