From 4b82b953ce24278dc9123f6441a58adc7a6283aa Mon Sep 17 00:00:00 2001 From: cs Date: Sat, 10 Mar 2007 18:59:15 +0000 Subject: [PATCH] *** empty log message *** --- idl/MULTIPR.idl | 28 ++- src/MULTIPR/MULTIPR_DecimationFilter.cxx | 2 + src/MULTIPR/MULTIPR_Mesh.cxx | 10 +- src/MULTIPR/MULTIPR_Mesh.hxx | 6 +- src/MULTIPR/MULTIPR_MeshDis.cxx | 90 ++++++- src/MULTIPR/MULTIPR_MeshDis.hxx | 18 ++ src/MULTIPR/MULTIPR_Obj.cxx | 28 ++- src/MULTIPR/MULTIPR_Obj.hxx | 18 ++ src/MULTIPR/MULTIPR_Utils.cxx | 2 +- src/MULTIPR/MULTIPR_Utils.hxx | 15 +- src/MULTIPR/MULTIPR_i.cxx | 48 +++- src/MULTIPR/MULTIPR_i.hxx | 37 ++- src/MULTIPR/multipr.cxx | 2 +- src/MULTIPRGUI/MULTIPR_GUI.cxx | 292 ++++++++++++++--------- src/MULTIPRGUI/MULTIPR_GUI.h | 1 + src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx | 82 +++---- 16 files changed, 470 insertions(+), 209 deletions(-) diff --git a/idl/MULTIPR.idl b/idl/MULTIPR.idl index c214a7c..34ff91f 100644 --- a/idl/MULTIPR.idl +++ b/idl/MULTIPR.idl @@ -96,14 +96,7 @@ interface MULTIPR_Obj */ 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 //-------------------------------------------------------------------- @@ -150,6 +143,25 @@ interface MULTIPR_Obj in double tlow, in double radius) raises (SALOME::SALOME_Exception); + + /*! + * Return useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + */ + string evalDecimationParams( + in string partName, + in string fieldName, + in long fieldIt, + in string filterName, + in string filterParams) + raises (SALOME::SALOME_Exception); + + /*! + * Remove all the parts starting with the given prefix from the distributed MED file. + * Assume this object encapsulates a distributed MED file. + */ + void removeParts(in string prefixPartName) + raises (SALOME::SALOME_Exception); //--------------------------------------------------------------------- // i/o diff --git a/src/MULTIPR/MULTIPR_DecimationFilter.cxx b/src/MULTIPR/MULTIPR_DecimationFilter.cxx index ef9e335..cef9380 100644 --- a/src/MULTIPR/MULTIPR_DecimationFilter.cxx +++ b/src/MULTIPR/MULTIPR_DecimationFilter.cxx @@ -218,6 +218,8 @@ void DecimationFilterGradAvg::getGradientInfo( *pOutGradAvg = 0.0; int count = 0; + cout << "numElements=" << numElements << endl; + cout << "num gauss pt by elt=" << numGaussPointsByElt << endl; // for each element for (int itElt = 0 ; itElt < numElements ; itElt++) { diff --git a/src/MULTIPR/MULTIPR_Mesh.cxx b/src/MULTIPR/MULTIPR_Mesh.cxx index fc16c30..461b54c 100644 --- a/src/MULTIPR/MULTIPR_Mesh.cxx +++ b/src/MULTIPR/MULTIPR_Mesh.cxx @@ -113,14 +113,20 @@ void Mesh::reset() } -vector Mesh::getNameFields() const +vector Mesh::getNameScalarFields() const { vector res; for (int itField = 0 ; itField < mFields.size() ; itField++) { Field* currentField = mFields[itField]; - res.push_back(currentField->getName()); + + // only get scalar fields, not vectorial fields + // (because, currently, decimation can only be performed on scalar fields) + if (currentField->getNumberOfComponents() == 1) + { + res.push_back(currentField->getName()); + } } return res; diff --git a/src/MULTIPR/MULTIPR_Mesh.hxx b/src/MULTIPR/MULTIPR_Mesh.hxx index d72bd8b..fde3195 100644 --- a/src/MULTIPR/MULTIPR_Mesh.hxx +++ b/src/MULTIPR/MULTIPR_Mesh.hxx @@ -91,10 +91,10 @@ public: const char* getName() const { return mMeshName; } /** - * Returns the name of all the fields. - * \return the name of all the fields. + * Returns the name of all the scalar fields. + * \return the name of all the scalar fields. */ - std::vector getNameFields() const; + std::vector getNameScalarFields() const; /** * Returns the number of iteration for a given field. diff --git a/src/MULTIPR/MULTIPR_MeshDis.cxx b/src/MULTIPR/MULTIPR_MeshDis.cxx index 9b93c2d..4f2a301 100644 --- a/src/MULTIPR/MULTIPR_MeshDis.cxx +++ b/src/MULTIPR/MULTIPR_MeshDis.cxx @@ -17,6 +17,7 @@ #include "MULTIPR_MeshDis.hxx" #include "MULTIPR_Mesh.hxx" +#include "MULTIPR_DecimationFilter.hxx" #include "MULTIPR_Utils.hxx" #include "MULTIPR_Globals.hxx" #include "MULTIPR_API.hxx" @@ -277,11 +278,17 @@ void MeshDis::removeParts(const char* pPrefixPartName) if (pPrefixPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + char strPrefix[256]; + sprintf(strPrefix, "%s_", pPrefixPartName); + for (vector::iterator itPart = mParts.begin() ; itPart != mParts.end() ; itPart++) { MeshDisPart* currentPart = (*itPart); - if (startWith(currentPart->getPartName(), pPrefixPartName)) + // remove part which have the same name and all sub_parts + // e.g. if pPrefixPartName="PART_4" => remove "PART_4" and "PART_4_*", but not "PART41" + if ((strcmp(currentPart->getPartName(), pPrefixPartName) == 0) || + startWith(currentPart->getPartName(), strPrefix)) { mParts.erase(itPart); @@ -360,7 +367,7 @@ vector MeshDis::getFields() const case MeshDisPart::MULTIPR_KEEP_AS_IT: case MeshDisPart::MULTIPR_WRITE_PARTS: { - vector > tmp = multipr::getListFields(mParts[0]->getMEDFileName()); + vector > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName()); for (int i = 0 ; i < tmp.size() ; i++) { @@ -370,7 +377,7 @@ vector MeshDis::getFields() const } case MeshDisPart::MULTIPR_WRITE_MESH: - return mParts[0]->mMesh->getNameFields(); + return mParts[0]->mMesh->getNameScalarFields(); default: throw IllegalStateException("", __FILE__, __LINE__); @@ -393,7 +400,7 @@ int MeshDis::getTimeStamps(const char* pFieldName) const case MeshDisPart::MULTIPR_KEEP_AS_IT: case MeshDisPart::MULTIPR_WRITE_PARTS: { - vector > tmp = multipr::getListFields(mParts[0]->getMEDFileName()); + vector > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName()); for (int i = 0 ; i < tmp.size() ; i++) { @@ -614,7 +621,80 @@ cout << (*this) << endl; part->mId + 1); } -cout << (*this) << endl; + // debug + //cout << (*this) << endl; +} + + +string MeshDis::evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams) +{ + MeshDisPart* part = findPart(pPartName); + if (part == NULL) return ""; + + try + { + if (part->mMesh == NULL) + { + part->readMED(); + } + + multipr::DecimationFilter* filter = multipr::DecimationFilter::create(pFilterName); + if (filter == NULL) return ""; + + multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast(filter); + + if (filterGrad != NULL) + { + int mode; + + int ret = sscanf(pFilterParams, "%d", &mode); + + // mode 2 = GET RADIUS + if ((ret == 1) && (mode == 2)) + { + double radius = part->mMesh->evalDefaultRadius(8); + char res[256]; + sprintf(res, "%f", radius); + return res; + } + + float radius; + int boxing; + + ret = sscanf(pFilterParams, "%d %f %d", &mode, &radius, &boxing); + + // mode 1 = GET GRADIENT MIN, MAX and AVG + if ((ret == 3) && (mode == 1)) + { + double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2; + + filterGrad->getGradientInfo( + part->mMesh, + pFieldName, + pFieldIt, + radius, + boxing, + &gradMin, + &gradAvg, + &gradMax); + + char res[2048]; + sprintf(res, "%f %f %f", gradMin, gradAvg, gradMax); + return res; + } + } + + delete filter; + } + catch(...) + { + return ""; + } } diff --git a/src/MULTIPR/MULTIPR_MeshDis.hxx b/src/MULTIPR/MULTIPR_MeshDis.hxx index f71a066..603bff6 100644 --- a/src/MULTIPR/MULTIPR_MeshDis.hxx +++ b/src/MULTIPR/MULTIPR_MeshDis.hxx @@ -288,6 +288,7 @@ public: /** * Removes all the part beginning by pPrefixPartName from this distributed mesh. + * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". * \param pPrefixPartName name of the part. */ void removeParts(const char* pPrefixPartName); @@ -376,6 +377,23 @@ public: med_float pTLow, med_float pRadius, int pBoxing = 100); + + /** + * Returns useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + * \param pPartName name of the part. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + * \return + */ + std::string evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams); //--------------------------------------------------------------------- // I/O diff --git a/src/MULTIPR/MULTIPR_Obj.cxx b/src/MULTIPR/MULTIPR_Obj.cxx index f167cc4..82cecfb 100644 --- a/src/MULTIPR/MULTIPR_Obj.cxx +++ b/src/MULTIPR/MULTIPR_Obj.cxx @@ -160,7 +160,7 @@ vector Obj::getFields() const (mState == MULTIPR_OBJ_STATE_SEQ)) { // CASE 1: sequential MED file - vector > tmp = multipr::getListFields(mMEDfilename.c_str()); + vector > tmp = multipr::getListScalarFields(mMEDfilename.c_str()); vector res; for (int i = 0 ; i < tmp.size() ; i++) @@ -187,7 +187,7 @@ int Obj::getTimeStamps(const char* pFieldName) const (mState == MULTIPR_OBJ_STATE_SEQ)) { // CASE 1: sequential MED file - vector > tmp = multipr::getListFields(mMEDfilename.c_str()); + vector > tmp = multipr::getListScalarFields(mMEDfilename.c_str()); for (int i = 0 ; i < tmp.size() ; i++) { @@ -384,6 +384,30 @@ vector Obj::decimePartition( } +string Obj::evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams) +{ + // decimePartition() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + string res = mMeshDis->evalDecimationParams( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pFilterParams); + + return res; +} + + vector Obj::getListParts() const { if (mMeshDis == NULL) throw IllegalStateException("not a distributed mesh", __FILE__, __LINE__); diff --git a/src/MULTIPR/MULTIPR_Obj.hxx b/src/MULTIPR/MULTIPR_Obj.hxx index 24a9cb9..14800a6 100644 --- a/src/MULTIPR/MULTIPR_Obj.hxx +++ b/src/MULTIPR/MULTIPR_Obj.hxx @@ -135,6 +135,7 @@ public: /** * Removes all the part beginning by pPrefixPartName from the distributed MED file. + * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". * Assume this object encapsulates a distributed MED file. * \param pPrefixPartName name of the part. */ @@ -200,6 +201,23 @@ public: double pRadius, int pBoxing); + /** + * Returns useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + * \param pPartName name of the part. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + */ + std::string evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams); + + //--------------------------------------------------------------------- // I/O //--------------------------------------------------------------------- diff --git a/src/MULTIPR/MULTIPR_Utils.cxx b/src/MULTIPR/MULTIPR_Utils.cxx index 1387433..df55304 100644 --- a/src/MULTIPR/MULTIPR_Utils.cxx +++ b/src/MULTIPR/MULTIPR_Utils.cxx @@ -148,7 +148,7 @@ vector multipr::getListMeshes(const char* pMEDfilename) } -vector > multipr::getListFields(const char* pMEDfilename) +vector > multipr::getListScalarFields(const char* pMEDfilename) { if (pMEDfilename == NULL) throw multipr::NullArgumentException("", __FILE__, __LINE__); diff --git a/src/MULTIPR/MULTIPR_Utils.hxx b/src/MULTIPR/MULTIPR_Utils.hxx index 3300579..b1d0062 100644 --- a/src/MULTIPR/MULTIPR_Utils.hxx +++ b/src/MULTIPR/MULTIPR_Utils.hxx @@ -87,13 +87,14 @@ std::string realToString(med_float mV); /** - * For each field in a sequential MED file, returns its name and the related number of iterations. - * \param pMEDfilename name of any valid sequential MED file; must not be NULL. - * \return a list of (name, #iterations). - * \throw NullArgumentException if pMEDfilename is NULL. - * \throw IOException if any other error occurs while reading MED file. - */ - std::vector > getListFields(const char* pMEDfilename); + * For each scalar field in a sequential MED file, returns its name and the related number of iterations. + * Do not returns info about vectorial fields (because, currently, decimation can only be performed on scalar fields). + * \param pMEDfilename name of any valid sequential MED file; must not be NULL. + * \return a list of (name, #iterations). + * \throw NullArgumentException if pMEDfilename is NULL. + * \throw IOException if any other error occurs while reading MED file. + */ + std::vector > getListScalarFields(const char* pMEDfilename); } // namespace MULTIPR diff --git a/src/MULTIPR/MULTIPR_i.cxx b/src/MULTIPR/MULTIPR_i.cxx index 6136568..03df31d 100644 --- a/src/MULTIPR/MULTIPR_i.cxx +++ b/src/MULTIPR/MULTIPR_i.cxx @@ -346,15 +346,6 @@ 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) { @@ -459,6 +450,45 @@ MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimePartition( } +char* MULTIPR_Obj_i::evalDecimationParams( + const char* pPartName, + const char* pFieldName, + CORBA::Long pFieldIt, + const char* pFilterName, + const char* pFilterParams) + throw (SALOME::SALOME_Exception) +{ + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + try + { + string res = mObj->evalDecimationParams( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pFilterParams); + + return CORBA::string_dup(res.c_str()); + + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to evaluate decimation parameters", SALOME::INTERNAL_ERROR); + } +} + + +void MULTIPR_Obj_i::removeParts(const char* pPrefixPartName) + throw (SALOME::SALOME_Exception) +{ + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + mObj->removeParts(pPrefixPartName); +} + + void MULTIPR_Obj_i::save() throw (SALOME::SALOME_Exception) { diff --git a/src/MULTIPR/MULTIPR_i.hxx b/src/MULTIPR/MULTIPR_i.hxx index 510f381..9876321 100644 --- a/src/MULTIPR/MULTIPR_i.hxx +++ b/src/MULTIPR/MULTIPR_i.hxx @@ -125,15 +125,6 @@ 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 @@ -191,7 +182,33 @@ public: CORBA::Double pTlow, CORBA::Double pRadius) throw (SALOME::SALOME_Exception); - + + /** + * Returns useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + * \param pPartName name of the part. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + */ + char* evalDecimationParams( + const char* pPartName, + const char* pFieldName, + CORBA::Long pFieldIt, + const char* pFilterName, + const char* pFilterParams) + throw (SALOME::SALOME_Exception); + + /*! + * Removes all the parts starting with "pPrefixPartName" from the distributed MED file. + * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". + * Assume this object encapsulates a distributed MED file. + * \param pPrefixPartName name of the part. + */ + void removeParts(const char* pPrefixPartName) + throw (SALOME::SALOME_Exception); + //--------------------------------------------------------------------- // I/O //--------------------------------------------------------------------- diff --git a/src/MULTIPR/multipr.cxx b/src/MULTIPR/multipr.cxx index ccdedb7..332412f 100644 --- a/src/MULTIPR/multipr.cxx +++ b/src/MULTIPR/multipr.cxx @@ -591,7 +591,7 @@ int runDumpMED() { // display list of fields contained in the MED file - vector > res = multipr::getListFields(g_medFilename); + vector > res = multipr::getListScalarFields(g_medFilename); cout << "List of fields in this MED file:" << endl; for (unsigned i = 0 ; i < res.size() ; i++) { diff --git a/src/MULTIPRGUI/MULTIPR_GUI.cxx b/src/MULTIPRGUI/MULTIPR_GUI.cxx index 6ff97df..3ce0330 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI.cxx @@ -302,6 +302,7 @@ void MULTIPR_GUI::OnImportFromMEDFile() this->application()->desktop(), true, tr("USE_BUILD_PROGRESS") ); + fd->setCaption(tr("MEN_IMPORT_FROM_MED_FILE")); fd->setFilters(aFilter); fd->exec(); @@ -331,23 +332,32 @@ void MULTIPR_GUI::OnImportFromMEDFile() } QApplication::restoreOverrideCursor(); - try + if (mMULTIPRObj != NULL) { - if (mMULTIPRObj->isValidSequentialMEDFile()) + try { - OnPartition1(); + if (mMULTIPRObj->isValidSequentialMEDFile()) + { + OnPartition1(); + } } + catch (...) + { + } + + getApp()->updateObjectBrowser(); } - catch (...) - { - } - - getApp()->updateObjectBrowser(); } void MULTIPR_GUI::OnPartition1() { + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this); dialog->exec(); delete dialog; @@ -356,6 +366,12 @@ void MULTIPR_GUI::OnPartition1() void MULTIPR_GUI::OnPartition2() { + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + retrieveSelectedParts(); if (mSelectedParts.count() == 0) @@ -368,6 +384,11 @@ void MULTIPR_GUI::OnPartition2() return; } + if (!removeLowerResolution()) + { + return; + } + MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this); dialog->exec(); delete dialog; @@ -377,6 +398,12 @@ void MULTIPR_GUI::OnPartition2() void MULTIPR_GUI::OnDecimate() { + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + retrieveSelectedParts(); if (mSelectedParts.count() == 0) @@ -389,66 +416,9 @@ 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++) + if (!removeLowerResolution()) { - 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(); + return; } MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this); @@ -460,6 +430,12 @@ void MULTIPR_GUI::OnDecimate() void MULTIPR_GUI::OnRemove() { + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + retrieveSelectedParts(); if (mSelectedParts.count() == 0) @@ -490,7 +466,7 @@ void MULTIPR_GUI::OnRemove() { const QString& partName = (*it); cout << "Remove " << partName.latin1() << endl; - mMULTIPRObj->removePart(partName.latin1()); + mMULTIPRObj->removeParts(partName.latin1()); } } @@ -511,6 +487,12 @@ void MULTIPR_GUI::OnRemove() void MULTIPR_GUI::OnSave() { + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + QApplication::setOverrideCursor(Qt::waitCursor); try @@ -570,6 +552,74 @@ bool MULTIPR_GUI::isPartExist(const char* partName) } +bool MULTIPR_GUI::removeLowerResolution() +{ + // for each selected part, check if there are lower resolution + // and then propose to remove them before performing new process + 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("Remove previous results"), + tr("Do you want to remove previous results?"), + tr("&Yes"), tr("&No"), + QString::null, 0, 1 ) ) + { + return false; + } + + 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->removeParts(partName.latin1()); + } + + } + catch(...) + { + SUIT_MessageBox::error1( + getApp()->desktop(), + "Remove error", + "Error while removing previous results", + tr("OK") ); + } + + QApplication::restoreOverrideCursor(); + + getApp()->updateObjectBrowser(); + } + + return true; +} + + //***************************************************************************** // Super class Data Object implementation //***************************************************************************** @@ -812,74 +862,80 @@ MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel() void MULTIPR_GUI_DataModel::build() { - MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast(root()); - - if (!modelRoot) - { - // root is not set yet - modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR"); - setRoot(modelRoot); - } - - MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj(); - - if (obj != NULL) + try { - MULTIPR_ORB::string_array* listParts = obj->getParts(); + MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast(root()); + + if (!modelRoot) + { + // root is not set yet + modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR"); + setRoot(modelRoot); + } - if (listParts->length() >= 1) + MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj(); + + if (obj != NULL) { - const char* strPartName0 = (*listParts)[0]; - char* strPartInfo0 = obj->getPartInfo(strPartName0); - - char lMeshName[256]; - int lId; - char lPartName[256]; - char lPath[256]; - char lMEDFileName[256]; - - // parse infos - int ret = sscanf(strPartInfo0, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - if (ret != 5) return; + MULTIPR_ORB::string_array* listParts = obj->getParts(); - MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName); - - MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL; - - for (int i = 0 ; i < listParts->length() ; i++) + if (listParts->length() >= 1) { - const char* strItem = (*listParts)[i]; - char* strPartInfo = obj->getPartInfo(strItem); + const char* strPartName0 = (*listParts)[0]; + char* strPartInfo0 = obj->getPartInfo(strPartName0); + + char lMeshName[256]; + int lId; + char lPartName[256]; + char lPath[256]; + char lMEDFileName[256]; // parse infos - int ret = sscanf(strPartInfo, "%s %d %s %s %s", + int ret = sscanf(strPartInfo0, "%s %d %s %s %s", lMeshName, &lId, lPartName, lPath, lMEDFileName); - + 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 + + MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName); + + MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL; + + for (int i = 0 ; i < listParts->length() ; i++) { - dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo); + const char* strItem = (*listParts)[i]; + char* strPartInfo = obj->getPartInfo(strItem); + + // parse infos + int ret = sscanf(strPartInfo, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + 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 + { + dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo); + } } } } } + catch (...) + { + } } diff --git a/src/MULTIPRGUI/MULTIPR_GUI.h b/src/MULTIPRGUI/MULTIPR_GUI.h index 3e2e7d8..499f711 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.h +++ b/src/MULTIPRGUI/MULTIPR_GUI.h @@ -92,6 +92,7 @@ protected slots: void retrieveSelectedParts(); bool isPartExist(const char* partName); + bool removeLowerResolution(); protected: virtual CAM_DataModel* createDataModel(); diff --git a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx index 1b08c61..526e70d 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx @@ -501,6 +501,8 @@ void MULTIPR_GUI_DecimateDlg::OnRadiusAuto() { // evaluates default radius for the first selected part const QStringList& partsList = mModule->getSelectedParts(); + const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); + int fieldIteration = atoi(strFieldIt); char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1()); char lMeshName[256]; @@ -521,11 +523,17 @@ void MULTIPR_GUI_DecimateDlg::OnRadiusAuto() float defaultRadius = 0.5f; try { - multipr::Mesh* mesh = new multipr::Mesh(); - mesh->readSequentialMED(lMEDFileName, lMeshName); - const int averageNumberOfNeighbours = 8; - defaultRadius = mesh->evalDefaultRadius(averageNumberOfNeighbours); - delete mesh; + char strParams[256]; + sprintf(strParams, "2"); + + char* res = mModule->getMULTIPRObj()->evalDecimationParams( + lPartName, + comboBoxSelectFieldName->currentText().latin1(), + fieldIteration, + comboBoxSelectFilter->currentText().latin1(), + strParams); + + sscanf(res, "%f", &defaultRadius); } catch (...) { @@ -540,6 +548,8 @@ void MULTIPR_GUI_DecimateDlg::OnThresholdAuto() { // evaluates default radius for the first selected part const QStringList& partsList = mModule->getSelectedParts(); + const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); + int fieldIteration = atoi(strFieldIt); char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1()); char lMeshName[256]; @@ -557,49 +567,34 @@ void MULTIPR_GUI_DecimateDlg::OnThresholdAuto() lMEDFileName); QApplication::setOverrideCursor(Qt::waitCursor); - float defaultRadius = 0.5f; + try { - multipr::Mesh* mesh = new multipr::Mesh(); - mesh->readSequentialMED(lMEDFileName, lMeshName); - - multipr::DecimationFilter* filter = - multipr::DecimationFilter::create(comboBoxSelectFilter->currentText().latin1()); - - double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2; - - multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast(filter); - if (filterGrad) + float radius; + ret = sscanf(lineEditRadius->text().latin1(), "%f", &radius); + if ((ret != 1) || (radius <= 0.0f)) { - const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); - int fieldIteration = atoi(strFieldIt); - - double radius; - ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius); - if ((ret != 1) || (radius <= 0.0f)) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Decimation parameters error", - "Invalid radius (should be > 0.0)", - tr("OK") ); - - return; - } - - filterGrad->getGradientInfo( - mesh, - comboBoxSelectFieldName->currentText().latin1(), - fieldIteration, - radius, - spinBoxBoxing->value(), - &gradMin, - &gradAvg, - &gradMax); + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Decimation parameters error", + "Invalid radius (should be > 0.0)", + tr("OK") ); + + return; } - delete filter; - delete mesh; + char strParams[256]; + sprintf(strParams, "1 %f %d", radius, spinBoxBoxing->value()); + + char* res = mModule->getMULTIPRObj()->evalDecimationParams( + lPartName, + comboBoxSelectFieldName->currentText().latin1(), + fieldIteration, + comboBoxSelectFilter->currentText().latin1(), + strParams); + + float gradMin, gradAvg, gradMax; + sscanf(res, "%f %f %f", &gradMin, &gradAvg, &gradMax); lineEditTMed->setText( QString::number(gradMin) ); lineEditTLow->setText( QString::number(gradMax) ); @@ -607,6 +602,7 @@ void MULTIPR_GUI_DecimateDlg::OnThresholdAuto() catch (...) { } + QApplication::restoreOverrideCursor(); } -- 2.39.2