MyProgressDialog.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00028 #include <config.h>
00029 #include "panoinc_WX.h"
00030 
00031 #include "MyProgressDialog.h"
00032 
00033 #include "PT/PTOptimise.h"
00034 
00035 // So that the translation is captured
00036 #define ELAPSED_TIME _("Elapsed time : ")
00037 
00038 ProgressReporterDialog::~ProgressReporterDialog()
00039 {
00040     
00041 }
00042 
00043 bool ProgressReporterDialog::increaseProgress(double i)
00044 {
00045     if (m_abort) return false;
00046 
00047     m_progress += i;
00048     // build the message:
00049     int percentage = (int) floor(m_progress/m_maxProgress*100);
00050     if (percentage > 100) percentage = 100;
00051 
00052     std::cerr << m_message.c_str() << ": " << percentage << "%" << std::endl;
00053 
00054     if (!Update(percentage, m_message)) {
00055         return false;
00056     }
00057     return true;
00058 }
00059 
00060 bool ProgressReporterDialog::increaseProgress(double i, const std::string & msg)
00061 {
00062     if (m_abort) return false;
00063 
00064     m_progress += i;
00065     m_message = wxString(msg.c_str(), wxConvLocal);
00066     // build the message:
00067     int percentage = (int) floor(m_progress/m_maxProgress*100);
00068     if (percentage > 100) percentage = 100;
00069     std::cerr << msg << ": " << percentage << "%" << std::endl;
00070     if (!Update(percentage, m_message)) {
00071         return false;
00072     }
00073     return true;
00074 }
00075 
00076 // TODO entire ProgressReporter and ProgressDisplay API needs be updated to use wstring.
00077 // Temporarily implemented only for this function. from here -->
00078 bool ProgressReporterDialog::increaseProgress(double i, const std::wstring & msg)
00079 {
00080     if (m_abort) return false;
00081     
00082     m_progress += i;
00083     m_message = wxString(msg.c_str());
00084     // build the message:
00085     int percentage = (int) floor(m_progress/m_maxProgress*100);
00086     if (percentage > 100) percentage = 100;
00087     std::cerr << m_message << ": " << percentage << "%" << std::endl;
00088     if (!Update(percentage, m_message)) {
00089         return false;
00090     }
00091     return true;
00092 }
00093 // <- to here
00094 
00095 void ProgressReporterDialog::setMessage(const std::string & msg)
00096 {
00097     m_message = wxString(msg.c_str(), wxConvLocal);
00098     int percentage = (int) floor(m_progress/m_maxProgress*100);
00099     if (percentage > 100) percentage = 100;
00100     std::cerr << m_message.c_str() << ": " << percentage << "%" << std::endl;
00101     if (!Update(percentage, m_message)) {
00102         m_abort = true;
00103     }
00104 }
00105 
00106 void MyProgressDialog::updateProgressDisplay()
00107 {
00108     wxString msg;
00109     // build the message:
00110     for (std::vector<AppBase::ProgressTask>::iterator it = tasks.begin();
00111          it != tasks.end(); ++it)
00112     {
00113         wxString cMsg;
00114         if (it->getProgress() > 0) {
00115             cMsg.Printf(wxT("%s: %s [%3.0f%%]\n"),
00116                         wxString(it->getShortMessage().c_str(), wxConvLocal).c_str(),
00117                         wxString(it->getMessage().c_str(), wxConvLocal).c_str(),
00118                         100 * it->getProgress());
00119         } else {
00120             cMsg.Printf(wxT("%s %s\n"),
00121                         wxString(it->getShortMessage().c_str(), wxConvLocal).c_str(),
00122                         wxString(it->getMessage().c_str(), wxConvLocal).c_str());
00123         }
00124         // append to main message
00125         msg.Append(cMsg);
00126     }
00127     int percentage = 0;
00128     if (tasks.size() > 0 && tasks.front().measureProgress) {
00129         percentage = (int) (tasks.front().getProgress() * 100.0);
00130     }
00131     if (!Update(percentage, msg)) {
00132         abortOperation();
00133     }
00134 
00135     // finally redraw
00136         Layout();
00137 }
00138 
00139 void OptProgressDialog::abortOperation()
00140 {
00141 #if PT_CUSTOM_OPT
00142     PTools::stopOptimiser();
00143 #endif
00144 }
00145 
00146 

Generated on Wed Apr 16 01:25:30 2014 for Hugintrunk by  doxygen 1.3.9.1