diff --git a/Core/Code/Common/mitkCoreObjectFactory.cpp b/Core/Code/Common/mitkCoreObjectFactory.cpp index 42711ff4d9..61e9cbb735 100644 --- a/Core/Code/Common/mitkCoreObjectFactory.cpp +++ b/Core/Code/Common/mitkCoreObjectFactory.cpp @@ -1,505 +1,501 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkConfig.h" #include "mitkCoreObjectFactory.h" #include "mitkAffineInteractor.h" #include "mitkColorProperty.h" #include "mitkDataNode.h" #include "mitkEnumerationProperty.h" #include "mitkGeometry2DData.h" #include "mitkGeometry2DDataMapper2D.h" #include "mitkGeometry2DDataVtkMapper3D.h" #include "mitkGeometry3D.h" #include "mitkGeometryData.h" #include "mitkImage.h" #include #include "mitkLevelWindowProperty.h" #include "mitkLookupTable.h" #include "mitkLookupTableProperty.h" #include "mitkPlaneGeometry.h" #include "mitkPointSet.h" #include "mitkPointSetVtkMapper2D.h" #include "mitkPointSetVtkMapper3D.h" #include "mitkPolyDataGLMapper2D.h" #include "mitkProperties.h" #include "mitkPropertyList.h" #include "mitkSlicedGeometry3D.h" #include "mitkSmartPointerProperty.h" #include "mitkStringProperty.h" #include "mitkSurface.h" #include "mitkSurface.h" #include "mitkSurfaceGLMapper2D.h" #include "mitkSurfaceVtkMapper3D.h" #include "mitkTimeSlicedGeometry.h" #include "mitkTransferFunctionProperty.h" #include "mitkVolumeDataVtkMapper3D.h" #include "mitkVtkInterpolationProperty.h" #include "mitkVtkRepresentationProperty.h" #include "mitkVtkResliceInterpolationProperty.h" //#include "mitkPicFileIOFactory.h" #include "mitkPointSetIOFactory.h" #include "mitkItkImageFileIOFactory.h" #include "mitkSTLFileIOFactory.h" #include "mitkVtkSurfaceIOFactory.h" #include "mitkVtkImageIOFactory.h" #include "mitkVtiFileIOFactory.h" //#include "mitkPicVolumeTimeSeriesIOFactory.h" #include "mitkImageWriterFactory.h" #include "mitkImageWriter.h" #include "mitkPointSetWriterFactory.h" #include "mitkSurfaceVtkWriterFactory.h" // Legacy Support: -#include -#include +#include +#include #include #include #include #include mitk::CoreObjectFactory::FileWriterList mitk::CoreObjectFactory::m_FileWriters; std::list< mitk::LegacyFileReaderService* > mitk::CoreObjectFactory::m_LegacyReaders; std::list< mitk::LegacyFileWriterService* > mitk::CoreObjectFactory::m_LegacyWriters; std::list< mitk::LegacyImageWriterService* > mitk::CoreObjectFactory::m_LegacyImageWriters; void mitk::CoreObjectFactory::RegisterExtraFactory(CoreObjectFactoryBase* factory) { MITK_DEBUG << "CoreObjectFactory: registering extra factory of type " << factory->GetNameOfClass(); m_ExtraFactories.insert(CoreObjectFactoryBase::Pointer(factory)); // Register Legacy Reader and Writer this->RegisterLegacyReaders(this); this->RegisterLegacyWriters(); } void mitk::CoreObjectFactory::UnRegisterExtraFactory(CoreObjectFactoryBase *factory) { MITK_DEBUG << "CoreObjectFactory: un-registering extra factory of type " << factory->GetNameOfClass(); try { m_ExtraFactories.erase(factory); } catch( std::exception const& e) { MITK_ERROR << "Caugt exception while unregistering: " << e.what(); } } mitk::CoreObjectFactory::Pointer mitk::CoreObjectFactory::GetInstance() { static mitk::CoreObjectFactory::Pointer instance; if (instance.IsNull()) { - instance = mitk::CoreObjectFactory::New(); + instance = mitk::CoreObjectFactory::New(); } return instance; } #include void mitk::CoreObjectFactory::SetDefaultProperties(mitk::DataNode* node) { if(node==NULL) return; mitk::DataNode::Pointer nodePointer = node; mitk::Image::Pointer image = dynamic_cast(node->GetData()); if(image.IsNotNull() && image->IsInitialized()) { mitk::ImageVtkMapper2D::SetDefaultProperties(node); mitk::VolumeDataVtkMapper3D::SetDefaultProperties(node); } mitk::Surface::Pointer surface = dynamic_cast(node->GetData()); if(surface.IsNotNull()) { mitk::SurfaceGLMapper2D::SetDefaultProperties(node); mitk::SurfaceVtkMapper3D::SetDefaultProperties(node); } mitk::PointSet::Pointer pointSet = dynamic_cast(node->GetData()); if(pointSet.IsNotNull()) { mitk::PointSetVtkMapper2D::SetDefaultProperties(node); mitk::PointSetVtkMapper3D::SetDefaultProperties(node); } for (ExtraFactoriesContainer::iterator it = m_ExtraFactories.begin(); it != m_ExtraFactories.end() ; it++ ) { (*it)->SetDefaultProperties(node); } } mitk::CoreObjectFactory::CoreObjectFactory() { static bool alreadyDone = false; if (!alreadyDone) { MITK_DEBUG << "CoreObjectFactory c'tor" << std::endl; // FIXME itk::ObjectFactoryBase::RegisterFactory( PicFileIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( PointSetIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( STLFileIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( VtkSurfaceIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( VtkImageIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( VtiFileIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( ItkImageFileIOFactory::New() ); // FIXME itk::ObjectFactoryBase::RegisterFactory( PicVolumeTimeSeriesIOFactory::New() ); mitk::SurfaceVtkWriterFactory::RegisterOneFactory(); mitk::PointSetWriterFactory::RegisterOneFactory(); mitk::ImageWriterFactory::RegisterOneFactory(); m_FileWriters.push_back(mitk::ImageWriter::New().GetPointer()); CreateFileExtensionsMap(); alreadyDone = true; } } mitk::Mapper::Pointer mitk::CoreObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper = NULL; mitk::Mapper::Pointer tmpMapper = NULL; // check whether extra factories provide mapper for (ExtraFactoriesContainer::iterator it = m_ExtraFactories.begin(); it != m_ExtraFactories.end() ; it++ ) { tmpMapper = (*it)->CreateMapper(node,id); if(tmpMapper.IsNotNull()) newMapper = tmpMapper; } if (newMapper.IsNull()) { - mitk::BaseData *data = node->GetData(); if ( id == mitk::BaseRenderer::Standard2D ) { if((dynamic_cast(data)!=NULL)) { newMapper = mitk::ImageVtkMapper2D::New(); newMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::Geometry2DDataMapper2D::New(); newMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::SurfaceGLMapper2D::New(); // cast because SetDataNode is not virtual mitk::SurfaceGLMapper2D *castedMapper = dynamic_cast(newMapper.GetPointer()); castedMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::PointSetVtkMapper2D::New(); newMapper->SetDataNode(node); } } else if ( id == mitk::BaseRenderer::Standard3D ) { if((dynamic_cast(data) != NULL)) { newMapper = mitk::VolumeDataVtkMapper3D::New(); newMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::Geometry2DDataVtkMapper3D::New(); newMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::SurfaceVtkMapper3D::New(); newMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::PointSetVtkMapper3D::New(); newMapper->SetDataNode(node); } } } return newMapper; } /* // @deprecated // #define EXTERNAL_FILE_EXTENSIONS \ - "All known formats(*.dcm *.DCM *.dc3 *.DC3 *.gdcm *.ima *.mhd *.mps *.nii *.pic *.pic.gz *.bmp *.png *.jpg *.tiff *.pvtk *.stl *.vtk *.vtp *.vtu *.obj *.vti *.hdr *.nrrd *.nhdr );;" \ - "DICOM files(*.dcm *.DCM *.dc3 *.DC3 *.gdcm);;" \ - "DKFZ Pic (*.seq *.pic *.pic.gz *.seq.gz);;" \ - "NRRD Vector Images (*.nrrd *.nhdr);;" \ - "Point sets (*.mps);;" \ - "Sets of 2D slices (*.pic *.pic.gz *.bmp *.png *.dcm *.gdcm *.ima *.tiff);;" \ - "Surface files (*.stl *.vtk *.vtp *.obj);;" \ - "NIfTI format (*.nii)" +"All known formats(*.dcm *.DCM *.dc3 *.DC3 *.gdcm *.ima *.mhd *.mps *.nii *.pic *.pic.gz *.bmp *.png *.jpg *.tiff *.pvtk *.stl *.vtk *.vtp *.vtu *.obj *.vti *.hdr *.nrrd *.nhdr );;" \ +"DICOM files(*.dcm *.DCM *.dc3 *.DC3 *.gdcm);;" \ +"DKFZ Pic (*.seq *.pic *.pic.gz *.seq.gz);;" \ +"NRRD Vector Images (*.nrrd *.nhdr);;" \ +"Point sets (*.mps);;" \ +"Sets of 2D slices (*.pic *.pic.gz *.bmp *.png *.dcm *.gdcm *.ima *.tiff);;" \ +"Surface files (*.stl *.vtk *.vtp *.obj);;" \ +"NIfTI format (*.nii)" #define SAVE_FILE_EXTENSIONS "all (*.pic *.mhd *.vtk *.vti *.hdr *.png *.tiff *.jpg *.hdr *.bmp *.dcm *.gipl *.nii *.nrrd *.nhdr *.spr *.lsm *.dwi *.hdwi *.qbi *.hqbi)" */ /** - * @brief This method gets the supported (open) file extensions as string. This string is can then used by the QT QFileDialog widget. - * @return The c-string that contains the file extensions - * - */ +* @brief This method gets the supported (open) file extensions as string. This string is can then used by the QT QFileDialog widget. +* @return The c-string that contains the file extensions +* +*/ const char* mitk::CoreObjectFactory::GetFileExtensions() { MultimapType aMap; for (ExtraFactoriesContainer::iterator it = m_ExtraFactories.begin(); it != m_ExtraFactories.end() ; it++ ) { aMap = (*it)->GetFileExtensionsMap(); this->MergeFileExtensions(m_FileExtensionsMap, aMap); } this->CreateFileExtensions(m_FileExtensionsMap, m_FileExtensions); return m_FileExtensions.c_str(); } /** - * @brief Merge the input map into the fileExtensionsMap. Duplicate entries are removed - * @param fileExtensionsMap the existing map, it contains value pairs like ("*.dcm", "DICOM files"),("*.dc3", "DICOM files"). - * This map is extented/merged with the values from the input map. - * @param inputMap the input map, it contains value pairs like ("*.dcm", "DICOM files"),("*.dc3", "DICOM files") returned by - * the extra factories. - * - */ +* @brief Merge the input map into the fileExtensionsMap. Duplicate entries are removed +* @param fileExtensionsMap the existing map, it contains value pairs like ("*.dcm", "DICOM files"),("*.dc3", "DICOM files"). +* This map is extented/merged with the values from the input map. +* @param inputMap the input map, it contains value pairs like ("*.dcm", "DICOM files"),("*.dc3", "DICOM files") returned by +* the extra factories. +* +*/ void mitk::CoreObjectFactory::MergeFileExtensions(MultimapType& fileExtensionsMap, MultimapType inputMap) { bool duplicateFound = false; std::pair pairOfIter; for (MultimapType::iterator it = inputMap.begin(); it != inputMap.end(); ++it) { duplicateFound = false; pairOfIter = fileExtensionsMap.equal_range((*it).first); for (MultimapType::iterator it2 = pairOfIter.first; it2 != pairOfIter.second; ++it2) { //cout << " [" << (*it).first << ", " << (*it).second << "]" << endl; std::string aString = (*it2).second; if (aString.compare((*it).second) == 0) { //cout << " DUP!! [" << (*it).first << ", " << (*it).second << "]" << endl; duplicateFound = true; break; } } if (!duplicateFound) { fileExtensionsMap.insert(std::pair((*it).first, (*it).second)); } } } /** - * @brief get the defined (open) file extension map - * @return the defined (open) file extension map - */ +* @brief get the defined (open) file extension map +* @return the defined (open) file extension map +*/ mitk::CoreObjectFactoryBase::MultimapType mitk::CoreObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } /** - * @brief initialize the file extension entries for open and save - */ +* @brief initialize the file extension entries for open and save +*/ void mitk::CoreObjectFactory::CreateFileExtensionsMap() { m_FileExtensionsMap.insert(std::pair("*.dcm", "DICOM files")); m_FileExtensionsMap.insert(std::pair("*.DCM", "DICOM files")); m_FileExtensionsMap.insert(std::pair("*.dc3", "DICOM files")); m_FileExtensionsMap.insert(std::pair("*.DC3", "DICOM files")); m_FileExtensionsMap.insert(std::pair("*.gdcm", "DICOM files")); m_FileExtensionsMap.insert(std::pair("*.seq", "DKFZ Pic")); m_FileExtensionsMap.insert(std::pair("*.pic", "DKFZ Pic")); m_FileExtensionsMap.insert(std::pair("*.pic.gz", "DKFZ Pic")); m_FileExtensionsMap.insert(std::pair("*.mhd", "MetaImage")); m_FileExtensionsMap.insert(std::pair("*.seq.gz", "DKFZ Pic")); m_FileExtensionsMap.insert(std::pair("*.hdr", "Analyze Format")); m_FileExtensionsMap.insert(std::pair("*.img", "Analyze Format")); m_FileExtensionsMap.insert(std::pair("*.img.gz", "Analyze Format")); m_FileExtensionsMap.insert(std::pair("*.nrrd", "Nearly Raw Raster Data")); m_FileExtensionsMap.insert(std::pair("*.nhdr", "NRRD with detached header")); m_FileExtensionsMap.insert(std::pair("*.mps", "Point sets")); m_FileExtensionsMap.insert(std::pair("*.pic", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.pic.gz", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.bmp", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.png", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.jpg", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.jpeg", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.dcm", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.gdcm", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.ima", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.tiff", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.tif", "Sets of 2D slices")); m_FileExtensionsMap.insert(std::pair("*.stl", "Surface files")); m_FileExtensionsMap.insert(std::pair("*.vtk", "Surface files")); m_FileExtensionsMap.insert(std::pair("*.vtp", "Surface files")); m_FileExtensionsMap.insert(std::pair("*.obj", "Surface files")); m_FileExtensionsMap.insert(std::pair("*.nii", "NIfTI format")); m_FileExtensionsMap.insert(std::pair("*.nii.gz", "NIfTI format")); //m_SaveFileExtensionsMap.insert(std::pair("*.pic", "DKFZ Pic")); m_SaveFileExtensionsMap.insert(std::pair("*.mhd", "MetaImage")); m_SaveFileExtensionsMap.insert(std::pair("*.vtk", "Surface Files")); m_SaveFileExtensionsMap.insert(std::pair("*.vti", "VTK Image Data Files")); m_SaveFileExtensionsMap.insert(std::pair("*.hdr", "Analyze Format")); m_SaveFileExtensionsMap.insert(std::pair("*.png", "Sets of 2D slices")); m_SaveFileExtensionsMap.insert(std::pair("*.tiff", "Sets of 2D slices")); m_SaveFileExtensionsMap.insert(std::pair("*.tif", "Sets of 2D slices")); m_SaveFileExtensionsMap.insert(std::pair("*.jpg", "Sets of 2D slices")); m_SaveFileExtensionsMap.insert(std::pair("*.jpeg", "Sets of 2D slices")); m_SaveFileExtensionsMap.insert(std::pair("*.bmp", "Sets of 2D slices")); m_SaveFileExtensionsMap.insert(std::pair("*.dcm", "Sets of 2D slices")); m_SaveFileExtensionsMap.insert(std::pair("*.gipl", "UMDS GIPL Format Files")); m_SaveFileExtensionsMap.insert(std::pair("*.nii", "NIfTI format")); m_SaveFileExtensionsMap.insert(std::pair("*.nrrd", "Nearly Raw Raster Data")); m_SaveFileExtensionsMap.insert(std::pair("*.nhdr", "NRRD with detached header")); m_SaveFileExtensionsMap.insert(std::pair("*.lsm", "Microscope Images")); m_SaveFileExtensionsMap.insert(std::pair("*.dwi", "Diffusion Weighted Images")); m_SaveFileExtensionsMap.insert(std::pair("*.hdwi", "Diffusion Weighted Images")); m_SaveFileExtensionsMap.insert(std::pair("*.qbi", "Q-Ball Images")); m_SaveFileExtensionsMap.insert(std::pair("*.hqbi", "Q-Ball Images")); RegisterLegacyReaders(this); RegisterLegacyWriters(); } /** - * @brief This method gets the supported (save) file extensions as string. This string is can then used by the QT QFileDialog widget. - * @return The c-string that contains the (save) file extensions - * - */ +* @brief This method gets the supported (save) file extensions as string. This string is can then used by the QT QFileDialog widget. +* @return The c-string that contains the (save) file extensions +* +*/ const char* mitk::CoreObjectFactory::GetSaveFileExtensions() { MultimapType aMap; for (ExtraFactoriesContainer::iterator it = m_ExtraFactories.begin(); it != m_ExtraFactories.end() ; it++ ) { aMap = (*it)->GetSaveFileExtensionsMap(); this->MergeFileExtensions(m_SaveFileExtensionsMap, aMap); - } this->CreateFileExtensions(m_SaveFileExtensionsMap, m_SaveFileExtensions); return m_SaveFileExtensions.c_str(); }; /** - * @brief get the defined (save) file extension map - * @return the defined (save) file extension map - */ +* @brief get the defined (save) file extension map +* @return the defined (save) file extension map +*/ mitk::CoreObjectFactoryBase::MultimapType mitk::CoreObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } mitk::CoreObjectFactory::FileWriterList mitk::CoreObjectFactory::GetFileWriters() { FileWriterList allWriters = m_FileWriters; for (ExtraFactoriesContainer::iterator it = m_ExtraFactories.begin(); it != m_ExtraFactories.end() ; it++ ) { FileWriterList list2 = (*it)->GetFileWriters(); allWriters.merge(list2); } return allWriters; } void mitk::CoreObjectFactory::MapEvent(const mitk::Event*, const int) { - } void mitk::CoreObjectFactory::RegisterLegacyReaders(mitk::CoreObjectFactoryBase::Pointer factory) { // We are not really interested in the string, but this function will make sure to merge // all extensions of all registered Factories into the map that we will work with. factory->GetFileExtensions(); std::multimap fileExtensionMap = factory->GetFileExtensionsMap(); for(std::multimap::iterator it = fileExtensionMap.begin(); it != fileExtensionMap.end(); it++) { //only add if no reader already registered under that extension std::string extension = it->first; extension = extension.erase(0,1); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); - mitk::FileReaderManager readerManager; - if(readerManager.GetReader(it->first) == 0) + mitk::FileReaderRegistry readerRegistry; + if(readerRegistry.GetReader(it->first) == 0) { mitk::LegacyFileReaderService* lfrs = new mitk::LegacyFileReaderService(extension, it->second); m_LegacyReaders.push_back(lfrs); } } } std::string mitk::CoreObjectFactory::GetDescriptionForExtension(const std::string& extension) { std::multimap fileExtensionMap = GetSaveFileExtensionsMap(); for(std::multimap::iterator it = fileExtensionMap.begin(); it != fileExtensionMap.end(); it++) if (it->first.compare(extension) == 0) return it->second; return ""; // If no matching extension was found, return emtpy string } - void mitk::CoreObjectFactory::RegisterLegacyWriters(/*mitk::CoreObjectFactoryBase::Pointer factory*/) { // Get all external Writers mitk::CoreObjectFactory::FileWriterList informedWriters = GetFileWriters(); std::list writers; // Upcast List for(mitk::CoreObjectFactory::FileWriterList::iterator it = informedWriters.begin(); it != informedWriters.end(); it++) writers.push_back(it->GetPointer()); // Add All ImageWriterTypes mitk::ImageWriter::Pointer dummyWriter = mitk::ImageWriter::New(); mitk::Image::Pointer dummyImage = mitk::Image::New(); std::vector extensions = dummyWriter->GetPossibleFileExtensions(); - mitk::FileWriterManager writerManager; + mitk::FileWriterRegistry writerRegistry; for(std::vector::iterator ext = extensions.begin(); ext != extensions.end(); ext++) { std::string extension = *ext; if (extension.compare("") == 0) continue; std::string description = GetDescriptionForExtension("*" + extension); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); - if(writerManager.GetWriter(extension) == 0) + if(writerRegistry.GetWriter(extension) == 0) { MITK_INFO << extension << "/" << description; mitk::LegacyImageWriterService* liws = new mitk::LegacyImageWriterService(dummyImage->GetNameOfClass(), extension, description); m_LegacyImageWriters.push_back(liws); } } // Add Aall external Writers writers.push_back(mitk::PointSetWriter::New().GetPointer()); for(std::list::iterator it = writers.begin(); it != writers.end(); it++) { std::vector extensions = it->GetPointer()->GetPossibleFileExtensions(); for(std::vector::iterator ext = extensions.begin(); ext != extensions.end(); ext++) { std::string extension = *ext; if (extension.compare("") == 0) continue; std::string description = GetDescriptionForExtension("*" + extension); //extension = extension.erase(0,1); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); - if(writerManager.GetWriter(extension) == 0) + if(writerRegistry.GetWriter(extension) == 0) { MITK_INFO << extension << "/" << description; mitk::LegacyFileWriterService* lfws = new mitk::LegacyFileWriterService(it->GetPointer(), "LegacyDataType", extension, description); m_LegacyWriters.push_back(lfws); } } } } diff --git a/Core/Code/IO/mitkFileReaderManager.cpp b/Core/Code/IO/mitkFileReaderRegistry.cpp similarity index 80% rename from Core/Code/IO/mitkFileReaderManager.cpp rename to Core/Code/IO/mitkFileReaderRegistry.cpp index 0344d20d0e..7ed2287718 100644 --- a/Core/Code/IO/mitkFileReaderManager.cpp +++ b/Core/Code/IO/mitkFileReaderRegistry.cpp @@ -1,222 +1,222 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "mitkFileReaderManager.h" +#include "mitkFileReaderRegistry.h" // Microservices #include #include #include #include // Legacy Support #include //const std::string mitk::IFileWriter::PROP_EXTENSION = "org.mitk.services.FileWriter.Extension"; -mitk::FileReaderManager::FileReaderManager() +mitk::FileReaderRegistry::FileReaderRegistry() { } -mitk::FileReaderManager::~FileReaderManager() +mitk::FileReaderRegistry::~FileReaderRegistry() { for (std::map >::iterator iter = m_ServiceObjects.begin(), end = m_ServiceObjects.end(); iter != end; ++iter) { iter->second.UngetService(iter->first); } } //////////////////// READING DIRECTLY //////////////////// -std::list< mitk::BaseData::Pointer > mitk::FileReaderManager::Read(const std::string& path, us::ModuleContext* context) +std::list< mitk::BaseData::Pointer > mitk::FileReaderRegistry::Read(const std::string& path, us::ModuleContext* context) { // Find extension std::string extension = path; extension.erase(0, path.find_last_of('.')); // Get best Reader mitk::IFileReader* reader = GetReader(extension, context); // Throw exception if no compatible reader was found - if (reader == NULL) mitkThrow() << "Tried to directly read a file of type '" + extension + "' via FileReaderManager, but no reader supporting this filetype was found."; + if (reader == NULL) mitkThrow() << "Tried to directly read a file of type '" + extension + "' via FileReaderRegistry, but no reader supporting this filetype was found."; return reader->Read(path); } -std::list< mitk::BaseData::Pointer > mitk::FileReaderManager::ReadAll(const std::list paths, std::list* unreadableFiles, +std::list< mitk::BaseData::Pointer > mitk::FileReaderRegistry::ReadAll(const std::list paths, std::list* unreadableFiles, us::ModuleContext* context) { std::list< mitk::BaseData::Pointer > result; for (std::list::const_iterator iterator = paths.begin(), end = paths.end(); iterator != end; ++iterator) { try { std::list baseDataList = Read( *iterator, context ); result.merge(baseDataList); } catch (...) { if (unreadableFiles) unreadableFiles->push_back( *iterator ); } } return result; } //////////////////// GETTING READERS //////////////////// -mitk::IFileReader* mitk::FileReaderManager::GetReader(const std::string& extension, us::ModuleContext* context ) +mitk::IFileReader* mitk::FileReaderRegistry::GetReader(const std::string& extension, us::ModuleContext* context ) { std::vector results = GetReaders(extension, context); if (results.empty()) return NULL; return results.front(); } -std::vector mitk::FileReaderManager::GetReaders(const std::string& extension, us::ModuleContext* context ) +std::vector mitk::FileReaderRegistry::GetReaders(const std::string& extension, us::ModuleContext* context ) { std::vector result; const std::vector > refs = GetReaderList(extension, context); result.reserve(refs.size()); // Translate List of ServiceRefs to List of Pointers for (std::vector >::const_iterator iter = refs.begin(), end = refs.end(); iter != end; ++iter) { us::ServiceObjects serviceObjects = context->GetServiceObjects(*iter); mitk::IFileReader* reader = serviceObjects.GetService(); m_ServiceObjects.insert(std::make_pair(reader, serviceObjects)); result.push_back(reader); } return result; } -mitk::IFileReader* mitk::FileReaderManager::GetReader(const std::string& extension, const std::list& options, us::ModuleContext* context ) +mitk::IFileReader* mitk::FileReaderRegistry::GetReader(const std::string& extension, const std::list& options, us::ModuleContext* context ) { - std::vector matching = mitk::FileReaderManager::GetReaders(extension, options, context); + std::vector matching = mitk::FileReaderRegistry::GetReaders(extension, options, context); if (matching.empty()) return NULL; return matching.front(); } -std::vector mitk::FileReaderManager::GetReaders(const std::string& extension, const std::list& options, us::ModuleContext* context ) +std::vector mitk::FileReaderRegistry::GetReaders(const std::string& extension, const std::list& options, us::ModuleContext* context ) { - const std::vector allReaders = mitk::FileReaderManager::GetReaders(extension, context); + const std::vector allReaders = mitk::FileReaderRegistry::GetReaders(extension, context); std::vector result; result.reserve(allReaders.size()); // the list is already sorted by priority. Now find reader that supports all options for (std::vector ::const_iterator iter = allReaders.begin(), end = allReaders.end(); iter != end; ++iter) { mitk::IFileReader * currentReader = *iter; // Now see if this reader supports all options. If yes, push to results - if ( mitk::FileReaderManager::ReaderSupportsOptions(currentReader, options) ) + if ( mitk::FileReaderRegistry::ReaderSupportsOptions(currentReader, options) ) { result.push_back(currentReader); } } return result; } -void mitk::FileReaderManager::UngetReader(mitk::IFileReader* reader) +void mitk::FileReaderRegistry::UngetReader(mitk::IFileReader* reader) { std::map >::iterator readerIter = m_ServiceObjects.find(reader); if (readerIter != m_ServiceObjects.end()) { readerIter->second.UngetService(reader); m_ServiceObjects.erase(readerIter); } } -void mitk::FileReaderManager::UngetReaders(const std::vector& readers) +void mitk::FileReaderRegistry::UngetReaders(const std::vector& readers) { for (std::vector::const_iterator iter = readers.begin(), end = readers.end(); iter != end; ++iter) { this->UngetReader(*iter); } } //////////////////// GENERIC INFORMATION //////////////////// -std::string mitk::FileReaderManager::GetSupportedExtensions(const std::string& extension) +std::string mitk::FileReaderRegistry::GetSupportedExtensions(const std::string& extension) { us::ModuleContext* context = us::GetModuleContext(); const std::vector > refs = GetReaderList(extension, context); std::vector entries; // Will contain Description + Extension (Human readable) entries.reserve(refs.size()); std::string knownExtensions; // Will contain plain list of all known extensions (for the QFileDialog entry "All Known Extensions") for (std::vector >::const_iterator iterator = refs.begin(), end = refs.end(); iterator != end; ++iterator) { // Generate List of Extensions if (iterator == refs.begin()) // First entry without semicolon knownExtensions += "*" + iterator->GetProperty(mitk::IFileReader::PROP_EXTENSION).ToString(); else // Ad semicolon for each following entry knownExtensions += "; *" + iterator->GetProperty(mitk::IFileReader::PROP_EXTENSION).ToString(); // Generate List of human readable entries composed of Description + Extension std::string entry = iterator->GetProperty(mitk::IFileReader::PROP_DESCRIPTION).ToString() + "(*" + iterator->GetProperty(mitk::IFileReader::PROP_EXTENSION).ToString() + ");;"; entries.push_back(entry); } std::sort(entries.begin(), entries.end()); std::string result = "Known Extensions (" + knownExtensions + ");;All (*)"; for (std::vector::const_iterator iterator = entries.begin(), end = entries.end(); iterator != end; ++iterator) { result += ";;" + *iterator; } return result; } //////////////////// INTERNAL CODE //////////////////// -bool mitk::FileReaderManager::ReaderSupportsOptions(mitk::IFileReader* reader, const std::list& options ) +bool mitk::FileReaderRegistry::ReaderSupportsOptions(mitk::IFileReader* reader, const std::list& options ) { const std::list< mitk::IFileReader::FileServiceOption > readerOptions = reader->GetOptions(); if (options.empty()) return true; // if no options were requested, return true unconditionally if (readerOptions.empty()) return false; // if options were requested and reader supports no options, return false // For each of the strings in requested options, check if option is available in reader for(std::list< std::string >::const_iterator options_i = options.begin(), i_end = options.end(); options_i != i_end; ++options_i) { { bool optionFound = false; // Iterate over each available option from reader to check if one of them matches the current option for(std::list::const_iterator options_j = readerOptions.begin(), j_end = readerOptions.end(); options_j != j_end; ++options_j) { if ( *options_i == options_j->first ) optionFound = true; } if (optionFound == false) return false; // If one option was not found, leave method and return false } } return true; // if all options have been found, return true } //////////////////// uS-INTERACTION //////////////////// -std::vector< us::ServiceReference > mitk::FileReaderManager::GetReaderList(const std::string& extension, us::ModuleContext* context ) +std::vector< us::ServiceReference > mitk::FileReaderRegistry::GetReaderList(const std::string& extension, us::ModuleContext* context ) { // filter for class and extension std::string filter; if (!extension.empty()) { filter = us::LDAPProp(mitk::IFileReader::PROP_EXTENSION) == extension; } std::vector > result = context->GetServiceReferences(filter); std::sort(result.begin(), result.end()); std::reverse(result.begin(), result.end()); return result; } diff --git a/Core/Code/IO/mitkFileReaderManager.h b/Core/Code/IO/mitkFileReaderRegistry.h similarity index 90% rename from Core/Code/IO/mitkFileReaderManager.h rename to Core/Code/IO/mitkFileReaderRegistry.h index 9575853421..fc4203b7a0 100644 --- a/Core/Code/IO/mitkFileReaderManager.h +++ b/Core/Code/IO/mitkFileReaderRegistry.h @@ -1,108 +1,108 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#ifndef FileReaderManager_H_HEADER_INCLUDED_C1E7E521 -#define FileReaderManager_H_HEADER_INCLUDED_C1E7E521 +#ifndef FileReaderRegistry_H_HEADER_INCLUDED_C1E7E521 +#define FileReaderRegistry_H_HEADER_INCLUDED_C1E7E521 #include #include // Microservices #include #include #include namespace mitk { struct IFileReader; } namespace mitk { /** * @ingroup Process * * Provides convenient access to mitk::IFileReader instances and reading * files into mitk::BaseData types. * * \note The life-time of all mitk::IFileReader objects returned by an * instance of this class ends with the destruction of that instance. */ -class MITK_CORE_EXPORT FileReaderManager +class MITK_CORE_EXPORT FileReaderRegistry { public: - FileReaderManager(); - ~FileReaderManager(); + FileReaderRegistry(); + ~FileReaderRegistry(); /** * Reads the file located at path and returns the * contents as a DataNode. * * This method will select the best available reader in the service * registry for the task. * * UnsupportedFileException: If no compatible reader was found * FileNotFoundException: If no file was found at path * FileReadException: If the selected reader failed to read the file **/ std::list< itk::SmartPointer > Read(const std::string& path, us::ModuleContext* context = us::GetModuleContext()); std::list< mitk::BaseData::Pointer > ReadAll(const std::list paths, std::list* unreadableFiles = 0, us::ModuleContext* context = us::GetModuleContext()); template itk::SmartPointer Read(const std::string& path, us::ModuleContext* context = us::GetModuleContext()) { std::list basedatas = Read(path, context); T* result = dynamic_cast (basedatas.front().GetPointer()); return result; } /** * Returns a compatible Reader to the given file extension **/ mitk::IFileReader* GetReader(const std::string& extension, us::ModuleContext* context = us::GetModuleContext() ); mitk::IFileReader* GetReader(const std::string& extension, const std::list& options, us::ModuleContext* context = us::GetModuleContext() ); std::vector GetReaders(const std::string& extension, us::ModuleContext* context = us::GetModuleContext() ); std::vector GetReaders(const std::string& extension, const std::list& options, us::ModuleContext* context = us::GetModuleContext() ); void UngetReader(mitk::IFileReader* reader); void UngetReaders(const std::vector& readers); std::string GetSupportedExtensions(const std::string& extension = ""); protected: std::vector< us::ServiceReference > GetReaderList(const std::string& extension, us::ModuleContext* context); bool ReaderSupportsOptions(mitk::IFileReader* reader, const std::list& options); private: // purposely not implemented - FileReaderManager(const FileReaderManager&); - FileReaderManager& operator=(const FileReaderManager&); + FileReaderRegistry(const FileReaderRegistry&); + FileReaderRegistry& operator=(const FileReaderRegistry&); std::map > m_ServiceObjects; }; } // namespace mitk -#endif /* FileReaderManager_H_HEADER_INCLUDED_C1E7E521 */ +#endif /* FileReaderRegistry_H_HEADER_INCLUDED_C1E7E521 */ diff --git a/Core/Code/IO/mitkFileWriterManager.cpp b/Core/Code/IO/mitkFileWriterRegistry.cpp similarity index 79% rename from Core/Code/IO/mitkFileWriterManager.cpp rename to Core/Code/IO/mitkFileWriterRegistry.cpp index 6165e978b3..8bfd47b178 100644 --- a/Core/Code/IO/mitkFileWriterManager.cpp +++ b/Core/Code/IO/mitkFileWriterRegistry.cpp @@ -1,202 +1,202 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "mitkFileWriterManager.h" +#include "mitkFileWriterRegistry.h" // MITK #include // Microservices #include #include #include #include -mitk::FileWriterManager::FileWriterManager() +mitk::FileWriterRegistry::FileWriterRegistry() { } -mitk::FileWriterManager::~FileWriterManager() +mitk::FileWriterRegistry::~FileWriterRegistry() { for (std::map >::iterator iter = m_ServiceObjects.begin(), end = m_ServiceObjects.end(); iter != end; ++iter) { iter->second.UngetService(iter->first); } } //////////////////// WRITING DIRECTLY //////////////////// -void mitk::FileWriterManager::Write(const mitk::BaseData* data, const std::string& path, us::ModuleContext* context) +void mitk::FileWriterRegistry::Write(const mitk::BaseData* data, const std::string& path, us::ModuleContext* context) { // Find extension std::string extension = path; extension.erase(0, path.find_last_of('.')); // Get best Writer mitk::IFileWriter* Writer = GetWriter(extension, context); // Throw exception if no compatible Writer was found - if (Writer == NULL) mitkThrow() << "Tried to directly Write a file of type '" + extension + "' via FileWriterManager, but no Writer supporting this filetype was found."; + if (Writer == NULL) mitkThrow() << "Tried to directly Write a file of type '" + extension + "' via FileWriterRegistry, but no Writer supporting this filetype was found."; Writer->Write(data, path); } //////////////////// GETTING WRITERS //////////////////// -mitk::IFileWriter* mitk::FileWriterManager::GetWriter(const std::string& extension, us::ModuleContext* context ) +mitk::IFileWriter* mitk::FileWriterRegistry::GetWriter(const std::string& extension, us::ModuleContext* context ) { std::vector results = GetWriters(extension, context); if (results.empty()) return NULL; return results.front(); } -std::vector mitk::FileWriterManager::GetWriters(const std::string& extension, us::ModuleContext* context ) +std::vector mitk::FileWriterRegistry::GetWriters(const std::string& extension, us::ModuleContext* context ) { std::vector result; const std::vector > refs = GetWriterList(extension, context); result.reserve(refs.size()); // Translate List of ServiceRefs to List of Pointers for (std::vector >::const_iterator iter = refs.begin(), end = refs.end(); iter != end; ++iter) { us::ServiceObjects serviceObjects = context->GetServiceObjects(*iter); mitk::IFileWriter* writer = serviceObjects.GetService(); m_ServiceObjects.insert(std::make_pair(writer, serviceObjects)); result.push_back(writer); } return result; } -mitk::IFileWriter* mitk::FileWriterManager::GetWriter(const std::string& extension, const std::list& options, +mitk::IFileWriter* mitk::FileWriterRegistry::GetWriter(const std::string& extension, const std::list& options, us::ModuleContext* context ) { - const std::vector matching = mitk::FileWriterManager::GetWriters(extension, options, context); + const std::vector matching = mitk::FileWriterRegistry::GetWriters(extension, options, context); if (matching.empty()) return NULL; return matching.front(); } -std::vector mitk::FileWriterManager::GetWriters(const std::string& extension, const std::list& options, us::ModuleContext* context ) +std::vector mitk::FileWriterRegistry::GetWriters(const std::string& extension, const std::list& options, us::ModuleContext* context ) { - const std::vector allWriters = mitk::FileWriterManager::GetWriters(extension, context); + const std::vector allWriters = mitk::FileWriterRegistry::GetWriters(extension, context); std::vector result; // the list is always sorted by priority. Now find Writer that supports all options for (std::vector ::const_iterator iter = allWriters.begin(), end = allWriters.end(); iter != end; ++iter) { // Now see if this Writer supports all options. If yes, push to results - if ( mitk::FileWriterManager::WriterSupportsOptions(*iter, options) ) + if ( mitk::FileWriterRegistry::WriterSupportsOptions(*iter, options) ) { result.push_back(*iter); } } return result; } //////////////////// GENERIC INFORMATION //////////////////// -std::string mitk::FileWriterManager::GetSupportedExtensions(const std::string& extension, us::ModuleContext* context) +std::string mitk::FileWriterRegistry::GetSupportedExtensions(const std::string& extension, us::ModuleContext* context) { const std::vector > refs = GetWriterList(extension, context); return CreateFileDialogString(refs); } -std::string mitk::FileWriterManager::GetSupportedWriters(const std::string& basedataType, us::ModuleContext* context) +std::string mitk::FileWriterRegistry::GetSupportedWriters(const std::string& basedataType, us::ModuleContext* context) { const std::vector > refs = GetWriterListByBasedataType(basedataType, context); return CreateFileDialogString(refs); } //////////////////// INTERNAL CODE //////////////////// -bool mitk::FileWriterManager::WriterSupportsOptions(mitk::IFileWriter* writer, const std::list& options ) +bool mitk::FileWriterRegistry::WriterSupportsOptions(mitk::IFileWriter* writer, const std::list& options ) { const std::list< mitk::IFileWriter::FileServiceOption > writerOptions = writer->GetOptions(); if (options.empty()) return true; // if no options were requested, return true unconditionally if (writerOptions.empty()) return false; // if options were requested and reader supports no options, return false // For each of the strings in requested options, check if option is available in reader for(std::list< std::string >::const_iterator options_i = options.begin(), i_end = options.end(); options_i != i_end; ++options_i) { { bool optionFound = false; // Iterate over each available option from reader to check if one of them matches the current option for(std::list::const_iterator options_j = writerOptions.begin(), j_end = writerOptions.end(); options_j != j_end; ++options_j) { if ( *options_i == options_j->first ) optionFound = true; } if (optionFound == false) return false; // If one option was not found, leave method and return false } } return true; // if all options have been found, return true } -std::string mitk::FileWriterManager::CreateFileDialogString(const std::vector >& refs) +std::string mitk::FileWriterRegistry::CreateFileDialogString(const std::vector >& refs) { std::vector entries; // Will contain Description + Extension (Human readable) entries.reserve(refs.size()); std::string knownExtensions; // Will contain plain list of all known extensions (for the QFileDialog entry "All Known Extensions") for (std::vector >::const_iterator iterator = refs.begin(), end = refs.end(); iterator != end; ++iterator) { // Generate List of Extensions if (iterator == refs.begin()) // First entry without semicolon knownExtensions += "*" + iterator->GetProperty(mitk::IFileWriter::PROP_EXTENSION).ToString(); else // Ad semicolon for each following entry knownExtensions += "; *" + iterator->GetProperty(mitk::IFileWriter::PROP_EXTENSION).ToString(); // Generate List of human readable entries composed of Description + Extension std::string entry = iterator->GetProperty(mitk::IFileWriter::PROP_DESCRIPTION).ToString() + "(*" + iterator->GetProperty(mitk::IFileWriter::PROP_EXTENSION).ToString() + ");;"; entries.push_back(entry); } std::sort(entries.begin(), entries.end()); std::string result = "Known Extensions (" + knownExtensions + ");;All (*)"; for (std::vector::const_iterator iterator = entries.begin(), end = entries.end(); iterator != end; ++iterator) { result += ";;" + *iterator; } return result; } //////////////////// uS-INTERACTION //////////////////// -std::vector< us::ServiceReference > mitk::FileWriterManager::GetWriterList(const std::string& extension, us::ModuleContext* context ) +std::vector< us::ServiceReference > mitk::FileWriterRegistry::GetWriterList(const std::string& extension, us::ModuleContext* context ) { // filter for class and extension std::string filter; if (!extension.empty()) { filter = "(" + mitk::IFileWriter::PROP_EXTENSION + "=" + extension + ")"; } std::vector > result = context->GetServiceReferences(filter); std::sort(result.begin(), result.end()); std::reverse(result.begin(), result.end()); return result; } -std::vector< us::ServiceReference > mitk::FileWriterManager::GetWriterListByBasedataType(const std::string& basedataType, us::ModuleContext* context ) +std::vector< us::ServiceReference > mitk::FileWriterRegistry::GetWriterListByBasedataType(const std::string& basedataType, us::ModuleContext* context ) { // filter for class and extension std::string filter = us::LDAPProp(mitk::IFileWriter::PROP_BASEDATA_TYPE) == basedataType; std::vector > result = context->GetServiceReferences(filter); std::sort(result.begin(), result.end()); std::reverse(result.begin(), result.end()); return result; } diff --git a/Core/Code/IO/mitkFileWriterManager.h b/Core/Code/IO/mitkFileWriterRegistry.h similarity index 88% rename from Core/Code/IO/mitkFileWriterManager.h rename to Core/Code/IO/mitkFileWriterRegistry.h index b293a7b921..e0f1af66de 100644 --- a/Core/Code/IO/mitkFileWriterManager.h +++ b/Core/Code/IO/mitkFileWriterRegistry.h @@ -1,98 +1,98 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#ifndef FileWriterManager_H_HEADER_INCLUDED_C1E7E521 -#define FileWriterManager_H_HEADER_INCLUDED_C1E7E521 +#ifndef FileWriterRegistry_H_HEADER_INCLUDED_C1E7E521 +#define FileWriterRegistry_H_HEADER_INCLUDED_C1E7E521 #include // Microservices #include #include #include // Temporarily disable warning until PIMPL pattern is implemented here #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4251) #endif namespace mitk { class BaseData; struct IFileWriter; } namespace mitk { /** * @ingroup Process * * Provides convenient access to mitk::IFileWriter instances and writing * files from mitk::BaseData types. * * \note The life-time of all mitk::IFileWriter objects returned by an * instance of this class ends with the destruction of that instance. */ - class MITK_CORE_EXPORT FileWriterManager + class MITK_CORE_EXPORT FileWriterRegistry { public: - FileWriterManager(); - ~FileWriterManager(); + FileWriterRegistry(); + ~FileWriterRegistry(); void Write(const mitk::BaseData* data, const std::string& path, us::ModuleContext* context = us::GetModuleContext()); /** * Returns a compatible Writer to the given file extension */ mitk::IFileWriter* GetWriter(const std::string& extension, us::ModuleContext* context = us::GetModuleContext() ); mitk::IFileWriter* GetWriter(const std::string& extension, const std::list& options, us::ModuleContext* context = us::GetModuleContext() ); std::vector GetWriters(const std::string& extension, us::ModuleContext* context = us::GetModuleContext() ); std::vector GetWriters(const std::string& extension, const std::list& options, us::ModuleContext* context = us::GetModuleContext() ); void UngetWriter(mitk::IFileWriter* writer); void UngetWriters(const std::vector& writers); std::string GetSupportedExtensions(const std::string& extension = std::string(), us::ModuleContext* context = us::GetModuleContext()); std::string GetSupportedWriters(const std::string& basedataType, us::ModuleContext* context = us::GetModuleContext()); protected: std::vector< us::ServiceReference > GetWriterList(const std::string& extension, us::ModuleContext* context); std::vector< us::ServiceReference > GetWriterListByBasedataType(const std::string& basedataType, us::ModuleContext* context); std::string CreateFileDialogString(const std::vector >& refs); bool WriterSupportsOptions(mitk::IFileWriter* writer, const std::list& options); private: // purposely not implemented - FileWriterManager(const FileWriterManager&); - FileWriterManager& operator=(const FileWriterManager&); + FileWriterRegistry(const FileWriterRegistry&); + FileWriterRegistry& operator=(const FileWriterRegistry&); std::map > m_ServiceObjects; }; } // namespace mitk #ifdef _MSC_VER # pragma warning(pop) #endif -#endif /* FileWriterManager_H_HEADER_INCLUDED_C1E7E521 */ +#endif /* FileWriterRegistry_H_HEADER_INCLUDED_C1E7E521 */ diff --git a/Core/Code/files.cmake b/Core/Code/files.cmake index 4ff5f49f48..4d968df1c0 100644 --- a/Core/Code/files.cmake +++ b/Core/Code/files.cmake @@ -1,389 +1,389 @@ set(H_FILES Algorithms/itkImportMitkImageContainer.h Algorithms/itkImportMitkImageContainer.txx Algorithms/itkLocalVariationImageFilter.h Algorithms/itkLocalVariationImageFilter.txx Algorithms/itkMITKScalarImageToHistogramGenerator.h Algorithms/itkMITKScalarImageToHistogramGenerator.txx Algorithms/itkTotalVariationDenoisingImageFilter.h Algorithms/itkTotalVariationDenoisingImageFilter.txx Algorithms/itkTotalVariationSingleIterationImageFilter.h Algorithms/itkTotalVariationSingleIterationImageFilter.txx Algorithms/mitkBilateralFilter.h Algorithms/mitkBilateralFilter.cpp Algorithms/mitkInstantiateAccessFunctions.h Algorithms/mitkPixelTypeList.h # Preprocessor macros taken from Boost Algorithms/mitkPPArithmeticDec.h Algorithms/mitkPPArgCount.h Algorithms/mitkPPCat.h Algorithms/mitkPPConfig.h Algorithms/mitkPPControlExprIIf.h Algorithms/mitkPPControlIf.h Algorithms/mitkPPControlIIf.h Algorithms/mitkPPDebugError.h Algorithms/mitkPPDetailAutoRec.h Algorithms/mitkPPDetailDMCAutoRec.h Algorithms/mitkPPExpand.h Algorithms/mitkPPFacilitiesEmpty.h Algorithms/mitkPPFacilitiesExpand.h Algorithms/mitkPPLogicalBool.h Algorithms/mitkPPRepetitionDetailDMCFor.h Algorithms/mitkPPRepetitionDetailEDGFor.h Algorithms/mitkPPRepetitionDetailFor.h Algorithms/mitkPPRepetitionDetailMSVCFor.h Algorithms/mitkPPRepetitionFor.h Algorithms/mitkPPSeqElem.h Algorithms/mitkPPSeqForEach.h Algorithms/mitkPPSeqForEachProduct.h Algorithms/mitkPPSeq.h Algorithms/mitkPPSeqEnum.h Algorithms/mitkPPSeqSize.h Algorithms/mitkPPSeqToTuple.h Algorithms/mitkPPStringize.h Algorithms/mitkPPTupleEat.h Algorithms/mitkPPTupleElem.h Algorithms/mitkPPTupleRem.h Algorithms/mitkClippedSurfaceBoundsCalculator.h Algorithms/mitkExtractSliceFilter.h Algorithms/mitkConvert2Dto3DImageFilter.h Algorithms/mitkPlaneClipping.h Common/mitkExceptionMacro.h Common/mitkServiceBaseObject.h Common/mitkTestingMacros.h DataManagement/mitkImageAccessByItk.h DataManagement/mitkImageCast.h DataManagement/mitkImagePixelAccessor.h DataManagement/mitkImagePixelReadAccessor.h DataManagement/mitkImagePixelWriteAccessor.h DataManagement/mitkImageReadAccessor.h DataManagement/mitkImageWriteAccessor.h DataManagement/mitkITKImageImport.h DataManagement/mitkITKImageImport.txx DataManagement/mitkImageToItk.h DataManagement/mitkImageToItk.txx Interactions/mitkEventMapperAddOn.h Interfaces/mitkIDataNodeReader.h Interfaces/mitkIFileWriter.h Interfaces/mitkIFileWriter.cpp Interfaces/mitkIFileReader.h Interfaces/mitkIFileReader.cpp Rendering/mitkLocalStorageHandler.h IO/mitkPixelTypeTraits.h ) set(CPP_FILES Algorithms/mitkBaseDataSource.cpp Algorithms/mitkDataNodeSource.cpp Algorithms/mitkGeometry2DDataToSurfaceFilter.cpp Algorithms/mitkHistogramGenerator.cpp Algorithms/mitkImageChannelSelector.cpp Algorithms/mitkImageSliceSelector.cpp Algorithms/mitkImageSource.cpp Algorithms/mitkImageTimeSelector.cpp Algorithms/mitkImageToImageFilter.cpp Algorithms/mitkImageToSurfaceFilter.cpp Algorithms/mitkPointSetSource.cpp Algorithms/mitkPointSetToPointSetFilter.cpp Algorithms/mitkRGBToRGBACastImageFilter.cpp Algorithms/mitkSubImageSelector.cpp Algorithms/mitkSurfaceSource.cpp Algorithms/mitkSurfaceToImageFilter.cpp Algorithms/mitkSurfaceToSurfaceFilter.cpp Algorithms/mitkUIDGenerator.cpp Algorithms/mitkVolumeCalculator.cpp Algorithms/mitkClippedSurfaceBoundsCalculator.cpp Algorithms/mitkExtractSliceFilter.cpp Algorithms/mitkConvert2Dto3DImageFilter.cpp Controllers/mitkBaseController.cpp Controllers/mitkCallbackFromGUIThread.cpp Controllers/mitkCameraController.cpp Controllers/mitkCameraRotationController.cpp Controllers/mitkCoreActivator.cpp Controllers/mitkFocusManager.cpp Controllers/mitkLimitedLinearUndo.cpp Controllers/mitkOperationEvent.cpp Controllers/mitkPlanePositionManager.cpp Controllers/mitkProgressBar.cpp Controllers/mitkRenderingManager.cpp Controllers/mitkSliceNavigationController.cpp Controllers/mitkSlicesCoordinator.cpp Controllers/mitkSlicesRotator.cpp Controllers/mitkSlicesSwiveller.cpp Controllers/mitkStatusBar.cpp Controllers/mitkStepper.cpp Controllers/mitkTestManager.cpp Controllers/mitkUndoController.cpp Controllers/mitkVerboseLimitedLinearUndo.cpp Controllers/mitkVtkInteractorCameraController.cpp Controllers/mitkVtkLayerController.cpp DataManagement/mitkAbstractTransformGeometry.cpp DataManagement/mitkAnnotationProperty.cpp DataManagement/mitkApplicationCursor.cpp DataManagement/mitkBaseData.cpp DataManagement/mitkBaseProperty.cpp DataManagement/mitkClippingProperty.cpp DataManagement/mitkChannelDescriptor.cpp DataManagement/mitkColorProperty.cpp DataManagement/mitkDataStorage.cpp #DataManagement/mitkDataTree.cpp DataManagement/mitkDataNode.cpp DataManagement/mitkDataNodeFactory.cpp #DataManagement/mitkDataTreeStorage.cpp DataManagement/mitkDisplayGeometry.cpp DataManagement/mitkEnumerationProperty.cpp DataManagement/mitkGeometry2D.cpp DataManagement/mitkGeometry2DData.cpp DataManagement/mitkGeometry3D.cpp DataManagement/mitkGeometryData.cpp DataManagement/mitkGroupTagProperty.cpp DataManagement/mitkImage.cpp DataManagement/mitkImageAccessorBase.cpp DataManagement/mitkImageCaster.cpp DataManagement/mitkImageCastPart1.cpp DataManagement/mitkImageCastPart2.cpp DataManagement/mitkImageCastPart3.cpp DataManagement/mitkImageCastPart4.cpp DataManagement/mitkImageDataItem.cpp DataManagement/mitkImageDescriptor.cpp DataManagement/mitkImageVtkAccessor.cpp DataManagement/mitkImageStatisticsHolder.cpp DataManagement/mitkLandmarkBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjectorBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjector.cpp DataManagement/mitkLevelWindow.cpp DataManagement/mitkLevelWindowManager.cpp DataManagement/mitkLevelWindowPreset.cpp DataManagement/mitkLevelWindowProperty.cpp DataManagement/mitkLookupTable.cpp DataManagement/mitkLookupTables.cpp # specializations of GenericLookupTable DataManagement/mitkMemoryUtilities.cpp DataManagement/mitkModalityProperty.cpp DataManagement/mitkModeOperation.cpp DataManagement/mitkNodePredicateAnd.cpp DataManagement/mitkNodePredicateBase.cpp DataManagement/mitkNodePredicateCompositeBase.cpp DataManagement/mitkNodePredicateData.cpp DataManagement/mitkNodePredicateDataType.cpp DataManagement/mitkNodePredicateDimension.cpp DataManagement/mitkNodePredicateFirstLevel.cpp DataManagement/mitkNodePredicateNot.cpp DataManagement/mitkNodePredicateOr.cpp DataManagement/mitkNodePredicateProperty.cpp DataManagement/mitkNodePredicateSource.cpp DataManagement/mitkPlaneOrientationProperty.cpp DataManagement/mitkPlaneGeometry.cpp DataManagement/mitkPlaneOperation.cpp DataManagement/mitkPointOperation.cpp DataManagement/mitkPointSet.cpp DataManagement/mitkProperties.cpp DataManagement/mitkPropertyList.cpp DataManagement/mitkRestorePlanePositionOperation.cpp DataManagement/mitkRotationOperation.cpp DataManagement/mitkSlicedData.cpp DataManagement/mitkSlicedGeometry3D.cpp DataManagement/mitkSmartPointerProperty.cpp DataManagement/mitkStandaloneDataStorage.cpp DataManagement/mitkStateTransitionOperation.cpp DataManagement/mitkStringProperty.cpp DataManagement/mitkSurface.cpp DataManagement/mitkSurfaceOperation.cpp DataManagement/mitkThinPlateSplineCurvedGeometry.cpp DataManagement/mitkTimeSlicedGeometry.cpp DataManagement/mitkTransferFunction.cpp DataManagement/mitkTransferFunctionProperty.cpp DataManagement/mitkTransferFunctionInitializer.cpp DataManagement/mitkVector.cpp DataManagement/mitkVtkInterpolationProperty.cpp DataManagement/mitkVtkRepresentationProperty.cpp DataManagement/mitkVtkResliceInterpolationProperty.cpp DataManagement/mitkVtkScalarModeProperty.cpp DataManagement/mitkVtkVolumeRenderingProperty.cpp DataManagement/mitkWeakPointerProperty.cpp DataManagement/mitkRenderingModeProperty.cpp DataManagement/mitkShaderProperty.cpp DataManagement/mitkResliceMethodProperty.cpp DataManagement/mitkMaterial.cpp DataManagement/mitkPointSetShapeProperty.cpp DataManagement/mitkFloatPropertyExtension.cpp DataManagement/mitkIntPropertyExtension.cpp DataManagement/mitkPropertyExtension.cpp DataManagement/mitkPropertyFilter.cpp DataManagement/mitkPropertyAliases.cpp DataManagement/mitkPropertyDescriptions.cpp DataManagement/mitkPropertyExtensions.cpp DataManagement/mitkPropertyFilters.cpp Interactions/mitkAction.cpp Interactions/mitkAffineInteractor.cpp Interactions/mitkBindDispatcherInteractor.cpp Interactions/mitkCoordinateSupplier.cpp Interactions/mitkDataInteractor.cpp Interactions/mitkDispatcher.cpp Interactions/mitkDisplayCoordinateOperation.cpp Interactions/mitkDisplayInteractor.cpp Interactions/mitkDisplayPositionEvent.cpp # Interactions/mitkDisplayVectorInteractorLevelWindow.cpp # legacy, prob even now unneeded # Interactions/mitkDisplayVectorInteractorScroll.cpp Interactions/mitkEvent.cpp Interactions/mitkEventConfig.cpp Interactions/mitkEventDescription.cpp Interactions/mitkEventFactory.cpp Interactions/mitkInteractionEventHandler.cpp Interactions/mitkEventMapper.cpp Interactions/mitkEventStateMachine.cpp Interactions/mitkGlobalInteraction.cpp Interactions/mitkInteractor.cpp Interactions/mitkInternalEvent.cpp Interactions/mitkInteractionEvent.cpp Interactions/mitkInteractionEventConst.cpp Interactions/mitkInteractionPositionEvent.cpp Interactions/mitkInteractionKeyEvent.cpp Interactions/mitkMousePressEvent.cpp Interactions/mitkMouseMoveEvent.cpp Interactions/mitkMouseReleaseEvent.cpp Interactions/mitkMouseWheelEvent.cpp Interactions/mitkMouseDoubleClickEvent.cpp Interactions/mitkMouseModeSwitcher.cpp Interactions/mitkMouseMovePointSetInteractor.cpp Interactions/mitkMoveBaseDataInteractor.cpp Interactions/mitkNodeDepententPointSetInteractor.cpp Interactions/mitkPointSetDataInteractor.cpp Interactions/mitkPointSetInteractor.cpp Interactions/mitkPositionEvent.cpp Interactions/mitkPositionTracker.cpp Interactions/mitkStateMachineAction.cpp Interactions/mitkStateMachineCondition.cpp Interactions/mitkStateMachineState.cpp Interactions/mitkStateMachineTransition.cpp Interactions/mitkState.cpp Interactions/mitkStateMachineContainer.cpp Interactions/mitkStateEvent.cpp Interactions/mitkStateMachine.cpp Interactions/mitkStateMachineFactory.cpp Interactions/mitkTransition.cpp Interactions/mitkWheelEvent.cpp Interactions/mitkKeyEvent.cpp Interactions/mitkVtkEventAdapter.cpp Interactions/mitkVtkInteractorStyle.cxx Interactions/mitkCrosshairPositionEvent.cpp Interfaces/mitkInteractionEventObserver.cpp Interfaces/mitkIShaderRepository.cpp Interfaces/mitkIPropertyAliases.cpp Interfaces/mitkIPropertyDescriptions.cpp Interfaces/mitkIPropertyExtensions.cpp Interfaces/mitkIPropertyFilters.cpp IO/mitkAbstractFileReader.cpp IO/mitkAbstractFileWriter.cpp IO/mitkLegacyImageWriterService.cpp IO/mitkLegacyFileReaderService.cpp IO/mitkLegacyFileWriterService.cpp IO/mitkBaseDataIOFactory.cpp IO/mitkCoreDataNodeReader.cpp IO/mitkDicomSeriesReader.cpp IO/mitkFileReader.cpp - IO/mitkFileReaderManager.cpp + IO/mitkFileReaderRegistry.cpp IO/mitkFileSeriesReader.cpp IO/mitkFileWriter.cpp - IO/mitkFileWriterManager.cpp + IO/mitkFileWriterRegistry.cpp #IO/mitkIpPicGet.c IO/mitkImageGenerator.cpp IO/mitkImageWriter.cpp IO/mitkImageWriterFactory.cpp IO/mitkItkImageFileIOFactory.cpp IO/mitkItkImageFileReader.cpp IO/mitkItkLoggingAdapter.cpp IO/mitkItkPictureWrite.cpp IO/mitkIOUtil.cpp IO/mitkLookupTableProperty.cpp IO/mitkOperation.cpp #IO/mitkPicFileIOFactory.cpp #IO/mitkPicFileReader.cpp #IO/mitkPicFileWriter.cpp #IO/mitkPicHelper.cpp #IO/mitkPicVolumeTimeSeriesIOFactory.cpp #IO/mitkPicVolumeTimeSeriesReader.cpp IO/mitkPixelType.cpp IO/mitkPointSetIOFactory.cpp IO/mitkPointSetReader.cpp IO/mitkPointSetWriter.cpp IO/mitkPointSetWriterFactory.cpp IO/mitkRawImageFileReader.cpp IO/mitkStandardFileLocations.cpp IO/mitkSTLFileIOFactory.cpp IO/mitkSTLFileReader.cpp IO/mitkSurfaceVtkWriter.cpp IO/mitkSurfaceVtkWriterFactory.cpp IO/mitkVtkLoggingAdapter.cpp IO/mitkVtiFileIOFactory.cpp IO/mitkVtiFileReader.cpp IO/mitkVtkImageIOFactory.cpp IO/mitkVtkImageReader.cpp IO/mitkVtkSurfaceIOFactory.cpp IO/mitkVtkSurfaceReader.cpp IO/vtkPointSetXMLParser.cpp IO/mitkLog.cpp Rendering/mitkBaseRenderer.cpp Rendering/mitkVtkMapper.cpp Rendering/mitkRenderWindowFrame.cpp Rendering/mitkGeometry2DDataMapper2D.cpp Rendering/mitkGeometry2DDataVtkMapper3D.cpp Rendering/mitkGLMapper.cpp Rendering/mitkGradientBackground.cpp Rendering/mitkManufacturerLogo.cpp Rendering/mitkMapper.cpp Rendering/mitkPointSetGLMapper2D.cpp Rendering/mitkPointSetVtkMapper2D.cpp Rendering/mitkPointSetVtkMapper3D.cpp Rendering/mitkPolyDataGLMapper2D.cpp Rendering/mitkSurfaceGLMapper2D.cpp Rendering/mitkSurfaceVtkMapper3D.cpp Rendering/mitkVolumeDataVtkMapper3D.cpp Rendering/mitkVtkPropRenderer.cpp Rendering/mitkVtkWidgetRendering.cpp Rendering/vtkMitkRectangleProp.cpp Rendering/vtkMitkRenderProp.cpp Rendering/mitkVtkEventProvider.cpp Rendering/mitkRenderWindow.cpp Rendering/mitkRenderWindowBase.cpp Rendering/mitkShaderRepository.cpp Rendering/mitkImageVtkMapper2D.cpp Rendering/vtkMitkThickSlicesFilter.cpp Rendering/vtkMitkLevelWindowFilter.cpp Rendering/vtkNeverTranslucentTexture.cpp Rendering/mitkRenderingTestHelper.cpp Common/mitkException.cpp Common/mitkCommon.h Common/mitkCoreObjectFactoryBase.cpp Common/mitkCoreObjectFactory.cpp Common/mitkCoreServices.cpp ) list(APPEND CPP_FILES ${CppMicroServices_SOURCES}) set(RESOURCE_FILES Interactions/globalConfig.xml Interactions/DisplayInteraction.xml Interactions/DisplayConfig.xml Interactions/DisplayConfigPACS.xml Interactions/DisplayConfigPACSPan.xml Interactions/DisplayConfigPACSScroll.xml Interactions/DisplayConfigPACSZoom.xml Interactions/DisplayConfigPACSLevelWindow.xml Interactions/DisplayConfigMITK.xml Interactions/PointSet.xml Interactions/Legacy/StateMachine.xml Interactions/Legacy/DisplayConfigMITKTools.xml Interactions/PointSetConfig.xml Shaders/mitkShaderLighting.xml mitkLevelWindowPresets.xml ) diff --git a/Modules/Qmitk/QmitkFileDialog.cpp b/Modules/Qmitk/QmitkFileDialog.cpp index 2ab9adc34e..c237e5f220 100644 --- a/Modules/Qmitk/QmitkFileDialog.cpp +++ b/Modules/Qmitk/QmitkFileDialog.cpp @@ -1,201 +1,199 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //#define _USE_MATH_DEFINES #include // MITK -#include #include // STL Headers #include //microservices #include #include #include //QT #include #include -#include #include // Test imports, delete later #include class DummyReader : public mitk::AbstractFileReader { public: DummyReader(const DummyReader& other) : mitk::AbstractFileReader(other) { } DummyReader(const std::string& extension, int priority) : mitk::AbstractFileReader(extension, "This is a dummy description") { m_Priority = priority; //std::list options; m_Options.push_front(std::make_pair("isANiceGuy", true)); m_Options.push_front(std::make_pair("canFly", false)); m_Options.push_front(std::make_pair("isAwesome", true)); m_Options.push_front(std::make_pair("hasOptions", true)); m_Options.push_front(std::make_pair("has more Options", true)); m_Options.push_front(std::make_pair("has maaaaaaaany Options", true)); m_ServiceReg = this->RegisterService(); } ~DummyReader() { if (m_ServiceReg) m_ServiceReg.Unregister(); } using mitk::AbstractFileReader::Read; virtual std::list< itk::SmartPointer > Read(const std::istream& /*stream*/, mitk::DataStorage* /*ds*/ = 0) { std::list result; return result; } virtual void SetOptions(const std::list< mitk::IFileReader::FileServiceOption >& options ) { m_Options = options; //m_Registration.SetProperties(GetServiceProperties()); } private: DummyReader* Clone() const { return new DummyReader(*this); } us::ServiceRegistration m_ServiceReg; }; // End of internal dummy reader const std::string QmitkFileDialog::VIEW_ID = "org.mitk.views.QmitkFileDialog"; // // // // // // // // // QmitkFileDialog::QmitkFileDialog(QWidget* parent, Qt::WindowFlags f): QFileDialog(parent, f) { this->setOption(QFileDialog::DontUseNativeDialog); this->setFileMode(QFileDialog::ExistingFile); DummyReader* dr = new DummyReader(".xsfd", 1000); CreateQtPartControl(this); } QmitkFileDialog::~QmitkFileDialog() { } //////////////////// INITIALIZATION ///////////////////// void QmitkFileDialog::CreateQtPartControl(QWidget *parent) { // cast own layout to gridLayout QGridLayout *layout = (QGridLayout*)this->layout(); // creat groupbox for options QGroupBox *box = new QGroupBox(this); box->setTitle("Options:"); box->setVisible(true); m_BoxLayout = new QGridLayout(box); box->setLayout(m_BoxLayout); layout->addWidget(box,4,0,1,3); this->CreateConnections(); // m_context = us::getmodulecontext(); } void QmitkFileDialog::CreateConnections() { connect( this, SIGNAL(currentChanged( const QString &)), this, SLOT(DisplayOptions( QString)) ); connect( this, SIGNAL(fileSelected( const QString &)), this, SLOT(ProcessSelectedFile()) ); } /////////////////////////// OPTIONS /////////////////////////////// void QmitkFileDialog::DisplayOptions(QString path) { ClearOptionsBox(); std::list< mitk::IFileReader::FileServiceOption > options = QueryAvailableOptions(path.toStdString()); int i = 0; while (options.size() > 0) { QCheckBox *checker = new QCheckBox(this); checker->setText( options.front().first.c_str() ); checker->setChecked( options.front().second ); options.pop_front(); m_BoxLayout->addWidget(checker, i / 4, i % 4); i++; } } void QmitkFileDialog::ClearOptionsBox() { if ( m_BoxLayout != NULL ) { QLayoutItem* item; while ( ( item = m_BoxLayout->takeAt( 0 ) ) != NULL ) { delete item->widget(); delete item; } } } std::list< mitk::IFileReader::FileServiceOption > QmitkFileDialog::GetSelectedOptions() { std::list result; if ( m_BoxLayout != NULL ) { QLayoutItem* item; while ( ( item = m_BoxLayout->takeAt( 0 ) ) != NULL ) { QCheckBox* checker = dynamic_cast (item->widget()); if (checker) { mitk::IFileReader::FileServiceOption option = std::make_pair( checker->text().toStdString() , checker->isChecked() ); result.push_back(option); } delete item->widget(); delete item; } } return result; } diff --git a/Modules/Qmitk/QmitkFileOpenDialog.cpp b/Modules/Qmitk/QmitkFileOpenDialog.cpp index c13227a428..0cd4c5dd59 100644 --- a/Modules/Qmitk/QmitkFileOpenDialog.cpp +++ b/Modules/Qmitk/QmitkFileOpenDialog.cpp @@ -1,98 +1,94 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //#define _USE_MATH_DEFINES #include // MITK -#include +#include #include // STL Headers #include //microservices #include #include #include //QT -#include -#include -#include #include // Test imports, delete later #include const std::string QmitkFileOpenDialog::VIEW_ID = "org.mitk.views.QmitkFileOpenDialog"; QmitkFileOpenDialog::QmitkFileOpenDialog(QWidget* parent, Qt::WindowFlags f): QmitkFileDialog(parent, f) { } QmitkFileOpenDialog::~QmitkFileOpenDialog() { } void QmitkFileOpenDialog::ProcessSelectedFile() { std::string file = this->selectedFiles().front().toStdString(); std::string extension = file; extension.erase(0, extension.find_last_of('.')); m_Options = GetSelectedOptions(); // We are not looking for specific options here, which is okay, since the dialog currently only shows the // reader with the highest priority. Better behaviour required, if we want selectable readers. - m_FileReader = m_FileReaderManager.GetReader(extension); + m_FileReader = m_FileReaderRegistry.GetReader(extension); m_FileReader->SetOptions(m_Options); } std::list QmitkFileOpenDialog::QueryAvailableOptions(std::string path) { std::string extension = path; extension.erase(0, extension.find_last_of('.')); us::ModuleContext* context = us::GetModuleContext(); - mitk::FileReaderManager manager; - mitk::IFileReader* reader = manager.GetReader(extension); + mitk::IFileReader* reader = m_FileReaderRegistry.GetReader(extension); if (reader == NULL) { // MITK_WARN << "Did not find ReaderService for registered Extension. This should be looked into by a developer."; std::list emptyList; return emptyList; } return reader->GetOptions(); } mitk::IFileReader* QmitkFileOpenDialog::GetReader() { return this->m_FileReader; } std::list< mitk::BaseData::Pointer > QmitkFileOpenDialog::GetBaseData() { if (m_FileReader == NULL ) { MITK_WARN << "Tried go get BaseData while no FileReader was selected in Dialog. Returning empty list."; std::list< mitk::BaseData::Pointer > emptyList; return emptyList; } return m_FileReader->Read(this->selectedFiles().front().toStdString()); } diff --git a/Modules/Qmitk/QmitkFileOpenDialog.h b/Modules/Qmitk/QmitkFileOpenDialog.h index 4cef05dc33..1b116d7439 100644 --- a/Modules/Qmitk/QmitkFileOpenDialog.h +++ b/Modules/Qmitk/QmitkFileOpenDialog.h @@ -1,88 +1,88 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _QmitkFileOpenDialog_H_INCLUDED #define _QmitkFileOpenDialog_H_INCLUDED #include "QmitkExports.h" #include //QT headers #include #include //Microservices #include "usServiceReference.h" #include "usModuleContext.h" #include "usServiceEvent.h" #include "usServiceInterface.h" // MITK #include #include -#include +#include /** * \ingroup QmitkModule * * \brief */ class QMITK_EXPORT QmitkFileOpenDialog :public QmitkFileDialog { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT private: //us::ModuleContext* m_Context; ///** \brief a filter to further narrow down the list of results*/ //std::string m_Filter; ///** \brief The name of the ServiceInterface that this class should list */ //std::string m_Interface; ///** \brief The name of the ServiceProperty that will be displayed in the list to represent the service */ //std::string m_NamingProperty; public: static const std::string VIEW_ID; QmitkFileOpenDialog(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkFileOpenDialog(); virtual mitk::IFileReader* GetReader(); virtual std::list< mitk::BaseData::Pointer > GetBaseData(); signals: public slots: protected slots: virtual void ProcessSelectedFile(); protected: mitk::IFileReader* m_FileReader; std::list m_Options; - mitk::FileReaderManager m_FileReaderManager; + mitk::FileReaderRegistry m_FileReaderRegistry; virtual std::list QueryAvailableOptions(std::string path) ; //Ui::QmitkFileOpenDialogControls* m_Controls; ///< member holding the UI elements of this widget }; #endif // _QmitkFileOpenDialog_H_INCLUDED diff --git a/Modules/Qmitk/QmitkFileSaveDialog.cpp b/Modules/Qmitk/QmitkFileSaveDialog.cpp index 9e580daf1a..7fcda9492c 100644 --- a/Modules/Qmitk/QmitkFileSaveDialog.cpp +++ b/Modules/Qmitk/QmitkFileSaveDialog.cpp @@ -1,159 +1,159 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //#define _USE_MATH_DEFINES #include // MITK -#include +#include #include // STL Headers #include //microservices #include #include #include //QT #include #include #include #include // Test imports, delete later #include class DummyReader : public mitk::AbstractFileReader { public: DummyReader(const DummyReader& other) : mitk::AbstractFileReader(other) { } DummyReader(const std::string& extension, int priority) : mitk::AbstractFileReader(extension, "This is a dummy description") { m_Priority = priority; //std::list options; m_Options.push_front(std::make_pair("isANiceGuy", true)); m_Options.push_front(std::make_pair("canFly", false)); m_Options.push_front(std::make_pair("isAwesome", true)); m_Options.push_front(std::make_pair("hasOptions", true)); m_Options.push_front(std::make_pair("has more Options", true)); m_Options.push_front(std::make_pair("has maaaaaaaany Options", true)); m_ServiceReg = this->RegisterService(); } ~DummyReader() { if (m_ServiceReg) m_ServiceReg.Unregister(); } using mitk::AbstractFileReader::Read; virtual std::list< itk::SmartPointer > Read(const std::istream& /*stream*/, mitk::DataStorage* /*ds*/ = 0) { std::list result; return result; } virtual void SetOptions(const std::list< mitk::IFileWriter::FileServiceOption >& options ) { m_Options = options; //m_Registration.SetProperties(GetServiceProperties()); } private: DummyReader* Clone() const { return new DummyReader(*this); } us::ServiceRegistration m_ServiceReg; }; // End of internal dummy reader const std::string QmitkFileSaveDialog::VIEW_ID = "org.mitk.views.QmitkFileSaveDialog"; // // // // // // // // // QmitkFileSaveDialog::QmitkFileSaveDialog(mitk::BaseData::Pointer baseData, QWidget* parent, Qt::WindowFlags f): QmitkFileDialog(parent, f) { m_BaseData = baseData; } QmitkFileSaveDialog::~QmitkFileSaveDialog() { } void QmitkFileSaveDialog::ProcessSelectedFile() { std::string file = this->selectedFiles().front().toStdString(); std::string extension = file; extension.erase(0, extension.find_last_of('.')); m_Options = GetSelectedOptions(); // We are not looking for specific Options here, which is okay, since the dialog currently only shows the // reader with the highest priority. Better behaviour required, if we want selectable readers. - m_FileWriter = m_FileWriterManager.GetWriter(extension); + m_FileWriter = m_FileWriterRegistry.GetWriter(extension); m_FileWriter->SetOptions(m_Options); } std::list QmitkFileSaveDialog::QueryAvailableOptions(std::string path) { us::ModuleContext* context = us::GetModuleContext(); - mitk::IFileWriter* writer = m_FileWriterManager.GetWriter(m_BaseData->GetNameOfClass()); + mitk::IFileWriter* writer = m_FileWriterRegistry.GetWriter(m_BaseData->GetNameOfClass()); if (writer == NULL) { // MITK_WARN << "Did not find WriterService for registered Extension. This should be looked into by a developer."; std::list emptyList; return emptyList; } return writer->GetOptions(); } mitk::IFileWriter* QmitkFileSaveDialog::GetWriter() { return this->m_FileWriter; } void QmitkFileSaveDialog::WriteBaseData() { if (m_FileWriter == NULL ) { MITK_WARN << "Tried go write BaseData while no FileWriter was selected in Dialog. Aborting."; return; } - m_FileWriter->Write(m_BaseData); + m_FileWriter->Write(m_BaseData, this->selectedFiles().front().toStdString()); } diff --git a/Modules/Qmitk/QmitkFileSaveDialog.h b/Modules/Qmitk/QmitkFileSaveDialog.h index 69089d528e..717b1b567a 100644 --- a/Modules/Qmitk/QmitkFileSaveDialog.h +++ b/Modules/Qmitk/QmitkFileSaveDialog.h @@ -1,80 +1,82 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _QmitkFileSaveDialog_H_INCLUDED #define _QmitkFileSaveDialog_H_INCLUDED #include "QmitkExports.h" #include //QT headers #include #include #include //Microservices #include "usServiceReference.h" // MITK #include #include -#include +#include #include /** * \ingroup QmitkModule * * \brief */ class QMITK_EXPORT QmitkFileSaveDialog :public QmitkFileDialog { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT private: public: static const std::string VIEW_ID; QmitkFileSaveDialog(mitk::BaseData::Pointer baseData, QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkFileSaveDialog(); virtual mitk::IFileWriter* GetWriter(); - virtual void WriteBaseData(std::list< mitk::BaseData::Pointer > data); + /** + * \brief Writes the Basedata that the WIdget was constructed with into the file selected by the user. + * + */ + virtual void WriteBaseData(); signals: - public slots: + protected slots: - protected slots: - - virtual void ProcessSelectedFile(); + virtual void ProcessSelectedFile(); protected: mitk::IFileWriter* m_FileWriter; std::list m_Options; - mitk::FileWriterManager m_FileWriterManager; + mitk::FileWriterRegistry m_FileWriterRegistry; mitk::BaseData::Pointer m_BaseData; std::list QueryAvailableOptions(std::string path); //Ui::QmitkFileSaveDialogControls* m_Controls; ///< member holding the UI elements of this widget }; #endif // _QmitkFileSaveDialog_H_INCLUDED