FIX: CLI: fix the crash issue caused by get_min_flush_volumes

JIRA: no jira
Change-Id: I0d5bfd605e51ebddac8fddc4d83dab5055b0fbf2
This commit is contained in:
lane.wei 2024-04-16 08:54:21 +08:00 committed by Lane.Wei
parent ffd292a62c
commit 37d49a4bf5
3 changed files with 58 additions and 30 deletions

View File

@ -2648,7 +2648,7 @@ int CLI::run(int argc, char **argv)
//set multiplier to 1?
m_print_config.option<ConfigOptionFloat>("flush_multiplier", true)->set(new ConfigOptionFloat(1.f));
const std::vector<int>& min_flush_volumes = Slic3r::GUI::get_min_flush_volumes();
const std::vector<int>& min_flush_volumes = Slic3r::GUI::get_min_flush_volumes(m_print_config);
if (filament_is_support->size() != project_filament_count)
{

View File

@ -403,7 +403,7 @@ void Sidebar::priv::show_preset_comboboxes()
void Sidebar::priv::on_search_update()
{
m_object_list->assembly_plate_object_name();
wxString search_text = m_search_bar->GetValue();
m_object_list->GetModel()->search_object(search_text);
dia->update_list();
@ -463,37 +463,63 @@ void Sidebar::priv::hide_rich_tip(wxButton* btn)
}
#endif
std::vector<int> get_min_flush_volumes()
std::vector<int> get_min_flush_volumes(const DynamicPrintConfig& full_config)
{
std::vector<int>extra_flush_volumes;
const auto& full_config = wxGetApp().preset_bundle->full_config();
auto& printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
//const auto& full_config = wxGetApp().preset_bundle->full_config();
//auto& printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
ConfigOption* nozzle_volume_opt = printer_config.option("nozzle_volume");
const ConfigOption* nozzle_volume_opt = full_config.option("nozzle_volume");
int nozzle_volume_val = nozzle_volume_opt ? (int)nozzle_volume_opt->getFloat() : 0;
int machine_enabled_level = printer_config.option<ConfigOptionInt>("enable_long_retraction_when_cut")->value;
bool machine_activated = printer_config.option<ConfigOptionBools>("long_retractions_when_cut")->values[0] == 1;
const ConfigOptionInt* enable_long_retraction_when_cut_opt = full_config.option<ConfigOptionInt>("enable_long_retraction_when_cut");
int machine_enabled_level = 0;
if (enable_long_retraction_when_cut_opt) {
machine_enabled_level = enable_long_retraction_when_cut_opt->value;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get enable_long_retraction_when_cut from config, value=%1%")%machine_enabled_level;
}
const ConfigOptionBools* long_retractions_when_cut_opt = full_config.option<ConfigOptionBools>("long_retractions_when_cut");
bool machine_activated = false;
if (long_retractions_when_cut_opt) {
machine_activated = long_retractions_when_cut_opt->values[0] == 1;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get long_retractions_when_cut from config, value=%1%, activated=%2%")%long_retractions_when_cut_opt->values[0] %machine_activated;
}
auto filament_retraction_distance_when_cut = full_config.option<ConfigOptionFloats>("filament_retraction_distances_when_cut");
auto printer_retraction_distance_when_cut = full_config.option<ConfigOptionFloats>("retraction_distances_when_cut");
auto filament_long_retractions_when_cut = full_config.option<ConfigOptionBools>("filament_long_retractions_when_cut");
size_t filament_size = full_config.option<ConfigOptionFloats>("filament_diameter")->values.size();
std::vector<double> filament_retraction_distance_when_cut(filament_size, 18.0f), printer_retraction_distance_when_cut(filament_size, 18.0f);
std::vector<unsigned char> filament_long_retractions_when_cut(filament_size, 0);
const ConfigOptionFloats* filament_retraction_distances_when_cut_opt = full_config.option<ConfigOptionFloats>("filament_retraction_distances_when_cut");
if (filament_retraction_distances_when_cut_opt) {
filament_retraction_distance_when_cut = filament_retraction_distances_when_cut_opt->values;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get filament_retraction_distance_when_cut from config, size=%1%, values=%2%")%filament_retraction_distance_when_cut.size() %filament_retraction_distances_when_cut_opt->serialize();
}
const ConfigOptionFloats* printer_retraction_distance_when_cut_opt = full_config.option<ConfigOptionFloats>("retraction_distances_when_cut");
if (printer_retraction_distance_when_cut_opt) {
printer_retraction_distance_when_cut = printer_retraction_distance_when_cut_opt->values;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get retraction_distances_when_cut from config, size=%1%, values=%2%")%printer_retraction_distance_when_cut.size() %printer_retraction_distance_when_cut_opt->serialize();
}
const ConfigOptionBools* filament_long_retractions_when_cut_opt = full_config.option<ConfigOptionBools>("filament_long_retractions_when_cut");
if (filament_long_retractions_when_cut_opt) {
filament_long_retractions_when_cut = filament_long_retractions_when_cut_opt->values;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get filament_long_retractions_when_cut from config, size=%1%, values=%2%")%filament_long_retractions_when_cut.size() %filament_long_retractions_when_cut_opt->serialize();
}
size_t filament_size = filament_retraction_distance_when_cut->values.size();
for (size_t idx = 0; idx < filament_size; ++idx) {
int extra_flush_volume = nozzle_volume_val;
int retract_length = machine_enabled_level && machine_activated ? printer_retraction_distance_when_cut->values[0] : 0;
int retract_length = machine_enabled_level && machine_activated ? printer_retraction_distance_when_cut[0] : 0;
char filament_activated = filament_long_retractions_when_cut->values[idx];
double filament_retract_length = filament_retraction_distance_when_cut->values[idx];
unsigned char filament_activated = filament_long_retractions_when_cut[idx];
double filament_retract_length = filament_retraction_distance_when_cut[idx];
if (filament_activated == 0)
retract_length = 0;
else if (filament_activated == 1 && machine_enabled_level == LongRectrationLevel::EnableFilament) {
if (!std::isnan(filament_retract_length))
retract_length = (int)filament_retraction_distance_when_cut->values[idx];
retract_length = (int)filament_retraction_distance_when_cut[idx];
else
retract_length = printer_retraction_distance_when_cut->values[0];
retract_length = printer_retraction_distance_when_cut[0];
}
extra_flush_volume -= PI * 1.75 * 1.75 / 4 * retract_length;
@ -823,7 +849,8 @@ Sidebar::Sidebar(Plater *parent)
float flush_multiplier = flush_multi_opt ? flush_multi_opt->getFloat() : 1.f;
const std::vector<std::string> extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config();
const auto& extra_flush_volumes = get_min_flush_volumes();
const auto& full_config = wxGetApp().preset_bundle->full_config();
const auto& extra_flush_volumes = get_min_flush_volumes(full_config);
WipingDialog dlg(parent, cast<float>(init_matrix), cast<float>(init_extruders), extruder_colours, extra_flush_volumes, flush_multiplier);
if (dlg.ShowModal() == wxID_OK) {
std::vector<float> matrix = dlg.get_matrix();
@ -1242,7 +1269,7 @@ void Sidebar::update_presets(Preset::Type preset_type)
if (preset) {
if (preset->is_compatible) preset_bundle.set_filament_preset(0, name);
}
}
for (size_t i = 0; i < filament_cnt; i++)
@ -1963,13 +1990,14 @@ void Sidebar::auto_calc_flushing_volumes(const int modify_id)
auto& preset_bundle = wxGetApp().preset_bundle;
auto& project_config = preset_bundle->project_config;
auto& printer_config = preset_bundle->printers.get_edited_preset().config;
const auto& full_config = wxGetApp().preset_bundle->full_config();
auto& ams_multi_color_filament = preset_bundle->ams_multi_color_filment;
auto& ams_filament_list = preset_bundle->filament_ams_list;
const std::vector<double>& init_matrix = (project_config.option<ConfigOptionFloats>("flush_volumes_matrix"))->values;
const std::vector<double>& init_extruders = (project_config.option<ConfigOptionFloats>("flush_volumes_vector"))->values;
const std::vector<int>& min_flush_volumes= get_min_flush_volumes();
const std::vector<int>& min_flush_volumes= get_min_flush_volumes(full_config);
ConfigOptionFloat* flush_multi_opt = project_config.option<ConfigOptionFloat>("flush_multiplier");
float flush_multiplier = flush_multi_opt ? flush_multi_opt->getFloat() : 1.f;
@ -8644,7 +8672,7 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString &project_
void Plater::load_project(wxString const& filename2,
wxString const& originfile)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "filename is: " << filename2 << "and originfile is: " << originfile;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "filename is: " << filename2 << "and originfile is: " << originfile;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__;
auto filename = filename2;
auto check = [&filename, this] (bool yes_or_no) {
@ -8721,13 +8749,13 @@ void Plater::load_project(wxString const& filename2,
if (load_restore && originfile.IsEmpty()) {
p->set_project_name(_L("Untitled"));
}
} else {
if (using_exported_file()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " using ecported set project filename: " << filename;
p->set_project_filename(filename);
}
}
// BBS set default 3D view and direction after loading project
@ -8892,7 +8920,7 @@ void Plater::import_model_id(wxString download_info)
wxString extension = fs::path(filename.wx_str()).extension().c_str();
//check file suffix
//check file suffix
if (!extension.Contains(".3mf")) {
msg = _L("Download failed, unknown file format.");
return;
@ -8952,14 +8980,14 @@ void Plater::import_model_id(wxString download_info)
while (cont && retry_count < max_retries) {
retry_count++;
http.on_progress([&percent, &cont, &msg, &filesize, &size_limit](Http::Progress progress, bool& cancel) {
if (!cont) cancel = true;
if (progress.dltotal != 0) {
if (filesize == 0) {
filesize = progress.dltotal;
double megabytes = static_cast<double>(progress.dltotal) / (1024 * 1024);
//The maximum size of a 3mf file is 500mb
//The maximum size of a 3mf file is 500mb
if (megabytes > 500) {
cont = false;
size_limit = true;
@ -9761,7 +9789,7 @@ void Plater::load_gcode(const wxString& filename)
} else {
set_project_filename(filename);
}
}
void Plater::reload_gcode_from_disk()
@ -12225,7 +12253,7 @@ void Plater::on_filaments_change(size_t num_filaments)
}
}
void Plater::on_bed_type_change(BedType bed_type, bool is_gcode_file) {
void Plater::on_bed_type_change(BedType bed_type, bool is_gcode_file) {
sidebar().set_is_gcode_file(is_gcode_file);
sidebar().on_bed_type_change(bed_type);
}

View File

@ -777,7 +777,7 @@ private:
bool m_was_scheduled;
};
std::vector<int> get_min_flush_volumes();
std::vector<int> get_min_flush_volumes(const DynamicPrintConfig& full_config);
} // namespace GUI
} // namespace Slic3r