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