소스 검색

Merge branch 'master' of github.com:pieper/CTK

Steve Pieper 15 년 전
부모
커밋
e217decfe5

+ 2 - 2
CMake/ctkMacroBuildQtLib.cmake

@@ -3,7 +3,7 @@
 #
 #
 MACRO(CtkMacroBuildQtLib)
-  CtkMacroParseArguments(MYQTLIB
+  ctkMacroParseArguments(MYQTLIB
     "NAME;EXPORT_DIRECTIVE;SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES;LIBRARY_TYPE"
     ""
     ${ARGN}
@@ -96,6 +96,6 @@ MACRO(CtkMacroBuildQtLib)
     DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
     )
 
-ENDMACRO(CtkMacroBuildQtLib)
+ENDMACRO()
 
 

+ 1 - 1
CMake/ctkMacroBuildQtPlugin.cmake

@@ -93,6 +93,6 @@ MACRO(CtkMacroBuildQtPlugin)
   #  DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
   #  )
 
-ENDMACRO(CtkMacroBuildQtPlugin)
+ENDMACRO()
 
 

+ 17 - 0
CMake/ctkMacroGetTargetLibraries.cmake

@@ -0,0 +1,17 @@
+
+MACRO(ctkMacroGetTargetLibraries varname)
+
+  SET(target_libraries_path ${CMAKE_CURRENT_SOURCE_DIR}/target_libraries.cmake)
+  
+  # Check if "target_libraries.cmake" file exists
+  IF(NOT EXISTS ${target_libraries_path})
+    MESSAGE(FATAL_ERROR "${target_libraries_path} doesn't exists !")
+  ENDIF()
+
+  # Make sure the variable is cleared 
+  SET(target_libraries )
+
+  INCLUDE(${target_libraries_path})
+
+  SET(${varname} ${target_libraries})
+ENDMACRO()

+ 1 - 1
CMake/ctkMacroParseArguments.cmake

@@ -31,4 +31,4 @@ MACRO(CtkMacroParseArguments prefix arg_names option_names)
     ENDIF (is_arg_name GREATER -1)
   ENDFOREACH(arg)
   SET(${prefix}_${current_arg_name} ${current_arg_list})
-ENDMACRO(CtkMacroParseArguments)
+ENDMACRO()

+ 5 - 1
CMake/ctkMacroSetupQt.cmake

@@ -14,6 +14,10 @@ MACRO(ctkMacroSetupQt)
   SET(minimum_required_qt_version "4.6")
 
   FIND_PACKAGE(Qt4)
+
+  # This option won't show up in the main CMake configure panel
+  MARK_AS_ADVANCED(QT_QMAKE_EXECUTABLE)
+  
   IF(QT4_FOUND)
 
     IF(NOT "${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" STREQUAL "${minimum_required_qt_version}")
@@ -30,4 +34,4 @@ MACRO(ctkMacroSetupQt)
     MESSAGE(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
   ENDIF(QT4_FOUND)
 
-ENDMACRO(ctkMacroSetupQt)
+ENDMACRO()

+ 9 - 4
CMakeLists.txt

@@ -47,6 +47,7 @@ INCLUDE(CMake/ctkMacroParseArguments.cmake)
 INCLUDE(CMake/ctkMacroBuildQtLib.cmake)
 INCLUDE(CMake/ctkMacroBuildQtPlugin.cmake)
 INCLUDE(CMake/ctkMacroSetupQt.cmake)
+INCLUDE(CMake/ctkMacroGetTargetLibraries.cmake)
 
 #-----------------------------------------------------------------------------
 # Testing
@@ -104,13 +105,17 @@ SET(ctk_libs
 # before the SuperBuild script is included
 #
 
+# Let's mark as advanced some default properties
+MARK_AS_ADVANCED(CMAKE_INSTALL_PREFIX)
+MARK_AS_ADVANCED(DART_TESTING_TIMEOUT)
+
 # KWStyle
 OPTION(CTK_USE_KWSTYLE     "Enable sourcecode-based style tests." OFF)
-MARK_AS_ADVANCED(CTK_USE_KWSTYLE)
+#MARK_AS_ADVANCED(CTK_USE_KWSTYLE)
 
 # Build options
 FOREACH(lib ${ctk_libs})
-  OPTION(CTK_USE_${lib} "Enable ${lib} Support." ON)
+  OPTION(CTK_ENABLE_${lib} "Enable ${lib} Support." ON)
 ENDFOREACH()
 
 #-----------------------------------------------------------------------------
@@ -128,11 +133,11 @@ ENDIF()
 # Add subdirectories
 #
 FOREACH(lib ${ctk_libs})
-  IF (CTK_USE_${lib})
+  IF (CTK_ENABLE_${lib})
     ADD_SUBDIRECTORY(Libs/${lib})
   ENDIF()
 ENDFOREACH()
-
+    
 #-----------------------------------------------------------------------------
 # Style Checking configuration
 #

+ 3 - 4
Libs/Core/CMakeLists.txt

@@ -28,11 +28,10 @@ SET(KIT_UI_FORMS
 SET(KIT_resources
 )
 
-# Additional Target libraries
-SET(KIT_target_libraries
-  ${QT_LIBRARIES}
-  )
+# Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake
+ctkMacroGetTargetLibraries(KIT_target_libraries)
 
+# See CMake/ctkMacroBuildQtLib.cmake
 ctkMacroBuildQtLib(
   NAME ${PROJECT_NAME}
   EXPORT_DIRECTIVE ${KIT_export_directive}

+ 9 - 0
Libs/Core/target_libraries.cmake

@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK libraries
+#
+
+SET(target_libraries
+  ${QT_LIBRARIES}
+  )

+ 3 - 4
Libs/DICOM/Core/CMakeLists.txt

@@ -33,11 +33,10 @@ SET(KIT_resources
   Resources/dicom.qrc
 )
 
-# Additional Target libraries
-SET(KIT_target_libraries
-  CTKCore
-  )
+# Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake
+ctkMacroGetTargetLibraries(KIT_target_libraries)
 
+# See CMake/ctkMacroBuildQtLib.cmake
 ctkMacroBuildQtLib(
   NAME ${PROJECT_NAME}
   EXPORT_DIRECTIVE ${KIT_export_directive}

+ 5 - 0
Libs/DICOM/Core/Resources/dicom-sample.sql

@@ -3,6 +3,11 @@
 -- For the corresponding DICOM files and more information see
 -- http://www.slicer.org/slicerWiki/index.php/DICOM:Database
 -- 
+-- Note: the semicolon at the end is necessary for the simple parser to separate
+--       the statements since the SQlite driver does not handle multiple
+--       commands per QSqlQuery::exec call!
+-- ;
+ 
 BEGIN TRANSACTION;
 CREATE TABLE 'Images' (   'Filename' VARCHAR(1024) NOT NULL ,   'SeriesInstanceUID' VARCHAR(255) NOT NULL ,   PRIMARY KEY ('Filename') );
 INSERT INTO "Images" VALUES('CTHeadAxialDicom/CTHead24.dcm','1.2.826.0.1.3680043.2.1125.1.65375240934815452318141136507497058');

+ 5 - 2
Libs/DICOM/Core/Resources/dicom-schema.sql

@@ -1,8 +1,11 @@
 -- 
+-- A simple SQLITE3 database schema for modelling locally stored DICOM files 
 -- 
+-- Note: the semicolon at the end is necessary for the simple parser to separate
+--       the statements since the SQlite driver does not handle multiple
+--       commands per QSqlQuery::exec call!
+-- ;
 
-BEGIN TRANSACTION;
 DROP TABLE IF EXISTS 'Images' ;
 DROP TABLE IF EXISTS 'Patients' ;
 DROP TABLE IF EXISTS 'Series' ;
@@ -46,5 +49,4 @@ CREATE TABLE 'Studies' (
   'ReferringPhysician' VARCHAR(255) NULL ,
   'StudyDescription' VARCHAR(255) NULL ,
   PRIMARY KEY ('StudyInstanceUID') );
-COMMIT;
 

+ 1 - 1
Libs/DICOM/Core/Testing/CMakeLists.txt

@@ -19,4 +19,4 @@ IF(WIN32)
 ENDIF(WIN32)
 
 ADD_TEST( qCTKDCMTKModelTest1 ${CTKDICOMCore_TESTS} qCTKDCMTKModelTest1 ../../Resources/dicom-sample.sql)
-ADD_TEST( qCTKDCMTKTest1 ${CTKDICOMCore_TESTS} qCTKDCMTKTest1 ${CMAKE_CURRENT_BINARY_DIR}/dicom.db)
+ADD_TEST( qCTKDCMTKTest1 ${CTKDICOMCore_TESTS} qCTKDCMTKTest1 ${CMAKE_CURRENT_BINARY_DIR}/dicom.db ${CMAKE_CURRENT_SOURCE_DIR}/../Resources/dicom-sample.sql)

+ 4 - 0
Libs/DICOM/Core/Testing/qCTKDCMTKTest1.cxx

@@ -14,7 +14,11 @@ int qCTKDCMTKTest1(int argc, char** argv) {
   if ( myCTK.openDatabase( argv[1]) )
     {
     out << "open db success\n";
+    /// make sure it is empty and properly initialized
     myCTK.initializeDatabase();
+    /// insert some sample data
+    myCTK.initializeDatabase(argv[2]);
+    myCTK.closeDatabase();
     }
   else
     { 

+ 28 - 20
Libs/DICOM/Core/qCTKDCMTK.cxx

@@ -44,9 +44,6 @@ qCTKDCMTK::~qCTKDCMTK()
 }
 
 //----------------------------------------------------------------------------
-QCTK_SET_CXX(qCTKDCMTK, const QString&, setDatabaseFileName, DatabaseFileName);
-
-//----------------------------------------------------------------------------
 bool qCTKDCMTK::openDatabase(const QString& databaseFileName) 
 {
   QCTK_D(qCTKDCMTK);
@@ -57,44 +54,55 @@ bool qCTKDCMTK::openDatabase(const QString& databaseFileName)
     d->LastError = d->Database.lastError().text();
     return false;
     }
+  if ( d->Database.tables().empty() ) 
+    {
+    initializeDatabase();
+    }
   return true;
 }
 const QString& qCTKDCMTK::GetLastError() const {
   QCTK_D(const qCTKDCMTK);
   return d->LastError; 
 }
-QSqlDatabase& qCTKDCMTK::database() {
-  QCTK_D(qCTKDCMTK);
+const QSqlDatabase& qCTKDCMTK::database() const {
+  QCTK_D(const qCTKDCMTK);
   return d->Database;
 }
 
 bool qCTKDCMTKPrivate::executeScript(const QString& script) {
   QFile scriptFile(script);
-  qDebug() << scriptFile.exists();
-  qDebug() << scriptFile.size();
-  QString sqlCommands( scriptFile.readAll() );
-  qDebug() << sqlCommands ;
+  scriptFile.open(QIODevice::ReadOnly);
+  QString sqlCommands( QTextStream(&scriptFile).readAll() );
   sqlCommands.replace( '\n', ' ' );
   sqlCommands.replace("; ", ";\n");
+
   QStringList sqlCommandsLines = sqlCommands.split('\n');
+
   QSqlQuery query(Database);
+
   for (QStringList::iterator it = sqlCommandsLines.begin(); it != sqlCommandsLines.end()-1; ++it)
-    {
-    query.exec(*it);
-    if (query.lastError().type())
+  {
+    if (! (*it).startsWith("--") )
       {
-      std::cerr 
-      << "There was an error during execution of the statement: " 
-      << (*it).toStdString();
+      query.exec(*it);
+      if (query.lastError().type())
+        {
+        qDebug() << "There was an error during execution of the statement: " << (*it);
+        return false;
+        }
       }
-      return false;
-    }
+  }
   return true;
 }
 
-bool qCTKDCMTK::initializeDatabase() 
+bool qCTKDCMTK::initializeDatabase(const char* sqlFileName) 
 {
   QCTK_D(qCTKDCMTK);
-  return d->executeScript(":/dicom/dicom-schema.sql");
+  return d->executeScript(sqlFileName);
+}
+  
+void qCTKDCMTK::closeDatabase()
+{
+  QCTK_D(qCTKDCMTK);
+  d->Database.close();
 }
-

+ 9 - 11
Libs/DICOM/Core/qCTKDCMTK.h

@@ -19,23 +19,21 @@ public:
   explicit qCTKDCMTK(QObject* parent = 0);
   virtual ~qCTKDCMTK();
   
-  /// 
-  /// 
-  void setDatabaseFileName(const QString& file);
-  
   ///
-  /// open the SQLite database in file
+  /// open the SQLite database in @param file. If the file does not
+  /// exist, a new database is created and initialized with the
+  /// default schema
   virtual bool openDatabase(const QString& file);
 
-  QSqlDatabase& database();
+  const QSqlDatabase& database() const;
   const QString& GetLastError() const; 
   
-  
-  
   ///
-  /// delete all data and initialize the database with
-  /// the default schema
-  bool initializeDatabase();
+  /// close the database. It must not be used afterwards.
+  void closeDatabase();  
+  ///
+  /// delete all data and reinitialize the database.
+  bool initializeDatabase(const char* schemaFile = ":/dicom/dicom-schema.sql");
 private:
   QCTK_DECLARE_PRIVATE(qCTKDCMTK);
 };

+ 9 - 0
Libs/DICOM/Core/target_libraries.cmake

@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK libraries
+# 
+
+SET(target_libraries
+  CTKCore
+  )

+ 4 - 6
Libs/DICOM/Widgets/CMakeLists.txt

@@ -35,12 +35,10 @@ SET(KIT_UI_FORMS
 SET(KIT_resources
 )
 
-# Additional Target libraries
-SET(KIT_target_libraries
-  CTKCore
-  CTKDICOMCore
-  )
-
+# Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake
+ctkMacroGetTargetLibraries(KIT_target_libraries)
+  
+# See CMake/ctkMacroBuildQtLib.cmake
 ctkMacroBuildQtLib(
   NAME ${PROJECT_NAME}
   EXPORT_DIRECTIVE ${KIT_export_directive}

+ 10 - 0
Libs/DICOM/Widgets/target_libraries.cmake

@@ -0,0 +1,10 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK libraries
+# 
+
+SET(target_libraries
+  CTKCore
+  CTKDICOMCore
+  )

+ 3 - 4
Libs/Widgets/CMakeLists.txt

@@ -29,11 +29,10 @@ SET(KIT_UI_FORMS
 SET(KIT_resources
 )
 
-# Additional Target libraries
-SET(KIT_target_libraries
-  CTKCore
-  )
+# Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake
+ctkMacroGetTargetLibraries(KIT_target_libraries)
 
+# See CMake/ctkMacroBuildQtLib.cmake
 ctkMacroBuildQtLib(
   NAME ${PROJECT_NAME}
   EXPORT_DIRECTIVE ${KIT_export_directive}

+ 9 - 0
Libs/Widgets/target_libraries.cmake

@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK libraries
+#
+
+SET(target_libraries
+  CTKCore
+  )

+ 14 - 0
SuperBuild.cmake

@@ -81,6 +81,19 @@ ExternalProject_Add(${proj}
     )
 
 #-----------------------------------------------------------------------------
+# Utilities/ZMQ
+#
+SET(proj ZMQ)
+ExternalProject_Add(${proj}
+    DOWNLOAD_COMMAND ""
+    INSTALL_COMMAND ""
+    CMAKE_GENERATOR ${gen}
+    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/ZMQ
+    CMAKE_ARGS
+      ${ep_common_args}
+    )
+    
+#-----------------------------------------------------------------------------
 # CTK Utilities
 #
 set(proj CTK-Utilities)
@@ -92,6 +105,7 @@ ExternalProject_Add(${proj}
   DEPENDS
     ${kwstyle_DEPENDS}
     "DCMTK"
+    "ZMQ"
 )
   
 #-----------------------------------------------------------------------------