From 0a4c0482be2a5744b82753d74beed844afaa4573 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Wed, 24 Sep 2014 16:37:51 -0300 Subject: [PATCH] Initing the option to set the unity of the size of brush --- invesalius/data/cursor_actors.py | 30 +++++++++++++++++++----------- invesalius/data/viewer_slice.py | 7 ++++--- invesalius/gui/task_slice.py | 14 +++++++++++--- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/invesalius/data/cursor_actors.py b/invesalius/data/cursor_actors.py index 601da24..065fbb2 100644 --- a/invesalius/data/cursor_actors.py +++ b/invesalius/data/cursor_actors.py @@ -78,6 +78,7 @@ class CursorBase(object): self.size = 15.0 self.orientation = "AXIAL" self.spacing = (1, 1, 1) + self.unity = 'mm' if vtk.vtkVersion().GetVTKVersion() > '5.8.0': self.mapper = vtk.vtkImageSliceMapper() cursor_property = vtk.vtkImageProperty() @@ -91,8 +92,9 @@ class CursorBase(object): self._build_actor() self._calculate_area_pixels() - def SetSize(self, diameter): + def SetSize(self, diameter, unity): self.radius = diameter/2.0 + self.unity = unity self._build_actor() self._calculate_area_pixels() @@ -241,7 +243,10 @@ class CursorCircle(CursorBase): """ print "Building circle cursor", self.orientation r = self.radius - sx, sy, sz = self.spacing + if self.unity == 'mm': + sx, sy, sz = self.spacing + else: + sx, sy, sz = 1.0, 1.0, 1.0 if self.orientation == 'AXIAL': xi = math.floor(-r/sx) xf = math.ceil(r/sx) + 1 @@ -293,15 +298,18 @@ class CursorCircle(CursorBase): Return the cursor's pixels. """ r = self.radius - if self.orientation == 'AXIAL': - sx = self.spacing[0] - sy = self.spacing[1] - elif self.orientation == 'CORONAL': - sx = self.spacing[0] - sy = self.spacing[2] - elif self.orientation == 'SAGITAL': - sx = self.spacing[1] - sy = self.spacing[2] + if self.unity == 'mm': + if self.orientation == 'AXIAL': + sx = self.spacing[0] + sy = self.spacing[1] + elif self.orientation == 'CORONAL': + sx = self.spacing[0] + sy = self.spacing[2] + elif self.orientation == 'SAGITAL': + sx = self.spacing[1] + sy = self.spacing[2] + else: + sx, sy = 1.0, 1.0 xi = math.floor(-r/sx) xf = math.ceil(r/sx) + 1 diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 3623674..9159753 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -534,10 +534,11 @@ class Viewer(wx.Panel): self.interactor.Render() def ChangeBrushSize(self, pubsub_evt): - size = pubsub_evt.data + size = pubsub_evt.data[0] + unity = pubsub_evt.data[1] self._brush_cursor_size = size #for slice_data in self.slice_data_list: - self.slice_data.cursor.SetSize(size) + self.slice_data.cursor.SetSize(size, unity) def ChangeBrushColour(self, pubsub_evt): vtk_colour = pubsub_evt.data[3] @@ -570,7 +571,7 @@ class Viewer(wx.Panel): cursor.SetPosition(coordinates[self.orientation]) cursor.SetSpacing(self.slice_.spacing) cursor.SetColour(self._brush_cursor_colour) - cursor.SetSize(self._brush_cursor_size) + cursor.SetSize(self._brush_cursor_size, 'mm') slice_data.SetCursor(cursor) self.interactor.Render() diff --git a/invesalius/gui/task_slice.py b/invesalius/gui/task_slice.py index d77570e..092dc83 100644 --- a/invesalius/gui/task_slice.py +++ b/invesalius/gui/task_slice.py @@ -599,24 +599,31 @@ class EditionTools(wx.Panel): btn_brush_format.SetMenu(menu) self.btn_brush_format = btn_brush_format - spin_brush_size = wx.SpinCtrl(self, -1, "", (20, 50)) + spin_brush_size = wx.SpinCtrl(self, -1, "", (20, -1)) spin_brush_size.SetRange(1,100) spin_brush_size.SetValue(const.BRUSH_SIZE) spin_brush_size.Bind(wx.EVT_TEXT, self.OnBrushSize) self.spin = spin_brush_size + unities = ("mm", "px") + self.combo_brush_unity = wx.ComboBox(self, -1, unities[0], + size=(15, -1), choices=unities, + style=wx.CB_DROPDOWN | wx.CB_READONLY) + combo_brush_op = wx.ComboBox(self, -1, "", size=(15,-1), choices = const.BRUSH_OP_NAME, style = wx.CB_DROPDOWN|wx.CB_READONLY) combo_brush_op.SetSelection(const.DEFAULT_BRUSH_OP) if sys.platform != 'win32': combo_brush_op.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) + self.combo_brush_unity.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) self.combo_brush_op = combo_brush_op # Sizer which represents the second line line2 = wx.BoxSizer(wx.HORIZONTAL) line2.Add(btn_brush_format, 0, wx.EXPAND|wx.GROW|wx.TOP|wx.RIGHT, 0) - line2.Add(spin_brush_size, 0, wx.RIGHT, 5) + line2.Add(spin_brush_size, 1, wx.RIGHT, 5) + line2.Add(self.combo_brush_unity, 1, wx.EXPAND| wx.RIGHT, 5) line2.Add(combo_brush_op, 1, wx.EXPAND|wx.TOP|wx.RIGHT|wx.LEFT, 5) ## LINE 3 @@ -706,7 +713,8 @@ class EditionTools(wx.Panel): # FIXME: Using wx.EVT_SPINCTRL in MacOS it doesnt capture changes only # in the text ctrl - so we are capturing only changes on text # Strangelly this is being called twice - Publisher.sendMessage('Set edition brush size',self.spin.GetValue()) + Publisher.sendMessage('Set edition brush size', (self.spin.GetValue(), + self.combo_brush_unity.GetValue())) def OnComboBrushOp(self, evt): brush_op_id = evt.GetSelection() -- libgit2 0.21.2