Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkProgressBar.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 "mitkProgressBar.h"
20 #include <itkCommand.h>
21 #include <itkObjectFactory.h>
22 #include <itkOutputWindow.h>
23 
24 #include <algorithm>
25 
26 namespace mitk
27 {
28  ProgressBar *ProgressBar::m_Instance = nullptr;
29 
34  void ProgressBar::Progress(unsigned int steps)
35  {
36  if (!m_Implementations.empty())
37  {
39  for (iter = m_Implementations.begin(); iter != m_Implementations.end(); iter++)
40  {
41  // update progress for all ProgressBarImplementations
42  if ((*iter) != nullptr)
43  {
44  (*iter)->Progress(steps);
45  }
46  }
47  }
48  }
49 
54  {
55  if (!m_Implementations.empty())
56  {
58  for (iter = m_Implementations.begin(); iter != m_Implementations.end(); iter++)
59  {
60  // set steps to do for all ProgressBarImplementations
61  if ((*iter) != nullptr)
62  {
63  (*iter)->Reset();
64  }
65  }
66  }
67  }
68 
72  void ProgressBar::AddStepsToDo(unsigned int steps)
73  {
74  if (!m_Implementations.empty())
75  {
77  for (iter = m_Implementations.begin(); iter != m_Implementations.end(); iter++)
78  {
79  // set steps to do for all ProgressBarImplementations
80  if ((*iter) != nullptr)
81  {
82  (*iter)->AddStepsToDo(steps);
83  }
84  }
85  }
86  }
87 
92  {
93  if (!m_Implementations.empty())
94  {
96  for (iter = m_Implementations.begin(); iter != m_Implementations.end(); iter++)
97  {
98  // set percentage visible for all ProgressBarImplementations
99  if ((*iter) != nullptr)
100  {
101  (*iter)->SetPercentageVisible(visible);
102  }
103  }
104  }
105  }
106 
111  {
112  if (m_Instance == nullptr)
113  {
114  m_Instance = new ProgressBar();
115  }
116 
117  return m_Instance;
118  }
119 
124  {
125  if (std::find(m_Implementations.begin(), m_Implementations.end(), implementation) == m_Implementations.end())
126  {
127  m_Implementations.push_back(implementation);
128  }
129  }
130 
132  {
133  auto iter = std::find(m_Implementations.begin(), m_Implementations.end(), implementation);
134  if (iter != m_Implementations.end())
135  {
136  m_Implementations.erase(iter);
137  }
138  }
139 
142 } // end namespace mitk
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
void RegisterImplementationInstance(ProgressBarImplementation *implementation)
Supply a GUI- dependent ProgressBar. Has to be set by the application to connect the application depe...
GUI indepentent Interface for all Gui depentent implementations of a ProgressBar. ...
Sending a message to the applications ProgressBar.
ProgressBarImplementationsList m_Implementations
DataCollection - Class to facilitate loading/accessing structured data.
void Reset()
Explicitly reset progress bar.
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
ProgressBarImplementationsList::iterator ProgressBarImplementationsListIterator
void UnregisterImplementationInstance(ProgressBarImplementation *implementation)
void SetPercentageVisible(bool visible)
Sets whether the current progress value is displayed.
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
static ProgressBar * m_Instance