From 6a6790b8e76848a1cebf6fcb4db250948b448b7a Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 12 Mar 2020 14:50:20 +0100 Subject: [PATCH] Implemented disabling of Add buttons if next layer range couldn't be added + Fixed "Layer ranges" expand. --- src/slic3r/GUI/GUI_ObjectLayers.cpp | 5 +++- src/slic3r/GUI/GUI_ObjectList.cpp | 40 ++++++++++++++++++++++++++--- src/slic3r/GUI/GUI_ObjectList.hpp | 1 + 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectLayers.cpp b/src/slic3r/GUI/GUI_ObjectLayers.cpp index d62bb2727..157e45ab4 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.cpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.cpp @@ -156,8 +156,11 @@ void ObjectLayers::create_layers_list() const t_layer_height_range& range = layer.first; auto del_btn = new PlusMinusButton(m_parent, m_bmp_delete, range); del_btn->SetToolTip(_(L("Remove layer range"))); + auto add_btn = new PlusMinusButton(m_parent, m_bmp_add, range); - add_btn->SetToolTip(_(L("Add layer range"))); + wxString tooltip = wxGetApp().obj_list()->can_add_new_range_after_current(range); + add_btn->SetToolTip(tooltip.IsEmpty() ? _(L("Add layer range")) : tooltip); + add_btn->Enable(tooltip.IsEmpty()); auto sizer = create_layer(range, del_btn, add_btn); sizer->Add(del_btn, 0, wxRIGHT | wxLEFT, em_unit(m_parent)); diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 80c1ce364..5ac22e54a 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -2978,6 +2978,40 @@ void ObjectList::add_layer_range_after_current(const t_layer_height_range curren select_item(layers_item); } +wxString ObjectList::can_add_new_range_after_current(const t_layer_height_range current_range) +{ + wxString ret; + const int obj_idx = get_selected_obj_idx(); + if (obj_idx < 0) + // This should not happen. + return ret; + + t_layer_config_ranges& ranges = object(obj_idx)->layer_config_ranges; + auto it_range = ranges.find(current_range); + assert(it_range != ranges.end()); + if (it_range == ranges.end()) + // This shoudl not happen. + return ret; + + auto it_next_range = it_range; + if (++it_next_range == ranges.end()) + return ret; + + if (const std::pair& next_range = it_next_range->first; current_range.second <= next_range.first) + { + if (current_range.second == next_range.first && + next_range.second - next_range.first < get_min_layer_height(ranges.at(next_range).opt_int("extruder"))) + ret = _(L("A difference between ranges is a less than minimum layer height.")); + } + else + ret = _(L("End of current range is bigger then next one.")); + + if (!ret.IsEmpty()) + ret += "\n" + _(L("New range between them couldn't be added.")); + + return ret; +} + void ObjectList::add_layer_item(const t_layer_height_range& range, const wxDataViewItem layers_item, const int layer_idx /* = -1*/) @@ -3048,12 +3082,10 @@ bool ObjectList::edit_layer_range(const t_layer_height_range& range, const t_lay add_layer_item(r.first, root_item); } - if (dont_update_ui) - return true; + if (!dont_update_ui) + select_item(sel_type&itLayer ? m_objects_model->GetItemByLayerRange(obj_idx, new_range) : root_item); - select_item(sel_type&itLayer ? m_objects_model->GetItemByLayerRange(obj_idx, new_range) : root_item); Expand(root_item); - return true; } diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 0f067d116..adaa31242 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -327,6 +327,7 @@ public: // may have been postponed from the "kill focus" event of a text field, if the focus was lost for the "add layer" button. // Rather providing the range by a value than by a reference, so that the memory referenced cannot be invalidated. void add_layer_range_after_current(const t_layer_height_range current_range); + wxString can_add_new_range_after_current( t_layer_height_range current_range); void add_layer_item (const t_layer_height_range& range, const wxDataViewItem layers_item, const int layer_idx = -1);