Salome HOME
35b8a567d54e9e93932a3b92eb82fbc2a8e6ac14
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_HypothesesUtils.cxx
1 // SMESH SMESHGUI : GUI for SMESH component
2 //
3 // Copyright (C) 2003  CEA
4 //
5 // This library is free software; you can redistribute it and/or 
6 // modify it under the terms of the GNU Lesser General Public 
7 // License as published by the Free Software Foundation; either 
8 // version 2.1 of the License. 
9 //
10 // This library is distributed in the hope that it will be useful, 
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 // Lesser General Public License for more details. 
14 //
15 // You should have received a copy of the GNU Lesser General Public 
16 // License along with this library; if not, write to the Free Software 
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 // File   : SMESHGUI_HypothesesUtils.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
23 //
24
25 // SMESH includes
26 #include "SMESHGUI_HypothesesUtils.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_Hypotheses.h"
30 #include "SMESHGUI_XmlHandler.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_GEOMGenUtils.h"
33
34 // SALOME GUI includes
35 #include <SUIT_Desktop.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_OverrideCursor.h>
38 #include <SUIT_ResourceMgr.h>
39
40 #include <SalomeApp_Study.h>
41 #include <SalomeApp_Tools.h>
42
43 // SALOME KERNEL includes
44 #include <utilities.h>
45
46 // STL includes
47 #include <string>
48
49 // Qt includes
50 #include <QMap>
51 //#include <QList>
52
53 // Other includes
54 #ifdef WNT
55 #include <windows.h>
56 #else
57 #include <dlfcn.h>
58 #endif
59
60 #ifdef WNT
61 #define LibHandle HMODULE
62 #define LoadLib( name ) LoadLibrary( name )
63 #define GetProc GetProcAddress
64 #define UnLoadLib( handle ) FreeLibrary( handle );
65 #else
66 #define LibHandle void*
67 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
68 #define GetProc dlsym
69 #define UnLoadLib( handle ) dlclose( handle );
70 #endif
71
72 #ifdef _DEBUG_
73 static int MYDEBUG = 0;
74 #else
75 static int MYDEBUG = 0;
76 #endif
77
78 namespace SMESH
79 {
80   typedef QMap<std::string,HypothesisData*> THypothesisDataMap;
81   THypothesisDataMap myHypothesesMap;
82   THypothesisDataMap myAlgorithmsMap;
83
84   typedef QMap<std::string,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
85   THypCreatorMap myHypCreatorMap;
86
87   std::list<HypothesesSet*> myListOfHypothesesSets;
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
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         {
146           SUIT_MessageBox::critical(SMESHGUI::desktop(),
147                                     QObject::tr("SMESH_WRN_WARNING"),
148                                     QObject::tr("MESHERS_FILE_NO_VARIABLE"));
149           return;
150         }
151
152       // loop on files in HypsXml
153       QString aNoAccessFiles;
154       for (int i = 0; i < HypsXmlList.count(); i++) {
155         QString HypsXml = HypsXmlList[ i ];
156
157         // Find full path to the resource XML file
158         QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
159         if ( xmlFile.isEmpty() ) // try PLUGIN resources
160           xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
161         
162         QFile file (xmlFile);
163         if (file.exists() && file.open(QIODevice::ReadOnly)) {
164           file.close();
165
166           SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
167           ASSERT(aXmlHandler);
168
169           QXmlInputSource source (&file);
170           QXmlSimpleReader reader;
171           reader.setContentHandler(aXmlHandler);
172           reader.setErrorHandler(aXmlHandler);
173           bool ok = reader.parse(source);
174           file.close();
175           if (ok) {
176             myHypothesesMap.unite( QMap<std::string,HypothesisData*>( aXmlHandler->myHypothesesMap ) );
177             myAlgorithmsMap.unite( QMap<std::string,HypothesisData*>( aXmlHandler->myAlgorithmsMap ) );
178             myListOfHypothesesSets.splice( myListOfHypothesesSets.begin(),
179                                            aXmlHandler->myListOfHypothesesSets );
180           }
181           else {
182             SUIT_MessageBox::critical(SMESHGUI::desktop(),
183                                       QObject::tr("INF_PARSE_ERROR"),
184                                       QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
185           }
186         }
187         else {
188           if (aNoAccessFiles.isEmpty())
189             aNoAccessFiles = xmlFile;
190           else
191             aNoAccessFiles += ", " + xmlFile;
192         }
193       } // end loop
194
195
196       if (!aNoAccessFiles.isEmpty()) {
197         QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
198         aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
199         wc.suspend();
200         SUIT_MessageBox::warning(SMESHGUI::desktop(),
201                                  QObject::tr("SMESH_WRN_WARNING"),
202                                  aMess);
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.value();
225         if ( ( theDim < 0 || aData->Dim.contains( theDim ) ) && aData->IsAux == isAux)
226           if (checkGeometry){
227             if (aData->IsNeedGeometry == isNeedGeometry)
228               aHypList.append(anIter.key().c_str());
229           }
230           else
231             aHypList.append(anIter.key().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     std::list<HypothesesSet*>::iterator hypoSet = myListOfHypothesesSets.begin();
245     //QList<HypothesesSet*>::iterator hypoSet = myListOfHypothesesSets.begin();
246     for ( ; hypoSet != myListOfHypothesesSets.end(); ++hypoSet )
247       {
248         HypothesesSet* aSet = *hypoSet;
249         if ( aSet && aSet->AlgoList.count() ) {
250           aSetNameList.append( aSet->HypoSetName );
251         }
252       }
253
254     return aSetNameList;
255   }
256
257   HypothesesSet* GetHypothesesSet(const QString& theSetName)
258   {
259     std::list<HypothesesSet*>::iterator hypoSet = myListOfHypothesesSets.begin();
260     //QList<HypothesesSet*>::iterator hypoSet = myListOfHypothesesSets.begin();
261     for ( ; hypoSet != myListOfHypothesesSets.end(); ++hypoSet )
262       {
263         HypothesesSet* aSet = *hypoSet;
264         if ( aSet && aSet->HypoSetName == theSetName )
265           return aSet;
266       }
267     return 0;
268   }
269
270   HypothesisData* GetHypothesisData (const QString& aHypType)
271   {
272     HypothesisData* aHypData = 0;
273
274     // Init list of available hypotheses, if needed
275     InitAvailableHypotheses();
276
277     THypothesisDataMap::iterator type_data = myHypothesesMap.find(aHypType.toLatin1().data());
278     if (type_data != myHypothesesMap.end()) {
279       aHypData = type_data.value();
280     }
281     else {
282       type_data = myAlgorithmsMap.find(aHypType.toLatin1().data());
283       if (type_data != myAlgorithmsMap.end())
284         aHypData = type_data.value();
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.toLatin1().data()) != myHypCreatorMap.end()) {
330       aCreator = myHypCreatorMap[aHypType.toLatin1().data()];
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             {
352 #ifdef WIN32
353               const char* anError = "Can't load client meshers plugin library";
354 #else
355               const char* anError = dlerror();    
356 #endif
357               MESSAGE(anError);
358             }
359         }
360         else {
361           // get method, returning hypothesis creator
362           if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
363           typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
364             ( const QString& );
365           GetHypothesisCreator procHandle =
366             (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
367           if (!procHandle) {
368             if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
369             UnLoadLib(libHandle);
370           }
371           else {
372             // get hypothesis creator
373             if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
374             aCreator = procHandle( aHypType );
375             if (!aCreator) {
376               if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
377             }
378             else {
379               // map hypothesis creator to a hypothesis name
380               myHypCreatorMap[aHypType.toLatin1().data()] = aCreator;
381             }
382           }
383         }
384       }
385       catch (const SALOME::SALOME_Exception& S_ex) {
386         SalomeApp_Tools::QtCatchCorbaException(S_ex);
387       }
388     }
389
390     return aCreator;
391   }
392
393
394   SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
395                                                const QString& aHypName,
396                                                const bool isAlgo)
397   {
398     if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() << 
399                         " with name " << aHypName.toLatin1().data());
400     HypothesisData* aHypData = GetHypothesisData(aHypType);
401     QString aServLib = aHypData->ServerLibName;
402     try {
403       SMESH::SMESH_Hypothesis_var aHypothesis;
404       aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
405                                                               aServLib.toLatin1().data());
406       if (!aHypothesis->_is_nil()) {
407         _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
408         if (aHypSObject) {
409           if (!aHypName.isEmpty())
410             SMESH::SetName(aHypSObject, aHypName);
411           SMESHGUI::GetSMESHGUI()->updateObjBrowser();
412           return aHypothesis._retn();
413         }
414       }
415     } catch (const SALOME::SALOME_Exception & S_ex) {
416       SalomeApp_Tools::QtCatchCorbaException(S_ex);
417     }
418
419     return SMESH::SMESH_Hypothesis::_nil();
420   }
421
422
423   bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
424   {
425     if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
426     int res = SMESH::HYP_UNKNOWN_FATAL;
427     SUIT_OverrideCursor wc;
428
429     if (!aMesh->_is_nil()) {
430       _PTR(SObject) SM = SMESH::FindSObject(aMesh);
431       GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
432       try {
433         res = aMesh->AddHypothesis(aShapeObject, aHyp);
434         if (res < SMESH::HYP_UNKNOWN_FATAL) {
435           _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
436           if (SM && aSH) {
437             SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
438           }
439         }
440         if (res > SMESH::HYP_OK) {
441           wc.suspend();
442           processHypothesisStatus(res, aHyp, true);
443           wc.resume();
444         }
445       }
446       catch(const SALOME::SALOME_Exception& S_ex) {
447         wc.suspend();
448         SalomeApp_Tools::QtCatchCorbaException(S_ex);
449         res = SMESH::HYP_UNKNOWN_FATAL;
450       }
451     }
452     return res < SMESH::HYP_UNKNOWN_FATAL;
453   }
454
455
456   bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
457   {
458     if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
459     int res = SMESH::HYP_UNKNOWN_FATAL;
460     SUIT_OverrideCursor wc;
461
462     if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
463       try {
464         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
465         _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
466         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
467         if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil()) {
468           res = aMesh->AddHypothesis(aShapeObject, aHyp);
469           if (res < SMESH::HYP_UNKNOWN_FATAL)  {
470             _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
471             if (meshSO)
472               SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
473           }
474           if (res > SMESH::HYP_OK) {
475             wc.suspend();
476             processHypothesisStatus(res, aHyp, true);
477             wc.resume();
478           }
479         }
480         else {
481           SCRUTE(aHyp->_is_nil());
482           SCRUTE(aMesh->_is_nil());
483           SCRUTE(!SsubM);
484           SCRUTE(aShapeObject->_is_nil());
485         }
486       }
487       catch(const SALOME::SALOME_Exception& S_ex) {
488         wc.suspend();
489         SalomeApp_Tools::QtCatchCorbaException(S_ex);
490         res = SMESH::HYP_UNKNOWN_FATAL;
491       }
492     }
493     else {
494       SCRUTE(aSubMesh->_is_nil());
495       SCRUTE(aHyp->_is_nil());
496     }
497     return res < SMESH::HYP_UNKNOWN_FATAL;
498   }
499
500   bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
501   {
502     int res = SMESH::HYP_UNKNOWN_FATAL;
503     SUIT_OverrideCursor wc;
504
505     try {
506       _PTR(Study) aStudy = GetActiveStudyDocument();
507       _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
508       if( aHypObj )
509         {
510           _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
511           _PTR(SObject) aRealHypo;
512           if( aHypObj->ReferencedObject( aRealHypo ) )
513             {
514               SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
515               RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
516             }
517           else
518             {
519               SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
520               SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
521               for( int i = 0; i < meshList.size(); i++ )
522                 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
523             }
524         }
525     }
526     catch(const SALOME::SALOME_Exception& S_ex)
527       {
528         wc.suspend();
529         SalomeApp_Tools::QtCatchCorbaException(S_ex);
530         res = SMESH::HYP_UNKNOWN_FATAL;
531       }
532     return res < SMESH::HYP_UNKNOWN_FATAL;
533   }
534
535   bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
536                                           SMESH::SMESH_Hypothesis_ptr anHyp)
537   {
538     SALOMEDS::GenericAttribute_var anAttr;
539     SALOMEDS::AttributeIOR_var anIOR;
540     int res = SMESH::HYP_UNKNOWN_FATAL;
541     SUIT_OverrideCursor wc;
542
543     if (MorSM) {
544       try {
545         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
546         SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
547         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
548         
549         if (!aSubMesh->_is_nil())
550           aMesh = aSubMesh->GetFather();
551         
552         if (!aMesh->_is_nil()) {    
553           if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
554             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
555             if (res < SMESH::HYP_UNKNOWN_FATAL) {
556               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
557               if (meshSO)
558                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
559             }
560             
561           }
562           else if(!aMesh->HasShapeToMesh()){
563             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
564             if (res < SMESH::HYP_UNKNOWN_FATAL) {
565               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
566               if (meshSO)
567                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);              
568             }
569           }
570           if (res > SMESH::HYP_OK) {
571             wc.suspend();
572             processHypothesisStatus(res, anHyp, false);
573             wc.resume();
574           }
575         }
576       } catch(const SALOME::SALOME_Exception& S_ex) {
577         wc.suspend();
578         SalomeApp_Tools::QtCatchCorbaException(S_ex);
579         res = SMESH::HYP_UNKNOWN_FATAL;
580       }
581     }
582     return res < SMESH::HYP_UNKNOWN_FATAL;
583   }
584
585   SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
586   {
587     SObjectList listSOmesh;
588     listSOmesh.resize(0);
589
590     unsigned int index = 0;
591     if (!AlgoOrHyp->_is_nil()) {
592       _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
593       if (SO_Hypothesis) {
594         SObjectList listSO =
595           SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
596
597         if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
598         for (unsigned int i = 0; i < listSO.size(); i++) {
599           _PTR(SObject) SO = listSO[i];
600           if (SO) {
601             _PTR(SObject) aFather = SO->GetFather();
602             if (aFather) {
603               _PTR(SObject) SOfatherFather = aFather->GetFather();
604               if (SOfatherFather) {
605                 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
606                 index++;
607                 listSOmesh.resize(index);
608                 listSOmesh[index - 1] = SOfatherFather;
609               }
610             }
611           }
612         }
613       }
614     }
615     if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
616     return listSOmesh;
617   }
618
619 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
620   QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
621   {
622     QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
623     for ( int i = 0; i < errors.length(); ++i ) {
624       const SMESH::AlgoStateError & error = errors[ i ];
625       const bool hasAlgo = ( strlen( error.algoName ) != 0 );
626       QString msg;
627       if ( !hasAlgo )
628         msg = QObject::tr( "STATE_ALGO_MISSING" );
629       else 
630         switch( error.state ) {
631           CASE2MESSAGE( HYP_MISSING );
632           CASE2MESSAGE( HYP_NOTCONFORM );
633           CASE2MESSAGE( HYP_BAD_PARAMETER );
634           CASE2MESSAGE( HYP_BAD_GEOMETRY );
635         default: continue;
636         }
637       // apply args to message:
638       // %1 - algo name
639       if ( hasAlgo )
640         msg = msg.arg( error.algoName.in() );
641       // %2 - dimension
642       msg = msg.arg( error.algoDim );
643       // %3 - global/local
644       msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
645       // %4 - hypothesis dim == algoDim
646       msg = msg.arg( error.algoDim );
647
648       if ( i ) resMsg += ";\n";
649       resMsg += msg;
650     }
651     return resMsg;
652   }
653 } // end of namespace SMESH