ObjectLayers::del_layer_range() -> delete a layers range using "Del" button from ObjectLayers sizer

This commit is contained in:
YuSanka 2019-05-31 10:54:52 +02:00
parent e531d224e8
commit 38641ef578
6 changed files with 84 additions and 44 deletions

View file

@ -16,8 +16,6 @@ namespace Slic3r
namespace GUI
{
typedef std::map<t_layer_height_range, coordf_t> t_layer_height_ranges;
#define field_width 8
ObjectLayers::ObjectLayers(wxWindow* parent) :
@ -76,7 +74,9 @@ static Line create_new_layer(const t_layer_height_ranges::value_type& layer)
void ObjectLayers::create_layers_list()
{
auto create_btns = [this](wxWindow* parent) {
for (const auto layer : m_object->layer_height_ranges)
{
auto create_btns = [this, layer](wxWindow* parent) {
auto sizer = new wxBoxSizer(wxHORIZONTAL);
auto del_btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete);
@ -84,13 +84,8 @@ void ObjectLayers::create_layers_list()
sizer->Add(del_btn, 0, wxRIGHT, em_unit(parent));
del_btn->Bind(wxEVT_BUTTON, [this](wxEvent &event) {
del_layer();
// wxTheApp->CallAfter([this]() {
// wxWindowUpdateLocker noUpdates(m_parent);
// update_layers_list();
// m_parent->Layout();
// });
del_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) {
wxGetApp().obj_list()->del_layer_range(layer.first);
});
auto add_btn = new ScalableButton(parent, wxID_ANY, m_bmp_add);
@ -98,20 +93,13 @@ void ObjectLayers::create_layers_list()
sizer->Add(add_btn, 0, wxRIGHT, em_unit(parent));
add_btn->Bind(wxEVT_BUTTON, [this](wxEvent &event) {
add_layer();
// wxTheApp->CallAfter([this]() {
// wxWindowUpdateLocker noUpdates(m_parent);
// update_layers_list();
// m_parent->Layout();
// });
add_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) {
wxGetApp().obj_list()->add_layer_range(layer.first);
});
return sizer;
};
for (const auto layer : m_object->layer_height_ranges)
{
Line line = create_new_layer(layer);
line.append_widget(create_btns);
m_og->append_line(line);
@ -122,6 +110,7 @@ void ObjectLayers::create_layer(int id)
{
t_layer_height_ranges::iterator layer_range = m_object->layer_height_ranges.begin();
// May be not a best solution #ys_FIXME
while (id > 0 && layer_range != m_object->layer_height_ranges.end()) {
layer_range++;
id--;

View file

@ -27,8 +27,6 @@ public:
void create_layers_list();
void create_layer(int id);
void update_layers_list();
void add_layer() {};
void del_layer() {};
void UpdateAndShow(const bool show) override;
void msw_rescale();

View file

@ -1812,7 +1812,7 @@ void ObjectList::layers_editing()
wxDataViewItem obj_item = m_objects_model->GetTopParent(item);
wxDataViewItem layers_item = m_objects_model->GetItemByType(obj_item, itLayerRoot);
wxDataViewItem layers_item = m_objects_model->GetLayerRootItem(obj_item);
if (!layers_item.IsOk())
{
// --->>>--- Just for testing
@ -2202,6 +2202,39 @@ void ObjectList::remove()
}
}
void ObjectList::del_layer_range(const std::pair<coordf_t, coordf_t>& range)
{
const int obj_idx = get_selected_obj_idx();
if (obj_idx < 0) return;
t_layer_height_ranges& ranges = object(obj_idx)->layer_height_ranges;
wxDataViewItem selectable_item = GetSelection();
int layer_idx = 0;
if (ranges.size() == 1)
selectable_item = m_objects_model->GetParent(selectable_item);
else {
// May be not a best solution #ys_FIXME
t_layer_height_ranges::iterator layer_selected = ranges.find(range);
t_layer_height_ranges::iterator it = ranges.begin();
while (it != layer_selected) {
it++;
layer_idx++;
}
}
wxDataViewItem layer_item = m_objects_model->GetItemByLayerId(obj_idx, layer_idx);
del_subobject_item(layer_item);
select_item(selectable_item);
}
void ObjectList::add_layer_range(const std::pair<coordf_t, coordf_t>& range)
{
}
void ObjectList::init_objects()
{
m_objects = wxGetApp().model_objects();

View file

@ -270,6 +270,8 @@ public:
// Remove objects/sub-object from the list
void remove();
void del_layer_range(const std::pair<coordf_t, coordf_t>& range);
void add_layer_range(const std::pair<coordf_t, coordf_t>& range);
void init_objects();
bool multiple_selection() const ;

View file

@ -1098,25 +1098,35 @@ wxDataViewItem ObjectDataViewModel::GetItemByVolumeId(int obj_idx, int volume_id
return wxDataViewItem(0);
}
wxDataViewItem ObjectDataViewModel::GetItemByInstanceId(int obj_idx, int inst_idx)
wxDataViewItem ObjectDataViewModel::GetItemById(const int obj_idx, const int sub_obj_idx, const ItemType parent_type)
{
if (obj_idx >= m_objects.size() || obj_idx < 0) {
printf("Error! Out of objects range.\n");
return wxDataViewItem(0);
}
auto instances_item = GetInstanceRootItem(wxDataViewItem(m_objects[obj_idx]));
if (!instances_item)
auto item = GetItemByType(wxDataViewItem(m_objects[obj_idx]), parent_type);
if (!item)
return wxDataViewItem(0);
auto parent = (ObjectDataViewModelNode*)instances_item.GetID();;
auto parent = (ObjectDataViewModelNode*)item.GetID();;
for (size_t i = 0; i < parent->GetChildCount(); i++)
if (parent->GetNthChild(i)->m_idx == inst_idx)
if (parent->GetNthChild(i)->m_idx == sub_obj_idx)
return wxDataViewItem(parent->GetNthChild(i));
return wxDataViewItem(0);
}
wxDataViewItem ObjectDataViewModel::GetItemByInstanceId(int obj_idx, int inst_idx)
{
return GetItemById(obj_idx, inst_idx, itInstanceRoot);
}
wxDataViewItem ObjectDataViewModel::GetItemByLayerId(int obj_idx, int layer_idx)
{
return GetItemById(obj_idx, layer_idx, itLayerRoot);
}
int ObjectDataViewModel::GetIdByItem(const wxDataViewItem& item) const
{
wxASSERT(item.IsOk());
@ -1447,6 +1457,11 @@ wxDataViewItem ObjectDataViewModel::GetInstanceRootItem(const wxDataViewItem &it
return GetItemByType(item, itInstanceRoot);
}
wxDataViewItem ObjectDataViewModel::GetLayerRootItem(const wxDataViewItem &item) const
{
return GetItemByType(item, itLayerRoot);
}
bool ObjectDataViewModel::IsSettingsItem(const wxDataViewItem &item) const
{
if (!item.IsOk())

View file

@ -404,8 +404,10 @@ public:
void DeleteVolumeChildren(wxDataViewItem& parent);
void DeleteSettings(const wxDataViewItem& parent);
wxDataViewItem GetItemById(int obj_idx);
wxDataViewItem GetItemById(const int obj_idx, const int sub_obj_idx, const ItemType parent_type);
wxDataViewItem GetItemByVolumeId(int obj_idx, int volume_idx);
wxDataViewItem GetItemByInstanceId(int obj_idx, int inst_idx);
wxDataViewItem GetItemByLayerId(int obj_idx, int layer_idx);
int GetIdByItem(const wxDataViewItem& item) const;
int GetIdByItemAndType(const wxDataViewItem& item, const ItemType type) const;
int GetObjectIdByItem(const wxDataViewItem& item) const;
@ -460,6 +462,7 @@ public:
ItemType type) const;
wxDataViewItem GetSettingsItem(const wxDataViewItem &item) const;
wxDataViewItem GetInstanceRootItem(const wxDataViewItem &item) const;
wxDataViewItem GetLayerRootItem(const wxDataViewItem &item) const;
bool IsSettingsItem(const wxDataViewItem &item) const;
void UpdateSettingsDigest( const wxDataViewItem &item,
const std::vector<std::string>& categories);