"Delete part" button works correctly
Prepared functions for "Split", "MoveUp" & "MoveDown" buttons (update_model function is missing)
This commit is contained in:
parent
99082bfe67
commit
12232f1a6d
4 changed files with 101 additions and 14 deletions
|
@ -148,28 +148,22 @@ wxBoxSizer* content_edit_object_buttons(wxWindow* win)
|
|||
m_btn_move_down = new wxButton(win, wxID_ANY, "", wxDefaultPosition, wxDefaultSize/*wxSize(30, -1)*/, wxBU_LEFT);
|
||||
|
||||
//*** button's functions
|
||||
btn_load_part->Bind(wxEVT_BUTTON, [win](wxEvent&)
|
||||
{
|
||||
btn_load_part->Bind(wxEVT_BUTTON, [win](wxEvent&) {
|
||||
on_btn_load(win);
|
||||
});
|
||||
|
||||
btn_load_modifier->Bind(wxEVT_BUTTON, [win](wxEvent&)
|
||||
{
|
||||
btn_load_modifier->Bind(wxEVT_BUTTON, [win](wxEvent&) {
|
||||
on_btn_load(win, true);
|
||||
});
|
||||
|
||||
btn_load_lambda_modifier->Bind(wxEVT_BUTTON, [win](wxEvent&)
|
||||
{
|
||||
btn_load_lambda_modifier->Bind(wxEVT_BUTTON, [win](wxEvent&) {
|
||||
on_btn_load(win, true, true);
|
||||
});
|
||||
|
||||
btn_delete->Bind(wxEVT_BUTTON, [](wxEvent&)
|
||||
{
|
||||
auto item = m_objects_ctrl->GetSelection();
|
||||
if (!item) return;
|
||||
m_objects_ctrl->Select(m_objects_model->Delete(item));
|
||||
parts_changed(m_selected_object_id);
|
||||
});
|
||||
btn_delete ->Bind(wxEVT_BUTTON, [](wxEvent&) { on_btn_del(); });
|
||||
btn_split ->Bind(wxEVT_BUTTON, [](wxEvent&) { on_btn_split(); });
|
||||
m_btn_move_up ->Bind(wxEVT_BUTTON, [](wxEvent&) { on_btn_move_up(); });
|
||||
m_btn_move_down ->Bind(wxEVT_BUTTON, [](wxEvent&) { on_btn_move_down(); });
|
||||
//***
|
||||
|
||||
m_btn_move_up->SetMinSize(wxSize(20, -1));
|
||||
|
@ -554,6 +548,82 @@ void on_btn_load(wxWindow* parent, bool is_modifier /*= false*/, bool is_lambda/
|
|||
is_modifier ? m_icon_modifiermesh : m_icon_solidmesh));
|
||||
}
|
||||
|
||||
void on_btn_del()
|
||||
{
|
||||
auto item = m_objects_ctrl->GetSelection();
|
||||
if (!item) return;
|
||||
|
||||
auto volume_id = m_objects_model->GetVolumeIdByItem(item);
|
||||
if (volume_id < 0)
|
||||
return;
|
||||
auto volume = m_objects[m_selected_object_id]->volumes[volume_id];
|
||||
|
||||
// if user is deleting the last solid part, throw error
|
||||
int solid_cnt = 0;
|
||||
for (auto vol : m_objects[m_selected_object_id]->volumes)
|
||||
if (!vol->modifier)
|
||||
++solid_cnt;
|
||||
if (!volume->modifier && solid_cnt == 1) {
|
||||
Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last solid part from this object.")));
|
||||
return;
|
||||
}
|
||||
|
||||
m_objects_ctrl->Select(m_objects_model->Delete(item));
|
||||
m_objects[m_selected_object_id]->delete_volume(volume_id);
|
||||
m_parts_changed = true;
|
||||
|
||||
parts_changed(m_selected_object_id);
|
||||
}
|
||||
|
||||
void on_btn_split()
|
||||
{
|
||||
auto item = m_objects_ctrl->GetSelection();
|
||||
if (!item)
|
||||
return;
|
||||
auto volume_id = m_objects_model->GetVolumeIdByItem(item);
|
||||
if (volume_id < 0)
|
||||
return;
|
||||
|
||||
auto volume = m_objects[m_selected_object_id]->volumes[volume_id];
|
||||
DynamicPrintConfig& config = get_preset_bundle()->prints.get_edited_preset().config;
|
||||
auto nozzle_dmrs_cnt = config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
|
||||
if (volume->split(nozzle_dmrs_cnt) > 1) {
|
||||
// TODO update model
|
||||
m_parts_changed = true;
|
||||
parts_changed(m_selected_object_id);
|
||||
}
|
||||
}
|
||||
|
||||
void on_btn_move_up(){
|
||||
auto item = m_objects_ctrl->GetSelection();
|
||||
if (!item)
|
||||
return;
|
||||
auto volume_id = m_objects_model->GetVolumeIdByItem(item);
|
||||
if (volume_id < 0)
|
||||
return;
|
||||
auto& volumes = m_objects[m_selected_object_id]->volumes;
|
||||
if (0 < volume_id && volume_id < volumes.size()) {
|
||||
std::swap(volumes[volume_id - 1], volumes[volume_id]);
|
||||
m_parts_changed = true;
|
||||
// TODO update model ($volume_id - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void on_btn_move_down(){
|
||||
auto item = m_objects_ctrl->GetSelection();
|
||||
if (!item)
|
||||
return;
|
||||
auto volume_id = m_objects_model->GetVolumeIdByItem(item);
|
||||
if (volume_id < 0)
|
||||
return;
|
||||
auto& volumes = m_objects[m_selected_object_id]->volumes;
|
||||
if (0 <= volume_id && volume_id+1 < volumes.size()) {
|
||||
std::swap(volumes[volume_id + 1], volumes[volume_id - 1]);
|
||||
m_parts_changed = true;
|
||||
// TODO update model ($volume_id - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void parts_changed(int obj_idx)
|
||||
{
|
||||
if (m_event_object_settings_changed <= 0) return;
|
||||
|
|
|
@ -71,6 +71,10 @@ void load_lambda(wxWindow* parent, ModelObject* model_object,
|
|||
wxArrayString& part_names, const bool is_modifier);
|
||||
|
||||
void on_btn_load(wxWindow* parent, bool is_modifier = false, bool is_lambda = false);
|
||||
void on_btn_del();
|
||||
void on_btn_split();
|
||||
void on_btn_move_up();
|
||||
void on_btn_move_down();
|
||||
|
||||
void parts_changed(int obj_idx);
|
||||
void part_selection_changed();
|
||||
|
|
|
@ -407,11 +407,21 @@ wxDataViewItem PrusaObjectDataViewModel::Delete(const wxDataViewItem &item)
|
|||
// thus removing the node from it doesn't result in freeing it
|
||||
if (node_parent){
|
||||
auto id = node_parent->GetChildren().Index(node);
|
||||
auto v_id = node->GetVolumeId();
|
||||
node_parent->GetChildren().Remove(node);
|
||||
if (id > 0){
|
||||
if(id == node_parent->GetChildCount()) id--;
|
||||
ret_item = wxDataViewItem(node_parent->GetChildren().Item(id));
|
||||
}
|
||||
|
||||
//update volume_id value for remaining child-nodes
|
||||
auto children = node_parent->GetChildren();
|
||||
for (size_t i = 0; i < node_parent->GetChildCount(); i++)
|
||||
{
|
||||
auto volume_id = children[i]->GetVolumeId();
|
||||
if (volume_id > v_id)
|
||||
children[i]->SetVolumeId(volume_id-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -276,7 +276,10 @@ public:
|
|||
return m_type;
|
||||
}
|
||||
|
||||
const int GetVolumeId(){
|
||||
void SetVolumeId(const int& volume_id){
|
||||
m_volume_id = volume_id;
|
||||
}
|
||||
const int& GetVolumeId(){
|
||||
return m_volume_id;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue