From 24f5127088b2ac67e06803bd4bb24b7ad1080041 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Fri, 22 May 2015 15:42:06 +0100
Subject: [PATCH] Options which modify the bounding box of a GLOject cannot be
 unbound, because the DC.bounds property cannot be unbound.

---
 fsl/data/model.py                       | 11 ++++++++++-
 fsl/fslview/displaycontext/modelopts.py | 18 ++++++++++++------
 fsl/fslview/gl/glmodel.py               |  7 +++----
 fsl/tools/fslview_parseargs.py          |  9 ++++-----
 4 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/fsl/data/model.py b/fsl/data/model.py
index f247b0ac4..d286c6572 100644
--- a/fsl/data/model.py
+++ b/fsl/data/model.py
@@ -58,7 +58,7 @@ class Model(object):
         """
         """
 
-        if isinstance(data, str):
+        if isinstance(data, basestring):
             infile = data
             data, lengths, indices = loadVTKPolydataFile(infile)
 
@@ -79,6 +79,15 @@ class Model(object):
         self.indices  = indices
 
 
+    def __repr__(self):
+        return '{}({}, {})'.format(type(self).__name__,
+                                   self.name,
+                                   self.dataSource)
+
+    def __str__(self):
+        return self.__repr__()
+
+
     def getBounds(self):
         return (self.vertices.min(axis=0),
                 self.vertices.max(axis=0))
diff --git a/fsl/fslview/displaycontext/modelopts.py b/fsl/fslview/displaycontext/modelopts.py
index 68bc0c69e..d838362f3 100644
--- a/fsl/fslview/displaycontext/modelopts.py
+++ b/fsl/fslview/displaycontext/modelopts.py
@@ -44,6 +44,10 @@ class ModelOpts(fsldisplay.DisplayOpts):
         # saturated colour
         colour      = colourmaps.randomBrightColour()
         self.colour = np.concatenate((colour, [1.0]))
+
+        nounbind = kwargs.get('nounbind', [])
+        nounbind.extend(['refImage', 'coordSpace', 'transform'])
+        kwargs['nounbind'] = nounbind
  
         # But create that colour before
         # base class initialisation, as
@@ -52,7 +56,7 @@ class ModelOpts(fsldisplay.DisplayOpts):
         # one we generated above.
         fsldisplay.DisplayOpts.__init__(self, *args, **kwargs)
 
-        self.__oldRefImage = None
+        self.__oldRefImage = 'none'
 
         self.overlayList.addListener('overlays',
                                      self.name,
@@ -77,6 +81,8 @@ class ModelOpts(fsldisplay.DisplayOpts):
         If a :attr:`refImage` is selected, it is returned. Otherwise,``None``
         is returned.
         """
+        if self.refImage == 'none':
+            return None
         return self.refImage
             
 
@@ -99,7 +105,7 @@ class ModelOpts(fsldisplay.DisplayOpts):
 
     def getCoordSpaceTransform(self):
 
-        if self.refImage is None:
+        if self.refImage == 'none':
             return None
 
         if self.coordSpace == self.transform:
@@ -112,13 +118,13 @@ class ModelOpts(fsldisplay.DisplayOpts):
 
     def __refImageChanged(self, *a):
         
-        if self.__oldRefImage is not None:
+        if self.__oldRefImage != 'none':
             opts = self.displayCtx.getOpts(self.__oldRefImage)
             self.unbindProps('transform', opts)
 
         self.__oldRefImage = self.refImage
         
-        if self.refImage is not None:
+        if self.refImage != 'none':
             opts = self.displayCtx.getOpts(self.refImage)
             self.bindProps('transform', opts)
             
@@ -139,7 +145,7 @@ class ModelOpts(fsldisplay.DisplayOpts):
             self.overlayList.removeListener('overlays', self.name)
             return
 
-        imgOptions = [None]
+        imgOptions = ['none']
         imgLabels  = [strings.choices['ModelOpts.refImage.none']]
 
         for overlay in overlays:
@@ -159,4 +165,4 @@ class ModelOpts(fsldisplay.DisplayOpts):
         imgProp.setChoices(imgOptions, imgLabels, self)
 
         if imgVal in overlays: self.refImage = imgVal
-        else:                  self.refImage = None
+        else:                  self.refImage = 'none'
diff --git a/fsl/fslview/gl/glmodel.py b/fsl/fslview/gl/glmodel.py
index dfd3f02e7..97fce55e2 100644
--- a/fsl/fslview/gl/glmodel.py
+++ b/fsl/fslview/gl/glmodel.py
@@ -41,11 +41,10 @@ class GLModel(globject.GLObject):
         vertices = self.overlay.vertices
         indices  = self.overlay.indices
 
-        if self.opts.refImage is not None:
-            xform = self.opts.getCoordSpaceTransform()
+        xform = self.opts.getCoordSpaceTransform()
 
-            if xform is not None:
-                vertices = transform.transform(vertices, xform)
+        if xform is not None:
+            vertices = transform.transform(vertices, xform)
 
         self.vertices = np.array(vertices, dtype=np.float32)
         self.indices  = np.array(indices,  dtype=np.uint32)
diff --git a/fsl/tools/fslview_parseargs.py b/fsl/tools/fslview_parseargs.py
index bed9394c0..858af47c2 100644
--- a/fsl/tools/fslview_parseargs.py
+++ b/fsl/tools/fslview_parseargs.py
@@ -844,7 +844,6 @@ def generateSceneArgs(overlayList, displayCtx, sceneOpts):
 
     args = []
 
-
     args += ['--{}'.format(ARGUMENTS['Main.scene'][1])]
     if   isinstance(sceneOpts, fsldisplay.OrthoOpts):    args += ['ortho']
     elif isinstance(sceneOpts, fsldisplay.LightBoxOpts): args += ['lightbox']
@@ -886,11 +885,11 @@ def applyOverlayArgs(args, overlayList, displayCtx, **kwargs):
     :arg overlayList: An :class:`.OverlayList` instance, to which the
                       overlays should be added.
     
-    :arg displayCtx:  A :class:`~fsl.fslview.displaycontext.DisplayContext`
-                      instance, which manages the scene and overlay display.
+    :arg displayCtx:  A :class:`.DisplayContext` instance, which manages the
+                      scene and overlay display.
     
-    :arg kwargs:     Passed through to the
-                     :func:`fsl.data.imageio.loadImages` function.
+    :arg kwargs:      Passed through to the :func:`.Overlay.loadOverlays`
+                      function.
     """
 
     paths    = [o.overlay for o in args.overlays]
-- 
GitLab