From 50689122a40844cd82e7d7b9b38d96bb8b4bdbd0 Mon Sep 17 00:00:00 2001 From: cs Date: Sat, 10 Mar 2007 15:29:29 +0000 Subject: [PATCH] *** empty log message *** --- idl/MULTIPR.idl | 9 +- src/MULTIPR/MULTIPR_MeshDis.cxx | 51 +++++++++- src/MULTIPR/MULTIPR_MeshDis.hxx | 8 +- src/MULTIPR/MULTIPR_Obj.cxx | 13 +++ src/MULTIPR/MULTIPR_Obj.hxx | 8 ++ src/MULTIPR/MULTIPR_Utils.cxx | 13 +++ src/MULTIPR/MULTIPR_Utils.hxx | 9 ++ src/MULTIPR/MULTIPR_i.cxx | 11 ++- src/MULTIPR/MULTIPR_i.hxx | 9 ++ src/MULTIPRGUI/MULTIPR_GUI.cxx | 148 +++++++++++++++++++++++++++++ src/MULTIPRGUI/MULTIPR_GUI.h | 3 + src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx | 3 +- src/MULTIPRGUI/MULTIPR_msg_en.po | 9 ++ 13 files changed, 288 insertions(+), 6 deletions(-) diff --git a/idl/MULTIPR.idl b/idl/MULTIPR.idl index 19510b7..c214a7c 100644 --- a/idl/MULTIPR.idl +++ b/idl/MULTIPR.idl @@ -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 diff --git a/src/MULTIPR/MULTIPR_MeshDis.cxx b/src/MULTIPR/MULTIPR_MeshDis.cxx index 3a856f3..9b93c2d 100644 --- a/src/MULTIPR/MULTIPR_MeshDis.cxx +++ b/src/MULTIPR/MULTIPR_MeshDis.cxx @@ -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::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::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; } diff --git a/src/MULTIPR/MULTIPR_MeshDis.hxx b/src/MULTIPR/MULTIPR_MeshDis.hxx index bcfeebc..f71a066 100644 --- a/src/MULTIPR/MULTIPR_MeshDis.hxx +++ b/src/MULTIPR/MULTIPR_MeshDis.hxx @@ -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. diff --git a/src/MULTIPR/MULTIPR_Obj.cxx b/src/MULTIPR/MULTIPR_Obj.cxx index 99e69f8..f167cc4 100644 --- a/src/MULTIPR/MULTIPR_Obj.cxx +++ b/src/MULTIPR/MULTIPR_Obj.cxx @@ -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 Obj::partitionneDomaine() { if (mState == MULTIPR_OBJ_STATE_SEQ_INIT) throw IllegalStateException("use setMesh() before", __FILE__, __LINE__); diff --git a/src/MULTIPR/MULTIPR_Obj.hxx b/src/MULTIPR/MULTIPR_Obj.hxx index ea1ab55..24a9cb9 100644 --- a/src/MULTIPR/MULTIPR_Obj.hxx +++ b/src/MULTIPR/MULTIPR_Obj.hxx @@ -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 diff --git a/src/MULTIPR/MULTIPR_Utils.cxx b/src/MULTIPR/MULTIPR_Utils.cxx index ad6b01f..1387433 100644 --- a/src/MULTIPR/MULTIPR_Utils.cxx +++ b/src/MULTIPR/MULTIPR_Utils.cxx @@ -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); diff --git a/src/MULTIPR/MULTIPR_Utils.hxx b/src/MULTIPR/MULTIPR_Utils.hxx index 01b5a73..3300579 100644 --- a/src/MULTIPR/MULTIPR_Utils.hxx +++ b/src/MULTIPR/MULTIPR_Utils.hxx @@ -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" diff --git a/src/MULTIPR/MULTIPR_i.cxx b/src/MULTIPR/MULTIPR_i.cxx index e9dd3a2..6136568 100644 --- a/src/MULTIPR/MULTIPR_i.cxx +++ b/src/MULTIPR/MULTIPR_i.cxx @@ -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) { diff --git a/src/MULTIPR/MULTIPR_i.hxx b/src/MULTIPR/MULTIPR_i.hxx index 73bd6cf..510f381 100644 --- a/src/MULTIPR/MULTIPR_i.hxx +++ b/src/MULTIPR/MULTIPR_i.hxx @@ -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 //--------------------------------------------------------------------- diff --git a/src/MULTIPRGUI/MULTIPR_GUI.cxx b/src/MULTIPRGUI/MULTIPR_GUI.cxx index 650b930..6ff97df 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI.cxx @@ -55,6 +55,7 @@ #include #include #include +#include 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 ; ilength() ; i++) + { + const char* strItem = (*listParts)[i]; + if (strcmp(strItem, partName) == 0) + { + return true; + } + } + return false; +} + + //***************************************************************************** // Super class Data Object implementation //***************************************************************************** diff --git a/src/MULTIPRGUI/MULTIPR_GUI.h b/src/MULTIPRGUI/MULTIPR_GUI.h index aa929e2..3e2e7d8 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.h +++ b/src/MULTIPRGUI/MULTIPR_GUI.h @@ -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 }; diff --git a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx index be2a2fd..1b08c61 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx @@ -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); } diff --git a/src/MULTIPRGUI/MULTIPR_msg_en.po b/src/MULTIPRGUI/MULTIPR_msg_en.po index e85b5fc..bd0b59c 100644 --- a/src/MULTIPRGUI/MULTIPR_msg_en.po +++ b/src/MULTIPRGUI/MULTIPR_msg_en.po @@ -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" -- 2.39.2