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