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