Rhino C++ API  8.6
Public Member Functions | Static Public Member Functions | List of all members
ON_ProgressReporter Class Reference

#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)
 

Static Public Member Functions

static double FractionComplete (ON_ProgressReporter *progress_reporter)
 
static void ReportProgress (ON_ProgressReporter *progress_reporter, double fraction_complete)
 
static void ReportProgress (ON_ProgressReporter *progress_reporter, int i, int max_i)
 
static void ReportProgress (ON_ProgressReporter *progress_reporter, unsigned int i, unsigned int max_i)
 

Detailed Description

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.

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

Description: 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 calculation 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

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/((double)count));
... } ON_ProgressReporter::ReportProgress(pr,1.0); ///< finished ... }

◆ ReportProgress() [2/3]

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 ... }

◆ ReportProgress() [3/3]

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 ... }

◆ SetSynchronousProgressCallbackFunction()

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.