Fixed object/part splitting
If object has additional settings and we split it, add this settings for each of the new objects(parts)
This commit is contained in:
parent
95af5c7cc6
commit
4a8b738a6b
3 changed files with 79 additions and 41 deletions
|
@ -898,8 +898,10 @@ bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, con
|
||||||
void ObjectList::split(const bool split_part)
|
void ObjectList::split(const bool split_part)
|
||||||
{
|
{
|
||||||
const auto item = GetSelection();
|
const auto item = GetSelection();
|
||||||
if (!item || m_selected_object_id < 0)
|
const int obj_idx = get_selected_obj_idx();
|
||||||
|
if (!item || obj_idx < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ModelVolume* volume;
|
ModelVolume* volume;
|
||||||
if (!get_volume_by_item(split_part, item, volume)) return;
|
if (!get_volume_by_item(split_part, item, volume)) return;
|
||||||
DynamicPrintConfig& config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
DynamicPrintConfig& config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
||||||
|
@ -909,52 +911,51 @@ void ObjectList::split(const bool split_part)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto model_object = (*m_objects)[m_selected_object_id];
|
auto model_object = (*m_objects)[obj_idx];
|
||||||
|
|
||||||
if (split_part) {
|
auto parent = m_objects_model->GetTopParent(item);
|
||||||
auto parent = m_objects_model->GetParent(item);
|
if (parent)
|
||||||
m_objects_model->DeleteChildren(parent);
|
m_objects_model->DeleteVolumeChildren(parent);
|
||||||
|
else
|
||||||
|
parent = item;
|
||||||
|
|
||||||
for (auto id = 0; id < model_object->volumes.size(); id++)
|
for (auto id = 0; id < model_object->volumes.size(); id++) {
|
||||||
m_objects_model->AddVolumeChild(parent, model_object->volumes[id]->name,
|
const auto vol_item = m_objects_model->AddVolumeChild(parent, model_object->volumes[id]->name,
|
||||||
model_object->volumes[id]->is_modifier() ? ModelVolume::PARAMETER_MODIFIER : ModelVolume::MODEL_PART,
|
model_object->volumes[id]->is_modifier() ?
|
||||||
model_object->volumes[id]->config.has("extruder") ?
|
ModelVolume::PARAMETER_MODIFIER : ModelVolume::MODEL_PART,
|
||||||
model_object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value : 0,
|
model_object->volumes[id]->config.has("extruder") ?
|
||||||
false);
|
model_object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value : 0,
|
||||||
|
false);
|
||||||
Expand(parent);
|
// add settings to the part, if it has those
|
||||||
}
|
auto opt_keys = model_object->volumes[id]->config.keys();
|
||||||
else {
|
if ( !(opt_keys.size() == 1 && opt_keys[0] == "extruder") ) {
|
||||||
for (auto id = 0; id < model_object->volumes.size(); id++)
|
select_item(m_objects_model->AddSettingsChild(vol_item));
|
||||||
m_objects_model->AddVolumeChild(item, model_object->volumes[id]->name,
|
Collapse(vol_item);
|
||||||
ModelVolume::MODEL_PART,
|
}
|
||||||
model_object->volumes[id]->config.has("extruder") ?
|
|
||||||
model_object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value : 0,
|
|
||||||
false);
|
|
||||||
Expand(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_parts_changed = true;
|
m_parts_changed = true;
|
||||||
parts_changed(m_selected_object_id);
|
parts_changed(obj_idx);
|
||||||
|
|
||||||
// restores selection
|
|
||||||
// _3DScene::get_canvas(wxGetApp().canvas3D())->get_selection().add_object(m_selected_object_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectList::get_volume_by_item(const bool split_part, const wxDataViewItem& item, ModelVolume*& volume)
|
bool ObjectList::get_volume_by_item(const bool split_part, const wxDataViewItem& item, ModelVolume*& volume)
|
||||||
{
|
{
|
||||||
if (!item || m_selected_object_id < 0)
|
auto obj_idx = get_selected_obj_idx();
|
||||||
|
if (!item || obj_idx < 0)
|
||||||
return false;
|
return false;
|
||||||
const auto volume_id = m_objects_model->GetVolumeIdByItem(item);
|
const auto volume_id = m_objects_model->GetVolumeIdByItem(item);
|
||||||
|
|
||||||
|
// object is selected
|
||||||
if (volume_id < 0) {
|
if (volume_id < 0) {
|
||||||
if (split_part) return false;
|
if ( split_part || (*m_objects)[obj_idx]->volumes.size() > 1 )
|
||||||
volume = (*m_objects)[m_selected_object_id]->volumes[0];
|
return false;
|
||||||
|
volume = (*m_objects)[obj_idx]->volumes[0];
|
||||||
}
|
}
|
||||||
|
// volume is selected
|
||||||
else
|
else
|
||||||
volume = (*m_objects)[m_selected_object_id]->volumes[volume_id];
|
volume = (*m_objects)[obj_idx]->volumes[volume_id];
|
||||||
if (volume)
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectList::is_splittable_object(const bool split_part)
|
bool ObjectList::is_splittable_object(const bool split_part)
|
||||||
|
@ -962,20 +963,14 @@ bool ObjectList::is_splittable_object(const bool split_part)
|
||||||
const wxDataViewItem item = GetSelection();
|
const wxDataViewItem item = GetSelection();
|
||||||
if (!item) return false;
|
if (!item) return false;
|
||||||
|
|
||||||
wxDataViewItemArray children;
|
|
||||||
if (!split_part && m_objects_model->GetChildren(item, children) > 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ModelVolume* volume;
|
ModelVolume* volume;
|
||||||
if (!get_volume_by_item(split_part, item, volume) || !volume)
|
if (!get_volume_by_item(split_part, item, volume) || !volume)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
TriangleMeshPtrs meshptrs = volume->mesh.split();
|
TriangleMeshPtrs meshptrs = volume->mesh.split();
|
||||||
bool splittable = meshptrs.size() > 1;
|
bool splittable = meshptrs.size() > 1;
|
||||||
for (TriangleMesh* m : meshptrs)
|
for (TriangleMesh* m : meshptrs) { delete m; }
|
||||||
{
|
|
||||||
delete m;
|
|
||||||
}
|
|
||||||
return splittable;
|
return splittable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1076,6 +1071,7 @@ void ObjectList::add_object_to_list(size_t obj_idx)
|
||||||
m_objects_model->SetValue(variant, item, 0);
|
m_objects_model->SetValue(variant, item, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add volumes to the object
|
||||||
if (model_object->volumes.size() > 1) {
|
if (model_object->volumes.size() > 1) {
|
||||||
for (auto id = 0; id < model_object->volumes.size(); id++)
|
for (auto id = 0; id < model_object->volumes.size(); id++)
|
||||||
m_objects_model->AddVolumeChild(item,
|
m_objects_model->AddVolumeChild(item,
|
||||||
|
@ -1086,9 +1082,17 @@ void ObjectList::add_object_to_list(size_t obj_idx)
|
||||||
Expand(item);
|
Expand(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add instances to the object, if it has those
|
||||||
if (model_object->instances.size()>1)
|
if (model_object->instances.size()>1)
|
||||||
increase_object_instances(obj_idx, model_object->instances.size());
|
increase_object_instances(obj_idx, model_object->instances.size());
|
||||||
|
|
||||||
|
// add settings to the object, if it has those
|
||||||
|
auto opt_keys = model_object->config.keys();
|
||||||
|
if ( !(opt_keys.size() == 1 && opt_keys[0] == "extruder") ) {
|
||||||
|
select_item(m_objects_model->AddSettingsChild(item));
|
||||||
|
Collapse(item);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef __WXOSX__
|
#ifndef __WXOSX__
|
||||||
selection_changed();
|
selection_changed();
|
||||||
#endif //__WXMSW__
|
#endif //__WXMSW__
|
||||||
|
|
|
@ -714,6 +714,39 @@ void PrusaObjectDataViewModel::DeleteChildren(wxDataViewItem& parent)
|
||||||
#endif //__WXGTK__
|
#endif //__WXGTK__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrusaObjectDataViewModel::DeleteVolumeChildren(wxDataViewItem& parent)
|
||||||
|
{
|
||||||
|
PrusaObjectDataViewModelNode *root = (PrusaObjectDataViewModelNode*)parent.GetID();
|
||||||
|
if (!root) // happens if item.IsOk()==false
|
||||||
|
return;
|
||||||
|
|
||||||
|
// first remove the node from the parent's array of children;
|
||||||
|
// NOTE: MyObjectTreeModelNodePtrArray is only an array of _pointers_
|
||||||
|
// thus removing the node from it doesn't result in freeing it
|
||||||
|
auto& children = root->GetChildren();
|
||||||
|
for (int id = root->GetChildCount() - 1; id >= 0; --id)
|
||||||
|
{
|
||||||
|
auto node = children[id];
|
||||||
|
if (node->m_type != itVolume)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto item = wxDataViewItem(node);
|
||||||
|
children.RemoveAt(id);
|
||||||
|
root->m_volumes_cnt--;
|
||||||
|
|
||||||
|
// free the node
|
||||||
|
delete node;
|
||||||
|
|
||||||
|
// notify control
|
||||||
|
ItemDeleted(parent, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set m_containet to FALSE if parent has no child
|
||||||
|
#ifndef __WXGTK__
|
||||||
|
root->m_container = false;
|
||||||
|
#endif //__WXGTK__
|
||||||
|
}
|
||||||
|
|
||||||
wxDataViewItem PrusaObjectDataViewModel::GetItemById(int obj_idx)
|
wxDataViewItem PrusaObjectDataViewModel::GetItemById(int obj_idx)
|
||||||
{
|
{
|
||||||
if (obj_idx >= m_objects.size())
|
if (obj_idx >= m_objects.size())
|
||||||
|
|
|
@ -443,6 +443,7 @@ public:
|
||||||
wxDataViewItem DeleteLastInstance(const wxDataViewItem &parent_item, size_t num);
|
wxDataViewItem DeleteLastInstance(const wxDataViewItem &parent_item, size_t num);
|
||||||
void DeleteAll();
|
void DeleteAll();
|
||||||
void DeleteChildren(wxDataViewItem& parent);
|
void DeleteChildren(wxDataViewItem& parent);
|
||||||
|
void DeleteVolumeChildren(wxDataViewItem& parent);
|
||||||
wxDataViewItem GetItemById(int obj_idx);
|
wxDataViewItem GetItemById(int obj_idx);
|
||||||
wxDataViewItem GetItemByVolumeId(int obj_idx, int volume_idx);
|
wxDataViewItem GetItemByVolumeId(int obj_idx, int volume_idx);
|
||||||
wxDataViewItem GetItemByInstanceId(int obj_idx, int inst_idx);
|
wxDataViewItem GetItemByInstanceId(int obj_idx, int inst_idx);
|
||||||
|
|
Loading…
Reference in a new issue