Salome HOME
Bugs in CopyMesh()
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 //  File   : SMESHGUI_MeshOp.cxx
23 //  Author : Sergey LITONIN, Open CASCADE S.A.S.
24
25 // SMESH includes
26 #include "SMESHGUI_MeshOp.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_MeshDlg.h"
30 #include "SMESHGUI_ShapeByMeshDlg.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_Hypotheses.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
35
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_NumberFilter.hxx>
38
39 // SALOME GEOM includes
40 #include <GEOM_SelectionFilter.h>
41 #include <GEOMBase.h>
42 #include <GeometryGUI.h>
43 #include <GEOM_wrap.hxx>
44
45 // SALOME GUI includes
46 #include <SalomeApp_Tools.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <LightApp_UpdateFlags.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_Session.h>
54 #include <SALOME_InteractiveObject.hxx>
55 #include <SALOME_ListIO.hxx>
56
57 // SALOME KERNEL includes
58 #include <SALOMEDS_SComponent.hxx>
59 #include <SALOMEDS_SObject.hxx>
60 #include <SALOMEDS_Study.hxx>
61 #include <SALOMEDS_wrap.hxx>
62
63 // Qt includes
64 #include <QStringList>
65 #include <QLineEdit>
66 #include <QApplication>
67
68 // OCCT includes
69 #include <TopoDS.hxx>
70 #include <TopoDS_Shape.hxx>
71 #include <TopoDS_Shell.hxx>
72 #include <TopExp_Explorer.hxx>
73 #include <BRep_Tool.hxx>
74
75 // IDL includes
76 #include <SALOMEconfig.h>
77 #include CORBA_CLIENT_HEADER(SMESH_Gen)
78
79 //================================================================================
80 /*!
81  * \brief Constructor
82   * \param theToCreate - if this parameter is true then operation is used for creation,
83   * for editing otherwise
84  *
85  * Initialize operation
86 */
87 //================================================================================
88 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
89 : SMESHGUI_SelectionOp(),
90   myToCreate( theToCreate ),
91   myIsMesh( theIsMesh ),
92   myDlg( 0 ),
93   myShapeByMeshOp( 0 ),
94   myHypoSet( 0 )
95 {
96   if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
97     GeometryGUI::InitGeomGen();
98   myIsOnGeometry = true;
99   myMaxShapeDim = -1;
100 }
101
102 //================================================================================
103 /*!
104  * \brief Destructor
105 */
106 //================================================================================
107 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
108 {
109   if ( myDlg )
110     delete myDlg;
111 }
112
113 //================================================================================
114 /*!
115  * \brief Gets dialog of this operation
116   * \retval LightApp_Dialog* - pointer to dialog of this operation
117 */
118 //================================================================================
119 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
120 {
121   return myDlg;
122 }
123
124 //================================================================================
125 /*!
126  * \brief Creates or edits mesh
127   * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
128  *
129  * Virtual slot redefined from the base class called when "Apply" button is clicked
130  * creates or edits mesh
131  */
132 //================================================================================
133 bool SMESHGUI_MeshOp::onApply()
134 {
135   if (isStudyLocked())
136     return false;
137
138   QString aMess;
139   if ( !isValid( aMess ) )
140   {
141     dlg()->show();
142     if ( aMess != "" )
143       SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
144     return false;
145   }
146
147   bool aResult = false;
148   aMess = "";
149   try
150   {
151     QStringList anEntryList;
152     if ( myToCreate && myIsMesh )
153       aResult = createMesh( aMess, anEntryList );
154     if ( myToCreate && !myIsMesh )
155       aResult = createSubMesh( aMess, anEntryList );
156     else if ( !myToCreate )
157       aResult = editMeshOrSubMesh( aMess );
158     if ( aResult )
159     {
160       SMESHGUI::Modified();
161       update( UF_ObjBrowser | UF_Model );
162       if( LightApp_Application* anApp =
163           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
164         myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
165     }
166   }
167   catch ( const SALOME::SALOME_Exception& S_ex )
168   {
169     SalomeApp_Tools::QtCatchCorbaException( S_ex );
170     aResult = false;
171   }
172   catch ( ... )
173   {
174     aResult = false;
175   }
176
177   if ( aResult )
178   {
179     if ( myToCreate )
180       setDefaultName();
181   }
182   else
183   {
184     if ( aMess == "" )
185       aMess = tr( "SMESH_OPERATION_FAILED" );
186     SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
187   }
188
189   return aResult;
190 }
191
192 //================================================================================
193 /*!
194  * \brief Creates dialog if necessary and shows it
195  *
196  * Virtual method redefined from base class called when operation is started creates
197  * dialog if necessary and shows it, activates selection
198  */
199 //================================================================================
200 void SMESHGUI_MeshOp::startOperation()
201 {
202   if (!myDlg)
203   {
204     myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
205     for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
206     {
207       connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
208               this, SLOT( onCreateHyp( const int, const int ) ) );
209       connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
210               this, SLOT( onEditHyp( const int, const int ) ) );
211       connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
212               this, SLOT( onAlgoSelected( const int ) ) );
213     }
214     connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
215     connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
216     connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
217     if ( myToCreate ) {
218       if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
219       else            myHelpFileName = "constructing_submeshes_page.html";
220     }
221     else {
222       myHelpFileName = "editing_meshes_page.html";
223     }
224   }
225   SMESHGUI_SelectionOp::startOperation();
226   // iterate through dimensions and get available algoritms, set them to the dialog
227   _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
228   for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
229   {
230     SMESHGUI_MeshTab* aTab = myDlg->tab( i );
231     QStringList hypList;
232     // clear available hypotheses
233     aTab->setAvailableHyps( MainHyp, hypList );
234     aTab->setAvailableHyps( AddHyp, hypList );
235     aTab->setExistingHyps( MainHyp, hypList );
236     aTab->setExistingHyps( AddHyp, hypList );
237     myExistingHyps[ i ][ MainHyp ].clear();
238     myExistingHyps[ i ][ AddHyp ].clear();
239     // set algos
240     availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
241     aTab->setAvailableHyps( Algo, hypList );
242   }
243   if ( myToCreate )
244   {
245     setDefaultName();
246     myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
247   }
248   else
249     myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
250
251   myDlg->setCurrentTab( SMESH::DIM_3D );
252
253   QStringList TypeMeshList;
254   createMeshTypeList( TypeMeshList );
255   setAvailableMeshType( TypeMeshList );
256
257   myDlg->show();
258   myDlg->setGeomPopupEnabled(false);
259   selectionDone();
260
261   myIgnoreAlgoSelection = false;
262   myHasConcurrentSubBefore = false;
263
264   myObjectToSelect.clear();
265 }
266
267 //=================================================================================
268 /*!
269  * \brief Selects a recently created mesh or sub-mesh if necessary
270  *
271  * Virtual method redefined from base class called when operation is commited
272  * selects a recently created mesh or sub-mesh if necessary. Allows to perform
273  * selection when the custom selection filters are removed.
274  */
275 //=================================================================================
276 void SMESHGUI_MeshOp::commitOperation()
277 {
278   SMESHGUI_SelectionOp::commitOperation();
279
280   if ( !myObjectToSelect.isEmpty() ) {
281     if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
282       SUIT_DataOwnerPtrList aList;
283       aList.append( new LightApp_DataOwner( myObjectToSelect ) );
284       aSelectionMgr->setSelected( aList );
285     }
286   }
287 }
288
289 //================================================================================
290 /*!
291  * \brief Creates selection filter
292   * \param theId - identifier of current selection widget
293   * \retval SUIT_SelectionFilter* - pointer to the created filter or null
294  *
295  * Creates selection filter in accordance with identifier of current selection widget
296  */
297 //================================================================================
298 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
299 {
300   if ( theId == SMESHGUI_MeshDlg::Geom )
301   {
302 //     TColStd_MapOfInteger allTypesMap;
303 //     for ( int i = 0; i < 10; i++ )
304 //       allTypesMap.Add( i );
305 //     return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
306     return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
307   }
308   else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
309     return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
310   else if ( theId == SMESHGUI_MeshDlg::Mesh )
311     return new SMESH_TypeFilter( SMESH::MESH );
312   else
313     return 0;
314 }
315
316 //================================================================================
317 /*!
318  * \brief check if selected shape is a sub-shape of the shape to mesh
319   * \retval bool - check result
320  */
321 //================================================================================
322 bool SMESHGUI_MeshOp::isSubshapeOk() const
323 {
324   if ( !myToCreate || myIsMesh ) // not submesh creation
325     return false;
326
327   // mesh
328   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
329   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
330   if (!pMesh) return false;
331
332   SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
333   if (mesh->_is_nil()) return false;
334
335   // main shape of the mesh
336   GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
337   if (mainGeom->_is_nil()) return false;
338
339   // geometry
340   QStringList aGEOMs;
341   myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
342
343   if (aGEOMs.count() > 0) {
344     GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
345     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
346     if (geomGen->_is_nil() || !aStudy) return false;
347
348     GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
349     if (op->_is_nil()) return false;
350
351     // check all selected shapes
352     QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
353     for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
354       QString aSubGeomEntry = (*aSubShapesIter);
355       _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
356       if (!pSubGeom) return false;
357
358       GEOM::GEOM_Object_var aSubGeomVar =
359         GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
360       if (aSubGeomVar->_is_nil()) return false;
361
362       // skl for NPAL14695 - implementation of searching of mainObj
363       GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
364                                                                         mainObj already exists! */
365       while(1) {
366         if (mainObj->_is_nil())
367           return false;
368         CORBA::String_var entry1 = mainObj->GetEntry();
369         CORBA::String_var entry2 = mainGeom->GetEntry();
370         if (std::string( entry1.in() ) == entry2.in() )
371           return true;
372         mainObj = op->GetMainShape(mainObj);
373       }
374     }
375   }
376
377   return false;
378 }
379
380 //================================================================================
381 /*!
382  * \brief Return name of the algorithm that does not support submeshes and makes
383  * submesh creation useless
384  *  \retval char* - string is to be deleted!!!
385  */
386 //================================================================================
387 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
388 {
389   if ( myToCreate && !myIsMesh ) {
390
391     QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
392     QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
393     _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
394     if ( pMesh ) {
395
396       QStringList algoNames;
397       THypList    algoList;
398       existingHyps(3, Algo, pMesh, algoNames, algoList);
399       if (!algoList.empty()) {
400         HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
401         if ( algo &&
402              algo->InputTypes.empty() && // builds all dimensions it-self
403              !algo->IsSupportSubmeshes )
404           return CORBA::string_dup( algoNames[0].toLatin1().data() );
405       }
406
407 //       GEOM::GEOM_Object_var geom;
408 //       if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
409 //         geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
410
411 //       if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
412         existingHyps(2, Algo, pMesh, algoNames, algoList);
413         if (!algoList.empty()) {
414           HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
415           if ( algo &&
416                algo->InputTypes.empty() && // builds all dimensions it-self
417                !algo->IsSupportSubmeshes )
418             return CORBA::string_dup( algoNames[0].toLatin1().data() );
419         }
420 //       }
421     }
422   }
423   return 0;
424 }
425
426 //================================================================================
427 /*!
428  * \brief find an existing submesh by the selected shape
429  * \retval _PTR(SObject) - the found submesh SObject
430  */
431 //================================================================================
432 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
433 {
434   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
435   QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
436   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
437   _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
438   if ( pMesh && pGeom ) {
439     GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
440     if ( !geom->_is_nil() ) {
441       int tag = -1;
442       switch ( geom->GetShapeType() ) {
443       case GEOM::VERTEX:   tag = SMESH::Tag_SubMeshOnVertex;   break;
444       case GEOM::EDGE:     tag = SMESH::Tag_SubMeshOnEdge;     break;
445       case GEOM::WIRE:     tag = SMESH::Tag_SubMeshOnWire;     break;
446       case GEOM::FACE:     tag = SMESH::Tag_SubMeshOnFace;     break;
447       case GEOM::SHELL:    tag = SMESH::Tag_SubMeshOnShell;    break;
448       case GEOM::SOLID:    tag = SMESH::Tag_SubMeshOnSolid;    break;
449       case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
450       default:;
451       }
452       _PTR(GenericAttribute) anAttr;
453       _PTR(SObject) aSubmeshRoot;
454       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
455       if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
456       {
457         _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
458         for ( ; smIter->More(); smIter->Next() )
459         {
460           _PTR(SObject) aSmObj = smIter->Value();
461           if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
462             continue;
463           _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
464           for ( ; anIter1->More(); anIter1->Next()) {
465             _PTR(SObject) pGeom2 = anIter1->Value();
466             if ( pGeom2->ReferencedObject( pGeom2 ) &&
467                  pGeom2->GetID() == pGeom->GetID() )
468               return aSmObj;
469           }
470         }
471       }
472     }
473   }
474   return _PTR(SObject)();
475 }
476
477 //================================================================================
478 /*!
479  * \brief Updates dialog's look and feel
480  *
481  * Virtual method redefined from the base class updates dialog's look and feel
482  */
483 //================================================================================
484 void SMESHGUI_MeshOp::selectionDone()
485 {
486   if (!dlg()->isVisible() || !myDlg->isEnabled())
487     return;
488
489   SMESHGUI_SelectionOp::selectionDone();
490
491   try
492   {
493     myIsOnGeometry = true;
494
495     //Check geometry for mesh
496     QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
497     _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
498     if (pObj)
499     {
500       SMESH::SMESH_Mesh_var aMeshVar =
501         SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
502       if (!aMeshVar->_is_nil()) {
503         if (!myToCreate && !aMeshVar->HasShapeToMesh())
504           myIsOnGeometry = false;
505       }
506     }
507
508     if (myIsOnGeometry)
509     {
510       // Enable tabs according to shape dimension
511
512       int shapeDim = 3;
513
514       QStringList aGEOMs;
515       myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
516       GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
517
518       if (aGEOMs.count() > 0) {
519         // one or more GEOM shape selected
520         aSeq->length(aGEOMs.count());
521         QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
522         int iSubSh = 0;
523         for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
524           QString aSubGeomEntry = (*aSubShapesIter);
525           _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
526           GEOM::GEOM_Object_var aSubGeomVar =
527             GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
528           aSeq[iSubSh] = aSubGeomVar;
529         }
530       } else {
531         // get geometry by selected sub-mesh
532         QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
533         _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
534         GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
535         if (!aGeomVar->_is_nil()) {
536           aSeq->length(1);
537           aSeq[0] = aGeomVar;
538         }
539       }
540
541       if (aSeq->length() > 0) {
542         shapeDim = -1;
543         for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
544           GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
545           switch ( aGeomVar->GetShapeType() ) {
546           case GEOM::SOLID:  shapeDim = 3; break;
547           case GEOM::SHELL:
548             // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
549             // {
550             //   TopoDS_Shape aShape;
551             //   bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
552             //   shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
553             // }
554             // break;
555           case GEOM::FACE:   shapeDim = qMax(2, shapeDim); break;
556           case GEOM::WIRE:
557           case GEOM::EDGE:   shapeDim = qMax(1, shapeDim); break;
558           case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
559           default:
560             {
561               TopoDS_Shape aShape;
562               if (GEOMBase::GetShape(aGeomVar, aShape))
563               {
564                 TopExp_Explorer exp (aShape, TopAbs_SOLID);
565                 if (exp.More()) {
566                   shapeDim = 3;
567                 }
568                 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
569                 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
570                 // {
571                 //   shapeDim = 2;
572                 //   for (; exp.More() && shapeDim == 2; exp.Next()) {
573                 //     if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
574                 //       shapeDim = 3;
575                 //   }
576                 // }
577                 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
578                   shapeDim = qMax(2, shapeDim);
579                 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
580                   shapeDim = qMax(1, shapeDim);
581                 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
582                   shapeDim = qMax(0, shapeDim);
583               }
584             }
585           }
586           if ( shapeDim == 3 )
587             break;
588         }
589       }
590       for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
591         // reset algos before disabling tabs (0020138)
592         onAlgoSelected(-1, i);
593       }
594       myDlg->setMaxHypoDim( shapeDim );
595       myMaxShapeDim = shapeDim;
596       myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
597
598       if (!myToCreate) // edition: read hypotheses
599       {
600         if (pObj != 0)
601         {
602           SMESH::SMESH_subMesh_var submeshVar =
603             SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
604           myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
605           myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
606           myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
607           myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
608           myDlg->updateGeometry();
609           myDlg->adjustSize();
610           readMesh();
611           myIsMesh = submeshVar->_is_nil();
612         }
613         else
614           myDlg->reset();
615       }
616       else if ( !myIsMesh ) // submesh creation
617       {
618         // if a submesh on the selected shape already exist, pass to submesh edition mode
619         if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
620           SMESH::SMESH_subMesh_var sm =
621             SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
622           bool editSubmesh = ( !sm->_is_nil() &&
623                                SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
624                                                           tr( "EDIT_SUBMESH_QUESTION"),
625                                                           SUIT_MessageBox::Yes |
626                                                           SUIT_MessageBox::No,
627                                                           SUIT_MessageBox::No )
628                                == SUIT_MessageBox::Yes );
629           if ( editSubmesh )
630           {
631             selectionMgr()->clearFilters();
632             selectObject( pSubmesh );
633             SMESHGUI::GetSMESHGUI()->switchToOperation(704);
634             return;
635           }
636           else
637           {
638             myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
639             selectObject( _PTR(SObject)() );
640             selectionDone();
641             return;
642           }
643         }
644         // discard selected mesh if submesh creation not allowed because of
645         // a global algorithm that does not support submeshes
646         if ( char* algoName = isSubmeshIgnored() ) {
647           SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
648                                     tr("SUBMESH_NOT_ALLOWED").arg(algoName));
649           CORBA::string_free( algoName );
650           myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
651           selectObject( _PTR(SObject)() );
652           selectionDone();
653           return;
654         }
655
656         // enable/disable popup for choice of geom selection way
657         bool enable = false;
658         QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
659         if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
660           SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
661           if ( !mesh->_is_nil() ) {
662             //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
663             QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
664             _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
665             if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
666               myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
667             enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
668           }
669         }
670         myDlg->setGeomPopupEnabled( enable );
671       }
672     }
673     else { // no geometry defined
674       myDlg->enableTab( SMESH::DIM_3D );
675       QStringList hypList;
676       availableHyps( SMESH::DIM_3D, Algo, hypList,
677                      myAvailableHypData[SMESH::DIM_3D][Algo]);
678
679       SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
680       aTab->setAvailableHyps( Algo, hypList );
681       for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
682         myDlg->disableTab(i);
683       }
684       myMaxShapeDim = -1;
685       //Hide labels and fields (Mesh and Geometry)
686       myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
687       myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
688       myDlg->adjustSize();
689       readMesh();
690     }
691     QStringList TypeMeshList;
692     createMeshTypeList( TypeMeshList );
693     setAvailableMeshType( TypeMeshList );
694     setFilteredAlgoData( myMaxShapeDim, myDlg->currentMeshType( ));
695   }
696   catch ( const SALOME::SALOME_Exception& S_ex )
697   {
698     SalomeApp_Tools::QtCatchCorbaException( S_ex );
699   }
700   catch ( ... )
701   {
702   }
703 }
704
705 //================================================================================
706 /*!
707  * \brief Verifies validity of input data
708   * \param theMess - Output parameter intended for returning error message
709   * \retval bool  - TRUE if input data is valid, false otherwise
710  *
711  * Verifies validity of input data. This method is called when "Apply" or "OK" button
712  * is pressed before mesh creation or editing.
713  */
714 //================================================================================
715 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
716 {
717   // Selected object to be  edited
718   if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
719   {
720     theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
721     return false;
722   }
723
724   // Name
725   QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
726   if ( aMeshName.isEmpty() )
727   {
728     theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
729     return false;
730   }
731
732 /*  // Imported mesh, if create sub-mesh or edit mesh
733   if ( !myToCreate || ( myToCreate && !myIsMesh ))
734   {
735     QString aMeshEntry = myDlg->selectedObject
736       ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
737     if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
738       SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
739       if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
740         theMess = tr( "IMPORTED_MESH" );
741         return false;
742       }
743     }
744   }*/
745
746   // Geom
747   if ( myToCreate )
748   {
749     QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
750     if ( aGeomEntry.isEmpty() )
751     {
752       theMess = tr( myIsMesh ?
753                     "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
754                     "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
755       if ( !myIsMesh )
756         return false;
757       dlg()->show();
758       if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
759            SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
760       {
761         theMess = "";
762         return false;
763       }
764       return true;
765     }
766     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
767     if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
768     {
769       theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
770       return false;
771     }
772
773     // Mesh
774     if ( !myIsMesh ) // i.e sub-mesh creation,
775     {
776       QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
777       if ( aMeshEntry == "" )
778       {
779         theMess = tr( "MESH_IS_NOT_DEFINED" );
780         return false;
781       }
782       _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
783       if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
784       {
785         theMess = tr( "MESH_IS_NULL" );
786         return false;
787       }
788       if ( !isSubshapeOk() )
789       {
790         theMess = tr( "INVALID_SUBSHAPE" );
791         return false;
792       }
793     }
794   }
795
796   return true;
797 }
798
799 //================================================================================
800 /*!
801  * \brief check compatibility of the algorithm and another algorithm or hypothesis
802   * \param theAlgoData - algorithm data
803   * \param theHypData - hypothesis data
804   * \param theHypType - hypothesis type
805   * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
806   * \retval bool - check result
807  */
808 //================================================================================
809 static bool isCompatible(const HypothesisData* theAlgoData,
810                          const HypothesisData* theHypData,
811                          const int             theHypType)
812 {
813   if ( !theAlgoData )
814     return true;
815
816   if ( theHypType == SMESHGUI_MeshOp::Algo )
817     return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
818
819   bool isOptional;
820   return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
821 }
822
823 //================================================================================
824 /*!
825  * \brief Gets available hypotheses or algorithms
826   * \param theDim - specifies dimension of returned hypotheses/algorifms
827   * \param theHypType - specifies whether algorims or hypotheses or additional ones
828   * are retrieved (possible values are in HypType enumeration)
829   * \param theHyps - Output list of hypotheses' names
830   * \param theAlgoData - to select hypos able to be used by this algo (optional)
831  *
832  * Gets available hypotheses or algorithm in accordance with input parameters
833  */
834 //================================================================================
835 void SMESHGUI_MeshOp::availableHyps( const int       theDim,
836                                      const int       theHypType,
837                                      QStringList&    theHyps,
838                                      THypDataList&   theDataList,
839                                      HypothesisData* theAlgoData ) const
840 {
841   theDataList.clear();
842   theHyps.clear();
843   bool isAlgo = ( theHypType == Algo );
844   bool isAux  = ( theHypType == AddHyp );
845   QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
846
847   QStringList::const_iterator anIter;
848   for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
849   {
850     HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
851     if ( isCompatible ( theAlgoData, aData, theHypType )) {
852       theDataList.append( aData );
853       theHyps.append( aData->Label );
854     }
855   }
856 }
857
858 //================================================================================
859 /*!
860  * \brief Gets existing hypotheses or algorithms
861  *  \param theDim - specifies dimension of returned hypotheses/algorifms
862  *  \param theHypType - specifies whether algorims or hypotheses or additional ones
863  *  are retrieved (possible values are in HypType enumeration)
864  *  \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
865  *  \param theHyps - output list of names.
866  *  \param theHypVars - output list of variables.
867  *  \param theAlgoData - to select hypos able to be used by this algo (optional)
868  *
869  * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
870  * input parameters
871  */
872 //================================================================================
873 void SMESHGUI_MeshOp::existingHyps( const int       theDim,
874                                     const int       theHypType,
875                                     _PTR(SObject)   theFather,
876                                     QStringList&    theHyps,
877                                     THypList&       theHypList,
878                                     HypothesisData* theAlgoData)
879 {
880   // Clear hypoheses list
881   theHyps.clear();
882   theHypList.clear();
883
884   if ( !theFather )
885     return;
886
887   const bool isAux  = ( theHypType == AddHyp );
888
889   _PTR(SObject)          aHypRoot;
890   _PTR(GenericAttribute) anAttr;
891   _PTR(AttributeName)    aName;
892   _PTR(AttributeIOR)     anIOR;
893
894   bool isMesh = !_CAST( SComponent, theFather );
895   int aPart = -1;
896   if ( isMesh )
897     aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
898   else
899     aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
900
901   if ( theFather->FindSubObject( aPart, aHypRoot ) )
902   {
903     _PTR(ChildIterator) anIter =
904       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
905     for ( ; anIter->More(); anIter->Next() )
906     {
907       _PTR(SObject) anObj = anIter->Value();
908       if ( isMesh ) // i.e. mesh or submesh
909       {
910         _PTR(SObject) aRefObj;
911         if ( anObj->ReferencedObject( aRefObj ) )
912           anObj = aRefObj;
913         else
914           continue;
915       }
916       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
917       {
918         aName = anAttr;
919         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
920         if ( !CORBA::is_nil( aVar ) )
921         {
922           SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
923           if ( !aHypVar->_is_nil() )
924           {
925             CORBA::String_var hypType = aHypVar->GetName();
926             HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
927             if ( !aData) continue;
928             if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
929                  ( isCompatible ( theAlgoData, aData, theHypType )) &&
930                  ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ))
931             {
932               std::string aHypName = aName->Value();
933               theHyps.append( aHypName.c_str() );
934               theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
935             }
936           }
937         }
938       }
939     }
940   }
941 }
942
943 //================================================================================
944 /*!
945  * \brief If create or edit a submesh, return a hypothesis holding parameters used
946  *        to mesh a sub-shape
947   * \param aHypType - The hypothesis type name
948   * \param aServerLib - Server library name
949   * \param hypData - The structure holding the hypothesis type etc.
950   * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
951  */
952 //================================================================================
953 SMESH::SMESH_Hypothesis_var
954 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
955                                           const QString& aServerLib ) const
956 {
957   if ( aHypType.isEmpty() || aServerLib.isEmpty() )
958     return SMESH::SMESH_Hypothesis::_nil();
959
960   const int nbColonsInMeshEntry = 3;
961   bool isSubMesh = myToCreate ?
962     !myIsMesh :
963     myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
964
965   // get mesh and geom object
966   SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
967   GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
968
969   QString anEntry;
970   if ( isSubMesh )
971   {
972     anEntry = myDlg->selectedObject
973       ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
974     if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
975     {
976       CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
977       if ( myToCreate ) // mesh and geom may be selected
978       {
979         aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
980         anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
981         if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
982           aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
983       }
984       else // edition: sub-mesh may be selected
985       {
986         SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
987         if ( !sm->_is_nil() ) {
988           aMeshVar = sm->GetFather();
989           aGeomVar = sm->GetSubShape();
990         }
991       }
992     }
993   }
994   else // mesh
995   {
996     if ( !myToCreate ) // mesh to edit can be selected
997     {
998       anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
999       if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1000       {
1001         aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1002         if ( !aMeshVar->_is_nil() )
1003           aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1004       }
1005     }
1006     if ( aGeomVar->_is_nil() ) {
1007       anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1008       if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1009       {
1010         aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1011       }
1012     }
1013   }
1014
1015   SMESH::SMESH_Hypothesis_var hyp =
1016     SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1017                                                            aServerLib.toLatin1().data(),
1018                                                            aMeshVar,
1019                                                            aGeomVar,
1020                                                            /*byMesh = */isSubMesh);
1021   if ( hyp->_is_nil() && isSubMesh )
1022     hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1023                                                                  aServerLib.toLatin1().data(),
1024                                                                  aMeshVar,
1025                                                                  aGeomVar,
1026                                                                  /*byMesh = */false);
1027   return hyp;
1028 }
1029
1030 //================================================================================
1031 /*!
1032  * \Brief Returns tab dimention
1033   * \param tab - the tab in the dlg
1034   * \param dlg - my dialogue
1035   * \retval int - dimention
1036  */
1037 //================================================================================
1038 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1039 {
1040   int aDim = -1;
1041   for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1042     if (tab == dlg->tab(i))
1043       aDim = i;
1044   return aDim;
1045 }
1046
1047 //================================================================================
1048 /*!
1049  * \brief Create hypothesis
1050   * \param theHypType - hypothesis category (main or additional)
1051   * \param theIndex - index of type of hypothesis to be cerated
1052  *
1053  * Specifies dimension of hypothesis to be created (using sender() method),
1054  * specifies its type and calls method for hypothesis creation
1055  */
1056 //================================================================================
1057 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1058 {
1059   // Specifies dimension of hypothesis to be created
1060   int aDim = getTabDim( sender(), myDlg );
1061   if (aDim == -1)
1062     return;
1063
1064   // Specifies type of hypothesis to be created
1065   THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1066   if (theIndex < 0 || theIndex >= dataList.count())
1067     return;
1068   QString aHypTypeName = dataList[ theIndex ]->TypeName;
1069
1070   // Create hypothesis
1071   createHypothesis(aDim, theHypType, aHypTypeName);
1072 }
1073
1074 namespace
1075 {
1076   QString GetUniqueName (const QStringList& theHypNames,
1077                          const QString& theName,
1078                          size_t theIteration = 1)
1079   {
1080     QString aName = theName + "_" + QString::number( theIteration );
1081     if ( theHypNames.contains( aName ) )
1082       return GetUniqueName( theHypNames, theName, ++theIteration );
1083     return aName;
1084   }
1085 }
1086
1087 //================================================================================
1088 /*!
1089  *  Create hypothesis and update dialog.
1090  *  \param theDim - dimension of hypothesis to be created
1091  *  \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1092  *  \param theTypeName - specifies hypothesis to be created
1093  */
1094 //================================================================================
1095 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1096                                        const int theType,
1097                                        const QString& theTypeName)
1098 {
1099   HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1100   if (!aData)
1101     return;
1102
1103   myDim = theDim;
1104   myType = theType;
1105   QStringList aHypNames;
1106   TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1107   for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1108     const TType2HypList& aType2HypList = aDimIter.value();
1109     TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1110     for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1111       const THypList& aHypList = aTypeIter.value();
1112       THypList::const_iterator anIter = aHypList.begin();
1113       for ( ; anIter != aHypList.end(); anIter++) {
1114         const THypItem& aHypItem = *anIter;
1115         const QString& aHypName = aHypItem.second;
1116         aHypNames.append(aHypName);
1117       }
1118     }
1119   }
1120   QString aHypName = GetUniqueName( aHypNames, aData->Label);
1121
1122   // existing hypos
1123   bool dialog = false;
1124
1125   QString aClientLibName = aData->ClientLibName;
1126   if (aClientLibName == "") {
1127     // Call hypothesis creation server method (without GUI)
1128     SMESH::SMESH_Hypothesis_var aHyp =
1129       SMESH::CreateHypothesis(theTypeName, aHypName, false);
1130     aHyp.out();
1131   }
1132   else {
1133     // Get hypotheses creator client (GUI)
1134     SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1135
1136     // Create hypothesis
1137     if (aCreator) {
1138       // Get parameters appropriate to initialize a new hypothesis
1139       SMESH::SMESH_Hypothesis_var initParamHyp =
1140         getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1141
1142       removeCustomFilters(); // Issue 0020170
1143
1144       // Get Entry of the Geom object
1145       QString aGeomEntry = "";
1146       QString aMeshEntry = "";
1147       QString anObjEntry = "";
1148       aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1149       aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1150       anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1151
1152       if ( myToCreate && myIsMesh )
1153         aMeshEntry = aGeomEntry;
1154
1155       if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1156         _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1157         GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1158         aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1159       }
1160
1161       if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1162         _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1163         bool isMesh;
1164         GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1165         if ( !aGeomVar->_is_nil() )
1166         {
1167           aGeomEntry = aGeomVar->GetStudyEntry();
1168           if ( isMesh )
1169             aMeshEntry = aGeomEntry;
1170         }
1171       }
1172
1173       if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1174         // take geometry from submesh being created
1175         _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1176         if ( pObj ) {
1177           // if current object is sub-mesh
1178           SMESH::SMESH_subMesh_var aSubMeshVar =
1179             SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1180           if ( !aSubMeshVar->_is_nil() ) {
1181             SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
1182             if ( !aMeshVar->_is_nil() ) {
1183               _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1184               GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1185               if ( !aGeomVar->_is_nil() )
1186                 aMeshEntry = aGeomVar->GetStudyEntry();
1187             }
1188           }
1189         }
1190       }
1191
1192       aCreator->setShapeEntry( aGeomEntry );
1193       if ( aMeshEntry != "" )
1194         aCreator->setMainShapeEntry( aMeshEntry );
1195       myDlg->setEnabled( false );
1196       aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1197       dialog = true;
1198     }
1199     else {
1200      SMESH::SMESH_Hypothesis_var aHyp =
1201        SMESH::CreateHypothesis(theTypeName, aHypName, false);
1202      aHyp.out();
1203     }
1204   }
1205
1206   if( !dialog )
1207     onHypoCreated(2);
1208 }
1209
1210 //================================================================================
1211 /*!
1212  *  Necessary steps after hypothesis creation
1213  *  \param result - creation result:
1214  *   0 = rejected
1215  *   1 = accepted
1216  *   2 = additional value meaning that slot is called not from dialog box
1217  */
1218 //================================================================================
1219 void SMESHGUI_MeshOp::onHypoCreated( int result )
1220 {
1221   if( result != 2 )
1222   {
1223     int obj = myDlg->getActiveObject();
1224     onActivateObject( obj ); // Issue 0020170. Restore filters
1225     myDlg->setEnabled( true );
1226   }
1227
1228   _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1229
1230   int nbHyp = myExistingHyps[myDim][myType].count();
1231   HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1232   QStringList aNewHyps;
1233   existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1234   if (aNewHyps.count() > nbHyp)
1235   {
1236     for (int i = nbHyp; i < aNewHyps.count(); i++)
1237       myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1238   }
1239
1240   if( result!=2 && myHypoSet )
1241     processSet();
1242 }
1243
1244 //================================================================================
1245 /*!
1246  * \brief Calls plugin methods for hypothesis editing
1247   * \param theHypType - specifies whether main hypothesis or additional one
1248   * is edited
1249   * \param theIndex - index of existing hypothesis
1250  *
1251  * Calls plugin methods for hypothesis editing
1252  */
1253 //================================================================================
1254 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1255 {
1256   // Speicfies dimension of hypothesis to be created
1257   int aDim = getTabDim( sender(), myDlg );
1258   if (aDim == -1)
1259     return;
1260
1261   const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1262   if ( theIndex < 0 || theIndex >= aList.count() )
1263     return;
1264   const THypItem& aHypItem = aList[ theIndex ];
1265   SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1266   if ( aHyp->_is_nil() )
1267     return;
1268
1269   SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1270   if ( aCreator )
1271   {
1272     // Get initial parameters
1273     SMESH::SMESH_Hypothesis_var initParamHyp =
1274       getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1275     aCreator->setInitParamsHypothesis( initParamHyp );
1276
1277     // Get Entry of the Geom object
1278     QString aGeomEntry = "";
1279     QString aMeshEntry = "";
1280     QString anObjEntry = "";
1281     aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1282     aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1283     anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1284
1285     if ( myToCreate && myIsMesh )
1286       aMeshEntry = aGeomEntry;
1287
1288     if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1289       _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1290       GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1291       aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1292     }
1293
1294     if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1295       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1296       bool isMesh;
1297       GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1298       if ( !aGeomVar->_is_nil() )
1299       {
1300         aGeomEntry = aGeomVar->GetStudyEntry();
1301         if ( isMesh )
1302           aMeshEntry = aGeomEntry;
1303       }
1304     }
1305
1306     if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1307       // take geometry from submesh being created
1308       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1309       if ( pObj ) {
1310         // if current object is sub-mesh
1311         SMESH::SMESH_subMesh_var aSubMeshVar =
1312           SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1313         if ( !aSubMeshVar->_is_nil() ) {
1314           SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
1315           if ( !aMeshVar->_is_nil() ) {
1316             _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1317             GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1318             if ( !aGeomVar->_is_nil() )
1319               aMeshEntry = aGeomVar->GetStudyEntry();
1320           }
1321         }
1322       }
1323     }
1324
1325     aCreator->setShapeEntry( aGeomEntry );
1326     if ( aMeshEntry != "" )
1327       aCreator->setMainShapeEntry( aMeshEntry );
1328     removeCustomFilters(); // Issue 0020170
1329     myDlg->setEnabled( false );
1330     aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1331   }
1332 }
1333
1334 //================================================================================
1335 /*!
1336  *  Necessary steps after hypothesis edition
1337  *  \param result - creation result:
1338  *   0 = rejected
1339  *   1 = accepted
1340  */
1341 //================================================================================
1342 void SMESHGUI_MeshOp::onHypoEdited( int result )
1343 {
1344   int obj = myDlg->getActiveObject();
1345   onActivateObject( obj ); // Issue 0020170. Restore filters
1346   myDlg->setEnabled( true );
1347 }
1348
1349 //================================================================================
1350 /*!
1351  * \brief access to hypothesis data
1352   * \param theDim - hyp dimension
1353   * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1354   * \param theIndex - index in the list
1355   * \retval HypothesisData* - result data, may be 0
1356  */
1357 //================================================================================
1358 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1359                                           const int theHypType,
1360                                           const int theIndex)
1361 {
1362   if ( theDim     > -1 && theDim    <= SMESH::DIM_3D &&
1363        theHypType > -1 && theHypType < NbHypTypes &&
1364        theIndex   > -1 && theIndex   < myAvailableHypData[ theDim ][ theHypType ].count() )
1365     return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1366   return 0;
1367 }
1368
1369 //================================================================================
1370 /*!
1371  * \brief Set available algos and hypos according to the selected algorithm
1372   * \param theIndex - algorithm index
1373  */
1374 //================================================================================
1375 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1376                                       const int theDim )
1377 {
1378   if ( myIgnoreAlgoSelection )
1379     return;
1380
1381   int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1382   if (aDim == -1)
1383     return;
1384
1385   // find highest available dimension, all algos of this dimension are available for choice
1386   int aTopDim = -1;
1387   for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1388     if (isAccessibleDim( i ))
1389       aTopDim = i;
1390   if (aTopDim == -1)
1391     return;
1392
1393   const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1394
1395   // if ( aDim >= SMESH::DIM_2D ) myAvailableHypData[ aDim ][ Algo ] = myFilteredAlgoData[aDim];
1396   HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1397   HypothesisData* algoByDim[4];
1398   algoByDim[ aDim ] = algoData;
1399
1400   QStringList anAvailable;
1401
1402   // check that tab enable, if algorithm building needed algo is one less than dimension
1403   if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() &&
1404        ( aDim > SMESH::DIM_0D ) && !isAccessibleDim( aDim - 1 ) ){
1405     myDlg->enableTab( aDim - 1 );
1406   }
1407   if ( (myDlg->currentMeshType() != MT_ANY) &&
1408        (( !algoData && ( aDim > SMESH::DIM_0D ) && isAccessibleDim( aDim - 1 )) ||
1409         ( algoData && myIsOnGeometry && algoData->InputTypes.isEmpty() &&
1410           ( aDim > SMESH::DIM_0D ) && isAccessibleDim( aDim - 1 ) ) ) ){
1411     for (int i = aDim - 1; i >= SMESH::DIM_0D; i--){
1412       if ( isAccessibleDim( i ) ) {
1413         myDlg->disableTab( i );
1414         setCurrentHyp(i, Algo, -1);
1415       }
1416     }
1417   }
1418
1419   // check that algorithms of other dimentions are compatible with
1420   // the selected one
1421   if ( !algoData ) { // all algos becomes available
1422     if (myDlg->currentMeshType() == MT_ANY)
1423       availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1424     else{
1425       anAvailable.clear();
1426       for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
1427         HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
1428         anAvailable.append( aCurAlgo->Label );
1429       }
1430     }
1431     myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1432   }
1433   // 2 loops: backward and forward from algo dimension
1434   for ( int forward = false; forward <= true; ++forward )
1435   {
1436     int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1437     if ( !forward ) {
1438       dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1439     }
1440     HypothesisData* prevAlgo = algoData;
1441     bool noCompatible = false;
1442     for ( ; dim * dir <= lastDim * dir; dim += dir)
1443     {
1444       if ( !isAccessibleDim( dim ))
1445         continue;
1446       if ( noCompatible ) { // the selected algo has no compatible ones
1447         anAvailable.clear();
1448         myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1449         myAvailableHypData[dim][Algo].clear();
1450         algoByDim[ dim ] = 0;
1451         continue;
1452       }
1453       // get currently selected algo
1454       int algoIndex = currentHyp( dim, Algo );
1455       HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1456       if ( curAlgo ) { // some algo selected
1457         if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1458           curAlgo = 0;
1459       }
1460       // set new available algoritms
1461       if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
1462         availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1463       else{
1464         anAvailable.clear();
1465         myAvailableHypData[dim][Algo].clear();
1466         for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
1467           HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
1468           if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
1469             anAvailable.append( aCurAlgo->Label );
1470             myAvailableHypData[dim][Algo].append( aCurAlgo );
1471           }
1472         }
1473       }
1474       HypothesisData* soleCompatible = 0;
1475       if ( anAvailable.count() == 1 )
1476         soleCompatible = myAvailableHypData[dim][Algo][0];
1477       if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
1478         if (myDlg->currentMeshType() == MT_ANY)
1479           availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1480       }
1481       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1482       noCompatible = anAvailable.isEmpty();
1483
1484       // restore previously selected algo
1485       algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1486       if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1487         // select the sole compatible algo
1488         algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1489       setCurrentHyp( dim, Algo, algoIndex);
1490
1491       // remember current algo
1492       prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1493     }
1494   }
1495
1496   // set hypotheses corresponding to the found algoritms
1497
1498   _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1499
1500   for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1501   {
1502     if ( !isAccessibleDim( dim ))
1503       continue;
1504     for ( int type = MainHyp; type < NbHypTypes; type++ )
1505     {
1506       myAvailableHypData[ dim ][ type ].clear();
1507       QStringList anAvailable, anExisting;
1508
1509       HypothesisData* curAlgo = algoByDim[ dim ];
1510       int hypIndex = currentHyp( dim, type );
1511
1512       SMESH::SMESH_Hypothesis_var curHyp;
1513       if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1514         curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1515
1516       if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1517         // try to find algo by selected hypothesis in order to keep it selected
1518         bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1519         CORBA::String_var curHypType = curHyp->GetName();
1520         if ( !algoDeselectedByUser &&
1521             myObjHyps[ dim ][ type ].count() > 0 &&
1522             !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1523         {
1524           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1525           for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1526             curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1527             if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1528               break;
1529             else
1530               curAlgo = 0;
1531           }
1532         }
1533       }
1534       // get hyps compatible with curAlgo
1535       bool defaulHypAvlbl = false;
1536       if ( curAlgo )
1537       {
1538         // check if a selected hyp is compatible with the curAlgo
1539         if ( !curHyp->_is_nil() ) {
1540           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1541           if ( !isCompatible( curAlgo, hypData, type ))
1542             curHyp = SMESH::SMESH_Hypothesis::_nil();
1543         }
1544         existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1545         availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1546         defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1547       }
1548       // set list of hypotheses
1549       myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1550       myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1551
1552       // set current existing hypothesis
1553       if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1554         hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1555       else
1556         hypIndex = -1;
1557       if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1558         // none is yet selected => select the sole existing if it is not optional
1559         CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1560         bool isOptional = true;
1561         if ( algoByDim[ dim ] &&
1562             SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1563             !isOptional )
1564           hypIndex = 0;
1565       }
1566       setCurrentHyp( dim, type, hypIndex );
1567     }
1568   }
1569 }
1570
1571 //================================================================================
1572 /*!
1573  * \brief Creates and selects hypothesis of hypotheses set
1574  * \param theSetName - The name of hypotheses set
1575  */
1576 //================================================================================
1577 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1578 {
1579   myHypoSet = SMESH::GetHypothesesSet(theSetName);
1580   if (!myHypoSet)
1581     return;
1582
1583   // clear all hyps
1584   for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1585     setCurrentHyp(dim, Algo, -1);
1586     setCurrentHyp(dim, AddHyp, -1);
1587     setCurrentHyp(dim, MainHyp, -1);
1588   }
1589
1590   myHypoSet->init(true); //algorithms
1591   processSet();
1592   myHypoSet->init(false); //hypotheses
1593   processSet();
1594   myHypoSet = 0;
1595 }
1596
1597 //================================================================================
1598 /*!
1599  * \brief One step of hypothesis/algorithm list creation
1600  *
1601  * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1602  */
1603 //================================================================================
1604 void SMESHGUI_MeshOp::processSet()
1605 {
1606   myHypoSet->next();
1607   if( !myHypoSet->more() )
1608     return;
1609
1610   bool isAlgo = myHypoSet->isAlgo();
1611   QString aHypoTypeName = myHypoSet->current();
1612   HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1613   if (!aHypData)
1614   {
1615     processSet();
1616     return;
1617   }
1618
1619   int aDim = aHypData->Dim[0];
1620   // create or/and set
1621   if (isAlgo)
1622   {
1623     int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1624     if ( index < 0 )
1625     {
1626       QStringList anAvailable;
1627       availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1628       myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1629       index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1630     }
1631     setCurrentHyp( aDim, Algo, index );
1632     onAlgoSelected( index, aDim );
1633     processSet();
1634   }
1635   else
1636   {
1637     bool mainHyp = true;
1638     QStringList anAvailable;
1639     availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1640     myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1641     int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1642     if ( index < 0 )
1643     {
1644       mainHyp = false;
1645       index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1646     }
1647     if (index >= 0)
1648       createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1649     else
1650       processSet();
1651   }
1652 }
1653
1654 //================================================================================
1655 /*!
1656  * \brief Creates mesh
1657   * \param theMess - Output parameter intended for returning error message
1658   * \param theEntryList - List of entries of published objects
1659   * \retval bool  - TRUE if mesh is created, FALSE otherwise
1660  *
1661  * Creates mesh
1662  */
1663 //================================================================================
1664 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1665 {
1666   theMess = "";
1667
1668   QStringList aList;
1669   myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1670   if ( aList.isEmpty() )
1671   {
1672     SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1673     if ( aSMESHGen->_is_nil() )
1674       return false;
1675
1676     SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1677     if ( aMeshVar->_is_nil() )
1678       return false;
1679
1680     _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1681     if ( aMeshSO ) {
1682       SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1683       theEntryList.append( aMeshSO->GetID().c_str() );
1684     }
1685     return true;
1686   }
1687   QString namePrefix;
1688   if ( aList.count() > 1 )
1689   {
1690     namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1691     int i = namePrefix.length() - 1;
1692     while ( i > 0 && namePrefix[i].isDigit() )
1693       --i;
1694     if ( i < namePrefix.length() - 1 )
1695       namePrefix.chop( namePrefix.length() - 1 - i );
1696     else
1697       namePrefix += "_";
1698   }
1699   QStringList::Iterator it = aList.begin();
1700   for ( int i = 0; it!=aList.end(); it++, ++i )
1701   {
1702     QString aGeomEntry = *it;
1703     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1704     GEOM::GEOM_Object_var aGeomVar =
1705       GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1706
1707     SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1708     if ( aSMESHGen->_is_nil() )
1709       return false;
1710
1711     SUIT_OverrideCursor aWaitCursor;
1712
1713     // create mesh
1714     SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1715     if ( aMeshVar->_is_nil() )
1716       return false;
1717     _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1718     if ( aMeshSO ) {
1719       theEntryList.append( aMeshSO->GetID().c_str() );
1720       if ( i > 0 ) setDefaultName( namePrefix );
1721       SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1722     }
1723
1724     for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1725       if ( !isAccessibleDim( aDim )) continue;
1726
1727       // assign hypotheses
1728       for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1729         int aHypIndex = currentHyp( aDim, aHypType );
1730         if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1731           SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1732           if ( !aHypVar->_is_nil() )
1733             SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1734         }
1735       }
1736       // find or create algorithm
1737       SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1738       if ( !anAlgoVar->_is_nil() )
1739         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1740     }
1741   }
1742   return true;
1743 }
1744
1745 //================================================================================
1746 /*!
1747  * \brief Creates sub-mesh
1748   * \param theMess - Output parameter intended for returning error message
1749   * \param theEntryList - List of entries of published objects
1750   * \retval bool  - TRUE if sub-mesh is created, FALSE otherwise
1751  *
1752  * Creates sub-mesh
1753  */
1754 //================================================================================
1755 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1756 {
1757   theMess = "";
1758
1759   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1760   if ( aSMESHGen->_is_nil() )
1761     return false;
1762
1763   // get mesh object
1764   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1765   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1766   SMESH::SMESH_Mesh_var aMeshVar =
1767     SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1768   if (aMeshVar->_is_nil())
1769     return false;
1770
1771   // GEOM shape of the main mesh
1772   GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1773
1774   // Name for the new sub-mesh
1775   QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1776
1777   // get geom object
1778   GEOM::GEOM_Object_var aGeomVar;
1779   QStringList aGEOMs;
1780   myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1781   if (aGEOMs.count() == 1)
1782   {
1783     //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1784     QString aGeomEntry = aGEOMs.first();
1785     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1786     aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1787   }
1788   else if (aGEOMs.count() > 1)
1789   {
1790     // create a GEOM group
1791     GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1792     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1793     if (!geomGen->_is_nil() && aStudy) {
1794       GEOM::GEOM_IGroupOperations_wrap op =
1795         geomGen->GetIGroupOperations(aStudy->StudyId());
1796       if (!op->_is_nil()) {
1797         // check and add all selected GEOM objects: they must be
1798         // a sub-shapes of the main GEOM and must be of one type
1799         int iSubSh = 0;
1800         TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1801         GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1802         aSeq->length(aGEOMs.count());
1803         QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1804         for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1805           QString aSubGeomEntry = (*aSubShapesIter);
1806           _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1807           GEOM::GEOM_Object_var aSubGeomVar =
1808             GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1809           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1810           if (iSubSh == 0) {
1811             aGroupType = aSubShapeType;
1812           } else {
1813             if (aSubShapeType != aGroupType)
1814               aGroupType = TopAbs_SHAPE;
1815           }
1816           aSeq[iSubSh] = aSubGeomVar;
1817         }
1818         // create a group
1819         GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1820         op->UnionList(aGroupVar, aSeq);
1821
1822         if (op->IsDone())
1823         {
1824           aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1825
1826           // publish the GEOM group in study
1827           QString aNewGeomGroupName ("Auto_group_for_");
1828           aNewGeomGroupName += aName;
1829           SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1830           SALOMEDS::SObject_wrap aNewGroupSO =
1831             geomGen->AddInStudy( aStudyVar, aGeomVar,
1832                                  aNewGeomGroupName.toLatin1().data(), mainGeom);
1833         }
1834       }
1835     }
1836   }
1837   else {
1838   }
1839   if (aGeomVar->_is_nil())
1840     return false;
1841
1842   SUIT_OverrideCursor aWaitCursor;
1843
1844   // create sub-mesh
1845   SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1846   _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1847   if ( aSubMeshSO ) {
1848     SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1849     theEntryList.append( aSubMeshSO->GetID().c_str() );
1850   }
1851
1852   for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1853   {
1854     if ( !isAccessibleDim( aDim )) continue;
1855
1856     // find or create algorithm
1857     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1858     if ( !anAlgoVar->_is_nil() )
1859       SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1860     // assign hypotheses
1861     for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1862     {
1863       int aHypIndex = currentHyp( aDim, aHypType );
1864       if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1865       {
1866         SMESH::SMESH_Hypothesis_var aHypVar =
1867           myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1868         if ( !aHypVar->_is_nil() )
1869           SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1870       }
1871     }
1872   }
1873
1874   // deselect geometry: next submesh should be created on other sub-shape
1875   myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1876   selectObject( _PTR(SObject)() );
1877   selectionDone();
1878
1879   checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1880
1881   return true;
1882 }
1883
1884 //================================================================================
1885 /*!
1886  * \brief Gets current hypothesis or algorithms
1887   * \param theDim - dimension of hypothesis or algorithm
1888   * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1889   * \retval int - current hypothesis or algorithms
1890  *
1891  * Gets current hypothesis or algorithms
1892  */
1893 //================================================================================
1894 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1895 {
1896   return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1897 }
1898
1899 //================================================================================
1900 /*!
1901  * \brief Returns true if hypotheses of given dim can be assigned
1902   * \param theDim - hypotheses dimension
1903   * \retval bool - result
1904  */
1905 //================================================================================
1906 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1907 {
1908   return myDlg->isTabEnabled( theDim );
1909 }
1910
1911 //================================================================================
1912 /*!
1913  * \brief Sets current hypothesis or algorithms
1914   * \param theDim - dimension of hypothesis or algorithm
1915   * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1916   * \param theIndex - Index of hypothesis
1917  *
1918  * Gets current hypothesis or algorithms
1919  */
1920 //================================================================================
1921 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1922                                      const int theHypType,
1923                                      const int theIndex )
1924 {
1925   myIgnoreAlgoSelection = true;
1926   myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1927   myIgnoreAlgoSelection = false;
1928 }
1929
1930 //================================================================================
1931 /*!
1932  * \brief Generates default and sets mesh/submesh name
1933  *
1934  * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1935  */
1936 //================================================================================
1937 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
1938 {
1939   QString aResName;
1940
1941   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1942   int i = 1;
1943
1944   QString aPrefix = thePrefix;
1945   if ( aPrefix.isEmpty() )
1946     aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1947
1948   _PTR(SObject) anObj;
1949   do
1950   {
1951     aResName = aPrefix + QString::number( i++ );
1952     anObj = aStudy->FindObject( aResName.toLatin1().data() );
1953   }
1954   while ( anObj );
1955
1956   QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1957     SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1958   aControl->setText( aResName );
1959 }
1960
1961 //================================================================================
1962 /*!
1963  * \brief Gets algorithm or creates it if necessary
1964   * \param theDim - specifies dimension of returned hypotheses/algorifms
1965   * \retval SMESH::SMESH_Hypothesis_var - algorithm
1966  *
1967  * Gets algorithm or creates it if necessary
1968  */
1969 //================================================================================
1970 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1971 {
1972   SMESH::SMESH_Hypothesis_var anAlgoVar;
1973
1974   // get type of the selected algo
1975   int aHypIndex = currentHyp( theDim, Algo );
1976   THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1977   if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1978     return anAlgoVar;
1979   QString aHypName = dataList[ aHypIndex ]->TypeName;
1980
1981   // get existing algoritms
1982   _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1983   QStringList tmp;
1984   existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1985
1986   // look for an existing algo of such a type
1987   THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1988   THypList::iterator anIter = aHypVarList.begin();
1989   for ( ; anIter != aHypVarList.end(); anIter++)
1990   {
1991     SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1992     CORBA::String_var aName = aHypVar->GetName();
1993     if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1994     {
1995       anAlgoVar = aHypVar;
1996       break;
1997     }
1998   }
1999
2000   if (anAlgoVar->_is_nil())
2001   {
2002     HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2003     if (aHypData)
2004     {
2005       QString aClientLibName = aHypData->ClientLibName;
2006       if ( aClientLibName.isEmpty() )
2007       {
2008         // Call hypothesis creation server method (without GUI)
2009         SMESH::SMESH_Hypothesis_var aHyp =
2010           SMESH::CreateHypothesis(aHypName, aHypName, true);
2011         aHyp.out();
2012       }
2013       else
2014       {
2015         // Get hypotheses creator client (GUI)
2016         SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2017
2018         // Create algorithm
2019         if (aCreator)
2020           aCreator->create( true, aHypName, myDlg, 0, QString::null );
2021         else {
2022           SMESH::SMESH_Hypothesis_var aHyp =
2023             SMESH::CreateHypothesis(aHypName, aHypName, true);
2024           aHyp.out();
2025         }
2026       }
2027       QStringList tmpList;
2028       _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2029       existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2030     }
2031
2032     THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2033     for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2034     {
2035       SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2036       CORBA::String_var aName = aHypVar->GetName();
2037       if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
2038       {
2039         anAlgoVar = aHypVar;
2040         break;
2041       }
2042     }
2043   }
2044
2045   return anAlgoVar._retn();
2046 }
2047
2048 //================================================================================
2049 /*!
2050  * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2051  *
2052  * Called when mesh is edited only.
2053  */
2054 //================================================================================
2055 void SMESHGUI_MeshOp::readMesh()
2056 {
2057   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2058   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2059   if ( !pObj )
2060     return;
2061
2062   if (myIsOnGeometry) {
2063     // Get name of mesh if current object is sub-mesh
2064     SMESH::SMESH_subMesh_var aSubMeshVar =
2065       SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2066     if ( !aSubMeshVar->_is_nil() )
2067     {
2068       SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
2069       if ( !aMeshVar->_is_nil() )
2070       {
2071         _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2072         QString aMeshName = name( aMeshSO );
2073         myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2074       }
2075       myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2076     }
2077
2078     // Get name of geometry object
2079     GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
2080     if ( !aGeomVar->_is_nil() )
2081     {
2082       _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2083       QString aShapeName = name( aGeomSO );
2084       myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2085     }
2086   }
2087
2088   // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2089   QStringList anExisting;
2090   const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2091   bool algoFound = false;
2092   for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2093   {
2094     // get algorithm
2095     existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2096     // find algo index among available ones
2097     int aHypIndex = -1;
2098     if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2099     {
2100       SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2101       HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2102       aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2103 //       if ( aHypIndex < 0 && algoData ) {
2104 //         // assigned algo is incompatible with other algorithms
2105 //         myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2106 //         aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2107 //       }
2108       algoFound = ( aHypIndex > -1 );
2109     }
2110     setCurrentHyp( dim, Algo, aHypIndex );
2111     // set existing and available hypothesis according to the selected algo
2112     if ( aHypIndex > -1 || !algoFound )
2113       onAlgoSelected( aHypIndex, dim );
2114   }
2115
2116   // get hypotheses
2117   bool hypWithoutAlgo = false;
2118   for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2119   {
2120     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2121     {
2122       // get hypotheses
2123       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2124       // find index of requered hypothesis among existing ones for this dimension and type
2125       int aHypIndex = -1;
2126       if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2127         aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2128                           myExistingHyps[ dim ][ hypType ] );
2129         if ( aHypIndex < 0 ) {
2130           // assigned hypothesis is incompatible with the algorithm
2131           if ( currentHyp( dim, Algo ) < 0 )
2132           { // none algo selected; it is edition for sure, of submesh maybe
2133             hypWithoutAlgo = true;
2134             myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2135             aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2136             myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2137           }
2138         }
2139       }
2140       setCurrentHyp( dim, hypType, aHypIndex );
2141     }
2142   }
2143   // make available other hyps of same type as one without algo
2144   if ( hypWithoutAlgo )
2145     onAlgoSelected( currentHyp( 0, Algo ), 0 );
2146 }
2147
2148 //================================================================================
2149 /*!
2150  * \brief Gets name of object
2151   * \param theSO - SObject
2152   * \retval QString - name of object
2153  *
2154  * Gets name of object
2155  */
2156 //================================================================================
2157 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2158 {
2159   QString aResName;
2160   if ( theSO )
2161   {
2162     _PTR(GenericAttribute) anAttr;
2163     _PTR(AttributeName)    aNameAttr;
2164     if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2165     {
2166       aNameAttr = anAttr;
2167       aResName = aNameAttr->Value().c_str();
2168     }
2169   }
2170   return aResName;
2171 }
2172
2173 //================================================================================
2174 /*!
2175  * \brief Finds hypothesis in input list
2176   * \param theHyp - hypothesis to be found
2177   * \param theHypList - input list of hypotheses
2178   * \retval int - index of hypothesis or -1 if it is not found
2179  *
2180  * Finds position of hypothesis in input list
2181  */
2182 //================================================================================
2183 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2184                            const THypList& theHypList ) const
2185 {
2186   int aRes = -1;
2187   if ( !theHyp->_is_nil() )
2188   {
2189     int i = 0;
2190     THypList::const_iterator anIter = theHypList.begin();
2191     for ( ; anIter != theHypList.end(); ++ anIter)
2192     {
2193       if ( theHyp->_is_equivalent( (*anIter).first ) )
2194       {
2195         aRes = i;
2196         break;
2197       }
2198       i++;
2199     }
2200   }
2201   return aRes;
2202 }
2203
2204 //================================================================================
2205 /*!
2206  * \brief Edits mesh or sub-mesh
2207   * \param theMess - Output parameter intended for returning error message
2208   * \retval bool  - TRUE if mesh is edited succesfully, FALSE otherwise
2209  *
2210  * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2211  */
2212 //================================================================================
2213 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2214 {
2215   theMess = "";
2216
2217   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2218   if ( aSMESHGen->_is_nil() )
2219     return false;
2220
2221   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2222   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2223   if ( !pObj )
2224     return false;
2225
2226   SUIT_OverrideCursor aWaitCursor;
2227
2228   // Set new name
2229   QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2230   SMESH::SetName( pObj, aName );
2231   int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2232
2233   // First, remove old algos in order to avoid messages on algorithm hiding
2234   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2235   {
2236     if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2237     {
2238       SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2239       SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2240       if ( anAlgoVar->_is_nil() || // no new algo selected or
2241            strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2242       {
2243         // remove old algorithm
2244         SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2245         myObjHyps[ dim ][ Algo ].clear();
2246       }
2247     }
2248   }
2249
2250   SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2251   CORBA::Object_var anObject = aSObject->GetObject();
2252   SMESH::SMESH_Mesh_var       aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2253   SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2254   bool isMesh = !aMeshVar->_is_nil();
2255   if ( !isMesh && !aSubMeshVar->_is_nil() )
2256     aMeshVar = aSubMeshVar->GetFather();
2257
2258   // Assign new algorithms and hypotheses
2259   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2260   {
2261     if ( !isAccessibleDim( dim )) continue;
2262
2263     // find or create algorithm
2264     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2265
2266     // assign new algorithm
2267     if ( !anAlgoVar->_is_nil() && // some algo selected and
2268          myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2269     {
2270       if ( isMesh )
2271         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2272       else if ( !aSubMeshVar->_is_nil() )
2273         SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2274
2275       myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2276     }
2277
2278     // assign hypotheses
2279     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2280     {
2281       int aNewHypIndex = currentHyp( dim, hypType );
2282       int anOldHypIndex = -1;
2283
2284       // remove old hypotheses
2285       if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2286       {
2287         anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2288                               myExistingHyps[ dim ][ hypType ] );
2289         if ( aNewHypIndex != anOldHypIndex || // different hyps
2290              anOldHypIndex == -1 )            // hyps of different algos
2291         {
2292           SMESH::RemoveHypothesisOrAlgorithmOnMesh
2293             ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2294           myObjHyps[ dim ][ hypType ].clear();
2295         }
2296       }
2297
2298       // assign new hypotheses
2299       if ( aNewHypIndex != anOldHypIndex && aNewHypIndex > -1 )
2300       {
2301         if ( isMesh )
2302           SMESH::AddHypothesisOnMesh
2303             (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2304         else if ( !aSubMeshVar->_is_nil() )
2305           SMESH::AddHypothesisOnSubMesh
2306             ( aSubMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2307       }
2308       // reread all hypotheses of mesh if necessary
2309       QStringList anExisting;
2310       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2311     }
2312   }
2313
2314   myHasConcurrentSubBefore =
2315     checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2316
2317   return true;
2318 }
2319
2320 //================================================================================
2321 /*!
2322  * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2323  *        creation/edition and, if (askUser) , proposes the uses to set up a desired
2324  *        order of sub-mesh computation.
2325  *        Returns \c true if a sub-mesh concurrency detected.
2326  */
2327 //================================================================================
2328
2329 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr    mesh,
2330                                               SMESH::SMESH_subMesh_ptr submesh,
2331                                               bool                     askUser)
2332 {
2333   if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2334     return false;
2335
2336   bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2337   if ( isNewConcurrent && askUser )
2338   {
2339     int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2340                                           tr("CONCURRENT_SUBMESH_APPEARS"),
2341                                           tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2342     if ( butID == 0 )
2343     {
2344       _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2345       LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2346       if ( meshSO && aSelectionMgr )
2347       {
2348         myDlg->setEnabled( false ); // disactivate selection
2349         selectionMgr()->clearFilters();
2350         selectObject( meshSO );
2351         SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
2352         qApp->processEvents();
2353
2354         myDlg->setEnabled( true );
2355         int obj = myDlg->getActiveObject();
2356         onActivateObject( obj ); // restore filter
2357         if ( !myToCreate )
2358         {
2359           selectObject( SMESH::FindSObject( submesh ));
2360           selectionDone();
2361         }
2362       }
2363     }
2364   }
2365
2366   return isNewConcurrent;
2367 }
2368
2369 //================================================================================
2370 /*!
2371  * \brief Verifies whether given operator is valid for this one
2372  * \param theOtherOp - other operation
2373  * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2374  *
2375  * method redefined from base class verifies whether given operator is valid for
2376  * this one (i.e. can be started "above" this operator). In current implementation method
2377  * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2378  * elements.
2379  */
2380 //================================================================================
2381 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2382 {
2383   return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2384 }
2385
2386 //================================================================================
2387 /*!
2388  * \brief SLOT. Is called when the user selects a way of geometry selection
2389  * \param theByMesh - true if the user wants to find geometry by mesh element
2390  */
2391 //================================================================================
2392 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2393 {
2394   if ( theByMesh ) {
2395     if ( !myShapeByMeshOp ) {
2396       myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2397       connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2398               SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2399       connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2400               SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2401     }
2402     // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2403     QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2404     if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2405       SMESH::SMESH_Mesh_var aMeshVar =
2406         SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2407       if ( !aMeshVar->_is_nil() ) {
2408         myDlg->hide(); // stop processing selection
2409         myShapeByMeshOp->setModule( getSMESHGUI() );
2410         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2411         myShapeByMeshOp->SetMesh( aMeshVar );
2412         myShapeByMeshOp->start();
2413       }
2414     }
2415   }
2416 }
2417
2418 //================================================================================
2419 /*!
2420  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2421  */
2422 //================================================================================
2423 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2424 {
2425   if ( myShapeByMeshOp == op ) {
2426     SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006  IPAL13980 - Object Browser update added
2427     myDlg->show();
2428     // Select a found geometry object
2429     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2430     if ( !aGeomVar->_is_nil() )
2431     {
2432       QString ID = aGeomVar->GetStudyEntry();
2433       if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2434         selectObject( aGeomSO );
2435         selectionDone();
2436       }
2437     }
2438   }
2439 }
2440
2441 //================================================================================
2442 /*!
2443  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2444  */
2445 //================================================================================
2446 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2447 {
2448   if ( myShapeByMeshOp == op && myDlg ) {
2449     myDlg->show();
2450   }
2451 }
2452
2453 //================================================================================
2454 /*!
2455  * \brief Selects a SObject
2456  * \param theSObj - the SObject to select
2457  */
2458 //================================================================================
2459 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2460 {
2461   if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2462     SALOME_ListIO anIOList;
2463     if ( theSObj ) {
2464       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2465         ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2466       anIOList.Append( anIO );
2467     }
2468     sm->setSelectedObjects( anIOList, false );
2469   }
2470 }
2471 //================================================================================
2472 /*!
2473  * \brief Create available list types of mesh
2474   * \param theTypeMesh - Output list of available types of mesh
2475  */
2476 //================================================================================
2477 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2478 {
2479   theTypeMesh.clear();
2480   theTypeMesh.append( tr( "MT_ANY" ) );
2481   if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2482   {
2483     theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2484     theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2485   }
2486   if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2487   {
2488     theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2489     theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2490   }
2491
2492 }
2493 //================================================================================
2494 /*!
2495  * \brief Set available types of mesh
2496   * \param theTypeMesh - List of available types of mesh
2497  */
2498 //================================================================================
2499 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2500 {
2501   myDlg->setAvailableMeshType( theTypeMesh );
2502 }
2503
2504 //================================================================================
2505 /*!
2506  * \brief SLOT. Is called when the user select type of mesh
2507   * \param theTabIndex - Index of current active tab
2508   * \param theIndex - Index of current type of mesh
2509  */
2510 //================================================================================
2511 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2512 {
2513   setFilteredAlgoData( theTabIndex, theIndex);
2514 }
2515
2516 //================================================================================
2517 /*!
2518  * \brief Set a filtered list of available algorithms by mesh type
2519   * \param theTabIndex - Index of current active tab
2520   * \param theIndex - Index of current type of mesh
2521  */
2522 //================================================================================
2523 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2524 {
2525   int aDim;
2526   THypDataList anAvailableAlgsData;
2527   QStringList anAvailableAlgs;
2528   QString anCompareType = "";
2529   bool isAvailableChoiceAlgo = false;
2530   int anCurrentAvailableAlgo = 0;
2531   bool isNone = true;
2532   switch ( theIndex ) {
2533   case MT_ANY:{
2534     anCompareType = "ANY";
2535     aDim = SMESH::DIM_3D;
2536   }
2537   break;
2538   case MT_TRIANGULAR:{
2539     aDim = SMESH::DIM_2D;
2540     anCompareType = "TRIA";
2541   }
2542   break;
2543   case MT_QUADRILATERAL:{
2544     aDim = SMESH::DIM_2D;
2545     anCompareType = "QUAD";
2546   }
2547   break;
2548   case MT_TETRAHEDRAL:{
2549     aDim = SMESH::DIM_3D;
2550     anCompareType = "TETRA";
2551   }
2552   break;
2553   case MT_HEXAHEDRAL:{
2554     aDim = SMESH::DIM_3D;
2555     anCompareType = "HEXA";
2556   }
2557   break;
2558   default:;
2559   }
2560   if ( anCompareType == "ANY" )
2561   {
2562     for ( int dim = SMESH::DIM_2D; dim <= SMESH::DIM_3D; dim++ )
2563     {
2564       isNone = currentHyp( dim, Algo ) < 0;
2565       isAvailableChoiceAlgo = false;
2566       // retrieves a list of available algorithms from resources
2567       availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2568       //return current algo in current tab and set new algorithm list
2569       HypothesisData* algoCur;
2570       if ( !isNone && !myAvailableHypData[dim][Algo].empty() ){
2571         algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2572       }
2573       myAvailableHypData[dim][Algo].clear();
2574       anAvailableAlgs.clear();
2575       for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2576       {
2577         HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2578         QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2579         GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
2580         if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2581         {
2582           aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2583         }
2584         if ( aGeomVar->_is_nil() ||
2585            ( !aGeomVar->_is_nil() && SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, !myIsMesh ))){
2586           anAvailableAlgs.append( curAlgo->Label );
2587           myAvailableHypData[dim][Algo].append( curAlgo );
2588         }
2589       }
2590       if ( !isNone && algoCur ){
2591         for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2592         {
2593           HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2594           if ( algoAny->Label == algoCur->Label ){
2595             isAvailableChoiceAlgo = true;
2596             anCurrentAvailableAlgo = i;
2597             break;
2598           }
2599         }
2600       }
2601       else if ( !isNone ){
2602         isAvailableChoiceAlgo = true;
2603         anCurrentAvailableAlgo = currentHyp( dim, Algo );
2604       }
2605       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2606       if ( isAvailableChoiceAlgo )
2607         setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2608     }
2609     int aDimNotGeometry = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2610     if ( !myIsOnGeometry )
2611       for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ){
2612         myDlg->disableTab( i );
2613       }
2614     for ( int i = aDimNotGeometry; i <= myMaxShapeDim; i++ ) {
2615       myDlg->enableTab( i );
2616     }
2617     myDlg->setCurrentTab( theTabIndex );
2618   }
2619   else
2620   {
2621     QString anCurrentAlgo;
2622     bool isReqDisBound = true;
2623     QString anCurrentCompareType = anCompareType;
2624     isNone = currentHyp( aDim, Algo ) < 0;
2625     if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
2626         myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
2627       isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2628     else if ( !isNone )
2629       isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2630     for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2631     {
2632       bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2633       isAvailableChoiceAlgo = false;
2634       // retrieves a list of available algorithms from resources
2635       availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2636       // finding algorithm which is selected
2637       if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
2638           myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
2639         anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
2640       else if ( !isNoneAlg )
2641         anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
2642       anAvailableAlgs.clear();
2643       myAvailableHypData[dim][Algo].clear();
2644       myFilteredAlgoData[dim].clear();
2645       // finding and adding algorithm depending on the type mesh
2646       for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2647       {
2648         HypothesisData* algoIn = anAvailableAlgsData.at( i );
2649         bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
2650         QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
2651         for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
2652         {
2653           if ( *inElemType == anCurrentCompareType ){
2654             isAvailableAlgo = true;
2655             break;
2656           }
2657         }
2658         if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ){
2659           QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2660           GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
2661           if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2662           {
2663             aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
2664           }
2665           if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
2666              ( !aGeomVar->_is_nil() && SMESH::IsApplicable( algoIn->TypeName, aGeomVar, !myIsMesh ))){
2667             anAvailableAlgs.append( algoIn->Label );
2668             myAvailableHypData[dim][Algo].append( algoIn );
2669             myFilteredAlgoData[dim].append( algoIn );
2670           }
2671         }
2672         //algorithm will be active, if the chosen algorithm available in the current mesh type
2673         if ( !isNoneAlg &&  isAvailableAlgo && algoIn->Label == anCurrentAlgo ){
2674           isAvailableChoiceAlgo = true;
2675           anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
2676         }
2677       }
2678       //set new algorithm list and select the current algorithm
2679       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2680       anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
2681       if ( isAvailableChoiceAlgo )
2682         setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2683       else
2684         setCurrentHyp( dim, Algo, -1 );
2685     }
2686
2687     int aMaxShapeDim = ( myMaxShapeDim != aDim) ? aDim : myMaxShapeDim;
2688     if ( isNone || isReqDisBound ) {
2689       for ( int i = SMESH::DIM_0D; i <= aMaxShapeDim; i++ ) {
2690         if ( aDim != i ) {
2691           myDlg->disableTab( i );
2692           setCurrentHyp(i, Algo, -1);
2693         }
2694       }
2695     }
2696     else if ( !isNone ){
2697       if ( aDim == SMESH::DIM_2D){
2698         myDlg->disableTab( SMESH::DIM_3D );
2699         setCurrentHyp( SMESH::DIM_3D, Algo, -1);
2700       }
2701       for ( int i = aMaxShapeDim; i > SMESH::DIM_0D; i-- )
2702       {
2703         isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
2704             myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2705         if ( isReqDisBound ) {
2706           for (int j = i - 1; j >= SMESH::DIM_0D; j--){
2707             myDlg->disableTab( j );
2708             setCurrentHyp( j , Algo, -1 );
2709           }
2710           break;
2711         }
2712       }
2713     }
2714     myDlg->enableTab( aDim );
2715     myDlg->setCurrentTab( aDim );
2716   }
2717   QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2718   QStringList aFilteredHypothesesSetsList;
2719   aFilteredHypothesesSetsList.clear();
2720   QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2721   for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2722   {
2723     HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2724     bool isAvailable = false;
2725     currentHypoSet->init( true );
2726     while ( currentHypoSet->next(), currentHypoSet->more() )
2727     {
2728       isAvailable = false;
2729       if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
2730       {
2731         for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
2732         {
2733           for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2734             HypothesisData* aCurAlgo =  hypData( i, Algo, j );
2735             if ( aCurAlgo->Label == algoDataIn->Label ){
2736               isAvailable = true;
2737               break;
2738             }
2739           }
2740           if ( isAvailable ) break;
2741         }
2742         if ( !isAvailable ) break;
2743       }
2744     }
2745     if ( isAvailable )
2746       aFilteredHypothesesSetsList.append( *inHypoSetName );
2747   }
2748   myDlg->setHypoSets( aFilteredHypothesesSetsList );
2749 }