Salome HOME
50de8b76221e7167081dca22032f0f8089b0b77a
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_HypothesesUtils.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_HypothesesUtils.cxx
24 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
25
26 // SMESH includes
27 #include "SMESHGUI_HypothesesUtils.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Hypotheses.h"
31 #include "SMESHGUI_XmlHandler.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_GEOMGenUtils.h"
34
35 // SALOME GUI includes
36 #include <SUIT_Desktop.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_OverrideCursor.h>
39 #include <SUIT_ResourceMgr.h>
40
41 #include <SalomeApp_Study.h>
42 #include <SalomeApp_Tools.h>
43
44 // SALOME KERNEL includes
45 #include <utilities.h>
46
47 // STL includes
48 #include <string>
49
50 // Qt includes
51 #include <QMap>
52 //#include <QList>
53
54 // Other includes
55 #ifdef WNT
56 #include <windows.h>
57 #else
58 #include <dlfcn.h>
59 #endif
60
61 #ifdef WNT
62 #define LibHandle HMODULE
63 #define LoadLib( name ) LoadLibrary( name )
64 #define GetProc GetProcAddress
65 #define UnLoadLib( handle ) FreeLibrary( handle );
66 #else
67 #define LibHandle void*
68 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
69 #define GetProc dlsym
70 #define UnLoadLib( handle ) dlclose( handle );
71 #endif
72
73 #ifdef _DEBUG_
74 static int MYDEBUG = 0;
75 #else
76 static int MYDEBUG = 0;
77 #endif
78
79 namespace SMESH
80 {
81   typedef QMap<QString,HypothesisData*> THypothesisDataMap;
82   THypothesisDataMap myHypothesesMap;
83   THypothesisDataMap myAlgorithmsMap;
84
85   // BUG 0020378
86   //typedef QMap<QString,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
87   //THypCreatorMap myHypCreatorMap;
88
89   QList<HypothesesSet*> myListOfHypothesesSets;
90
91   void processHypothesisStatus(const int theHypStatus,
92                                SMESH::SMESH_Hypothesis_ptr theHyp,
93                                const bool theIsAddition)
94   {
95     if (theHypStatus > SMESH::HYP_OK) {
96       // get Hyp name
97       QString aHypName ("NULL Hypothesis");
98       if (!CORBA::is_nil(theHyp)) {
99         _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
100         if (Shyp)
101           // name in study
102           aHypName = Shyp->GetName().c_str();
103         else
104           // label in xml file
105           aHypName = GetHypothesisData(theHyp->GetName())->Label;
106       }
107
108       // message
109       bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
110       QString aMsg;
111       if (theIsAddition)
112         aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
113       else
114         aMsg = (isFatal ? "SMESH_CANT_RM_HYP"  : "SMESH_RM_HYP_WRN");
115
116       aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName) +
117         QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
118
119       if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO ) // PAL18501
120         aMsg = aMsg.arg( GetHypothesisData(theHyp->GetName())->Dim[0] );
121
122       SUIT_MessageBox::warning(SMESHGUI::desktop(),
123                                QObject::tr("SMESH_WRN_WARNING"),
124                                aMsg);
125     }
126   }
127
128
129   void InitAvailableHypotheses()
130   {
131     SUIT_OverrideCursor wc;
132     if (myHypothesesMap.empty() && myAlgorithmsMap.empty()) {
133       // Resource manager
134       SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
135       if (!resMgr) return;
136
137       // Find name of a resource XML file ("SMESH_Meshers.xml");
138       QString HypsXml;
139       char* cenv = getenv("SMESH_MeshersList");
140       if (cenv)
141         HypsXml.sprintf("%s", cenv);
142
143       QStringList HypsXmlList = HypsXml.split(":", QString::SkipEmptyParts);
144       if (HypsXmlList.count() == 0) {
145         SUIT_MessageBox::critical(SMESHGUI::desktop(),
146                                   QObject::tr("SMESH_WRN_WARNING"),
147                                   QObject::tr("MESHERS_FILE_NO_VARIABLE"));
148         return;
149       }
150
151       // loop on files in HypsXml
152       QString aNoAccessFiles;
153       for (int i = 0; i < HypsXmlList.count(); i++) {
154         QString HypsXml = HypsXmlList[ i ];
155
156         // Find full path to the resource XML file
157         QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
158         if ( xmlFile.isEmpty() ) // try PLUGIN resources
159           xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
160         
161         QFile file (xmlFile);
162         if (file.exists() && file.open(QIODevice::ReadOnly)) {
163           file.close();
164
165           SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
166           ASSERT(aXmlHandler);
167
168           QXmlInputSource source (&file);
169           QXmlSimpleReader reader;
170           reader.setContentHandler(aXmlHandler);
171           reader.setErrorHandler(aXmlHandler);
172           bool ok = reader.parse(source);
173           file.close();
174           if (ok) {
175             myHypothesesMap.unite( aXmlHandler->myHypothesesMap );
176             myAlgorithmsMap.unite( aXmlHandler->myAlgorithmsMap );
177             QList<HypothesesSet*>::iterator it, pos = myListOfHypothesesSets.begin();
178             for ( it = aXmlHandler->myListOfHypothesesSets.begin(); 
179                   it != aXmlHandler->myListOfHypothesesSets.end();
180                   ++it ) {
181               myListOfHypothesesSets.insert( pos, *it );
182             }
183           }
184           else {
185             SUIT_MessageBox::critical(SMESHGUI::desktop(),
186                                       QObject::tr("INF_PARSE_ERROR"),
187                                       QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
188           }
189         }
190         else {
191           if (aNoAccessFiles.isEmpty())
192             aNoAccessFiles = xmlFile;
193           else
194             aNoAccessFiles += ", " + xmlFile;
195         }
196       } // end loop
197
198
199       if (!aNoAccessFiles.isEmpty()) {
200         QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
201         aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
202         wc.suspend();
203         SUIT_MessageBox::warning(SMESHGUI::desktop(),
204                                  QObject::tr("SMESH_WRN_WARNING"),
205                                  aMess);
206         wc.resume();
207       }
208     }
209   }
210
211
212   QStringList GetAvailableHypotheses( const bool isAlgo, 
213                                       const int theDim,                          
214                                       const bool isAux,
215                                       const bool isNeedGeometry)
216   {
217     QStringList aHypList;
218
219     // Init list of available hypotheses, if needed
220     InitAvailableHypotheses();
221     bool checkGeometry = ( !isNeedGeometry && isAlgo );
222     // fill list of hypotheses/algorithms
223     THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
224     THypothesisDataMap::iterator anIter;
225     for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ ) {
226       HypothesisData* aData = anIter.value();
227       if ( ( theDim < 0 || aData->Dim.contains( theDim ) ) && aData->IsAux == isAux) {
228         if (checkGeometry) {
229           if (aData->IsNeedGeometry == isNeedGeometry)
230             aHypList.append(anIter.key());
231         }
232         else {
233           aHypList.append(anIter.key());
234         }
235       }
236     }
237     return aHypList;
238   }
239
240
241   QStringList GetHypothesesSets()
242   {
243     QStringList aSetNameList;
244
245     // Init list of available hypotheses, if needed
246     InitAvailableHypotheses();
247
248     QList<HypothesesSet*>::iterator hypoSet;
249     for ( hypoSet  = myListOfHypothesesSets.begin(); 
250           hypoSet != myListOfHypothesesSets.end();
251           ++hypoSet ) {
252       HypothesesSet* aSet = *hypoSet;
253       if ( aSet && aSet->AlgoList.count() ) {
254         aSetNameList.append( aSet->HypoSetName );
255       }
256     }
257     
258     return aSetNameList;
259   }
260
261   HypothesesSet* GetHypothesesSet(const QString& theSetName)
262   {
263     QList<HypothesesSet*>::iterator hypoSet;
264     for ( hypoSet  = myListOfHypothesesSets.begin(); 
265           hypoSet != myListOfHypothesesSets.end();
266           ++hypoSet ) {
267       HypothesesSet* aSet = *hypoSet;
268       if ( aSet && aSet->HypoSetName == theSetName )
269         return aSet;
270     }
271     return 0;
272   }
273
274   HypothesisData* GetHypothesisData (const QString& aHypType)
275   {
276     HypothesisData* aHypData = 0;
277
278     // Init list of available hypotheses, if needed
279     InitAvailableHypotheses();
280
281     if (myHypothesesMap.find(aHypType) != myHypothesesMap.end()) {
282       aHypData = myHypothesesMap[aHypType];
283     }
284     else if (myAlgorithmsMap.find(aHypType) != myAlgorithmsMap.end()) {
285       aHypData = myAlgorithmsMap[aHypType];
286     }
287     return aHypData;
288   }
289
290   bool IsAvailableHypothesis(const HypothesisData* algoData,
291                              const QString&        hypType,
292                              bool&                 isAuxiliary)
293   {
294     isAuxiliary = false;
295     if ( !algoData )
296       return false;
297     if ( algoData->NeededHypos.contains( hypType ))
298       return true;
299     if ( algoData->OptionalHypos.contains( hypType)) {
300       isAuxiliary = true;
301       return true;
302     }
303     return false;
304   }
305
306   bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
307                              const HypothesisData* algo2Data)
308   {
309     if ( !algo1Data || !algo2Data )
310       return false;
311     const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
312     if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
313       algoIn = algo2Data; algoMain = algo1Data;
314     }
315     // look for any output type of algoIn between input types of algoMain
316     QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
317     for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
318       if ( algoMain->InputTypes.contains( *inElemType ))
319         return true;
320     return false;
321   }
322
323   HypothesisCreatorPtr GetHypothesisCreator(const QString& aHypType)
324   {
325     if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
326
327     SMESHGUI_GenericHypothesisCreator* aCreator = 0;
328
329     // check, if creator for this hypothesis type already exists
330     // BUG 0020378
331     //if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
332     //  aCreator = myHypCreatorMap[aHypType];
333     //}
334     //else
335     {
336       // 1. Init list of available hypotheses, if needed
337       InitAvailableHypotheses();
338
339       // 2. Get names of plugin libraries
340       HypothesisData* aHypData = GetHypothesisData(aHypType);
341       if (!aHypData) 
342         return HypothesisCreatorPtr(aCreator);
343       QString aClientLibName = aHypData->ClientLibName;
344       QString aServerLibName = aHypData->ServerLibName;
345
346       // 3. Load Client Plugin Library
347       try {
348         // load plugin library
349         if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
350         LibHandle libHandle = LoadLib( aClientLibName.toLatin1().data() );
351         if (!libHandle) {
352           // report any error, if occured
353           if ( MYDEBUG ) {
354 #ifdef WIN32
355             const char* anError = "Can't load client meshers plugin library";
356 #else
357             const char* anError = dlerror();      
358 #endif
359             MESSAGE(anError);
360           }
361         }
362         else {
363           // get method, returning hypothesis creator
364           if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
365           typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
366             ( const QString& );
367           GetHypothesisCreator procHandle =
368             (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
369           if (!procHandle) {
370             if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
371             UnLoadLib(libHandle);
372           }
373           else {
374             // get hypothesis creator
375             if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
376             aCreator = procHandle( aHypType );
377             if (!aCreator) {
378               if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
379             }
380             else {
381               // map hypothesis creator to a hypothesis name
382               // BUG 0020378
383               //myHypCreatorMap[aHypType] = aCreator;
384             }
385           }
386         }
387       }
388       catch (const SALOME::SALOME_Exception& S_ex) {
389         SalomeApp_Tools::QtCatchCorbaException(S_ex);
390       }
391     }
392
393     return HypothesisCreatorPtr(aCreator);
394   }
395
396
397   SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
398                                                const QString& aHypName,
399                                                const bool isAlgo)
400   {
401     if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() << 
402                         " with name " << aHypName.toLatin1().data());
403     HypothesisData* aHypData = GetHypothesisData(aHypType);
404     QString aServLib = aHypData->ServerLibName;
405     try {
406       SMESH::SMESH_Hypothesis_var aHypothesis;
407       aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
408                                                               aServLib.toLatin1().data());
409       if (!aHypothesis->_is_nil()) {
410         _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
411         if (aHypSObject) {
412           if (!aHypName.isEmpty())
413             SMESH::SetName(aHypSObject, aHypName);
414           SMESHGUI::GetSMESHGUI()->updateObjBrowser();
415           return aHypothesis._retn();
416         }
417       }
418     } catch (const SALOME::SALOME_Exception & S_ex) {
419       SalomeApp_Tools::QtCatchCorbaException(S_ex);
420     }
421
422     return SMESH::SMESH_Hypothesis::_nil();
423   }
424
425
426   bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
427   {
428     if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
429     int res = SMESH::HYP_UNKNOWN_FATAL;
430     SUIT_OverrideCursor wc;
431
432     if (!aMesh->_is_nil()) {
433       _PTR(SObject) SM = SMESH::FindSObject(aMesh);
434       GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
435       try {
436         res = aMesh->AddHypothesis(aShapeObject, aHyp);
437         if (res < SMESH::HYP_UNKNOWN_FATAL) {
438           _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
439           if (SM && aSH) {
440             SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
441           }
442         }
443         if (res > SMESH::HYP_OK) {
444           wc.suspend();
445           processHypothesisStatus(res, aHyp, true);
446           wc.resume();
447         }
448       }
449       catch(const SALOME::SALOME_Exception& S_ex) {
450         wc.suspend();
451         SalomeApp_Tools::QtCatchCorbaException(S_ex);
452         res = SMESH::HYP_UNKNOWN_FATAL;
453       }
454     }
455     return res < SMESH::HYP_UNKNOWN_FATAL;
456   }
457
458
459   bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
460   {
461     if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
462     int res = SMESH::HYP_UNKNOWN_FATAL;
463     SUIT_OverrideCursor wc;
464
465     if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
466       try {
467         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
468         _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
469         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
470         if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil()) {
471           res = aMesh->AddHypothesis(aShapeObject, aHyp);
472           if (res < SMESH::HYP_UNKNOWN_FATAL)  {
473             _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
474             if (meshSO)
475               SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
476           }
477           if (res > SMESH::HYP_OK) {
478             wc.suspend();
479             processHypothesisStatus(res, aHyp, true);
480             wc.resume();
481           }
482         }
483         else {
484           SCRUTE(aHyp->_is_nil());
485           SCRUTE(aMesh->_is_nil());
486           SCRUTE(!SsubM);
487           SCRUTE(aShapeObject->_is_nil());
488         }
489       }
490       catch(const SALOME::SALOME_Exception& S_ex) {
491         wc.suspend();
492         SalomeApp_Tools::QtCatchCorbaException(S_ex);
493         res = SMESH::HYP_UNKNOWN_FATAL;
494       }
495     }
496     else {
497       SCRUTE(aSubMesh->_is_nil());
498       SCRUTE(aHyp->_is_nil());
499     }
500     return res < SMESH::HYP_UNKNOWN_FATAL;
501   }
502
503   bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
504   {
505     int res = SMESH::HYP_UNKNOWN_FATAL;
506     SUIT_OverrideCursor wc;
507
508     try {
509       _PTR(Study) aStudy = GetActiveStudyDocument();
510       _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
511       if( aHypObj )
512         {
513           _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
514           _PTR(SObject) aRealHypo;
515           if( aHypObj->ReferencedObject( aRealHypo ) )
516             {
517               SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
518               RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
519             }
520           else
521             {
522               SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
523               SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
524               for( int i = 0; i < meshList.size(); i++ )
525                 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
526             }
527         }
528     }
529     catch(const SALOME::SALOME_Exception& S_ex)
530       {
531         wc.suspend();
532         SalomeApp_Tools::QtCatchCorbaException(S_ex);
533         res = SMESH::HYP_UNKNOWN_FATAL;
534       }
535     return res < SMESH::HYP_UNKNOWN_FATAL;
536   }
537
538   bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
539                                           SMESH::SMESH_Hypothesis_ptr anHyp)
540   {
541     SALOMEDS::GenericAttribute_var anAttr;
542     SALOMEDS::AttributeIOR_var anIOR;
543     int res = SMESH::HYP_UNKNOWN_FATAL;
544     SUIT_OverrideCursor wc;
545
546     if (MorSM) {
547       try {
548         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
549         SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
550         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
551         
552         if (!aSubMesh->_is_nil())
553           aMesh = aSubMesh->GetFather();
554         
555         if (!aMesh->_is_nil()) {    
556           if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
557             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
558             if (res < SMESH::HYP_UNKNOWN_FATAL) {
559               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
560               if (meshSO)
561                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
562             }
563             
564           }
565           else if(!aMesh->HasShapeToMesh()){
566             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
567             if (res < SMESH::HYP_UNKNOWN_FATAL) {
568               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
569               if (meshSO)
570                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);              
571             }
572           }
573           if (res > SMESH::HYP_OK) {
574             wc.suspend();
575             processHypothesisStatus(res, anHyp, false);
576             wc.resume();
577           }
578         }
579       } catch(const SALOME::SALOME_Exception& S_ex) {
580         wc.suspend();
581         SalomeApp_Tools::QtCatchCorbaException(S_ex);
582         res = SMESH::HYP_UNKNOWN_FATAL;
583       }
584     }
585     return res < SMESH::HYP_UNKNOWN_FATAL;
586   }
587
588   SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
589   {
590     SObjectList listSOmesh;
591     listSOmesh.resize(0);
592
593     unsigned int index = 0;
594     if (!AlgoOrHyp->_is_nil()) {
595       _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
596       if (SO_Hypothesis) {
597         SObjectList listSO =
598           SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
599
600         if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
601         for (unsigned int i = 0; i < listSO.size(); i++) {
602           _PTR(SObject) SO = listSO[i];
603           if (SO) {
604             _PTR(SObject) aFather = SO->GetFather();
605             if (aFather) {
606               _PTR(SObject) SOfatherFather = aFather->GetFather();
607               if (SOfatherFather) {
608                 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
609                 index++;
610                 listSOmesh.resize(index);
611                 listSOmesh[index - 1] = SOfatherFather;
612               }
613             }
614           }
615         }
616       }
617     }
618     if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
619     return listSOmesh;
620   }
621
622 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
623   QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
624   {
625     QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
626     for ( int i = 0; i < errors.length(); ++i ) {
627       const SMESH::AlgoStateError & error = errors[ i ];
628       const bool hasAlgo = ( strlen( error.algoName ) != 0 );
629       QString msg;
630       if ( !hasAlgo )
631         msg = QObject::tr( "STATE_ALGO_MISSING" );
632       else 
633         switch( error.state ) {
634           CASE2MESSAGE( HYP_MISSING );
635           CASE2MESSAGE( HYP_NOTCONFORM );
636           CASE2MESSAGE( HYP_BAD_PARAMETER );
637           CASE2MESSAGE( HYP_BAD_GEOMETRY );
638         default: continue;
639         }
640       // apply args to message:
641       // %1 - algo name
642       if ( hasAlgo )
643         msg = msg.arg( error.algoName.in() );
644       // %2 - dimension
645       msg = msg.arg( error.algoDim );
646       // %3 - global/local
647       msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
648       // %4 - hypothesis dim == algoDim
649       msg = msg.arg( error.algoDim );
650
651       if ( i ) resMsg += ";\n";
652       resMsg += msg;
653     }
654     return resMsg;
655   }
656 } // end of namespace SMESH