Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkLegacyFileWriterService.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include <mitkCustomMimeType.h>
20 #include <mitkDataNode.h>
21 #include <mitkIOMimeTypes.h>
22 
24  const std::string &description)
25  : AbstractFileWriter(legacyWriter->GetSupportedBaseData()), m_LegacyWriter(legacyWriter)
26 {
28  this->SetDescription(description);
29 
30  CustomMimeType customMimeType;
31  std::vector<std::string> extensions = legacyWriter->GetPossibleFileExtensions();
32  for (std::vector<std::string>::iterator ext = extensions.begin(); ext != extensions.end(); ++ext)
33  {
34  if (ext->empty())
35  continue;
36 
37  std::string extension = *ext;
38  if (extension.size() > 1 && extension[0] == '*')
39  {
40  // remove "*"
41  extension = extension.substr(1);
42  }
43  if (extension.size() > 1 && extension[0] == '.')
44  {
45  // remove "."
46  extension = extension.substr(1);
47  }
48  std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
49  customMimeType.AddExtension(extension);
50  }
51  this->SetMimeType(customMimeType);
52 
53  m_ServiceRegistration = RegisterService();
54 }
55 
57 {
58 }
59 
61 
63 {
64  if (m_LegacyWriter.IsNull())
65  mitkThrow() << "LegacyFileWriterService was incorrectly initialized: Has no LegacyFileWriter.";
66 
67  ValidateOutputLocation();
68 
69  LocalFile localFile(this);
70 
71  m_LegacyWriter->SetFileName(localFile.GetFileName().c_str());
72  m_LegacyWriter->SetInput(const_cast<BaseData *>(this->GetInput()));
73  m_LegacyWriter->Write();
74 }
75 
77 {
79  return Unsupported;
81  node->SetData(const_cast<BaseData *>(this->GetInput()));
82  return m_LegacyWriter->CanWriteDataType(node) ? Supported : Unsupported;
83 }
84 
85 mitk::LegacyFileWriterService *mitk::LegacyFileWriterService::Clone() const
86 {
87  return new LegacyFileWriterService(*this);
88 }
virtual void Write() override
Write the base data to the specified location or output stream.
LegacyFileWriterService(mitk::FileWriter::Pointer legacyWriter, const std::string &description)
virtual ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
virtual ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static std::string DEFAULT_BASE_NAME()
static Pointer New()
#define mitkThrow()
A local file representation for streams.
void AddExtension(const std::string &extension)
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
void SetMimeType(const CustomMimeType &mimeType)
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:49
void SetMimeTypePrefix(const std::string &prefix)
Base class for writing mitk::BaseData objects to files or streams.
void SetDescription(const std::string &description)
Sets a human readable description of this writer.