From 8057fbeddc02d5811e2f56c01f1b278ca7c23d22 Mon Sep 17 00:00:00 2001 From: tatiana Date: Fri, 22 Jan 2010 14:25:12 +0000 Subject: [PATCH] EHN: Surface GUI, select surface from combo working --- invesalius/data/surface.py | 58 +++++++++++++++++++--------------------------------------- invesalius/gui/dialogs.py | 9 +++++++-- invesalius/gui/task_surface.py | 33 +++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 1263be7..e42971b 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -45,6 +45,7 @@ class Surface(): self.index = Surface.general_index else: self.index = index + Surface.general_index -= 1 self.polydata = '' self.colour = '' self.transparency = const.SURFACE_TRANSPARENCY @@ -113,6 +114,7 @@ class SurfaceManager(): ps.Publisher().subscribe(self.OnExportSurface,'Export surface to file') ps.Publisher().subscribe(self.OnLoadSurfaceDict, 'Load surface dict') ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') + ps.Publisher().subscribe(self.OnSelectSurface, 'Change surface selected') def OnCloseProject(self, pubsub_evt): self.CloseProject() @@ -121,47 +123,28 @@ class SurfaceManager(): del self.actors_dict self.actors_dict = {} + def OnSelectSurface(self, pubsub_evt): + index = pubsub_evt.data + #self.last_surface_index = index + # self.actors_dict. + proj = prj.Project() + surface = proj.surface_dict[index] + + ps.Publisher().sendMessage('Update surface info in GUI', + (surface.index, surface.name, + surface.colour, surface.volume, + surface.transparency)) + self.last_surface_index = index + + + def OnLoadSurfaceDict(self, pubsub_evt): surface_dict = pubsub_evt.data + #self.actors_dict[surface.index] for key in surface_dict: surface = surface_dict[key] - # Map polygonal data (vtkPolyData) to graphics primitives. - - normals = vtk.vtkPolyDataNormals() - normals.SetInput(surface.polydata) - normals.SetFeatureAngle(80) - normals.AutoOrientNormalsOn() - normals.GetOutput().ReleaseDataFlagOn() - - stripper = vtk.vtkStripper() - stripper.SetInput(normals.GetOutput()) - stripper.PassThroughCellIdsOn() - stripper.PassThroughPointIdsOn() - - mapper = vtk.vtkPolyDataMapper() - mapper.SetInput(stripper.GetOutput()) - mapper.ScalarVisibilityOff() - - # Represent an object (geometry & properties) in the rendered scene - actor = vtk.vtkActor() - actor.SetMapper(mapper) - - # Set actor colour and transparency - actor.GetProperty().SetColor(surface.colour) - actor.GetProperty().SetOpacity(1-surface.transparency) - - self.actors_dict[surface.index] = actor - - - # Send actor by pubsub to viewer's render - ps.Publisher().sendMessage('Load surface actor into viewer', (actor)) - - ps.Publisher().sendMessage('Update status text in GUI', - _("Ready")) - - # The following lines have to be here, otherwise all volumes disappear ps.Publisher().sendMessage('Update surface info in GUI', (surface.index, surface.name, @@ -280,15 +263,12 @@ class SurfaceManager(): os.remove(filename_polydata) except (WindowsError): print "Error while removing surface temporary file" - elif sys.platform == 'linux2': + else: # sys.platform == "linux2" or sys.platform == "darwin" try: os.remove(filename_img) os.remove(filename_polydata) except (OSError): print "Error while removing surface temporary file" - else: - os.remove(filename_img) - os.remove(filename_polydata) # Append surface into Project.surface_dict proj = prj.Project() diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 89eee58..2bf14ac 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -29,6 +29,7 @@ import wx.lib.pubsub as ps import project import session as ses + class NumberDialog(wx.Dialog): def __init__(self, message, value=0): pre = wx.PreDialog() @@ -385,11 +386,13 @@ def ShowSavePresetDialog(default_filename="raycasting"): return filename - +MASK_LIST = [] class NewSurfaceDialog(wx.Dialog): def __init__(self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, useMetal=False): + import data.surface as surface + import constants as const # Instead of calling wx.Dialog.__init__ we precreate the dialog # so we can set an extra style that must be set before @@ -429,7 +432,9 @@ class NewSurfaceDialog(wx.Dialog): text = wx.TextCtrl(self, -1, "", size=(80,-1)) text.SetHelpText(_("Name of the new surface to be created")) - text.SetValue(_("Surface")) + + default_name = const.SURFACE_NAME_PATTERN %(surface.Surface.general_index+2) + text.SetValue(default_name) self.text = text sizer = wx.BoxSizer(wx.VERTICAL) diff --git a/invesalius/gui/task_surface.py b/invesalius/gui/task_surface.py index 9199d66..b0b12ee 100644 --- a/invesalius/gui/task_surface.py +++ b/invesalius/gui/task_surface.py @@ -26,10 +26,9 @@ import wx.lib.pubsub as ps import gui.dialogs as dlg import gui.widgets.foldpanelbar as fpb import gui.widgets.colourselect as csel +import utils as utl #INTERPOLATION_MODE_LIST = ["Cubic", "Linear", "NearestNeighbor"] -SURFACE_LIST = [] -MASK_LIST = [] MIN_TRANSPARENCY = 0 MAX_TRANSPARENCY = 100 @@ -128,10 +127,11 @@ class InnerTaskPanel(wx.Panel): evt.Skip() def OnLinkNewSurface(self, evt=None): - dlg = dlg.NewSurfaceDialog(self, -1, _('InVesalius 3 - New surface')) - if dlg.ShowModal() == wx.ID_OK: - print "TODO: Send Signal - Create 3d surface %s \n" % dlg.GetValue() - dlg.Destroy() + #import gui.dialogs as dlg + dialog = dlg.NewSurfaceDialog(self, -1, _('InVesalius 3 - New surface')) + if dialog.ShowModal() == wx.ID_OK: + print "TODO: Send Signal - Create 3d surface %s \n" % dialog.GetValue() + dialog.Destroy() if evt: evt.Skip() @@ -211,10 +211,12 @@ class SurfaceProperties(wx.Panel): default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) self.SetBackgroundColour(default_colour) + self.surface_dict = utl.TwoWaysDictionary() + ## LINE 1 # Combo related to mask naem - combo_surface_name = wx.ComboBox(self, -1, "", choices= SURFACE_LIST, + combo_surface_name = wx.ComboBox(self, -1, "", choices= self.surface_dict.keys(), style=wx.CB_DROPDOWN|wx.CB_READONLY) combo_surface_name.SetSelection(0) if sys.platform != 'win32': @@ -288,20 +290,31 @@ class SurfaceProperties(wx.Panel): def ChangeSurfaceName(self, pubsub_evt): index, name = pubsub_evt.data + old_name = self.surface_dict.get_key(index) + self.surface_dict.pop(old_name, None) + self.surface_dict[name] = index self.combo_surface_name.SetString(index, name) self.combo_surface_name.Refresh() def InsertNewSurface(self, pubsub_evt): + #not_update = len(pubsub_evt.data) == 5 + index = pubsub_evt.data[0] 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) + self.combo_surface_name.SetSelection(index) + transparency = 100*pubsub_evt.data[4] - index = self.combo_surface_name.Append(name) - self.combo_surface_name.SetSelection(index) self.button_colour.SetColour(colour) self.slider_transparency.SetValue(transparency) def OnComboName(self, evt): - print "TODO: Send Signal - Change 3D surface selected: %s" % (evt.GetString()) + surface_name = evt.GetString() + surface_index = evt.GetSelection() + ps.Publisher().sendMessage('Change surface selected', surface_index) def OnSelectColour(self, evt): colour = [value/255.0 for value in evt.GetValue()] -- libgit2 0.21.2