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