From: jfa Date: Mon, 23 Jul 2007 06:03:24 +0000 (+0000) Subject: Implement saving progress bar corresponding to Client-Server architecture. X-Git-Tag: T_MULTIPR_INDUS_2007-07-23~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3effc70f3822405efecd9478d33d5bce4faa7102;p=modules%2Fmultipr.git Implement saving progress bar corresponding to Client-Server architecture. --- diff --git a/idl/MULTIPR.idl b/idl/MULTIPR.idl index c4d9511..ba9828d 100644 --- a/idl/MULTIPR.idl +++ b/idl/MULTIPR.idl @@ -187,6 +187,17 @@ interface MULTIPR_Obj : SALOME::GenericObj */ void save(in string path) raises (SALOME::SALOME_Exception); + + /*! + * Check save progress. + * \return current save progress in percents. + */ + long getSaveProgress(); + + /*! + * Reset save progress to zero. + */ + void resetSaveProgress(); }; // interface MULTIPR_Obj diff --git a/src/MULTIPR/MULTIPR_i.cxx b/src/MULTIPR/MULTIPR_i.cxx index cfc9ddb..442fb71 100644 --- a/src/MULTIPR/MULTIPR_i.cxx +++ b/src/MULTIPR/MULTIPR_i.cxx @@ -767,6 +767,15 @@ void MULTIPR_Obj_i::save(const char* pPath) MULTIPR::TPythonDump(_engine) << this << ".save(\"" << pPath << "\")"; } +CORBA::Long MULTIPR_Obj_i::getSaveProgress() +{ + return mObj->getProgress(); +} + +void MULTIPR_Obj_i::resetSaveProgress() +{ + mObj->resetProgress(); +} //----------------------------------------------------------------------------- // savePersistent and setEngine (for Persistence & Dump Python) diff --git a/src/MULTIPR/MULTIPR_i.hxx b/src/MULTIPR/MULTIPR_i.hxx index fc3ff82..e0b7e3a 100644 --- a/src/MULTIPR/MULTIPR_i.hxx +++ b/src/MULTIPR/MULTIPR_i.hxx @@ -259,6 +259,17 @@ public: void save(const char* pPath) throw (SALOME::SALOME_Exception); + /** + * Check save progress. + * \return current save progress in percents. + */ + CORBA::Long getSaveProgress(); + + /** + * Reset save progress to zero. + */ + void resetSaveProgress(); + //--------------------------------------------------------------------- // Persistence and Dump Python //--------------------------------------------------------------------- diff --git a/src/MULTIPRGUI/MULTIPR_GUI.cxx b/src/MULTIPRGUI/MULTIPR_GUI.cxx index b5bb286..56755cd 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI.cxx @@ -41,6 +41,8 @@ #include #include +#include + #include // QT Includes @@ -62,7 +64,8 @@ #include #include #include - +#include +#include #include @@ -73,13 +76,70 @@ using namespace std; // Global variable //***************************************************************************** -namespace multipr +//namespace multipr +//{ +// // progress callback used by the MULTIPR library +// extern MULTIPR_ProgressCallback* gProgressCallback; +// extern MULTIPR_EmptyMeshCallback* gEmptyMeshCallback; +//} +class MULTIPR_GUI_FinishSaveEvent: public SALOME_Event { - // progress callback used by the MULTIPR library - extern MULTIPR_ProgressCallback* gProgressCallback; - extern MULTIPR_EmptyMeshCallback* gEmptyMeshCallback; -} + SalomeApp_Application* myApp; + bool myIsError; +public: + MULTIPR_GUI_FinishSaveEvent (SalomeApp_Application* theApp, + bool theIsError) + : myApp(theApp), + myIsError(theIsError) + {} + virtual void Execute() + { + if (myIsError) { + SUIT_MessageBox::error1(myApp->desktop(), + "Save distributed MED file error", + "Error while writing distributed MED file", + myApp->tr("MULTIPR_BUT_OK")); + } + else { + myApp->updateObjectBrowser(); + } + QApplication::restoreOverrideCursor(); + } +}; + +class MULTIPR_GUI_SaveThread : public QThread +{ +public: + MULTIPR_GUI_SaveThread (MULTIPR_GUI* pModule, + MULTIPR_ORB::MULTIPR_Obj_ptr pObj, + QString pPath) + : mModule(pModule) + { + mObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(pObj); + mPath = pPath; + } + virtual void run(); +private: + MULTIPR_GUI* mModule; + MULTIPR_ORB::MULTIPR_Obj_ptr mObj; + QString mPath; +}; + +void MULTIPR_GUI_SaveThread::run() +{ + try + { + mObj->save(mPath); + } + catch(...) + { + ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), true)); + return; + } + + ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), false)); +} //***************************************************************************** // Global function @@ -119,10 +179,14 @@ MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen (const CAM_Module* theModule) // Class MULTIPR_GUI implementation //***************************************************************************** -MULTIPR_GUI::MULTIPR_GUI() : SalomeApp_Module("MULTIPR") +MULTIPR_GUI::MULTIPR_GUI() + : SalomeApp_Module("MULTIPR"), + mMULTIPRObj(NULL), + mMEDFileName(""), + mProgress(NULL) { - mMEDFileName = ""; - mMULTIPRObj = NULL; + mTimer = new QTimer (this); + connect(mTimer, SIGNAL(timeout()), this, SLOT(timerDone())); } @@ -269,11 +333,13 @@ void MULTIPR_GUI::initialize(CAM_Application* app) //------------------------------------------------------------------------- // set progress dialog //------------------------------------------------------------------------- - MULTIPR_GUI_ProgressCallbackDlg* progressDlg = new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop()); - multipr::gProgressCallback = progressDlg; + //MULTIPR_GUI_ProgressCallbackDlg* progressDlg = + // new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop()); + //multipr::gProgressCallback = progressDlg; - MULTIPR_GUI_EmptyMeshCallbackDlg* emptyMeshDlg = new MULTIPR_GUI_EmptyMeshCallbackDlg(application()->desktop()); - multipr::gEmptyMeshCallback = emptyMeshDlg; + //MULTIPR_GUI_EmptyMeshCallbackDlg* emptyMeshDlg = + // new MULTIPR_GUI_EmptyMeshCallbackDlg(application()->desktop()); + //multipr::gEmptyMeshCallback = emptyMeshDlg; } @@ -527,16 +593,16 @@ void MULTIPR_GUI::OnRemove() } QApplication::setOverrideCursor(Qt::waitCursor); - + try { - for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++) - { - const QString& partName = (*it); - cout << "Remove " << partName.latin1() << endl; - mMULTIPRObj->removeParts(partName.latin1()); - } - + QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); + for (; it != last; it++) + { + const QString& partName = (*it); + cout << "Remove " << partName.latin1() << endl; + mMULTIPRObj->removeParts(partName.latin1()); + } } catch(...) { @@ -546,59 +612,67 @@ void MULTIPR_GUI::OnRemove() "Error while removing selected part(s)", tr("MULTIPR_BUT_OK") ); } - + QApplication::restoreOverrideCursor(); - + getApp()->updateObjectBrowser(); } void MULTIPR_GUI::OnSave() { - // check if MULTIPRObj exists - if (mMULTIPRObj == NULL) - { - return; - } - - SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( - this->application()->desktop(), - true, - tr("") ); - - fd->setCaption(tr("Save distributed MED file - Destination directory")); - fd->setMode(QFileDialog::DirectoryOnly); - - if (fd->exec() == QDialog::Rejected) - { - delete fd; - return; - } - - QFileInfo aFileInfo(fd->selectedFile()); + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + + SalomeApp_CheckFileDlg* fd = + new SalomeApp_CheckFileDlg(this->application()->desktop(), + true, + tr("")); + + fd->setCaption(tr("Save distributed MED file - Destination directory")); + fd->setMode(QFileDialog::DirectoryOnly); + + if (fd->exec() == QDialog::Rejected) + { delete fd; - - QString path = aFileInfo.filePath(); - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - mMULTIPRObj->save(path); - getApp()->updateObjectBrowser(); - } - catch(...) - { - SUIT_MessageBox::error1( - getApp()->desktop(), - "Save distributed MED file error", - "Error while writing distributed MED file", - tr("MULTIPR_BUT_OK") ); - } - - QApplication::restoreOverrideCursor(); + return; + } + + QFileInfo aFileInfo(fd->selectedFile()); + delete fd; + + QApplication::setOverrideCursor(Qt::waitCursor); + + QString path = aFileInfo.filePath(); + mMULTIPRObj->resetSaveProgress(); + + MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path); + a->start(); + + // save progress + //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop()); + //mProgress->start("Save mesh", 100); + if (mProgress == NULL) + mProgress = new QProgressDialog ("Save mesh", "Cancel", /*totalSteps*/100, getApp()->desktop()); + //mProgress->setProgress(0); + //mProgress->init(100); + mTimer->start(500); // 0.5 seconds timer } +void MULTIPR_GUI::timerDone() +{ + int progress = mMULTIPRObj->getSaveProgress(); + if (mProgress != NULL) { + mProgress->setProgress(progress); + + if (progress >= 100) { + mTimer->stop(); + } + } +} void MULTIPR_GUI::retrieveSelectedParts() @@ -644,7 +718,8 @@ bool MULTIPR_GUI::removeLowerResolution() // for each selected part, check if there are lower resolution // and then propose to remove them before performing new process QStringList partNameLowerResolution; - for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++) + for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); + it != last; it++) { const QString& partName = (*it); QString partNameLow = partName + "_LOW"; @@ -681,7 +756,8 @@ bool MULTIPR_GUI::removeLowerResolution() try { - for (QStringList::const_iterator it = partNameLowerResolution.begin(), last = partNameLowerResolution.end(); it != last; it++) + for (QStringList::const_iterator it = partNameLowerResolution.begin(), + last = partNameLowerResolution.end(); it != last; it++) { const QString& partName = (*it); cout << "Remove " << partName.latin1() << endl; @@ -711,8 +787,8 @@ bool MULTIPR_GUI::removeLowerResolution() // Super class Data Object implementation //***************************************************************************** -MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject(SUIT_DataObject* parent, const char* name) : - LightApp_DataObject(parent), +MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject (SUIT_DataObject* parent, const char* name) + : LightApp_DataObject(parent), CAM_DataObject(parent) { mName = name; @@ -756,8 +832,10 @@ QString MULTIPR_GUI_DataObject::toolTip() const // Class Data Object Module implementation //***************************************************************************** -MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module(CAM_DataModel* dm, SUIT_DataObject* parent, const char* name) : - MULTIPR_GUI_DataObject(parent, name), +MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module (CAM_DataModel* dm, + SUIT_DataObject* parent, + const char* name) + : MULTIPR_GUI_DataObject(parent, name), LightApp_ModuleObject(dm, parent), CAM_DataObject(parent) { @@ -799,8 +877,8 @@ QString MULTIPR_GUI_DataObject_Module::toolTip() const // Class Data Object Mesh implementation //***************************************************************************** -MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh(SUIT_DataObject* parent, const char* name) : - MULTIPR_GUI_DataObject(parent, name), +MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh (SUIT_DataObject* parent, const char* name) + : MULTIPR_GUI_DataObject(parent, name), CAM_DataObject(parent) { // do nothing! @@ -835,8 +913,9 @@ QString MULTIPR_GUI_DataObject_Mesh::toolTip() const // Class Data Object Part implementation //***************************************************************************** -MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part(SUIT_DataObject* parent, const char* name, const char* info) : - MULTIPR_GUI_DataObject(parent, name), +MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part (SUIT_DataObject* parent, + const char* name, const char* info) + : MULTIPR_GUI_DataObject(parent, name), CAM_DataObject(parent) { mMeshName = ""; @@ -898,8 +977,9 @@ QString MULTIPR_GUI_DataObject_Part::toolTip() const // Class Data Object Resolution implementation //***************************************************************************** -MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution(SUIT_DataObject* parent, const char* name, const char* info) : - MULTIPR_GUI_DataObject_Part(parent, name, info), +MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution (SUIT_DataObject* parent, + const char* name, const char* info) + : MULTIPR_GUI_DataObject_Part(parent, name, info), CAM_DataObject(parent) { // do nothing! @@ -977,7 +1057,6 @@ void MULTIPR_GUI_DataModel::update (LightApp_DataObject*, LightApp_Study* theStu void MULTIPR_GUI_DataModel::build() { - cout << endl << " *** !!! MULTIPR_GUI_DataModel::build()" << endl << endl; } void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy) diff --git a/src/MULTIPRGUI/MULTIPR_GUI.h b/src/MULTIPRGUI/MULTIPR_GUI.h index e3ff9b6..6bcaeaf 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.h +++ b/src/MULTIPRGUI/MULTIPR_GUI.h @@ -48,6 +48,9 @@ class QLineEdit; class QSpinBox; class QPushButton; +class QTimer; +//class MULTIPR_GUI_ProgressCallbackDlg; +class QProgressDialog; //***************************************************************************** // Class MULTIPR_GUI @@ -92,6 +95,8 @@ protected slots: void OnDecimate(); void OnRemove(); void OnSave(); + + void timerDone(); // update saving progress dialog protected: @@ -117,7 +122,11 @@ private: QString mMEDFileName; QStringList mSelectedParts; MULTIPR_ORB::MULTIPR_Obj_ptr mMULTIPRObj; - + + QProgressDialog* mProgress; + //MULTIPR_GUI_ProgressCallbackDlg* mProgress; + QTimer* mTimer; + }; // class MULTIPR_GUI @@ -250,4 +259,3 @@ private: // EOF - diff --git a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx index 9dd4187..68921c1 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx @@ -618,12 +618,11 @@ void MULTIPR_GUI_DecimateDlg::OnThresholdAuto() // QT dialog box used to display progress in time consuming task (e.g. save) //***************************************************************************** -MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) : - QProgressDialog( - parent, - 0, - false, - WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) + : QProgressDialog(parent, + 0, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) { setLabel(new QLabel(this, "Please wait")); setLabelText("Please wait"); @@ -649,7 +648,7 @@ void MULTIPR_GUI_ProgressCallbackDlg::done() setProgress(100); } - + void MULTIPR_GUI_ProgressCallbackDlg::progress(float pPercent) { setProgress(int(pPercent));