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