mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-29 07:43:15 +08:00
ENH: UnsavedChangesDialog support extruder variant
Change-Id: Ifd021461d23b385b71dedbe9cc864eeee1a2541b Jira: STUDIO-7711
This commit is contained in:
parent
c49c0c8f72
commit
2aed1142ec
@ -94,7 +94,7 @@ void OptionsSearcher::append_options(DynamicPrintConfig *config, Preset::Type ty
|
||||
|
||||
int cnt = 0;
|
||||
|
||||
if ((type == Preset::TYPE_SLA_MATERIAL || type == Preset::TYPE_PRINTER) && opt_key != "printable_area")
|
||||
if ((type == Preset::TYPE_SLA_MATERIAL || type == Preset::TYPE_PRINTER || type == Preset::TYPE_PRINT) && opt_key != "printable_area")
|
||||
switch (config->option(opt_key)->type()) {
|
||||
case coInts: change_opt_key<ConfigOptionInts>(opt_key, config, cnt); break;
|
||||
case coBools: change_opt_key<ConfigOptionBools>(opt_key, config, cnt); break;
|
||||
@ -107,6 +107,9 @@ void OptionsSearcher::append_options(DynamicPrintConfig *config, Preset::Type ty
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (type == Preset::TYPE_FILAMENT && filament_options_with_variant.find(opt_key) != filament_options_with_variant.end())
|
||||
opt_key += "#0";
|
||||
|
||||
wxString label = opt.full_label.empty() ? opt.label : opt.full_label;
|
||||
|
||||
std::string key = get_key(opt_key, type);
|
||||
@ -209,12 +212,12 @@ bool OptionsSearcher::search(const std::string &search, bool force /* = false*/,
|
||||
if (full_list) {
|
||||
std::string label = into_u8(get_label(opt));
|
||||
//all
|
||||
if (type == Preset::TYPE_INVALID) {
|
||||
if (type == Preset::TYPE_INVALID) {
|
||||
found.emplace_back(FoundOption{label, label, boost::nowide::narrow(get_tooltip(opt)), i, 0});
|
||||
} else if (type == opt.type){
|
||||
found.emplace_back(FoundOption{label, label, boost::nowide::narrow(get_tooltip(opt)), i, 0});
|
||||
}
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -257,7 +260,7 @@ bool OptionsSearcher::search(const std::string &search, bool force /* = false*/,
|
||||
} else if (type == opt.type) {
|
||||
found.emplace_back(FoundOption{label_plain, label_u8, boost::nowide::narrow(get_tooltip(opt)), i, score});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,12 +304,34 @@ const Option &OptionsSearcher::get_option(size_t pos_in_filter) const
|
||||
return options[found[pos_in_filter].option_idx];
|
||||
}
|
||||
|
||||
const Option &OptionsSearcher::get_option(const std::string &opt_key, Preset::Type type) const
|
||||
const Option &OptionsSearcher::get_option(const std::string &opt_key, Preset::Type type, int &variant_index) const
|
||||
{
|
||||
auto it = std::lower_bound(options.begin(), options.end(), Option({boost::nowide::widen(get_key(opt_key, type))}));
|
||||
std::string opt_key2 = opt_key;
|
||||
if (auto n = opt_key.find('#'); n != std::string::npos) {
|
||||
variant_index = std::atoi(opt_key.c_str() + n + 1);
|
||||
opt_key2 = opt_key.substr(0, n);
|
||||
}
|
||||
auto it = std::lower_bound(options.begin(), options.end(), Option({boost::nowide::widen(get_key(opt_key2, type))}));
|
||||
// BBS: return the 0th option when not found in searcher caused by mode difference
|
||||
// assert(it != options.end());
|
||||
if (it == options.end()) return options[0];
|
||||
if (it->opt_key() == opt_key2) {
|
||||
variant_index = -1;
|
||||
} else if (it->opt_key() != opt_key) {
|
||||
auto it2 = it;
|
||||
while (it2 != options.end() && it2->opt_key() != opt_key && it2->opt_key().compare(0, opt_key2.length(), opt_key2) == 0)
|
||||
++it2;
|
||||
if (it2->opt_key() == opt_key)
|
||||
it = it2;
|
||||
if (it2 == it)
|
||||
variant_index = -2;
|
||||
} else {
|
||||
auto it2 = it;
|
||||
++it2;
|
||||
if (it2 != options.end() && it2->opt_key().compare(0, opt_key2.length(), opt_key2) == 0
|
||||
&& printer_options_with_variant_1.find(opt_key2) == printer_options_with_variant_1.end())
|
||||
variant_index = -2;
|
||||
}
|
||||
|
||||
return options[it - options.begin()];
|
||||
}
|
||||
@ -434,7 +459,7 @@ void SearchItem::OnPaint(wxPaintEvent &event)
|
||||
int left = 20;
|
||||
|
||||
auto bold_pair = std::vector<std::pair<int, int>>();
|
||||
|
||||
|
||||
auto index = 0;
|
||||
|
||||
auto b_first_list = std::vector<int>();
|
||||
@ -473,19 +498,19 @@ void SearchItem::OnPaint(wxPaintEvent &event)
|
||||
auto inset = false;
|
||||
auto pair_index = 0;
|
||||
for (auto o = 0; o < bold_pair.size(); o++) {
|
||||
if (c >= bold_pair[o].first && c <= bold_pair[o].second) {
|
||||
if (c >= bold_pair[o].first && c <= bold_pair[o].second) {
|
||||
pair_index = o;
|
||||
inset = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inset) {
|
||||
if (!inset) {
|
||||
left += DrawTextString(dc, str, wxPoint(left, top), false).GetWidth();
|
||||
} else {
|
||||
//str = str.erase(bold_pair[pair_index].first, 3);
|
||||
//str = str.erase(bold_pair[pair_index].second, 4);
|
||||
if (c - bold_pair[pair_index].first >= 3 && bold_pair[pair_index].second - c > 3) {
|
||||
if (c - bold_pair[pair_index].first >= 3 && bold_pair[pair_index].second - c > 3) {
|
||||
left += DrawTextString(dc, str, wxPoint(left, top), true).GetWidth();
|
||||
}
|
||||
}
|
||||
@ -538,7 +563,7 @@ static const std::map<const char, int> icon_idxs = {
|
||||
{ImGui::PrintIconMarker, 0}, {ImGui::PrinterIconMarker, 1}, {ImGui::PrinterSlaIconMarker, 2}, {ImGui::FilamentIconMarker, 3}, {ImGui::MaterialIconMarker, 4},
|
||||
};
|
||||
|
||||
SearchDialog::SearchDialog(OptionsSearcher *searcher, Preset::Type type, wxWindow *parent, TextInput *input, wxWindow *search_btn)
|
||||
SearchDialog::SearchDialog(OptionsSearcher *searcher, Preset::Type type, wxWindow *parent, TextInput *input, wxWindow *search_btn)
|
||||
: PopupWindow(parent, wxBORDER_NONE | wxPU_CONTAINS_CONTROLS), searcher(searcher)
|
||||
{
|
||||
m_event_tag = parent;
|
||||
@ -674,7 +699,7 @@ void SearchDialog::Dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
void SearchDialog::Die()
|
||||
void SearchDialog::Die()
|
||||
{
|
||||
PopupWindow::Dismiss();
|
||||
wxCommandEvent event(wxCUSTOMEVT_EXIT_SEARCH);
|
||||
|
@ -132,7 +132,7 @@ public:
|
||||
|
||||
const FoundOption &operator[](const size_t pos) const noexcept { return found[pos]; }
|
||||
const Option & get_option(size_t pos_in_filter) const;
|
||||
const Option & get_option(const std::string &opt_key, Preset::Type type) const;
|
||||
const Option & get_option(const std::string &opt_key, Preset::Type type, int &variant_index) const;
|
||||
Option get_option(const std::string &opt_key, const wxString &label, Preset::Type type) const;
|
||||
|
||||
const std::vector<FoundOption> &found_options() { return found; }
|
||||
|
@ -5915,7 +5915,7 @@ void Tab::switch_excluder(int extruder_id, bool reload)
|
||||
}
|
||||
page->m_opt_id_map.clear();
|
||||
for (auto group : page->m_optgroups) {
|
||||
if (is_extruder && group->title == "Type") {
|
||||
if (is_extruder && (group->title == "Type" || group->title == "Layer height limits" || group->title == "Position")) {
|
||||
for (auto &opt : group->opt_map())
|
||||
page->m_opt_id_map.insert({opt.first, opt.first});
|
||||
continue;
|
||||
|
@ -602,7 +602,7 @@ DiffViewCtrl::DiffViewCtrl(wxWindow* parent, wxSize size)
|
||||
this->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &DiffViewCtrl::item_value_changed, this);
|
||||
}
|
||||
|
||||
DiffViewCtrl::~DiffViewCtrl() {
|
||||
DiffViewCtrl::~DiffViewCtrl() {
|
||||
this->AssociateModel(nullptr);
|
||||
delete model;
|
||||
}
|
||||
@ -830,7 +830,7 @@ UnsavedChangesDialog::UnsavedChangesDialog(Preset::Type type, PresetCollection *
|
||||
|
||||
inline int UnsavedChangesDialog::ShowModal()
|
||||
{
|
||||
auto choise_key = "save_preset_choise";
|
||||
auto choise_key = "save_preset_choise";
|
||||
auto choise = wxGetApp().app_config->get(choise_key);
|
||||
long result = 0;
|
||||
if ((m_buttons & REMEMBER_CHOISE) && !choise.empty() && wxString(choise).ToLong(&result) && (1 << result) & (m_buttons | DONT_SAVE)) {
|
||||
@ -1444,7 +1444,7 @@ void UnsavedChangesDialog::update(Preset::Type type, PresetCollection* dependent
|
||||
else
|
||||
action_msg += _L("\nYou can save or discard the preset values you have modified.");
|
||||
}
|
||||
|
||||
|
||||
m_action_line->SetLabel(action_msg);
|
||||
|
||||
update_tree(type, presets);
|
||||
@ -1459,21 +1459,23 @@ void UnsavedChangesDialog::update_list()
|
||||
|
||||
// group
|
||||
for (auto i = 0; i < m_presetitems.size(); i++) {
|
||||
if (class_g_list.count(m_presetitems[i].group_name) <= 0) {
|
||||
auto name = m_presetitems[i].category_name + ":" + m_presetitems[i].group_name;
|
||||
if (class_g_list.count(name) <= 0) {
|
||||
std::vector<PresetItem> vp;
|
||||
vp.push_back(m_presetitems[i]);
|
||||
class_g_list.emplace(m_presetitems[i].group_name, vp);
|
||||
class_g_list.emplace(name, vp);
|
||||
} else {
|
||||
//for (auto iter = class_g_list.begin(); iter != class_g_list.end(); iter++) iter->second.push_back(m_presetitems[i]);
|
||||
class_g_list[m_presetitems[i].group_name].push_back(m_presetitems[i]);
|
||||
class_g_list[name].push_back(m_presetitems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// category
|
||||
for (auto i = 0; i < m_presetitems.size(); i++) {
|
||||
auto name = m_presetitems[i].category_name + ":" + m_presetitems[i].group_name;
|
||||
if (class_c_list.count(m_presetitems[i].category_name) <= 0) {
|
||||
std::vector<wxString> vp;
|
||||
vp.push_back(m_presetitems[i].group_name);
|
||||
vp.push_back(name);
|
||||
class_c_list.emplace(m_presetitems[i].category_name, vp);
|
||||
category_list.push_back(m_presetitems[i].category_name);
|
||||
} else {
|
||||
@ -1481,9 +1483,9 @@ void UnsavedChangesDialog::update_list()
|
||||
iter->second.push_back(m_presetitems[i].group_name);*/
|
||||
//class_c_list[m_presetitems[i].category_name].push_back(m_presetitems[i].group_name);
|
||||
std::vector<wxString>::iterator it;
|
||||
it = find(class_c_list[m_presetitems[i].category_name].begin(), class_c_list[m_presetitems[i].category_name].end(), m_presetitems[i].group_name);
|
||||
it = find(class_c_list[m_presetitems[i].category_name].begin(), class_c_list[m_presetitems[i].category_name].end(), name);
|
||||
if (it == class_c_list[m_presetitems[i].category_name].end()) {
|
||||
class_c_list[m_presetitems[i].category_name].push_back(m_presetitems[i].group_name);
|
||||
class_c_list[m_presetitems[i].category_name].push_back(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1535,7 +1537,7 @@ void UnsavedChangesDialog::update_list()
|
||||
|
||||
wxBoxSizer *sizer_left_v = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
auto text_left = new wxStaticText(panel_left, wxID_ANY, gname, wxDefaultPosition, wxSize(-1, -1), 0);
|
||||
auto text_left = new wxStaticText(panel_left, wxID_ANY, class_g_list[gname][0].group_name, wxDefaultPosition, wxSize(-1, -1), 0);
|
||||
text_left->SetFont(::Label::Head_13);
|
||||
text_left->Wrap(-1);
|
||||
#ifdef __linux__
|
||||
@ -1637,7 +1639,7 @@ void UnsavedChangesDialog::update_list()
|
||||
wxSize text_size = m_action_line->GetTextExtent(m_action_line->GetLabel());
|
||||
int width = UNSAVE_CHANGE_DIALOG_ACTION_LINE_SIZE.GetWidth();
|
||||
// +2: Ensure that there is at least one line and that the content contains '\n'
|
||||
int rows = int(text_size.GetWidth() / width) + 2;
|
||||
int rows = int(text_size.GetWidth() / width) + 2;
|
||||
int height = rows * text_size.GetHeight();
|
||||
m_action_line->SetMinSize(wxSize(width, height));
|
||||
Layout();
|
||||
@ -1686,7 +1688,7 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
|
||||
//m_tree->model->AddPreset(type, from_u8(presets->get_edited_preset().name), old_pt);
|
||||
|
||||
// Collect dirty options.
|
||||
const bool deep_compare = (type == Preset::TYPE_PRINTER || type == Preset::TYPE_SLA_MATERIAL);
|
||||
const bool deep_compare = (type == Preset::TYPE_PRINTER || type == Preset::TYPE_PRINT || type == Preset::TYPE_FILAMENT || type == Preset::TYPE_SLA_MATERIAL);
|
||||
auto dirty_options = presets->current_dirty_options(deep_compare);
|
||||
|
||||
// process changes of extruders count
|
||||
@ -1704,14 +1706,30 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
|
||||
m_presetitems.push_back(pi);
|
||||
}
|
||||
|
||||
auto variant_key = Preset::get_iot_type_string(type) + "_extruder_variant";
|
||||
auto id_key = Preset::get_iot_type_string(type) + "_extruder_id";
|
||||
auto extruder_variant = dynamic_cast<ConfigOptionStrings const *>(old_config.option(variant_key));
|
||||
auto extruder_id = dynamic_cast<ConfigOptionInts const *>(old_config.option(id_key));
|
||||
|
||||
for (const std::string& opt_key : dirty_options) {
|
||||
const Search::Option& option = searcher.get_option(opt_key, type);
|
||||
if (option.opt_key() != opt_key) {
|
||||
int variant_index = -2;
|
||||
const Search::Option &option = searcher.get_option(opt_key, type, variant_index);
|
||||
if (option.opt_key() != opt_key && variant_index < -1) {
|
||||
// When founded option isn't the correct one.
|
||||
// It can be for dirty_options: "default_print_profile", "printer_model", "printer_settings_id",
|
||||
// because of they don't exist in searcher
|
||||
continue;
|
||||
}
|
||||
auto category = option.category_local;
|
||||
if (variant_index >= 0) {
|
||||
if (boost::nowide::narrow(category).find("Extruder ") == 0)
|
||||
category = category.substr(0, 8);
|
||||
if (extruder_id)
|
||||
category = category + (wxString(" {") + (extruder_id->values[variant_index] == 1 ? _L("Left: ") : _L("Right: "))
|
||||
+ L(extruder_variant->values[variant_index]) + "}");
|
||||
else
|
||||
category = category + (" {" + L(extruder_variant->values[variant_index]) + "}");
|
||||
}
|
||||
|
||||
/*m_tree->Append(opt_key, type, option.category_local, option.group_local, option.label_local,
|
||||
get_string_value(opt_key, old_config), get_string_value(opt_key, new_config), category_icon_map.at(option.category));*/
|
||||
@ -1719,7 +1737,7 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
|
||||
|
||||
//PresetItem pi = {opt_key, type, 1983};
|
||||
//m_presetitems.push_back()
|
||||
PresetItem pi = {type, opt_key, option.category_local, option.group_local, option.label_local, get_string_value(opt_key, old_config), get_string_value(opt_key, new_config)};
|
||||
PresetItem pi = {type, opt_key, category, option.group_local, option.label_local, get_string_value(opt_key, old_config), get_string_value(opt_key, new_config)};
|
||||
m_presetitems.push_back(pi);
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user