Salome HOME
0020321: EDF : Some windows do not appear depending on the platform (MinimumSizeHint())
[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 // SMESH includes
26 //
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   typedef QMap<QString,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
86   THypCreatorMap myHypCreatorMap;
87
88   QList<HypothesesSet*> myListOfHypothesesSets;
89
90   void processHypothesisStatus(const int theHypStatus,
91                                SMESH::SMESH_Hypothesis_ptr theHyp,
92                                const bool theIsAddition)
93   {
94     if (theHypStatus > SMESH::HYP_OK) {
95       // get Hyp name
96       QString aHypName ("NULL Hypothesis");
97       if (!CORBA::is_nil(theHyp)) {
98         _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
99         if (Shyp)
100           // name in study
101           aHypName = Shyp->GetName().c_str();
102         else
103           // label in xml file
104           aHypName = GetHypothesisData(theHyp->GetName())->Label;
105       }
106
107       // message
108       bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
109       QString aMsg;
110       if (theIsAddition)
111         aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
112       else
113         aMsg = (isFatal ? "SMESH_CANT_RM_HYP"  : "SMESH_RM_HYP_WRN");
114
115       aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName) +
116         QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
117
118       if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO ) // PAL18501
119         aMsg = aMsg.arg( GetHypothesisData(theHyp->GetName())->Dim[0] );
120
121       SUIT_MessageBox::warning(SMESHGUI::desktop(),
122                                QObject::tr("SMESH_WRN_WARNING"),
123                                aMsg);
124     }
125   }
126
127
128   void InitAvailableHypotheses()
129   {
130     SUIT_OverrideCursor wc;
131     if (myHypothesesMap.empty() && myAlgorithmsMap.empty()) {
132       // Resource manager
133       SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
134       if (!resMgr) return;
135
136       // Find name of a resource XML file ("SMESH_Meshers.xml");
137       QString HypsXml;
138       char* cenv = getenv("SMESH_MeshersList");
139       if (cenv)
140         HypsXml.sprintf("%s", cenv);
141
142       QStringList HypsXmlList = HypsXml.split(":", QString::SkipEmptyParts);
143       if (HypsXmlList.count() == 0) {
144         SUIT_MessageBox::critical(SMESHGUI::desktop(),
145                                   QObject::tr("SMESH_WRN_WARNING"),
146                                   QObject::tr("MESHERS_FILE_NO_VARIABLE"));
147         return;
148       }
149
150       // loop on files in HypsXml
151       QString aNoAccessFiles;
152       for (int i = 0; i < HypsXmlList.count(); i++) {
153         QString HypsXml = HypsXmlList[ i ];
154
155         // Find full path to the resource XML file
156         QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
157         if ( xmlFile.isEmpty() ) // try PLUGIN resources
158           xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
159         
160         QFile file (xmlFile);
161         if (file.exists() && file.open(QIODevice::ReadOnly)) {
162           file.close();
163
164           SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
165           ASSERT(aXmlHandler);
166
167           QXmlInputSource source (&file);
168           QXmlSimpleReader reader;
169           reader.setContentHandler(aXmlHandler);
170           reader.setErrorHandler(aXmlHandler);
171           bool ok = reader.parse(source);
172           file.close();
173           if (ok) {
174             myHypothesesMap.unite( aXmlHandler->myHypothesesMap );
175             myAlgorithmsMap.unite( aXmlHandler->myAlgorithmsMap );
176             QList<HypothesesSet*>::iterator it, pos = myListOfHypothesesSets.begin();
177             for ( it = aXmlHandler->myListOfHypothesesSets.begin(); 
178                   it != aXmlHandler->myListOfHypothesesSets.end();
179                   ++it ) {
180               myListOfHypothesesSets.insert( pos, *it );
181             }
182           }
183           else {
184             SUIT_MessageBox::critical(SMESHGUI::desktop(),
185                                       QObject::tr("INF_PARSE_ERROR"),
186                                       QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
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::warning(SMESHGUI::desktop(),
203                                  QObject::tr("SMESH_WRN_WARNING"),
204                                  aMess);
205         wc.resume();
206       }
207     }
208   }
209
210
211   QStringList GetAvailableHypotheses( const bool isAlgo, 
212                                       const int theDim,                          
213                                       const bool isAux,
214                                       const bool isNeedGeometry)
215   {
216     QStringList aHypList;
217
218     // Init list of available hypotheses, if needed
219     InitAvailableHypotheses();
220     bool checkGeometry = ( !isNeedGeometry && isAlgo );
221     // fill list of hypotheses/algorithms
222     THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
223     THypothesisDataMap::iterator anIter;
224     for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ ) {
225       HypothesisData* aData = anIter.value();
226       if ( ( theDim < 0 || aData->Dim.contains( theDim ) ) && aData->IsAux == isAux) {
227         if (checkGeometry) {
228           if (aData->IsNeedGeometry == isNeedGeometry)
229             aHypList.append(anIter.key());
230         }
231         else {
232           aHypList.append(anIter.key());
233         }
234       }
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     QList<HypothesesSet*>::iterator hypoSet;
248     for ( hypoSet  = myListOfHypothesesSets.begin(); 
249           hypoSet != myListOfHypothesesSets.end();
250           ++hypoSet ) {
251       HypothesesSet* aSet = *hypoSet;
252       if ( aSet && aSet->AlgoList.count() ) {
253         aSetNameList.append( aSet->HypoSetName );
254       }
255     }
256     
257     return aSetNameList;
258   }
259
260   HypothesesSet* GetHypothesesSet(const QString& theSetName)
261   {
262     QList<HypothesesSet*>::iterator hypoSet;
263     for ( hypoSet  = myListOfHypothesesSets.begin(); 
264           hypoSet != myListOfHypothesesSets.end();
265           ++hypoSet ) {
266       HypothesesSet* aSet = *hypoSet;
267       if ( aSet && aSet->HypoSetName == theSetName )
268         return aSet;
269     }
270     return 0;
271   }
272
273   HypothesisData* GetHypothesisData (const QString& aHypType)
274   {
275     HypothesisData* aHypData = 0;
276
277     // Init list of available hypotheses, if needed
278     InitAvailableHypotheses();
279
280     if (myHypothesesMap.find(aHypType) != myHypothesesMap.end()) {
281       aHypData = myHypothesesMap[aHypType];
282     }
283     else if (myAlgorithmsMap.find(aHypType) != myAlgorithmsMap.end()) {
284       aHypData = myAlgorithmsMap[aHypType];
285     }
286     return aHypData;
287   }
288
289   bool IsAvailableHypothesis(const HypothesisData* algoData,
290                              const QString&        hypType,
291                              bool&                 isAuxiliary)
292   {
293     isAuxiliary = false;
294     if ( !algoData )
295       return false;
296     if ( algoData->NeededHypos.contains( hypType ))
297       return true;
298     if ( algoData->OptionalHypos.contains( hypType)) {
299       isAuxiliary = true;
300       return true;
301     }
302     return false;
303   }
304
305   bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
306                              const HypothesisData* algo2Data)
307   {
308     if ( !algo1Data || !algo2Data )
309       return false;
310     const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
311     if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
312       algoIn = algo2Data; algoMain = algo1Data;
313     }
314     // look for any output type of algoIn between input types of algoMain
315     QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
316     for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
317       if ( algoMain->InputTypes.contains( *inElemType ))
318         return true;
319     return false;
320   }
321
322   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
323   {
324     if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
325
326     SMESHGUI_GenericHypothesisCreator* aCreator = 0;
327
328     // check, if creator for this hypothesis type already exists
329     if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
330       aCreator = myHypCreatorMap[aHypType];
331     }
332     else {
333       // 1. Init list of available hypotheses, if needed
334       InitAvailableHypotheses();
335
336       // 2. Get names of plugin libraries
337       HypothesisData* aHypData = GetHypothesisData(aHypType);
338       if (!aHypData) 
339         return aCreator;
340       QString aClientLibName = aHypData->ClientLibName;
341       QString aServerLibName = aHypData->ServerLibName;
342
343       // 3. Load Client Plugin Library
344       try {
345         // load plugin library
346         if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
347         LibHandle libHandle = LoadLib( aClientLibName.toLatin1().data() );
348         if (!libHandle) {
349           // report any error, if occured
350           if ( MYDEBUG ) {
351 #ifdef WIN32
352             const char* anError = "Can't load client meshers plugin library";
353 #else
354             const char* anError = dlerror();      
355 #endif
356             MESSAGE(anError);
357           }
358         }
359         else {
360           // get method, returning hypothesis creator
361           if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
362           typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
363             ( const QString& );
364           GetHypothesisCreator procHandle =
365             (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
366           if (!procHandle) {
367             if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
368             UnLoadLib(libHandle);
369           }
370           else {
371             // get hypothesis creator
372             if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
373             aCreator = procHandle( aHypType );
374             if (!aCreator) {
375               if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
376             }
377             else {
378               // map hypothesis creator to a hypothesis name
379               myHypCreatorMap[aHypType] = aCreator;
380             }
381           }
382         }
383       }
384       catch (const SALOME::SALOME_Exception& S_ex) {
385         SalomeApp_Tools::QtCatchCorbaException(S_ex);
386       }
387     }
388
389     return aCreator;
390   }
391
392
393   SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
394                                                const QString& aHypName,
395                                                const bool isAlgo)
396   {
397     if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() << 
398                         " with name " << aHypName.toLatin1().data());
399     HypothesisData* aHypData = GetHypothesisData(aHypType);
400     QString aServLib = aHypData->ServerLibName;
401     try {
402       SMESH::SMESH_Hypothesis_var aHypothesis;
403       aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
404                                                               aServLib.toLatin1().data());
405       if (!aHypothesis->_is_nil()) {
406         _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
407         if (aHypSObject) {
408           if (!aHypName.isEmpty())
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 } // end of namespace SMESH