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