cgma
TextProgressTool.cpp
Go to the documentation of this file.
00001 //#include "cstring"
00002 #include "TextProgressTool.hpp"
00003 #include "CubitMessage.hpp"
00004 
00005 //=============================================================================
00006 // Description: constructor
00007 // Notes:  This will initialize the progress bar and display it
00008 //         The difference between nLower and nUpper will be the number of
00009 //         integral steps the progress bar will before the process is complete
00010 // Author: sjowen
00011 // Date: 11/7/01
00012 //=============================================================================
00013 TextProgressTool::TextProgressTool()
00014 {
00015   nTotal = 0;
00016   nCurrent = 0;
00017   nShown = 0;
00018 }
00019 
00020 TextProgressTool::~TextProgressTool()
00021 {
00022 }
00023 
00024 void TextProgressTool::start(int nLower, int nUpper,
00025                            const char* title           /* = NULL */,
00026                            const char* info_string     /* = NULL      */,
00027                            CubitBoolean ,
00028                            CubitBoolean )
00029 {
00030   const char* progress_title = title ? title : "Progress";
00031 
00032   //bSmooth; bHasCancelButton;
00033   PRINT_INFO("%s\n",progress_title);
00034   if (info_string != NULL)
00035   {
00036     PRINT_INFO("%s\n",info_string);
00037   }
00038   PRINT_INFO("0   |    |    |    |    50   |    |    |    |  100\n");
00039 
00040   nTotal = nUpper - nLower;
00041   nCurrent = 0;
00042   nShown = 0;
00043 }
00044 
00045 //=============================================================================
00046 // Description: end
00047 // Notes:  closes/finishes the prgress bar window
00048 // Author: sjowen
00049 // Date: 11/7/01
00050 //=============================================================================
00051 void TextProgressTool::end()
00052 {
00053   PRINT_INFO("\n");
00054 }
00055 
00056 //=============================================================================
00057 // Description: makes one integer step of the progress bar
00058 // Notes:
00059 // Author: sjowen
00060 // Date: 11/7/01
00061 //=============================================================================
00062 void TextProgressTool::step()
00063 {
00064   if( nTotal > 0 )
00065   {
00066     nCurrent++;  
00067     int n = 50 * nCurrent / nTotal;
00068     for( ; nShown < n; nShown++ )
00069       PRINT_INFO("*");
00070   }
00071 }
00072 
00073 //=============================================================================
00074 // Description: moves the progress bar to the specified percentage
00075 // Notes:  only moves if percentage is greater the the current step
00076 //         pcnt should be between 0 and 1
00077 // Author: sjowen
00078 // Date: 11/7/01
00079 //=============================================================================
00080 void TextProgressTool::percent( double pcnt )
00081 {
00082   int ncur = (int)(pcnt * (double)nTotal + 0.5);
00083   if(ncur > nTotal) 
00084     ncur = nTotal;
00085   if (ncur > nCurrent)
00086   {
00087     int ii;
00088     for (ii=nCurrent; ii<ncur; ii++)
00089     {
00090       step();
00091     }
00092     nCurrent = ncur;
00093   }
00094 }
00095 
00096 void TextProgressTool::check_interrupt()
00097 {
00098 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines