diff --git a/invesalius/control.py b/invesalius/control.py index a872290..d856de1 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -116,7 +116,8 @@ class Controller(): ps.Publisher().sendMessage('Show content panel') ps.Publisher().sendMessage('Update AUI') - + + ps.Publisher().sendMessage('Load slice plane') def LoadImagedataInfo(self): proj = prj.Project() diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index 1e70d24..f0b1d10 100755 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -72,6 +72,7 @@ class Viewer(wx.Panel): self.__bind_events() self.__bind_events_wx() + def OnMove(self, obj, evt): if self.onclick and self.raycasting_volume: @@ -157,8 +158,18 @@ class Viewer(wx.Panel): ps.Publisher().subscribe(self.OnDisableBrightContrast, ('Set interaction mode', const.MODE_SLICE_EDITOR)) - + ps.Publisher().subscribe(self.OnExportSurface, 'Export surface to file') + + ps.Publisher().subscribe(self.LoadSlicePlane, 'Load slice plane') + + ps.Publisher().subscribe(self.ResetCamClippingRange, 'Reset cam clipping range') + + + def ResetCamClippingRange(self, pubsub_evt): + self.ren.ResetCamera() + self.ren.ResetCameraClippingRange() + def OnExportSurface(self, pubsub_evt): filename, filetype = pubsub_evt.data @@ -243,11 +254,8 @@ class Viewer(wx.Panel): self.UpdateRender() - def LoadPlane(self): - self.plane = SlicePlane() - self.plane.EnableX() - self.plane.EnableY() - self.plane.EnableZ() + def LoadSlicePlane(self, pubsub_evt): + self.slice_plane = SlicePlane() def ChangeBackgroundColour(self, pubsub_evt): colour = pubsub_evt.data @@ -308,12 +316,7 @@ class Viewer(wx.Panel): class SlicePlane: def __init__(self): - self.Create() - self.__bind_events() - - def __bind_events(self): - self.plane_x.AddObserver("InteractionEvent", self.Update) def Create(self): @@ -352,35 +355,55 @@ class SlicePlane: prop1.SetColor(1, 0, 0) cursor_property = plane_z.GetCursorProperty() cursor_property.SetOpacity(0) - + ps.Publisher().sendMessage('Set Widget Interactor', plane_x) ps.Publisher().sendMessage('Set Widget Interactor', plane_y) ps.Publisher().sendMessage('Set Widget Interactor', plane_z) - def EnableX(self, evt_pubsub=None): - self.plane_x.On() - self.Update() - - def EnableY(self, evt_pubsub=None): - self.plane_y.On() - self.Update() - - def EnableZ(self, evt_pubsub=None): - self.plane_z.On() - self.Update() + ps.Publisher().subscribe(self.Enable, 'Enable plane') + ps.Publisher().subscribe(self.Disable, 'Disable plane') - def DisableX(self, evt_pubsub=None): - self.plane_x.Off() - self.Update() + self.Enable() + self.Disable() + + self.Render() + + def Enable(self, evt_pubsub=None): + if (evt_pubsub): + label = evt_pubsub.data + + if(label == "Axial"): + self.plane_z.On() + elif(label == "Coronal"): + self.plane_x.On() + elif(label == "Sagital"): + self.plane_y.On() + + else: + self.plane_z.On() + self.plane_x.On() + self.plane_y.On() + ps.Publisher().sendMessage('Set volume view angle', const.VOL_ISO) + self.Render() + + def Disable(self, evt_pubsub=None): + if (evt_pubsub): + label = evt_pubsub.data + + if(label == "Axial"): + self.plane_z.Off() + elif(label == "Coronal"): + self.plane_x.Off() + elif(label == "Sagital"): + self.plane_y.Off() + else: + self.plane_z.Off() + self.plane_x.Off() + self.plane_y.Off() - def DisableY(self, evt_pubsub=None): - self.plane_y.Off() - self.Update() + self.Render() - def DisableZ(self, evt_pubsub=None): - self.plane_z.Off() - self.Update() - def Update(self, obj, evt): - ps.Publisher().sendMessage('Render volume viewer', None) + def Render(self): + ps.Publisher().sendMessage('Render volume viewer') \ No newline at end of file diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index fceaaf4..c53118c 100755 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -248,7 +248,7 @@ import wx.lib.pubsub as ps import wx.lib.colourselect as csel import constants as const -[BUTTON_RAYCASTING, BUTTON_VIEW] = [wx.NewId() for num in xrange(2)] +[BUTTON_RAYCASTING, BUTTON_VIEW, BUTTON_SLICE_PLANE] = [wx.NewId() for num in xrange(3)] RAYCASTING_TOOLS = wx.NewId() ID_TO_BMP = {const.VOL_FRONT: ["Front", "../icons/view_front.png"], @@ -264,6 +264,7 @@ ID_TO_NAME = {} ID_TO_TOOL = {} ID_TO_TOOL_ITEM = {} TOOL_STATE = {} +ID_TO_ITEMSLICEMENU = {} class VolumeViewerCover(wx.Panel): def __init__(self, parent): @@ -286,10 +287,19 @@ class VolumeToolPanel(wx.Panel): BMP_RAYCASTING = wx.Bitmap("../icons/volume_raycasting.png", wx.BITMAP_TYPE_PNG) + BMP_SLICE_PLANE = wx.Bitmap("../icons/slice_plane.png", + wx.BITMAP_TYPE_PNG) + button_raycasting = pbtn.PlateButton(self, BUTTON_RAYCASTING,"", BMP_RAYCASTING, style=pbtn.PB_STYLE_SQUARE, size=(24,24)) + + button_slice_plane = self.button_slice_plane = pbtn.PlateButton(self, BUTTON_SLICE_PLANE,"", + BMP_SLICE_PLANE, style=pbtn.PB_STYLE_SQUARE, + size=(24,24)) + button_slice_plane.Bind(wx.EVT_LEFT_DOWN, self.OnButtonSlicePlane) + self.button_raycasting = button_raycasting self.button_raycasting.Bind(wx.EVT_LEFT_DOWN, self.OnButtonRaycasting) @@ -321,6 +331,7 @@ class VolumeToolPanel(wx.Panel): sizer.Add(button_colour, 0, wx.ALL, sp) sizer.Add(button_raycasting, 0, wx.TOP|wx.BOTTOM, 1) sizer.Add(button_view, 0, wx.TOP|wx.BOTTOM, 1) + sizer.Add(button_slice_plane, 0, wx.TOP|wx.BOTTOM, 1) sizer.Fit(self) @@ -343,6 +354,9 @@ class VolumeToolPanel(wx.Panel): def OnButtonView(self, evt): self.button_view.PopupMenu(self.menu_view) + + def OnButtonSlicePlane(self, evt): + self.button_slice_plane.PopupMenu(self.slice_plane_menu) def __init_menus(self, pubsub_evt=None): # MENU RELATED TO RAYCASTING TYPES @@ -386,10 +400,37 @@ class VolumeToolPanel(wx.Panel): menu.AppendItem(item) menu.Bind(wx.EVT_MENU, self.OnMenuView) self.menu_view = menu - + + #SLICE PLANES BUTTON + self.slice_plane_menu = slice_plane_menu = wx.Menu() + itens = ["Axial", "Coronal", "Sagital"] + + for value in itens: + new_id = wx.NewId() + + item = wx.MenuItem(slice_plane_menu, new_id, value, + kind = wx.ITEM_CHECK) + ID_TO_ITEMSLICEMENU[new_id] = item + slice_plane_menu.AppendItem(item) + + slice_plane_menu.Bind(wx.EVT_MENU, self.OnMenuPlaneSlice) + self.Fit() self.Update() + + def OnMenuPlaneSlice(self, evt): + + id = evt.GetId() + item = ID_TO_ITEMSLICEMENU[id] + checked = item.IsChecked() + label = item.GetLabel() + + if not (checked): + ps.Publisher().sendMessage('Disable plane', label) + else: + ps.Publisher().sendMessage('Enable plane', label) + def ChangeButtonColour(self, pubsub_evt): colour = [i*255 for i in pubsub_evt.data] self.button_colour.SetColour(colour) -- libgit2 0.21.2