Copyright (c) 1993-2022 Robert McNeel & Associates. All rights reserved. OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert McNeel & Associates.
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
For complete openNURBS copyright information see http://www.opennurbs.org. Calculation use ON_ProgressReporter to report progress to the calling code.
static void ON_ProgressReporter::ReportProgress |
( |
ON_ProgressReporter * |
progress_reporter, |
|
|
int |
i, |
|
|
int |
max_i |
|
) |
| |
|
static |
Description: The calculation 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 calculation is beginning and 1.0 indicates the calculation is complete. Example:
void MyLongCalculation( ..., ON_ProgressReporter* pr, ...) { ... for ( i = 0; i < count; i++ ) { ON_ProgressReporter::ReportProgress(pr,i,count);
... } ON_ProgressReporter::ReportProgress(pr,1.0); ///< finished ... }
static void ON_ProgressReporter::ReportProgress |
( |
ON_ProgressReporter * |
progress_reporter, |
|
|
unsigned int |
i, |
|
|
unsigned int |
max_i |
|
) |
| |
|
static |
Description: The calculation 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 calculation is beginning and 1.0 indicates the calculation is complete. Example:
void MyLongCalculation( ..., ON_ProgressReporter* pr, ...) { ... for ( i = 0; i < count; i++ ) { ON_ProgressReporter::ReportProgress(pr,i,count);
... } ON_ProgressReporter::ReportProgress(pr,1.0); ///< finished ... }
void ON_ProgressReporter::SetSynchronousProgressCallbackFunction |
( |
void(*)(ON__UINT_PTR context, double fraction_complete) |
callback_function, |
|
|
ON__UINT_PTR |
callback_context |
|
) |
| |
Description: 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.
Parameters 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. Example:
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 = ...;
ON_ProgressReporter pr;
pr.SetSynchronousProgressCallbackFunction(MyProgressCallback,&my_msg);
...
Pass &pr to a calculation function. The calculation will generally be running
in a different thread or allowing Windows messages to be pumped.