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