Browse Source

Merge branch 'add_dicomutil'

* add_dicomutil:
  Re-factor ctkDICOMUtil to be consistent with ctkUtil
  Define ctkErrorLogLevel::logLevelAsString as static for easier re-use
  Add ctkDICOMUtil and ::setDICOMLogLevel helper
Jean-Christophe Fillion-Robin 11 years ago
parent
commit
71c234bb8f

+ 1 - 1
CMakeExternals/PythonQt.cmake

@@ -53,7 +53,7 @@ if(${add_project})
         message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
       endif()
 
-      set(revision_tag 9c92fd212605bb5ff4d462323763acf65d87e4a7)
+      set(revision_tag e1f1c77d9675c3c5fb1cba19d2a32ace483eda2c)
       if(${proj}_REVISION_TAG)
         set(revision_tag ${${proj}_REVISION_TAG})
       endif()

+ 13 - 0
Libs/Core/ctkCorePythonQtDecorators.h

@@ -25,6 +25,7 @@
 #include <PythonQt.h>
 
 // CTK includes
+#include <ctkErrorLogModel.h>
 #include <ctkWorkflowStep.h>
 #include <ctkWorkflowTransitions.h>
 
@@ -160,11 +161,23 @@ public Q_SLOTS:
     {
     delete transition;
     }
+
+  // ctkErrorLogLevel
+
+  QString static_ctkErrorLogLevel_logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)
+    {
+    return ctkErrorLogLevel::logLevelAsString(logLevel);
+    }
 };
 
 //-----------------------------------------------------------------------------
 void initCTKCorePythonQtDecorators()
 {
+  // HACK: Since the CMake based light wrapping only consider class name matching the
+  //       filename where the class is defined, let's explicitly register ctkErrorLogLevel
+  //       so that the log level QFlags are exposed to python.
+  PythonQt::self()->registerClass(&ctkErrorLogLevel::staticMetaObject, "CTKCore");
+
   PythonQt::self()->addDecorators(new ctkCorePythonQtDecorators);
 }
 

+ 3 - 3
Libs/Core/ctkErrorLogModel.cpp

@@ -55,13 +55,13 @@ ctkErrorLogLevel::ctkErrorLogLevel()
 // --------------------------------------------------------------------------
 QString ctkErrorLogLevel::operator()(ctkErrorLogLevel::LogLevel logLevel)
 {
-  return this->logLevelAsString(logLevel);
+  return ctkErrorLogLevel::logLevelAsString(logLevel);
 }
 
 // --------------------------------------------------------------------------
-QString ctkErrorLogLevel::logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)const
+QString ctkErrorLogLevel::logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)
 {
-  QMetaEnum logLevelEnum = this->metaObject()->enumerator(0);
+  QMetaEnum logLevelEnum = ctkErrorLogLevel::staticMetaObject.enumerator(0);
   Q_ASSERT(QString("LogLevel").compare(logLevelEnum.name()) == 0);
   return QLatin1String(logLevelEnum.valueToKey(logLevel));
 }

+ 1 - 1
Libs/Core/ctkErrorLogModel.h

@@ -54,7 +54,7 @@ public:
 
   QString operator ()(LogLevel logLevel);
 
-  QString logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)const;
+  static QString logLevelAsString(ctkErrorLogLevel::LogLevel logLevel);
 };
 Q_DECLARE_OPERATORS_FOR_FLAGS(ctkErrorLogLevel::LogLevels)
 

+ 2 - 0
Libs/DICOM/Core/CMakeLists.txt

@@ -48,6 +48,8 @@ set(KIT_SRCS
   ctkDICOMRetrieve.h
   ctkDICOMTester.cpp
   ctkDICOMTester.h
+  ctkDICOMUtil.cpp
+  ctkDICOMUtil.h
 )
 
 if(DCMTK_VERSION_IS_360)

+ 24 - 0
Libs/DICOM/Core/ctkDICOMCorePythonQtDecorators.h

@@ -25,6 +25,7 @@
 #include <PythonQt.h>
 
 // CTK includes
+#include <ctkDICOMUtil.h>
 
 // NOTE:
 //
@@ -52,9 +53,32 @@ public Q_SLOTS:
 };
 
 //-----------------------------------------------------------------------------
+class PythonQtWrapper_CTKDICOMCore : public QObject
+{
+  Q_OBJECT
+
+public Q_SLOTS:
+  ctkErrorLogLevel::LogLevel static_ctk_dicomLogLevel()
+    {
+    return ctk::dicomLogLevel();
+    }
+
+  void static_ctk_setDICOMLogLevel(ctkErrorLogLevel::LogLevel level)
+    {
+    ctk::setDICOMLogLevel(level);
+    }
+
+  QString static_ctk_dicomLogLevelAsString()
+    {
+    return ctk::dicomLogLevelAsString();
+    }
+};
+
+//-----------------------------------------------------------------------------
 void initCTKDICOMCorePythonQtDecorators()
 {
   PythonQt::self()->addDecorators(new ctkDICOMCorePythonQtDecorators);
+  PythonQt::self()->registerCPPClass("ctk", "", "CTKDICOMCore", PythonQtCreateObject<PythonQtWrapper_CTKDICOMCore>);
 }
 
 #endif

+ 69 - 0
Libs/DICOM/Core/ctkDICOMUtil.cpp

@@ -0,0 +1,69 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Brigham & Women's Hospital
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QDebug>
+
+// CTK includes
+#include "ctkDICOMUtil.h"
+
+// DCMTK includes
+#include <dcmtk/dcmnet/diutil.h>
+
+//------------------------------------------------------------------------------
+void ctk::setDICOMLogLevel(ctkErrorLogLevel::LogLevel level)
+{
+  dcmtk::log4cplus::Logger log = dcmtk::log4cplus::Logger::getRoot();
+  switch (level)
+    {
+    case ctkErrorLogLevel::Trace: log.setLogLevel(OFLogger::TRACE_LOG_LEVEL); break;
+    case ctkErrorLogLevel::Debug: log.setLogLevel(OFLogger::DEBUG_LOG_LEVEL); break;
+    case ctkErrorLogLevel::Info: log.setLogLevel(OFLogger::INFO_LOG_LEVEL); break;
+    case ctkErrorLogLevel::Warning: log.setLogLevel(OFLogger::WARN_LOG_LEVEL); break;
+    case ctkErrorLogLevel::Error: log.setLogLevel(OFLogger::ERROR_LOG_LEVEL); break;
+    case ctkErrorLogLevel::Fatal: log.setLogLevel(OFLogger::FATAL_LOG_LEVEL); break;
+    default:
+      qWarning() << "Failed to set DICOM log level - Supported levels are Trace, Debug, "
+                    "Info, Warning, Error and Fatal !";
+      break;
+    }
+}
+
+//------------------------------------------------------------------------------
+ctkErrorLogLevel::LogLevel ctk::dicomLogLevel()
+{
+  dcmtk::log4cplus::Logger log = dcmtk::log4cplus::Logger::getRoot();
+  switch (log.getLogLevel())
+    {
+    case OFLogger::TRACE_LOG_LEVEL: return ctkErrorLogLevel::Trace;
+    case OFLogger::DEBUG_LOG_LEVEL: return ctkErrorLogLevel::Debug;
+    case OFLogger::INFO_LOG_LEVEL: return ctkErrorLogLevel::Info;
+    case OFLogger::WARN_LOG_LEVEL: return ctkErrorLogLevel::Warning;
+    case OFLogger::ERROR_LOG_LEVEL: return ctkErrorLogLevel::Error;
+    case OFLogger::FATAL_LOG_LEVEL: return ctkErrorLogLevel::Fatal;
+    default: return ctkErrorLogLevel::None;
+    }
+}
+
+//------------------------------------------------------------------------------
+QString ctk::dicomLogLevelAsString()
+{
+  return ctkErrorLogLevel::logLevelAsString(ctk::dicomLogLevel());
+}

+ 38 - 0
Libs/DICOM/Core/ctkDICOMUtil.h

@@ -0,0 +1,38 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Brigham & Women's Hospital
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkDICOMUtil_h
+#define __ctkDICOMUtil_h
+
+// CTK includes
+#include "ctkDICOMCoreExport.h"
+#include "ctkErrorLogModel.h"
+
+namespace ctk {
+
+void CTK_DICOM_CORE_EXPORT setDICOMLogLevel(ctkErrorLogLevel::LogLevel level);
+
+ctkErrorLogLevel::LogLevel CTK_DICOM_CORE_EXPORT dicomLogLevel();
+
+QString CTK_DICOM_CORE_EXPORT dicomLogLevelAsString();
+
+} // end of ctk namespace
+
+#endif