ENH: presets: add more logs to debug some issues

jira: no-jira
Change-Id: I84dd4eb8fb32bde2ebcefccfb89fa53d64b3ef7f
This commit is contained in:
lane.wei 2025-01-17 15:34:46 +08:00
parent 4cf4c82c9e
commit d09e023368
3 changed files with 36 additions and 21 deletions

View File

@ -646,7 +646,7 @@ bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const Pre
return PlaceholderParser::evaluate_boolean_expression(condition, active_printer.preset.config, extra_config); return PlaceholderParser::evaluate_boolean_expression(condition, active_printer.preset.config, extra_config);
} catch (const std::runtime_error &err) { } catch (const std::runtime_error &err) {
//FIXME in case of an error, return "compatible with everything". //FIXME in case of an error, return "compatible with everything".
printf("Preset::is_compatible_with_printer - parsing error of compatible_printers_condition %s:\n%s\n", active_printer.preset.name.c_str(), err.what()); BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": parsing error of compatible_printers_condition %1%: %2%")%active_printer.preset.name %err.what();
return true; return true;
} }
} }
@ -695,7 +695,7 @@ void Preset::set_visible_from_appconfig(const AppConfig &app_config)
} }
} }
//BBS: add config related log //BBS: add config related log
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": name %1%, is_visible set to %2%")%name % is_visible; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": name %1%, is_visible set to %2%")%name % is_visible;
} }
std::string Preset::get_filament_type(std::string &display_filament_type) std::string Preset::get_filament_type(std::string &display_filament_type)
@ -2708,7 +2708,12 @@ size_t PresetCollection::update_compatible_internal(const PresetWithVendorProfil
const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter"); const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter");
if (opt) if (opt)
config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloatsNullable*>(opt)->values.size())); config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloatsNullable*>(opt)->values.size()));
bool some_compatible = false; int some_compatible = 0;
if (active_print)
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": active printer %1%, print %2%, unselect_if_incompatible %3%")%active_printer.preset.name %active_print->preset.name % (int)unselect_if_incompatible;
else
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": active printer %1%, unselect_if_incompatible %2%")%active_printer.preset.name % (int)unselect_if_incompatible;
for (size_t idx_preset = m_num_default_presets; idx_preset < m_presets.size(); ++ idx_preset) { for (size_t idx_preset = m_num_default_presets; idx_preset < m_presets.size(); ++ idx_preset) {
bool selected = idx_preset == m_idx_selected; bool selected = idx_preset == m_idx_selected;
Preset &preset_selected = m_presets[idx_preset]; Preset &preset_selected = m_presets[idx_preset];
@ -2717,19 +2722,29 @@ size_t PresetCollection::update_compatible_internal(const PresetWithVendorProfil
const PresetWithVendorProfile this_preset_with_vendor_profile = this->get_preset_with_vendor_profile(preset_edited); const PresetWithVendorProfile this_preset_with_vendor_profile = this->get_preset_with_vendor_profile(preset_edited);
bool was_compatible = preset_edited.is_compatible; bool was_compatible = preset_edited.is_compatible;
preset_edited.is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config); preset_edited.is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config);
some_compatible |= preset_edited.is_compatible; if (preset_edited.is_compatible)
some_compatible++;
if (active_print != nullptr) if (active_print != nullptr)
preset_edited.is_compatible &= is_compatible_with_print(this_preset_with_vendor_profile, *active_print, active_printer); preset_edited.is_compatible &= is_compatible_with_print(this_preset_with_vendor_profile, *active_print, active_printer);
if (! preset_edited.is_compatible && selected && if (! preset_edited.is_compatible && selected &&
(unselect_if_incompatible == PresetSelectCompatibleType::Always || (unselect_if_incompatible == PresetSelectCompatibleType::OnlyIfWasCompatible && was_compatible))) (unselect_if_incompatible == PresetSelectCompatibleType::Always || (unselect_if_incompatible == PresetSelectCompatibleType::OnlyIfWasCompatible && was_compatible)))
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": type %1% , previous selected %2% becomes uncompatible, will select later")%Preset::get_type_string(m_type) %m_idx_selected;
m_idx_selected = size_t(-1); m_idx_selected = size_t(-1);
}
if (selected) if (selected)
preset_selected.is_compatible = preset_edited.is_compatible; preset_selected.is_compatible = preset_edited.is_compatible;
} }
// Update visibility of the default profiles here if the defaults are suppressed, the current profile is not compatible and we don't want to select another compatible profile. // Update visibility of the default profiles here if the defaults are suppressed, the current profile is not compatible and we don't want to select another compatible profile.
if (m_idx_selected >= m_num_default_presets && m_default_suppressed) if (m_idx_selected >= m_num_default_presets && m_default_suppressed)
for (size_t i = 0; i < m_num_default_presets; ++ i) {
m_presets[i].is_visible = ! some_compatible; for (size_t i = 0; i < m_num_default_presets; ++ i)
{
m_presets[i].is_visible = (some_compatible == 0);
}
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": type %1% returned m_idx_selected %2%, some_compatible %3%")%Preset::get_type_string(m_type) %m_idx_selected %some_compatible;
return m_idx_selected; return m_idx_selected;
} }
@ -2908,7 +2923,7 @@ std::vector<std::string> PresetCollection::dirty_options_without_option_list(con
Preset& PresetCollection::select_preset(size_t idx) Preset& PresetCollection::select_preset(size_t idx)
{ {
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1% try to select preset %2%")%Preset::get_type_string(m_type) %idx; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1% try to select preset %2%")%Preset::get_type_string(m_type) %idx;
for (Preset &preset : m_presets) for (Preset &preset : m_presets)
preset.is_dirty = false; preset.is_dirty = false;
if (idx >= m_presets.size()) if (idx >= m_presets.size())
@ -2920,14 +2935,14 @@ Preset& PresetCollection::select_preset(size_t idx)
for (size_t i = 0; i < m_num_default_presets; ++i) for (size_t i = 0; i < m_num_default_presets; ++i)
m_presets[i].is_visible = default_visible; m_presets[i].is_visible = default_visible;
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1% select success, m_idx_selected %2%, name %3%, is_system %4%, is_default %5%")%Preset::get_type_string(m_type) % m_idx_selected % m_edited_preset.name % m_edited_preset.is_system % m_edited_preset.is_default; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1% select success, m_idx_selected %2%, name %3%, is_system %4%, is_default %5%")%Preset::get_type_string(m_type) % m_idx_selected % m_edited_preset.name % m_edited_preset.is_system % m_edited_preset.is_default;
return m_presets[idx]; return m_presets[idx];
} }
bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, bool force) bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, bool force)
{ {
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, try to select by name %2%, force %3%")%Preset::get_type_string(m_type) %name_w_suffix %force; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, try to select by name %2%, force %3%")%Preset::get_type_string(m_type) %name_w_suffix %force;
std::string name = Preset::remove_suffix_modified(name_w_suffix); std::string name = Preset::remove_suffix_modified(name_w_suffix);
// 1) Try to find the preset by its name. // 1) Try to find the preset by its name.
auto it = this->find_preset_internal(name); auto it = this->find_preset_internal(name);
@ -2949,19 +2964,19 @@ bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, b
if (m_idx_selected != idx || force) { if (m_idx_selected != idx || force) {
this->select_preset(idx); this->select_preset(idx);
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, select %2%, success")%Preset::get_type_string(m_type) %name_w_suffix; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, success")%Preset::get_type_string(m_type) %name_w_suffix;
return true; return true;
} }
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name_w_suffix; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name_w_suffix;
return false; return false;
} }
bool PresetCollection::select_preset_by_name_strict(const std::string &name) bool PresetCollection::select_preset_by_name_strict(const std::string &name)
{ {
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, try to select by name %2%")%Preset::get_type_string(m_type) %name; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, try to select by name %2%")%Preset::get_type_string(m_type) %name;
// 1) Try to find the preset by its name. // 1) Try to find the preset by its name.
auto it = this->find_preset_internal(name); auto it = this->find_preset_internal(name);
@ -2973,12 +2988,12 @@ bool PresetCollection::select_preset_by_name_strict(const std::string &name)
if (idx != (size_t)-1) { if (idx != (size_t)-1) {
this->select_preset(idx); this->select_preset(idx);
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, select %2%, success")%Preset::get_type_string(m_type) %name; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, success")%Preset::get_type_string(m_type) %name;
return true; return true;
} }
m_idx_selected = idx; m_idx_selected = idx;
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name;
return false; return false;
} }

View File

@ -1555,7 +1555,7 @@ void PresetBundle::load_installed_sla_materials(AppConfig &config)
// This is done on application start up or after updates are applied. // This is done on application start up or after updates are applied.
void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& preferred_selection/* = PresetPreferences()*/) void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& preferred_selection/* = PresetPreferences()*/)
{ {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": enter, preferred printer_model_id %1%")%preferred_selection.printer_model_id; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, preferred printer_model_id %1%")%preferred_selection.printer_model_id;
// Update visibility of presets based on application vendor / model / variant configuration. // Update visibility of presets based on application vendor / model / variant configuration.
this->load_installed_printers(config); this->load_installed_printers(config);
@ -1704,7 +1704,7 @@ void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& p
if (!initial_physical_printer_name.empty()) if (!initial_physical_printer_name.empty())
physical_printers.select_printer(initial_physical_printer_name); physical_printers.select_printer(initial_physical_printer_name);
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": finished, preferred printer_model_id %1%")%preferred_selection.printer_model_id; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": finished, preferred printer_model_id %1%")%preferred_selection.printer_model_id;
} }
// Export selections (current print, current filaments, current printer) into config.ini // Export selections (current print, current filaments, current printer) into config.ini
@ -1747,7 +1747,7 @@ void PresetBundle::export_selections(AppConfig &config)
//config.set("presets", "sla_material", sla_materials.get_selected_preset_name()); //config.set("presets", "sla_material", sla_materials.get_selected_preset_name());
//config.set("presets", "physical_printer", physical_printers.get_selected_full_printer_name()); //config.set("presets", "physical_printer", physical_printers.get_selected_full_printer_name());
//BBS: add config related log //BBS: add config related log
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": printer %1%, print %2%, filaments[0] %3% ")%printers.get_selected_preset_name() % prints.get_selected_preset_name() %filament_presets[0]; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1%, print %2%, filaments[0] %3% ")%printers.get_selected_preset_name() % prints.get_selected_preset_name() %filament_presets[0];
} }
// BBS // BBS
@ -3866,7 +3866,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
loaded.description = description; loaded.description = description;
loaded.setting_id = setting_id; loaded.setting_id = setting_id;
loaded.filament_id = filament_id; loaded.filament_id = filament_id;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << ", " << loaded.name << " load filament_id: " << filament_id; BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << " " << __LINE__ << ", " << loaded.name << " load filament_id: " << filament_id;
if (presets_collection->type() == Preset::TYPE_FILAMENT) { if (presets_collection->type() == Preset::TYPE_FILAMENT) {
if (filament_id.empty() && "Template" != vendor_name) { if (filament_id.empty() && "Template" != vendor_name) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": can not find filament_id for " << preset_name; BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": can not find filament_id for " << preset_name;
@ -4144,7 +4144,7 @@ void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_pri
const std::vector<std::string> &m_prefered_names; const std::vector<std::string> &m_prefered_names;
}; };
BOOST_LOG_TRIVIAL(info) << boost::format("update_compatibility for all presets enter"); BOOST_LOG_TRIVIAL(info) << boost::format("update_compatibility for all presets enter, select_other_print_if_incompatible %1%, select_other_filament_if_incompatible %2%")%(int)select_other_print_if_incompatible %(int)select_other_filament_if_incompatible;
switch (printer_preset.printer_technology()) { switch (printer_preset.printer_technology()) {
case ptFFF: case ptFFF:
{ {

View File

@ -4495,7 +4495,7 @@ void Tab::reactive_preset_combo_box()
// Initialize the UI from the current preset // Initialize the UI from the current preset
void Tab::load_current_preset() void Tab::load_current_preset()
{ {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<<boost::format(": enter"); BOOST_LOG_TRIVIAL(info) << __FUNCTION__<<boost::format(": enter, m_type %1%")%Preset::get_type_string(m_type);
const Preset& preset = m_presets->get_edited_preset(); const Preset& preset = m_presets->get_edited_preset();
int previous_extruder_count = 0; int previous_extruder_count = 0;