Salome HOME
Merge from V5_1_main 10/06/2010
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_HypothesesUtils.cxx
1 //  Copyright (C) 2007-2010  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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_HypothesesUtils.cxx
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_HypothesesUtils.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Hypotheses.h"
32 #include "SMESHGUI_XmlHandler.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
35
36 // SALOME GUI includes
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SUIT_ResourceMgr.h>
41
42 #include <SalomeApp_Study.h>
43 #include <SalomeApp_Tools.h>
44
45 // SALOME KERNEL includes
46 #include <utilities.h>
47
48 // STL includes
49 #include <string>
50
51 // Qt includes
52 #include <QMap>
53 //#include <QList>
54
55 // Other includes
56 #ifdef WNT
57 #include <windows.h>
58 #else
59 #include <dlfcn.h>
60 #endif
61
62 #ifdef WNT
63 #define LibHandle HMODULE
64 #define LoadLib( name ) LoadLibrary( name )
65 #define GetProc GetProcAddress
66 #define UnLoadLib( handle ) FreeLibrary( handle );
67 #else
68 #define LibHandle void*
69 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
70 #define GetProc dlsym
71 #define UnLoadLib( handle ) dlclose( handle );
72 #endif
73
74 #ifdef _DEBUG_
75 static int MYDEBUG = 0;
76 #else
77 static int MYDEBUG = 0;
78 #endif
79
80 namespace SMESH
81 {
82   typedef QMap<QString,HypothesisData*> THypothesisDataMap;
83   THypothesisDataMap myHypothesesMap;
84   THypothesisDataMap myAlgorithmsMap;
85
86   // BUG 0020378
87   //typedef QMap<QString,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
88   //THypCreatorMap myHypCreatorMap;
89
90   QList<HypothesesSet*> myListOfHypothesesSets;
91
92   void processHypothesisStatus(const int theHypStatus,
93                                SMESH::SMESH_Hypothesis_ptr theHyp,
94                                const bool theIsAddition)
95   {
96     if (theHypStatus > SMESH::HYP_OK) {
97       // get Hyp name
98       QString aHypName ("NULL Hypothesis");
99       if (!CORBA::is_nil(theHyp)) {
100         _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
101         if (Shyp)
102           // name in study
103           aHypName = Shyp->GetName().c_str();
104         else
105           // label in xml file
106           aHypName = GetHypothesisData(theHyp->GetName())->Label;
107       }
108
109       // message
110       bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
111       QString aMsg;
112       if (theIsAddition)
113         aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
114       else
115         aMsg = (isFatal ? "SMESH_CANT_RM_HYP"  : "SMESH_RM_HYP_WRN");
116
117       aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName) +
118         QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
119
120       if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO ) // PAL18501
121         aMsg = aMsg.arg( GetHypothesisData(theHyp->GetName())->Dim[0] );
122
123       SUIT_MessageBox::warning(SMESHGUI::desktop(),
124                                QObject::tr("SMESH_WRN_WARNING"),
125                                aMsg);
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 = HypsXml.split(":", QString::SkipEmptyParts);
145       if (HypsXmlList.count() == 0) {
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( aXmlHandler->myHypothesesMap );
177             myAlgorithmsMap.unite( aXmlHandler->myAlgorithmsMap );
178             QList<HypothesesSet*>::iterator it, pos = myListOfHypothesesSets.begin();
179             for ( it = aXmlHandler->myListOfHypothesesSets.begin(); 
180                   it != aXmlHandler->myListOfHypothesesSets.end();
181                   ++it ) {
182               myListOfHypothesesSets.insert( pos, *it );
183             }
184           }
185           else {
186             SUIT_MessageBox::critical(SMESHGUI::desktop(),
187                                       QObject::tr("INF_PARSE_ERROR"),
188                                       QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
189           }
190     delete aXmlHandler;
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::warning(SMESHGUI::desktop(),
206                                  QObject::tr("SMESH_WRN_WARNING"),
207                                  aMess);
208         wc.resume();
209       }
210     }
211   }
212
213
214   QStringList GetAvailableHypotheses( const bool isAlgo, 
215                                       const int theDim,                          
216                                       const bool isAux,
217                                       const bool isNeedGeometry)
218   {
219     QStringList aHypList;
220
221     // Init list of available hypotheses, if needed
222     InitAvailableHypotheses();
223     bool checkGeometry = ( !isNeedGeometry && isAlgo );
224     // fill list of hypotheses/algorithms
225     THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
226     THypothesisDataMap::iterator anIter;
227     for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ ) {
228       HypothesisData* aData = anIter.value();
229       if ( ( theDim < 0 || aData->Dim.contains( theDim ) ) && aData->IsAux == isAux) {
230         if (checkGeometry) {
231           if (aData->IsNeedGeometry == isNeedGeometry)
232             aHypList.append(anIter.key());
233         }
234         else {
235           aHypList.append(anIter.key());
236         }
237       }
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     QList<HypothesesSet*>::iterator hypoSet;
251     for ( hypoSet  = myListOfHypothesesSets.begin(); 
252           hypoSet != myListOfHypothesesSets.end();
253           ++hypoSet ) {
254       HypothesesSet* aSet = *hypoSet;
255       if ( aSet && aSet->count( true ) ) {
256         aSetNameList.append( aSet->name() );
257       }
258     }
259     
260     return aSetNameList;
261   }
262
263   HypothesesSet* GetHypothesesSet(const QString& theSetName)
264   {
265     QList<HypothesesSet*>::iterator hypoSet;
266     for ( hypoSet  = myListOfHypothesesSets.begin(); 
267           hypoSet != myListOfHypothesesSets.end();
268           ++hypoSet ) {
269       HypothesesSet* aSet = *hypoSet;
270       if ( aSet && aSet->name() == theSetName )
271         return aSet;
272     }
273     return 0;
274   }
275
276   HypothesisData* GetHypothesisData (const QString& aHypType)
277   {
278     HypothesisData* aHypData = 0;
279
280     // Init list of available hypotheses, if needed
281     InitAvailableHypotheses();
282
283     if (myHypothesesMap.find(aHypType) != myHypothesesMap.end()) {
284       aHypData = myHypothesesMap[aHypType];
285     }
286     else if (myAlgorithmsMap.find(aHypType) != myAlgorithmsMap.end()) {
287       aHypData = myAlgorithmsMap[aHypType];
288     }
289     return aHypData;
290   }
291
292   bool IsAvailableHypothesis(const HypothesisData* algoData,
293                              const QString&        hypType,
294                              bool&                 isAuxiliary)
295   {
296     isAuxiliary = false;
297     if ( !algoData )
298       return false;
299     if ( algoData->NeededHypos.contains( hypType ))
300       return true;
301     if ( algoData->OptionalHypos.contains( hypType)) {
302       isAuxiliary = true;
303       return true;
304     }
305     return false;
306   }
307
308   bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
309                              const HypothesisData* algo2Data)
310   {
311     if ( !algo1Data || !algo2Data )
312       return false;
313     const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
314     if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
315       algoIn = algo2Data; algoMain = algo1Data;
316     }
317     // look for any output type of algoIn between input types of algoMain
318     QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
319     for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
320       if ( algoMain->InputTypes.contains( *inElemType ))
321         return true;
322     return false;
323   }
324
325   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
326   {
327     if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
328
329     SMESHGUI_GenericHypothesisCreator* aCreator = 0;
330
331     // check, if creator for this hypothesis type already exists
332     // BUG 0020378
333     //if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
334     //  aCreator = myHypCreatorMap[aHypType];
335     //}
336     //else
337     {
338       // 1. Init list of available hypotheses, if needed
339       InitAvailableHypotheses();
340
341       // 2. Get names of plugin libraries
342       HypothesisData* aHypData = GetHypothesisData(aHypType);
343       if (!aHypData) 
344         return aCreator;
345
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.toLatin1().data() );
354         if (!libHandle) {
355           // report any error, if occured
356           if ( MYDEBUG ) {
357 #ifdef WIN32
358             const char* anError = "Can't load client meshers plugin library";
359 #else
360             const char* anError = dlerror();      
361 #endif
362             MESSAGE(anError);
363           }
364         }
365         else {
366           // get method, returning hypothesis creator
367           if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
368           typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
369             ( const QString& );
370           GetHypothesisCreator procHandle =
371             (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
372           if (!procHandle) {
373             if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
374             UnLoadLib(libHandle);
375           }
376           else {
377             // get hypothesis creator
378             if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
379             aCreator = procHandle( aHypType );
380             if (!aCreator) {
381               if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
382             }
383             else {
384               // map hypothesis creator to a hypothesis name
385               // BUG 0020378
386               //myHypCreatorMap[aHypType] = aCreator;
387             }
388           }
389         }
390       }
391       catch (const SALOME::SALOME_Exception& S_ex) {
392         SalomeApp_Tools::QtCatchCorbaException(S_ex);
393       }
394     }
395
396     return aCreator;
397   }
398
399
400   SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
401                                                const QString& aHypName,
402                                                const bool isAlgo)
403   {
404     if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() << 
405                         " with name " << aHypName.toLatin1().data());
406     HypothesisData* aHypData = GetHypothesisData(aHypType);
407     QString aServLib = aHypData->ServerLibName;
408     try {
409       SMESH::SMESH_Hypothesis_var aHypothesis;
410       aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
411                                                               aServLib.toLatin1().data());
412       if (!aHypothesis->_is_nil()) {
413         _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
414         if (aHypSObject) {
415           if (!aHypName.isEmpty())
416             SMESH::SetName(aHypSObject, aHypName);
417           SMESHGUI::Modified();
418           SMESHGUI::GetSMESHGUI()->updateObjBrowser();
419           return aHypothesis._retn();
420         }
421       }
422     } catch (const SALOME::SALOME_Exception & S_ex) {
423       SalomeApp_Tools::QtCatchCorbaException(S_ex);
424     }
425
426     return SMESH::SMESH_Hypothesis::_nil();
427   }
428
429
430   bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
431   {
432     if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
433     int res = SMESH::HYP_UNKNOWN_FATAL;
434     SUIT_OverrideCursor wc;
435
436     if (!aMesh->_is_nil()) {
437       _PTR(SObject) SM = SMESH::FindSObject(aMesh);
438       GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
439       try {
440         res = aMesh->AddHypothesis(aShapeObject, aHyp);
441         if (res < SMESH::HYP_UNKNOWN_FATAL) {
442           _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
443           if (SM && aSH) {
444             SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
445           }
446         }
447         if (res > SMESH::HYP_OK) {
448           wc.suspend();
449           processHypothesisStatus(res, aHyp, true);
450           wc.resume();
451         }
452       }
453       catch(const SALOME::SALOME_Exception& S_ex) {
454         wc.suspend();
455         SalomeApp_Tools::QtCatchCorbaException(S_ex);
456         res = SMESH::HYP_UNKNOWN_FATAL;
457       }
458     }
459     return res < SMESH::HYP_UNKNOWN_FATAL;
460   }
461
462
463   bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
464   {
465     if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
466     int res = SMESH::HYP_UNKNOWN_FATAL;
467     SUIT_OverrideCursor wc;
468
469     if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
470       try {
471         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
472         _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
473         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
474         if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil()) {
475           res = aMesh->AddHypothesis(aShapeObject, aHyp);
476           if (res < SMESH::HYP_UNKNOWN_FATAL)  {
477             _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
478             if (meshSO)
479               SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
480           }
481           if (res > SMESH::HYP_OK) {
482             wc.suspend();
483             processHypothesisStatus(res, aHyp, true);
484             wc.resume();
485           }
486         }
487         else {
488           SCRUTE(aHyp->_is_nil());
489           SCRUTE(aMesh->_is_nil());
490           SCRUTE(!SsubM);
491           SCRUTE(aShapeObject->_is_nil());
492         }
493       }
494       catch(const SALOME::SALOME_Exception& S_ex) {
495         wc.suspend();
496         SalomeApp_Tools::QtCatchCorbaException(S_ex);
497         res = SMESH::HYP_UNKNOWN_FATAL;
498       }
499     }
500     else {
501       SCRUTE(aSubMesh->_is_nil());
502       SCRUTE(aHyp->_is_nil());
503     }
504     return res < SMESH::HYP_UNKNOWN_FATAL;
505   }
506
507   bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
508   {
509     int res = SMESH::HYP_UNKNOWN_FATAL;
510     SUIT_OverrideCursor wc;
511
512     try {
513       _PTR(Study) aStudy = GetActiveStudyDocument();
514       _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
515       if( aHypObj )
516         {
517           _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
518           _PTR(SObject) aRealHypo;
519           if( aHypObj->ReferencedObject( aRealHypo ) )
520             {
521               SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
522               RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
523             }
524           else
525             {
526               SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
527               SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
528               for( int i = 0; i < meshList.size(); i++ )
529                 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
530             }
531         }
532     }
533     catch(const SALOME::SALOME_Exception& S_ex)
534       {
535         wc.suspend();
536         SalomeApp_Tools::QtCatchCorbaException(S_ex);
537         res = SMESH::HYP_UNKNOWN_FATAL;
538       }
539     return res < SMESH::HYP_UNKNOWN_FATAL;
540   }
541
542   bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
543                                           SMESH::SMESH_Hypothesis_ptr anHyp)
544   {
545     SALOMEDS::GenericAttribute_var anAttr;
546     SALOMEDS::AttributeIOR_var anIOR;
547     int res = SMESH::HYP_UNKNOWN_FATAL;
548     SUIT_OverrideCursor wc;
549
550     if (MorSM) {
551       try {
552         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
553         SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
554         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
555         
556         if (!aSubMesh->_is_nil())
557           aMesh = aSubMesh->GetFather();
558         
559         if (!aMesh->_is_nil()) {    
560           if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
561             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
562             if (res < SMESH::HYP_UNKNOWN_FATAL) {
563               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
564               if (meshSO)
565                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
566             }
567             
568           }
569           else if(!aMesh->HasShapeToMesh()){
570             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
571             if (res < SMESH::HYP_UNKNOWN_FATAL) {
572               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
573               if (meshSO)
574                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);              
575             }
576           }
577           if (res > SMESH::HYP_OK) {
578             wc.suspend();
579             processHypothesisStatus(res, anHyp, false);
580             wc.resume();
581           }
582         }
583       } catch(const SALOME::SALOME_Exception& S_ex) {
584         wc.suspend();
585         SalomeApp_Tools::QtCatchCorbaException(S_ex);
586         res = SMESH::HYP_UNKNOWN_FATAL;
587       }
588     }
589     return res < SMESH::HYP_UNKNOWN_FATAL;
590   }
591
592   SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
593   {
594     SObjectList listSOmesh;
595     listSOmesh.resize(0);
596
597     unsigned int index = 0;
598     if (!AlgoOrHyp->_is_nil()) {
599       _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
600       if (SO_Hypothesis) {
601         SObjectList listSO =
602           SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
603
604         if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
605         for (unsigned int i = 0; i < listSO.size(); i++) {
606           _PTR(SObject) SO = listSO[i];
607           if (SO) {
608             _PTR(SObject) aFather = SO->GetFather();
609             if (aFather) {
610               _PTR(SObject) SOfatherFather = aFather->GetFather();
611               if (SOfatherFather) {
612                 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
613                 index++;
614                 listSOmesh.resize(index);
615                 listSOmesh[index - 1] = SOfatherFather;
616               }
617             }
618           }
619         }
620       }
621     }
622     if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
623     return listSOmesh;
624   }
625
626 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
627   QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
628   {
629     QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
630     for ( int i = 0; i < errors.length(); ++i ) {
631       const SMESH::AlgoStateError & error = errors[ i ];
632       const bool hasAlgo = ( strlen( error.algoName ) != 0 );
633       QString msg;
634       if ( !hasAlgo )
635         msg = QObject::tr( "STATE_ALGO_MISSING" );
636       else 
637         switch( error.state ) {
638           CASE2MESSAGE( HYP_MISSING );
639           CASE2MESSAGE( HYP_NOTCONFORM );
640           CASE2MESSAGE( HYP_BAD_PARAMETER );
641           CASE2MESSAGE( HYP_BAD_GEOMETRY );
642         default: continue;
643         }
644       // apply args to message:
645       // %1 - algo name
646       if ( hasAlgo )
647         msg = msg.arg( error.algoName.in() );
648       // %2 - dimension
649       msg = msg.arg( error.algoDim );
650       // %3 - global/local
651       msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
652       // %4 - hypothesis dim == algoDim
653       msg = msg.arg( error.algoDim );
654
655       if ( i ) resMsg += ";\n";
656       resMsg += msg;
657     }
658     return resMsg;
659   }
660 } // end of namespace SMESH