FIX: the object list order changed after clone

github: 2798
Change-Id: I10a05ee7e00b05cb1255cfb708876ed784cabac7
This commit is contained in:
zhimin.zeng 2024-01-25 16:18:28 +08:00 committed by Lane.Wei
parent 0589348c32
commit 8aabee9982
1 changed files with 8 additions and 1 deletions

View File

@ -1732,6 +1732,13 @@ void Selection::copy_to_clipboard()
m_clipboard.reset(); m_clipboard.reset();
// sort as the object list order
std::vector<unsigned int> selected_list;
selected_list.assign(m_list.begin(), m_list.end());
std::sort(selected_list.begin(), selected_list.end(), [this](unsigned int left, unsigned int right) {
return (*m_volumes)[left]->volume_idx() < (*m_volumes)[right]->volume_idx();
});
for (const ObjectIdxsToInstanceIdxsMap::value_type& object : m_cache.content) for (const ObjectIdxsToInstanceIdxsMap::value_type& object : m_cache.content)
{ {
ModelObject* src_object = m_model->objects[object.first]; ModelObject* src_object = m_model->objects[object.first];
@ -1751,7 +1758,7 @@ void Selection::copy_to_clipboard()
dst_object->add_instance(*src_object->instances[i]); dst_object->add_instance(*src_object->instances[i]);
} }
for (unsigned int i : m_list) for (unsigned int i : selected_list)
{ {
// Copy the ModelVolumes only for the selected GLVolumes of the 1st selected instance. // Copy the ModelVolumes only for the selected GLVolumes of the 1st selected instance.
const GLVolume* volume = (*m_volumes)[i]; const GLVolume* volume = (*m_volumes)[i];