Some refactoring for ObjectList::remove() for the purpose of getting correct Undo/Redo snapshots

This commit is contained in:
YuSanka 2019-08-23 12:29:47 +02:00
parent 1cf311529a
commit 058a1d9a98

View file

@ -2495,35 +2495,47 @@ void ObjectList::remove()
if (GetSelectedItemsCount() == 0) if (GetSelectedItemsCount() == 0)
return; return;
wxDataViewItemArray sels; auto delete_item = [this](wxDataViewItem item)
GetSelections(sels);
wxDataViewItem parent = wxDataViewItem(0);
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Delete Selected")));
for (auto& item : sels)
{ {
if (m_objects_model->InvalidItem(item)) // item can be deleted for this moment (like last 2 Instances or Volumes) wxDataViewItem parent = m_objects_model->GetParent(item);
continue; if (m_objects_model->GetItemType(item) & itObject)
if (m_objects_model->GetParent(item) == wxDataViewItem(0))
delete_from_model_and_list(itObject, m_objects_model->GetIdByItem(item), -1); delete_from_model_and_list(itObject, m_objects_model->GetIdByItem(item), -1);
else { else {
if (m_objects_model->GetItemType(item) & itLayer) { if (m_objects_model->GetItemType(item) & itLayer) {
parent = m_objects_model->GetParent(item);
wxDataViewItemArray children; wxDataViewItemArray children;
if (m_objects_model->GetChildren(parent, children) == 1) if (m_objects_model->GetChildren(parent, children) == 1)
parent = m_objects_model->GetTopParent(item); parent = m_objects_model->GetTopParent(item);
} }
else if (sels.size() == 1)
select_item(m_objects_model->GetParent(item));
del_subobject_item(item); del_subobject_item(item);
} }
return parent;
};
wxDataViewItemArray sels;
GetSelections(sels);
wxDataViewItem parent = wxDataViewItem(0);
if (sels.Count() == 1)
parent = delete_item(GetSelection());
else
{
Plater::TakeSnapshot snapshot = Plater::TakeSnapshot(wxGetApp().plater(), _(L("Delete Selected")));
for (auto& item : sels)
{
if (m_objects_model->InvalidItem(item)) // item can be deleted for this moment (like last 2 Instances or Volumes)
continue;
parent = delete_item(item);
}
} }
if (parent) if (parent && !m_objects_model->InvalidItem(parent)) {
select_item(parent); select_item(parent);
update_selections_on_canvas();
}
} }
void ObjectList::del_layer_range(const t_layer_height_range& range) void ObjectList::del_layer_range(const t_layer_height_range& range)
@ -2780,8 +2792,12 @@ void ObjectList::update_selections()
} }
else if (m_selection_mode & smLayerRoot) else if (m_selection_mode & smLayerRoot)
sels.Add(m_objects_model->GetLayerRootItem(obj_item)); sels.Add(m_objects_model->GetLayerRootItem(obj_item));
else if (m_selection_mode & smLayer) else if (m_selection_mode & smLayer) {
sels.Add(m_objects_model->GetItemByLayerId(obj_idx, m_selected_layers_range_idx)); if (m_selected_layers_range_idx >= 0)
sels.Add(m_objects_model->GetItemByLayerId(obj_idx, m_selected_layers_range_idx));
else
sels.Add(obj_item);
}
} }
else { else {
for (const auto& object : objects_content) { for (const auto& object : objects_content) {