Пример #1
0
  def setup( self ):
    self.workflow = ctk.ctkWorkflow()
    workflowWidget = ctk.ctkWorkflowStackedWidget()
    workflowWidget.setWorkflow( self.workflow )
  
    nNodes = slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLScriptedModuleNode')
    self.parameterNode = None
    for n in xrange(nNodes):
      compNode = slicer.mrmlScene.GetNthNodeByClass(n, 'vtkMRMLScriptedModuleNode')
      nodeid = None
      if compNode.GetModuleName() == 'workflow':
        self.parameterNode = compNode
        print 'Found existing workflow parameter node'
        break
    if self.parameterNode == None:
      self.parameterNode = slicer.vtkMRMLScriptedModuleNode()
      self.parameterNode.SetModuleName('workflow')
      slicer.mrmlScene.AddNode(self.parameterNode)

    loginStep = WorkflowSteps.LoginStep('Login', self.parameterNode)
    approachStep = WorkflowSteps.ApproachStep('Approach', self.parameterNode)
    screwStep = WorkflowSteps.ScrewStep('Screw', self.parameterNode)
    doneStep = WorkflowSteps.FinalStep('Final', self.parameterNode)
    
    self.workflow.addTransition(loginStep, approachStep, None, ctk.ctkWorkflow.Forward)
    self.workflow.addTransition(approachStep, screwStep, None, ctk.ctkWorkflow.Forward)
    self.workflow.addTransition(screwStep, doneStep, None, ctk.ctkWorkflow.Forward)

    self.workflow.setInitialStep(loginStep)
    self.workflow.start()
    workflowWidget.visible = True
    self.layout.addWidget( workflowWidget )
    def setup(self):
        ScriptedLoadableModuleWidget.setup(self)

        # Instantiate and connect widgets ...

        self.workflow = ctk.ctkWorkflow()

        workflowWidget = ctk.ctkWorkflowStackedWidget()
        workflowWidget.setWorkflow(self.workflow)

        # create all wizard steps
        self.loadDataStep = PedicleScrewSimulatorWizard.LoadDataStep(
            'LoadData')
        self.defineROIStep = PedicleScrewSimulatorWizard.DefineROIStep(
            'DefineROI')
        self.measurementsStep = PedicleScrewSimulatorWizard.MeasurementsStep(
            'Measurements')
        self.landmarksStep = PedicleScrewSimulatorWizard.LandmarksStep(
            'Landmarks')
        self.screwStep = PedicleScrewSimulatorWizard.ScrewStep('Screw')
        self.gradeStep = PedicleScrewSimulatorWizard.GradeStep('Grade')
        self.endStep = PedicleScrewSimulatorWizard.EndStep('Final')

        # add the wizard steps to an array for convenience
        allSteps = []

        allSteps.append(self.loadDataStep)
        allSteps.append(self.defineROIStep)
        allSteps.append(self.landmarksStep)
        allSteps.append(self.measurementsStep)
        allSteps.append(self.screwStep)
        allSteps.append(self.gradeStep)
        allSteps.append(self.endStep)

        # Add transition
        # Check if volume is loaded
        self.workflow.addTransition(self.loadDataStep, self.defineROIStep)

        self.workflow.addTransition(self.defineROIStep, self.landmarksStep,
                                    'pass', ctk.ctkWorkflow.Bidirectional)
        self.workflow.addTransition(self.defineROIStep, self.loadDataStep,
                                    'fail', ctk.ctkWorkflow.Bidirectional)

        self.workflow.addTransition(self.landmarksStep, self.measurementsStep,
                                    'pass', ctk.ctkWorkflow.Bidirectional)
        self.workflow.addTransition(self.landmarksStep, self.measurementsStep,
                                    'fail', ctk.ctkWorkflow.Bidirectional)

        self.workflow.addTransition(self.measurementsStep, self.screwStep,
                                    'pass', ctk.ctkWorkflow.Bidirectional)
        self.workflow.addTransition(self.measurementsStep, self.screwStep,
                                    'fail', ctk.ctkWorkflow.Bidirectional)

        self.workflow.addTransition(self.screwStep, self.gradeStep, 'pass',
                                    ctk.ctkWorkflow.Bidirectional)
        self.workflow.addTransition(self.screwStep, self.gradeStep, 'fail',
                                    ctk.ctkWorkflow.Bidirectional)

        self.workflow.addTransition(self.gradeStep, self.endStep)

        nNodes = slicer.mrmlScene.GetNumberOfNodesByClass(
            'vtkMRMLScriptedModuleNode')

        self.parameterNode = None
        for n in xrange(nNodes):
            compNode = slicer.mrmlScene.GetNthNodeByClass(
                n, 'vtkMRMLScriptedModuleNode')
            nodeid = None
            if compNode.GetModuleName() == 'PedicleScrewSimulator':
                self.parameterNode = compNode
                print 'Found existing PedicleScrewSimulator parameter node'
                break
        if self.parameterNode == None:
            self.parameterNode = slicer.vtkMRMLScriptedModuleNode()
            self.parameterNode.SetModuleName('PedicleScrewSimulator')
            slicer.mrmlScene.AddNode(self.parameterNode)

        for s in allSteps:
            s.setParameterNode(self.parameterNode)

        # restore workflow step
        currentStep = self.parameterNode.GetParameter('currentStep')

        if currentStep != '':
            print 'Restoring workflow step to ', currentStep
            if currentStep == 'LoadData':
                self.workflow.setInitialStep(self.loadDataStep)
            if currentStep == 'DefineROI':
                self.workflow.setInitialStep(self.defineROIStep)
            if currentStep == 'Measurements':
                self.workflow.setInitialStep(self.measurementsStep)
            if currentStep == 'Landmarks':
                self.workflow.setInitialStep(self.landmarksStep)
            if currentStep == 'Screw':
                self.workflow.setInitialStep(self.screwStep)
            if currentStep == 'Grade':
                self.workflow.setInitialStep(self.gradeStep)
            if currentStep == 'Final':
                self.workflow.setInitialStep(self.endStep)
        else:
            print 'currentStep in parameter node is empty!'

        # start the workflow and show the widget
        self.workflow.start()
        workflowWidget.visible = True
        self.layout.addWidget(workflowWidget)
Пример #3
0
    def __init__(self, workflow_configuration, parent=None):
        if not parent:
            self.parent = qt.QWidget()
            self.parent.setLayout(qt.QVBoxLayout())
        else:
            self.parent = parent

        self.workflow_configuration = workflow_configuration

        parent.connect(parent, 'mrmlSceneChanged(vtkMRMLScene*)',
                       self.workflow_configuration.setMRMLScene)
        self.workflow_configuration.setMRMLScene(slicer.mrmlScene)

        loader = qt.QUiLoader()

        self.steps = []

        def onEntryCallback(actual_step, comingFrom, transitionType):
            data = self.extract_data()

            method_name = 'on_entry_' + actual_step.id()
            if hasattr(self.workflow_configuration, method_name):
                on_entry = getattr(self.workflow_configuration, method_name)
                on_entry(actual_step, comingFrom, transitionType, data)
                self.update_data(data)

        def onExitCallback(actual_step, comingFrom, transitionType):
            data = self.extract_data()

            method_name = 'on_exit_' + actual_step.id()
            if hasattr(self.workflow_configuration, method_name):
                on_exit = getattr(self.workflow_configuration, method_name)
                on_exit(actual_step, comingFrom, transitionType, data)
                self.update_data(data)

        def validateCallback(actual_step, desiredBranchId):
            data = self.extract_data()

            method_name = 'validate_' + actual_step.id()
            if hasattr(self.workflow_configuration, method_name):
                validate = getattr(self.workflow_configuration, method_name)
                return validate(actual_step, data)
            else:
                return True

        self.callbacks = {
            'onEntryCallback': onEntryCallback,
            'onExitCallback': onExitCallback,
            'validateCallback': validateCallback
        }

        for step_widget_file in self.workflow_configuration.step_widget_files:
            path = os.path.join(os.path.dirname(__file__), 'Resources', 'UI',
                                step_widget_file + '.ui')

            qfile = qt.QFile(path)
            qfile.open(qt.QFile.ReadOnly)
            widget = loader.load(qfile)

            if hasattr(widget, 'setMRMLScene'):
                widget.connect(parent, 'mrmlSceneChanged(vtkMRMLScene*)',
                               widget.setMRMLScene)
                widget.setMRMLScene(slicer.mrmlScene)

            if hasattr(self.workflow_configuration, 'post_widget_init'):
                self.workflow_configuration.post_widget_init(
                    step_widget_file, widget)

            step = GeneralizedStep(step_widget_file,
                                   widget,
                                   onEntryCallback=onEntryCallback,
                                   onExitCallback=onExitCallback,
                                   validateCallback=validateCallback)

            self.steps.append((step_widget_file, step))

        self.workflow = ctk.ctkWorkflow(self.parent)
        self.workflowWidget = ctk.ctkWorkflowStackedWidget()

        self.workflowWidget.setWorkflow(self.workflow)
        self.parent.layout().addWidget(self.workflowWidget)

        for i in xrange(len(self.steps) - 1):
            self.workflow.addTransition(self.steps[i][1], self.steps[i + 1][1])

        self.workflow.start()
    if goingTo: goingToId = goingTo.id()
    print "-> onExit - current [%s] - goingTo [%s]" % (self.id(), goingToId)
    super(ExampleStep, self).onExit(goingTo, transitionType)
    
  def validate(self, desiredBranchId):
    validationSuceeded = True
    print "-> validate %s" % self.id()
    
    super(ExampleStep, self).validate(validationSuceeded, desiredBranchId)


if __name__ == "__main__":

  workflow = ctk.ctkWorkflow()

  workflowWidget = ctk.ctkWorkflowStackedWidget()
  workflowWidget.setWorkflow(workflow)

  steps = []

  steps.append(ExampleStep('step1'))
  steps.append(ExampleStep('step2'))
  steps.append(ExampleStep('step3'))

  # Add transition associated to steps
  for i in range(len(steps) - 1):
    workflow.addTransition(steps[i], steps[i + 1])

  workflow.start()

  workflowWidget.visible = True
    def __init__(self, workflow_configuration, parent=None):
        if not parent:
            self.parent = qt.QWidget()
            self.parent.setLayout(qt.QVBoxLayout())
        else:
            self.parent = parent

        self.workflow_configuration = workflow_configuration

        loader = qt.QUiLoader()

        self.steps = []

        def onEntryCallback(actual_step, comingFrom, transitionType):
            data = self.extract_data()

            method_name = 'on_entry_'+actual_step.id()
            if hasattr(self.workflow_configuration, method_name):
                on_entry = getattr(self.workflow_configuration, method_name)
                on_entry(actual_step, comingFrom, transitionType, data)
                self.update_data(data)

        def onExitCallback(actual_step, comingFrom, transitionType):
            data = self.extract_data()

            method_name = 'on_exit_'+actual_step.id()
            if hasattr(self.workflow_configuration, method_name):
                on_exit = getattr(self.workflow_configuration, method_name)
                on_exit(actual_step, comingFrom, transitionType, data)
                self.update_data(data)

        def validateCallback(actual_step, desiredBranchId):
            data = self.extract_data()

            method_name = 'validate_'+actual_step.id()
            if hasattr(self.workflow_configuration, method_name):
                validate = getattr(self.workflow_configuration, method_name)
                return validate(actual_step, data)
            else:
                return True

        for step_widget_file in self.workflow_configuration.step_widget_files:
            path = os.path.join(
                 os.path.dirname(__file__), 'Resources', 'UI',
                 step_widget_file + '.ui'
             )

            qfile = qt.QFile(path)
            qfile.open(qt.QFile.ReadOnly)
            widget = loader.load( qfile )


            step = GeneralizedStep(step_widget_file, widget,
                                   onEntryCallback=onEntryCallback,
                                   onExitCallback=onExitCallback,
                                   validateCallback=validateCallback)

            self.steps.append((step_widget_file, step))

        self.workflow = ctk.ctkWorkflow()
        self.workflowWidget = ctk.ctkWorkflowStackedWidget()

        self.workflowWidget.setWorkflow(self.workflow)
        self.parent.layout().addWidget(self.workflowWidget)

        for i in xrange(len(self.steps) - 1):
            self.workflow.addTransition(self.steps[i][1], self.steps[i + 1][1])

        self.workflow.start()
  def setup(self):
    ScriptedLoadableModuleWidget.setup(self)

    # Instantiate and connect widgets ...

    self.workflow = ctk.ctkWorkflow()

    workflowWidget = ctk.ctkWorkflowStackedWidget()
    workflowWidget.setWorkflow( self.workflow )

    # create all wizard steps
    self.loadDataStep = PedicleScrewSimulatorWizard.LoadDataStep( 'LoadData'  )
    self.defineROIStep = PedicleScrewSimulatorWizard.DefineROIStep( 'DefineROI'  )
    self.measurementsStep = PedicleScrewSimulatorWizard.MeasurementsStep( 'Measurements'  )
    self.landmarksStep = PedicleScrewSimulatorWizard.LandmarksStep( 'Landmarks' )
    self.screwStep = PedicleScrewSimulatorWizard.ScrewStep( 'Screw' )
    self.gradeStep = PedicleScrewSimulatorWizard.GradeStep( 'Grade' )
    self.endStep = PedicleScrewSimulatorWizard.EndStep( 'Final'  )
    
    # add the wizard steps to an array for convenience
    allSteps = []

    allSteps.append( self.loadDataStep )
    allSteps.append( self.defineROIStep )
    allSteps.append( self.landmarksStep)
    allSteps.append( self.measurementsStep )
    allSteps.append( self.screwStep)
    allSteps.append( self.gradeStep)
    allSteps.append( self.endStep )
    
    
    # Add transition 
    # Check if volume is loaded
    self.workflow.addTransition( self.loadDataStep, self.defineROIStep )
    
    self.workflow.addTransition( self.defineROIStep, self.landmarksStep, 'pass', ctk.ctkWorkflow.Bidirectional )
    self.workflow.addTransition( self.defineROIStep, self.loadDataStep, 'fail', ctk.ctkWorkflow.Bidirectional  )
    
    self.workflow.addTransition( self.landmarksStep, self.measurementsStep, 'pass', ctk.ctkWorkflow.Bidirectional )
    self.workflow.addTransition( self.landmarksStep, self.measurementsStep, 'fail', ctk.ctkWorkflow.Bidirectional )
    
    self.workflow.addTransition( self.measurementsStep, self.screwStep, 'pass', ctk.ctkWorkflow.Bidirectional )
    self.workflow.addTransition( self.measurementsStep, self.screwStep, 'fail', ctk.ctkWorkflow.Bidirectional )
    
    self.workflow.addTransition( self.screwStep, self.gradeStep, 'pass', ctk.ctkWorkflow.Bidirectional )
    self.workflow.addTransition( self.screwStep, self.gradeStep, 'fail', ctk.ctkWorkflow.Bidirectional )
          
    self.workflow.addTransition( self.gradeStep, self.endStep )
           
    nNodes = slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLScriptedModuleNode')

    self.parameterNode = None
    for n in xrange(nNodes):
      compNode = slicer.mrmlScene.GetNthNodeByClass(n, 'vtkMRMLScriptedModuleNode')
      nodeid = None
      if compNode.GetModuleName() == 'PedicleScrewSimulator':
        self.parameterNode = compNode
        print 'Found existing PedicleScrewSimulator parameter node'
        break
    if self.parameterNode == None:
      self.parameterNode = slicer.vtkMRMLScriptedModuleNode()
      self.parameterNode.SetModuleName('PedicleScrewSimulator')
      slicer.mrmlScene.AddNode(self.parameterNode)
 
    for s in allSteps:
        s.setParameterNode (self.parameterNode)
    
    
    # restore workflow step
    currentStep = self.parameterNode.GetParameter('currentStep')
    
    if currentStep != '':
      print 'Restoring workflow step to ', currentStep
      if currentStep == 'LoadData':
        self.workflow.setInitialStep(self.loadDataStep)
      if currentStep == 'DefineROI':
        self.workflow.setInitialStep(self.defineROIStep)
      if currentStep == 'Measurements':
        self.workflow.setInitialStep(self.measurementsStep)
      if currentStep == 'Landmarks':
        self.workflow.setInitialStep(self.landmarksStep)
      if currentStep == 'Screw':
        self.workflow.setInitialStep(self.screwStep) 
      if currentStep == 'Grade':
        self.workflow.setInitialStep(self.gradeStep)   
      if currentStep == 'Final':
        self.workflow.setInitialStep(self.endStep)
    else:
      print 'currentStep in parameter node is empty!'
    
    
    # start the workflow and show the widget
    self.workflow.start()
    workflowWidget.visible = True
    self.layout.addWidget( workflowWidget )