Esempio n. 1
0
    def __init__(self, parent):
        import string
        parent.title = "DICOM"
        parent.categories = ["", "Informatics"]  # top level module
        parent.contributors = ["Steve Pieper (Isomics)"]
        parent.helpText = string.Template("""
The DICOM module integrates DICOM classes from CTK (based on DCMTK).  See <a href=\"$a/Documentation/$b.$c/Modules/DICOM\">the documentaiton</a> for more information.
""").substitute({
            'a': parent.slicerWikiUrl,
            'b': slicer.app.majorVersion,
            'c': slicer.app.minorVersion
        })
        parent.acknowledgementText = """
This work is supported by NA-MIC, NAC, BIRN, NCIGT, and the Slicer Community. See <a href=http://www.slicer.org>http://www.slicer.org</a> for details.  Module implemented by Steve Pieper.  Based on work from CommonTK (http://www.commontk.org).
    """
        parent.icon = qt.QIcon(':Icons/Medium/SlicerLoadDICOM.png')
        self.parent = parent

        if slicer.mrmlScene.GetTagByClassName(
                "vtkMRMLScriptedModuleNode") != 'ScriptedModule':
            slicer.mrmlScene.RegisterNodeClass(vtkMRMLScriptedModuleNode())

        # initialize the dicom infrastructure
        slicer.dicomDatabase = None
        settings = qt.QSettings()
        # the dicom database is a global object for slicer
        if settings.contains('DatabaseDirectory'):
            databaseDirectory = settings.value('DatabaseDirectory')
            if databaseDirectory:
                slicer.dicomDatabase = ctk.ctkDICOMDatabase()
                slicer.dicomDatabase.openDatabase(
                    databaseDirectory + "/ctkDICOM.sql", "SLICER")
                if not slicer.dicomDatabase.isOpen:
                    # can't open the database, so prompt the user later if they enter module
                    slicer.dicomDatabase = None
                else:
                    # the dicom listener is also global, but only started on app start if
                    # the user so chooses
                    if settings.contains('DICOM/RunListenerAtStart'):
                        if settings.value(
                                'DICOM/RunListenerAtStart') == 'true':
                            if not hasattr(slicer, 'dicomListener'):
                                try:
                                    slicer.dicomListener = DICOMLib.DICOMListener(
                                        slicer.dicomDatabase)
                                    slicer.dicomListener.start()
                                except (UserWarning, OSError) as message:
                                    # TODO: how to put this into the error log?
                                    print(
                                        'Problem trying to start DICOMListener:\n %s'
                                        % message)
                if slicer.dicomDatabase:
                    slicer.app.setDICOMDatabase(slicer.dicomDatabase)

        # Trigger the menu to be added when application has started up
        if not slicer.app.commandOptions().noMainWindow:
            qt.QTimer.singleShot(0, self.addMenu)
        # set the dicom pre-cache tags once all plugin classes have been initialized
        qt.QTimer.singleShot(0, DICOM.setDatabasePrecacheTags)
Esempio n. 2
0
    def __init__(self, parent):
        ScriptedLoadableModule.__init__(self, parent)

        import string
        self.parent.title = "DICOM"
        self.parent.categories = ["", "Informatics"]  # top level module
        self.parent.contributors = ["Steve Pieper (Isomics)"]
        self.parent.helpText = """
The DICOM module integrates DICOM classes from CTK (based on DCMTK).
"""
        self.parent.helpText += self.getDefaultModuleDocumentationLink()
        self.parent.acknowledgementText = """
This work is supported by NA-MIC, NAC, BIRN, NCIGT, and the Slicer Community. See <a href=http://www.slicer.org>http://www.slicer.org</a> for details.  Module implemented by Steve Pieper.  Based on work from CommonTK (http://www.commontk.org).
"""
        self.parent.icon = qt.QIcon(':Icons/Medium/SlicerLoadDICOM.png')
        self.parent.dependencies = ["SubjectHierarchy"]

        if slicer.mrmlScene.GetTagByClassName(
                "vtkMRMLScriptedModuleNode") != 'ScriptedModule':
            slicer.mrmlScene.RegisterNodeClass(vtkMRMLScriptedModuleNode())

        # initialize the dicom infrastructure
        slicer.dicomDatabase = None
        settings = qt.QSettings()
        # the dicom database is a global object for slicer
        if settings.contains('DatabaseDirectory'):
            databaseDirectory = settings.value('DatabaseDirectory')
            if databaseDirectory:
                slicer.dicomDatabase = ctk.ctkDICOMDatabase()
                slicer.dicomDatabase.openDatabase(
                    databaseDirectory + "/ctkDICOM.sql", "SLICER")
                if not slicer.dicomDatabase.isOpen:
                    # can't open the database, so prompt the user later if they enter module
                    slicer.dicomDatabase = None
                else:
                    # the dicom listener is also global, but only started on app start if
                    # the user so chooses
                    if settings.contains('DICOM/RunListenerAtStart'):
                        if settings.value(
                                'DICOM/RunListenerAtStart') == 'true':
                            if not hasattr(slicer, 'dicomListener'):
                                try:
                                    slicer.dicomListener = DICOMLib.DICOMListener(
                                        slicer.dicomDatabase)
                                    slicer.dicomListener.start()
                                except (UserWarning, OSError) as message:
                                    logging.error(
                                        'Problem trying to start DICOMListener:\n %s'
                                        % message)
                if slicer.dicomDatabase:
                    slicer.app.setDICOMDatabase(slicer.dicomDatabase)

        # Tasks to execute after the application has started up
        slicer.app.connect("startupCompleted()",
                           self.performPostModuleDiscoveryTasks)
Esempio n. 3
0
 def startListener(self):
   # the dicom listener is also global, but only started on app start if
   # the user so chooses
   settings = qt.QSettings()
   if settings.contains('DICOM/RunListenerAtStart'):
     if settings.value('DICOM/RunListenerAtStart') == 'true':
       if not hasattr(slicer, 'dicomListener'):
         try:
           slicer.dicomListener = DICOMLib.DICOMListener(slicer.dicomDatabase)
           slicer.dicomListener.start()
         except (UserWarning,OSError) as message:
           logging.error('Problem trying to start DICOMListener:\n %s' % message)
Esempio n. 4
0
 def onToggleListener(self):
   if hasattr(slicer, 'dicomListener'):
     slicer.dicomListener.stop()
     del slicer.dicomListener
     self.toggleListener.text = "Start Listener"
   else:
     try:
       slicer.dicomListener = DICOMLib.DICOMListener(database=slicer.dicomDatabase)
       slicer.dicomListener.start()
       self.onListenerStateChanged(slicer.dicomListener.process.state())
       slicer.dicomListener.process.connect('stateChanged(QProcess::ProcessState)',self.onListenerStateChanged)
       slicer.dicomListener.fileToBeAddedCallback = self.onListenerToAddFile
       slicer.dicomListener.fileAddedCallback = self.onListenerAddedFile
       self.toggleListener.text = "Stop Listener"
     except UserWarning as message:
       self.messageBox(self,"Could not start listener:\n %s" % message,title='DICOM')
Esempio n. 5
0
 def onToggleListener(self):
   self.toggleListener.checked = False
   if hasattr(slicer, 'dicomListener'):
     slicer.dicomListener.stop()
     del slicer.dicomListener
   else:
     try:
       dicomListener = DICOMLib.DICOMListener(database=slicer.dicomDatabase)
       dicomListener.start()
       if dicomListener.process:
         self.onListenerStateChanged(dicomListener.process.state())
         dicomListener.process.connect('stateChanged(QProcess::ProcessState)',self.onListenerStateChanged)
         dicomListener.fileToBeAddedCallback = self.onListenerToAddFile
         dicomListener.fileAddedCallback = self.onListenerAddedFile
         slicer.dicomListener = dicomListener
     except UserWarning as message:
       slicer.util.warningDisplay("Could not start listener:\n %s" % message, windowTitle="DICOM")
Esempio n. 6
0
  def startListener(self):

    if not slicer.dicomDatabase.isOpen:
      logging.error("Failed to start DICOM listener. DICOM database is not open.")
      return False

    if not hasattr(slicer, 'dicomListener'):
      try:
        dicomListener = DICOMLib.DICOMListener(slicer.dicomDatabase)
        dicomListener.start()
      except (UserWarning, OSError) as message:
        logging.error('Problem trying to start DICOM listener:\n %s' % message)
        return False
      if not dicomListener.process:
        logging.error("Failed to start DICOM listener. Process start failed.")
        return False
      slicer.dicomListener = dicomListener
      logging.info("DICOM C-Store SCP service started at port "+str(slicer.dicomListener.port))
Esempio n. 7
0
    def __init__(self, parent):
        parent.title = "DICOM"
        parent.category = ""  # top level module
        parent.contributor = "Steve Pieper"
        parent.helpText = """
The DICOM module is a place to experiment a bit with dicom classes from CTK (based on DCMTK).  It is a 'tent' because it is meant to be suitable for explorers, but may not be robust enough for civilized people.

Warning: all data directories are temporary and data may be gone next time you look!
    """
        parent.acknowledgementText = """
This work is supported by NA-MIC, NAC, BIRN, NCIGT, and the Slicer Community. See <a>http://www.slicer.org</a> for details.  Module implemented by Steve Pieper.  Based on work from CommonTK (http://www.commontk.org).
    """
        self.parent = parent

        if slicer.mrmlScene.GetTagByClassName(
                "vtkMRMLScriptedModuleNode") != 'ScriptedModule':
            slicer.mrmlScene.RegisterNodeClass(vtkMRMLScriptedModuleNode())

        # initialize the dicom infrastructure
        settings = qt.QSettings()
        # the dicom database is a global object for slicer
        databaseDirectory = settings.value('DatabaseDirectory')
        if databaseDirectory:
            slicer.dicomDatabase = ctk.ctkDICOMDatabase()
            slicer.dicomDatabase.openDatabase(
                databaseDirectory + "/ctkDICOM.sql", "SLICER")
            # the dicom listener is also global, but only started on app start if
            # the user so chooses
            if settings.contains('DICOM/RunListenerAtStart'):
                if bool(settings.value('DICOM/RunListenerAtStart')):
                    if not hasattr(slicer, 'dicomListener'):
                        try:
                            slicer.dicomListener = DICOMLib.DICOMListener(
                                slicer.dicomDatabase)
                        except UserWarning as message:
                            # TODO: how to put this into the error log?
                            print(
                                'Problem trying to start DICOMListener:\n %s' %
                                message)
                        slicer.dicomListener.start()