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