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