Added functions for deleting (sub)objects from model and list at the same time

This commit is contained in:
YuSanka 2018-11-13 14:17:35 +01:00
parent ad8f270796
commit 05e2d33d3f
4 changed files with 63 additions and 1 deletions

View File

@ -823,9 +823,12 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const int
#endif //no __WXOSX__ //__WXMSW__
}
void ObjectList::del_object(const int obj_idx)
{
wxGetApp().plater()->delete_object_from_model(obj_idx);
}
// Delete subobject
void ObjectList::del_subobject_item(wxDataViewItem& item)
{
if (!item) return;
@ -1160,6 +1163,44 @@ void ObjectList::delete_instance_from_list(const size_t obj_idx, const size_t in
select_item(m_objects_model->Delete(m_objects_model->GetItemByInstanceId(obj_idx, inst_idx)));
}
void ObjectList::delete_from_model_and_list(const ItemType type, const int obj_idx, const int sub_obj_idx)
{
if ( !(type&(itObject|itVolume|itInstance)) )
return;
if (type&itObject) {
del_object(obj_idx);
delete_object_from_list(obj_idx);
}
else {
del_subobject_from_object(obj_idx, sub_obj_idx, type);
type == itVolume ? delete_volume_from_list(obj_idx, sub_obj_idx) :
delete_instance_from_list(obj_idx, sub_obj_idx);
}
}
void ObjectList::delete_from_model_and_list(const std::vector<ItemForDelete> * items_for_delete)
{
for (auto& item : *items_for_delete)
{
if ( !(item.type&(itObject|itVolume|itInstance)) )
continue;
if (item.type&itObject) {
del_object(item.obj_idx);
m_objects_model->Delete(m_objects_model->GetItemById(item.obj_idx));
}
else {
del_subobject_from_object(item.obj_idx, item.sub_obj_idx, item.type);
if (item.type&itVolume)
m_objects_model->Delete(m_objects_model->GetItemByVolumeId(item.obj_idx, item.sub_obj_idx));
else
m_objects_model->Delete(m_objects_model->GetItemByInstanceId(item.obj_idx, item.sub_obj_idx));
}
}
part_selection_changed();
}
void ObjectList::delete_all_objects_from_list()
{
m_objects_model->DeleteAll();

View File

@ -5,7 +5,9 @@
#include <wx/dataview.h>
#include <map>
#include <vector>
#include "Event.hpp"
#include "wxExtensions.hpp"
class wxBoxSizer;
class PrusaObjectDataViewModel;
@ -20,6 +22,13 @@ namespace GUI {
wxDECLARE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
struct ItemForDelete
{
ItemType type;
int obj_idx;
int sub_obj_idx;
};
class ObjectList : public wxDataViewCtrl
{
wxBoxSizer *m_sizer {nullptr};
@ -92,6 +101,7 @@ public:
void load_subobject(int type);
void load_part(ModelObject* model_object, wxArrayString& part_names, int type);
void load_generic_subobject(const std::string& type_name, const int type);
void del_object(const int obj_idx);
void del_subobject_item(wxDataViewItem& item);
void del_settings_from_config();
void del_instances_from_object(const int obj_idx);
@ -117,6 +127,8 @@ public:
void delete_object_from_list(const size_t obj_idx);
void delete_volume_from_list(const size_t obj_idx, const size_t vol_idx);
void delete_instance_from_list(const size_t obj_idx, const size_t inst_idx);
void delete_from_model_and_list(const ItemType type, const int obj_idx, const int sub_obj_idx);
void delete_from_model_and_list(const std::vector<ItemForDelete> * items_for_delete);
// Delete all objects from the list
void delete_all_objects_from_list();
// Increase instances count

View File

@ -907,6 +907,7 @@ struct Plater::priv
void object_list_changed();
void remove(size_t obj_idx);
void delete_object_from_model(size_t obj_idx);
void reset();
void mirror(Axis axis);
void arrange();
@ -1436,6 +1437,12 @@ void Plater::priv::remove(size_t obj_idx)
update();
}
void Plater::priv::delete_object_from_model(size_t obj_idx)
{
model.delete_object(obj_idx);
}
void Plater::priv::reset()
{
// Prevent toolpaths preview from rendering while we modify the Print object
@ -2055,6 +2062,7 @@ void Plater::update(bool force_autocenter) { p->update(force_autocenter); }
void Plater::select_view(const std::string& direction) { p->select_view(direction); }
void Plater::remove(size_t obj_idx) { p->remove(obj_idx); }
void Plater::delete_object_from_model(size_t obj_idx) { p->delete_object_from_model(obj_idx); }
void Plater::remove_selected()
{

View File

@ -119,6 +119,7 @@ public:
void select_view(const std::string& direction);
void remove(size_t obj_idx);
void delete_object_from_model(size_t obj_idx);
void remove_selected();
void increase_instances(size_t num = 1);
void decrease_instances(size_t num = 1);