ENH: do not invalid thumbnails when using expoted file

fix missing project name for gcode.3mf

Change-Id: Iabc43cd54ceaa9cbbdfb7b045f5d4a24124d7007
Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
Stone Li 2022-12-09 20:34:12 +08:00 committed by Lane.Wei
parent 3fae63e8cf
commit c69b7780ad
2 changed files with 53 additions and 13 deletions

View file

@ -2972,6 +2972,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
ConfigSubstitutionContext config_substitutions{ForwardCompatibilitySubstitutionRule::Enable}; ConfigSubstitutionContext config_substitutions{ForwardCompatibilitySubstitutionRule::Enable};
std::vector<Preset *> project_presets; std::vector<Preset *> project_presets;
// BBS: backup & restore // BBS: backup & restore
q->skip_thumbnail_invalid = true;
model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, &config_substitutions, en_3mf_file_type, strategy, &plate_data, &project_presets, model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, &config_substitutions, en_3mf_file_type, strategy, &plate_data, &project_presets,
&file_version, &file_version,
[this, &dlg, real_filename, &progress_percent, &file_percent, stage_percent, INPUT_FILES_RATIO, total_files, i, [this, &dlg, real_filename, &progress_percent, &file_percent, stage_percent, INPUT_FILES_RATIO, total_files, i,
@ -3036,6 +3037,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
if (!load_model) { if (!load_model) {
// only load config case, return directly // only load config case, return directly
show_info(q, _L("The Config can not be loaded."), _L("Load 3mf")); show_info(q, _L("The Config can not be loaded."), _L("Load 3mf"));
q->skip_thumbnail_invalid = false;
return empty_result; return empty_result;
} }
load_old_project = true; load_old_project = true;
@ -3111,7 +3113,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format(", import 3mf UPDATE_GCODE_RESULT \n"); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format(", import 3mf UPDATE_GCODE_RESULT \n");
wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename));
dlg_cont = dlg.Update(progress_percent, msg); dlg_cont = dlg.Update(progress_percent, msg);
if (!dlg_cont) return empty_result; if (!dlg_cont) {
q->skip_thumbnail_invalid = false;
return empty_result;
}
if (load_config) { if (load_config) {
partplate_list.load_from_3mf_structure(plate_data); partplate_list.load_from_3mf_structure(plate_data);
@ -3141,7 +3146,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format(", import 3mf IMPORT_LOAD_CONFIG \n"); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format(", import 3mf IMPORT_LOAD_CONFIG \n");
wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename));
dlg_cont = dlg.Update(progress_percent, msg); dlg_cont = dlg.Update(progress_percent, msg);
if (!dlg_cont) return empty_result; if (!dlg_cont) {
q->skip_thumbnail_invalid = false;
return empty_result;
}
// Based on the printer technology field found in the loaded config, select the base for the config, // Based on the printer technology field found in the loaded config, select the base for the config,
PrinterTechnology printer_technology = Preset::printer_technology(config_loaded); PrinterTechnology printer_technology = Preset::printer_technology(config_loaded);
@ -3319,7 +3327,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
progress_percent = 100.0f * (float)i / (float)total_files + INIT_MODEL_RATIO * 100.0f / (float)total_files; progress_percent = 100.0f * (float)i / (float)total_files + INIT_MODEL_RATIO * 100.0f / (float)total_files;
dlg_cont = dlg.Update(progress_percent); dlg_cont = dlg.Update(progress_percent);
if (!dlg_cont) return empty_result; if (!dlg_cont) {
q->skip_thumbnail_invalid = false;
return empty_result;
}
if (load_model) { if (load_model) {
// The model should now be initialized // The model should now be initialized
@ -3399,7 +3410,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
progress_percent = 100.0f * (float)i / (float)total_files + CENTER_AROUND_ORIGIN_RATIO * 100.0f / (float)total_files; progress_percent = 100.0f * (float)i / (float)total_files + CENTER_AROUND_ORIGIN_RATIO * 100.0f / (float)total_files;
dlg_cont = dlg.Update(progress_percent); dlg_cont = dlg.Update(progress_percent);
if (!dlg_cont) return empty_result; if (!dlg_cont) {
q->skip_thumbnail_invalid = false;
return empty_result;
}
int model_idx = 0; int model_idx = 0;
for (ModelObject *model_object : model.objects) { for (ModelObject *model_object : model.objects) {
@ -3410,7 +3424,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
wxString msg = wxString::Format("Loading file: %s", from_path(real_filename)); wxString msg = wxString::Format("Loading file: %s", from_path(real_filename));
model_idx++; model_idx++;
dlg_cont = dlg.Update(progress_percent, msg); dlg_cont = dlg.Update(progress_percent, msg);
if (!dlg_cont) return empty_result; if (!dlg_cont) {
q->skip_thumbnail_invalid = false;
return empty_result;
}
model_object->ensure_on_bed(is_project_file); model_object->ensure_on_bed(is_project_file);
} }
@ -3419,7 +3436,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
progress_percent = 100.0f * (float)i / (float)total_files + LOAD_MODEL_RATIO * 100.0f / (float)total_files; progress_percent = 100.0f * (float)i / (float)total_files + LOAD_MODEL_RATIO * 100.0f / (float)total_files;
dlg_cont = dlg.Update(progress_percent); dlg_cont = dlg.Update(progress_percent);
if (!dlg_cont) return empty_result; if (!dlg_cont) {
q->skip_thumbnail_invalid = false;
return empty_result;
}
if (one_by_one) { if (one_by_one) {
// BBS: add load_old_project logic // BBS: add load_old_project logic
@ -3440,7 +3460,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format("import 3mf IMPORT_LOAD_MODEL_OBJECTS \n"); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format("import 3mf IMPORT_LOAD_MODEL_OBJECTS \n");
wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename));
dlg_cont = dlg.Update(progress_percent, msg); dlg_cont = dlg.Update(progress_percent, msg);
if (!dlg_cont) return empty_result; if (!dlg_cont) {
q->skip_thumbnail_invalid = false;
return empty_result;
}
} else { } else {
// This must be an .stl or .obj file, which may contain a maximum of one volume. // This must be an .stl or .obj file, which may contain a maximum of one volume.
for (const ModelObject *model_object : model.objects) { for (const ModelObject *model_object : model.objects) {
@ -3449,7 +3472,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format("import 3mf IMPORT_ADD_MODEL_OBJECTS \n"); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format("import 3mf IMPORT_ADD_MODEL_OBJECTS \n");
wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename));
dlg_cont = dlg.Update(progress_percent, msg); dlg_cont = dlg.Update(progress_percent, msg);
if (!dlg_cont) return empty_result; if (!dlg_cont) {
q->skip_thumbnail_invalid = false;
return empty_result;
}
} }
} }
} }
@ -3471,6 +3497,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
//BBS: add gcode loading logic in the end //BBS: add gcode loading logic in the end
q->m_exported_file = false; q->m_exported_file = false;
q->skip_thumbnail_invalid = false;
if (load_model && load_config) { if (load_model && load_config) {
if (model.objects.empty()) { if (model.objects.empty()) {
partplate_list.load_gcode_files(); partplate_list.load_gcode_files();
@ -5287,8 +5314,7 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice)
notification_manager->set_in_preview(false); notification_manager->set_in_preview(false);
} }
else if (current_panel == preview) { else if (current_panel == preview) {
if (!q->using_exported_file()) q->invalid_all_plate_thumbnails();
q->invalid_all_plate_thumbnails();
if (old_panel == view3D) if (old_panel == view3D)
view3D->get_canvas3d()->unbind_event_handlers(); view3D->get_canvas3d()->unbind_event_handlers();
else if (old_panel == assemble_view) else if (old_panel == assemble_view)
@ -7457,7 +7483,11 @@ void Plater::load_project(wxString const& filename2,
// if res is empty no data has been loaded // if res is empty no data has been loaded
if (!res.empty() && (load_restore || !(strategy & LoadStrategy::Silence))) { if (!res.empty() && (load_restore || !(strategy & LoadStrategy::Silence))) {
p->set_project_filename(load_restore ? originfile : filename); p->set_project_filename(load_restore ? originfile : filename);
} else {
if (using_exported_file())
p->set_project_filename(filename);
} }
// BBS set default 3D view and direction after loading project // BBS set default 3D view and direction after loading project
//p->select_view_3D("3D"); //p->select_view_3D("3D");
@ -7908,6 +7938,9 @@ void Plater::update_all_plate_thumbnails(bool force_update)
//invalid all plate's thumbnails //invalid all plate's thumbnails
void Plater::invalid_all_plate_thumbnails() void Plater::invalid_all_plate_thumbnails()
{ {
if (using_exported_file() || skip_thumbnail_invalid)
return;
BOOST_LOG_TRIVIAL(info) << "thumb: invalid all";
for (int i = 0; i < get_partplate_list().get_plate_count(); i++) { for (int i = 0; i < get_partplate_list().get_plate_count(); i++) {
PartPlate* plate = get_partplate_list().get_plate(i); PartPlate* plate = get_partplate_list().get_plate(i);
plate->thumbnail_data.reset(); plate->thumbnail_data.reset();
@ -7916,8 +7949,12 @@ void Plater::invalid_all_plate_thumbnails()
void Plater::force_update_all_plate_thumbnails() void Plater::force_update_all_plate_thumbnails()
{ {
invalid_all_plate_thumbnails(); if (using_exported_file() || skip_thumbnail_invalid) {
update_all_plate_thumbnails(true); }
else {
invalid_all_plate_thumbnails();
update_all_plate_thumbnails(true);
}
get_preview_canvas3D()->update_plate_thumbnails(); get_preview_canvas3D()->update_plate_thumbnails();
} }

View file

@ -231,7 +231,9 @@ public:
//BBS: add only gcode mode //BBS: add only gcode mode
bool using_exported_file() { return m_exported_file; } bool using_exported_file() { return m_exported_file; }
void set_using_exported_file(bool exported_file) { m_exported_file = exported_file; } void set_using_exported_file(bool exported_file) {
m_exported_file = exported_file;
}
// BBS // BBS
wxString get_project_name(); wxString get_project_name();
@ -677,6 +679,7 @@ private:
//BBS: add only gcode mode //BBS: add only gcode mode
bool m_only_gcode { false }; bool m_only_gcode { false };
bool m_exported_file { false }; bool m_exported_file { false };
bool skip_thumbnail_invalid { false };
int m_valid_plates_count { 0 }; int m_valid_plates_count { 0 };
void suppress_snapshots(); void suppress_snapshots();