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