Salome HOME
*** empty log message ***
[modules/multipr.git] / src / MULTIPRGUI / MULTIPR_GUI.cxx
index 650b93082c5629b4333a57e16d29c84cdd292ed4..6ff97df9b17338e99e542c1c3b5a1fb10fcf9815 100644 (file)
@@ -55,6 +55,7 @@
 #include <qwhatsthis.h>
 #include <qimage.h>
 #include <qpixmap.h>
+#include <qmessagebox.h>
 
 
 using namespace std;
@@ -152,6 +153,18 @@ void MULTIPR_GUI::initialize(CAM_Application* app)
                false,
                this, 
                SLOT(OnDecimate()));
+       
+       createAction( 
+               ACTION_REMOVE, 
+               tr("TLT_REMOVE"), 
+               QIconSet(), 
+               tr("MEN_REMOVE"), 
+               tr("STS_REMOVE"), 
+               0,
+               aParent, 
+               false,
+               this, 
+               SLOT(OnRemove()));
                
        QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("ICON_SAVE_MED"));
        
@@ -181,6 +194,7 @@ void MULTIPR_GUI::initialize(CAM_Application* app)
        createMenu(ACTION_SAVE, aMenuId, 10);
        createMenu(ACTION_SPLIT, aMenuId, 10);
        createMenu(ACTION_DECIMATE, aMenuId, 10);
+       createMenu(ACTION_REMOVE, aMenuId, 10);
        
        //-------------------------------------------------------------------------
        // create toolbars
@@ -195,11 +209,13 @@ void MULTIPR_GUI::initialize(CAM_Application* app)
        QtxPopupMgr* mgr = popupMgr();
        mgr->insert( action(ACTION_SPLIT), -1, -1, -1 );
        mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 );
+       mgr->insert( action(ACTION_REMOVE), -1, -1, -1 );
        mgr->insert( action(ACTION_SAVE), -1, -1, -1 );
        
        QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}";
        mgr->setRule(action(ACTION_SPLIT), aRule, true);
        mgr->setRule(action(ACTION_DECIMATE), aRule, true);
+       mgr->setRule(action(ACTION_REMOVE), aRule, true);
        mgr->setRule(action(ACTION_SAVE), aRule, true);
        
        //-------------------------------------------------------------------------
@@ -325,6 +341,8 @@ void MULTIPR_GUI::OnImportFromMEDFile()
        catch (...)
        {
        }
+       
+       getApp()->updateObjectBrowser();
 }
 
 
@@ -371,6 +389,68 @@ void MULTIPR_GUI::OnDecimate()
                return;
        }
        
+       // for each selected part, check if there are lower resolution
+       // and then propose to remove them before processing new decimation
+       QStringList partNameLowerResolution;
+       for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++)
+       {
+               const QString& partName = (*it);
+               QString partNameLow = partName + "_LOW";
+               QString partNameMed = partName + "_MED";
+               const char* strPartNameLow = partNameLow.latin1();
+               const char* strPartNameMed = partNameMed.latin1();
+               
+               if (isPartExist(strPartNameLow))
+               {
+                       partNameLowerResolution.push_back(partNameLow);
+                       cout << "Part to be removed: " << partNameLow << endl;
+               }
+               
+               if (isPartExist(strPartNameMed))
+               {
+                       partNameLowerResolution.push_back(partNameMed);
+                       cout << "Part to be removed: " << partNameMed << endl;
+               }
+       }
+        
+       if (partNameLowerResolution.count() > 0)
+       {
+               if (QMessageBox::question(
+                               getApp()->desktop(),
+                               tr("Decimation: remove previous results"),
+                               tr("Do you want to remove previous results?"),
+                               tr("&Yes"), tr("&No"),
+                               QString::null, 0, 1 ) )
+               {
+                       return;
+               }
+       
+               QApplication::setOverrideCursor(Qt::waitCursor);
+               
+               try
+               {
+                       for (QStringList::const_iterator it = partNameLowerResolution.begin(), last = partNameLowerResolution.end(); it != last; it++)
+                       {
+                               const QString& partName = (*it);
+                               cout << "Remove " << partName.latin1() << endl;
+                               mMULTIPRObj->removePart(partName.latin1());
+                       }
+                       
+               }
+               catch(...)
+               {
+                       SUIT_MessageBox::error1( 
+                               getApp()->desktop(),
+                               "Remove error", 
+                               "Error while removing previous results", 
+                               tr("OK") );
+               }
+               
+               QApplication::restoreOverrideCursor();
+               
+               getApp()->updateObjectBrowser();
+       }
+       
        MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
        dialog->exec();
        delete dialog;
@@ -378,6 +458,57 @@ void MULTIPR_GUI::OnDecimate()
 }
 
 
+void MULTIPR_GUI::OnRemove()
+{
+       retrieveSelectedParts();
+       
+       if (mSelectedParts.count() == 0)
+       {
+               SUIT_MessageBox::warn1( 
+                       getApp()->desktop(),
+                       "Remove warning", 
+                       "No parts selected", 
+                       tr("OK") );
+               return;
+       }
+       
+       if (QMessageBox::question(
+            getApp()->desktop(),
+            tr("Remove selected part(s)"),
+            tr("Do you want to remove selected part(s)?"),
+            tr("&Yes"), tr("&No"),
+            QString::null, 0, 1 ) )
+       {
+               return;
+       }
+
+       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->removePart(partName.latin1());
+               }
+               
+       }
+       catch(...)
+       {
+               SUIT_MessageBox::error1( 
+                       getApp()->desktop(),
+                       "Remove error", 
+                       "Error while removing selected part(s)", 
+                       tr("OK") );
+       }
+       
+       QApplication::restoreOverrideCursor();
+       
+       getApp()->updateObjectBrowser();
+}
+
+
 void MULTIPR_GUI::OnSave()
 {
        QApplication::setOverrideCursor(Qt::waitCursor);
@@ -422,6 +553,23 @@ void MULTIPR_GUI::retrieveSelectedParts()
 }
 
 
+bool MULTIPR_GUI::isPartExist(const char* partName)
+{
+       if (mMULTIPRObj == NULL) return false;
+       
+       MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts();
+       for (int i=0 ; i<listParts->length() ; i++)
+       {
+               const char* strItem = (*listParts)[i];
+               if (strcmp(strItem, partName) == 0) 
+               {
+                       return true;
+               }
+       }
+       return false;
+}
+
+
 //*****************************************************************************
 // Super class Data Object implementation
 //*****************************************************************************