Medical Imaging Interaction Toolkit  2018.4.99-a3d2e8fb
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkExampleIOMimeTypes.h"
14 #include "mitkIOMimeTypes.h"
15 #include <itksys/SystemTools.hxx>
16 #include <mitkLogMacros.h>
17 
18 namespace mitk
19 {
20  std::vector<CustomMimeType *> ExampleIOMimeTypes::Get()
21  {
22  std::vector<CustomMimeType *> mimeTypes;
23 
24  // order matters here (descending rank for mime types)
25 
26  mimeTypes.push_back(EXAMPLE_MIMETYPE().Clone());
27  mimeTypes.push_back(EXAMPLE_TWO_MIMETYPE().Clone());
28 
29  return mimeTypes;
30  }
31 
32  // Mime Types
33 
36  {
37  std::string category = "Example and Tutorial Data";
38  this->SetCategory(category);
39  this->SetComment("Example data structure containing just a string");
40 
41  this->AddExtension("example");
42  this->AddExtension("txt");
43  }
44 
46  {
47  bool canRead(CustomMimeType::AppliesTo(path));
48 
49  // fix for bug 18572
50  // Currently this function is called for writing as well as reading, in that case
51  // the image information can of course not be read
52  // This is a bug, this function should only be called for reading.
53  if (!itksys::SystemTools::FileExists(path.c_str()))
54  {
55  return canRead;
56  }
57  // end fix for bug 18572
58 
59  std::string ext = this->GetExtension(path);
60  ext = itksys::SystemTools::LowerCase(ext);
61 
62  if (ext == ".txt")
63  {
64  // we could test something here
65  if (false)
66  {
67  MITK_WARN << "Can not read .txt file as ExampleDataStructure";
68  canRead = false;
69  }
70  }
71 
72  return canRead;
73  }
74 
76  {
77  return new ExampleDataStructureMimeType(*this);
78  }
79 
81  {
83  }
84 
86  {
88  std::string category = "Example and Tutorial Data";
89  mimeType.SetComment("Simpler Example Data MimeType");
90  mimeType.SetCategory(category);
91  mimeType.AddExtension("example2");
92  return mimeType;
93  }
94 
95  // Names
97  {
98  // create a unique and sensible name for this mime type
99  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".examples.example-data-structure";
100  return name;
101  }
102 
104  {
105  // create a unique and sensible name for this mime type
106  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".examples.example-data-structure-the-second";
107  return name;
108  }
109 }
static CustomMimeType EXAMPLE_TWO_MIMETYPE()
std::string GetExtension(const std::string &path) const
Provides the first matching extension.
DataCollection - Class to facilitate loading/accessing structured data.
virtual bool AppliesTo(const std::string &path) const
Checks if the MimeType can handle file at the given location.
static ExampleDataStructureMimeType EXAMPLE_MIMETYPE()
static std::string EXAMPLE_TWO_MIMETYPE_NAME()
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:19
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)
ExampleDataStructureMimeType * Clone() const override
static std::string EXAMPLE_MIMETYPE_NAME()