Skip to content

Commit

Permalink
FIX: fix the crash issue when dragging object in seq-print
Browse files Browse the repository at this point in the history
Change-Id: If2fd7e2d4d41e6cde6c8d4824cf489e10700c91e
  • Loading branch information
lanewei120 committed Dec 15, 2022
1 parent 941df8b commit 81e7237
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/slic3r/GUI/ObjectDataViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,14 +1720,21 @@ wxDataViewItem ObjectDataViewModel::ReorganizeObjects( const int current_id, co
return wxDataViewItem(nullptr);

ObjectDataViewModelNode* deleted_node = m_objects[current_id];
ObjectDataViewModelNode* new_node = m_objects[new_id];
ObjectDataViewModelNode* plate_node = deleted_node->m_parent;

m_objects.erase(m_objects.begin() + current_id);
plate_node->GetChildren().Remove(deleted_node);
ItemDeleted(wxDataViewItem(deleted_node->m_parent), wxDataViewItem(deleted_node));

m_objects.emplace(m_objects.begin() + new_id, deleted_node);
plate_node->Insert(deleted_node, new_id);
int plate_child_index = plate_node->GetChildIndex(new_node);
if (current_id < new_id)
plate_node->Insert(deleted_node, plate_child_index+1);
else {
//should not happen
plate_node->Insert(deleted_node, plate_child_index);
}
ItemAdded(wxDataViewItem(deleted_node->m_parent), wxDataViewItem(deleted_node));

//ItemChanged(wxDataViewItem(nullptr));
Expand Down
12 changes: 12 additions & 0 deletions src/slic3r/GUI/ObjectDataViewModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ class ObjectDataViewModelNode
{
return m_children.Item(n);
}

int GetChildIndex(ObjectDataViewModelNode* child) const
{
size_t child_count = GetChildCount();
for (int index = 0; index < child_count; index++)
{
if (m_children.Item(index) == child)
return index;
}
return -1;
}

void Insert(ObjectDataViewModelNode* child, unsigned int n)
{
if (!m_container)
Expand Down

0 comments on commit 81e7237

Please sign in to comment.