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
QmitkFunctionality2.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 "QmitkFunctionality.h"
18 #include "internal/QmitkFunctionalityUtil.h"
19 
20 #include <berryIWorkbenchWindow.h>
21 #include <berryISelectionService.h>
22 
23 #include <mitkDataNodeObject.h>
24 
25 std::vector<mitk::DataNode*> QmitkFunctionality::GetCurrentSelection() const
26 {
27  berry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection());
28  // buffer for the data manager selection
29  mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast<const mitk::DataNodeSelection>();
30  return this->DataNodeSelectionToVector(currentSelection);
31 }
32 
33 std::vector<mitk::DataNode*> QmitkFunctionality::GetDataManagerSelection() const
34 {
35  berry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager"));
36  // buffer for the data manager selection
37  mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast<const mitk::DataNodeSelection>();
38  return this->DataNodeSelectionToVector(currentSelection);
39 }
40 
41 void QmitkFunctionality::OnSelectionChanged(std::vector<mitk::DataNode*> /*nodes*/)
42 {
43 }
44 
46 {
47 
48  std::vector<mitk::DataNode*> selectedNodes;
49  if(currentSelection.IsNull())
50  return selectedNodes;
51 
52  mitk::DataNodeObject* _DataNodeObject = 0;
53  mitk::DataNode* _DataNode = 0;
54 
55  for(mitk::DataNodeSelection::iterator it = currentSelection->Begin();
56  it != currentSelection->End(); ++it)
57  {
58  _DataNodeObject = dynamic_cast<mitk::DataNodeObject*>((*it).GetPointer());
59  if(_DataNodeObject)
60  {
61  _DataNode = _DataNodeObject->GetDataNode();
62  if(_DataNode)
63  selectedNodes.push_back(_DataNode);
64  }
65  }
66 
67  return selectedNodes;
68 }
69 
71 {
72  // garantuee no recursions when a new node event is thrown in NodeAdded()
73  if(!m_InDataStorageChanged)
74  {
75  m_InDataStorageChanged = true;
76  this->NodeAdded(node);
77  this->DataStorageChanged();
78  m_InDataStorageChanged = false;
79  }
80 
81 }
82 
84 {
85 
86 }
87 
89 {
90  // garantuee no recursions when a new node event is thrown in NodeAdded()
91  if(!m_InDataStorageChanged)
92  {
93  m_InDataStorageChanged = true;
94  this->NodeRemoved(node);
95  this->DataStorageChanged();
96  m_InDataStorageChanged = false;
97  }
98 }
99 
101 {
102 
103 }
104 
106 {
107 
108 }
109 
111 {
112  // garantuee no recursions when a new node event is thrown in NodeAdded()
113  if(!m_InDataStorageChanged)
114  {
115  m_InDataStorageChanged = true;
116  this->NodeChanged(node);
117  this->DataStorageChanged();
118  m_InDataStorageChanged = false;
119  }
120 }
121 
123 {
124  std::vector<mitk::DataNode*> nodes;
125  nodes.push_back(node);
126  this->FireNodesSelected(nodes);
127 }
128 
129 void QmitkFunctionality::FireNodesSelected( std::vector<mitk::DataNode*> nodes )
130 {
131  if( !m_SelectionProvider )
132  return;
133 
134  std::vector<mitk::DataNode::Pointer> nodesSmartPointers;
135  for (std::vector<mitk::DataNode*>::iterator it = nodes.begin()
136  ; it != nodes.end(); it++)
137  {
138  nodesSmartPointers.push_back( *it );
139  }
140  m_SelectionProvider->FireNodesSelected(nodesSmartPointers);
141 
142 }
virtual void NodeRemoved(const mitk::DataNode *node)
std::vector< mitk::DataNode * > GetDataManagerSelection() const
void NodeRemovedProxy(const mitk::DataNode *node)
std::vector< mitk::DataNode * > GetCurrentSelection() const
DataNode::Pointer GetDataNode() const
virtual void NodeChanged(const mitk::DataNode *)
ContainerType::const_iterator iterator
void FireNodeSelected(mitk::DataNode *node)
virtual void NodeAdded(const mitk::DataNode *node)
void NodeAddedProxy(const mitk::DataNode *node)
virtual void DataStorageChanged()
void NodeChangedProxy(const mitk::DataNode *node)
SmartPointer< Other > Cast() const
std::vector< mitk::DataNode * > DataNodeSelectionToVector(mitk::DataNodeSelection::ConstPointer currentSelection) const
void FireNodesSelected(std::vector< mitk::DataNode * > nodes)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
IWorkbenchPartSite::Pointer GetSite() const override
virtual void OnSelectionChanged(std::vector< mitk::DataNode * >)