Salome HOME
Rename Engines::Component to Engines::EngineComponent
[modules/multipr.git] / src / MULTIPRGUI / MULTIPR_GUI.cxx
index d635228860c26ec03a3cff6ceb8321ff5087c1b7..67fd1cacf8a31571397921948683618fea3a88ed 100644 (file)
@@ -1,4 +1,21 @@
-// Project MULTIPR, IOLS WP1.2.1 - EDF/CS
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
 // Partitioning/decimation module for the SALOME v3.2 platform
 
 /**
  * \brief   see MULTIPR_GUI.h
  *
  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
- * 
+ *
  * \date    01/2007
  */
-  
+
 //*****************************************************************************
 // Includes section
 //*****************************************************************************
@@ -97,7 +114,7 @@ public:
     if (myIsError) {
       SUIT_MessageBox::critical((QWidget*) MULTIPR_GUI::desktop(),
                             QObject::tr("SAVE_DISTMED_ERROR"),
-//                           QString("Save distributed MED file error"), 
+//                           QString("Save distributed MED file error"),
                               QObject::tr("WRIT_DISTMED_ERROR"));
 //                            QString("Error while writing distributed MED file"));
     }
@@ -155,7 +172,7 @@ MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen (SalomeApp_Application* app)
     if (!aGen)
     {
         SALOME_LifeCycleCORBA aLCC (SalomeApp_Application::namingService());
-        Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","MULTIPR" );
+        Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","MULTIPR" );
         aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(comp);
         if (!CORBA::is_nil(aGen))
         {
@@ -221,79 +238,79 @@ SalomeApp_Application* MULTIPR_GUI::getAppli() const
 void MULTIPR_GUI::initialize(CAM_Application* app)
 {
     SalomeApp_Module::initialize(app);
-    
+
     GetMultiprGen(dynamic_cast<SalomeApp_Application*>( app ));
-    
+
     QWidget* aParent = (QWidget*) application()->desktop();
     SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
-    
+
     //-------------------------------------------------------------------------
     // create actions
-    //-------------------------------------------------------------------------    
+    //-------------------------------------------------------------------------
     QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_IMPORT_MED"));
-    
-    createAction( 
-        ACTION_IMPORT_MED, 
-        tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"), 
-        QIcon(aPixmapImportFromMEDFile), 
-        tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"), 
-        tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"), 
+
+    createAction(
+        ACTION_IMPORT_MED,
+        tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"),
+        QIcon(aPixmapImportFromMEDFile),
+        tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"),
+        tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"),
         (Qt::CTRL + Qt::Key_I),
-        aParent, 
+        aParent,
         false,
-        this, 
+        this,
         SLOT(OnImportFromMEDFile()));
-        
-    createAction( 
-        ACTION_SPLIT, 
-        tr("MULTIPR_TLT_SPLIT"), 
-        QIcon(), 
-        tr("MULTIPR_MEN_SPLIT"), 
-        tr("MULTIPR_STS_SPLIT"), 
+
+    createAction(
+        ACTION_SPLIT,
+        tr("MULTIPR_TLT_SPLIT"),
+        QIcon(),
+        tr("MULTIPR_MEN_SPLIT"),
+        tr("MULTIPR_STS_SPLIT"),
         0,
-        aParent, 
+        aParent,
         false,
-        this, 
+        this,
         SLOT(OnPartition2()));
-    
-    createAction( 
-        ACTION_DECIMATE, 
-        tr("MULTIPR_TLT_DECIMATE"), 
-        QIcon(), 
-        tr("MULTIPR_MEN_DECIMATE"), 
-        tr("MULTIPR_STS_DECIMATE"), 
+
+    createAction(
+        ACTION_DECIMATE,
+        tr("MULTIPR_TLT_DECIMATE"),
+        QIcon(),
+        tr("MULTIPR_MEN_DECIMATE"),
+        tr("MULTIPR_STS_DECIMATE"),
         0,
-        aParent, 
+        aParent,
         false,
-        this, 
+        this,
         SLOT(OnDecimate()));
-    
-    createAction( 
-        ACTION_REMOVE, 
-        tr("MULTIPR_TLT_REMOVE"), 
-        QIcon(), 
-        tr("MULTIPR_MEN_REMOVE"), 
-        tr("MULTIPR_STS_REMOVE"), 
+
+    createAction(
+        ACTION_REMOVE,
+        tr("MULTIPR_TLT_REMOVE"),
+        QIcon(),
+        tr("MULTIPR_MEN_REMOVE"),
+        tr("MULTIPR_STS_REMOVE"),
         0,
-        aParent, 
+        aParent,
         false,
-        this, 
+        this,
         SLOT(OnRemove()));
-        
+
     QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_SAVE_MED"));
-    
-    createAction( 
-        ACTION_SAVE, 
-        tr("MULTIPR_TLT_SAVE"), 
-        QIcon(aPixmapSaveMEDFile), 
-        tr("MULTIPR_MEN_SAVE"), 
-        tr("MULTIPR_STS_SAVE"), 
+
+    createAction(
+        ACTION_SAVE,
+        tr("MULTIPR_TLT_SAVE"),
+        QIcon(aPixmapSaveMEDFile),
+        tr("MULTIPR_MEN_SAVE"),
+        tr("MULTIPR_STS_SAVE"),
         0,
-        aParent, 
+        aParent,
         false,
-        this, 
+        this,
         SLOT(OnSave()));
-    
+
     //-------------------------------------------------------------------------
     // create menus
     //-------------------------------------------------------------------------
@@ -302,21 +319,21 @@ void MULTIPR_GUI::initialize(CAM_Application* app)
     createMenu(separator(), aMenuId, -1, 10);
     aMenuId = createMenu(tr("MULTIPR_MEN_FILE_MULTIPR"), aMenuId, -1, 10);
     createMenu(ACTION_IMPORT_MED, aMenuId);
-    
+
     aMenuId = createMenu(tr("MULTIPR_MEN_MULTIPR"), -1, -1, 30);
     createMenu(ACTION_IMPORT_MED, aMenuId, 10);
     createMenu(ACTION_SAVE, aMenuId, 10);
     createMenu(ACTION_SPLIT, aMenuId, 10);
     createMenu(ACTION_DECIMATE, aMenuId, 10);
     createMenu(ACTION_REMOVE, aMenuId, 10);
-    
+
     //-------------------------------------------------------------------------
     // create toolbars
     //-------------------------------------------------------------------------
     int aToolId = createTool(tr("MULTIPR_TOOL_MULTIPR"));
     createTool(ACTION_IMPORT_MED, aToolId);
     createTool(ACTION_SAVE, aToolId);
-    
+
     //-------------------------------------------------------------------------
     // create popup menus
     //-------------------------------------------------------------------------
@@ -325,20 +342,20 @@ void MULTIPR_GUI::initialize(CAM_Application* app)
     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);
     mgr->setRule(action(ACTION_DECIMATE), aRule);
     mgr->setRule(action(ACTION_REMOVE), aRule);
     mgr->setRule(action(ACTION_SAVE), aRule);
-    
+
     //-------------------------------------------------------------------------
     // set progress dialog
     //-------------------------------------------------------------------------
     //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;
@@ -419,21 +436,21 @@ void MULTIPR_GUI::windows(QMap<int, int>& theMap) const
 void MULTIPR_GUI::selected(QStringList& entries, const bool multiple)
 {
     LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
-    
+
     if(!mgr) return;
-    
+
     SUIT_DataOwnerPtrList anOwnersList;
     mgr->selected(anOwnersList);
-    
+
     for (int i = 0 ; i < anOwnersList.size() ; i++)
     {
         const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(anOwnersList[i].get());
-        
+
         if (!entries.contains(owner->entry()))
         {
             entries.append(owner->entry());
         }
-            
+
         if (!multiple)
             break;
     }
@@ -446,12 +463,12 @@ void MULTIPR_GUI::OnImportFromMEDFile()
     QStringList aFilter;
     aFilter.append(tr("MULTIPR_FLT_MED_FILES"));
     aFilter.append(tr("MULTIPR_FLT_ALL_FILES"));
-    
+
     SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
-        (QWidget*) MULTIPR_GUI::desktop(), 
-        true, 
+        (QWidget*) MULTIPR_GUI::desktop(),
+        true,
         tr("") );
-        
+
     fd->setWindowTitle(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"));
     fd->setFilters(aFilter);
     if (fd->exec() == QDialog::Rejected)
@@ -459,10 +476,10 @@ void MULTIPR_GUI::OnImportFromMEDFile()
         delete fd;
         return;
     }
-    
+
     QFileInfo aFileInfo(fd->selectedFile());
     delete fd;
-    
+
     // Check the file name
     if (!aFileInfo.exists())
         return;
@@ -486,15 +503,15 @@ void MULTIPR_GUI::OnImportFromMEDFile()
     }
     catch(...)
     {
-        SUIT_MessageBox::critical( 
+        SUIT_MessageBox::critical(
             (QWidget*) MULTIPR_GUI::desktop(),
-            QObject::tr("IMPORT_MED_ERROR"), 
-//            "Import MED file error", 
+            QObject::tr("IMPORT_MED_ERROR"),
+//            "Import MED file error",
             QObject::tr("INVALID_MED_FILE"));
-//          "Invalid MED file (not recognized by MULTIPR)"); 
+//          "Invalid MED file (not recognized by MULTIPR)");
     }
     QApplication::restoreOverrideCursor();
-    
+
     //if (mMULTIPRObj != NULL)
     if (!CORBA::is_nil(mMULTIPRObj))
     {
@@ -529,21 +546,21 @@ void MULTIPR_GUI::OnPartition1()
     {
         return;
     }
-    // do the partition.   
+
+    // do the partition.
     MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this);
     dialog->exec();
     delete dialog;
 
     // Now we need to save the file.
     SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
-        (QWidget*) MULTIPR_GUI::desktop(), 
-        true, 
+        (QWidget*) MULTIPR_GUI::desktop(),
+        true,
         tr("") );
-        
+
     fd->setWindowTitle(tr("Save distributed MED file - Destination directory"));
     fd->setFileMode(QFileDialog::DirectoryOnly);
-    
+
     if (fd->exec() == QDialog::Rejected)
     {
         delete fd;
@@ -551,18 +568,18 @@ void MULTIPR_GUI::OnPartition1()
         getApp()->updateObjectBrowser();
         return;
     }
-    
+
     QFileInfo aFileInfo(fd->selectedFile());
     delete fd;
-        
+
     QString path = aFileInfo.filePath();
-    
+
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     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);
@@ -573,7 +590,7 @@ void MULTIPR_GUI::OnPartition1()
     //mTimer->start(500); // 0.5 seconds timer
     //QApplication::restoreOverrideCursor();
     //getApp()->updateObjectBrowser();
-    
+
 }
 
 
@@ -585,25 +602,23 @@ void MULTIPR_GUI::OnPartition2()
     {
         return;
     }
-    
+
     retrieveSelectedParts();
-    
+
     if (mSelectedParts.count() == 0)
     {
-        SUIT_MessageBox::warning( 
+        SUIT_MessageBox::warning(
             (QWidget*) MULTIPR_GUI::desktop(),
-            QObject::tr("SPLIT_WARN"), 
-//            "Split warning", 
-            QObject::tr("NO_PART_SELECTED")); 
-//            "No parts selected");
+            QString("Split warning"),
+            QString("No parts selected"));
         return;
     }
-    
+
     if (!removeLowerResolution())
     {
         return;
     }
-    
+
     MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
     dialog->exec();
     delete dialog;
@@ -620,17 +635,15 @@ void MULTIPR_GUI::OnDecimate()
     {
         return;
     }
-    
+
     retrieveSelectedParts();
-    
+
     if (mSelectedParts.count() == 0)
     {
-        SUIT_MessageBox::warning( 
+        SUIT_MessageBox::warning(
             (QWidget*) MULTIPR_GUI::desktop(),
-            QObject::tr("DECIMATION_WARN"), 
-//           "Decimation warning", 
-            QObject::tr("NO_PART_SELECTED")); 
-//            "No parts selected"); 
+            QString("Decimation warning"),
+            QString("No parts selected"));
         return;
     }
 
@@ -644,10 +657,10 @@ void MULTIPR_GUI::OnDecimate()
     MULTIPR_ORB::string_array* listFields = this->getMULTIPRObj()->getFields(allParts.toLatin1());
     if (listFields->length() == 0)
     {
-      SUIT_MessageBox::critical( 
+      SUIT_MessageBox::critical(
             (QWidget*) MULTIPR_GUI::desktop(),
-            QObject::tr("DECIM_ERROR"), 
-//            "Decimation error", 
+            QObject::tr("DECIM_ERROR"),
+//            "Decimation error",
             QObject::tr("NO_FIELD_ON_PART"));
 //          "No field for this part.",);
       return ;
@@ -669,27 +682,23 @@ void MULTIPR_GUI::OnRemove()
     {
         return;
     }
-    
+
     retrieveSelectedParts();
-    
+
     if (mSelectedParts.count() == 0)
     {
-        SUIT_MessageBox::warning( 
+        SUIT_MessageBox::warning(
             (QWidget*) MULTIPR_GUI::desktop(),
-            QObject::tr("DEL_WARN"), 
-//            "Remove warning", 
-            QObject::tr("NO_PART_SELECTED"));
-//           "No parts selected"); 
+            QString("Remove warning"),
+            QString("No parts selected"));
         return;
     }
-    
+
     if (QMessageBox::question(
             (QWidget*) MULTIPR_GUI::desktop(),
-            QObject::tr("DEL_SELECTED_PARTS"),
-//            QObject::tr("Remove selected part(s)"),
-            QObject::tr("DEL_SELECTED_PARTS_QUEST"),
-//           QObject::tr("Do you want to remove selected part(s)?"),
-            QObject::tr("&Yes"), tr("&No"),
+            QString("Remove selected part(s)"),
+            QString("Do you want to remove selected part(s)?"),
+            QString("&Yes"), QString("&No"),
             QString::null, 0, 1 ) )
     {
         return;
@@ -709,12 +718,10 @@ void MULTIPR_GUI::OnRemove()
     }
     catch(...)
     {
-        SUIT_MessageBox::critical( 
+        SUIT_MessageBox::critical(
             (QWidget*) MULTIPR_GUI::desktop(),
-            QObject::tr("DEL_ERROR"), 
-//            "Remove error", 
-            QObject::tr("ERROR_DEL_PART"));
-//            "Error while removing selected part(s)"); 
+            QString("Remove error"),
+            QString("Error while removing selected part(s)"));
     }
 
     QApplication::restoreOverrideCursor();
@@ -804,12 +811,12 @@ bool MULTIPR_GUI::isPartExist(const char* partName)
 {
   //if (mMULTIPRObj == NULL) return false;
     if (CORBA::is_nil(mMULTIPRObj)) 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) 
+        if (strcmp(strItem, partName) == 0)
         {
             return true;
         }
@@ -831,20 +838,20 @@ bool MULTIPR_GUI::removeLowerResolution()
         QString partNameMed = partName + "_MED";
         const char* strPartNameLow = partNameLow.toLatin1();
         const char* strPartNameMed = partNameMed.toLatin1();
-        
+
         if (isPartExist(strPartNameLow))
         {
             partNameLowerResolution.push_back(partNameLow);
             cout << "Part to be removed: " << strPartNameLow << endl;
         }
-        
+
         if (isPartExist(strPartNameMed))
         {
             partNameLowerResolution.push_back(partNameMed);
             cout << "Part to be removed: " << strPartNameMed << endl;
         }
     }
-     
+
     if (partNameLowerResolution.count() > 0)
     {
         if (QMessageBox::question(
@@ -858,9 +865,9 @@ bool MULTIPR_GUI::removeLowerResolution()
         {
             return false;
         }
-    
+
         QApplication::setOverrideCursor(Qt::WaitCursor);
-        
+
         try
         {
             for (QStringList::const_iterator it = partNameLowerResolution.begin(),
@@ -870,24 +877,23 @@ bool MULTIPR_GUI::removeLowerResolution()
                 cout << "Remove " << (const char*)partName.toLatin1() << endl;
                 mMULTIPRObj->removeParts(partName.toLatin1());
             }
-            
         }
         catch(...)
         {
-            SUIT_MessageBox::critical( 
+            SUIT_MessageBox::critical(
                 (QWidget*) MULTIPR_GUI::desktop(),
                 QObject::tr("DEL_ERROR"),
-//                "Remove error", 
-                QObject::tr("ERROR_DEL_PREV_RESULT")); 
-//                "Error while removing previous results", 
+//                "Remove error",
+                QObject::tr("ERROR_DEL_PREV_RESULT"));
+//                "Error while removing previous results",
         }
-        
+
         QApplication::restoreOverrideCursor();
-        
+
         getApp()->updateObjectBrowser();
         getApp()->updateActions();
     }
-    
+
     return true;
 }
 
@@ -935,7 +941,7 @@ QPixmap MULTIPR_GUI_DataObject::icon() const
 {
     //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false);
     return QPixmap();
-    
+
 }
 
 
@@ -1044,26 +1050,26 @@ MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part (SUIT_DataObject* paren
     mId          = 0;
     mPath        = "";
     mMEDFileName = "";
-    
+
     mTooltip = info;
-    
+
     // parse info to retrieve all the fields
     char   lMeshName[256];
     int    lId;
     char   lPartName[256];
     char   lPath[256];
     char   lMEDFileName[256];
-    
-    int ret = sscanf(info, "%s %d %s %s %s", 
+
+    int ret = sscanf(info, "%s %d %s %s %s",
                 lMeshName,
                 &lId,
                 lPartName,
                 lPath,
                 lMEDFileName);
-                
+
     // number of read parameters should be 5
     if (ret != 5) return;
-    
+
     mMeshName    = lMeshName;
     mId          = lId;
     mPath        = lPath;
@@ -1195,8 +1201,8 @@ void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)
     if (!aSAStudy) return;
 
     MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
-    if (!modelRoot)  
-    {  
+    if (!modelRoot)
+    {
       // root is not set yet
       modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
       setRoot(modelRoot);
@@ -1280,17 +1286,17 @@ void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)
         int    lId;
         char   lPartName[256];
         char   lPath[256];
-        char   lMEDFileName[256];    
+        char   lMEDFileName[256];
 
         // parse infos
-        int ret = sscanf(strPartInfo0, "%s %d %s %s %s", 
+        int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
                          lMeshName,
                          &lId,
                          lPartName,
                          lPath,
                          lMEDFileName);
 
-        if (ret != 5) 
+        if (ret != 5)
         {
           cout << "MULTIPR: build() tree; error while parsing part info" << endl;
           std::runtime_error("MULTIPR: build() tree; error while parsing part info");
@@ -1309,7 +1315,7 @@ void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)
           char* strPartInfo = obj->getPartInfo(strItem);
 
           // parse infos
-          int ret = sscanf(strPartInfo, "%s %d %s %s %s", 
+          int ret = sscanf(strPartInfo, "%s %d %s %s %s",
                            lMeshName,
                            &lId,
                            lPartName,
@@ -1336,7 +1342,7 @@ void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)
 }
 
 
-extern "C" 
+extern "C"
 {
     CAM_Module* createModule()
     {