Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkDataNodeSelection.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 "mitkDataNodeSelection.h"
14 
15 #include "mitkDataNodeObject.h"
16 
17 namespace mitk
18 {
19 
21  m_Selection(new ContainerType())
22 {
23 
24 }
25 
28 {
30  m_Selection->push_back(obj);
31 }
32 
33 DataNodeSelection::DataNodeSelection(const std::vector<DataNode::Pointer>& nodes) :
35 {
36  for (auto i = nodes.begin(); i != nodes.end(); ++i)
37  {
39  m_Selection->push_back(obj);
40  }
41 }
42 
44 {
45  if (m_Selection->empty())
46  return berry::Object::Pointer();
47 
48  return *(m_Selection->begin());
49 }
50 
52 {
53  return m_Selection->begin();
54 }
55 
57 {
58  return m_Selection->end();
59 }
60 
62 {
63  return m_Selection->size();
64 }
65 
67 {
68  return m_Selection;
69 }
70 
71 std::list<DataNode::Pointer> DataNodeSelection::GetSelectedDataNodes() const
72 {
73  std::list<DataNode::Pointer> selectedNodes;
74  if(IsEmpty())
75  return selectedNodes;
76 
77  DataNodeObject::Pointer dataNodeObject;
78  DataNode::Pointer dataNode;
79 
80  for(iterator it = Begin(); it != End(); ++it)
81  {
82  dataNodeObject = it->Cast<DataNodeObject>();
83  if(dataNodeObject.IsNotNull())
84  {
85  dataNode = dataNodeObject->GetDataNode();
86  if(dataNode.IsNotNull())
87  selectedNodes.push_back(dataNode);
88  }
89  }
90  return selectedNodes;
91 }
92 
94 {
95  return m_Selection->empty();
96 }
97 
99 {
100  if (const berry::IStructuredSelection* other = dynamic_cast<const berry::IStructuredSelection*>(obj))
101  {
102  return m_Selection == other->ToVector();
103  }
104 
105  return false;
106 }
107 
108 }
Object::Pointer GetFirstElement() const override
iterator Begin() const override
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
SmartPointer< Other > Cast() const
DataCollection - Class to facilitate loading/accessing structured data.
ContainerType::const_iterator iterator
ContainerType::Pointer m_Selection
ContainerType::Pointer ToVector() const override
std::list< mitk::DataNode::Pointer > GetSelectedDataNodes() const
bool IsEmpty() const override
bool operator==(const berry::Object *obj) const override
iterator End() const override