Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 (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 "mitkProgressBar.h"
16 #include <itkCommand.h>
17 #include <itkObjectFactory.h>
18 #include <itkOutputWindow.h>
19 
20 #include <algorithm>
21 
22 namespace mitk
23 {
24  ProgressBar *ProgressBar::m_Instance = nullptr;
25 
30  void ProgressBar::Progress(unsigned int steps)
31  {
32  if (!m_Implementations.empty())
33  {
35  for (iter = m_Implementations.begin(); iter != m_Implementations.end(); iter++)
36  {
37  // update progress for all ProgressBarImplementations
38  if ((*iter) != nullptr)
39  {
40  (*iter)->Progress(steps);
41  }
42  }
43  }
44  }
45 
50  {
51  if (!m_Implementations.empty())
52  {
54  for (iter = m_Implementations.begin(); iter != m_Implementations.end(); iter++)
55  {
56  // set steps to do for all ProgressBarImplementations
57  if ((*iter) != nullptr)
58  {
59  (*iter)->Reset();
60  }
61  }
62  }
63  }
64 
68  void ProgressBar::AddStepsToDo(unsigned int steps)
69  {
70  if (!m_Implementations.empty())
71  {
73  for (iter = m_Implementations.begin(); iter != m_Implementations.end(); iter++)
74  {
75  // set steps to do for all ProgressBarImplementations
76  if ((*iter) != nullptr)
77  {
78  (*iter)->AddStepsToDo(steps);
79  }
80  }
81  }
82  }
83 
88  {
89  if (!m_Implementations.empty())
90  {
92  for (iter = m_Implementations.begin(); iter != m_Implementations.end(); iter++)
93  {
94  // set percentage visible for all ProgressBarImplementations
95  if ((*iter) != nullptr)
96  {
97  (*iter)->SetPercentageVisible(visible);
98  }
99  }
100  }
101  }
102 
107  {
108  if (m_Instance == nullptr)
109  {
110  m_Instance = new ProgressBar();
111  }
112 
113  return m_Instance;
114  }
115 
120  {
121  if (std::find(m_Implementations.begin(), m_Implementations.end(), implementation) == m_Implementations.end())
122  {
123  m_Implementations.push_back(implementation);
124  }
125  }
126 
128  {
129  auto iter = std::find(m_Implementations.begin(), m_Implementations.end(), implementation);
130  if (iter != m_Implementations.end())
131  {
132  m_Implementations.erase(iter);
133  }
134  }
135 
138 } // 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