Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkExampleIOMimeTypes.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 
17 #include "mitkExampleIOMimeTypes.h"
18 #include "mitkIOMimeTypes.h"
19 #include <itksys/SystemTools.hxx>
20 #include <mitkLogMacros.h>
21 
22 namespace mitk
23 {
24  std::vector<CustomMimeType *> ExampleIOMimeTypes::Get()
25  {
26  std::vector<CustomMimeType *> mimeTypes;
27 
28  // order matters here (descending rank for mime types)
29 
30  mimeTypes.push_back(EXAMPLE_MIMETYPE().Clone());
31  mimeTypes.push_back(EXAMPLE_TWO_MIMETYPE().Clone());
32 
33  return mimeTypes;
34  }
35 
36  // Mime Types
37 
39  : CustomMimeType(EXAMPLE_MIMETYPE_NAME())
40  {
41  std::string category = "Example and Tutorial Data";
42  this->SetCategory(category);
43  this->SetComment("Example data structure containing just a string");
44 
45  this->AddExtension("example");
46  this->AddExtension("txt");
47  }
48 
50  {
51  bool canRead(CustomMimeType::AppliesTo(path));
52 
53  // fix for bug 18572
54  // Currently this function is called for writing as well as reading, in that case
55  // the image information can of course not be read
56  // This is a bug, this function should only be called for reading.
57  if (!itksys::SystemTools::FileExists(path.c_str()))
58  {
59  return canRead;
60  }
61  // end fix for bug 18572
62 
63  std::string ext = this->GetExtension(path);
64  ext = itksys::SystemTools::LowerCase(ext);
65 
66  if (ext == ".txt")
67  {
68  // we could test something here
69  if (false)
70  {
71  MITK_WARN << "Can not read .txt file as ExampleDataStructure";
72  canRead = false;
73  }
74  }
75 
76  return canRead;
77  }
78 
80  {
81  return new ExampleDataStructureMimeType(*this);
82  }
83 
85  {
87  }
88 
90  {
92  std::string category = "Example and Tutorial Data";
93  mimeType.SetComment("Simpler Example Data MimeType");
94  mimeType.SetCategory(category);
95  mimeType.AddExtension("example2");
96  return mimeType;
97  }
98 
99  // Names
101  {
102  // create a unique and sensible name for this mime type
103  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".examples.example-data-structure";
104  return name;
105  }
106 
108  {
109  // create a unique and sensible name for this mime type
110  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".examples.example-data-structure-the-second";
111  return name;
112  }
113 }
Pointer Clone() const
static CustomMimeType EXAMPLE_TWO_MIMETYPE()
DataCollection - Class to facilitate loading/accessing structured data.
static ExampleDataStructureMimeType EXAMPLE_MIMETYPE()
static std::string EXAMPLE_TWO_MIMETYPE_NAME()
virtual bool AppliesTo(const std::string &path) const
Checks if the MimeType can handle file at the given location.
void SetComment(const std::string &comment)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static std::string DEFAULT_BASE_NAME()
#define MITK_WARN
Definition: mitkLogMacros.h:23
virtual bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
void AddExtension(const std::string &extension)
static std::vector< CustomMimeType * > Get()
void SetCategory(const std::string &category)
virtual ExampleDataStructureMimeType * Clone() const override
static std::string EXAMPLE_MIMETYPE_NAME()