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