Isis 3 Programmer Reference
Progress.cpp
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <unistd.h>
3 #include <sys/socket.h>
4 #include <sys/un.h>
27 #include "Progress.h"
28 #include "Application.h"
29 #include "Preference.h"
30 
31 using namespace std;
32 namespace Isis {
38  Progress::Progress() {
39  // Get user preferences
40  int percent;
41  bool printPercent;
42  Isis::PvlGroup &group = Isis::Preference::Preferences().findGroup("UserInterface");
43  percent = group["ProgressBarPercent"];
44  QString temp = (QString) group["ProgressBar"];
45  printPercent = temp.toUpper() == "ON";
46 
47  // Check for an error
48  if((percent != 1) && (percent != 2) &&
49  (percent != 5) && (percent != 10)) {
50  string m = "Invalid preference for [ProgressBarPercent] in ";
51  m += "group [UserInterface] must be 1, 2, 5, or 10";
52  throw IException(IException::User, m, _FILEINFO_);
53  }
54 
55  // Initialize private variables
56  p_text = "Working";
57  p_maximumSteps = 0;
58  p_currentStep = 0;
59  p_currentPercent = 0;
60  p_percentIncrement = percent;
61  p_printPercent = printPercent;
62  p_autoDisplay = true;
63  }
64 
66  Progress::~Progress() {
67  }
68 
77  void Progress::SetText(const QString &text) {
78  p_text = text;
79  }
80 
88  QString Progress::Text() const {
89  return p_text;
90  }
91 
101  void Progress::SetMaximumSteps(const int steps) {
102  if(steps < 0) {
103  string m = "Value for [steps] must be greater than ";
104  m += "or equal to zero in [Progress::SetMaximumSteps]";
105  throw IException(IException::Programmer, m, _FILEINFO_);
106  }
107  p_maximumSteps = steps;
108  p_currentStep = 0;
109  p_currentPercent = 0;
110  }
111 
121  void Progress::CheckStatus() {
122  // Error check
123  //std::cout << p_currentStep << " / " << p_maximumSteps << std::endl;
124  if(p_currentStep > p_maximumSteps) {
125  string m = "Step exceeds maximumSteps in [Progress::CheckStatus]";
126  throw IException(IException::Programmer, m, _FILEINFO_);
127  }
128 
129  if(p_currentStep == 0) {
130  if(Isis::iApp != NULL) {
131  if (p_autoDisplay) {
132  Isis::iApp->UpdateProgress(p_text, p_printPercent);
133  }
134  }
135  else {
136  if(p_printPercent && p_autoDisplay) {
137  cout << p_text << endl;
138  }
139  }
140  }
141 
142  // See if the percent processed needs to be updated
143  while(100.0 * p_currentStep / p_maximumSteps >= p_currentPercent) {
144  if(Isis::iApp != NULL) {
145  if (p_autoDisplay) {
146  Isis::iApp->UpdateProgress(p_currentPercent, p_printPercent);
147  }
148  }
149  else {
150  if(p_printPercent && p_autoDisplay) {
151  if(p_currentPercent < 100) {
152  cout << p_currentPercent << "% Processed\r" << flush;
153  }
154  else {
155  cout << p_currentPercent << "% Processed" << endl;
156  }
157  }
158  }
159  p_currentPercent += p_percentIncrement;
160  }
161 
162  if(p_autoDisplay && Isis::iApp != NULL) {
163  Isis::iApp->ProcessGuiEvents();
164  }
165 
166  // Increment to the next step
167  p_currentStep++;
168 
169  return;
170  }
171 
172 
177  void Progress::DisableAutomaticDisplay() {
178  p_autoDisplay = false;
179  }
180 
181 
188  int Progress::MaximumSteps() const {
189  return p_maximumSteps;
190  }
191 
192 
201  int Progress::CurrentStep() const {
202  return p_currentStep;
203  }
204 
205 
215  void Progress::AddSteps(const int steps) {
216  if(steps == 0) {
217  string m = "Value for [steps] must not be zero in [Progress::AddSteps]";
218  throw IException(IException::Programmer, m, _FILEINFO_);
219  }
220 
221  p_maximumSteps += steps;
222 
223  if(p_currentStep > p_maximumSteps) {
224  string m = "Step exceeds maximumSteps in [Progress::AddSteps]";
225  throw IException(IException::Programmer, m, _FILEINFO_);
226  }
227 
228  if(p_maximumSteps <= 0) {
229  string m = "Maximum steps must be greater than zero in [Progress::AddSteps]";
230  throw IException(IException::Programmer, m, _FILEINFO_);
231  }
232  }
233 } // end namespace isis
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
Namespace for the standard library.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
void ProcessGuiEvents()
Processes the gui events.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void UpdateProgress(const QString &text, bool print)
Updates the progress bar in the gui.