Salome HOME
7898e44e42a28a105c4ca812cfbf1e1726a8a04d
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_HypothesesUtils.cxx
1 // Copyright (C) 2007-2013  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 <QDir>
54 //#include <QList>
55
56
57 // Other includes
58 #ifdef WNT
59 #include <windows.h>
60 #else
61 #include <dlfcn.h>
62 #endif
63
64 #ifdef WNT
65 #define LibHandle HMODULE
66 #define LoadLib( name ) LoadLibrary( name )
67 #define GetProc GetProcAddress
68 #define UnLoadLib( handle ) FreeLibrary( handle );
69 #else
70 #define LibHandle void*
71 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
72 #define GetProc dlsym
73 #define UnLoadLib( handle ) dlclose( handle );
74 #endif
75
76 #ifdef _DEBUG_
77 static int MYDEBUG = 1;
78 #else
79 static int MYDEBUG = 0;
80 #endif
81
82 namespace SMESH
83 {
84   typedef IMap<QString,HypothesisData*> THypothesisDataMap;
85   THypothesisDataMap myHypothesesMap;
86   THypothesisDataMap myAlgorithmsMap;
87   
88   // BUG 0020378
89   //typedef QMap<QString,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
90   //THypCreatorMap myHypCreatorMap;
91
92   QList<HypothesesSet*> myListOfHypothesesSets;
93
94   void processHypothesisStatus(const int theHypStatus,
95                                SMESH::SMESH_Hypothesis_ptr theHyp,
96                                const bool theIsAddition)
97   {
98     if (theHypStatus > SMESH::HYP_OK) {
99       // get Hyp name
100       QString aHypName ("NULL Hypothesis");
101       if (!CORBA::is_nil(theHyp)) {
102         _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
103         if (Shyp)
104           // name in study
105           aHypName = Shyp->GetName().c_str();
106         else
107           // label in xml file
108           aHypName = GetHypothesisData(theHyp->GetName())->Label;
109       }
110
111       // message
112       bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
113       QString aMsg;
114       if (theIsAddition)
115         aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
116       else
117         aMsg = (isFatal ? "SMESH_CANT_RM_HYP"  : "SMESH_RM_HYP_WRN");
118
119       aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName) +
120         QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
121
122       if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO ) // PAL18501
123         aMsg = aMsg.arg( GetHypothesisData(theHyp->GetName())->Dim[0] );
124
125       SUIT_MessageBox::warning(SMESHGUI::desktop(),
126                                QObject::tr("SMESH_WRN_WARNING"),
127                                aMsg);
128     }
129   }
130
131   //================================================================================
132   /*!
133    * \brief Prepends dimension and appends '[custom]' to the name of hypothesis set
134    */
135   //================================================================================
136
137   static QString mangledHypoSetName(HypothesesSet* hypSet)
138   {
139     QString name = hypSet->name();
140
141     // prepend 'xD: '
142     int dim = hypSet->maxDim();
143     if ( dim > -1 )
144       name = QString("%1D: %2").arg(dim).arg(name);
145
146     // custom
147     if ( hypSet->getIsCustom() )
148       name = QString("%1 [custom]").arg(name);
149
150     return name;
151   }
152
153   //================================================================================
154   /*!
155    * \brief Removes dimension and '[custom]' from the name of hypothesis set
156    */
157   //================================================================================
158
159   static QString demangledHypoSetName(QString name)
160   {
161     name.remove(QRegExp("[0-3]D: "));
162     name.remove(" [custom]");
163     return name;
164   }
165
166   void InitAvailableHypotheses()
167   {
168     SUIT_OverrideCursor wc;
169     if (myHypothesesMap.empty() && myAlgorithmsMap.empty()) {
170       // Resource manager
171       SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
172       if (!resMgr) return;
173
174       // Find name of a resource XML file ("SMESH_Meshers.xml");
175       QString HypsXml;
176       char* cenv = getenv("SMESH_MeshersList");
177       if (cenv)
178         HypsXml.sprintf("%s", cenv);
179
180       QStringList HypsXmlList = HypsXml.split(":", QString::SkipEmptyParts);
181       if (HypsXmlList.count() == 0) {
182         SUIT_MessageBox::critical(SMESHGUI::desktop(),
183                                   QObject::tr("SMESH_WRN_WARNING"),
184                                   QObject::tr("MESHERS_FILE_NO_VARIABLE"));
185         return;
186       }
187       // get full names of xml files from HypsXmlList
188       QStringList xmlFiles;
189       xmlFiles.append( QDir::home().filePath("CustomMeshers.xml")); // may be inexistent
190       for (int i = 0; i < HypsXmlList.count(); i++) {
191         QString HypsXml = HypsXmlList[ i ];
192
193         // Find full path to the resource XML file
194         QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
195         if ( xmlFile.isEmpty() ) // try PLUGIN resources
196           xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
197         if ( !xmlFile.isEmpty() )
198           xmlFiles.append( xmlFile );
199       }
200
201       // loop on xmlFiles
202       QString aNoAccessFiles;
203       for (int i = 0; i < xmlFiles.count(); i++)
204       {
205         QString xmlFile = xmlFiles[ i ];
206         QFile file (xmlFile);
207         if (file.exists() && file.open(QIODevice::ReadOnly))
208         {
209           file.close();
210
211           SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
212           ASSERT(aXmlHandler);
213
214           QXmlInputSource source (&file);
215           QXmlSimpleReader reader;
216           reader.setContentHandler(aXmlHandler);
217           reader.setErrorHandler(aXmlHandler);
218           bool ok = reader.parse(source);
219           file.close();
220           if (ok) {
221
222             THypothesisDataMap::ConstIterator it1 = aXmlHandler->myHypothesesMap.begin();
223             
224             for( ;it1 != aXmlHandler->myHypothesesMap.end(); it1++)
225               myHypothesesMap.insert( it1.key(), it1.value() );
226             
227             it1 = aXmlHandler->myAlgorithmsMap.begin();
228             for( ;it1 != aXmlHandler->myAlgorithmsMap.end(); it1++)
229               myAlgorithmsMap.insert( it1.key(), it1.value() );
230             
231             QList<HypothesesSet*>::iterator it;
232             for ( it = aXmlHandler->myListOfHypothesesSets.begin(); 
233                   it != aXmlHandler->myListOfHypothesesSets.end();
234                   ++it )
235             {
236               (*it)->setIsCustom( i == 0 );
237               myListOfHypothesesSets.append( *it );
238             }
239           }
240           else {
241             SUIT_MessageBox::critical(SMESHGUI::desktop(),
242                                       QObject::tr("INF_PARSE_ERROR"),
243                                       QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
244           }
245           delete aXmlHandler;
246         }
247         else if ( i > 0 ) { // 1st is ~/CustomMeshers.xml
248           if (aNoAccessFiles.isEmpty())
249             aNoAccessFiles = xmlFile;
250           else
251             aNoAccessFiles += ", " + xmlFile;
252         }
253       } // end loop on xmlFiles
254
255
256       if (!aNoAccessFiles.isEmpty()) {
257         QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
258         aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
259         wc.suspend();
260         SUIT_MessageBox::warning(SMESHGUI::desktop(),
261                                  QObject::tr("SMESH_WRN_WARNING"),
262                                  aMess);
263         wc.resume();
264       }
265     }
266   }
267
268
269   QStringList GetAvailableHypotheses( const bool isAlgo, 
270                                       const int theDim,                          
271                                       const bool isAux,
272                                       const bool isNeedGeometry)
273   {
274     QStringList aHypList;
275
276     // Init list of available hypotheses, if needed
277     InitAvailableHypotheses();
278     bool checkGeometry = ( !isNeedGeometry && isAlgo );
279     // fill list of hypotheses/algorithms
280     THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
281     THypothesisDataMap::ConstIterator anIter;
282     for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ ) {
283       HypothesisData* aData = anIter.value();
284       if(!aData || aData->Label.isEmpty()) continue;
285       if ( ( theDim < 0 || aData->Dim.contains( theDim ) ) && aData->IsAux == isAux) {
286         if (checkGeometry) {
287           if (aData->IsNeedGeometry == isNeedGeometry)
288             aHypList.append(anIter.key());
289         }
290         else {
291           aHypList.append(anIter.key());
292         }
293       }
294     }
295     return aHypList;
296   }
297
298
299   QStringList GetHypothesesSets(int maxDim)
300   {
301     QStringList aSetNameList;
302
303     // Init list of available hypotheses, if needed
304     InitAvailableHypotheses();
305
306     QList<HypothesesSet*>::iterator hypoSet;
307     for ( hypoSet  = myListOfHypothesesSets.begin(); 
308           hypoSet != myListOfHypothesesSets.end();
309           ++hypoSet ) {
310       HypothesesSet* aSet = *hypoSet;
311       if ( aSet &&
312            ( aSet->count( true ) || aSet->count( false )) &&
313            aSet->maxDim() <= maxDim)
314       {
315         aSetNameList.append( mangledHypoSetName( aSet ));
316       }
317     }
318     aSetNameList.removeDuplicates();
319     aSetNameList.sort();
320
321     //  reverse order of aSetNameList
322     QStringList reversedNames;
323     for ( int i = 0; i < aSetNameList.count(); ++i )
324       reversedNames.prepend( aSetNameList[i] );
325     
326     return reversedNames;
327   }
328
329   HypothesesSet* GetHypothesesSet(const QString& theSetName)
330   {
331     QString name = demangledHypoSetName( theSetName );
332     QList<HypothesesSet*>::iterator hypoSet;
333     for ( hypoSet  = myListOfHypothesesSets.begin(); 
334           hypoSet != myListOfHypothesesSets.end();
335           ++hypoSet ) {
336       HypothesesSet* aSet = *hypoSet;
337       if ( aSet && aSet->name() == name )
338         return aSet;
339     }
340     return 0;
341   }
342
343   HypothesisData* GetHypothesisData (const QString& aHypType)
344   {
345     HypothesisData* aHypData = 0;
346
347     // Init list of available hypotheses, if needed
348     InitAvailableHypotheses();
349
350     if (myHypothesesMap.contains(aHypType)) {
351       aHypData = myHypothesesMap[aHypType];
352     }
353     else if (myAlgorithmsMap.contains(aHypType)) {
354       aHypData = myAlgorithmsMap[aHypType];
355     }
356     return aHypData;
357   }
358
359   bool IsAvailableHypothesis(const HypothesisData* algoData,
360                              const QString&        hypType,
361                              bool&                 isAuxiliary)
362   {
363     isAuxiliary = false;
364     if ( !algoData )
365       return false;
366     if ( algoData->NeededHypos.contains( hypType ))
367       return true;
368     if ( algoData->OptionalHypos.contains( hypType)) {
369       isAuxiliary = true;
370       return true;
371     }
372     return false;
373   }
374
375   bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
376                              const HypothesisData* algo2Data)
377   {
378     if ( !algo1Data || !algo2Data )
379       return false;
380     const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
381     if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
382       algoIn = algo2Data; algoMain = algo1Data;
383     }
384     // look for any output type of algoIn between input types of algoMain
385     QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
386     for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
387       if ( algoMain->InputTypes.contains( *inElemType ))
388         return true;
389     return false;
390   }
391
392   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
393   {
394     if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
395
396     SMESHGUI_GenericHypothesisCreator* aCreator = 0;
397
398     // check, if creator for this hypothesis type already exists
399     // BUG 0020378
400     //if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
401     //  aCreator = myHypCreatorMap[aHypType];
402     //}
403     //else
404     {
405       // 1. Init list of available hypotheses, if needed
406       InitAvailableHypotheses();
407
408       // 2. Get names of plugin libraries
409       HypothesisData* aHypData = GetHypothesisData(aHypType);
410       if (!aHypData) 
411         return aCreator;
412
413       QString aClientLibName = aHypData->ClientLibName;
414       QString aServerLibName = aHypData->ServerLibName;
415
416       // 3. Load Client Plugin Library
417       try {
418         // load plugin library
419         if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
420         LibHandle libHandle = LoadLib( aClientLibName.toLatin1().data() );
421         if (!libHandle) {
422           // report any error, if occured
423           {
424 #ifdef WIN32
425             const char* anError = "Can't load client meshers plugin library";
426 #else
427             const char* anError = dlerror();      
428 #endif
429             INFOS(anError); // always display this kind of error !
430           }
431         }
432         else {
433           // get method, returning hypothesis creator
434           if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
435           typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
436             ( const QString& );
437           GetHypothesisCreator procHandle =
438             (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
439           if (!procHandle) {
440             if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
441             UnLoadLib(libHandle);
442           }
443           else {
444             // get hypothesis creator
445             if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
446             aCreator = procHandle( aHypType );
447             if (!aCreator) {
448               if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
449             }
450             else {
451               // map hypothesis creator to a hypothesis name
452               // BUG 0020378
453               //myHypCreatorMap[aHypType] = aCreator;
454
455               //rnv : This dynamic property of the QObject stores the name of the plugin.
456               //      It is used to obtain plugin root dir environment variable
457               //      in the SMESHGUI_HypothesisDlg class. Plugin root dir environment 
458               //      variable is used to display documentation.
459               aCreator->setProperty(PLUGIN_NAME,aHypData->PluginName);
460             }
461           }
462         }
463       }
464       catch (const SALOME::SALOME_Exception& S_ex) {
465         SalomeApp_Tools::QtCatchCorbaException(S_ex);
466       }
467     }
468
469     return aCreator;
470   }
471
472
473   SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
474                                                const QString& aHypName,
475                                                const bool isAlgo)
476   {
477     if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() << 
478                         " with name " << aHypName.toLatin1().data());
479     HypothesisData* aHypData = GetHypothesisData(aHypType);
480     QString aServLib = aHypData->ServerLibName;
481     try {
482       SMESH::SMESH_Hypothesis_var aHypothesis;
483       aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
484                                                               aServLib.toLatin1().data());
485       if (!aHypothesis->_is_nil()) {
486         _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
487         if (aHypSObject) {
488           if (!aHypName.isEmpty())
489             SMESH::SetName(aHypSObject, aHypName);
490           SMESHGUI::Modified();
491           SMESHGUI::GetSMESHGUI()->updateObjBrowser();
492           return aHypothesis._retn();
493         }
494       }
495     } catch (const SALOME::SALOME_Exception & S_ex) {
496       SalomeApp_Tools::QtCatchCorbaException(S_ex);
497     }
498
499     return SMESH::SMESH_Hypothesis::_nil();
500   }
501
502
503   bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
504   {
505     if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
506     int res = SMESH::HYP_UNKNOWN_FATAL;
507     SUIT_OverrideCursor wc;
508
509     if (!aMesh->_is_nil()) {
510       _PTR(SObject) SM = SMESH::FindSObject(aMesh);
511       GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
512       try {
513         res = aMesh->AddHypothesis(aShapeObject, aHyp);
514         if (res < SMESH::HYP_UNKNOWN_FATAL) {
515           _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
516           if (SM && aSH) {
517             SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
518           }
519         }
520         if (res > SMESH::HYP_OK) {
521           wc.suspend();
522           processHypothesisStatus(res, aHyp, true);
523           wc.resume();
524         }
525       }
526       catch(const SALOME::SALOME_Exception& S_ex) {
527         wc.suspend();
528         SalomeApp_Tools::QtCatchCorbaException(S_ex);
529         res = SMESH::HYP_UNKNOWN_FATAL;
530       }
531     }
532     return res < SMESH::HYP_UNKNOWN_FATAL;
533   }
534
535
536   bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
537   {
538     if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
539     int res = SMESH::HYP_UNKNOWN_FATAL;
540     SUIT_OverrideCursor wc;
541
542     if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
543       try {
544         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
545         _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
546         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
547         if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil()) {
548           res = aMesh->AddHypothesis(aShapeObject, aHyp);
549           if (res < SMESH::HYP_UNKNOWN_FATAL)  {
550             _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
551             if (meshSO)
552               SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
553           }
554           if (res > SMESH::HYP_OK) {
555             wc.suspend();
556             processHypothesisStatus(res, aHyp, true);
557             wc.resume();
558           }
559         }
560         else {
561           SCRUTE(aHyp->_is_nil());
562           SCRUTE(aMesh->_is_nil());
563           SCRUTE(!SsubM);
564           SCRUTE(aShapeObject->_is_nil());
565         }
566       }
567       catch(const SALOME::SALOME_Exception& S_ex) {
568         wc.suspend();
569         SalomeApp_Tools::QtCatchCorbaException(S_ex);
570         res = SMESH::HYP_UNKNOWN_FATAL;
571       }
572     }
573     else {
574       SCRUTE(aSubMesh->_is_nil());
575       SCRUTE(aHyp->_is_nil());
576     }
577     return res < SMESH::HYP_UNKNOWN_FATAL;
578   }
579
580   bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
581   {
582     int res = SMESH::HYP_UNKNOWN_FATAL;
583     SUIT_OverrideCursor wc;
584
585     try {
586       _PTR(Study) aStudy = GetActiveStudyDocument();
587       _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
588       if( aHypObj )
589         {
590           _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
591           _PTR(SObject) aRealHypo;
592           if( aHypObj->ReferencedObject( aRealHypo ) )
593             {
594               SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
595               RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
596             }
597           else
598             {
599               SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
600               SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
601               for( int i = 0; i < meshList.size(); i++ )
602                 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
603             }
604         }
605     }
606     catch(const SALOME::SALOME_Exception& S_ex)
607       {
608         wc.suspend();
609         SalomeApp_Tools::QtCatchCorbaException(S_ex);
610         res = SMESH::HYP_UNKNOWN_FATAL;
611       }
612     return res < SMESH::HYP_UNKNOWN_FATAL;
613   }
614
615   bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject)               MorSM,
616                                           SMESH::SMESH_Hypothesis_ptr anHyp)
617   {
618     int res = SMESH::HYP_UNKNOWN_FATAL;
619     SUIT_OverrideCursor wc;
620
621     if (MorSM) {
622       try {
623         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
624         SMESH::SMESH_Mesh_var aMesh        = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
625         SMESH::SMESH_subMesh_var aSubMesh  = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
626
627         if (!aSubMesh->_is_nil())
628           aMesh = aSubMesh->GetFather();
629
630         if (!aMesh->_is_nil()) {    
631           if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
632             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
633             if (res < SMESH::HYP_UNKNOWN_FATAL) {
634               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
635               if (meshSO)
636                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
637             }
638             
639           }
640           else if(!aMesh->HasShapeToMesh()){
641             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
642             if (res < SMESH::HYP_UNKNOWN_FATAL) {
643               _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
644               if (meshSO)
645                 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);              
646             }
647           }
648           if (res > SMESH::HYP_OK) {
649             wc.suspend();
650             processHypothesisStatus(res, anHyp, false);
651             wc.resume();
652           }
653         }
654       } catch(const SALOME::SALOME_Exception& S_ex) {
655         wc.suspend();
656         SalomeApp_Tools::QtCatchCorbaException(S_ex);
657         res = SMESH::HYP_UNKNOWN_FATAL;
658       }
659     }
660     return res < SMESH::HYP_UNKNOWN_FATAL;
661   }
662
663   SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
664   {
665     SObjectList listSOmesh;
666     listSOmesh.resize(0);
667
668     unsigned int index = 0;
669     if (!AlgoOrHyp->_is_nil()) {
670       _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
671       if (SO_Hypothesis) {
672         SObjectList listSO =
673           SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
674
675         if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
676         for (unsigned int i = 0; i < listSO.size(); i++) {
677           _PTR(SObject) SO = listSO[i];
678           if (SO) {
679             _PTR(SObject) aFather = SO->GetFather();
680             if (aFather) {
681               _PTR(SObject) SOfatherFather = aFather->GetFather();
682               if (SOfatherFather) {
683                 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
684                 index++;
685                 listSOmesh.resize(index);
686                 listSOmesh[index - 1] = SOfatherFather;
687               }
688             }
689           }
690         }
691       }
692     }
693     if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
694     return listSOmesh;
695   }
696
697 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
698   QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
699   {
700     QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
701     for ( int i = 0; i < errors.length(); ++i ) {
702       const SMESH::AlgoStateError & error = errors[ i ];
703       const bool hasAlgo = ( strlen( error.algoName ) != 0 );
704       QString msg;
705       if ( !hasAlgo )
706         msg = QObject::tr( "STATE_ALGO_MISSING" );
707       else 
708         switch( error.state ) {
709           CASE2MESSAGE( HYP_MISSING );
710           CASE2MESSAGE( HYP_NOTCONFORM );
711           CASE2MESSAGE( HYP_BAD_PARAMETER );
712           CASE2MESSAGE( HYP_BAD_GEOMETRY );
713         default: continue;
714         }
715       // apply args to message:
716       // %1 - algo name
717       if ( hasAlgo )
718         msg = msg.arg( error.algoName.in() );
719       // %2 - dimension
720       msg = msg.arg( error.algoDim );
721       // %3 - global/local
722       msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
723       // %4 - hypothesis dim == algoDim
724       msg = msg.arg( error.algoDim );
725
726       if ( i ) resMsg += ";\n";
727       resMsg += msg;
728     }
729     return resMsg;
730   }
731 } // end of namespace SMESH