Salome HOME
Merge branch V7_3_1_BR
[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   // if ( aDim >= SMESH::DIM_2D ) myAvailableHypData[ aDim ][ Algo ] = myFilteredAlgoData[aDim];
1400   HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1401   HypothesisData* algoByDim[4];
1402   algoByDim[ aDim ] = algoData;
1403
1404   QStringList anAvailable;
1405
1406   // check that tab enabled of one less dimension
1407   if ( aDim > SMESH::DIM_0D )
1408   {
1409     if ( isAccessibleDim( aDim - 1 ) )
1410     {
1411       if (( myDlg->currentMeshType() != MT_ANY ) &&
1412           ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
1413         for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
1414           if ( isAccessibleDim( i ) ) {
1415             myDlg->disableTab( i );
1416             setCurrentHyp(i, Algo, -1);
1417           }
1418     }
1419     else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
1420     {
1421       myDlg->enableTab( aDim - 1 );
1422     }
1423   }
1424
1425   // check that algorithms of other dimentions are compatible with
1426   // the selected one
1427   if ( !algoData ) { // all algos becomes available
1428     if (myDlg->currentMeshType() == MT_ANY || aDim == SMESH::DIM_1D || aDim == SMESH::DIM_0D)
1429       availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1430     else{
1431       anAvailable.clear();
1432       for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
1433         HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
1434         anAvailable.append( aCurAlgo->Label );
1435       }
1436     }
1437     myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1438   }
1439   // 2 loops: backward and forward from algo dimension
1440   for ( int forward = false; forward <= true; ++forward )
1441   {
1442     int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1443     if ( !forward ) {
1444       dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1445     }
1446     HypothesisData* prevAlgo = algoData;
1447     bool noCompatible = false;
1448     for ( ; dim * dir <= lastDim * dir; dim += dir)
1449     {
1450       if ( !isAccessibleDim( dim ))
1451         continue;
1452       if ( noCompatible ) { // the selected algo has no compatible ones
1453         anAvailable.clear();
1454         myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1455         myAvailableHypData[dim][Algo].clear();
1456         algoByDim[ dim ] = 0;
1457         continue;
1458       }
1459       // get currently selected algo
1460       int algoIndex = currentHyp( dim, Algo );
1461       HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1462       if ( curAlgo ) { // some algo selected
1463         if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1464           curAlgo = 0;
1465       }
1466       // set new available algoritms
1467       if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
1468         availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1469       else{
1470         anAvailable.clear();
1471         myAvailableHypData[dim][Algo].clear();
1472         for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
1473           HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
1474           if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
1475             anAvailable.append( aCurAlgo->Label );
1476             myAvailableHypData[dim][Algo].append( aCurAlgo );
1477           }
1478         }
1479       }
1480       HypothesisData* soleCompatible = 0;
1481       if ( anAvailable.count() == 1 )
1482         soleCompatible = myAvailableHypData[dim][Algo][0];
1483       if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
1484         if (myDlg->currentMeshType() == MT_ANY)
1485           availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1486       }
1487       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1488       noCompatible = anAvailable.isEmpty();
1489
1490       // restore previously selected algo
1491       algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1492       if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1493         // select the sole compatible algo
1494         algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1495       setCurrentHyp( dim, Algo, algoIndex);
1496
1497       // remember current algo
1498       prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1499     }
1500   }
1501
1502   // set hypotheses corresponding to the found algoritms
1503
1504   _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1505
1506   for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1507   {
1508     if ( !isAccessibleDim( dim ))
1509       continue;
1510     for ( int type = MainHyp; type < NbHypTypes; type++ )
1511     {
1512       myAvailableHypData[ dim ][ type ].clear();
1513       QStringList anAvailable, anExisting;
1514
1515       HypothesisData* curAlgo = algoByDim[ dim ];
1516       int hypIndex = currentHyp( dim, type );
1517
1518       SMESH::SMESH_Hypothesis_var curHyp;
1519       if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1520         curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1521
1522       if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1523         // try to find algo by selected hypothesis in order to keep it selected
1524         bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1525         CORBA::String_var curHypType = curHyp->GetName();
1526         if ( !algoDeselectedByUser &&
1527             myObjHyps[ dim ][ type ].count() > 0 &&
1528             !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1529         {
1530           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1531           for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1532             curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1533             if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1534               break;
1535             else
1536               curAlgo = 0;
1537           }
1538         }
1539       }
1540       // get hyps compatible with curAlgo
1541       bool defaulHypAvlbl = false;
1542       if ( curAlgo )
1543       {
1544         // check if a selected hyp is compatible with the curAlgo
1545         if ( !curHyp->_is_nil() ) {
1546           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1547           if ( !isCompatible( curAlgo, hypData, type ))
1548             curHyp = SMESH::SMESH_Hypothesis::_nil();
1549         }
1550         existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1551         availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1552         defaulHypAvlbl = (type == MainHyp && !curAlgo->IsAuxOrNeedHyp );
1553       }
1554       // set list of hypotheses
1555       myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1556       myDlg->tab( dim )->setExistingHyps( type, anExisting, defaulHypAvlbl );
1557
1558       // set current existing hypothesis
1559       if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1560         hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1561       else
1562         hypIndex = -1;
1563       if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1564         // none is yet selected => select the sole existing if it is not optional
1565         CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1566         bool isOptional = true;
1567         if ( algoByDim[ dim ] &&
1568             SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1569             !isOptional )
1570           hypIndex = 0;
1571       }
1572       setCurrentHyp( dim, type, hypIndex );
1573     }
1574   }
1575 }
1576
1577 //================================================================================
1578 /*!
1579  * \brief Creates and selects hypothesis of hypotheses set
1580  * \param theSetName - The name of hypotheses set
1581  */
1582 //================================================================================
1583 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1584 {
1585   myHypoSet = SMESH::GetHypothesesSet(theSetName);
1586   if (!myHypoSet)
1587     return;
1588
1589   // clear all hyps
1590   for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1591     setCurrentHyp(dim, Algo, -1);
1592     setCurrentHyp(dim, AddHyp, -1);
1593     setCurrentHyp(dim, MainHyp, -1);
1594   }
1595
1596   myHypoSet->init(true); //algorithms
1597   processSet();
1598   myHypoSet->init(false); //hypotheses
1599   processSet();
1600   myHypoSet = 0;
1601 }
1602
1603 //================================================================================
1604 /*!
1605  * \brief One step of hypothesis/algorithm list creation
1606  *
1607  * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1608  */
1609 //================================================================================
1610 void SMESHGUI_MeshOp::processSet()
1611 {
1612   myHypoSet->next();
1613   if( !myHypoSet->more() )
1614     return;
1615
1616   bool isAlgo = myHypoSet->isAlgo();
1617   QString aHypoTypeName = myHypoSet->current();
1618   HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1619   if (!aHypData)
1620   {
1621     processSet();
1622     return;
1623   }
1624
1625   int aDim = aHypData->Dim[0];
1626   // create or/and set
1627   if (isAlgo)
1628   {
1629     int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1630     if ( index < 0 )
1631     {
1632       QStringList anAvailable;
1633       availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1634       myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1635       index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1636     }
1637     setCurrentHyp( aDim, Algo, index );
1638     onAlgoSelected( index, aDim );
1639     processSet();
1640   }
1641   else
1642   {
1643     bool mainHyp = true;
1644     QStringList anAvailable;
1645     availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1646     myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1647     int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1648     if ( index < 0 )
1649     {
1650       mainHyp = false;
1651       index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1652     }
1653     if (index >= 0)
1654       createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1655     else
1656       processSet();
1657   }
1658 }
1659
1660 //================================================================================
1661 /*!
1662  * \brief Creates mesh
1663   * \param theMess - Output parameter intended for returning error message
1664   * \param theEntryList - List of entries of published objects
1665   * \retval bool  - TRUE if mesh is created, FALSE otherwise
1666  *
1667  * Creates mesh
1668  */
1669 //================================================================================
1670 bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
1671 {
1672   theMess = "";
1673
1674   QStringList aList;
1675   myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1676   if ( aList.isEmpty() )
1677   {
1678     SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1679     if ( aSMESHGen->_is_nil() )
1680       return false;
1681
1682     SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
1683     if ( aMeshVar->_is_nil() )
1684       return false;
1685
1686     _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1687     if ( aMeshSO ) {
1688       SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1689       theEntryList.append( aMeshSO->GetID().c_str() );
1690     }
1691     return true;
1692   }
1693   QString namePrefix;
1694   if ( aList.count() > 1 )
1695   {
1696     namePrefix = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1697     int i = namePrefix.length() - 1;
1698     while ( i > 0 && namePrefix[i].isDigit() )
1699       --i;
1700     if ( i < namePrefix.length() - 1 )
1701       namePrefix.chop( namePrefix.length() - 1 - i );
1702     else
1703       namePrefix += "_";
1704   }
1705   QStringList::Iterator it = aList.begin();
1706   for ( int i = 0; it!=aList.end(); it++, ++i )
1707   {
1708     QString aGeomEntry = *it;
1709     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1710     GEOM::GEOM_Object_var aGeomVar =
1711       GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1712
1713     SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1714     if ( aSMESHGen->_is_nil() )
1715       return false;
1716
1717     SUIT_OverrideCursor aWaitCursor;
1718
1719     // create mesh
1720     SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1721     if ( aMeshVar->_is_nil() )
1722       return false;
1723     _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1724     if ( aMeshSO ) {
1725       theEntryList.append( aMeshSO->GetID().c_str() );
1726       if ( i > 0 ) setDefaultName( namePrefix );
1727       SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1728     }
1729
1730     for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1731       if ( !isAccessibleDim( aDim )) continue;
1732
1733       // assign hypotheses
1734       for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1735         int aHypIndex = currentHyp( aDim, aHypType );
1736         if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1737           SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1738           if ( !aHypVar->_is_nil() )
1739             SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1740         }
1741       }
1742       // find or create algorithm
1743       SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1744       if ( !anAlgoVar->_is_nil() )
1745         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1746     }
1747   }
1748   return true;
1749 }
1750
1751 //================================================================================
1752 /*!
1753  * \brief Creates sub-mesh
1754   * \param theMess - Output parameter intended for returning error message
1755   * \param theEntryList - List of entries of published objects
1756   * \retval bool  - TRUE if sub-mesh is created, FALSE otherwise
1757  *
1758  * Creates sub-mesh
1759  */
1760 //================================================================================
1761 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList )
1762 {
1763   theMess = "";
1764
1765   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1766   if ( aSMESHGen->_is_nil() )
1767     return false;
1768
1769   // get mesh object
1770   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1771   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1772   SMESH::SMESH_Mesh_var aMeshVar =
1773     SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1774   if (aMeshVar->_is_nil())
1775     return false;
1776
1777   // GEOM shape of the main mesh
1778   GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1779
1780   // Name for the new sub-mesh
1781   QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1782
1783   // get geom object
1784   GEOM::GEOM_Object_var aGeomVar;
1785   QStringList aGEOMs;
1786   myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1787   if (aGEOMs.count() == 1)
1788   {
1789     //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1790     QString aGeomEntry = aGEOMs.first();
1791     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1792     aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1793   }
1794   else if (aGEOMs.count() > 1)
1795   {
1796     // create a GEOM group
1797     GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1798     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1799     if (!geomGen->_is_nil() && aStudy) {
1800       GEOM::GEOM_IGroupOperations_wrap op =
1801         geomGen->GetIGroupOperations(aStudy->StudyId());
1802       if (!op->_is_nil()) {
1803         // check and add all selected GEOM objects: they must be
1804         // a sub-shapes of the main GEOM and must be of one type
1805         int iSubSh = 0;
1806         TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1807         GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1808         aSeq->length(aGEOMs.count());
1809         QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1810         for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1811           QString aSubGeomEntry = (*aSubShapesIter);
1812           _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1813           GEOM::GEOM_Object_var aSubGeomVar =
1814             GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1815           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1816           if (iSubSh == 0) {
1817             aGroupType = aSubShapeType;
1818           } else {
1819             if (aSubShapeType != aGroupType)
1820               aGroupType = TopAbs_SHAPE;
1821           }
1822           aSeq[iSubSh] = aSubGeomVar;
1823         }
1824         // create a group
1825         GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1826         op->UnionList(aGroupVar, aSeq);
1827
1828         if (op->IsDone())
1829         {
1830           aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
1831
1832           // publish the GEOM group in study
1833           QString aNewGeomGroupName ("Auto_group_for_");
1834           aNewGeomGroupName += aName;
1835           SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy();
1836           SALOMEDS::SObject_wrap aNewGroupSO =
1837             geomGen->AddInStudy( aStudyVar, aGeomVar,
1838                                  aNewGeomGroupName.toLatin1().data(), mainGeom);
1839         }
1840       }
1841     }
1842   }
1843   else {
1844   }
1845   if (aGeomVar->_is_nil())
1846     return false;
1847
1848   SUIT_OverrideCursor aWaitCursor;
1849
1850   // create sub-mesh
1851   SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1852   _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1853   if ( aSubMeshSO ) {
1854     SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1855     theEntryList.append( aSubMeshSO->GetID().c_str() );
1856   }
1857
1858   for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1859   {
1860     if ( !isAccessibleDim( aDim )) continue;
1861
1862     // find or create algorithm
1863     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1864     if ( !anAlgoVar->_is_nil() )
1865       SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1866     // assign hypotheses
1867     for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1868     {
1869       int aHypIndex = currentHyp( aDim, aHypType );
1870       if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1871       {
1872         SMESH::SMESH_Hypothesis_var aHypVar =
1873           myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1874         if ( !aHypVar->_is_nil() )
1875           SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1876       }
1877     }
1878   }
1879
1880   // deselect geometry: next submesh should be created on other sub-shape
1881   myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1882   selectObject( _PTR(SObject)() );
1883   selectionDone();
1884
1885   checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/true );
1886
1887   return true;
1888 }
1889
1890 //================================================================================
1891 /*!
1892  * \brief Gets current hypothesis or algorithms
1893   * \param theDim - dimension of hypothesis or algorithm
1894   * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1895   * \retval int - current hypothesis or algorithms
1896  *
1897  * Gets current hypothesis or algorithms
1898  */
1899 //================================================================================
1900 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1901 {
1902   return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1903 }
1904
1905 //================================================================================
1906 /*!
1907  * \brief Returns true if hypotheses of given dim can be assigned
1908   * \param theDim - hypotheses dimension
1909   * \retval bool - result
1910  */
1911 //================================================================================
1912 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1913 {
1914   return myDlg->isTabEnabled( theDim );
1915 }
1916
1917 //================================================================================
1918 /*!
1919  * \brief Sets current hypothesis or algorithms
1920   * \param theDim - dimension of hypothesis or algorithm
1921   * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1922   * \param theIndex - Index of hypothesis
1923  *
1924  * Gets current hypothesis or algorithms
1925  */
1926 //================================================================================
1927 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1928                                      const int theHypType,
1929                                      const int theIndex )
1930 {
1931   myIgnoreAlgoSelection = true;
1932   myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1933   myIgnoreAlgoSelection = false;
1934 }
1935
1936 //================================================================================
1937 /*!
1938  * \brief Generates default and sets mesh/submesh name
1939  *
1940  * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1941  */
1942 //================================================================================
1943 void SMESHGUI_MeshOp::setDefaultName( const QString& thePrefix ) const
1944 {
1945   QString aResName;
1946
1947   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1948   int i = 1;
1949
1950   QString aPrefix = thePrefix;
1951   if ( aPrefix.isEmpty() )
1952     aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1953
1954   _PTR(SObject) anObj;
1955   do
1956   {
1957     aResName = aPrefix + QString::number( i++ );
1958     anObj = aStudy->FindObject( aResName.toLatin1().data() );
1959   }
1960   while ( anObj );
1961
1962   QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1963     SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1964   aControl->setText( aResName );
1965 }
1966
1967 //================================================================================
1968 /*!
1969  * \brief Gets algorithm or creates it if necessary
1970   * \param theDim - specifies dimension of returned hypotheses/algorifms
1971   * \retval SMESH::SMESH_Hypothesis_var - algorithm
1972  *
1973  * Gets algorithm or creates it if necessary
1974  */
1975 //================================================================================
1976 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1977 {
1978   SMESH::SMESH_Hypothesis_var anAlgoVar;
1979
1980   // get type of the selected algo
1981   int aHypIndex = currentHyp( theDim, Algo );
1982   THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1983   if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1984     return anAlgoVar;
1985   QString aHypName = dataList[ aHypIndex ]->TypeName;
1986
1987   // get existing algoritms
1988   _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1989   QStringList tmp;
1990   existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1991
1992   // look for an existing algo of such a type
1993   THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1994   THypList::iterator anIter = aHypVarList.begin();
1995   for ( ; anIter != aHypVarList.end(); anIter++)
1996   {
1997     SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1998     CORBA::String_var aName = aHypVar->GetName();
1999     if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
2000     {
2001       anAlgoVar = aHypVar;
2002       break;
2003     }
2004   }
2005
2006   if (anAlgoVar->_is_nil())
2007   {
2008     HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
2009     if (aHypData)
2010     {
2011       QString aClientLibName = aHypData->ClientLibName;
2012       if ( aClientLibName.isEmpty() )
2013       {
2014         // Call hypothesis creation server method (without GUI)
2015         SMESH::SMESH_Hypothesis_var aHyp =
2016           SMESH::CreateHypothesis(aHypName, aHypName, true);
2017         aHyp.out();
2018       }
2019       else
2020       {
2021         // Get hypotheses creator client (GUI)
2022         SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
2023
2024         // Create algorithm
2025         if (aCreator)
2026           aCreator->create( true, aHypName, myDlg, 0, QString::null );
2027         else {
2028           SMESH::SMESH_Hypothesis_var aHyp =
2029             SMESH::CreateHypothesis(aHypName, aHypName, true);
2030           aHyp.out();
2031         }
2032       }
2033       QStringList tmpList;
2034       _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
2035       existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
2036     }
2037
2038     THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
2039     for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
2040     {
2041       SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
2042       CORBA::String_var aName = aHypVar->GetName();
2043       if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
2044       {
2045         anAlgoVar = aHypVar;
2046         break;
2047       }
2048     }
2049   }
2050
2051   return anAlgoVar._retn();
2052 }
2053
2054 //================================================================================
2055 /*!
2056  * \brief Reads parameters of an edited mesh/sub-mesh and assigns them to the dialog
2057  *
2058  * Called when mesh is edited only.
2059  */
2060 //================================================================================
2061 void SMESHGUI_MeshOp::readMesh()
2062 {
2063   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2064   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2065   if ( !pObj )
2066     return;
2067
2068   if (myIsOnGeometry) {
2069     // Get name of mesh if current object is sub-mesh
2070     SMESH::SMESH_subMesh_var aSubMeshVar =
2071       SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
2072     if ( !aSubMeshVar->_is_nil() )
2073     {
2074       SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
2075       if ( !aMeshVar->_is_nil() )
2076       {
2077         _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
2078         QString aMeshName = name( aMeshSO );
2079         myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
2080       }
2081       myHasConcurrentSubBefore = checkSubMeshConcurrency( aMeshVar, aSubMeshVar );
2082     }
2083
2084     // Get name of geometry object
2085     GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
2086     if ( !aGeomVar->_is_nil() )
2087     {
2088       _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
2089       QString aShapeName = name( aGeomSO );
2090       myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
2091     }
2092   }
2093
2094   // Get hypotheses and algorithms assigned to the mesh/sub-mesh
2095   QStringList anExisting;
2096   const int lastDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2097   bool algoFound = false;
2098   for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2099   {
2100     // get algorithm
2101     existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
2102     // find algo index among available ones
2103     int aHypIndex = -1;
2104     if ( myObjHyps[ dim ][ Algo ].count() > 0 )
2105     {
2106       SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
2107       HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
2108       aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
2109 //       if ( aHypIndex < 0 && algoData ) {
2110 //         // assigned algo is incompatible with other algorithms
2111 //         myAvailableHypData[ dim ][ Algo ].push_back( algoData );
2112 //         aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
2113 //       }
2114       algoFound = ( aHypIndex > -1 );
2115     }
2116     setCurrentHyp( dim, Algo, aHypIndex );
2117     // set existing and available hypothesis according to the selected algo
2118     if ( aHypIndex > -1 || !algoFound )
2119       onAlgoSelected( aHypIndex, dim );
2120   }
2121
2122   // get hypotheses
2123   bool hypWithoutAlgo = false;
2124   for ( int dim = SMESH::DIM_3D; dim >= lastDim; --dim )
2125   {
2126     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2127     {
2128       // get hypotheses
2129       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2130       // find index of requered hypothesis among existing ones for this dimension and type
2131       int aHypIndex = -1;
2132       if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
2133         aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2134                           myExistingHyps[ dim ][ hypType ] );
2135         if ( aHypIndex < 0 ) {
2136           // assigned hypothesis is incompatible with the algorithm
2137           if ( currentHyp( dim, Algo ) < 0 )
2138           { // none algo selected; it is edition for sure, of submesh maybe
2139             hypWithoutAlgo = true;
2140             myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
2141             aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
2142             myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
2143           }
2144         }
2145       }
2146       setCurrentHyp( dim, hypType, aHypIndex );
2147     }
2148   }
2149   // make available other hyps of same type as one without algo
2150   if ( hypWithoutAlgo )
2151     onAlgoSelected( currentHyp( 0, Algo ), 0 );
2152 }
2153
2154 //================================================================================
2155 /*!
2156  * \brief Gets name of object
2157   * \param theSO - SObject
2158   * \retval QString - name of object
2159  *
2160  * Gets name of object
2161  */
2162 //================================================================================
2163 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
2164 {
2165   QString aResName;
2166   if ( theSO )
2167   {
2168     _PTR(GenericAttribute) anAttr;
2169     _PTR(AttributeName)    aNameAttr;
2170     if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
2171     {
2172       aNameAttr = anAttr;
2173       aResName = aNameAttr->Value().c_str();
2174     }
2175   }
2176   return aResName;
2177 }
2178
2179 //================================================================================
2180 /*!
2181  * \brief Finds hypothesis in input list
2182   * \param theHyp - hypothesis to be found
2183   * \param theHypList - input list of hypotheses
2184   * \retval int - index of hypothesis or -1 if it is not found
2185  *
2186  * Finds position of hypothesis in input list
2187  */
2188 //================================================================================
2189 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2190                            const THypList& theHypList ) const
2191 {
2192   int aRes = -1;
2193   if ( !theHyp->_is_nil() )
2194   {
2195     int i = 0;
2196     THypList::const_iterator anIter = theHypList.begin();
2197     for ( ; anIter != theHypList.end(); ++ anIter)
2198     {
2199       if ( theHyp->_is_equivalent( (*anIter).first ) )
2200       {
2201         aRes = i;
2202         break;
2203       }
2204       i++;
2205     }
2206   }
2207   return aRes;
2208 }
2209
2210 //================================================================================
2211 /*!
2212  * \brief Edits mesh or sub-mesh
2213   * \param theMess - Output parameter intended for returning error message
2214   * \retval bool  - TRUE if mesh is edited succesfully, FALSE otherwise
2215  *
2216  * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2217  */
2218 //================================================================================
2219 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2220 {
2221   theMess = "";
2222
2223   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2224   if ( aSMESHGen->_is_nil() )
2225     return false;
2226
2227   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2228   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2229   if ( !pObj )
2230     return false;
2231
2232   SUIT_OverrideCursor aWaitCursor;
2233
2234   // Set new name
2235   QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2236   SMESH::SetName( pObj, aName );
2237   int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2238
2239   // First, remove old algos in order to avoid messages on algorithm hiding
2240   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2241   {
2242     if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2243     {
2244       SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2245       SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2246       if ( anAlgoVar->_is_nil() || // no new algo selected or
2247            strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2248       {
2249         // remove old algorithm
2250         SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2251         myObjHyps[ dim ][ Algo ].clear();
2252       }
2253     }
2254   }
2255
2256   SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2257   CORBA::Object_var anObject = aSObject->GetObject();
2258   SMESH::SMESH_Mesh_var       aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2259   SMESH::SMESH_subMesh_var aSubMeshVar = SMESH::SMESH_subMesh::_narrow( anObject );
2260   bool isMesh = !aMeshVar->_is_nil();
2261   if ( !isMesh && !aSubMeshVar->_is_nil() )
2262     aMeshVar = aSubMeshVar->GetFather();
2263
2264   // Assign new algorithms and hypotheses
2265   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2266   {
2267     if ( !isAccessibleDim( dim )) continue;
2268
2269     // find or create algorithm
2270     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2271
2272     // assign new algorithm
2273     if ( !anAlgoVar->_is_nil() && // some algo selected and
2274          myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2275     {
2276       if ( isMesh )
2277         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2278       else if ( !aSubMeshVar->_is_nil() )
2279         SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
2280
2281       myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2282     }
2283
2284     // assign hypotheses
2285     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2286     {
2287       int aNewHypIndex = currentHyp( dim, hypType );
2288       int anOldHypIndex = -1;
2289
2290       // remove old hypotheses
2291       if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2292       {
2293         anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2294                               myExistingHyps[ dim ][ hypType ] );
2295         if ( aNewHypIndex != anOldHypIndex || // different hyps
2296              anOldHypIndex == -1 )            // hyps of different algos
2297         {
2298           SMESH::RemoveHypothesisOrAlgorithmOnMesh
2299             ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2300           myObjHyps[ dim ][ hypType ].clear();
2301         }
2302       }
2303
2304       // assign new hypotheses
2305       if ( aNewHypIndex != anOldHypIndex && aNewHypIndex > -1 )
2306       {
2307         if ( isMesh )
2308           SMESH::AddHypothesisOnMesh
2309             (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2310         else if ( !aSubMeshVar->_is_nil() )
2311           SMESH::AddHypothesisOnSubMesh
2312             ( aSubMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2313       }
2314       // reread all hypotheses of mesh if necessary
2315       QStringList anExisting;
2316       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2317     }
2318   }
2319
2320   myHasConcurrentSubBefore =
2321     checkSubMeshConcurrency( aMeshVar, aSubMeshVar, /*askUser=*/!myHasConcurrentSubBefore );
2322
2323   return true;
2324 }
2325
2326 //================================================================================
2327 /*!
2328  * \brief Checks if a concurrent sub-meshes appear as result of sub-mesh
2329  *        creation/edition and, if (askUser) , proposes the uses to set up a desired
2330  *        order of sub-mesh computation.
2331  *        Returns \c true if a sub-mesh concurrency detected.
2332  */
2333 //================================================================================
2334
2335 bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr    mesh,
2336                                               SMESH::SMESH_subMesh_ptr submesh,
2337                                               bool                     askUser)
2338 {
2339   if ( CORBA::is_nil( mesh ) || CORBA::is_nil( submesh ))
2340     return false;
2341
2342   bool isNewConcurrent = mesh->IsUnorderedSubMesh( submesh->GetId() );
2343   if ( isNewConcurrent && askUser )
2344   {
2345     int butID = SUIT_MessageBox::warning( myDlg->parentWidget(), tr( "SMESH_WARNING" ),
2346                                           tr("CONCURRENT_SUBMESH_APPEARS"),
2347                                           tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"));
2348     if ( butID == 0 )
2349     {
2350       _PTR(SObject) meshSO = SMESH::FindSObject( mesh );
2351       LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
2352       if ( meshSO && aSelectionMgr )
2353       {
2354         myDlg->setEnabled( false ); // disactivate selection
2355         selectionMgr()->clearFilters();
2356         selectObject( meshSO );
2357         SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
2358         qApp->processEvents();
2359
2360         myDlg->setEnabled( true );
2361         int obj = myDlg->getActiveObject();
2362         onActivateObject( obj ); // restore filter
2363         if ( !myToCreate )
2364         {
2365           selectObject( SMESH::FindSObject( submesh ));
2366           selectionDone();
2367         }
2368       }
2369     }
2370   }
2371
2372   return isNewConcurrent;
2373 }
2374
2375 //================================================================================
2376 /*!
2377  * \brief Verifies whether given operator is valid for this one
2378  * \param theOtherOp - other operation
2379  * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2380  *
2381  * method redefined from base class verifies whether given operator is valid for
2382  * this one (i.e. can be started "above" this operator). In current implementation method
2383  * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2384  * elements.
2385  */
2386 //================================================================================
2387 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2388 {
2389   return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2390 }
2391
2392 //================================================================================
2393 /*!
2394  * \brief SLOT. Is called when the user selects a way of geometry selection
2395  * \param theByMesh - true if the user wants to find geometry by mesh element
2396  */
2397 //================================================================================
2398 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2399 {
2400   if ( theByMesh ) {
2401     if ( !myShapeByMeshOp ) {
2402       myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2403       connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2404               SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2405       connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2406               SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2407     }
2408     // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2409     QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2410     if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2411       SMESH::SMESH_Mesh_var aMeshVar =
2412         SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2413       if ( !aMeshVar->_is_nil() ) {
2414         myDlg->hide(); // stop processing selection
2415         myShapeByMeshOp->setModule( getSMESHGUI() );
2416         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2417         myShapeByMeshOp->SetMesh( aMeshVar );
2418         myShapeByMeshOp->start();
2419       }
2420     }
2421   }
2422 }
2423
2424 //================================================================================
2425 /*!
2426  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2427  */
2428 //================================================================================
2429 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2430 {
2431   if ( myShapeByMeshOp == op ) {
2432     SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006  IPAL13980 - Object Browser update added
2433     myDlg->show();
2434     // Select a found geometry object
2435     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2436     if ( !aGeomVar->_is_nil() )
2437     {
2438       QString ID = aGeomVar->GetStudyEntry();
2439       if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2440         selectObject( aGeomSO );
2441         selectionDone();
2442       }
2443     }
2444   }
2445 }
2446
2447 //================================================================================
2448 /*!
2449  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2450  */
2451 //================================================================================
2452 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2453 {
2454   if ( myShapeByMeshOp == op && myDlg ) {
2455     myDlg->show();
2456   }
2457 }
2458
2459 //================================================================================
2460 /*!
2461  * \brief Selects a SObject
2462  * \param theSObj - the SObject to select
2463  */
2464 //================================================================================
2465 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2466 {
2467   if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2468     SALOME_ListIO anIOList;
2469     if ( theSObj ) {
2470       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2471         ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2472       anIOList.Append( anIO );
2473     }
2474     sm->setSelectedObjects( anIOList, false );
2475   }
2476 }
2477 //================================================================================
2478 /*!
2479  * \brief Create available list types of mesh
2480   * \param theTypeMesh - Output list of available types of mesh
2481  */
2482 //================================================================================
2483 void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
2484 {
2485   theTypeMesh.clear();
2486   theTypeMesh.append( tr( "MT_ANY" ) );
2487   if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
2488   {
2489     theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
2490     theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
2491   }
2492   if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
2493   {
2494     theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
2495     theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
2496   }
2497
2498 }
2499 //================================================================================
2500 /*!
2501  * \brief Set available types of mesh
2502   * \param theTypeMesh - List of available types of mesh
2503  */
2504 //================================================================================
2505 void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
2506 {
2507   myDlg->setAvailableMeshType( theTypeMesh );
2508 }
2509
2510 //================================================================================
2511 /*!
2512  * \brief SLOT. Is called when the user select type of mesh
2513   * \param theTabIndex - Index of current active tab
2514   * \param theIndex - Index of current type of mesh
2515  */
2516 //================================================================================
2517 void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
2518 {
2519   setFilteredAlgoData( theTabIndex, theIndex);
2520 }
2521
2522 //================================================================================
2523 /*!
2524  * \brief Set a filtered list of available algorithms by mesh type
2525   * \param theTabIndex - Index of current active tab
2526   * \param theIndex - Index of current type of mesh
2527  */
2528 //================================================================================
2529 void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
2530 {
2531   int aDim;
2532   THypDataList anAvailableAlgsData;
2533   QStringList anAvailableAlgs;
2534   QString anCompareType = "";
2535   bool isAvailableChoiceAlgo = false;
2536   int anCurrentAvailableAlgo = 0;
2537   bool isNone = true;
2538   switch ( theIndex ) {
2539   case MT_ANY:
2540     anCompareType = "ANY";
2541     aDim = SMESH::DIM_3D;
2542     break;
2543   case MT_TRIANGULAR:
2544     aDim = SMESH::DIM_2D;
2545     anCompareType = "TRIA";
2546     break;
2547   case MT_QUADRILATERAL:
2548     aDim = SMESH::DIM_2D;
2549     anCompareType = "QUAD";
2550     break;
2551   case MT_TETRAHEDRAL:
2552     aDim = SMESH::DIM_3D;
2553     anCompareType = "TETRA";
2554     break;
2555   case MT_HEXAHEDRAL:
2556     aDim = SMESH::DIM_3D;
2557     anCompareType = "HEXA";
2558     break;
2559   default:;
2560   }
2561
2562   bool toCheckIsApplicableToAll = !myIsMesh;
2563   GEOM::GEOM_Object_var aGeomVar;
2564   QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
2565   if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
2566   {
2567     CORBA::Object_var obj = _CAST( SObject,so )->GetObject();
2568     aGeomVar = GEOM::GEOM_Object::_narrow( obj );
2569     if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
2570       toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
2571   }
2572
2573   if ( anCompareType == "ANY" )
2574   {
2575     for ( int dim = SMESH::DIM_2D; dim <= SMESH::DIM_3D; dim++ )
2576     {
2577       isNone = currentHyp( dim, Algo ) < 0;
2578       isAvailableChoiceAlgo = false;
2579       // retrieves a list of available algorithms from resources
2580       availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
2581       //return current algo in current tab and set new algorithm list
2582       HypothesisData* algoCur;
2583       if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
2584         algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
2585       }
2586       myAvailableHypData[dim][Algo].clear();
2587       anAvailableAlgs.clear();
2588       for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
2589       {
2590         HypothesisData* curAlgo = anAvailableAlgsData.at(i);
2591         if ( aGeomVar->_is_nil() ||
2592              SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
2593         {
2594           anAvailableAlgs.append( curAlgo->Label );
2595           myAvailableHypData[dim][Algo].append( curAlgo );
2596         }
2597       }
2598       if ( !isNone && algoCur ) {
2599         for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
2600         {
2601           HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
2602           if ( algoAny->Label == algoCur->Label ){
2603             isAvailableChoiceAlgo = true;
2604             anCurrentAvailableAlgo = i;
2605             break;
2606           }
2607         }
2608       }
2609       else if ( !isNone ) {
2610         isAvailableChoiceAlgo = true;
2611         anCurrentAvailableAlgo = currentHyp( dim, Algo );
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           for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
2738             HypothesisData* aCurAlgo =  hypData( i, Algo, j );
2739             if ( aCurAlgo->Label == algoDataIn->Label ){
2740               isAvailable = true;
2741               break;
2742             }
2743           }
2744           if ( isAvailable ) break;
2745         }
2746         if ( !isAvailable ) break;
2747       }
2748     }
2749     if ( isAvailable )
2750       aFilteredHypothesesSetsList.append( *inHypoSetName );
2751   }
2752   myDlg->setHypoSets( aFilteredHypothesesSetsList );
2753 }