Commit cfd1a0b94de66e029ce1b3940c54e1bf83b759a3
1 parent
b97d82f8
Exists in
master
and in
6 other branches
ADD: Surface removal... finallysvn stsvn st
Showing
4 changed files
with
49 additions
and
41 deletions
Show diff stats
invesalius/data/surface.py
@@ -153,14 +153,9 @@ class SurfaceManager(): | @@ -153,14 +153,9 @@ class SurfaceManager(): | ||
153 | 153 | ||
154 | 154 | ||
155 | def OnRemove(self, pubsub_evt): | 155 | def OnRemove(self, pubsub_evt): |
156 | - print "OnRemove" | ||
157 | selected_items = pubsub_evt.data | 156 | selected_items = pubsub_evt.data |
158 | proj = prj.Project() | 157 | proj = prj.Project() |
159 | 158 | ||
160 | - print "before" | ||
161 | - print "1:", proj.surface_dict | ||
162 | - print "2:", self.actors_dict | ||
163 | - | ||
164 | old_dict = self.actors_dict | 159 | old_dict = self.actors_dict |
165 | new_dict = {} | 160 | new_dict = {} |
166 | if selected_items: | 161 | if selected_items: |
@@ -176,13 +171,12 @@ class SurfaceManager(): | @@ -176,13 +171,12 @@ class SurfaceManager(): | ||
176 | ps.Publisher().sendMessage('Remove surface actor from viewer', actor) | 171 | ps.Publisher().sendMessage('Remove surface actor from viewer', actor) |
177 | self.actors_dict = new_dict | 172 | self.actors_dict = new_dict |
178 | 173 | ||
179 | - print "after" | ||
180 | - print "1", proj.surface_dict | ||
181 | - print "2", self.actors_dict | ||
182 | - print "\n" | ||
183 | - | ||
184 | - | ||
185 | - | 174 | + if self.last_surface_index in selected_items: |
175 | + if self.actors_dict: | ||
176 | + self.last_surface_index = 0 | ||
177 | + else: | ||
178 | + self.last_surface_index = None | ||
179 | + | ||
186 | 180 | ||
187 | def OnSeedSurface(self, pubsub_evt): | 181 | def OnSeedSurface(self, pubsub_evt): |
188 | """ | 182 | """ |
@@ -318,9 +312,8 @@ class SurfaceManager(): | @@ -318,9 +312,8 @@ class SurfaceManager(): | ||
318 | # self.actors_dict. | 312 | # self.actors_dict. |
319 | proj = prj.Project() | 313 | proj = prj.Project() |
320 | surface = proj.surface_dict[index] | 314 | surface = proj.surface_dict[index] |
321 | - | ||
322 | ps.Publisher().sendMessage('Update surface info in GUI', | 315 | ps.Publisher().sendMessage('Update surface info in GUI', |
323 | - (surface.index, surface.name, | 316 | + (index, surface.name, |
324 | surface.colour, surface.volume, | 317 | surface.colour, surface.volume, |
325 | surface.transparency)) | 318 | surface.transparency)) |
326 | self.last_surface_index = index | 319 | self.last_surface_index = index |
@@ -330,7 +323,6 @@ class SurfaceManager(): | @@ -330,7 +323,6 @@ class SurfaceManager(): | ||
330 | 323 | ||
331 | def OnLoadSurfaceDict(self, pubsub_evt): | 324 | def OnLoadSurfaceDict(self, pubsub_evt): |
332 | surface_dict = pubsub_evt.data | 325 | surface_dict = pubsub_evt.data |
333 | - | ||
334 | for key in surface_dict: | 326 | for key in surface_dict: |
335 | surface = surface_dict[key] | 327 | surface = surface_dict[key] |
336 | # Map polygonal data (vtkPolyData) to graphics primitives. | 328 | # Map polygonal data (vtkPolyData) to graphics primitives. |
invesalius/gui/data_notebook.py
@@ -543,9 +543,6 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -543,9 +543,6 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
543 | selected_items = self.GetSelected() | 543 | selected_items = self.GetSelected() |
544 | old_dict = self.surface_list_index | 544 | old_dict = self.surface_list_index |
545 | new_dict = {} | 545 | new_dict = {} |
546 | - print "RemoveSurfaces" | ||
547 | - print "selected_items" | ||
548 | - print "before", self.surface_list_index | ||
549 | if selected_items: | 546 | if selected_items: |
550 | for index in selected_items: | 547 | for index in selected_items: |
551 | self.DeleteItem(index) | 548 | self.DeleteItem(index) |
@@ -560,7 +557,6 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -560,7 +557,6 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
560 | ps.Publisher().sendMessage('Remove surfaces', selected_items) | 557 | ps.Publisher().sendMessage('Remove surfaces', selected_items) |
561 | else: | 558 | else: |
562 | dlg.SurfaceSelectionRequiredForRemoval() | 559 | dlg.SurfaceSelectionRequiredForRemoval() |
563 | - print "after", self.surface_list_index | ||
564 | 560 | ||
565 | 561 | ||
566 | def OnCloseProject(self, pubsub_evt): | 562 | def OnCloseProject(self, pubsub_evt): |
@@ -572,6 +568,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -572,6 +568,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
572 | # Note: DON'T rename to OnItemSelected!!! | 568 | # Note: DON'T rename to OnItemSelected!!! |
573 | # Otherwise the parent's method will be overwritten and other | 569 | # Otherwise the parent's method will be overwritten and other |
574 | # things will stop working, e.g.: OnCheckItem | 570 | # things will stop working, e.g.: OnCheckItem |
571 | + | ||
575 | last_surface_index = evt.m_itemIndex | 572 | last_surface_index = evt.m_itemIndex |
576 | ps.Publisher().sendMessage('Change surface selected', | 573 | ps.Publisher().sendMessage('Change surface selected', |
577 | last_surface_index) | 574 | last_surface_index) |
@@ -588,6 +585,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -588,6 +585,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
588 | # it is important to revert items order, so | 585 | # it is important to revert items order, so |
589 | # listctrl update is ok | 586 | # listctrl update is ok |
590 | selected.sort(reverse=True) | 587 | selected.sort(reverse=True) |
588 | + | ||
591 | return selected | 589 | return selected |
592 | 590 | ||
593 | def __init_columns(self): | 591 | def __init_columns(self): |
@@ -659,28 +657,26 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -659,28 +657,26 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
659 | (index, visibility)) | 657 | (index, visibility)) |
660 | 658 | ||
661 | def AddSurface(self, pubsub_evt): | 659 | def AddSurface(self, pubsub_evt): |
662 | - | ||
663 | - | ||
664 | index = pubsub_evt.data[0] | 660 | index = pubsub_evt.data[0] |
665 | name = pubsub_evt.data[1] | 661 | name = pubsub_evt.data[1] |
666 | colour = pubsub_evt.data[2] | 662 | colour = pubsub_evt.data[2] |
667 | volume = "%d"%(int(pubsub_evt.data[3])) | 663 | volume = "%d"%(int(pubsub_evt.data[3])) |
668 | transparency = "%d%%"%(int(100*pubsub_evt.data[4])) | 664 | transparency = "%d%%"%(int(100*pubsub_evt.data[4])) |
669 | - | ||
670 | - image = self.CreateColourBitmap(colour) | ||
671 | - image_index = self.imagelist.Add(image) | 665 | + |
666 | + if index not in self.surface_list_index: | ||
667 | + image = self.CreateColourBitmap(colour) | ||
668 | + image_index = self.imagelist.Add(image) | ||
672 | 669 | ||
673 | 670 | ||
674 | 671 | ||
675 | - index_list = self.surface_list_index.keys() | ||
676 | - self.surface_list_index[index] = image_index | 672 | + index_list = self.surface_list_index.keys() |
673 | + self.surface_list_index[index] = image_index | ||
677 | 674 | ||
678 | - if (index in index_list) and index_list: | ||
679 | - self.UpdateItemInfo(index, name, volume, transparency, colour) | ||
680 | - else: | ||
681 | - self.InsertNewItem(index, name, volume, transparency, colour) | 675 | + if (index in index_list) and index_list: |
676 | + self.UpdateItemInfo(index, name, volume, transparency, colour) | ||
677 | + else: | ||
678 | + self.InsertNewItem(index, name, volume, transparency, colour) | ||
682 | 679 | ||
683 | - | ||
684 | 680 | ||
685 | 681 | ||
686 | def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3", | 682 | def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3", |
@@ -880,7 +876,6 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -880,7 +876,6 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
880 | 876 | ||
881 | def OnItemActivated(self, evt): | 877 | def OnItemActivated(self, evt): |
882 | self.ToggleItem(evt.m_itemIndex) | 878 | self.ToggleItem(evt.m_itemIndex) |
883 | - print m_itemIndex | ||
884 | 879 | ||
885 | def OnCheckItem(self, index, flag): | 880 | def OnCheckItem(self, index, flag): |
886 | # TODO: use pubsub to communicate to models | 881 | # TODO: use pubsub to communicate to models |
invesalius/gui/task_surface.py
@@ -436,6 +436,26 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) | @@ -436,6 +436,26 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) | ||
436 | ps.Publisher().subscribe(self.ChangeSurfaceName, | 436 | ps.Publisher().subscribe(self.ChangeSurfaceName, |
437 | 'Change surface name') | 437 | 'Change surface name') |
438 | ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') | 438 | ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') |
439 | + ps.Publisher().subscribe(self.OnRemoveSurfaces, 'Remove surfaces') | ||
440 | + | ||
441 | + | ||
442 | + def OnRemoveSurfaces(self, pubsub_evt): | ||
443 | + list_index = pubsub_evt.data | ||
444 | + | ||
445 | + old_dict = self.surface_dict | ||
446 | + new_dict = utl.TwoWaysDictionary() | ||
447 | + for index in list_index: | ||
448 | + self.combo_surface_name.Delete(index) | ||
449 | + | ||
450 | + for name in old_dict: | ||
451 | + if old_dict[name] < index: | ||
452 | + new_dict[name] = old_dict[name] | ||
453 | + if old_dict[name] > index: | ||
454 | + new_dict[name] = old_dict[name] -1 | ||
455 | + old_dict = new_dict | ||
456 | + self.surface_dict = new_dict | ||
457 | + | ||
458 | + | ||
439 | 459 | ||
440 | def OnCloseProject(self, pubsub_evt): | 460 | def OnCloseProject(self, pubsub_evt): |
441 | self.CloseProject() | 461 | self.CloseProject() |
@@ -459,14 +479,14 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) | @@ -459,14 +479,14 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) | ||
459 | name = pubsub_evt.data[1] | 479 | name = pubsub_evt.data[1] |
460 | colour = [value*255 for value in pubsub_evt.data[2]] | 480 | colour = [value*255 for value in pubsub_evt.data[2]] |
461 | overwrite = name in self.surface_dict.keys() | 481 | overwrite = name in self.surface_dict.keys() |
462 | - if not overwrite or not self.surface_dict: | ||
463 | - self.surface_dict[name] = index | ||
464 | - index = self.combo_surface_name.Append(name) | ||
465 | - | ||
466 | - transparency = 100*pubsub_evt.data[4] | ||
467 | - self.button_colour.SetColour(colour) | ||
468 | - self.slider_transparency.SetValue(transparency) | ||
469 | - self.combo_surface_name.SetSelection(index) | 482 | + if index not in self.surface_dict.values(): |
483 | + if not overwrite or not self.surface_dict: | ||
484 | + self.surface_dict[name] = index | ||
485 | + index = self.combo_surface_name.Append(name) | ||
486 | + transparency = 100*pubsub_evt.data[4] | ||
487 | + self.button_colour.SetColour(colour) | ||
488 | + self.slider_transparency.SetValue(transparency) | ||
489 | + self.combo_surface_name.SetSelection(index) | ||
470 | 490 | ||
471 | def OnComboName(self, evt): | 491 | def OnComboName(self, evt): |
472 | surface_name = evt.GetString() | 492 | surface_name = evt.GetString() |
@@ -480,7 +500,6 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) | @@ -480,7 +500,6 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) | ||
480 | colour)) | 500 | colour)) |
481 | 501 | ||
482 | def OnTransparency(self, evt): | 502 | def OnTransparency(self, evt): |
483 | - print evt.GetInt() | ||
484 | transparency = evt.GetInt()/float(MAX_TRANSPARENCY) | 503 | transparency = evt.GetInt()/float(MAX_TRANSPARENCY) |
485 | # FIXME: In Mac OS/X, wx.Slider (wx.Python 2.8.10) has problem on the | 504 | # FIXME: In Mac OS/X, wx.Slider (wx.Python 2.8.10) has problem on the |
486 | # right-limit as reported on http://trac.wxwidgets.org/ticket/4555. | 505 | # right-limit as reported on http://trac.wxwidgets.org/ticket/4555. |
invesalius/project.py
@@ -121,6 +121,7 @@ class Project(object): | @@ -121,6 +121,7 @@ class Project(object): | ||
121 | new_dict[i] = self.mask_dict[i] | 121 | new_dict[i] = self.mask_dict[i] |
122 | if i > index: | 122 | if i > index: |
123 | new_dict[i-1] = self.mask_dict[i] | 123 | new_dict[i-1] = self.mask_dict[i] |
124 | + new_dict[i-1].index = i-1 | ||
124 | self.mask_dict = new_dict | 125 | self.mask_dict = new_dict |
125 | 126 | ||
126 | def GetMask(self, index): | 127 | def GetMask(self, index): |
@@ -143,6 +144,7 @@ class Project(object): | @@ -143,6 +144,7 @@ class Project(object): | ||
143 | new_dict[i] = self.surface_dict[i] | 144 | new_dict[i] = self.surface_dict[i] |
144 | if i > index: | 145 | if i > index: |
145 | new_dict[i-1] = self.surface_dict[i] | 146 | new_dict[i-1] = self.surface_dict[i] |
147 | + new_dict[i-1].index = i-1 | ||
146 | self.surface_dict = new_dict | 148 | self.surface_dict = new_dict |
147 | 149 | ||
148 | def SetAcquisitionModality(self, type_=None): | 150 | def SetAcquisitionModality(self, type_=None): |