diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 8c12c9d..f3530eb 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -153,14 +153,9 @@ class SurfaceManager(): def OnRemove(self, pubsub_evt): - print "OnRemove" selected_items = pubsub_evt.data proj = prj.Project() - print "before" - print "1:", proj.surface_dict - print "2:", self.actors_dict - old_dict = self.actors_dict new_dict = {} if selected_items: @@ -176,13 +171,12 @@ class SurfaceManager(): ps.Publisher().sendMessage('Remove surface actor from viewer', actor) self.actors_dict = new_dict - print "after" - print "1", proj.surface_dict - print "2", self.actors_dict - print "\n" - - - + if self.last_surface_index in selected_items: + if self.actors_dict: + self.last_surface_index = 0 + else: + self.last_surface_index = None + def OnSeedSurface(self, pubsub_evt): """ @@ -318,9 +312,8 @@ class SurfaceManager(): # self.actors_dict. proj = prj.Project() surface = proj.surface_dict[index] - ps.Publisher().sendMessage('Update surface info in GUI', - (surface.index, surface.name, + (index, surface.name, surface.colour, surface.volume, surface.transparency)) self.last_surface_index = index @@ -330,7 +323,6 @@ class SurfaceManager(): def OnLoadSurfaceDict(self, pubsub_evt): surface_dict = pubsub_evt.data - for key in surface_dict: surface = surface_dict[key] # Map polygonal data (vtkPolyData) to graphics primitives. diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index 674238f..c8e7b0d 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -543,9 +543,6 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): selected_items = self.GetSelected() old_dict = self.surface_list_index new_dict = {} - print "RemoveSurfaces" - print "selected_items" - print "before", self.surface_list_index if selected_items: for index in selected_items: self.DeleteItem(index) @@ -560,7 +557,6 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): ps.Publisher().sendMessage('Remove surfaces', selected_items) else: dlg.SurfaceSelectionRequiredForRemoval() - print "after", self.surface_list_index def OnCloseProject(self, pubsub_evt): @@ -572,6 +568,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): # Note: DON'T rename to OnItemSelected!!! # Otherwise the parent's method will be overwritten and other # things will stop working, e.g.: OnCheckItem + last_surface_index = evt.m_itemIndex ps.Publisher().sendMessage('Change surface selected', last_surface_index) @@ -588,6 +585,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): # it is important to revert items order, so # listctrl update is ok selected.sort(reverse=True) + return selected def __init_columns(self): @@ -659,28 +657,26 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): (index, visibility)) def AddSurface(self, pubsub_evt): - - index = pubsub_evt.data[0] name = pubsub_evt.data[1] colour = pubsub_evt.data[2] volume = "%d"%(int(pubsub_evt.data[3])) transparency = "%d%%"%(int(100*pubsub_evt.data[4])) - - image = self.CreateColourBitmap(colour) - image_index = self.imagelist.Add(image) + + if index not in self.surface_list_index: + image = self.CreateColourBitmap(colour) + image_index = self.imagelist.Add(image) - index_list = self.surface_list_index.keys() - self.surface_list_index[index] = image_index + index_list = self.surface_list_index.keys() + self.surface_list_index[index] = image_index - if (index in index_list) and index_list: - self.UpdateItemInfo(index, name, volume, transparency, colour) - else: - self.InsertNewItem(index, name, volume, transparency, colour) + if (index in index_list) and index_list: + self.UpdateItemInfo(index, name, volume, transparency, colour) + else: + self.InsertNewItem(index, name, volume, transparency, colour) - def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3", @@ -880,7 +876,6 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): def OnItemActivated(self, evt): self.ToggleItem(evt.m_itemIndex) - print m_itemIndex def OnCheckItem(self, index, flag): # TODO: use pubsub to communicate to models diff --git a/invesalius/gui/task_surface.py b/invesalius/gui/task_surface.py index 08b6284..f6616da 100644 --- a/invesalius/gui/task_surface.py +++ b/invesalius/gui/task_surface.py @@ -436,6 +436,26 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) ps.Publisher().subscribe(self.ChangeSurfaceName, 'Change surface name') ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') + ps.Publisher().subscribe(self.OnRemoveSurfaces, 'Remove surfaces') + + + def OnRemoveSurfaces(self, pubsub_evt): + list_index = pubsub_evt.data + + old_dict = self.surface_dict + new_dict = utl.TwoWaysDictionary() + for index in list_index: + self.combo_surface_name.Delete(index) + + for name in old_dict: + if old_dict[name] < index: + new_dict[name] = old_dict[name] + if old_dict[name] > index: + new_dict[name] = old_dict[name] -1 + old_dict = new_dict + self.surface_dict = new_dict + + def OnCloseProject(self, pubsub_evt): self.CloseProject() @@ -459,14 +479,14 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) name = pubsub_evt.data[1] colour = [value*255 for value in pubsub_evt.data[2]] overwrite = name in self.surface_dict.keys() - if not overwrite or not self.surface_dict: - self.surface_dict[name] = index - index = self.combo_surface_name.Append(name) - - transparency = 100*pubsub_evt.data[4] - self.button_colour.SetColour(colour) - self.slider_transparency.SetValue(transparency) - self.combo_surface_name.SetSelection(index) + if index not in self.surface_dict.values(): + if not overwrite or not self.surface_dict: + self.surface_dict[name] = index + index = self.combo_surface_name.Append(name) + transparency = 100*pubsub_evt.data[4] + self.button_colour.SetColour(colour) + self.slider_transparency.SetValue(transparency) + self.combo_surface_name.SetSelection(index) def OnComboName(self, evt): surface_name = evt.GetString() @@ -480,7 +500,6 @@ wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, 10) colour)) def OnTransparency(self, evt): - print evt.GetInt() transparency = evt.GetInt()/float(MAX_TRANSPARENCY) # FIXME: In Mac OS/X, wx.Slider (wx.Python 2.8.10) has problem on the # right-limit as reported on http://trac.wxwidgets.org/ticket/4555. diff --git a/invesalius/project.py b/invesalius/project.py index 631c999..7b33744 100755 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -121,6 +121,7 @@ class Project(object): new_dict[i] = self.mask_dict[i] if i > index: new_dict[i-1] = self.mask_dict[i] + new_dict[i-1].index = i-1 self.mask_dict = new_dict def GetMask(self, index): @@ -143,6 +144,7 @@ class Project(object): new_dict[i] = self.surface_dict[i] if i > index: new_dict[i-1] = self.surface_dict[i] + new_dict[i-1].index = i-1 self.surface_dict = new_dict def SetAcquisitionModality(self, type_=None): -- libgit2 0.21.2