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