Salome HOME
0052451: "Assign a set of hypotheses" is disabled by mistake
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI_MeshOp.cxx
23 //  Author : Sergey LITONIN, Open CASCADE S.A.S.
24
25 // SMESH includes
26 #include "SMESHGUI_MeshOp.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_MeshDlg.h"
30 #include "SMESHGUI_ShapeByMeshDlg.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_Hypotheses.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
35
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_NumberFilter.hxx>
38
39 // SALOME GEOM includes
40 #include <GEOM_SelectionFilter.h>
41 #include <GEOMBase.h>
42 #include <GeometryGUI.h>
43 #include <GEOM_wrap.hxx>
44 #include <GEOMImpl_Types.hxx>
45
46 // SALOME GUI includes
47 #include <SalomeApp_Tools.h>
48 #include <SalomeApp_Application.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <LightApp_UpdateFlags.h>
52 #include <SUIT_MessageBox.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_Session.h>
55 #include <SALOME_InteractiveObject.hxx>
56 #include <SALOME_ListIO.hxx>
57
58 // SALOME KERNEL includes
59 #include <SALOMEDS_SComponent.hxx>
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDS_Study.hxx>
62 #include <SALOMEDS_wrap.hxx>
63
64 // Qt includes
65 #include <QStringList>
66 #include <QLineEdit>
67 #include <QApplication>
68
69 // OCCT includes
70 #include <TopoDS.hxx>
71 #include <TopoDS_Shape.hxx>
72 #include <TopoDS_Shell.hxx>
73 #include <TopExp_Explorer.hxx>
74 #include <BRep_Tool.hxx>
75
76 // IDL includes
77 #include <SALOMEconfig.h>
78 #include CORBA_CLIENT_HEADER(SMESH_Gen)
79
80 //================================================================================
81 /*!
82  * \brief Constructor
83   * \param theToCreate - if this parameter is true then operation is used for creation,
84   * for editing otherwise
85  *
86  * Initialize operation
87 */
88 //================================================================================
89 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
90 : SMESHGUI_SelectionOp(),
91   myToCreate( theToCreate ),
92   myIsMesh( theIsMesh ),
93   myDlg( 0 ),
94   myShapeByMeshOp( 0 ),
95   myHypoSet( 0 )
96 {
97   if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
98     GeometryGUI::InitGeomGen();
99   myIsOnGeometry = true;
100   myMaxShapeDim = -1;
101 }
102
103 //================================================================================
104 /*!
105  * \brief Destructor
106 */
107 //================================================================================
108 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
109 {
110   if ( myDlg )
111     delete myDlg;
112 }
113
114 //================================================================================
115 /*!
116  * \brief Gets dialog of this operation
117   * \retval LightApp_Dialog* - pointer to dialog of this operation
118 */
119 //================================================================================
120 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
121 {
122   return myDlg;
123 }
124
125 //================================================================================
126 /*!
127  * \brief Creates or edits mesh
128   * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
129  *
130  * Virtual slot redefined from the base class called when "Apply" button is clicked
131  * creates or edits mesh
132  */
133 //================================================================================
134 bool SMESHGUI_MeshOp::onApply()
135 {
136   if (isStudyLocked())
137     return false;
138
139   QString aMess;
140   if ( !isValid( aMess ) )
141   {
142     dlg()->show();
143     if ( aMess != "" )
144       SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), aMess );
145     return false;
146   }
147
148   bool aResult = false;
149   aMess = "";
150   try
151   {
152     QStringList anEntryList;
153     if ( myToCreate && myIsMesh )
154       aResult = createMesh( aMess, anEntryList );
155     if ( myToCreate && !myIsMesh )
156       aResult = createSubMesh( aMess, anEntryList );
157     else if ( !myToCreate )
158       aResult = editMeshOrSubMesh( aMess );
159     if ( aResult )
160     {
161       SMESHGUI::Modified();
162       update( UF_ObjBrowser | UF_Model );
163       if( LightApp_Application* anApp =
164           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
165         myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
166     }
167   }
168   catch ( const SALOME::SALOME_Exception& S_ex )
169   {
170     SalomeApp_Tools::QtCatchCorbaException( S_ex );
171     aResult = false;
172   }
173   catch ( ... )
174   {
175     aResult = false;
176   }
177
178   if ( aResult )
179   {
180     if ( myToCreate )
181       setDefaultName();
182   }
183   else
184   {
185     if ( aMess == "" )
186       aMess = tr( "SMESH_OPERATION_FAILED" );
187     SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), aMess );
188   }
189
190   return aResult;
191 }
192
193 //================================================================================
194 /*!
195  * \brief Creates dialog if necessary and shows it
196  *
197  * Virtual method redefined from base class called when operation is started creates
198  * dialog if necessary and shows it, activates selection
199  */
200 //================================================================================
201 void SMESHGUI_MeshOp::startOperation()
202 {
203   if (!myDlg)
204   {
205     myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
206     for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
207     {
208       connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
209               this, SLOT( onCreateHyp( const int, const int ) ) );
210       connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
211               this, SLOT( onEditHyp( const int, const int ) ) );
212       connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
213               this, SLOT( onAlgoSelected( const int ) ) );
214     }
215     connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
216     connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
217     connect( myDlg, SIGNAL( selectMeshType( const int, const int ) ), SLOT( onAlgoSetByMeshType( const int, const int)));
218     if ( myToCreate ) {
219       if ( myIsMesh ) myHelpFileName = "constructing_meshes_page.html";
220       else            myHelpFileName = "constructing_submeshes_page.html";
221     }
222     else {
223       myHelpFileName = "editing_meshes_page.html";
224     }
225   }
226   SMESHGUI_SelectionOp::startOperation();
227   // iterate through dimensions and get available algoritms, set them to the dialog
228   _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
229   for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ )
230   {
231     SMESHGUI_MeshTab* aTab = myDlg->tab( i );
232     QStringList hypList;
233     // clear available hypotheses
234     aTab->setAvailableHyps( MainHyp, hypList );
235     aTab->setAvailableHyps( AddHyp, hypList );
236     aTab->setExistingHyps( MainHyp, hypList );
237     aTab->setExistingHyps( AddHyp, hypList );
238     myExistingHyps[ i ][ MainHyp ].clear();
239     myExistingHyps[ i ][ AddHyp ].clear();
240     // set algos
241     availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
242     aTab->setAvailableHyps( Algo, hypList );
243   }
244   if ( myToCreate )
245   {
246     setDefaultName();
247     myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
248   }
249   else
250     myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
251
252   myDlg->setCurrentTab( SMESH::DIM_3D );
253
254   QStringList TypeMeshList;
255   createMeshTypeList( TypeMeshList );
256   setAvailableMeshType( TypeMeshList );
257
258   myDlg->show();
259   myDlg->setGeomPopupEnabled(false);
260   selectionDone();
261
262   myIgnoreAlgoSelection = false;
263   myHasConcurrentSubBefore = false;
264
265   myObjectToSelect.clear();
266 }
267
268 //=================================================================================
269 /*!
270  * \brief Selects a recently created mesh or sub-mesh if necessary
271  *
272  * Virtual method redefined from base class called when operation is commited
273  * selects a recently created mesh or sub-mesh if necessary. Allows to perform
274  * selection when the custom selection filters are removed.
275  */
276 //=================================================================================
277 void SMESHGUI_MeshOp::commitOperation()
278 {
279   SMESHGUI_SelectionOp::commitOperation();
280
281   if ( !myObjectToSelect.isEmpty() ) {
282     if ( LightApp_SelectionMgr* aSelectionMgr = selectionMgr() ) {
283       SUIT_DataOwnerPtrList aList;
284       aList.append( new LightApp_DataOwner( myObjectToSelect ) );
285       aSelectionMgr->setSelected( aList );
286     }
287   }
288 }
289
290 //================================================================================
291 /*!
292  * \brief Creates selection filter
293   * \param theId - identifier of current selection widget
294   * \retval SUIT_SelectionFilter* - pointer to the created filter or null
295  *
296  * Creates selection filter in accordance with identifier of current selection widget
297  */
298 //================================================================================
299 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
300 {
301   if ( theId == SMESHGUI_MeshDlg::Geom )
302   {
303 //     TColStd_MapOfInteger allTypesMap;
304 //     for ( int i = 0; i < 10; i++ )
305 //       allTypesMap.Add( i );
306 //     return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
307     return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
308   }
309   else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
310     return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
311   else if ( theId == SMESHGUI_MeshDlg::Mesh )
312     return new SMESH_TypeFilter( SMESH::MESH );
313   else
314     return 0;
315 }
316
317 //================================================================================
318 /*!
319  * \brief check if selected shape is a sub-shape of the shape to mesh
320   * \retval bool - check result
321  */
322 //================================================================================
323 bool SMESHGUI_MeshOp::isSubshapeOk() const
324 {
325   if ( !myToCreate || myIsMesh ) // not submesh creation
326     return false;
327
328   // mesh
329   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
330   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
331   if (!pMesh) return false;
332
333   SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
334   if (mesh->_is_nil()) return false;
335
336   // main shape of the mesh
337   GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
338   if (mainGeom->_is_nil()) return false;
339
340   // geometry
341   QStringList aGEOMs;
342   myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
343
344   if (aGEOMs.count() > 0) {
345     GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
346     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
347     if (geomGen->_is_nil() || !aStudy) return false;
348
349     GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
350     if (op->_is_nil()) return false;
351
352     // check all selected shapes
353     QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
354     for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
355       QString aSubGeomEntry = (*aSubShapesIter);
356       _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
357       if (!pSubGeom) return false;
358
359       GEOM::GEOM_Object_var aSubGeomVar =
360         GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
361       if (aSubGeomVar->_is_nil()) return false;
362
363       // skl for NPAL14695 - implementation of searching of mainObj
364       GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
365                                                                         mainObj already exists! */
366       while(1) {
367         if (mainObj->_is_nil())
368           return false;
369         CORBA::String_var entry1 = mainObj->GetEntry();
370         CORBA::String_var entry2 = mainGeom->GetEntry();
371         if (std::string( entry1.in() ) == entry2.in() )
372           return true;
373         mainObj = op->GetMainShape(mainObj);
374       }
375     }
376   }
377
378   return false;
379 }
380
381 //================================================================================
382 /*!
383  * \brief Return name of the algorithm that does not support submeshes and makes
384  * submesh creation useless
385  *  \retval char* - string is to be deleted!!!
386  */
387 //================================================================================
388 char* SMESHGUI_MeshOp::isSubmeshIgnored() const
389 {
390   if ( myToCreate && !myIsMesh ) {
391
392     QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
393     QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
394     _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
395     if ( pMesh ) {
396
397       QStringList algoNames;
398       THypList    algoList;
399       existingHyps(3, Algo, pMesh, algoNames, algoList);
400       if (!algoList.empty()) {
401         HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
402         if ( algo &&
403              algo->InputTypes.empty() && // builds all dimensions it-self
404              !algo->IsSupportSubmeshes )
405           return CORBA::string_dup( algoNames[0].toLatin1().data() );
406       }
407
408 //       GEOM::GEOM_Object_var geom;
409 //       if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
410 //         geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
411
412 //       if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
413         existingHyps(2, Algo, pMesh, algoNames, algoList);
414         if (!algoList.empty()) {
415           HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
416           if ( algo &&
417                algo->InputTypes.empty() && // builds all dimensions it-self
418                !algo->IsSupportSubmeshes )
419             return CORBA::string_dup( algoNames[0].toLatin1().data() );
420         }
421 //       }
422     }
423   }
424   return 0;
425 }
426
427 //================================================================================
428 /*!
429  * \brief find an existing submesh by the selected shape
430  * \retval _PTR(SObject) - the found submesh SObject
431  */
432 //================================================================================
433 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
434 {
435   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
436   QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
437   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
438   _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
439   if ( pMesh && pGeom ) {
440     GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
441     if ( !geom->_is_nil() ) {
442       int tag = -1;
443       switch ( geom->GetShapeType() ) {
444       case GEOM::VERTEX:   tag = SMESH::Tag_SubMeshOnVertex;   break;
445       case GEOM::EDGE:     tag = SMESH::Tag_SubMeshOnEdge;     break;
446       case GEOM::WIRE:     tag = SMESH::Tag_SubMeshOnWire;     break;
447       case GEOM::FACE:     tag = SMESH::Tag_SubMeshOnFace;     break;
448       case GEOM::SHELL:    tag = SMESH::Tag_SubMeshOnShell;    break;
449       case GEOM::SOLID:    tag = SMESH::Tag_SubMeshOnSolid;    break;
450       case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
451       default:;
452       }
453       _PTR(GenericAttribute) anAttr;
454       _PTR(SObject) aSubmeshRoot;
455       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
456       if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
457       {
458         _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
459         for ( ; smIter->More(); smIter->Next() )
460         {
461           _PTR(SObject) aSmObj = smIter->Value();
462           if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
463             continue;
464           _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
465           for ( ; anIter1->More(); anIter1->Next()) {
466             _PTR(SObject) pGeom2 = anIter1->Value();
467             if ( pGeom2->ReferencedObject( pGeom2 ) &&
468                  pGeom2->GetID() == pGeom->GetID() )
469               return aSmObj;
470           }
471         }
472       }
473     }
474   }
475   return _PTR(SObject)();
476 }
477
478 //================================================================================
479 /*!
480  * \brief Updates dialog's look and feel
481  *
482  * Virtual method redefined from the base class updates dialog's look and feel
483  */
484 //================================================================================
485 void SMESHGUI_MeshOp::selectionDone()
486 {
487   if (!dlg()->isVisible() || !myDlg->isEnabled())
488     return;
489
490   SMESHGUI_SelectionOp::selectionDone();
491
492   try
493   {
494     myIsOnGeometry = true;
495
496     //Check geometry for mesh
497     QString anObjEntry = myDlg->selectedObject(SMESHGUI_MeshDlg::Obj);
498     _PTR(SObject) pObj = studyDS()->FindObjectID(anObjEntry.toLatin1().data());
499     if (pObj)
500     {
501       SMESH::SMESH_Mesh_var aMeshVar =
502         SMESH::SMESH_Mesh::_narrow(_CAST(SObject,pObj)->GetObject());
503       if (!aMeshVar->_is_nil()) {
504         if (!myToCreate && !aMeshVar->HasShapeToMesh())
505           myIsOnGeometry = false;
506       }
507     }
508
509     if (myIsOnGeometry)
510     {
511       // Enable tabs according to shape dimension
512
513       int shapeDim = 3;
514
515       QStringList aGEOMs;
516       myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
517       GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
518
519       if (aGEOMs.count() > 0) {
520         // one or more GEOM shape selected
521         aSeq->length(aGEOMs.count());
522         QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
523         int iSubSh = 0;
524         for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
525           QString aSubGeomEntry = (*aSubShapesIter);
526           _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
527           GEOM::GEOM_Object_var aSubGeomVar =
528             GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
529           aSeq[iSubSh] = aSubGeomVar;
530         }
531       } else {
532         // get geometry by selected sub-mesh
533         QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
534         _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
535         GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
536         if (!aGeomVar->_is_nil()) {
537           aSeq->length(1);
538           aSeq[0] = aGeomVar;
539         }
540       }
541
542       if (aSeq->length() > 0) {
543         shapeDim = -1;
544         for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
545           GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
546           switch ( aGeomVar->GetShapeType() ) {
547           case GEOM::SOLID:  shapeDim = 3; break;
548           case GEOM::SHELL:
549             // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
550             // {
551             //   TopoDS_Shape aShape;
552             //   bool isClosed = GEOMBase::GetShape(aGeomVar, aShape) && /*aShape.Closed()*/BRep_Tool::IsClosed(aShape);
553             //   shapeDim = qMax(isClosed ? 3 : 2, shapeDim);
554             // }
555             // break;
556           case GEOM::FACE:   shapeDim = qMax(2, shapeDim); break;
557           case GEOM::WIRE:
558           case GEOM::EDGE:   shapeDim = qMax(1, shapeDim); break;
559           case GEOM::VERTEX: shapeDim = qMax(0, shapeDim); break;
560           default:
561             {
562               TopoDS_Shape aShape;
563               if (GEOMBase::GetShape(aGeomVar, aShape))
564               {
565                 TopExp_Explorer exp (aShape, TopAbs_SOLID);
566                 if (exp.More()) {
567                   shapeDim = 3;
568                 }
569                 // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
570                 // else if ( exp.Init( aShape, TopAbs_SHELL ), exp.More() )
571                 // {
572                 //   shapeDim = 2;
573                 //   for (; exp.More() && shapeDim == 2; exp.Next()) {
574                 //     if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
575                 //       shapeDim = 3;
576                 //   }
577                 // }
578                 else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
579                   shapeDim = qMax(2, shapeDim);
580                 else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
581                   shapeDim = qMax(1, shapeDim);
582                 else if ( exp.Init( aShape, TopAbs_VERTEX ), exp.More() )
583                   shapeDim = qMax(0, shapeDim);
584               }
585             }
586           }
587           if ( shapeDim == 3 )
588             break;
589         }
590       }
591       for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
592         // reset algos before disabling tabs (0020138)
593         onAlgoSelected(-1, i);
594       }
595       myDlg->setMaxHypoDim( shapeDim );
596       myMaxShapeDim = shapeDim;
597       myDlg->setHypoSets( SMESH::GetHypothesesSets( shapeDim ));
598
599       if (!myToCreate) // edition: read hypotheses
600       {
601         if (pObj != 0)
602         {
603           SMESH::SMESH_subMesh_var submeshVar =
604             SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
605           myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !submeshVar->_is_nil() );
606           myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, true );
607           myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
608           myDlg->objectWg( SMESHGUI_MeshDlg::Geom, SMESHGUI_MeshDlg::Btn )->hide();
609           myDlg->updateGeometry();
610           myDlg->adjustSize();
611           readMesh();
612           myIsMesh = submeshVar->_is_nil();
613         }
614         else
615           myDlg->reset();
616       }
617       else if ( !myIsMesh ) // submesh creation
618       {
619         // if a submesh on the selected shape already exist, pass to submesh edition mode
620         if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
621           SMESH::SMESH_subMesh_var sm =
622             SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
623           bool editSubmesh = ( !sm->_is_nil() &&
624                                SUIT_MessageBox::question( myDlg, tr( "SMESH_WARNING" ),
625                                                           tr( "EDIT_SUBMESH_QUESTION"),
626                                                           SUIT_MessageBox::Yes |
627                                                           SUIT_MessageBox::No,
628                                                           SUIT_MessageBox::No )
629                                == SUIT_MessageBox::Yes );
630           if ( editSubmesh )
631           {
632             selectionMgr()->clearFilters();
633             selectObject( pSubmesh );
634             SMESHGUI::GetSMESHGUI()->switchToOperation(704);
635             return;
636           }
637           else
638           {
639             myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
640             selectObject( _PTR(SObject)() );
641             selectionDone();
642             return;
643           }
644         }
645         // discard selected mesh if submesh creation not allowed because of
646         // a global algorithm that does not support submeshes
647         if ( char* algoName = isSubmeshIgnored() ) {
648           SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
649                                     tr("SUBMESH_NOT_ALLOWED").arg(algoName));
650           CORBA::string_free( algoName );
651           myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
652           selectObject( _PTR(SObject)() );
653           selectionDone();
654           return;
655         }
656
657         // enable/disable popup for choice of geom selection way
658         bool enable = false;
659         QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
660         if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
661           SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
662           if ( !mesh->_is_nil() ) {
663             //rnv: issue 21056: EDF 1608 SMESH: Dialog Box "Create Sub Mesh": focus should automatically switch to geometry
664             QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
665             _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
666             if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
667               myDlg->activateObject(SMESHGUI_MeshDlg::Geom);
668             enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
669           }
670         }
671         myDlg->setGeomPopupEnabled( enable );
672       }
673     }
674     else { // no geometry defined
675       myDlg->enableTab( SMESH::DIM_3D );
676       QStringList hypList;
677       availableHyps( SMESH::DIM_3D, Algo, hypList,
678                      myAvailableHypData[SMESH::DIM_3D][Algo]);
679
680       SMESHGUI_MeshTab* aTab = myDlg->tab( SMESH::DIM_3D );
681       aTab->setAvailableHyps( Algo, hypList );
682       for (int i = SMESH::DIM_0D;i < SMESH::DIM_3D; ++i) {
683         myDlg->disableTab(i);
684       }
685       myMaxShapeDim = -1;
686       //Hide labels and fields (Mesh and Geometry)
687       myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, false );
688       myDlg->setObjectShown( SMESHGUI_MeshDlg::Geom, false );
689       myDlg->adjustSize();
690       readMesh();
691     }
692     int curIndex = myDlg->currentMeshType( );
693     QStringList TypeMeshList;
694     createMeshTypeList( TypeMeshList );
695     setAvailableMeshType( TypeMeshList );
696     curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
697     myDlg->setCurrentMeshType( curIndex );
698     setFilteredAlgoData( myMaxShapeDim, curIndex);
699   }
700   catch ( const SALOME::SALOME_Exception& S_ex )
701   {
702     SalomeApp_Tools::QtCatchCorbaException( S_ex );
703   }
704   catch ( ... )
705   {
706   }
707 }
708
709 //================================================================================
710 /*!
711  * \brief Verifies validity of input data
712   * \param theMess - Output parameter intended for returning error message
713   * \retval bool  - TRUE if input data is valid, false otherwise
714  *
715  * Verifies validity of input data. This method is called when "Apply" or "OK" button
716  * is pressed before mesh creation or editing.
717  */
718 //================================================================================
719 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
720 {
721   // Selected object to be  edited
722   if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
723   {
724     theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
725     return false;
726   }
727
728   // Name
729   QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj ).trimmed();
730   if ( aMeshName.isEmpty() )
731   {
732     theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
733     return false;
734   }
735
736 /*  // Imported mesh, if create sub-mesh or edit mesh
737   if ( !myToCreate || ( myToCreate && !myIsMesh ))
738   {
739     QString aMeshEntry = myDlg->selectedObject
740       ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
741     if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
742       SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
743       if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
744         theMess = tr( "IMPORTED_MESH" );
745         return false;
746       }
747     }
748   }*/
749
750   // Geom
751   if ( myToCreate )
752   {
753     QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
754     if ( aGeomEntry.isEmpty() )
755     {
756       theMess = tr( myIsMesh ?
757                     "GEOMETRY_OBJECT_IS_NOT_DEFINED_MESH" :
758                     "GEOMETRY_OBJECT_IS_NOT_DEFINED_SUBMESH");
759       if ( !myIsMesh )
760         return false;
761       dlg()->show();
762       if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
763            SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
764       {
765         theMess = "";
766         return false;
767       }
768       return true;
769     }
770     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
771     if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
772     {
773       theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
774       return false;
775     }
776
777     // Mesh
778     if ( !myIsMesh ) // i.e sub-mesh creation,
779     {
780       QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
781       if ( aMeshEntry == "" )
782       {
783         theMess = tr( "MESH_IS_NOT_DEFINED" );
784         return false;
785       }
786       _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
787       if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
788       {
789         theMess = tr( "MESH_IS_NULL" );
790         return false;
791       }
792       if ( !isSubshapeOk() )
793       {
794         theMess = tr( "INVALID_SUBSHAPE" );
795         return false;
796       }
797     }
798   }
799
800   return true;
801 }
802
803 //================================================================================
804 /*!
805  * \brief check compatibility of the algorithm and another algorithm or hypothesis
806   * \param theAlgoData - algorithm data
807   * \param theHypData - hypothesis data
808   * \param theHypType - hypothesis type
809   * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
810   * \retval bool - check result
811  */
812 //================================================================================
813 static bool isCompatible(const HypothesisData* theAlgoData,
814                          const HypothesisData* theHypData,
815                          const int             theHypType)
816 {
817   if ( !theAlgoData )
818     return true;
819
820   if ( theHypType == SMESHGUI_MeshOp::Algo )
821     return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
822
823   bool isOptional;
824   return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
825 }
826
827 //================================================================================
828 /*!
829  * \brief Gets available hypotheses or algorithms
830   * \param theDim - specifies dimension of returned hypotheses/algorifms
831   * \param theHypType - specifies whether algorims or hypotheses or additional ones
832   * are retrieved (possible values are in HypType enumeration)
833   * \param theHyps - Output list of hypotheses' names
834   * \param theAlgoData - to select hypos able to be used by this algo (optional)
835  *
836  * Gets available hypotheses or algorithm in accordance with input parameters
837  */
838 //================================================================================
839 void SMESHGUI_MeshOp::availableHyps( const int       theDim,
840                                      const int       theHypType,
841                                      QStringList&    theHyps,
842                                      THypDataList&   theDataList,
843                                      HypothesisData* theAlgoData ) const
844 {
845   theDataList.clear();
846   theHyps.clear();
847   bool isAlgo = ( theHypType == Algo );
848   bool isAux  = ( theHypType == AddHyp );
849   QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux, myIsOnGeometry, !myIsMesh );
850
851   QStringList::const_iterator anIter;
852   for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
853   {
854     HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
855     if ( isCompatible ( theAlgoData, aData, theHypType )) {
856       theDataList.append( aData );
857       theHyps.append( aData->Label );
858     }
859   }
860 }
861
862 //================================================================================
863 /*!
864  * \brief Gets existing hypotheses or algorithms
865  *  \param theDim - specifies dimension of returned hypotheses/algorifms
866  *  \param theHypType - specifies whether algorims or hypotheses or additional ones
867  *  are retrieved (possible values are in HypType enumeration)
868  *  \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
869  *  \param theHyps - output list of names.
870  *  \param theHypVars - output list of variables.
871  *  \param theAlgoData - to select hypos able to be used by this algo (optional)
872  *
873  * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
874  * input parameters
875  */
876 //================================================================================
877 void SMESHGUI_MeshOp::existingHyps( const int       theDim,
878                                     const int       theHypType,
879                                     _PTR(SObject)   theFather,
880                                     QStringList&    theHyps,
881                                     THypList&       theHypList,
882                                     HypothesisData* theAlgoData)
883 {
884   // Clear hypoheses list
885   theHyps.clear();
886   theHypList.clear();
887
888   if ( !theFather )
889     return;
890
891   const bool isAux  = ( theHypType == AddHyp );
892
893   _PTR(SObject)          aHypRoot;
894   _PTR(GenericAttribute) anAttr;
895   _PTR(AttributeName)    aName;
896   _PTR(AttributeIOR)     anIOR;
897
898   bool isMesh = !_CAST( SComponent, theFather );
899   int aPart = -1;
900   if ( isMesh )
901     aPart = theHypType == Algo ? SMESH::Tag_RefOnAppliedAlgorithms : SMESH::Tag_RefOnAppliedHypothesis;
902   else
903     aPart = theHypType == Algo ? SMESH::Tag_AlgorithmsRoot : SMESH::Tag_HypothesisRoot;
904
905   if ( theFather->FindSubObject( aPart, aHypRoot ) )
906   {
907     _PTR(ChildIterator) anIter =
908       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
909     for ( ; anIter->More(); anIter->Next() )
910     {
911       _PTR(SObject) anObj = anIter->Value();
912       if ( isMesh ) // i.e. mesh or submesh
913       {
914         _PTR(SObject) aRefObj;
915         if ( anObj->ReferencedObject( aRefObj ) )
916           anObj = aRefObj;
917         else
918           continue;
919       }
920       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
921       {
922         aName = anAttr;
923         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
924         if ( !CORBA::is_nil( aVar ) )
925         {
926           SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
927           if ( !aHypVar->_is_nil() )
928           {
929             CORBA::String_var hypType = aHypVar->GetName();
930             HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() );
931             if ( !aData) continue;
932             if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
933                  ( isCompatible ( theAlgoData, aData, theHypType )) &&
934                  ( theHypType == Algo || isAux == aData->IsAuxOrNeedHyp ))
935             {
936               std::string aHypName = aName->Value();
937               theHyps.append( aHypName.c_str() );
938               theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
939             }
940           }
941         }
942       }
943     }
944   }
945 }
946
947 //================================================================================
948 /*!
949  * \brief If create or edit a submesh, return a hypothesis holding parameters used
950  *        to mesh a sub-shape
951   * \param aHypType - The hypothesis type name
952   * \param aServerLib - Server library name
953   * \param hypData - The structure holding the hypothesis type etc.
954   * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
955  */
956 //================================================================================
957 SMESH::SMESH_Hypothesis_var
958 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
959                                           const QString& aServerLib ) const
960 {
961   if ( aHypType.isEmpty() || aServerLib.isEmpty() )
962     return SMESH::SMESH_Hypothesis::_nil();
963
964   const int nbColonsInMeshEntry = 3;
965   bool isSubMesh = myToCreate ?
966     !myIsMesh :
967     myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
968
969   // get mesh and geom object
970   SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
971   GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
972
973   QString anEntry;
974   if ( isSubMesh )
975   {
976     anEntry = myDlg->selectedObject
977       ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
978     if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
979     {
980       CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
981       if ( myToCreate ) // mesh and geom may be selected
982       {
983         aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
984         anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
985         if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
986           aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
987       }
988       else // edition: sub-mesh may be selected
989       {
990         SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
991         if ( !sm->_is_nil() ) {
992           aMeshVar = sm->GetFather();
993           aGeomVar = sm->GetSubShape();
994         }
995       }
996     }
997   }
998   else // mesh
999   {
1000     if ( !myToCreate ) // mesh to edit can be selected
1001     {
1002       anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1003       if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1004       {
1005         aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1006         if ( !aMeshVar->_is_nil() )
1007           aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
1008       }
1009     }
1010     if ( aGeomVar->_is_nil() ) {
1011       anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1012       if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
1013       {
1014         aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1015       }
1016     }
1017   }
1018
1019   SMESH::SMESH_Hypothesis_var hyp =
1020     SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1021                                                            aServerLib.toLatin1().data(),
1022                                                            aMeshVar,
1023                                                            aGeomVar,
1024                                                            /*byMesh = */isSubMesh);
1025   if ( hyp->_is_nil() && isSubMesh )
1026     hyp = SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
1027                                                                  aServerLib.toLatin1().data(),
1028                                                                  aMeshVar,
1029                                                                  aGeomVar,
1030                                                                  /*byMesh = */false);
1031   return hyp;
1032 }
1033
1034 //================================================================================
1035 /*!
1036  * \Brief Returns tab dimention
1037   * \param tab - the tab in the dlg
1038   * \param dlg - my dialogue
1039   * \retval int - dimention
1040  */
1041 //================================================================================
1042 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
1043 {
1044   int aDim = -1;
1045   for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1046     if (tab == dlg->tab(i))
1047       aDim = i;
1048   return aDim;
1049 }
1050
1051 //================================================================================
1052 /*!
1053  * \brief Create hypothesis
1054   * \param theHypType - hypothesis category (main or additional)
1055   * \param theIndex - index of type of hypothesis to be cerated
1056  *
1057  * Specifies dimension of hypothesis to be created (using sender() method),
1058  * specifies its type and calls method for hypothesis creation
1059  */
1060 //================================================================================
1061 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
1062 {
1063   // Specifies dimension of hypothesis to be created
1064   int aDim = getTabDim( sender(), myDlg );
1065   if (aDim == -1)
1066     return;
1067
1068   // Specifies type of hypothesis to be created
1069   THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
1070   if (theIndex < 0 || theIndex >= dataList.count())
1071     return;
1072   QString aHypTypeName = dataList[ theIndex ]->TypeName;
1073
1074   // Create hypothesis
1075   createHypothesis(aDim, theHypType, aHypTypeName);
1076 }
1077
1078 namespace
1079 {
1080   QString GetUniqueName (const QStringList& theHypNames,
1081                          const QString& theName,
1082                          size_t theIteration = 1)
1083   {
1084     QString aName = theName + "_" + QString::number( theIteration );
1085     if ( theHypNames.contains( aName ) )
1086       return GetUniqueName( theHypNames, theName, ++theIteration );
1087     return aName;
1088   }
1089 }
1090
1091 //================================================================================
1092 /*!
1093  *  Create hypothesis and update dialog.
1094  *  \param theDim - dimension of hypothesis to be created
1095  *  \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
1096  *  \param theTypeName - specifies hypothesis to be created
1097  */
1098 //================================================================================
1099 void SMESHGUI_MeshOp::createHypothesis(const int theDim,
1100                                        const int theType,
1101                                        const QString& theTypeName)
1102 {
1103   HypothesisData* aData = SMESH::GetHypothesisData(theTypeName);
1104   if (!aData)
1105     return;
1106
1107   myDim = theDim;
1108   myType = theType;
1109   QStringList aHypNames;
1110   TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
1111   for ( ; aDimIter != myExistingHyps.end(); aDimIter++) {
1112     const TType2HypList& aType2HypList = aDimIter.value();
1113     TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
1114     for ( ; aTypeIter != aType2HypList.end(); aTypeIter++) {
1115       const THypList& aHypList = aTypeIter.value();
1116       THypList::const_iterator anIter = aHypList.begin();
1117       for ( ; anIter != aHypList.end(); anIter++) {
1118         const THypItem& aHypItem = *anIter;
1119         const QString& aHypName = aHypItem.second;
1120         aHypNames.append(aHypName);
1121       }
1122     }
1123   }
1124   QString aHypName = GetUniqueName( aHypNames, aData->Label);
1125
1126   // existing hypos
1127   bool dialog = false;
1128
1129   QString aClientLibName = aData->ClientLibName;
1130   if (aClientLibName == "") {
1131     // Call hypothesis creation server method (without GUI)
1132     SMESH::SMESH_Hypothesis_var aHyp =
1133       SMESH::CreateHypothesis(theTypeName, aHypName, false);
1134     aHyp.out();
1135   }
1136   else {
1137     // Get hypotheses creator client (GUI)
1138     SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
1139
1140     // Create hypothesis
1141     if (aCreator) {
1142       // Get parameters appropriate to initialize a new hypothesis
1143       SMESH::SMESH_Hypothesis_var initParamHyp =
1144         getInitParamsHypothesis(theTypeName, aData->ServerLibName);
1145
1146       removeCustomFilters(); // Issue 0020170
1147
1148       // Get Entry of the Geom object
1149       QString aGeomEntry = "";
1150       QString aMeshEntry = "";
1151       QString anObjEntry = "";
1152       aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1153       aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1154       anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1155
1156       if ( myToCreate && myIsMesh )
1157         aMeshEntry = aGeomEntry;
1158
1159       if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1160         _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1161         GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1162         aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1163       }
1164
1165       if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1166         _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1167         bool isMesh;
1168         GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1169         if ( !aGeomVar->_is_nil() )
1170         {
1171           aGeomEntry = aGeomVar->GetStudyEntry();
1172           if ( isMesh )
1173             aMeshEntry = aGeomEntry;
1174         }
1175       }
1176
1177       if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1178         // take geometry from submesh being created
1179         _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1180         if ( pObj ) {
1181           // if current object is sub-mesh
1182           SMESH::SMESH_subMesh_var aSubMeshVar =
1183             SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1184           if ( !aSubMeshVar->_is_nil() ) {
1185             SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
1186             if ( !aMeshVar->_is_nil() ) {
1187               _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1188               GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1189               if ( !aGeomVar->_is_nil() )
1190                 aMeshEntry = aGeomVar->GetStudyEntry();
1191             }
1192           }
1193         }
1194       }
1195
1196       aCreator->setShapeEntry( aGeomEntry );
1197       if ( aMeshEntry != "" )
1198         aCreator->setMainShapeEntry( aMeshEntry );
1199       myDlg->setEnabled( false );
1200       aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1201       dialog = true;
1202     }
1203     else {
1204      SMESH::SMESH_Hypothesis_var aHyp =
1205        SMESH::CreateHypothesis(theTypeName, aHypName, false);
1206      aHyp.out();
1207     }
1208   }
1209
1210   if( !dialog )
1211     onHypoCreated(2);
1212 }
1213
1214 //================================================================================
1215 /*!
1216  *  Necessary steps after hypothesis creation
1217  *  \param result - creation result:
1218  *   0 = rejected
1219  *   1 = accepted
1220  *   2 = additional value meaning that slot is called not from dialog box
1221  */
1222 //================================================================================
1223 void SMESHGUI_MeshOp::onHypoCreated( int result )
1224 {
1225   if( result != 2 )
1226   {
1227     int obj = myDlg->getActiveObject();
1228     onActivateObject( obj ); // Issue 0020170. Restore filters
1229     myDlg->setEnabled( true );
1230   }
1231
1232   _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1233
1234   int nbHyp = myExistingHyps[myDim][myType].count();
1235   HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1236   QStringList aNewHyps;
1237   existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1238   if (aNewHyps.count() > nbHyp)
1239   {
1240     for (int i = nbHyp; i < aNewHyps.count(); i++)
1241       myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1242   }
1243
1244   if( result!=2 && myHypoSet )
1245     processSet();
1246 }
1247
1248 //================================================================================
1249 /*!
1250  * \brief Calls plugin methods for hypothesis editing
1251   * \param theHypType - specifies whether main hypothesis or additional one
1252   * is edited
1253   * \param theIndex - index of existing hypothesis
1254  *
1255  * Calls plugin methods for hypothesis editing
1256  */
1257 //================================================================================
1258 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1259 {
1260   // Speicfies dimension of hypothesis to be created
1261   int aDim = getTabDim( sender(), myDlg );
1262   if (aDim == -1)
1263     return;
1264
1265   const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1266   if ( theIndex < 0 || theIndex >= aList.count() )
1267     return;
1268   const THypItem& aHypItem = aList[ theIndex ];
1269   SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1270   if ( aHyp->_is_nil() )
1271     return;
1272
1273   SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1274   if ( aCreator )
1275   {
1276     // Get initial parameters
1277     SMESH::SMESH_Hypothesis_var initParamHyp =
1278       getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1279     aCreator->setInitParamsHypothesis( initParamHyp );
1280
1281     // Get Entry of the Geom object
1282     QString aGeomEntry = "";
1283     QString aMeshEntry = "";
1284     QString anObjEntry = "";
1285     aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1286     aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1287     anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1288
1289     if ( myToCreate && myIsMesh )
1290       aMeshEntry = aGeomEntry;
1291
1292     if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
1293       _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1294       GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1295       aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1296     }
1297
1298     if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
1299       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1300       bool isMesh;
1301       GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
1302       if ( !aGeomVar->_is_nil() )
1303       {
1304         aGeomEntry = aGeomVar->GetStudyEntry();
1305         if ( isMesh )
1306           aMeshEntry = aGeomEntry;
1307       }
1308     }
1309
1310     if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
1311       // take geometry from submesh being created
1312       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1313       if ( pObj ) {
1314         // if current object is sub-mesh
1315         SMESH::SMESH_subMesh_var aSubMeshVar =
1316           SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1317         if ( !aSubMeshVar->_is_nil() ) {
1318           SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
1319           if ( !aMeshVar->_is_nil() ) {
1320             _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1321             GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1322             if ( !aGeomVar->_is_nil() )
1323               aMeshEntry = aGeomVar->GetStudyEntry();
1324           }
1325         }
1326       }
1327     }
1328
1329     aCreator->setShapeEntry( aGeomEntry );
1330     if ( aMeshEntry != "" )
1331       aCreator->setMainShapeEntry( aMeshEntry );
1332     removeCustomFilters(); // Issue 0020170
1333     myDlg->setEnabled( false );
1334     aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1335   }
1336 }
1337
1338 //================================================================================
1339 /*!
1340  *  Necessary steps after hypothesis edition
1341  *  \param result - creation result:
1342  *   0 = rejected
1343  *   1 = accepted
1344  */
1345 //================================================================================
1346 void SMESHGUI_MeshOp::onHypoEdited( int result )
1347 {
1348   int obj = myDlg->getActiveObject();
1349   onActivateObject( obj ); // Issue 0020170. Restore filters
1350   myDlg->setEnabled( true );
1351 }
1352
1353 //================================================================================
1354 /*!
1355  * \brief access to hypothesis data
1356   * \param theDim - hyp dimension
1357   * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1358   * \param theIndex - index in the list
1359   * \retval HypothesisData* - result data, may be 0
1360  */
1361 //================================================================================
1362 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1363                                           const int theHypType,
1364                                           const int theIndex)
1365 {
1366   if ( theDim     > -1 && theDim    <= SMESH::DIM_3D &&
1367        theHypType > -1 && theHypType < NbHypTypes &&
1368        theIndex   > -1 && theIndex   < myAvailableHypData[ theDim ][ theHypType ].count() )
1369     return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1370   return 0;
1371 }
1372
1373 //================================================================================
1374 /*!
1375  * \brief Set available algos and hypos according to the selected algorithm
1376   * \param theIndex - algorithm index
1377  */
1378 //================================================================================
1379 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1380                                       const int theDim )
1381 {
1382   if ( myIgnoreAlgoSelection )
1383     return;
1384
1385   int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1386   if (aDim == -1)
1387     return;
1388
1389   // find highest available dimension, all algos of this dimension are available for choice
1390   int aTopDim = -1;
1391   for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1392     if (isAccessibleDim( i ))
1393       aTopDim = i;
1394   if (aTopDim == -1)
1395     return;
1396
1397   const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1398
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     CORBA::String_var name = SMESH::GetGeomName( pObj );
2085     if ( name.in() )
2086       myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
2087   }
2088
2089   // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2090   QStringList anExisting;
2091   const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2092   bool algoFound = false;
2093   for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2094   {
2095     // get algorithm
2096     existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2097     // find algo index among available ones
2098     int aHypIndex = -1;
2099     if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2100     {
2101       SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2102       HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2103       aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2104 //       if ( aHypIndex < 0 && algoData ) {
2105 //         // assigned algo is incompatible with other algorithms
2106 //         myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2107 //         aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2108 //       }
2109       algoFound = ( aHypIndex > -1 );
2110     }
2111     setCurrentHyp( dim, Algo, aHypIndex );
2112     // set existing and available hypothesis according to the selected algo
2113     if ( aHypIndex > -1 || !algoFound )
2114       onAlgoSelected( aHypIndex, dim );
2115   }
2116
2117   // get hypotheses
2118   bool hypWithoutAlgo = false;
2119   for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2120   {
2121     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2122     {
2123       // get hypotheses
2124       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2125       // find index of requered hypothesis among existing ones for this dimension and type
2126       int aHypIndex = -1;
2127       if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2128         aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2129                           myExistingHyps[ dim ][ hypType ] );
2130         if ( aHypIndex < 0 ) {
2131           // assigned hypothesis is incompatible with the algorithm
2132           if ( currentHyp( dim, Algo ) < 0 )
2133           { // none algo selected; it is edition for sure, of submesh maybe
2134             hypWithoutAlgo = true;
2135             myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2136             aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2137             myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2138           }
2139         }
2140       }
2141       setCurrentHyp( dim, hypType, aHypIndex );
2142     }
2143   }
2144   // make available other hyps of same type as one without algo
2145   if ( hypWithoutAlgo )
2146     onAlgoSelected( currentHyp( 0, Algo ), 0 );
2147 }
2148
2149 //================================================================================
2150 /*!
2151  * \brief Gets name of object
2152   * \param theSO - SObject
2153   * \retval QString - name of object
2154  *
2155  * Gets name of object
2156  */
2157 //================================================================================
2158 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2159 {
2160   QString aResName;
2161   if ( theSO )
2162   {
2163     _PTR(GenericAttribute) anAttr;
2164     _PTR(AttributeName)    aNameAttr;
2165     if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2166     {
2167       aNameAttr = anAttr;
2168       aResName = aNameAttr->Value().c_str();
2169     }
2170   }
2171   return aResName;
2172 }
2173
2174 //================================================================================
2175 /*!
2176  * \brief Finds hypothesis in input list
2177   * \param theHyp - hypothesis to be found
2178   * \param theHypList - input list of hypotheses
2179   * \retval int - index of hypothesis or -1 if it is not found
2180  *
2181  * Finds position of hypothesis in input list
2182  */
2183 //================================================================================
2184 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2185                            const THypList& theHypList ) const
2186 {
2187   int aRes = -1;
2188   if ( !theHyp->_is_nil() )
2189   {
2190     int i = 0;
2191     THypList::const_iterator anIter = theHypList.begin();
2192     for ( ; anIter != theHypList.end(); ++ anIter)
2193     {
2194       if ( theHyp->_is_equivalent( (*anIter).first ) )
2195       {
2196         aRes = i;
2197         break;
2198       }
2199       i++;
2200     }
2201   }
2202   return aRes;
2203 }
2204
2205 //================================================================================
2206 /*!
2207  * \brief Edits mesh or sub-mesh
2208   * \param theMess - Output parameter intended for returning error message
2209   * \retval bool  - TRUE if mesh is edited succesfully, FALSE otherwise
2210  *
2211  * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2212  */
2213 //================================================================================
2214 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2215 {
2216   theMess = "";
2217
2218   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2219   if ( aSMESHGen->_is_nil() )
2220     return false;
2221
2222   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2223   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2224   if ( !pObj )
2225     return false;
2226
2227   SUIT_OverrideCursor aWaitCursor;
2228
2229   // Set new name
2230   QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2231   SMESH::SetName( pObj, aName );
2232   int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2233
2234   // First, remove old algos in order to avoid messages on algorithm hiding
2235   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2236   {
2237     if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2238     {
2239       SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2240       SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2241       if ( anAlgoVar->_is_nil() || // no new algo selected or
2242            strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2243       {
2244         // remove old algorithm
2245         SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2246         myObjHyps[ dim ][ Algo ].clear();
2247       }
2248     }
2249   }
2250
2251   SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2252   CORBA::Object_var anObject = aSObject->GetObject();
2253   SMESH::SMESH_Mesh_var       aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2254   SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2255   bool isMesh = !aMeshVar->_is_nil();
2256   if ( !isMesh && !aSubMeshVar->_is_nil() )
2257     aMeshVar = aSubMeshVar->GetFather();
2258
2259   // Assign new algorithms and hypotheses
2260   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2261   {
2262     if ( !isAccessibleDim( dim )) continue;
2263
2264     // find or create algorithm
2265     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2266
2267     // assign new algorithm
2268     if ( !anAlgoVar->_is_nil() && // some algo selected and
2269          myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2270     {
2271       if ( isMesh )
2272         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2273       else if ( !aSubMeshVar->_is_nil() )
2274         SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2275
2276       myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2277     }
2278
2279     // assign hypotheses
2280     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2281     {
2282       int aNewHypIndex = currentHyp( dim, hypType );
2283       int anOldHypIndex = -1;
2284
2285       // remove old hypotheses
2286       if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2287       {
2288         anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2289                               myExistingHyps[ dim ][ hypType ] );
2290         if ( aNewHypIndex != anOldHypIndex || // different hyps
2291              anOldHypIndex == -1 )            // hyps of different algos
2292         {
2293           SMESH::RemoveHypothesisOrAlgorithmOnMesh
2294             ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2295           myObjHyps[ dim ][ hypType ].clear();
2296         }
2297       }
2298
2299       // assign new hypotheses
2300       if ( aNewHypIndex != anOldHypIndex && aNewHypIndex > -1 )
2301       {
2302         if ( isMesh )
2303           SMESH::AddHypothesisOnMesh
2304             (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2305         else if ( !aSubMeshVar->_is_nil() )
2306           SMESH::AddHypothesisOnSubMesh
2307             ( aSubMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2308       }
2309       // reread all hypotheses of mesh if necessary
2310       QStringList anExisting;
2311       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2312     }
2313   }
2314
2315   myHasConcurrentSubBefore =
2316     checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2317
2318   return true;
2319 }
2320
2321 //================================================================================
2322 /*!
2323  * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2324  *        creation/edition and, if (askUser) , proposes the uses to set up a desired
2325  *        order of sub-mesh computation.
2326  *        Returns \c true if a sub-mesh concurrency detected.
2327  */
2328 //================================================================================
2329
2330 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr    mesh,
2331                                               SMESH::SMESH_subMesh_ptr submesh,
2332                                               bool                     askUser)
2333 {
2334   if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2335     return false;
2336
2337   bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2338   if ( isNewConcurrent && askUser )
2339   {
2340     int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2341                                           tr("CONCURRENT_SUBMESH_APPEARS"),
2342                                           tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2343     if ( butID == 0 )
2344     {
2345       _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2346       LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2347       if ( meshSO && aSelectionMgr )
2348       {
2349         myDlg->setEnabled( false ); // disactivate selection
2350         selectionMgr()->clearFilters();
2351         selectObject( meshSO );
2352         SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
2353         qApp->processEvents();
2354
2355         myDlg->setEnabled( true );
2356         int obj = myDlg->getActiveObject();
2357         onActivateObject( obj ); // restore filter
2358         if ( !myToCreate )
2359         {
2360           selectObject( SMESH::FindSObject( submesh ));
2361           selectionDone();
2362         }
2363       }
2364     }
2365   }
2366
2367   return isNewConcurrent;
2368 }
2369
2370 //================================================================================
2371 /*!
2372  * \brief Verifies whether given operator is valid for this one
2373  * \param theOtherOp - other operation
2374  * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2375  *
2376  * method redefined from base class verifies whether given operator is valid for
2377  * this one (i.e. can be started "above" this operator). In current implementation method
2378  * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2379  * elements.
2380  */
2381 //================================================================================
2382 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2383 {
2384   return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2385 }
2386
2387 //================================================================================
2388 /*!
2389  * \brief SLOT. Is called when the user selects a way of geometry selection
2390  * \param theByMesh - true if the user wants to find geometry by mesh element
2391  */
2392 //================================================================================
2393 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2394 {
2395   if ( theByMesh ) {
2396     if ( !myShapeByMeshOp ) {
2397       myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2398       connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2399               SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2400       connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2401               SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2402     }
2403     // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2404     QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2405     if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2406       SMESH::SMESH_Mesh_var aMeshVar =
2407         SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2408       if ( !aMeshVar->_is_nil() ) {
2409         myDlg->hide(); // stop processing selection
2410         myShapeByMeshOp->setModule( getSMESHGUI() );
2411         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2412         myShapeByMeshOp->SetMesh( aMeshVar );
2413         myShapeByMeshOp->start();
2414       }
2415     }
2416   }
2417 }
2418
2419 //================================================================================
2420 /*!
2421  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2422  */
2423 //================================================================================
2424 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2425 {
2426   if ( myShapeByMeshOp == op ) {
2427     SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006  IPAL13980 - Object Browser update added
2428     myDlg->show();
2429     // Select a found geometry object
2430     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2431     if ( !aGeomVar->_is_nil() )
2432     {
2433       QString ID = aGeomVar->GetStudyEntry();
2434       if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2435         selectObject( aGeomSO );
2436         selectionDone();
2437       }
2438     }
2439   }
2440 }
2441
2442 //================================================================================
2443 /*!
2444  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2445  */
2446 //================================================================================
2447 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2448 {
2449   if ( myShapeByMeshOp == op && myDlg ) {
2450     myDlg->show();
2451   }
2452 }
2453
2454 //================================================================================
2455 /*!
2456  * \brief Selects a SObject
2457  * \param theSObj - the SObject to select
2458  */
2459 //================================================================================
2460 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2461 {
2462   if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2463     SALOME_ListIO anIOList;
2464     if ( theSObj ) {
2465       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2466         ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2467       anIOList.Append( anIO );
2468     }
2469     sm->setSelectedObjects( anIOList, false );
2470   }
2471 }
2472 //================================================================================
2473 /*!
2474  * \brief Create available list types of mesh
2475   * \param theTypeMesh - Output list of available types of mesh
2476  */
2477 //================================================================================
2478 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2479 {
2480   theTypeMesh.clear();
2481   theTypeMesh.append( tr( "MT_ANY" ) );
2482   if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2483   {
2484     theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2485     theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2486   }
2487   if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2488   {
2489     theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2490     theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2491   }
2492
2493 }
2494 //================================================================================
2495 /*!
2496  * \brief Set available types of mesh
2497   * \param theTypeMesh - List of available types of mesh
2498  */
2499 //================================================================================
2500 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2501 {
2502   myDlg->setAvailableMeshType( theTypeMesh );
2503 }
2504
2505 //================================================================================
2506 /*!
2507  * \brief SLOT. Is called when the user select type of mesh
2508   * \param theTabIndex - Index of current active tab
2509   * \param theIndex - Index of current type of mesh
2510  */
2511 //================================================================================
2512 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2513 {
2514   setFilteredAlgoData( theTabIndex, theIndex);
2515 }
2516
2517 //================================================================================
2518 /*!
2519  * \brief Set a filtered list of available algorithms by mesh type
2520   * \param theTabIndex - Index of current active tab
2521   * \param theIndex - Index of current type of mesh
2522  */
2523 //================================================================================
2524 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2525 {
2526   int aDim;
2527   THypDataList anAvailableAlgsData;
2528   QStringList anAvailableAlgs;
2529   QString anCompareType = "";
2530   bool isAvailableChoiceAlgo = false;
2531   int anCurrentAvailableAlgo = 0;
2532   bool isNone = true;
2533   switch ( theIndex ) {
2534   case MT_ANY:
2535     anCompareType = "ANY";
2536     aDim = SMESH::DIM_3D;
2537     break;
2538   case MT_TRIANGULAR:
2539     aDim = SMESH::DIM_2D;
2540     anCompareType = "TRIA";
2541     break;
2542   case MT_QUADRILATERAL:
2543     aDim = SMESH::DIM_2D;
2544     anCompareType = "QUAD";
2545     break;
2546   case MT_TETRAHEDRAL:
2547     aDim = SMESH::DIM_3D;
2548     anCompareType = "TETRA";
2549     break;
2550   case MT_HEXAHEDRAL:
2551     aDim = SMESH::DIM_3D;
2552     anCompareType = "HEXA";
2553     break;
2554   default:;
2555   }
2556
2557   bool toCheckIsApplicableToAll = !myIsMesh;
2558   GEOM::GEOM_Object_var aGeomVar;
2559   QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2560   if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2561   {
2562     CORBA::Object_var obj = _CAST( SObject,so )->GetObject();
2563     aGeomVar = GEOM::GEOM_Object::_narrow( obj );
2564     if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
2565       toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
2566   }
2567
2568   if ( anCompareType == "ANY" )
2569   {
2570     for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
2571     {
2572       isNone = currentHyp( dim, Algo ) < 0;
2573       isAvailableChoiceAlgo = false;
2574       // retrieves a list of available algorithms from resources
2575       availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2576       //return current algo in current tab and set new algorithm list
2577       HypothesisData* algoCur;
2578       if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2579         algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2580       }
2581       myAvailableHypData[dim][Algo].clear();
2582       anAvailableAlgs.clear();
2583       if ( dim != SMESH::DIM_2D || currentHyp( SMESH::DIM_3D, Algo ) < 0 ||
2584            myAvailableHypData[SMESH::DIM_3D][Algo].empty() ||
2585            !myAvailableHypData[SMESH::DIM_3D][Algo].at( currentHyp( SMESH::DIM_3D, Algo ) )->InputTypes.isEmpty() )
2586       {
2587         for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2588         {
2589           HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2590           if ( aGeomVar->_is_nil() ||
2591               SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2592           {
2593             anAvailableAlgs.append( curAlgo->Label );
2594             myAvailableHypData[dim][Algo].append( curAlgo );
2595           }
2596         }
2597         if ( !isNone && algoCur ) {
2598           for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2599           {
2600             HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2601             if ( algoAny->Label == algoCur->Label ){
2602               isAvailableChoiceAlgo = true;
2603               anCurrentAvailableAlgo = i;
2604               break;
2605             }
2606           }
2607         }
2608         else if ( !isNone ) {
2609           isAvailableChoiceAlgo = true;
2610           anCurrentAvailableAlgo = currentHyp( dim, Algo );
2611         }
2612       }
2613       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2614       if ( isAvailableChoiceAlgo )
2615         setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2616     }
2617     if ( !myIsOnGeometry )
2618       for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2619         if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
2620         else                     myDlg->enableTab( i );
2621       }
2622     else
2623       for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
2624         if ( i > myMaxShapeDim ) myDlg->disableTab( i );
2625         else                     myDlg->enableTab( i );
2626       }
2627     myDlg->setCurrentTab( theTabIndex );
2628   }
2629   else
2630   {
2631     QString anCurrentAlgo;
2632     bool isReqDisBound = true;
2633     QString anCurrentCompareType = anCompareType;
2634     isNone = currentHyp( aDim, Algo ) < 0;
2635     if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
2636         myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
2637       isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2638     else if ( !isNone )
2639       isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
2640     for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
2641     {
2642       bool isNoneAlg = currentHyp( dim, Algo ) < 0;
2643       isAvailableChoiceAlgo = false;
2644       // retrieves a list of available algorithms from resources
2645       availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2646       // finding algorithm which is selected
2647       if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
2648           myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
2649         anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
2650       else if ( !isNoneAlg )
2651         anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
2652       anAvailableAlgs.clear();
2653       myAvailableHypData[dim][Algo].clear();
2654       myFilteredAlgoData[dim].clear();
2655       // finding and adding algorithm depending on the type mesh
2656       for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2657       {
2658         HypothesisData* algoIn = anAvailableAlgsData.at( i );
2659         bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
2660         QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
2661         for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
2662         {
2663           if ( *inElemType == anCurrentCompareType ) {
2664             isAvailableAlgo = true;
2665             break;
2666           }
2667         }
2668         if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ) {
2669           if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
2670                SMESH::IsApplicable( algoIn->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2671           {
2672             anAvailableAlgs.append( algoIn->Label );
2673             myAvailableHypData[dim][Algo].append( algoIn );
2674             myFilteredAlgoData[dim].append( algoIn );
2675           }
2676         }
2677         //algorithm will be active, if the chosen algorithm available in the current mesh type
2678         if ( !isNoneAlg &&  isAvailableAlgo && algoIn->Label == anCurrentAlgo ) {
2679           isAvailableChoiceAlgo = true;
2680           anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
2681         }
2682       }
2683       //set new algorithm list and select the current algorithm
2684       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
2685       anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
2686       if ( isAvailableChoiceAlgo )
2687         setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
2688       else
2689         setCurrentHyp( dim, Algo, -1 );
2690     }
2691
2692     if ( isNone || isReqDisBound ) {
2693       for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
2694         if ( aDim != i ) {
2695           myDlg->disableTab( i );
2696           setCurrentHyp(i, Algo, -1);
2697         }
2698       }
2699     }
2700     else if ( !isNone ) {
2701       if ( aDim == SMESH::DIM_2D){
2702         myDlg->disableTab( SMESH::DIM_3D );
2703         setCurrentHyp( SMESH::DIM_3D, Algo, -1);
2704       }
2705       for ( int i = myMaxShapeDim; i > SMESH::DIM_0D; i-- )
2706       {
2707         isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
2708             myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
2709         if ( isReqDisBound ) {
2710           for (int j = i - 1; j >= SMESH::DIM_0D; j--){
2711             myDlg->disableTab( j );
2712             setCurrentHyp( j , Algo, -1 );
2713           }
2714           break;
2715         }
2716       }
2717     }
2718     myDlg->enableTab( aDim );
2719     myDlg->setCurrentTab( aDim );
2720   }
2721   QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
2722   QStringList aFilteredHypothesesSetsList;
2723   aFilteredHypothesesSetsList.clear();
2724   QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
2725   for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
2726   {
2727     HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
2728     bool isAvailable = false;
2729     currentHypoSet->init( true );
2730     while ( currentHypoSet->next(), currentHypoSet->more() )
2731     {
2732       isAvailable = false;
2733       if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
2734       {
2735         for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++)
2736         {
2737           if ( myAvailableHypData[i][Algo].count() == 0 ) {
2738             availableHyps( i, Algo, anAvailableAlgs, anAvailableAlgsData );
2739             for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
2740             {
2741               HypothesisData* aCurAlgo = anAvailableAlgsData.at( i );
2742               if ( aCurAlgo->Label == algoDataIn->Label ){
2743                 isAvailable = true;
2744                 break;
2745               }
2746             }
2747           }
2748           else {
2749             for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2750               HypothesisData* aCurAlgo = hypData( i, Algo, j );
2751               if ( aCurAlgo->Label == algoDataIn->Label ){
2752                 isAvailable = true;
2753                 break;
2754               }
2755             }
2756           }
2757           if ( isAvailable ) break;
2758         }
2759         if ( !isAvailable ) break;
2760       }
2761     }
2762     if ( isAvailable )
2763       aFilteredHypothesesSetsList.append( *inHypoSetName );
2764   }
2765   myDlg->setHypoSets( aFilteredHypothesesSetsList );
2766 }