#include <opennurbs_progress_reporter.h>

Public Member Functions

 ON_ProgressReporter ()
 
 ~ON_ProgressReporter ()
 
void SetSynchronousProgressCallbackFunction (void(*callback_function)(ON__UINT_PTR context, double fraction_complete), ON__UINT_PTR callback_context)
 Set the function that is called when a calculation calls ReportProgress(). More...
 

Static Public Member Functions

static double FractionComplete (ON_ProgressReporter *progress_reporter)
 The calculation may call ON_ProgressReporter::FractionComplete to get the current fraction completed. More...
 
static void ReportProgress (ON_ProgressReporter *progress_reporter, double fraction_complete)
 The caclulation calls ON_ProgressReporter::ReportProgress to report its current progress. If it is the first call to ReportProgress, or the faction_complete is 1.0, or the fraction_complete has increased a reasonable amount, then the callback function is called. More...
 
static void ReportProgress (ON_ProgressReporter *progress_reporter, int i, int max_i)
 The caclulation calls ON_ProgressReporter::ReportProgress to report its current progress. If it is the first call to ReportProgress, or the faction_complete is 1.0, or the fraction_complete has increased a reasonable amount, then the callback function is called. More...
 
static void ReportProgress (ON_ProgressReporter *progress_reporter, unsigned int i, unsigned int max_i)
 The caclulation calls ON_ProgressReporter::ReportProgress to report its current progress. If it is the first call to ReportProgress, or the faction_complete is 1.0, or the fraction_complete has increased a reasonable amount, then the callback function is called. More...
 

Constructor & Destructor Documentation

◆ ON_ProgressReporter()

ON_ProgressReporter::ON_ProgressReporter ( )

◆ ~ON_ProgressReporter()

ON_ProgressReporter::~ON_ProgressReporter ( )

Member Function Documentation

◆ FractionComplete()

static double ON_ProgressReporter::FractionComplete ( ON_ProgressReporter progress_reporter)
static

The calculation may call ON_ProgressReporter::FractionComplete to get the current fraction completed.

Parameters
progress_reporter[in] A pointer to an ON_ProgressReporter or null pointer.
Returns
ON_UNSET_VALUE is returned when progress_reporter is nullptr. Otherwise, a value between 0.0 and 1.0 is returned where 0.0 indicates the calcuation is beginning and 1.0 indicates the calculation is complete.

◆ ReportProgress() [1/3]

static void ON_ProgressReporter::ReportProgress ( ON_ProgressReporter progress_reporter,
double  fraction_complete 
)
static

The caclulation calls ON_ProgressReporter::ReportProgress to report its current progress. If it is the first call to ReportProgress, or the faction_complete is 1.0, or the fraction_complete has increased a reasonable amount, then the callback function is called.

Parameters
progress_reporter[in] A pointer to an ON_ProgressReporter or null pointer.
fraction_complete[in] a value between 0.0 and 1.0 where 0.0 indicates the calcuation is beginning and 1.0 indicates the calculation is complete.
void MyLongCalculation( ..., ON_ProgressReporter* pr, ...)
{
...
for ( i = 0; i < count; i++ )
{
ON_ProgressReporter::ReportProgress(pr,i/((double)count));
...
}
...
}

◆ ReportProgress() [2/3]

static void ON_ProgressReporter::ReportProgress ( ON_ProgressReporter progress_reporter,
int  i,
int  max_i 
)
static

The caclulation calls ON_ProgressReporter::ReportProgress to report its current progress. If it is the first call to ReportProgress, or the faction_complete is 1.0, or the fraction_complete has increased a reasonable amount, then the callback function is called.

Parameters
progress_reporter[in] A pointer to an ON_ProgressReporter or null pointer.
fraction_complete[in] a value between 0.0 and 1.0 where 0.0 indicates the calcuation is beginning and 1.0 indicates the calculation is complete.
void MyLongCalculation( ..., ON_ProgressReporter* pr, ...)
{
...
for ( i = 0; i < count; i++ )
{
...
}
...
}

◆ ReportProgress() [3/3]

static void ON_ProgressReporter::ReportProgress ( ON_ProgressReporter progress_reporter,
unsigned int  i,
unsigned int  max_i 
)
static

The caclulation calls ON_ProgressReporter::ReportProgress to report its current progress. If it is the first call to ReportProgress, or the faction_complete is 1.0, or the fraction_complete has increased a reasonable amount, then the callback function is called.

Parameters
progress_reporter[in] A pointer to an ON_ProgressReporter or null pointer.
fraction_complete[in] a value between 0.0 and 1.0 where 0.0 indicates the calcuation is beginning and 1.0 indicates the calculation is complete.
void MyLongCalculation( ..., ON_ProgressReporter* pr, ...)
{
...
for ( i = 0; i < count; i++ )
{
...
}
...
}

◆ SetSynchronousProgressCallbackFunction()

void ON_ProgressReporter::SetSynchronousProgressCallbackFunction ( void(*)(ON__UINT_PTR context, double fraction_complete)  callback_function,
ON__UINT_PTR  callback_context 
)

Set the function that is called when a calculation calls ReportProgress().

Parameters
callback_function[in]
  • This function is called when the calculation reports progress.
  • The calculation thread calls in this callback function.
  • The callback function should do something that is fast and simple, like post a message to a user interface control and return immediately. Paramters passed to the callback function:
context[in] the value of callback_context.
fraction_complete[in] A value between 0.0 and 1.0 indicating how much of the calculation is compete.
@verbatim
struct MyWindowsMessage
{
HWND m_hWnd;
UINT m_Msg,
WPARAM m_wParam
};
...
void MyProgressCallback(
ON__UINT_PTR context,
double fraction_complete
)
{
if ( 0 != context )
{
MyWindowsMessage* msg = (MyWindowsMessage*)context;
LPARAM lParam = (UINT)ceil(100.0*fraction_complete); // 0 to 100.
PostWindowsMessage(msg.m_hWnd,msg.m_Msg,msg.m_wParam,lParam);
}
}
...
struct MyWindowsMessage my_msg;
my_msg.m_hWnd = my progress bar window
my_msg.m_Msg = RegisterWindowMessage(L"MyProgressBarWindowsMessage");
my_msg.m_wParam = ...;
pr.SetSynchronousProgressCallbackFunction(MyProgressCallback,&my_msg);
...
Pass &pr to a calculation function. The calcuation will generally be running
in a different thread or allowing Windows messages to be pumped.
@endverbatim