Salome HOME
*** empty log message ***
[modules/multipr.git] / src / MULTIPRGUI / MULTIPR_GUI.cxx
index a9d83b0ac218a6001e13287557b234bce5b75232..d54fa0cedaa7d32ac2f0bdc62b075981a364abaf 100644 (file)
@@ -18,6 +18,7 @@
 // MULTIPR Includes
 #include "MULTIPR_GUI.h"
 #include "MULTIPR_GUI_Dlg.h"
+#include "MULTIPR_Utils.hxx"
 
 // Salome Includes
 #include <SUIT_MessageBox.h>
 #include <qimage.h>
 #include <qpixmap.h>
 #include <qmessagebox.h>
+#include <qaction.h>
 
 
+#include <stdexcept>
+
 using namespace std;
 
 
@@ -72,6 +76,33 @@ namespace multipr
 }
 
 
+//*****************************************************************************
+// Global function
+//*****************************************************************************
+
+// singleton
+MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen(const CAM_Module* theModule)
+{
+       static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL;
+    
+       if (!aGen)
+       {
+               SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
+               Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer", "MULTIPR");
+               aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(aComponent);
+               if (!CORBA::is_nil(aGen))
+               {
+                       //aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
+               }
+       }
+    
+       if (CORBA::is_nil(aGen))
+               throw std::runtime_error("Can't find MULTIPR component");
+    
+       return aGen;
+}
+  
+
 //*****************************************************************************
 // Class MULTIPR_GUI implementation
 //*****************************************************************************
@@ -83,24 +114,24 @@ MULTIPR_GUI::MULTIPR_GUI() : SalomeApp_Module("MULTIPR")
 }
 
 
-MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj()
+MULTIPR_GUI::~MULTIPR_GUI()
 {
-       return mMULTIPRObj;
+       if (mMULTIPRObj != NULL)
+       {
+               CORBA::release(mMULTIPRObj);
+       }
 }
 
 
-SalomeApp_Application* MULTIPR_GUI::getAppli() const
+MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj()
 {
-       return getApp();
+       return mMULTIPRObj;
 }
 
 
-MULTIPR_ORB::MULTIPR_Gen_ptr MULTIPR_GUI::InitMULTIPRGen(SalomeApp_Application* app)
+SalomeApp_Application* MULTIPR_GUI::getAppli() const
 {
-       Engines::Component_var comp = app->lcc()->FindOrLoad_Component("FactoryServer", "MULTIPR");
-       MULTIPR_ORB::MULTIPR_Gen_ptr clr = MULTIPR_ORB::MULTIPR_Gen::_narrow(comp);
-       ASSERT(!CORBA::is_nil(clr));
-       return clr;
+       return getApp();
 }
 
 
@@ -108,7 +139,7 @@ void MULTIPR_GUI::initialize(CAM_Application* app)
 {
        SalomeApp_Module::initialize(app);
        
-       InitMULTIPRGen(dynamic_cast<SalomeApp_Application*>(app));
+       GetMultiprGen(this);
        
        QWidget* aParent = app->desktop();
        SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
@@ -234,7 +265,7 @@ CAM_DataModel* MULTIPR_GUI::createDataModel()
 
 QString MULTIPR_GUI::engineIOR() const
 {
-       CORBA::String_var anIOR = getApp()->orb()->object_to_string(InitMULTIPRGen(getApp()));
+       CORBA::String_var anIOR = getApp()->orb()->object_to_string(GetMultiprGen(this));
        return QString(anIOR.in());
 }
 
@@ -246,6 +277,8 @@ bool MULTIPR_GUI::activateModule(SUIT_Study* theStudy)
        setMenuShown(true);
        setToolShown(true);
        
+       action(ACTION_IMPORT_MED)->setAccel(QKeySequence(CTRL + Key_I));
+       
        return bOk;
 }
 
@@ -255,10 +288,13 @@ bool MULTIPR_GUI::deactivateModule(SUIT_Study* theStudy)
        setMenuShown(false);
        setToolShown(false);
        
+       // Unset actions accelerator keys
+       action(ACTION_IMPORT_MED)->setAccel(QKeySequence());
+  
        return SalomeApp_Module::deactivateModule(theStudy);
 }
 
-
+  
 void MULTIPR_GUI::windows(QMap<int, int>& theMap) const
 {
        theMap.clear();
@@ -301,11 +337,16 @@ void MULTIPR_GUI::OnImportFromMEDFile()
        SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
                this->application()->desktop(), 
                true, 
-               tr("MULTIPR_USE_BUILD_PROGRESS") );
+               tr("") );
                
        fd->setCaption(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"));
        fd->setFilters(aFilter);
-       fd->exec();
+       if (fd->exec() == QDialog::Rejected)
+       {
+               delete fd;
+               return;
+       }
+       
        QFileInfo aFileInfo(fd->selectedFile());
        delete fd;
        
@@ -319,7 +360,7 @@ void MULTIPR_GUI::OnImportFromMEDFile()
        
        try
        {
-               MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = MULTIPR_GUI::InitMULTIPRGen(getApp());
+               MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(this);
                mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1());
        }
        catch(...)
@@ -328,7 +369,7 @@ void MULTIPR_GUI::OnImportFromMEDFile()
                        getApp()->desktop(),
                        "Import MED file error", 
                        "Invalid MED file (not recognized by MULTIPR)", 
-                       tr("MULTIPR_OK") );
+                       tr("MULTIPR_BUT_OK") );
        }
        QApplication::restoreOverrideCursor();
        
@@ -380,7 +421,7 @@ void MULTIPR_GUI::OnPartition2()
                        getApp()->desktop(),
                        "Split warning", 
                        "No parts selected", 
-                       tr("MULTIPR_OK") );
+                       tr("MULTIPR_BUT_OK") );
                return;
        }
        
@@ -412,7 +453,7 @@ void MULTIPR_GUI::OnDecimate()
                        getApp()->desktop(),
                        "Decimation warning", 
                        "No parts selected", 
-                       tr("MULTIPR_OK") );
+                       tr("MULTIPR_BUT_OK") );
                return;
        }
        
@@ -444,7 +485,7 @@ void MULTIPR_GUI::OnRemove()
                        getApp()->desktop(),
                        "Remove warning", 
                        "No parts selected", 
-                       tr("MULTIPR_OK") );
+                       tr("MULTIPR_BUT_OK") );
                return;
        }
        
@@ -476,7 +517,7 @@ void MULTIPR_GUI::OnRemove()
                        getApp()->desktop(),
                        "Remove error", 
                        "Error while removing selected part(s)", 
-                       tr("MULTIPR_OK") );
+                       tr("MULTIPR_BUT_OK") );
        }
        
        QApplication::restoreOverrideCursor();
@@ -492,12 +533,31 @@ void MULTIPR_GUI::OnSave()
        {
                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());
+       delete fd;
+               
+       QString path = aFileInfo.filePath();
+       
        QApplication::setOverrideCursor(Qt::waitCursor);
        
        try
        {
-               mMULTIPRObj->save();
+               mMULTIPRObj->save(path);
                getApp()->updateObjectBrowser();
        }
        catch(...)
@@ -506,7 +566,7 @@ void MULTIPR_GUI::OnSave()
                        getApp()->desktop(),
                        "Save distributed MED file error", 
                        "Error while writing distributed MED file", 
-                       tr("MULTIPR_OK") );
+                       tr("MULTIPR_BUT_OK") );
        }
        
        QApplication::restoreOverrideCursor();
@@ -608,7 +668,7 @@ bool MULTIPR_GUI::removeLowerResolution()
                                getApp()->desktop(),
                                "Remove error", 
                                "Error while removing previous results", 
-                               tr("OK") );
+                               tr("MULTIPR_BUT_OK") );
                }
                
                QApplication::restoreOverrideCursor();
@@ -898,7 +958,12 @@ void MULTIPR_GUI_DataModel::build()
                                        lPath,
                                        lMEDFileName);
                                        
-                               if (ret != 5) return;
+                               if (ret != 5) 
+                               {
+                                       cout << "MULTIPR: build() tree; error while parsing part info" << endl;
+                                       std::runtime_error("MULTIPR: build() tree; error while parsing part info");
+                                       return;
+                               }
                                
                                MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName);
                                
@@ -919,10 +984,8 @@ void MULTIPR_GUI_DataModel::build()
                                        
                                        if (ret != 5) return;
                                
-                                       //cout << "Part : " << lPartName << endl;
                                        if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
                                        {
-                                               //cout << "Found MED/LOW" << endl;
                                                new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
                                        }
                                        else