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