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