Isis 3 Programmer Reference
Progress.cpp
1#include <sys/types.h>
2#include <unistd.h>
3#include <sys/socket.h>
4#include <sys/un.h>
10/* SPDX-License-Identifier: CC0-1.0 */
11#include "Progress.h"
12#include "Application.h"
13#include "Preference.h"
14
15using namespace std;
16namespace Isis {
23 // Get user preferences
24 int percent;
25 bool printPercent;
26 Isis::PvlGroup &group = Isis::Preference::Preferences().findGroup("UserInterface");
27 percent = group["ProgressBarPercent"];
28 QString temp = (QString) group["ProgressBar"];
29 printPercent = temp.toUpper() == "ON";
30
31 // Check for an error
32 if((percent != 1) && (percent != 2) &&
33 (percent != 5) && (percent != 10)) {
34 string m = "Invalid preference for [ProgressBarPercent] in ";
35 m += "group [UserInterface] must be 1, 2, 5, or 10";
36 throw IException(IException::User, m, _FILEINFO_);
37 }
38
39 // Initialize private variables
40 p_text = "Working";
42 p_currentStep = 0;
44 p_percentIncrement = percent;
45 p_printPercent = printPercent;
46 p_autoDisplay = true;
47 }
48
52
61 void Progress::SetText(const QString &text) {
62 p_text = text;
63 }
64
72 QString Progress::Text() const {
73 return p_text;
74 }
75
85 void Progress::SetMaximumSteps(const int steps) {
86 if(steps < 0) {
87 string m = "Value for [steps] must be greater than ";
88 m += "or equal to zero in [Progress::SetMaximumSteps]";
89 throw IException(IException::Programmer, m, _FILEINFO_);
90 }
91 p_maximumSteps = steps;
92 p_currentStep = 0;
94 }
95
106 // Error check
107 //std::cout << p_currentStep << " / " << p_maximumSteps << std::endl;
109 string m = "Step exceeds maximumSteps in [Progress::CheckStatus]";
110 throw IException(IException::Programmer, m, _FILEINFO_);
111 }
112
113 if(p_currentStep == 0) {
114 if(Isis::iApp != NULL) {
115 if (p_autoDisplay) {
116 Isis::iApp->UpdateProgress(p_text, p_printPercent);
117 }
118 }
119 else {
120 if(p_printPercent && p_autoDisplay) {
121 cout << p_text << endl;
122 }
123 }
124 }
125
126 // See if the percent processed needs to be updated
127 while(100.0 * p_currentStep / p_maximumSteps >= p_currentPercent) {
128 if(Isis::iApp != NULL) {
129 if (p_autoDisplay) {
130 Isis::iApp->UpdateProgress(p_currentPercent, p_printPercent);
131 }
132 }
133 else {
134 if(p_printPercent && p_autoDisplay) {
135 if(p_currentPercent < 100) {
136 cout << p_currentPercent << "% Processed\r" << flush;
137 }
138 else {
139 cout << p_currentPercent << "% Processed" << endl;
140 }
141 }
142 }
144 }
145
146 if(p_autoDisplay && Isis::iApp != NULL) {
147 Isis::iApp->ProcessGuiEvents();
148 }
149
150 // Increment to the next step
152
153 return;
154 }
155
156
162 p_autoDisplay = false;
163 }
164
165
173 return p_maximumSteps;
174 }
175
176
186 return p_currentStep;
187 }
188
189
199 void Progress::AddSteps(const int steps) {
200 if(steps == 0) {
201 string m = "Value for [steps] must not be zero in [Progress::AddSteps]";
202 throw IException(IException::Programmer, m, _FILEINFO_);
203 }
204
205 p_maximumSteps += steps;
206
208 string m = "Step exceeds maximumSteps in [Progress::AddSteps]";
209 throw IException(IException::Programmer, m, _FILEINFO_);
210 }
211
212 if(p_maximumSteps <= 0) {
213 string m = "Maximum steps must be greater than zero in [Progress::AddSteps]";
214 throw IException(IException::Programmer, m, _FILEINFO_);
215 }
216 }
217} // end namespace isis
void ProcessGuiEvents()
Processes the gui events.
void UpdateProgress(const QString &text, bool print)
Updates the progress bar in the gui.
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
QString p_text
Text string to output at the initial call to CheckStatus (0% processed)
Definition Progress.h:72
void AddSteps(const int steps)
If the initial step size was a guess, it can be modified using this method.
Definition Progress.cpp:199
int p_currentPercent
The current percent we are checking against.
Definition Progress.h:80
~Progress()
Destroys the Progress object.
Definition Progress.cpp:50
int MaximumSteps() const
Returns the maximum number of steps of the progress.
Definition Progress.cpp:172
int p_maximumSteps
Number of steps in your processing sequence.
Definition Progress.h:74
Progress()
Constructs a Progress object.
Definition Progress.cpp:22
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
Definition Progress.cpp:85
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
Definition Progress.cpp:61
void DisableAutomaticDisplay()
Turns off updating the Isis Gui when CheckStatus() is called.
Definition Progress.cpp:161
int p_currentStep
The current step in the processing sequence.
Definition Progress.h:77
QString Text() const
Returns the text to output.
Definition Progress.cpp:72
int p_percentIncrement
How much to increment the currentPercent by.
Definition Progress.h:84
void CheckStatus()
Checks and updates the status.
Definition Progress.cpp:105
int CurrentStep() const
Returns the current step of the progress.
Definition Progress.cpp:185
Contains multiple PvlContainers.
Definition PvlGroup.h:41
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
Namespace for the standard library.