Salome HOME
NPAL16198: EDF462: Submeshes creation duplicate algorithms and hypotheses. Refix.
[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       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
117                             QObject::tr("SMESH_WRN_WARNING"),
118                             aMsg,
119                             QObject::tr("SMESH_BUT_OK"));
120     }
121   }
122
123
124   void InitAvailableHypotheses()
125   {
126     SUIT_OverrideCursor wc;
127     if (myHypothesesMap.empty() && myAlgorithmsMap.empty()) {
128       // Resource manager
129       SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
130       if (!resMgr) return;
131
132       // Find name of a resource XML file ("SMESH_Meshers.xml");
133       QString HypsXml;
134       char* cenv = getenv("SMESH_MeshersList");
135       if (cenv)
136         HypsXml.sprintf("%s", cenv);
137
138       QStringList HypsXmlList = QStringList::split(":", HypsXml, false);
139       if (HypsXmlList.count() == 0)
140         {
141           SUIT_MessageBox::error1(SMESHGUI::desktop(),
142                                  QObject::tr("SMESH_WRN_WARNING"),
143                                  QObject::tr("MESHERS_FILE_NO_VARIABLE"),
144                                  QObject::tr("SMESH_BUT_OK"));
145           return;
146         }
147
148       // loop on files in HypsXml
149       QString aNoAccessFiles;
150       for (int i = 0; i < HypsXmlList.count(); i++) {
151         QString HypsXml = HypsXmlList[ i ];
152
153         // Find full path to the resource XML file
154         QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
155         if ( xmlFile.isEmpty() ) // try PLUGIN resources
156           xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
157         
158         QFile file (xmlFile);
159         if (file.exists() && file.open(IO_ReadOnly)) {
160           file.close();
161
162           SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
163           ASSERT(aXmlHandler);
164
165           QXmlInputSource source (file);
166           QXmlSimpleReader reader;
167           reader.setContentHandler(aXmlHandler);
168           reader.setErrorHandler(aXmlHandler);
169           bool ok = reader.parse(source);
170           file.close();
171           if (ok) {
172             myHypothesesMap.insert( aXmlHandler->myHypothesesMap.begin(),
173                                     aXmlHandler->myHypothesesMap.end() );
174             myAlgorithmsMap.insert( aXmlHandler->myAlgorithmsMap.begin(),
175                                     aXmlHandler->myAlgorithmsMap.end() );
176             myListOfHypothesesSets.splice( myListOfHypothesesSets.begin(),
177                                            aXmlHandler->myListOfHypothesesSets );
178           }
179           else {
180             SUIT_MessageBox::error1(SMESHGUI::desktop(),
181                                    QObject::tr("INF_PARSE_ERROR"),
182                                    QObject::tr(aXmlHandler->errorProtocol()),
183                                    QObject::tr("SMESH_BUT_OK"));
184           }
185         }
186         else {
187           if (aNoAccessFiles.isEmpty())
188             aNoAccessFiles = xmlFile;
189           else
190             aNoAccessFiles += ", " + xmlFile;
191         }
192       } // end loop
193
194
195       if (!aNoAccessFiles.isEmpty()) {
196         QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
197         aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
198         wc.suspend();
199         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
200                               QObject::tr("SMESH_WRN_WARNING"),
201                               aMess,
202                               QObject::tr("SMESH_BUT_OK"));
203         wc.resume();
204       }
205     }
206   }
207
208
209   QStringList GetAvailableHypotheses( const bool isAlgo, 
210                                       const int theDim,                          
211                                       const bool isAux,
212                                       const bool isNeedGeometry)
213   {
214     QStringList aHypList;
215
216     // Init list of available hypotheses, if needed
217     InitAvailableHypotheses();
218     bool checkGeometry = !isNeedGeometry;
219     // fill list of hypotheses/algorithms
220     THypothesisDataMap* pMap = isAlgo ? &myAlgorithmsMap : &myHypothesesMap;
221     THypothesisDataMap::iterator anIter;
222     for ( anIter = pMap->begin(); anIter != pMap->end(); anIter++ )
223     {
224       HypothesisData* aData = (*anIter).second;
225       if ( ( theDim < 0 || aData->Dim.contains( theDim ) ) && aData->IsAux == isAux)
226         if (checkGeometry){
227           if (aData->IsNeedGeometry == isNeedGeometry)
228             aHypList.append(((*anIter).first).c_str());
229         }
230         else
231           aHypList.append(((*anIter).first).c_str());
232     }
233     return aHypList;
234   }
235
236
237   QStringList GetHypothesesSets()
238   {
239     QStringList aSetNameList;
240
241     // Init list of available hypotheses, if needed
242     InitAvailableHypotheses();
243
244     list<HypothesesSet*>::iterator hypoSet = myListOfHypothesesSets.begin();
245     for ( ; hypoSet != myListOfHypothesesSets.end(); ++hypoSet )
246     {
247       HypothesesSet* aSet = *hypoSet;
248       if ( aSet && aSet->AlgoList.count() ) {
249         aSetNameList.append( aSet->HypoSetName );
250       }
251     }
252
253     return aSetNameList;
254   }
255
256   HypothesesSet* GetHypothesesSet(const QString theSetName)
257   {
258     list<HypothesesSet*>::iterator hypoSet = myListOfHypothesesSets.begin();
259     for ( ; hypoSet != myListOfHypothesesSets.end(); ++hypoSet )
260     {
261       HypothesesSet* aSet = *hypoSet;
262       if ( aSet && aSet->HypoSetName == theSetName )
263         return aSet;
264     }
265     return 0;
266   }
267
268   HypothesisData* GetHypothesisData (const char* aHypType)
269   {
270     HypothesisData* aHypData = 0;
271
272     // Init list of available hypotheses, if needed
273     InitAvailableHypotheses();
274
275     THypothesisDataMap::iterator type_data = myHypothesesMap.find(aHypType);
276     if (type_data != myHypothesesMap.end()) {
277       aHypData = type_data->second;
278     }
279     else {
280       type_data = myAlgorithmsMap.find(aHypType);
281       if (type_data != myAlgorithmsMap.end())
282         aHypData = type_data->second;
283     }
284     return aHypData;
285   }
286
287   bool IsAvailableHypothesis(const HypothesisData* algoData,
288                              const QString&        hypType,
289                              bool&                 isAuxiliary)
290   {
291     isAuxiliary = false;
292     if ( !algoData )
293       return false;
294     if ( algoData->NeededHypos.contains( hypType ))
295       return true;
296     if ( algoData->OptionalHypos.contains( hypType)) {
297       isAuxiliary = true;
298       return true;
299     }
300     return false;
301   }
302
303   bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
304                              const HypothesisData* algo2Data)
305   {
306     if ( !algo1Data || !algo2Data )
307       return false;
308     const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
309     if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
310       algoIn = algo2Data; algoMain = algo1Data;
311     }
312     // look for any output type of algoIn between input types of algoMain
313     QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
314     for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
315       if ( algoMain->InputTypes.contains( *inElemType ))
316         return true;
317     return false;
318   }
319
320   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const char* aHypType)
321   {
322     if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType);
323
324     SMESHGUI_GenericHypothesisCreator* aCreator = 0;
325
326     // check, if creator for this hypothesis type already exists
327     if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
328       aCreator = myHypCreatorMap[aHypType];
329     }
330     else {
331       // 1. Init list of available hypotheses, if needed
332       InitAvailableHypotheses();
333
334       // 2. Get names of plugin libraries
335       HypothesisData* aHypData = GetHypothesisData(aHypType);
336       if (!aHypData) 
337         return aCreator;
338       QString aClientLibName = aHypData->ClientLibName;
339       QString aServerLibName = aHypData->ServerLibName;
340
341       // 3. Load Client Plugin Library
342       try {
343         // load plugin library
344         if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
345         LibHandle libHandle = LoadLib( aClientLibName );
346         if (!libHandle) {
347           // report any error, if occured
348     if ( MYDEBUG )
349     {
350 #ifdef WIN32
351       const char* anError = "Can't load client meshers plugin library";
352 #else
353             const char* anError = dlerror();      
354 #endif
355       MESSAGE(anError);
356     }
357         }
358         else {
359           // get method, returning hypothesis creator
360           if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
361           typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
362             ( const QString& );
363           GetHypothesisCreator procHandle =
364             (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
365           if (!procHandle) {
366             if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
367             UnLoadLib(libHandle);
368           }
369           else {
370             // get hypothesis creator
371             if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType);
372             aCreator = procHandle( aHypType );
373             if (!aCreator) {
374               if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
375             }
376             else {
377               // map hypothesis creator to a hypothesis name
378               myHypCreatorMap[aHypType] = aCreator;
379             }
380           }
381         }
382       }
383       catch (const SALOME::SALOME_Exception& S_ex) {
384         SalomeApp_Tools::QtCatchCorbaException(S_ex);
385       }
386     }
387
388     return aCreator;
389   }
390
391
392   SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const char* aHypType,
393                                                const char* aHypName,
394                                                const bool isAlgo)
395   {
396     if(MYDEBUG) MESSAGE("Create " << aHypType << " with name " << aHypName);
397     HypothesisData* aHypData = GetHypothesisData(aHypType);
398     QString aServLib = aHypData->ServerLibName;
399     try {
400       SMESH::SMESH_Hypothesis_var aHypothesis;
401       aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType, aServLib);
402       if (!aHypothesis->_is_nil()) {
403         _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
404         if (aHypSObject) {
405           if (strlen(aHypName) > 0)
406             SMESH::SetName(aHypSObject, aHypName);
407           SMESHGUI::GetSMESHGUI()->updateObjBrowser();
408           return aHypothesis._retn();
409         }
410       }
411     } catch (const SALOME::SALOME_Exception & S_ex) {
412       SalomeApp_Tools::QtCatchCorbaException(S_ex);
413     }
414
415     return SMESH::SMESH_Hypothesis::_nil();
416   }
417
418
419   bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
420   {
421     if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
422     int res = SMESH::HYP_UNKNOWN_FATAL;
423     SUIT_OverrideCursor wc;
424
425     if (!aMesh->_is_nil()) {
426       _PTR(SObject) SM = SMESH::FindSObject(aMesh);
427       GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
428       try {
429         res = aMesh->AddHypothesis(aShapeObject, aHyp);
430         if (res < SMESH::HYP_UNKNOWN_FATAL) {
431           _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
432           if (SM && aSH) {
433             SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
434           }
435         }
436         if (res > SMESH::HYP_OK) {
437           wc.suspend();
438           processHypothesisStatus(res, aHyp, true);
439           wc.resume();
440         }
441       }
442       catch(const SALOME::SALOME_Exception& S_ex) {
443         wc.suspend();
444         SalomeApp_Tools::QtCatchCorbaException(S_ex);
445         res = SMESH::HYP_UNKNOWN_FATAL;
446       }
447     }
448     return res < SMESH::HYP_UNKNOWN_FATAL;
449   }
450
451
452   bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
453   {
454     if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
455     int res = SMESH::HYP_UNKNOWN_FATAL;
456     SUIT_OverrideCursor wc;
457
458     if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
459       try {
460         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
461         _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
462         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
463         if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil()) {
464           res = aMesh->AddHypothesis(aShapeObject, aHyp);
465           if (res < SMESH::HYP_UNKNOWN_FATAL)  {
466             _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
467             if (meshSO)
468               SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
469           }
470           if (res > SMESH::HYP_OK) {
471             wc.suspend();
472             processHypothesisStatus(res, aHyp, true);
473             wc.resume();
474           }
475         }
476         else {
477           SCRUTE(aHyp->_is_nil());
478           SCRUTE(aMesh->_is_nil());
479           SCRUTE(!SsubM);
480           SCRUTE(aShapeObject->_is_nil());
481         }
482       }
483       catch(const SALOME::SALOME_Exception& S_ex) {
484         wc.suspend();
485         SalomeApp_Tools::QtCatchCorbaException(S_ex);
486         res = SMESH::HYP_UNKNOWN_FATAL;
487       }
488     }
489     else {
490       SCRUTE(aSubMesh->_is_nil());
491       SCRUTE(aHyp->_is_nil());
492     }
493     return res < SMESH::HYP_UNKNOWN_FATAL;
494   }
495
496   bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
497   {
498     int res = SMESH::HYP_UNKNOWN_FATAL;
499     SUIT_OverrideCursor wc;
500
501     try {
502       _PTR(Study) aStudy = GetActiveStudyDocument();
503       _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
504       if( aHypObj )
505       {
506         _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
507         _PTR(SObject) aRealHypo;
508         if( aHypObj->ReferencedObject( aRealHypo ) )
509         {
510           SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
511           RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
512         }
513         else
514         {
515           SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
516           SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
517           for( int i = 0; i < meshList.size(); i++ )
518             RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
519         }
520       }
521     }
522     catch(const SALOME::SALOME_Exception& S_ex)
523     {
524       wc.suspend();
525       SalomeApp_Tools::QtCatchCorbaException(S_ex);
526       res = SMESH::HYP_UNKNOWN_FATAL;
527     }
528     return res < SMESH::HYP_UNKNOWN_FATAL;
529   }
530
531   bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
532                                           SMESH::SMESH_Hypothesis_ptr anHyp)
533   {
534     SALOMEDS::GenericAttribute_var anAttr;
535     SALOMEDS::AttributeIOR_var anIOR;
536     int res = SMESH::HYP_UNKNOWN_FATAL;
537     SUIT_OverrideCursor wc;
538
539     if (MorSM) {
540       try {
541         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
542         SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
543         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
544         
545         if (!aSubMesh->_is_nil())
546           aMesh = aSubMesh->GetFather();
547         
548         if (!aMesh->_is_nil()) {    
549           if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
550             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
551             if (res < SMESH::HYP_UNKNOWN_FATAL) {
552               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
553               if (meshSO)
554                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
555             }
556             
557           }
558           else if(!aMesh->HasShapeToMesh()){
559             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
560             if (res < SMESH::HYP_UNKNOWN_FATAL) {
561               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
562               if (meshSO)
563                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);              
564             }
565           }
566           if (res > SMESH::HYP_OK) {
567             wc.suspend();
568             processHypothesisStatus(res, anHyp, false);
569             wc.resume();
570           }
571         }
572       } catch(const SALOME::SALOME_Exception& S_ex) {
573         wc.suspend();
574         SalomeApp_Tools::QtCatchCorbaException(S_ex);
575         res = SMESH::HYP_UNKNOWN_FATAL;
576       }
577     }
578     return res < SMESH::HYP_UNKNOWN_FATAL;
579   }
580
581   SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
582   {
583     SObjectList listSOmesh;
584     listSOmesh.resize(0);
585
586     unsigned int index = 0;
587     if (!AlgoOrHyp->_is_nil()) {
588       _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
589       if (SO_Hypothesis) {
590         SObjectList listSO =
591           SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
592
593         if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
594         for (unsigned int i = 0; i < listSO.size(); i++) {
595           _PTR(SObject) SO = listSO[i];
596           if (SO) {
597             _PTR(SObject) aFather = SO->GetFather();
598             if (aFather) {
599               _PTR(SObject) SOfatherFather = aFather->GetFather();
600               if (SOfatherFather) {
601                 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
602                 index++;
603                 listSOmesh.resize(index);
604                 listSOmesh[index - 1] = SOfatherFather;
605               }
606             }
607           }
608         }
609       }
610     }
611     if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
612     return listSOmesh;
613   }
614
615 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
616   QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
617   {
618     QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
619     for ( int i = 0; i < errors.length(); ++i ) {
620       const SMESH::AlgoStateError & error = errors[ i ];
621       const bool hasAlgo = ( strlen( error.algoName ) != 0 );
622       QString msg;
623       if ( !hasAlgo )
624         msg = QObject::tr( "STATE_ALGO_MISSING" );
625       else 
626         switch( error.state ) {
627           CASE2MESSAGE( HYP_MISSING );
628           CASE2MESSAGE( HYP_NOTCONFORM );
629           CASE2MESSAGE( HYP_BAD_PARAMETER );
630           CASE2MESSAGE( HYP_BAD_GEOMETRY );
631         default: continue;
632         }
633       // apply args to message:
634       // %1 - algo name
635       if ( hasAlgo )
636         msg = msg.arg( error.algoName.in() );
637       // %2 - dimension
638       msg = msg.arg( error.algoDim );
639       // %3 - global/local
640       msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
641       // %4 - hypothesis dim == algoDim
642       msg = msg.arg( error.algoDim );
643
644       if ( i ) resMsg += ";\n";
645       resMsg += msg;
646     }
647     return resMsg;
648   }
649
650 }