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