#include <SALOME_LifeCycleCORBA.hxx>
#include <SALOMEDS_Study.hxx>
+#include <SALOME_Event.hxx>
+
#include <QtxPopupMgr.h>
// QT Includes
#include <qpixmap.h>
#include <qmessagebox.h>
#include <qaction.h>
-
+#include <qtimer.h>
+#include <qthread.h>
#include <stdexcept>
// 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
// 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()));
}
//-------------------------------------------------------------------------
// 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;
}
}
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(...)
{
"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()
// 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";
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;
// 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;
// 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)
{
// 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!
// 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 = "";
// 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!
void MULTIPR_GUI_DataModel::build()
{
- cout << endl << " *** !!! MULTIPR_GUI_DataModel::build()" << endl << endl;
}
void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)