From 54e47bba33433be3602895a26955f81c49c1bebf Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Thu, 9 Feb 2023 14:39:33 +0800 Subject: [PATCH] ENH: support styles to sets Change-Id: I18d4add12907d4d4a10980c1f1244e287934c34c (cherry picked from commit 8ead53319222a2ab4bd76b434afcd657e5045fc7) --- src/slic3r/GUI/ConfigManipulation.cpp | 13 +++++++++++++ src/slic3r/GUI/Field.cpp | 8 ++++---- src/slic3r/GUI/Tab.cpp | 28 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 812883fc6..248568859 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -429,6 +429,19 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con m_support_material_overhangs_queried = false; } + if (config->opt_bool("enable_support")) { + auto support_type = config->opt_enum("support_type"); + auto support_style = config->opt_enum("support_style"); + std::set enum_set_normal = {0, 1, 2}; + std::set enum_set_tree = {0, 3, 4, 5}; + auto & set = is_tree(support_type) ? enum_set_tree : enum_set_normal; + if (set.find(support_style) == set.end()) { + DynamicPrintConfig new_conf = *config; + new_conf.set_key_value("support_style", new ConfigOptionEnum(smsDefault)); + apply(config, &new_conf); + } + } + if (config->option("sparse_infill_density")->value == 100) { std::string sparse_infill_pattern = config->option>("sparse_infill_pattern")->serialize(); const auto &top_fill_pattern_values = config->def()->get("top_surface_pattern")->enum_values; diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 3d09afd56..3bc19396c 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -1291,10 +1291,10 @@ void Choice::set_value(const boost::any& value, bool change_event) if (m_opt_id.compare("host_type") == 0 && val != 0 && m_opt.enum_values.size() > field->GetCount()) // for case, when PrusaLink isn't used as a HostType val--; - if (m_opt_id == "top_surface_pattern" || m_opt_id == "bottom_surface_pattern" || m_opt_id == "sparse_infill_pattern") + if (m_opt_id == "top_surface_pattern" || m_opt_id == "bottom_surface_pattern" || m_opt_id == "sparse_infill_pattern" || m_opt_id == "support_style") { std::string key; - const t_config_enum_values& map_names = ConfigOptionEnum::get_enum_values(); + const t_config_enum_values& map_names = *m_opt.enum_keys_map; for (auto it : map_names) if (val == it.second) { key = it.first; @@ -1370,9 +1370,9 @@ boost::any& Choice::get_value() // BBS if (m_opt.type == coEnum || m_opt.type == coEnums) { - if (m_opt_id == "top_surface_pattern" || m_opt_id == "bottom_surface_pattern" || m_opt_id == "sparse_infill_pattern") { + if (m_opt_id == "top_surface_pattern" || m_opt_id == "bottom_surface_pattern" || m_opt_id == "sparse_infill_pattern" || m_opt_id == "support_style") { const std::string& key = m_opt.enum_values[field->GetSelection()]; - m_value = int(ConfigOptionEnum::get_enum_values().at(key)); + m_value = int(m_opt.enum_keys_map->at(key)); } // Support ThirdPartyPrinter else if (m_opt_id.compare("host_type") == 0 && m_opt.enum_values.size() > field->GetCount()) { diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 9e5ba6f15..17dde95c6 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1416,6 +1416,13 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value) } } + // BBS set support style to default when support type changes + if (opt_key == "support_type") { + DynamicPrintConfig new_conf = *m_config; + new_conf.set_key_value("support_style", new ConfigOptionEnum(smsDefault)); + m_config_manipulation.apply(m_config, &new_conf); + } + // BBS popup a message to ask the user to set optimum parameters for tree support if (opt_key == "support_type" || opt_key == "support_style") { if (is_tree_slim(m_config->opt_enum("support_type"), m_config->opt_enum("support_style")) && @@ -2061,6 +2068,27 @@ void TabPrint::toggle_options() if (!m_active_page) return; m_config_manipulation.toggle_print_fff_options(m_config, m_type < Preset::TYPE_COUNT); + + Field *field = m_active_page->get_field("support_style"); + auto support_type = m_config->opt_enum("support_type"); + if (auto choice = dynamic_cast(field)) { + auto def = print_config_def.get("support_style"); + std::vector enum_set_normal = {0, 1, 2}; + std::vector enum_set_tree = {0, 3, 4, 5}; + auto & set = is_tree(support_type) ? enum_set_tree : enum_set_normal; + auto & opt = const_cast(field->m_opt); + auto cb = dynamic_cast(choice->window); + int n = cb->GetSelection(); + opt.enum_values.clear(); + opt.enum_labels.clear(); + cb->Clear(); + for (auto i : set) { + opt.enum_values.push_back(def->enum_values[i]); + opt.enum_labels.push_back(def->enum_labels[i]); + cb->Append(def->enum_labels[i]); + } + cb->SetSelection(n >= cb->GetCount() ? cb->GetCount() - 1 : n); + } } void TabPrint::update()