Commit ddde2457e3e0f32f81fbd878415974c9c374a4cc
1 parent
c62c2951
Exists in
master
and in
6 other branches
ENH: Surface removel (still needs testing)
Showing
2 changed files
with
58 additions
and
48 deletions
Show diff stats
invesalius/data/surface.py
... | ... | @@ -156,18 +156,33 @@ class SurfaceManager(): |
156 | 156 | print "OnRemove" |
157 | 157 | selected_items = pubsub_evt.data |
158 | 158 | proj = prj.Project() |
159 | - for item in selected_items: | |
160 | - print "before" | |
161 | - print "1:", proj.surface_dict | |
162 | - print "2:", self.actors_dict | |
163 | - proj.RemoveSurface(item) | |
164 | - print "after" | |
165 | - print "1", proj.surface_dict | |
166 | - actor = self.actors_dict[item] | |
167 | - self.actors_dict.pop(item) | |
168 | - print "2", self.actors_dict | |
169 | - print "\n" | |
170 | - ps.Publisher().sendMessage('Remove surface actor from viewer', actor) | |
159 | + | |
160 | + print "before" | |
161 | + print "1:", proj.surface_dict | |
162 | + print "2:", self.actors_dict | |
163 | + | |
164 | + old_dict = self.actors_dict | |
165 | + new_dict = {} | |
166 | + if selected_items: | |
167 | + for index in selected_items: | |
168 | + proj.RemoveSurface(index) | |
169 | + actor = old_dict[index] | |
170 | + for i in old_dict: | |
171 | + if i < index: | |
172 | + new_dict[i] = old_dict[i] | |
173 | + if i > index: | |
174 | + new_dict[i-1] = old_dict[i] | |
175 | + old_dict = new_dict | |
176 | + ps.Publisher().sendMessage('Remove surface actor from viewer', actor) | |
177 | + self.actors_dict = new_dict | |
178 | + | |
179 | + print "after" | |
180 | + print "1", proj.surface_dict | |
181 | + print "2", self.actors_dict | |
182 | + print "\n" | |
183 | + | |
184 | + | |
185 | + | |
171 | 186 | |
172 | 187 | def OnSeedSurface(self, pubsub_evt): |
173 | 188 | """ | ... | ... |
invesalius/gui/data_notebook.py
... | ... | @@ -363,7 +363,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
363 | 363 | return selected |
364 | 364 | |
365 | 365 | |
366 | - | |
366 | +#------------------------------------------------- | |
367 | 367 | #------------------------------------------------- |
368 | 368 | class SurfacePage(wx.Panel): |
369 | 369 | """ |
... | ... | @@ -476,13 +476,8 @@ class SurfaceButtonControlPanel(wx.Panel): |
476 | 476 | ps.Publisher().sendMessage('Create surface', surface_data) |
477 | 477 | |
478 | 478 | def OnRemove(self): |
479 | - selected_items = self.parent.listctrl.GetSelected() | |
480 | - if selected_items: | |
481 | - for item in selected_items: | |
482 | - self.parent.listctrl.RemoveSurface(item) | |
483 | - ps.Publisher().sendMessage('Remove surfaces', selected_items) | |
484 | - else: | |
485 | - dlg.SurfaceSelectionRequiredForRemoval() | |
479 | + self.parent.listctrl.RemoveSurfaces() | |
480 | + | |
486 | 481 | |
487 | 482 | def OnDuplicate(self): |
488 | 483 | selected_items = self.parent.listctrl.GetSelected() |
... | ... | @@ -535,23 +530,38 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
535 | 530 | keycode = event.GetKeyCode() |
536 | 531 | # Delete key |
537 | 532 | if (sys.platform == 'darwin') and (keycode == wx.WXK_BACK): |
538 | - selected = self.GetSelected() | |
539 | - self.__remove_items() | |
540 | - for item in selected: | |
541 | - self.RemoveSurface(item) | |
542 | - | |
533 | + self.RemoveSurfaces() | |
543 | 534 | elif (keycode == wx.WXK_DELETE): |
544 | - selected = self.GetSelected() | |
545 | - self.__remove_items() | |
546 | - for item in selected: | |
547 | - self.RemoveSurface(item) | |
535 | + self.RemoveSurfaces() | |
548 | 536 | |
549 | - def __remove_items(self): | |
537 | + def RemoveSurfaces(self): | |
538 | + """ | |
539 | + Remove item given its index. | |
540 | + """ | |
541 | + # it is necessary to update internal dictionary | |
542 | + # that maps bitmap given item index | |
550 | 543 | selected_items = self.GetSelected() |
544 | + old_dict = self.surface_list_index | |
545 | + new_dict = {} | |
546 | + print "RemoveSurfaces" | |
547 | + print "selected_items" | |
548 | + print "before", self.surface_list_index | |
551 | 549 | if selected_items: |
552 | - for item in selected_items: | |
553 | - self.RemoveSurface(item) | |
550 | + for index in selected_items: | |
551 | + self.DeleteItem(index) | |
552 | + for i in old_dict: | |
553 | + if i < index: | |
554 | + new_dict[i] = old_dict[i] | |
555 | + if i > index: | |
556 | + new_dict[i-1] = old_dict[i] | |
557 | + old_dict = new_dict | |
558 | + self.surface_list_index = new_dict | |
559 | + | |
554 | 560 | ps.Publisher().sendMessage('Remove surfaces', selected_items) |
561 | + else: | |
562 | + dlg.SurfaceSelectionRequiredForRemoval() | |
563 | + print "after", self.surface_list_index | |
564 | + | |
555 | 565 | |
556 | 566 | def OnCloseProject(self, pubsub_evt): |
557 | 567 | self.DeleteAllItems() |
... | ... | @@ -726,24 +736,9 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
726 | 736 | self.imagelist.Replace(image_index, image) |
727 | 737 | self.Refresh() |
728 | 738 | |
729 | - def RemoveSurface(self, index): | |
730 | - """ | |
731 | - Remove item given its index. | |
732 | - """ | |
733 | - # it is necessary to update internal dictionary | |
734 | - # that maps bitmap given item index | |
735 | - old_dict = self.surface_list_index | |
736 | - new_dict = {} | |
737 | - for i in old_dict: | |
738 | - if i < index: | |
739 | - new_dict[i] = old_dict[i] | |
740 | - if i > index: | |
741 | - new_dict[i-1] = old_dict[i] | |
742 | - self.surface_list_index = new_dict | |
743 | - | |
744 | - self.DeleteItem(index) | |
745 | 739 | |
746 | 740 | #------------------------------------------------- |
741 | +#------------------------------------------------- | |
747 | 742 | |
748 | 743 | class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
749 | 744 | # TODO: Change edimixin to affect third column also | ... | ... |