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