00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_HypothesesUtils.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Hypotheses.h"
00032 #include "SMESHGUI_XmlHandler.h"
00033 #include "SMESHGUI_Utils.h"
00034 #include "SMESHGUI_GEOMGenUtils.h"
00035
00036
00037 #include <SUIT_Desktop.h>
00038 #include <SUIT_MessageBox.h>
00039 #include <SUIT_OverrideCursor.h>
00040 #include <SUIT_ResourceMgr.h>
00041
00042 #include <SalomeApp_Study.h>
00043 #include <SalomeApp_Tools.h>
00044
00045
00046 #include <utilities.h>
00047
00048
00049 #include <string>
00050
00051
00052 #include <QMap>
00053 #include <QDir>
00054
00055
00056
00057 #ifdef WNT
00058 #include <windows.h>
00059 #else
00060 #include <dlfcn.h>
00061 #endif
00062
00063 #ifdef WNT
00064 #define LibHandle HMODULE
00065 #define LoadLib( name ) LoadLibrary( name )
00066 #define GetProc GetProcAddress
00067 #define UnLoadLib( handle ) FreeLibrary( handle );
00068 #else
00069 #define LibHandle void*
00070 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
00071 #define GetProc dlsym
00072 #define UnLoadLib( handle ) dlclose( handle );
00073 #endif
00074
00075 #ifdef _DEBUG_
00076 static int MYDEBUG = 0;
00077 #else
00078 static int MYDEBUG = 0;
00079 #endif
00080
00081 namespace SMESH
00082 {
00083 typedef QMap<QString,HypothesisData*> THypothesisDataMap;
00084 THypothesisDataMap myHypothesesMap;
00085 THypothesisDataMap myAlgorithmsMap;
00086
00087
00088
00089
00090
00091 QList<HypothesesSet*> myListOfHypothesesSets;
00092
00093 void processHypothesisStatus(const int theHypStatus,
00094 SMESH::SMESH_Hypothesis_ptr theHyp,
00095 const bool theIsAddition)
00096 {
00097 if (theHypStatus > SMESH::HYP_OK) {
00098
00099 QString aHypName ("NULL Hypothesis");
00100 if (!CORBA::is_nil(theHyp)) {
00101 _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
00102 if (Shyp)
00103
00104 aHypName = Shyp->GetName().c_str();
00105 else
00106
00107 aHypName = GetHypothesisData(theHyp->GetName())->Label;
00108 }
00109
00110
00111 bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
00112 QString aMsg;
00113 if (theIsAddition)
00114 aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
00115 else
00116 aMsg = (isFatal ? "SMESH_CANT_RM_HYP" : "SMESH_RM_HYP_WRN");
00117
00118 aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName) +
00119 QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
00120
00121 if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO )
00122 aMsg = aMsg.arg( GetHypothesisData(theHyp->GetName())->Dim[0] );
00123
00124 SUIT_MessageBox::warning(SMESHGUI::desktop(),
00125 QObject::tr("SMESH_WRN_WARNING"),
00126 aMsg);
00127 }
00128 }
00129
00130
00134
00135
00136 static QString mangledHypoSetName(HypothesesSet* hypSet)
00137 {
00138 QString name = hypSet->name();
00139
00140
00141 int dim = hypSet->maxDim();
00142 if ( dim > -1 )
00143 name = QString("%1D: %2").arg(dim).arg(name);
00144
00145
00146 if ( hypSet->getIsCustom() )
00147 name = QString("%1 [custom]").arg(name);
00148
00149 return name;
00150 }
00151
00152
00156
00157
00158 static QString demangledHypoSetName(QString name)
00159 {
00160 name.remove(QRegExp("[0-3]D: "));
00161 name.remove(" [custom]");
00162 return name;
00163 }
00164
00165 void InitAvailableHypotheses()
00166 {
00167 SUIT_OverrideCursor wc;
00168 if (myHypothesesMap.empty() && myAlgorithmsMap.empty()) {
00169
00170 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
00171 if (!resMgr) return;
00172
00173
00174 QString HypsXml;
00175 char* cenv = getenv("SMESH_MeshersList");
00176 if (cenv)
00177 HypsXml.sprintf("%s", cenv);
00178
00179 QStringList HypsXmlList = HypsXml.split(":", QString::SkipEmptyParts);
00180 if (HypsXmlList.count() == 0) {
00181 SUIT_MessageBox::critical(SMESHGUI::desktop(),
00182 QObject::tr("SMESH_WRN_WARNING"),
00183 QObject::tr("MESHERS_FILE_NO_VARIABLE"));
00184 return;
00185 }
00186
00187 QStringList xmlFiles;
00188 xmlFiles.append( QDir::home().filePath("CustomMeshers.xml"));
00189 for (int i = 0; i < HypsXmlList.count(); i++) {
00190 QString HypsXml = HypsXmlList[ i ];
00191
00192
00193 QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
00194 if ( xmlFile.isEmpty() )
00195 xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
00196 if ( !xmlFile.isEmpty() )
00197 xmlFiles.append( xmlFile );
00198 }
00199
00200
00201 QString aNoAccessFiles;
00202 for (int i = 0; i < xmlFiles.count(); i++)
00203 {
00204 QString xmlFile = xmlFiles[ i ];
00205 QFile file (xmlFile);
00206 if (file.exists() && file.open(QIODevice::ReadOnly))
00207 {
00208 file.close();
00209
00210 SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
00211 ASSERT(aXmlHandler);
00212
00213 QXmlInputSource source (&file);
00214 QXmlSimpleReader reader;
00215 reader.setContentHandler(aXmlHandler);
00216 reader.setErrorHandler(aXmlHandler);
00217 bool ok = reader.parse(source);
00218 file.close();
00219 if (ok) {
00220 myHypothesesMap.unite( aXmlHandler->myHypothesesMap );
00221 myAlgorithmsMap.unite( aXmlHandler->myAlgorithmsMap );
00222 QList<HypothesesSet*>::iterator it, pos = myListOfHypothesesSets.begin();
00223 for ( it = aXmlHandler->myListOfHypothesesSets.begin();
00224 it != aXmlHandler->myListOfHypothesesSets.end();
00225 ++it )
00226 {
00227 (*it)->setIsCustom( i == 0 );
00228 myListOfHypothesesSets.insert( pos, *it );
00229 }
00230 }
00231 else {
00232 SUIT_MessageBox::critical(SMESHGUI::desktop(),
00233 QObject::tr("INF_PARSE_ERROR"),
00234 QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
00235 }
00236 delete aXmlHandler;
00237 }
00238 else if ( i > 0 ) {
00239 if (aNoAccessFiles.isEmpty())
00240 aNoAccessFiles = xmlFile;
00241 else
00242 aNoAccessFiles += ", " + xmlFile;
00243 }
00244 }
00245
00246
00247 if (!aNoAccessFiles.isEmpty()) {
00248 QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
00249 aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
00250 wc.suspend();
00251 SUIT_MessageBox::warning(SMESHGUI::desktop(),
00252 QObject::tr("SMESH_WRN_WARNING"),
00253 aMess);
00254 wc.resume();
00255 }
00256 }
00257 }
00258
00259
00260 QStringList GetAvailableHypotheses( const bool isAlgo,
00261 const int theDim,
00262 const bool isAux,
00263 const bool isNeedGeometry)
00264 {
00265 QStringList aHypList;
00266
00267
00268 InitAvailableHypotheses();
00269 bool checkGeometry = ( !isNeedGeometry && isAlgo );
00270
00271 THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
00272 THypothesisDataMap::iterator anIter;
00273 for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ ) {
00274 HypothesisData* aData = anIter.value();
00275 if ( ( theDim < 0 || aData->Dim.contains( theDim ) ) && aData->IsAux == isAux) {
00276 if (checkGeometry) {
00277 if (aData->IsNeedGeometry == isNeedGeometry)
00278 aHypList.append(anIter.key());
00279 }
00280 else {
00281 aHypList.append(anIter.key());
00282 }
00283 }
00284 }
00285 return aHypList;
00286 }
00287
00288
00289 QStringList GetHypothesesSets(int maxDim)
00290 {
00291 QStringList aSetNameList;
00292
00293
00294 InitAvailableHypotheses();
00295
00296 QList<HypothesesSet*>::iterator hypoSet;
00297 for ( hypoSet = myListOfHypothesesSets.begin();
00298 hypoSet != myListOfHypothesesSets.end();
00299 ++hypoSet ) {
00300 HypothesesSet* aSet = *hypoSet;
00301 if ( aSet &&
00302 ( aSet->count( true ) || aSet->count( false )) &&
00303 aSet->maxDim() <= maxDim)
00304 {
00305 aSetNameList.append( mangledHypoSetName( aSet ));
00306 }
00307 }
00308 aSetNameList.sort();
00309
00310
00311 QStringList reversedNames;
00312 for ( int i = 0; i < aSetNameList.count(); ++i )
00313 reversedNames.prepend( aSetNameList[i] );
00314
00315 return reversedNames;
00316 }
00317
00318 HypothesesSet* GetHypothesesSet(const QString& theSetName)
00319 {
00320 QString name = demangledHypoSetName( theSetName );
00321 QList<HypothesesSet*>::iterator hypoSet;
00322 for ( hypoSet = myListOfHypothesesSets.begin();
00323 hypoSet != myListOfHypothesesSets.end();
00324 ++hypoSet ) {
00325 HypothesesSet* aSet = *hypoSet;
00326 if ( aSet && aSet->name() == name )
00327 return aSet;
00328 }
00329 return 0;
00330 }
00331
00332 HypothesisData* GetHypothesisData (const QString& aHypType)
00333 {
00334 HypothesisData* aHypData = 0;
00335
00336
00337 InitAvailableHypotheses();
00338
00339 if (myHypothesesMap.find(aHypType) != myHypothesesMap.end()) {
00340 aHypData = myHypothesesMap[aHypType];
00341 }
00342 else if (myAlgorithmsMap.find(aHypType) != myAlgorithmsMap.end()) {
00343 aHypData = myAlgorithmsMap[aHypType];
00344 }
00345 return aHypData;
00346 }
00347
00348 bool IsAvailableHypothesis(const HypothesisData* algoData,
00349 const QString& hypType,
00350 bool& isAuxiliary)
00351 {
00352 isAuxiliary = false;
00353 if ( !algoData )
00354 return false;
00355 if ( algoData->NeededHypos.contains( hypType ))
00356 return true;
00357 if ( algoData->OptionalHypos.contains( hypType)) {
00358 isAuxiliary = true;
00359 return true;
00360 }
00361 return false;
00362 }
00363
00364 bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
00365 const HypothesisData* algo2Data)
00366 {
00367 if ( !algo1Data || !algo2Data )
00368 return false;
00369 const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
00370 if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
00371 algoIn = algo2Data; algoMain = algo1Data;
00372 }
00373
00374 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
00375 for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
00376 if ( algoMain->InputTypes.contains( *inElemType ))
00377 return true;
00378 return false;
00379 }
00380
00381 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
00382 {
00383 if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
00384
00385 SMESHGUI_GenericHypothesisCreator* aCreator = 0;
00386
00387
00388
00389
00390
00391
00392
00393 {
00394
00395 InitAvailableHypotheses();
00396
00397
00398 HypothesisData* aHypData = GetHypothesisData(aHypType);
00399 if (!aHypData)
00400 return aCreator;
00401
00402 QString aClientLibName = aHypData->ClientLibName;
00403 QString aServerLibName = aHypData->ServerLibName;
00404
00405
00406 try {
00407
00408 if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
00409 LibHandle libHandle = LoadLib( aClientLibName.toLatin1().data() );
00410 if (!libHandle) {
00411
00412 if ( MYDEBUG ) {
00413 #ifdef WIN32
00414 const char* anError = "Can't load client meshers plugin library";
00415 #else
00416 const char* anError = dlerror();
00417 #endif
00418 MESSAGE(anError);
00419 }
00420 }
00421 else {
00422
00423 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
00424 typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
00425 ( const QString& );
00426 GetHypothesisCreator procHandle =
00427 (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
00428 if (!procHandle) {
00429 if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
00430 UnLoadLib(libHandle);
00431 }
00432 else {
00433
00434 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
00435 aCreator = procHandle( aHypType );
00436 if (!aCreator) {
00437 if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
00438 }
00439 else {
00440
00441
00442
00443 }
00444 }
00445 }
00446 }
00447 catch (const SALOME::SALOME_Exception& S_ex) {
00448 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00449 }
00450 }
00451
00452 return aCreator;
00453 }
00454
00455
00456 SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
00457 const QString& aHypName,
00458 const bool isAlgo)
00459 {
00460 if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() <<
00461 " with name " << aHypName.toLatin1().data());
00462 HypothesisData* aHypData = GetHypothesisData(aHypType);
00463 QString aServLib = aHypData->ServerLibName;
00464 try {
00465 SMESH::SMESH_Hypothesis_var aHypothesis;
00466 aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
00467 aServLib.toLatin1().data());
00468 if (!aHypothesis->_is_nil()) {
00469 _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
00470 if (aHypSObject) {
00471 if (!aHypName.isEmpty())
00472 SMESH::SetName(aHypSObject, aHypName);
00473 SMESHGUI::Modified();
00474 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
00475 return aHypothesis._retn();
00476 }
00477 }
00478 } catch (const SALOME::SALOME_Exception & S_ex) {
00479 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00480 }
00481
00482 return SMESH::SMESH_Hypothesis::_nil();
00483 }
00484
00485
00486 bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
00487 {
00488 if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
00489 int res = SMESH::HYP_UNKNOWN_FATAL;
00490 SUIT_OverrideCursor wc;
00491
00492 if (!aMesh->_is_nil()) {
00493 _PTR(SObject) SM = SMESH::FindSObject(aMesh);
00494 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
00495 try {
00496 res = aMesh->AddHypothesis(aShapeObject, aHyp);
00497 if (res < SMESH::HYP_UNKNOWN_FATAL) {
00498 _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
00499 if (SM && aSH) {
00500 SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
00501 }
00502 }
00503 if (res > SMESH::HYP_OK) {
00504 wc.suspend();
00505 processHypothesisStatus(res, aHyp, true);
00506 wc.resume();
00507 }
00508 }
00509 catch(const SALOME::SALOME_Exception& S_ex) {
00510 wc.suspend();
00511 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00512 res = SMESH::HYP_UNKNOWN_FATAL;
00513 }
00514 }
00515 return res < SMESH::HYP_UNKNOWN_FATAL;
00516 }
00517
00518
00519 bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
00520 {
00521 if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
00522 int res = SMESH::HYP_UNKNOWN_FATAL;
00523 SUIT_OverrideCursor wc;
00524
00525 if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
00526 try {
00527 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
00528 _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
00529 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
00530 if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil()) {
00531 res = aMesh->AddHypothesis(aShapeObject, aHyp);
00532 if (res < SMESH::HYP_UNKNOWN_FATAL) {
00533 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
00534 if (meshSO)
00535 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
00536 }
00537 if (res > SMESH::HYP_OK) {
00538 wc.suspend();
00539 processHypothesisStatus(res, aHyp, true);
00540 wc.resume();
00541 }
00542 }
00543 else {
00544 SCRUTE(aHyp->_is_nil());
00545 SCRUTE(aMesh->_is_nil());
00546 SCRUTE(!SsubM);
00547 SCRUTE(aShapeObject->_is_nil());
00548 }
00549 }
00550 catch(const SALOME::SALOME_Exception& S_ex) {
00551 wc.suspend();
00552 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00553 res = SMESH::HYP_UNKNOWN_FATAL;
00554 }
00555 }
00556 else {
00557 SCRUTE(aSubMesh->_is_nil());
00558 SCRUTE(aHyp->_is_nil());
00559 }
00560 return res < SMESH::HYP_UNKNOWN_FATAL;
00561 }
00562
00563 bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
00564 {
00565 int res = SMESH::HYP_UNKNOWN_FATAL;
00566 SUIT_OverrideCursor wc;
00567
00568 try {
00569 _PTR(Study) aStudy = GetActiveStudyDocument();
00570 _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
00571 if( aHypObj )
00572 {
00573 _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
00574 _PTR(SObject) aRealHypo;
00575 if( aHypObj->ReferencedObject( aRealHypo ) )
00576 {
00577 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
00578 RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
00579 }
00580 else
00581 {
00582 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
00583 SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
00584 for( int i = 0; i < meshList.size(); i++ )
00585 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
00586 }
00587 }
00588 }
00589 catch(const SALOME::SALOME_Exception& S_ex)
00590 {
00591 wc.suspend();
00592 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00593 res = SMESH::HYP_UNKNOWN_FATAL;
00594 }
00595 return res < SMESH::HYP_UNKNOWN_FATAL;
00596 }
00597
00598 bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
00599 SMESH::SMESH_Hypothesis_ptr anHyp)
00600 {
00601 SALOMEDS::GenericAttribute_var anAttr;
00602 SALOMEDS::AttributeIOR_var anIOR;
00603 int res = SMESH::HYP_UNKNOWN_FATAL;
00604 SUIT_OverrideCursor wc;
00605
00606 if (MorSM) {
00607 try {
00608 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
00609 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
00610 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
00611
00612 if (!aSubMesh->_is_nil())
00613 aMesh = aSubMesh->GetFather();
00614
00615 if (!aMesh->_is_nil()) {
00616 if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
00617 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
00618 if (res < SMESH::HYP_UNKNOWN_FATAL) {
00619 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
00620 if (meshSO)
00621 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
00622 }
00623
00624 }
00625 else if(!aMesh->HasShapeToMesh()){
00626 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
00627 if (res < SMESH::HYP_UNKNOWN_FATAL) {
00628 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
00629 if (meshSO)
00630 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
00631 }
00632 }
00633 if (res > SMESH::HYP_OK) {
00634 wc.suspend();
00635 processHypothesisStatus(res, anHyp, false);
00636 wc.resume();
00637 }
00638 }
00639 } catch(const SALOME::SALOME_Exception& S_ex) {
00640 wc.suspend();
00641 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00642 res = SMESH::HYP_UNKNOWN_FATAL;
00643 }
00644 }
00645 return res < SMESH::HYP_UNKNOWN_FATAL;
00646 }
00647
00648 SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
00649 {
00650 SObjectList listSOmesh;
00651 listSOmesh.resize(0);
00652
00653 unsigned int index = 0;
00654 if (!AlgoOrHyp->_is_nil()) {
00655 _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
00656 if (SO_Hypothesis) {
00657 SObjectList listSO =
00658 SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
00659
00660 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
00661 for (unsigned int i = 0; i < listSO.size(); i++) {
00662 _PTR(SObject) SO = listSO[i];
00663 if (SO) {
00664 _PTR(SObject) aFather = SO->GetFather();
00665 if (aFather) {
00666 _PTR(SObject) SOfatherFather = aFather->GetFather();
00667 if (SOfatherFather) {
00668 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
00669 index++;
00670 listSOmesh.resize(index);
00671 listSOmesh[index - 1] = SOfatherFather;
00672 }
00673 }
00674 }
00675 }
00676 }
00677 }
00678 if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
00679 return listSOmesh;
00680 }
00681
00682 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
00683 QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
00684 {
00685 QString resMsg;
00686 for ( int i = 0; i < errors.length(); ++i ) {
00687 const SMESH::AlgoStateError & error = errors[ i ];
00688 const bool hasAlgo = ( strlen( error.algoName ) != 0 );
00689 QString msg;
00690 if ( !hasAlgo )
00691 msg = QObject::tr( "STATE_ALGO_MISSING" );
00692 else
00693 switch( error.state ) {
00694 CASE2MESSAGE( HYP_MISSING );
00695 CASE2MESSAGE( HYP_NOTCONFORM );
00696 CASE2MESSAGE( HYP_BAD_PARAMETER );
00697 CASE2MESSAGE( HYP_BAD_GEOMETRY );
00698 default: continue;
00699 }
00700
00701
00702 if ( hasAlgo )
00703 msg = msg.arg( error.algoName.in() );
00704
00705 msg = msg.arg( error.algoDim );
00706
00707 msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
00708
00709 msg = msg.arg( error.algoDim );
00710
00711 if ( i ) resMsg += ";\n";
00712 resMsg += msg;
00713 }
00714 return resMsg;
00715 }
00716 }