Replace with STL: Fixed update of the item name after replacing

+ OSX specific: Code refactoring for ObjectList:Rename() function
This commit is contained in:
YuSanka 2021-07-14 09:22:03 +02:00
parent 428362ec53
commit 062031a4c6
5 changed files with 55 additions and 18 deletions

View File

@ -595,13 +595,31 @@ void ObjectList::update_name_in_model(const wxDataViewItem& item) const
take_snapshot(volume_id < 0 ? _(L("Rename Object")) : _(L("Rename Sub-object"))); take_snapshot(volume_id < 0 ? _(L("Rename Object")) : _(L("Rename Sub-object")));
ModelObject* obj = object(obj_idx);
if (m_objects_model->GetItemType(item) & itObject) { if (m_objects_model->GetItemType(item) & itObject) {
(*m_objects)[obj_idx]->name = m_objects_model->GetName(item).ToUTF8().data(); obj->name = m_objects_model->GetName(item).ToUTF8().data();
// if object has just one volume, rename this volume too
if (obj->volumes.size() == 1)
obj->volumes[0]->name = obj->name;
return; return;
} }
if (volume_id < 0) return; if (volume_id < 0) return;
(*m_objects)[obj_idx]->volumes[volume_id]->name = m_objects_model->GetName(item).ToUTF8().data(); obj->volumes[volume_id]->name = m_objects_model->GetName(item).ToUTF8().data();
}
void ObjectList::update_name_in_list(int obj_idx, int vol_idx) const
{
if (obj_idx < 0) return;
wxDataViewItem item = GetSelection();
if (!item || !(m_objects_model->GetItemType(item) & (itVolume | itObject)))
return;
wxString new_name = from_u8(object(obj_idx)->volumes[vol_idx]->name);
if (new_name.IsEmpty() || m_objects_model->GetName(item) == new_name)
return;
m_objects_model->SetName(new_name, item);
} }
void ObjectList::selection_changed() void ObjectList::selection_changed()
@ -3746,21 +3764,7 @@ void ObjectList::rename_item()
return; return;
} }
// The icon can't be edited so get its old value and reuse it. if (m_objects_model->SetName(new_name, item))
wxVariant valueOld;
m_objects_model->GetValue(valueOld, item, colName);
DataViewBitmapText bmpText;
bmpText << valueOld;
// But replace the text with the value entered by user.
bmpText.SetText(new_name);
wxVariant value;
value << bmpText;
m_objects_model->SetValue(value, item, colName);
m_objects_model->ItemChanged(item);
update_name_in_model(item); update_name_in_model(item);
} }

View File

@ -202,6 +202,7 @@ public:
void update_extruder_in_config(const wxDataViewItem& item); void update_extruder_in_config(const wxDataViewItem& item);
// update changed name in the object model // update changed name in the object model
void update_name_in_model(const wxDataViewItem& item) const; void update_name_in_model(const wxDataViewItem& item) const;
void update_name_in_list(int obj_idx, int vol_idx) const;
void update_extruder_values_for_items(const size_t max_extruder); void update_extruder_values_for_items(const size_t max_extruder);
// Get obj_idx and vol_idx values for the selected (by default) or an adjusted item // Get obj_idx and vol_idx values for the selected (by default) or an adjusted item

View File

@ -1293,6 +1293,30 @@ void ObjectDataViewModel::SetExtruder(const wxString& extruder, wxDataViewItem i
UpdateVolumesExtruderBitmap(item); UpdateVolumesExtruderBitmap(item);
} }
bool ObjectDataViewModel::SetName(const wxString& new_name, wxDataViewItem item)
{
if (!item.IsOk())
return false;
// The icon can't be edited so get its old value and reuse it.
wxVariant valueOld;
GetValue(valueOld, item, colName);
DataViewBitmapText bmpText;
bmpText << valueOld;
// But replace the text with the value entered by user.
bmpText.SetText(new_name);
wxVariant value;
value << bmpText;
if (SetValue(value, item, colName)) {
ItemChanged(item);
return true;
}
return false;
}
void ObjectDataViewModel::AddAllChildren(const wxDataViewItem& parent) void ObjectDataViewModel::AddAllChildren(const wxDataViewItem& parent)
{ {
ObjectDataViewModelNode* node = static_cast<ObjectDataViewModelNode*>(parent.GetID()); ObjectDataViewModelNode* node = static_cast<ObjectDataViewModelNode*>(parent.GetID());

View File

@ -324,6 +324,7 @@ public:
unsigned int col); unsigned int col);
void SetExtruder(const wxString& extruder, wxDataViewItem item); void SetExtruder(const wxString& extruder, wxDataViewItem item);
bool SetName (const wxString& new_name, wxDataViewItem item);
// For parent move child from cur_volume_id place to new_volume_id // For parent move child from cur_volume_id place to new_volume_id
// Remaining items will moved up/down accordingly // Remaining items will moved up/down accordingly

View File

@ -3284,6 +3284,13 @@ void Plater::priv::replace_with_stl()
old_model_object->ensure_on_bed(); old_model_object->ensure_on_bed();
old_model_object->sort_volumes(wxGetApp().app_config->get("order_volumes") == "1"); old_model_object->sort_volumes(wxGetApp().app_config->get("order_volumes") == "1");
// if object has just one volume, rename object too
if (old_model_object->volumes.size() == 1)
old_model_object->name = old_model_object->volumes[0]->name;
// update new name in ObjectList
sidebar->obj_list()->update_name_in_list(object_idx, volume_idx);
sla::reproject_points_and_holes(old_model_object); sla::reproject_points_and_holes(old_model_object);
// update 3D scene // update 3D scene