ENH: [STUDIO-1608] select support filament by combobox

Change-Id: I26543530202a53ef5753c38404617458a6d4a1ef
This commit is contained in:
chunmao.guo 2022-12-06 18:53:26 +08:00 committed by Lane.Wei
parent 278eab5ae2
commit 41b1ad6f2f
5 changed files with 132 additions and 14 deletions

View file

@ -986,13 +986,46 @@ using choice_ctrl = ::ComboBox; // BBS
using choice_ctrl = ::ComboBox; // BBS
#endif // __WXOSX__
void Choice::BUILD() {
static std::map<std::string, DynamicList*> dynamic_lists;
void Choice::register_dynamic_list(std::string const &optname, DynamicList *list) { dynamic_lists.emplace(optname, list); }
void DynamicList::update()
{
for (auto c : m_choices) apply_on(c);
}
void DynamicList::add_choice(Choice *choice)
{
auto iter = std::find(m_choices.begin(), m_choices.end(), choice);
if (iter != m_choices.end()) return;
apply_on(choice);
m_choices.push_back(choice);
}
void DynamicList::remove_choice(Choice *choice)
{
auto iter = std::find(m_choices.begin(), m_choices.end(), choice);
if (iter != m_choices.end()) m_choices.erase(iter);
}
Choice::~Choice()
{
if (m_list) { m_list->remove_choice(this); }
}
void Choice::BUILD()
{
wxSize size(def_width_wider() * m_em_unit, wxDefaultCoord);
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
choice_ctrl* temp;
if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined && m_opt.gui_type != ConfigOptionDef::GUIType::select_open) {
auto dynamic_list = dynamic_lists.find(m_opt.opt_key);
if (dynamic_list != dynamic_lists.end())
m_list = dynamic_list->second;
if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined && m_opt.gui_type != ConfigOptionDef::GUIType::select_open
&& m_list == nullptr) {
m_is_editable = true;
temp = new choice_ctrl(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size, 0, nullptr, wxTE_PROCESS_ENTER);
}
@ -1051,7 +1084,10 @@ void Choice::BUILD() {
}
}
set_selection();
}
} else if (m_list) {
m_list->add_choice(this);
set_selection();
}
temp->Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent& e) {
if (m_suppress_scroll && !m_is_dropped)
@ -1224,7 +1260,9 @@ void Choice::set_value(const boost::any& value, bool change_event)
break;
++idx;
}
if (idx == enums.size()) {
if (m_list)
field->SetSelection(m_list->index_of(text_value));
else if (idx == enums.size()) {
// For editable Combobox under OSX is needed to set selection to -1 explicitly,
// otherwise selection doesn't be changed
field->SetSelection(-1);
@ -1344,7 +1382,10 @@ boost::any& Choice::get_value()
}
else if (m_opt.gui_type == ConfigOptionDef::GUIType::f_enum_open || m_opt.gui_type == ConfigOptionDef::GUIType::i_enum_open) {
const int ret_enum = field->GetSelection();
if (ret_enum < 0 || m_opt.enum_values.empty() || m_opt.type == coStrings ||
if (m_list) {
ret_str = m_list->get_value(ret_enum);
get_value_by_opt_type(ret_str);
} else if (ret_enum < 0 || m_opt.enum_values.empty() || m_opt.type == coStrings ||
(ret_str != m_opt.enum_values[ret_enum] && ret_str != _(m_opt.enum_labels[ret_enum])))
// modifies ret_string!
get_value_by_opt_type(ret_str);
@ -1802,5 +1843,4 @@ boost::any& SliderCtrl::get_value()
}
} // GUI
} // Slic3r
}} // Slic3r