Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
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 "mitkDataNodeSelection.h"
18 
19 #include "mitkDataNodeObject.h"
20 
21 namespace mitk
22 {
23 
25  m_Selection(new ContainerType())
26 {
27 
28 }
29 
31  m_Selection(new ContainerType())
32 {
34  m_Selection->push_back(obj);
35 }
36 
37 DataNodeSelection::DataNodeSelection(const std::vector<DataNode::Pointer>& nodes) :
38  m_Selection(new ContainerType())
39 {
40  for (auto i = nodes.begin(); i != nodes.end(); ++i)
41  {
43  m_Selection->push_back(obj);
44  }
45 }
46 
48 {
49  if (m_Selection->empty())
50  return berry::Object::Pointer();
51 
52  return *(m_Selection->begin());
53 }
54 
56 {
57  return m_Selection->begin();
58 }
59 
61 {
62  return m_Selection->end();
63 }
64 
66 {
67  return m_Selection->size();
68 }
69 
71 {
72  return m_Selection;
73 }
74 
75 std::list<DataNode::Pointer> DataNodeSelection::GetSelectedDataNodes() const
76 {
77  std::list<DataNode::Pointer> selectedNodes;
78  if(IsEmpty())
79  return selectedNodes;
80 
81  DataNodeObject::Pointer dataNodeObject;
82  DataNode::Pointer dataNode;
83 
84  for(iterator it = Begin(); it != End(); ++it)
85  {
86  dataNodeObject = it->Cast<DataNodeObject>();
87  if(dataNodeObject.IsNotNull())
88  {
89  dataNode = dataNodeObject->GetDataNode();
90  if(dataNode.IsNotNull())
91  selectedNodes.push_back(dataNode);
92  }
93  }
94  return selectedNodes;
95 }
96 
98 {
99  return m_Selection->empty();
100 }
101 
103 {
104  if (const berry::IStructuredSelection* other = dynamic_cast<const berry::IStructuredSelection*>(obj))
105  {
106  return m_Selection == other->ToVector();
107  }
108 
109  return false;
110 }
111 
112 }
virtual Object::Pointer GetFirstElement() const override
virtual iterator Begin() const override
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:78
DataCollection - Class to facilitate loading/accessing structured data.
ContainerType::const_iterator iterator
virtual int Size() const override
ContainerType::Pointer m_Selection
virtual ContainerType::Pointer ToVector() const override
bool IsEmpty() const override
bool operator==(const berry::Object *obj) const override
SmartPointer< Other > Cast() const
std::list< mitk::DataNode::Pointer > GetSelectedDataNodes() const
virtual iterator End() const override