Commit cfd1a0b94de66e029ce1b3940c54e1bf83b759a3
1 parent
b97d82f8
Exists in
master
and in
68 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 | 153 | |
| 154 | 154 | |
| 155 | 155 | def OnRemove(self, pubsub_evt): |
| 156 | - print "OnRemove" | |
| 157 | 156 | selected_items = pubsub_evt.data |
| 158 | 157 | proj = prj.Project() |
| 159 | 158 | |
| 160 | - print "before" | |
| 161 | - print "1:", proj.surface_dict | |
| 162 | - print "2:", self.actors_dict | |
| 163 | - | |
| 164 | 159 | old_dict = self.actors_dict |
| 165 | 160 | new_dict = {} |
| 166 | 161 | if selected_items: |
| ... | ... | @@ -176,13 +171,12 @@ class SurfaceManager(): |
| 176 | 171 | ps.Publisher().sendMessage('Remove surface actor from viewer', actor) |
| 177 | 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 | 181 | def OnSeedSurface(self, pubsub_evt): |
| 188 | 182 | """ |
| ... | ... | @@ -318,9 +312,8 @@ class SurfaceManager(): |
| 318 | 312 | # self.actors_dict. |
| 319 | 313 | proj = prj.Project() |
| 320 | 314 | surface = proj.surface_dict[index] |
| 321 | - | |
| 322 | 315 | ps.Publisher().sendMessage('Update surface info in GUI', |
| 323 | - (surface.index, surface.name, | |
| 316 | + (index, surface.name, | |
| 324 | 317 | surface.colour, surface.volume, |
| 325 | 318 | surface.transparency)) |
| 326 | 319 | self.last_surface_index = index |
| ... | ... | @@ -330,7 +323,6 @@ class SurfaceManager(): |
| 330 | 323 | |
| 331 | 324 | def OnLoadSurfaceDict(self, pubsub_evt): |
| 332 | 325 | surface_dict = pubsub_evt.data |
| 333 | - | |
| 334 | 326 | for key in surface_dict: |
| 335 | 327 | surface = surface_dict[key] |
| 336 | 328 | # Map polygonal data (vtkPolyData) to graphics primitives. | ... | ... |
invesalius/gui/data_notebook.py
| ... | ... | @@ -543,9 +543,6 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 543 | 543 | selected_items = self.GetSelected() |
| 544 | 544 | old_dict = self.surface_list_index |
| 545 | 545 | new_dict = {} |
| 546 | - print "RemoveSurfaces" | |
| 547 | - print "selected_items" | |
| 548 | - print "before", self.surface_list_index | |
| 549 | 546 | if selected_items: |
| 550 | 547 | for index in selected_items: |
| 551 | 548 | self.DeleteItem(index) |
| ... | ... | @@ -560,7 +557,6 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 560 | 557 | ps.Publisher().sendMessage('Remove surfaces', selected_items) |
| 561 | 558 | else: |
| 562 | 559 | dlg.SurfaceSelectionRequiredForRemoval() |
| 563 | - print "after", self.surface_list_index | |
| 564 | 560 | |
| 565 | 561 | |
| 566 | 562 | def OnCloseProject(self, pubsub_evt): |
| ... | ... | @@ -572,6 +568,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 572 | 568 | # Note: DON'T rename to OnItemSelected!!! |
| 573 | 569 | # Otherwise the parent's method will be overwritten and other |
| 574 | 570 | # things will stop working, e.g.: OnCheckItem |
| 571 | + | |
| 575 | 572 | last_surface_index = evt.m_itemIndex |
| 576 | 573 | ps.Publisher().sendMessage('Change surface selected', |
| 577 | 574 | last_surface_index) |
| ... | ... | @@ -588,6 +585,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 588 | 585 | # it is important to revert items order, so |
| 589 | 586 | # listctrl update is ok |
| 590 | 587 | selected.sort(reverse=True) |
| 588 | + | |
| 591 | 589 | return selected |
| 592 | 590 | |
| 593 | 591 | def __init_columns(self): |
| ... | ... | @@ -659,28 +657,26 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 659 | 657 | (index, visibility)) |
| 660 | 658 | |
| 661 | 659 | def AddSurface(self, pubsub_evt): |
| 662 | - | |
| 663 | - | |
| 664 | 660 | index = pubsub_evt.data[0] |
| 665 | 661 | name = pubsub_evt.data[1] |
| 666 | 662 | colour = pubsub_evt.data[2] |
| 667 | 663 | volume = "%d"%(int(pubsub_evt.data[3])) |
| 668 | 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 | 682 | def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3", |
| ... | ... | @@ -880,7 +876,6 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 880 | 876 | |
| 881 | 877 | def OnItemActivated(self, evt): |
| 882 | 878 | self.ToggleItem(evt.m_itemIndex) |
| 883 | - print m_itemIndex | |
| 884 | 879 | |
| 885 | 880 | def OnCheckItem(self, index, flag): |
| 886 | 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 | 436 | ps.Publisher().subscribe(self.ChangeSurfaceName, |
| 437 | 437 | 'Change surface name') |
| 438 | 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 | 460 | def OnCloseProject(self, pubsub_evt): |
| 441 | 461 | self.CloseProject() |
| ... | ... | @@ -459,14 +479,14 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) |
| 459 | 479 | name = pubsub_evt.data[1] |
| 460 | 480 | colour = [value*255 for value in pubsub_evt.data[2]] |
| 461 | 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 | 491 | def OnComboName(self, evt): |
| 472 | 492 | surface_name = evt.GetString() |
| ... | ... | @@ -480,7 +500,6 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) |
| 480 | 500 | colour)) |
| 481 | 501 | |
| 482 | 502 | def OnTransparency(self, evt): |
| 483 | - print evt.GetInt() | |
| 484 | 503 | transparency = evt.GetInt()/float(MAX_TRANSPARENCY) |
| 485 | 504 | # FIXME: In Mac OS/X, wx.Slider (wx.Python 2.8.10) has problem on the |
| 486 | 505 | # right-limit as reported on http://trac.wxwidgets.org/ticket/4555. | ... | ... |
invesalius/project.py
| ... | ... | @@ -121,6 +121,7 @@ class Project(object): |
| 121 | 121 | new_dict[i] = self.mask_dict[i] |
| 122 | 122 | if i > index: |
| 123 | 123 | new_dict[i-1] = self.mask_dict[i] |
| 124 | + new_dict[i-1].index = i-1 | |
| 124 | 125 | self.mask_dict = new_dict |
| 125 | 126 | |
| 126 | 127 | def GetMask(self, index): |
| ... | ... | @@ -143,6 +144,7 @@ class Project(object): |
| 143 | 144 | new_dict[i] = self.surface_dict[i] |
| 144 | 145 | if i > index: |
| 145 | 146 | new_dict[i-1] = self.surface_dict[i] |
| 147 | + new_dict[i-1].index = i-1 | |
| 146 | 148 | self.surface_dict = new_dict |
| 147 | 149 | |
| 148 | 150 | def SetAcquisitionModality(self, type_=None): | ... | ... |