ENH: config: allow invisible preset to be selected
when switch printer, we found some filament preset not visible and we need to allow it to be selected jira: STUDIO-9979 Change-Id: I9613747a755f449c2f48563082b6893e426f37ea
This commit is contained in:
parent
aeba1ebfa2
commit
bc5514bbab
|
@ -13,7 +13,7 @@ BuildVolume::BuildVolume(const std::vector<Vec2d> &printable_area, const double
|
|||
: m_bed_shape(printable_area), m_max_print_height(printable_height), m_extruder_shapes(extruder_areas), m_extruder_printable_height(extruder_printable_heights)
|
||||
{
|
||||
assert(printable_height >= 0);
|
||||
assert(extruder_printable_heights.size() == extruder_areas.size());
|
||||
//assert(extruder_printable_heights.size() == extruder_areas.size());
|
||||
|
||||
m_polygon = Polygon::new_scale(printable_area);
|
||||
|
||||
|
|
|
@ -1309,7 +1309,7 @@ void PresetCollection::load_presets(
|
|||
m_presets.insert(m_presets.end(), std::make_move_iterator(presets_loaded.begin()), std::make_move_iterator(presets_loaded.end()));
|
||||
std::sort(m_presets.begin() + m_num_default_presets, m_presets.end());
|
||||
//BBS: add config related logs
|
||||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": loaded %1% presets from %2%, type %3%")%presets_loaded.size() %dir %Preset::get_type_string(m_type);
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": loaded %1% presets from %2%, type %3%")%presets_loaded.size() %dir %Preset::get_type_string(m_type);
|
||||
//this->select_preset(first_visible_idx());
|
||||
if (! errors_cummulative.empty())
|
||||
throw Slic3r::RuntimeError(errors_cummulative);
|
||||
|
@ -2937,6 +2937,12 @@ Preset& PresetCollection::select_preset(size_t idx)
|
|||
bool default_visible = ! m_default_suppressed || m_idx_selected < m_num_default_presets;
|
||||
for (size_t i = 0; i < m_num_default_presets; ++i)
|
||||
m_presets[i].is_visible = default_visible;
|
||||
|
||||
//set this preset to true
|
||||
if (!m_presets[idx].is_visible) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1% set %2%, idx %3% to visible") % Preset::get_type_string(m_type) % m_presets[idx].name % idx;
|
||||
m_presets[idx].is_visible = true;
|
||||
}
|
||||
//BBS: add config related logs
|
||||
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];
|
||||
|
@ -2972,7 +2978,10 @@ bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, b
|
|||
}
|
||||
|
||||
//BBS: add config related logs
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name_w_suffix;
|
||||
if (m_idx_selected == idx)
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, already selected before") % Preset::get_type_string(m_type);
|
||||
else
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name_w_suffix;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -605,7 +605,7 @@ public:
|
|||
int match_quality = -1;
|
||||
for (; i < n; ++ i)
|
||||
// Since we use the filament selection from Wizard, it's needed to control the preset visibility too
|
||||
if (m_presets[i].is_compatible && m_presets[i].is_visible) {
|
||||
if (m_presets[i].is_compatible) {
|
||||
int this_match_quality = prefered_condition(m_presets[i]);
|
||||
if (this_match_quality > match_quality) {
|
||||
if (match_quality == std::numeric_limits<int>::max())
|
||||
|
@ -644,9 +644,11 @@ public:
|
|||
template<typename PreferedCondition>
|
||||
void update_compatible(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible, PreferedCondition prefered_condition)
|
||||
{
|
||||
if (this->update_compatible_internal(active_printer, active_print, select_other_if_incompatible) == (size_t)-1)
|
||||
if (this->update_compatible_internal(active_printer, active_print, select_other_if_incompatible) == (size_t)-1) {
|
||||
// Find some other compatible preset, or the "-- default --" preset.
|
||||
this->select_preset(this->first_compatible_idx(prefered_condition));
|
||||
size_t index = this->first_compatible_idx(prefered_condition);
|
||||
this->select_preset(index);
|
||||
}
|
||||
}
|
||||
void update_compatible(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible)
|
||||
{ this->update_compatible(active_printer, active_print, select_other_if_incompatible, [](const Preset&) -> int { return 0; }); }
|
||||
|
|
|
@ -1508,6 +1508,7 @@ void PresetBundle::save_changes_for_preset(const std::string& new_name, Preset::
|
|||
|
||||
void PresetBundle::load_installed_filaments(AppConfig &config)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, printer size %1%")%printers.size();
|
||||
//if (! config.has_section(AppConfig::SECTION_FILAMENTS)
|
||||
// || config.get_section(AppConfig::SECTION_FILAMENTS).empty()) {
|
||||
// Compatibility with the PrusaSlicer 2.1.1 and older, where the filament profiles were not installable yet.
|
||||
|
@ -1527,6 +1528,7 @@ void PresetBundle::load_installed_filaments(AppConfig &config)
|
|||
{
|
||||
//already has compatible filament
|
||||
add_default_materials = false;
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1% vendor %2% already has default filament %3%")%printer.name %printer.vendor %filament_iter.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1540,6 +1542,7 @@ void PresetBundle::load_installed_filaments(AppConfig &config)
|
|||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": can not find printer_model for printer %1%")%printer.name;
|
||||
continue;
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1% vendor %2% don't have filament visible, will add %3% default filaments")%printer.name %printer.vendor %printer_model->default_materials.size();
|
||||
for (auto default_filament: printer_model->default_materials)
|
||||
{
|
||||
Preset* filament = filaments.find_preset(default_filament, false, true);
|
||||
|
@ -1552,12 +1555,15 @@ void PresetBundle::load_installed_filaments(AppConfig &config)
|
|||
// compatible_filaments.insert(&filament);
|
||||
}
|
||||
// and mark these filaments as installed, therefore this code will not be executed at the next start of the application.
|
||||
for (const auto &filament: compatible_filaments)
|
||||
for (const auto &filament: compatible_filaments) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": set filament %1% to visible by default")%filament->name;
|
||||
config.set(AppConfig::SECTION_FILAMENTS, filament->name, "true");
|
||||
}
|
||||
//}
|
||||
|
||||
for (auto &preset : filaments)
|
||||
preset.set_visible_from_appconfig(config);
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": exit.");
|
||||
}
|
||||
|
||||
void PresetBundle::load_installed_sla_materials(AppConfig &config)
|
||||
|
@ -4205,6 +4211,8 @@ void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_pri
|
|||
int match_quality = PreferedProfileMatch::operator()(preset);
|
||||
if (match_quality < std::numeric_limits<int>::max()) {
|
||||
match_quality += 1;
|
||||
if (preset.is_visible)
|
||||
match_quality += 1;
|
||||
if (m_prefered_layer_height > 0. && std::abs(preset.config.opt_float("layer_height") - m_prefered_layer_height) < 0.0005)
|
||||
match_quality *= 10;
|
||||
}
|
||||
|
@ -4231,6 +4239,8 @@ void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_pri
|
|||
int match_quality = PreferedProfileMatch::operator()(preset);
|
||||
if (match_quality < std::numeric_limits<int>::max()) {
|
||||
match_quality += 1;
|
||||
if(preset.is_visible)
|
||||
match_quality += 1;
|
||||
if (! m_prefered_filament_type.empty() && m_prefered_filament_type == preset.config.opt_string("filament_type", 0))
|
||||
match_quality *= 10;
|
||||
}
|
||||
|
@ -4288,6 +4298,14 @@ void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_pri
|
|||
filament_preset_was_compatible[idx] = preset != nullptr && preset->is_compatible;
|
||||
}
|
||||
// First select a first compatible profile for the preset editor.
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("prefered filaments: size %1%, previous selected %2%") %prefered_filament_profiles.size() % this->filaments.get_selected_idx();
|
||||
if (this->filaments.get_selected_idx() != size_t(-1))
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("previous selected filament: %1%") % this->filaments.get_edited_preset().name;
|
||||
}
|
||||
for (size_t idx = 0; idx < prefered_filament_profiles.size(); ++idx) {
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("prefered filament: %1%") % prefered_filament_profiles[idx];
|
||||
}
|
||||
this->filaments.update_compatible(printer_preset_with_vendor_profile, &print_preset_with_vendor_profile, select_other_filament_if_incompatible,
|
||||
PreferedFilamentsProfileMatch(this->filaments.get_selected_idx() == size_t(-1) ? nullptr : &this->filaments.get_edited_preset(), prefered_filament_profiles));
|
||||
if (select_other_filament_if_incompatible != PresetSelectCompatibleType::Never) {
|
||||
|
|
Loading…
Reference in New Issue