Salome HOME
*** empty log message ***
authorcs <cs>
Sat, 10 Mar 2007 15:29:29 +0000 (15:29 +0000)
committercs <cs>
Sat, 10 Mar 2007 15:29:29 +0000 (15:29 +0000)
13 files changed:
idl/MULTIPR.idl
src/MULTIPR/MULTIPR_MeshDis.cxx
src/MULTIPR/MULTIPR_MeshDis.hxx
src/MULTIPR/MULTIPR_Obj.cxx
src/MULTIPR/MULTIPR_Obj.hxx
src/MULTIPR/MULTIPR_Utils.cxx
src/MULTIPR/MULTIPR_Utils.hxx
src/MULTIPR/MULTIPR_i.cxx
src/MULTIPR/MULTIPR_i.hxx
src/MULTIPRGUI/MULTIPR_GUI.cxx
src/MULTIPRGUI/MULTIPR_GUI.h
src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx
src/MULTIPRGUI/MULTIPR_msg_en.po

index 19510b714bb56ddb13c2f8463711553ee3f855ba..c214a7c4fa5a9895a1b21b8270b4bc891019039c 100644 (file)
@@ -91,11 +91,18 @@ interface MULTIPR_Obj
                raises (SALOME::SALOME_Exception);
 
        /*!
-        * Return all information abour a part.
+        * Return all information about a part.
         * Assume this object encapsulates a distributed MED file.
         */
        string getPartInfo(in string partName)
                raises (SALOME::SALOME_Exception);
+
+       /*!
+        * Remove the given part from the distributed MED file.
+        * Assume this object encapsulates a distributed MED file.
+        */
+       void removePart(in string partName)
+               raises (SALOME::SALOME_Exception);
        
        //---------------------------------------------------------------------
        // Algorithms
index 3a856f3ef4a7571c4df7e2764ed8e3436949b48e..9b93c2d070d24e43a3f6811fce359f8e9219cf5f 100644 (file)
@@ -240,6 +240,10 @@ void MeshDis::insertMesh(
        Mesh*       pMesh,
        int         pPosition)
 {
+       // debug
+       //cout << "INSERT PARTS BEFORE: " << endl;
+       //cout << (*this) << endl;
+       
        MeshDisPart* part = new MeshDisPart();
        
        part->create(
@@ -256,8 +260,50 @@ void MeshDis::insertMesh(
        // rename id of following parts
        for (unsigned i = pPosition + 1 ; i < mParts.size() ; i++)
        {
-               mParts[i]->mId = i + 1;
+               mParts[i]->mId++;
+       }
+       
+       // debug
+       //cout << "INSERT PARTS AFTER: " << endl;
+       //cout << (*this) << endl;
+}
+
+
+void MeshDis::removeParts(const char* pPrefixPartName)
+{
+       // debug
+       //cout << "REMOVE PARTS BEFORE: " << endl;
+       //cout << (*this) << endl;
+       
+       if (pPrefixPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
+       
+       for (vector<MeshDisPart*>::iterator itPart = mParts.begin() ; itPart != mParts.end() ; itPart++)
+       {
+               MeshDisPart* currentPart = (*itPart);
+               
+               if (startWith(currentPart->getPartName(), pPrefixPartName))
+               {
+                       mParts.erase(itPart);
+               
+                       // decrement id of following parts
+                       for (vector<MeshDisPart*>::iterator itPart2 = itPart ; itPart2 != mParts.end() ; itPart2++)
+                       {
+                               (*itPart2)->mId--;
+                       }
+                       
+                       itPart--;
+                       if (currentPart->mMEDFileName != NULL)
+                       {
+                               remove(currentPart->mMEDFileName);
+                       }
+                       
+                       delete currentPart;
+               }
        }
+       
+       // debug
+       //cout << "REMOVE PARTS AFTER: " << endl;
+       //cout << (*this) << endl;
 }
 
 
@@ -513,6 +559,7 @@ void MeshDis::decimatePart(
        const char* originalFilename = part->getMEDFileName();
        string strPrefix = removeExtension(originalFilename, ".med");
        
+cout << (*this) << endl;
        //---------------------------------------------------------------------
        // Decimates the given mesh
        //---------------------------------------------------------------------
@@ -566,6 +613,8 @@ void MeshDis::decimatePart(
                        meshLow,
                        part->mId + 1);
        }
+       
+cout << (*this) << endl;
 }
 
 
index bcfeebc8822fda431b697dd973572fcc0a546d22..f71a066d1e8a43dec134059d4857a6824b372df0 100644 (file)
@@ -285,7 +285,13 @@ public:
                const char* pMEDFileName,
                Mesh*       pMesh,
                int         pPosition);
-               
+       
+       /**
+        * Removes all the part beginning by pPrefixPartName from this distributed mesh.
+        * \param  pPrefixPartName name of the part.
+        */
+       void removeParts(const char* pPrefixPartName);
+       
        /**
         * Returns the current number of parts in this distributed mesh.
         * \return the current number of parts in this distributed mesh.
index 99e69f805f108c87293ae5431cee2f30209caf1a..f167cc408a2ee0ae10789f17b761fcc5e1bb748b 100644 (file)
@@ -233,6 +233,19 @@ string Obj::getPartInfo(const char* pPartName) const
 }
 
 
+void Obj::removeParts(const char* pPrefixPartName)
+{
+       // removePart() is only available for distributed MED file (not sequential MED file)
+       if ((mState != MULTIPR_OBJ_STATE_DIS) &&
+           (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__);
+               
+       if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__);
+       
+       mMeshDis->removeParts(pPrefixPartName);
+       mState = MULTIPR_OBJ_STATE_DIS_MEM;
+}
+
+
 vector<string> Obj::partitionneDomaine()
 {
        if (mState == MULTIPR_OBJ_STATE_SEQ_INIT) throw IllegalStateException("use setMesh() before", __FILE__, __LINE__);
index ea1ab55d5cba4a65286eaff3688905eef982b74d..24a9cb9c7f1aa0f45849c69dda128ced6b960928 100644 (file)
@@ -132,6 +132,14 @@ public:
         * \return all information about a part.
         */
        std::string getPartInfo(const char* pPartName) const;
+       
+       /**
+        * Removes all the part beginning by pPrefixPartName from the distributed MED file.
+        * Assume this object encapsulates a distributed MED file.
+        * \param  pPrefixPartName name of the part.
+        */
+       void removeParts(const char* pPrefixPartName);
+       
          
        //---------------------------------------------------------------------
        // Algorithms
index ad6b01f91d3d010d61ea48432fcb98430fba54a5..138743364e2301cad358ec480e01b442df88ff77 100644 (file)
@@ -42,6 +42,19 @@ void multipr::trim(char* pStr, char pChar)
 }
 
 
+bool multipr::startWith(const char* pStr, const char* pStrPrefix)
+{
+       int lenStr = strlen(pStr);
+       
+       int i = 0;
+       while ((pStr[i] != '\0') && (pStrPrefix[i] != '\0') && (pStr[i] == pStrPrefix[i]))
+       {
+               i++;
+       }
+       return (pStrPrefix[i] == '\0');
+}
+
+
 string multipr::removeExtension(const char* pFilename, const char* pExtension)
 {
        string strPrefix(pFilename); 
index 01b5a738accc40d14132c0392907ce7ec1e1d386..3300579f33689474fa9c4866b475fb221f280c44 100644 (file)
@@ -36,6 +36,15 @@ namespace multipr
 void trim(char* pStr, char pChar=' ');
 
 
+/**
+ * Returns true iff the given string starts by prefix.
+ * \param  pStr       any valid C string ending with the char '\0'.
+ * \param  pStrPrefix any valid C string ending with the char '\0'.
+ * \return true iff the given string starts by prefix.
+ */
+bool startWith(const char* pStr, const char* pStrPrefix);
+
 /**
  * Removes the extension (suffix) of a filename.
  * Example: removeExtension("agregat100grains_12pas.med", ".med") -> "agregat100grains_12pas"
index e9dd3a2a335a9872fc2155b76918cdf3e69cb145..6136568770fa247868f99adb295b39c2c2d9e9e6 100644 (file)
@@ -338,7 +338,7 @@ MULTIPR_ORB::string_array* MULTIPR_Obj_i::getParts()
 
 
 char* MULTIPR_Obj_i::getPartInfo(const char* pPartName)
-               throw (SALOME::SALOME_Exception)
+       throw (SALOME::SALOME_Exception)
 {
        if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
        
@@ -346,6 +346,15 @@ char* MULTIPR_Obj_i::getPartInfo(const char* pPartName)
 }
 
 
+void MULTIPR_Obj_i::removePart(const char* pPartName)
+       throw (SALOME::SALOME_Exception)
+{
+       if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
+       
+       mObj->removeParts(pPartName);
+}
+
+
 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneDomaine()
        throw (SALOME::SALOME_Exception)
 {
index 73bd6cf258798ed1f9c21bd4806bf6415b11ed08..510f3816cc024fb05c2a9f0d98463f17e0955f8f 100644 (file)
@@ -126,6 +126,15 @@ public:
        char* getPartInfo(const char* pPartName)
                throw (SALOME::SALOME_Exception);
 
+       /*!
+        * Removes the given part from the distributed MED file.
+        * Assume this object encapsulates a distributed MED file.
+        * \param  pPartName name of the part.
+        */
+       void removePart(const char* pPartName)
+               throw (SALOME::SALOME_Exception);
+       
+       
        //---------------------------------------------------------------------
        // Algorithms
        //---------------------------------------------------------------------
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
 //*****************************************************************************
index aa929e2483b3db15b3c29e23b77fe814794686c9..3e2e7d8914689eb02bc3a88494e3a23ec3dab9d4 100644 (file)
@@ -87,9 +87,11 @@ protected slots:
        void OnPartition1();
        void OnPartition2();
        void OnDecimate();
+       void OnRemove();
        void OnSave();
        
        void retrieveSelectedParts();
+       bool isPartExist(const char* partName);
        
 protected:
        virtual CAM_DataModel* createDataModel();
@@ -100,6 +102,7 @@ protected:
        { 
                ACTION_IMPORT_MED = 190,
                ACTION_SAVE,
+               ACTION_REMOVE,
                ACTION_SPLIT,
                ACTION_DECIMATE
        };
index be2a2fdaf96a8f4fb5571af0e014e384b0ec2c7d..1b08c61a4e79c14188f9f15018a6ea83edcc66a3 100644 (file)
@@ -138,7 +138,6 @@ void MULTIPR_GUI_Partition1Dlg::accept()
        }
 
        QDialog::accept();
-       mModule->getAppli()->updateObjectBrowser();
 }
 
 
@@ -229,7 +228,7 @@ void MULTIPR_GUI_Partition2Dlg::accept()
                for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++)
                {
                        const QString& partName = (*it);
-                       cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter;
+                       cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter << endl;
                        mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner);
                }
                
index e85b5fca37fe7d2c41d5ae9137fa970b7c9723a6..bd0b59ce403a2c199152721713f80a704a794237 100644 (file)
@@ -61,6 +61,15 @@ msgstr "Decimate"
 msgid "STS_DECIMATE"
 msgstr "Decimate selected parts (build two new meshes at lower resolution)"
 
+msgid "TLT_REMOVE"
+msgstr "Remove"
+
+msgid "MEN_REMOVE"
+msgstr "Remove"
+
+msgid "STS_DECIMATE"
+msgstr "Remove selected parts"
+
 msgid "TLT_SAVE"
 msgstr "Save distributed mesh"