(continued)
GUI coupling
You will want to subclass Message_ProgressIndicator to couple with your favorite GUI toolkit you are using to develop your application. An alternative choice is to provide simple text output (e.g. for debugging purposes). Either way, you will have to redefine Show() and UserBreak() methods.
In my QOLib (Qt/Open CASCADE Library) I used Qt's QProgressDialog widget to visualize a progress bar and a cancel button. You might want to use your own QWidget consisting of QProgressBar, QLabel and optionally QButton.

Here are some code snippets from QLib:
class QOBase_ProgressIndicator : public Message_ProgressIndicator
{
public:
//! Creates an object.
Standard_EXPORT QOBase_ProgressIndicator (QWidget* theParent,
int theMinVal = 0, int theMaxVal = 100, Qt::WindowFlags theFlags = 0);
//! Deletes the object.
Standard_EXPORT virtual ~QOBase_ProgressIndicator ();
//! Updates presentation of the object.
Standard_EXPORT virtual Standard_Boolean Show (const Standard_Boolean theForce);
//! Returns True if the user has signaled to cancel the process.
Standard_EXPORT virtual Standard_Boolean UserBreak();
protected:
QProgressDialog* myProgress;
public:
DEFINE_STANDARD_RTTI(QOBase_ProgressIndicator)
};
/*! Creates a widget using specified paramters to initialize QProgressIndicator.
\a theMin and \a theMax are also used to set the range for \a this progress
indicator.
*/
QOBase_ProgressIndicator::QOBase_ProgressIndicator (QWidget* theParent,
int theMinVal, int theMaxVal,
Qt::WindowFlags theFlags)
{
QOLib_ASSERT (theMinVal < theMaxVal);
myProgress = new QProgressDialog (theParent, theFlags);
myProgress->setWindowModality (Qt::WindowModal);
myProgress->setMinimum (theMinVal);
myProgress->setMaximum (theMaxVal);
myProgress->setMinimumDuration (500); //the dialog will pop up if operation takes >500ms
SetScale (theMinVal, theMaxVal, 1); //synch up ranges between Qt and Open CASCADE
}
/*! Destroys the associated progress dialog.*/
QOBase_ProgressIndicator::~QOBase_ProgressIndicator ()
{
if (myProgress) {
delete myProgress;
myProgress = 0;
}
}
/*! Updates visual presentation according to currently achieved progress.
The text label is updated according to the name of a current step.
Always returns TRUE to signal that the presentation has been updated.
*/
Standard_Boolean QOBase_ProgressIndicator::Show (const Standard_Boolean theForce)
{
Handle(TCollection_HAsciiString) aName = GetScope(1).GetName(); //current step
if (!aName.IsNull())
myProgress->setLabelText (aName->ToCString());
Standard_Real aPc = GetPosition(); //always within [0,1]
int aVal = myProgress->minimum() + aPc *
(myProgress->maximum() - myProgress->minimum());
myProgress->setValue (aVal);
QApplication::processEvents(); //to let redraw and keep GUI responsive
return Standard_True;
}
/*! Returns True if the user has clicked the Cancel button in QProgressDialog.
*/
Standard_Boolean QOBase_ProgressIndicator::UserBreak()
{
return myProgress->wasCanceled();
}
Open CASCADE ships with a Tcl/Tk-based implementation (see class Draw_ProgressIndicator). Unfortunately, version 6.3.0 has (unintentionally) eliminated the XProgress Draw command that you could use to activate it and use inside the Draw session. I reported this to the folks at OCC, so hopefully they will restore it in upcoming releases. If you are impatient you could simply port it from previous versions.
(To be continued...)
GUI coupling
You will want to subclass Message_ProgressIndicator to couple with your favorite GUI toolkit you are using to develop your application. An alternative choice is to provide simple text output (e.g. for debugging purposes). Either way, you will have to redefine Show() and UserBreak() methods.
In my QOLib (Qt/Open CASCADE Library) I used Qt's QProgressDialog widget to visualize a progress bar and a cancel button. You might want to use your own QWidget consisting of QProgressBar, QLabel and optionally QButton.
Here are some code snippets from QLib:
class QOBase_ProgressIndicator : public Message_ProgressIndicator
{
public:
//! Creates an object.
Standard_EXPORT QOBase_ProgressIndicator (QWidget* theParent,
int theMinVal = 0, int theMaxVal = 100, Qt::WindowFlags theFlags = 0);
//! Deletes the object.
Standard_EXPORT virtual ~QOBase_ProgressIndicator ();
//! Updates presentation of the object.
Standard_EXPORT virtual Standard_Boolean Show (const Standard_Boolean theForce);
//! Returns True if the user has signaled to cancel the process.
Standard_EXPORT virtual Standard_Boolean UserBreak();
protected:
QProgressDialog* myProgress;
public:
DEFINE_STANDARD_RTTI(QOBase_ProgressIndicator)
};
/*! Creates a widget using specified paramters to initialize QProgressIndicator.
\a theMin and \a theMax are also used to set the range for \a this progress
indicator.
*/
QOBase_ProgressIndicator::QOBase_ProgressIndicator (QWidget* theParent,
int theMinVal, int theMaxVal,
Qt::WindowFlags theFlags)
{
QOLib_ASSERT (theMinVal < theMaxVal);
myProgress = new QProgressDialog (theParent, theFlags);
myProgress->setWindowModality (Qt::WindowModal);
myProgress->setMinimum (theMinVal);
myProgress->setMaximum (theMaxVal);
myProgress->setMinimumDuration (500); //the dialog will pop up if operation takes >500ms
SetScale (theMinVal, theMaxVal, 1); //synch up ranges between Qt and Open CASCADE
}
/*! Destroys the associated progress dialog.*/
QOBase_ProgressIndicator::~QOBase_ProgressIndicator ()
{
if (myProgress) {
delete myProgress;
myProgress = 0;
}
}
/*! Updates visual presentation according to currently achieved progress.
The text label is updated according to the name of a current step.
Always returns TRUE to signal that the presentation has been updated.
*/
Standard_Boolean QOBase_ProgressIndicator::Show (const Standard_Boolean theForce)
{
Handle(TCollection_HAsciiString) aName = GetScope(1).GetName(); //current step
if (!aName.IsNull())
myProgress->setLabelText (aName->ToCString());
Standard_Real aPc = GetPosition(); //always within [0,1]
int aVal = myProgress->minimum() + aPc *
(myProgress->maximum() - myProgress->minimum());
myProgress->setValue (aVal);
QApplication::processEvents(); //to let redraw and keep GUI responsive
return Standard_True;
}
/*! Returns True if the user has clicked the Cancel button in QProgressDialog.
*/
Standard_Boolean QOBase_ProgressIndicator::UserBreak()
{
return myProgress->wasCanceled();
}
Open CASCADE ships with a Tcl/Tk-based implementation (see class Draw_ProgressIndicator). Unfortunately, version 6.3.0 has (unintentionally) eliminated the XProgress Draw command that you could use to activate it and use inside the Draw session. I reported this to the folks at OCC, so hopefully they will restore it in upcoming releases. If you are impatient you could simply port it from previous versions.
(To be continued...)