Пример #1
0
    def _onEffectChanged(self, effectName):

        if self.currentEffect == effectName:
            return

        #
        # If there is no background volume or label map, do nothing
        #
        if not EditUtil.getBackgroundVolume():
            return
        if not EditUtil.getLabelVolume():
            return

        self.currentEffect = effectName

        EditUtil.restoreLabel()

        # Update action if possible - if not, we aren't ready to select the effect
        if effectName not in self.actions:
            return
        self.actions[effectName].checked = True

        #
        # an effect was selected, so build an options GUI
        # - check to see if it is an extension effect,
        # if not, try to create it, else ignore it
        # For extensions, look for 'effect'Options and 'effect'Tool
        # in the editorExtensions map and use those to create the
        # effect
        #
        if self.currentOption:
            # clean up any existing effect
            self.currentOption.__del__()
            self.currentOption = None
            for tool in self.currentTools:
                tool.sliceWidget.unsetCursor()
                tool.cleanup()
            self.currentTools = []

        # look at builtins and extensions
        # - TODO: other effect styles are deprecated
        effectClass = None
        if effectName in slicer.modules.editorExtensions.keys():
            effectClass = slicer.modules.editorExtensions[effectName]()
        elif effectName in self.editorBuiltins.keys():
            effectClass = self.editorBuiltins[effectName]()
        if effectClass:
            # for effects, create an options gui and an
            # instance for every slice view
            self.currentOption = effectClass.options(self.optionsFrame)
            self.currentOption.setMRMLDefaults()
            self.currentOption.undoRedo = self.undoRedo
            self.currentOption.defaultEffect = self.defaultEffect
            self.currentOption.create()
            self.currentOption.updateGUI()
            layoutManager = slicer.app.layoutManager()
            sliceNodeCount = slicer.mrmlScene.GetNumberOfNodesByClass(
                'vtkMRMLSliceNode')
            for nodeIndex in xrange(sliceNodeCount):
                # find the widget for each node in scene
                sliceNode = slicer.mrmlScene.GetNthNodeByClass(
                    nodeIndex, 'vtkMRMLSliceNode')
                sliceWidget = layoutManager.sliceWidget(
                    sliceNode.GetLayoutName())
                if sliceWidget:
                    tool = effectClass.tool(sliceWidget)
                    tool.undoRedo = self.undoRedo
                    self.currentTools.append(tool)
            self.currentOption.tools = self.currentTools
        else:
            # fallback to internal classes
            try:
                options = eval("%sOptions" % effectName)
                self.currentOption = options(self.optionsFrame)
            except NameError, AttributeError:
                # No options for this effect, skip it
                pass
Пример #2
0
  def _onEffectChanged(self, effectName):

    if self.currentEffect == effectName:
      return

    #
    # If there is no background volume or label map, do nothing
    #
    if not EditUtil.getBackgroundVolume():
      return
    if not EditUtil.getLabelVolume():
      return

    self.currentEffect = effectName

    EditUtil.restoreLabel()

    # Update action if possible - if not, we aren't ready to select the effect
    if effectName not in self.actions:
      return
    self.actions[effectName].checked = True

    #
    # an effect was selected, so build an options GUI
    # - check to see if it is an extension effect,
    # if not, try to create it, else ignore it
    # For extensions, look for 'effect'Options and 'effect'Tool
    # in the editorExtensions map and use those to create the
    # effect
    #
    if self.currentOption:
      # clean up any existing effect
      self.currentOption.__del__()
      self.currentOption = None
      for tool in self.currentTools:
        tool.sliceWidget.unsetCursor()
        tool.cleanup()
      self.currentTools = []

    # look at builtins and extensions
    # - TODO: other effect styles are deprecated
    effectClass = None
    if effectName in slicer.modules.editorExtensions.keys():
      effectClass = slicer.modules.editorExtensions[effectName]()
    elif effectName in self.editorBuiltins.keys():
      effectClass = self.editorBuiltins[effectName]()
    if effectClass:
      # for effects, create an options gui and an
      # instance for every slice view
      self.currentOption = effectClass.options(self.optionsFrame)
      self.currentOption.setMRMLDefaults()
      self.currentOption.undoRedo = self.undoRedo
      self.currentOption.defaultEffect = self.defaultEffect
      self.currentOption.create()
      self.currentOption.updateGUI()
      layoutManager = slicer.app.layoutManager()
      sliceNodeCount = slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLSliceNode')
      for nodeIndex in xrange(sliceNodeCount):
        # find the widget for each node in scene
        sliceNode = slicer.mrmlScene.GetNthNodeByClass(nodeIndex, 'vtkMRMLSliceNode')
        sliceWidget = layoutManager.sliceWidget(sliceNode.GetLayoutName())
        if sliceWidget:
          tool = effectClass.tool(sliceWidget)
          tool.undoRedo = self.undoRedo
          self.currentTools.append(tool)
      self.currentOption.tools = self.currentTools
    else:
      # fallback to internal classes
      try:
        options = eval("%sOptions" % effectName)
        self.currentOption = options(self.optionsFrame)
      except NameError, AttributeError:
        # No options for this effect, skip it
        pass