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