Salome HOME
correct previous integration (Porting to Python 2.6)
[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         if ( !aGeomVar->_is_nil() )
1089           aGeomEntry = aGeomVar->GetStudyEntry();
1090       }
1091
1092       if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { // take geometry from submesh
1093         _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1094         if ( pObj ) {
1095           // if current object is sub-mesh
1096           SMESH::SMESH_subMesh_var aSubMeshVar =
1097             SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1098           if ( !aSubMeshVar->_is_nil() ) {
1099             SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
1100             if ( !aMeshVar->_is_nil() ) {
1101               _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1102               GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1103               if ( !aGeomVar->_is_nil() )
1104                 aMeshEntry = aGeomVar->GetStudyEntry();
1105             }
1106           }
1107         }
1108       }
1109       
1110       aCreator->setShapeEntry( aGeomEntry );
1111       if ( aMeshEntry != "" )
1112         aCreator->setMainShapeEntry( aMeshEntry );
1113       myDlg->setEnabled( false );
1114       aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
1115       dialog = true;
1116     }
1117     else
1118       SMESH::CreateHypothesis(theTypeName, aHypName, false);
1119   }
1120
1121   if( !dialog )
1122     onHypoCreated(2);
1123 }
1124
1125 //================================================================================
1126 /*!
1127  *  Necessary steps after hypothesis creation
1128  *  \param result - creation result:
1129  *   0 = rejected
1130  *   1 = accepted
1131  *   2 = additional value meaning that slot is called not from dialog box
1132  */
1133 //================================================================================
1134 void SMESHGUI_MeshOp::onHypoCreated( int result )
1135 {
1136   if( result != 2 )
1137   {
1138     int obj = myDlg->getActiveObject();
1139     onActivateObject( obj ); // Issue 0020170. Restore filters
1140     myDlg->setEnabled( true );
1141   }
1142
1143   _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1144
1145   int nbHyp = myExistingHyps[myDim][myType].count();
1146   HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
1147   QStringList aNewHyps;
1148   existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
1149   if (aNewHyps.count() > nbHyp)
1150   {
1151     for (int i = nbHyp; i < aNewHyps.count(); i++)
1152       myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
1153   }
1154
1155   if( result!=2 && myHypoSet )
1156     processSet();
1157 }
1158
1159 //================================================================================
1160 /*!
1161  * \brief Calls plugin methods for hypothesis editing
1162   * \param theHypType - specifies whether main hypothesis or additional one
1163   * is edited
1164   * \param theIndex - index of existing hypothesis
1165  *
1166  * Calls plugin methods for hypothesis editing
1167  */
1168 //================================================================================
1169 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
1170 {
1171   // Speicfies dimension of hypothesis to be created
1172   int aDim = getTabDim( sender(), myDlg );
1173   if (aDim == -1)
1174     return;
1175
1176   const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
1177   if ( theIndex < 0 || theIndex >= aList.count() )
1178     return;
1179   const THypItem& aHypItem = aList[ theIndex ];
1180   SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
1181   if ( aHyp->_is_nil() )
1182     return;
1183
1184   // BUG 0020378
1185   //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1186   SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
1187   if ( aCreator )
1188   {
1189     // Get initial parameters
1190     SMESH::SMESH_Hypothesis_var initParamHyp =
1191       getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
1192     aCreator->setInitParamsHypothesis( initParamHyp );
1193
1194     // Get Entry of the Geom object
1195     QString aGeomEntry = "";
1196     QString aMeshEntry = "";
1197     QString anObjEntry = "";
1198     aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1199     aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1200     anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1201
1202     if ( aMeshEntry != "" ) { // Get Geom object from Mesh
1203       _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1204       GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1205       aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
1206     }
1207
1208     if ( aMeshEntry == "" && aGeomEntry == "" ) {
1209       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1210       GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1211       if ( !aGeomVar->_is_nil() )
1212         aGeomEntry = aGeomVar->GetStudyEntry();
1213     }
1214
1215     if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { // take geometry from submesh
1216       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1217       if ( pObj ) {
1218         // if current object is sub-mesh
1219         SMESH::SMESH_subMesh_var aSubMeshVar =
1220           SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1221         if ( !aSubMeshVar->_is_nil() ) {
1222           SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
1223           if ( !aMeshVar->_is_nil() ) {
1224             _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1225             GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
1226             if ( !aGeomVar->_is_nil() )
1227               aMeshEntry = aGeomVar->GetStudyEntry();
1228           }
1229         }
1230       }
1231     }
1232
1233     aCreator->setShapeEntry( aGeomEntry );
1234     if ( aMeshEntry != "" )
1235       aCreator->setMainShapeEntry( aMeshEntry );
1236     removeCustomFilters(); // Issue 0020170
1237     myDlg->setEnabled( false );
1238     aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
1239   }
1240 }
1241
1242 //================================================================================
1243 /*!
1244  *  Necessary steps after hypothesis edition
1245  *  \param result - creation result:
1246  *   0 = rejected
1247  *   1 = accepted
1248  */
1249 //================================================================================
1250 void SMESHGUI_MeshOp::onHypoEdited( int result )
1251 {
1252   int obj = myDlg->getActiveObject();
1253   onActivateObject( obj ); // Issue 0020170. Restore filters
1254   myDlg->setEnabled( true );
1255 }
1256
1257 //================================================================================
1258 /*!
1259  * \brief access to hypothesis data
1260   * \param theDim - hyp dimension
1261   * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
1262   * \param theIndex - index in the list
1263   * \retval HypothesisData* - result data, may be 0
1264  */
1265 //================================================================================
1266
1267 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
1268                                           const int theHypType,
1269                                           const int theIndex)
1270 {
1271   if ( theDim     > -1 && theDim    <= SMESH::DIM_3D &&
1272        theHypType > -1 && theHypType < NbHypTypes &&
1273        theIndex   > -1 && theIndex   < myAvailableHypData[ theDim ][ theHypType ].count() )
1274     return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
1275   return 0;
1276 }
1277
1278 //================================================================================
1279 /*!
1280  * \brief Set available algos and hypos according to the selected algorithm
1281   * \param theIndex - algorithm index
1282  */
1283 //================================================================================
1284
1285 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
1286                                       const int theDim )
1287 {
1288   if ( myIgnoreAlgoSelection )
1289     return;
1290
1291   int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
1292   if (aDim == -1)
1293     return;
1294
1295   // find highest available dimension, all algos of this dimension are available for choice
1296   int aTopDim = -1;
1297   for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
1298     if (isAccessibleDim( i ))
1299       aTopDim = i;
1300   if (aTopDim == -1)
1301     return;
1302
1303   const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
1304
1305   HypothesisData* algoData = hypData( aDim, Algo, theIndex );
1306   HypothesisData* algoByDim[4];
1307   algoByDim[ aDim ] = algoData;
1308
1309   QStringList anAvailable;
1310   if ( !algoData ) { // all algos becomes available
1311     availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
1312     myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1313   }
1314
1315   // check that algorithms of other dimentions are compatible with
1316   // the selected one
1317
1318    // 2 loops: backward and forward from algo dimension
1319   for ( int forward = false; forward <= true; ++forward )
1320   {
1321     int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
1322     if ( !forward ) {
1323       dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
1324     }
1325     HypothesisData* prevAlgo = algoData;
1326     bool noCompatible = false;
1327     for ( ; dim * dir <= lastDim * dir; dim += dir)
1328     {
1329       if ( !isAccessibleDim( dim ))
1330         continue;
1331       if ( noCompatible ) { // the selected algo has no compatible ones
1332         anAvailable.clear();
1333         myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1334         myAvailableHypData[dim][Algo].clear();
1335         algoByDim[ dim ] = 0;
1336         continue;
1337       }
1338       // get currently selected algo
1339       int algoIndex = currentHyp( dim, Algo );
1340       HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1341       if ( curAlgo ) { // some algo selected
1342         if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1343           curAlgo = 0;
1344       }
1345       // set new available algoritms
1346       availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1347       HypothesisData* soleCompatible = 0;
1348       if ( anAvailable.count() == 1 )
1349         soleCompatible = myAvailableHypData[dim][Algo][0];
1350       if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1351         availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1352       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1353       noCompatible = anAvailable.isEmpty();
1354
1355       // restore previously selected algo
1356       algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
1357       if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
1358         // select the sole compatible algo
1359         algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
1360       setCurrentHyp( dim, Algo, algoIndex );
1361
1362       // remember current algo
1363       prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1364     }
1365   }
1366
1367   // set hypotheses corresponding to the found algoritms
1368
1369   _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1370
1371   for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
1372   {
1373     if ( !isAccessibleDim( dim ))
1374       continue;
1375     for ( int type = MainHyp; type < NbHypTypes; type++ )
1376     {
1377       myAvailableHypData[ dim ][ type ].clear();
1378       QStringList anAvailable, anExisting;
1379
1380       HypothesisData* curAlgo = algoByDim[ dim ];
1381       int hypIndex = currentHyp( dim, type );
1382
1383       SMESH::SMESH_Hypothesis_var curHyp;
1384       if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1385         curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
1386
1387       if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1388         // try to find algo by selected hypothesis in order to keep it selected
1389         bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1390         CORBA::String_var curHypType = curHyp->GetName();
1391         if ( !algoDeselectedByUser &&
1392              myObjHyps[ dim ][ type ].count() > 0 &&
1393              !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
1394         {
1395           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1396           for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
1397             curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1398             if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
1399               break;
1400             else
1401               curAlgo = 0;
1402           }
1403         }
1404       }
1405       // get hyps compatible with curAlgo
1406       if ( curAlgo )
1407       {
1408         // check if a selected hyp is compatible with the curAlgo
1409         if ( !curHyp->_is_nil() ) {
1410           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1411           if ( !isCompatible( curAlgo, hypData, type ))
1412             curHyp = SMESH::SMESH_Hypothesis::_nil();
1413         }
1414         existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1415         availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1416       }
1417       // set list of hypotheses
1418       myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1419       myDlg->tab( dim )->setExistingHyps( type, anExisting );
1420
1421       // set current existing hypothesis
1422       if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1423         hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1424       else
1425         hypIndex = -1;
1426       if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1427         // none is yet selected => select the sole existing if it is not optional
1428         CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
1429         bool isOptional = true;
1430         if ( algoByDim[ dim ] &&
1431              SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
1432              !isOptional )
1433           hypIndex = 0;
1434       }
1435       setCurrentHyp( dim, type, hypIndex );
1436     }
1437   }
1438 }
1439
1440 //================================================================================
1441 /*!
1442  * \brief Creates and selects hypothesis of hypotheses set
1443  * \param theSetName - The name of hypotheses set
1444  */
1445 //================================================================================
1446 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1447 {
1448   myHypoSet = SMESH::GetHypothesesSet(theSetName);
1449   if (!myHypoSet)
1450     return;
1451
1452   // clear all hyps
1453   for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
1454     setCurrentHyp(dim, Algo, -1);
1455     setCurrentHyp(dim, AddHyp, -1);
1456     setCurrentHyp(dim, MainHyp, -1);
1457   }
1458
1459   myHypoSet->init(true); //algorithms
1460   processSet();
1461   myHypoSet->init(false); //hypotheses
1462   processSet();
1463   myHypoSet = 0;
1464 }
1465
1466 //================================================================================
1467 /*!
1468  * \brief One step of hypothesis/algorithm list creation
1469  *
1470  * Creates a hypothesis or an algorithm for current item of internal list of names myHypoSet
1471  */
1472 //================================================================================
1473 void SMESHGUI_MeshOp::processSet()
1474 {
1475   myHypoSet->next();
1476   if( !myHypoSet->more() )
1477     return;
1478
1479   bool isAlgo = myHypoSet->isAlgo();
1480   QString aHypoTypeName = myHypoSet->current();
1481   HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1482   if (!aHypData)
1483   {
1484     processSet();
1485     return;
1486   }
1487
1488   int aDim = aHypData->Dim[0];
1489   // create or/and set
1490   if (isAlgo)
1491   {
1492     int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1493     if ( index < 0 )
1494     {
1495       QStringList anAvailable;
1496       availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
1497       myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
1498       index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
1499     }
1500     setCurrentHyp( aDim, Algo, index );
1501     onAlgoSelected( index, aDim );
1502     processSet();
1503   }
1504   else
1505   {
1506     bool mainHyp = true;
1507     QStringList anAvailable;
1508     availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
1509     myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
1510     int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
1511     if ( index < 0 )
1512     {
1513       mainHyp = false;
1514       index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
1515     }
1516     if (index >= 0)
1517       createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1518     else
1519       processSet();
1520   }
1521 }
1522
1523 //================================================================================
1524 /*!
1525  * \brief Creates mesh
1526   * \param theMess - Output parameter intended for returning error message
1527   * \retval bool  - TRUE if mesh is created, FALSE otherwise
1528  *
1529  * Creates mesh
1530  */
1531 //================================================================================
1532 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1533 {
1534   theMess = "";
1535
1536   //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1537   //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1538
1539   QStringList aList;
1540   myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
1541   QStringList::Iterator it = aList.begin();
1542   for ( ; it!=aList.end(); it++)
1543   {
1544     QString aGeomEntry = *it;
1545     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1546     GEOM::GEOM_Object_var aGeomVar =
1547       GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1548
1549     SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1550     if ( aSMESHGen->_is_nil() )
1551       return false;
1552
1553     SUIT_OverrideCursor aWaitCursor;
1554
1555     // create mesh
1556     SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1557     if ( aMeshVar->_is_nil() )
1558       return false;
1559     _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1560     if ( aMeshSO )
1561       SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
1562
1563     for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ ) {
1564       if ( !isAccessibleDim( aDim )) continue;
1565
1566       // assign hypotheses
1567       for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
1568         int aHypIndex = currentHyp( aDim, aHypType );
1569         if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
1570           SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1571           if ( !aHypVar->_is_nil() )
1572             SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1573         }
1574       }
1575       // find or create algorithm
1576       SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1577       if ( !anAlgoVar->_is_nil() )
1578         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1579     }
1580
1581   }
1582   return true;
1583 }
1584
1585 //================================================================================
1586 /*!
1587  * \brief Creates sub-mesh
1588   * \param theMess - Output parameter intended for returning error message
1589   * \retval bool  - TRUE if sub-mesh is created, FALSE otherwise
1590  *
1591  * Creates sub-mesh
1592  */
1593 //================================================================================
1594 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1595 {
1596   theMess = "";
1597
1598   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1599   if ( aSMESHGen->_is_nil() )
1600     return false;
1601
1602   // get mesh object
1603   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1604   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
1605   SMESH::SMESH_Mesh_var aMeshVar =
1606     SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1607   if (aMeshVar->_is_nil())
1608     return false;
1609
1610   // GEOM shape of the main mesh
1611   GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
1612
1613   // Name for the new sub-mesh
1614   QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
1615
1616   // get geom object
1617   GEOM::GEOM_Object_var aGeomVar;
1618   QStringList aGEOMs;
1619   myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
1620   if (aGEOMs.count() == 1)
1621   {
1622     //QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1623     QString aGeomEntry = aGEOMs.first();
1624     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
1625     aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1626   }
1627   else if (aGEOMs.count() > 1)
1628   {
1629     // create a GEOM group
1630     GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1631     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1632     if (!geomGen->_is_nil() && aStudy) {
1633       GEOM::GEOM_IGroupOperations_var op =
1634         geomGen->GetIGroupOperations(aStudy->StudyId());
1635       if (!op->_is_nil()) {
1636         // check and add all selected GEOM objects: they must be
1637         // a sub-shapes of the main GEOM and must be of one type
1638         int iSubSh = 0;
1639         TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1640         GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1641         aSeq->length(aGEOMs.count());
1642         QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
1643         for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
1644           QString aSubGeomEntry = (*aSubShapesIter);
1645           _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
1646           GEOM::GEOM_Object_var aSubGeomVar =
1647             GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
1648           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
1649           if (iSubSh == 0) {
1650             aGroupType = aSubShapeType;
1651           } else {
1652             if (aSubShapeType != aGroupType)
1653               aGroupType = TopAbs_SHAPE;
1654           }
1655           aSeq[iSubSh] = aSubGeomVar;
1656         }
1657         // create a group
1658         GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
1659         op->UnionList(aGroupVar, aSeq);
1660
1661         if (op->IsDone()) {
1662           aGeomVar = aGroupVar;
1663
1664           // publish the GEOM group in study
1665           QString aNewGeomGroupName ("Auto_group_for_");
1666           aNewGeomGroupName += aName;
1667           SALOMEDS::SObject_var aNewGroupSO =
1668             geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, 
1669                                 aNewGeomGroupName.toLatin1().data(), mainGeom);
1670         }
1671       }
1672     }
1673   }
1674   else {
1675   }
1676   if (aGeomVar->_is_nil())
1677     return false;
1678
1679   SUIT_OverrideCursor aWaitCursor;
1680
1681   // create sub-mesh
1682   SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
1683   _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
1684   if ( aSubMeshSO )
1685     SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
1686
1687   for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
1688   {
1689     if ( !isAccessibleDim( aDim )) continue;
1690
1691     // find or create algorithm
1692     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1693     if ( !anAlgoVar->_is_nil() )
1694       SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1695     // assign hypotheses
1696     for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1697     {
1698       int aHypIndex = currentHyp( aDim, aHypType );
1699       if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1700       {
1701         SMESH::SMESH_Hypothesis_var aHypVar =
1702           myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
1703         if ( !aHypVar->_is_nil() )
1704           SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1705       }
1706     }
1707   }
1708
1709   // deselect geometry: next submesh should be created on other subshape
1710   myDlg->clearSelection( SMESHGUI_MeshDlg::Geom );
1711   selectObject( _PTR(SObject)() );
1712   selectionDone();
1713
1714   return true;
1715 }
1716
1717 //================================================================================
1718 /*!
1719  * \brief Gets current hypothesis or algorithms
1720   * \param theDim - dimension of hypothesis or algorithm
1721   * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1722   * \retval int - current hypothesis or algorithms
1723  *
1724  * Gets current hypothesis or algorithms
1725  */
1726 //================================================================================
1727 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1728 {
1729   return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1730 }
1731
1732 //================================================================================
1733 /*!
1734  * \brief Returns true if hypotheses of given dim can be assigned
1735   * \param theDim - hypotheses dimension
1736   * \retval bool - result
1737  */
1738 //================================================================================
1739 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1740 {
1741   return myDlg->isTabEnabled( theDim );
1742 }
1743
1744 //================================================================================
1745 /*!
1746  * \brief Sets current hypothesis or algorithms
1747   * \param theDim - dimension of hypothesis or algorithm
1748   * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1749   * \param theIndex - Index of hypothesis
1750  *
1751  * Gets current hypothesis or algorithms
1752  */
1753 //================================================================================
1754 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1755                                      const int theHypType,
1756                                      const int theIndex )
1757 {
1758   myIgnoreAlgoSelection = true;
1759   myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1760   myIgnoreAlgoSelection = false;
1761 }
1762
1763 //================================================================================
1764 /*!
1765  * \brief Generates default and sets mesh/submesh name
1766  *
1767  * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1768  */
1769 //================================================================================
1770 void SMESHGUI_MeshOp::setDefaultName() const
1771 {
1772   QString aResName;
1773
1774   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1775   int i = 1;
1776   QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1777   _PTR(SObject) anObj;
1778   do
1779   {
1780     aResName = aPrefix + QString::number( i++ );
1781     anObj = aStudy->FindObject( aResName.toLatin1().data() );
1782   }
1783   while ( anObj );
1784
1785   QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1786     SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1787   aControl->setText( aResName );
1788 }
1789
1790 //================================================================================
1791 /*!
1792  * \brief Gets algorithm or creates it if necessary
1793   * \param theDim - specifies dimension of returned hypotheses/algorifms
1794   * \retval SMESH::SMESH_Hypothesis_var - algorithm
1795  *
1796  * Gets algorithm or creates it if necessary
1797  */
1798 //================================================================================
1799 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1800 {
1801   SMESH::SMESH_Hypothesis_var anAlgoVar;
1802
1803   // get type of the selected algo
1804   int aHypIndex = currentHyp( theDim, Algo );
1805   THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1806   if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1807     return anAlgoVar;
1808   QString aHypName = dataList[ aHypIndex ]->TypeName;
1809
1810   // get existing algoritms
1811   _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1812   QStringList tmp;
1813   existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1814
1815   // look for an existing algo of such a type
1816   THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1817   THypList::iterator anIter = aHypVarList.begin();
1818   for ( ; anIter != aHypVarList.end(); anIter++)
1819   {
1820     SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1821     CORBA::String_var aName = aHypVar->GetName();
1822     if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1823     {
1824       anAlgoVar = aHypVar;
1825       break;
1826     }
1827   }
1828
1829   if (anAlgoVar->_is_nil())
1830   {
1831     HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1832     if (aHypData)
1833     {
1834       QString aClientLibName = aHypData->ClientLibName;
1835       if (aClientLibName == "")
1836       {
1837         // Call hypothesis creation server method (without GUI)
1838         SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1839       }
1840       else
1841       {
1842         // Get hypotheses creator client (GUI)
1843         // BUG 0020378
1844         //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1845         SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1846
1847         // Create algorithm
1848         if (aCreator)
1849           aCreator->create(true, aHypName, myDlg, 0, QString::null );
1850         else
1851           SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1852       }
1853       QStringList tmpList;
1854       _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1855       existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1856     }
1857
1858     THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1859     for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1860     {
1861       SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
1862       CORBA::String_var aName = aHypVar->GetName();
1863       if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
1864       {
1865         anAlgoVar = aHypVar;
1866         break;
1867       }
1868     }
1869   }
1870
1871   return anAlgoVar._retn();
1872 }
1873
1874 //================================================================================
1875 /*!
1876  * \brief Reads parameters of edited mesh and assigns them to the dialog
1877  *
1878  * Reads parameters of edited mesh and assigns them to the dialog (called when
1879  * mesh is edited only)
1880  */
1881 //================================================================================
1882 void SMESHGUI_MeshOp::readMesh()
1883 {
1884   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1885   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
1886   if ( !pObj )
1887     return;
1888
1889   if (myIsOnGeometry) {
1890     // Get name of mesh if current object is sub-mesh
1891     SMESH::SMESH_subMesh_var aSubMeshVar =
1892       SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1893     if ( !aSubMeshVar->_is_nil() )
1894     {
1895       SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
1896       if ( !aMeshVar->_is_nil() )
1897       {
1898         _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1899         QString aMeshName = name( aMeshSO );
1900         myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1901       }
1902     }
1903
1904     // Get name of geometry object
1905     GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1906     if ( !aGeomVar->_is_nil() )
1907     {
1908       _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1909       QString aShapeName = name( aGeomSO );
1910       myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1911     }
1912   }
1913
1914   // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1915   QStringList anExisting;
1916   const int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
1917   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1918   {
1919     // get algorithm
1920     existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1921     // find algo index among available ones
1922     int aHypIndex = -1;
1923     if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1924     {
1925       SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
1926       HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
1927       aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
1928 //       if ( aHypIndex < 0 && algoData ) {
1929 //         // assigned algo is incompatible with other algorithms
1930 //         myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1931 //         aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1932 //       }
1933     }
1934     setCurrentHyp( dim, Algo, aHypIndex );
1935     // set existing and available hypothesis according to the selected algo
1936     onAlgoSelected( aHypIndex, dim );
1937   }
1938
1939   // get hypotheses
1940   bool hypWithoutAlgo = false;
1941   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
1942   {
1943     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1944     {
1945       // get hypotheses
1946       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1947       // find index of requered hypothesis among existing ones for this dimension and type
1948       int aHypIndex = -1;
1949       if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1950         aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
1951                           myExistingHyps[ dim ][ hypType ] );
1952         if ( aHypIndex < 0 ) {
1953           // assigned hypothesis is incompatible with the algorithm
1954           if ( currentHyp( dim, Algo ) < 0 )
1955           { // none algo selected; it is edition for sure, of submesh maybe
1956             hypWithoutAlgo = true;
1957             myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1958             aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1959             myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1960           }
1961         }
1962       }
1963       setCurrentHyp( dim, hypType, aHypIndex );
1964     }
1965   }
1966   // make available other hyps of same type as one without algo
1967   if ( hypWithoutAlgo )
1968     onAlgoSelected( currentHyp( 0, Algo ), 0 );
1969 }
1970
1971 //================================================================================
1972 /*!
1973  * \brief Gets name of object
1974   * \param theSO - SObject
1975   * \retval QString - name of object
1976  *
1977  * Gets name of object
1978  */
1979 //================================================================================
1980 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1981 {
1982   QString aResName;
1983   if ( theSO )
1984   {
1985     _PTR(GenericAttribute) anAttr;
1986     _PTR(AttributeName)    aNameAttr;
1987     if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1988     {
1989       aNameAttr = anAttr;
1990       aResName = aNameAttr->Value().c_str();
1991     }
1992   }
1993   return aResName;
1994 }
1995
1996 //================================================================================
1997 /*!
1998  * \brief Finds hypothesis in input list
1999   * \param theHyp - hypothesis to be found
2000   * \param theHypList - input list of hypotheses
2001   * \retval int - index of hypothesis or -1 if it is not found
2002  *
2003  * Finds position of hypothesis in input list
2004  */
2005 //================================================================================
2006 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
2007                            const THypList& theHypList ) const
2008 {
2009   int aRes = -1;
2010   if ( !theHyp->_is_nil() )
2011   {
2012     int i = 0;
2013     THypList::const_iterator anIter = theHypList.begin();
2014     for ( ; anIter != theHypList.end(); ++ anIter)
2015     {
2016       if ( theHyp->_is_equivalent( (*anIter).first ) )
2017       {
2018         aRes = i;
2019         break;
2020       }
2021       i++;
2022     }
2023   }
2024   return aRes;
2025 }
2026
2027 //================================================================================
2028 /*!
2029  * \brief Edits mesh or sub-mesh
2030   * \param theMess - Output parameter intended for returning error message
2031   * \retval bool  - TRUE if mesh is edited succesfully, FALSE otherwise
2032  *
2033  * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
2034  */
2035 //================================================================================
2036 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
2037 {
2038   theMess = "";
2039
2040   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
2041   if ( aSMESHGen->_is_nil() )
2042     return false;
2043
2044   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
2045   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
2046   if ( !pObj )
2047     return false;
2048
2049   SUIT_OverrideCursor aWaitCursor;
2050
2051   // Set new name
2052   QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
2053   SMESH::SetName( pObj, aName );
2054   int aDim = ( myIsOnGeometry ) ? SMESH::DIM_0D : SMESH::DIM_3D;
2055
2056   // First, remove old algos in order to avoid messages on algorithm hiding
2057   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2058   {
2059     if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
2060     {
2061       SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
2062       SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2063       if ( anAlgoVar->_is_nil() || // no new algo selected or
2064            strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
2065       {
2066         // remove old algorithm
2067         SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
2068         myObjHyps[ dim ][ Algo ].clear();
2069       }
2070     }
2071   }
2072
2073   // Assign new algorithms and hypotheses
2074   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
2075   {
2076     if ( !isAccessibleDim( dim )) continue;
2077
2078     // find or create algorithm
2079     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
2080
2081     // assign new algorithm
2082     if ( !anAlgoVar->_is_nil() && // some algo selected and
2083          myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
2084     {
2085       SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
2086       CORBA::Object_var anObject = aSObject->GetObject();
2087       SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
2088       bool isMesh = !aMeshVar->_is_nil();
2089       if ( isMesh ) {
2090         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
2091       } else {
2092         SMESH::SMESH_subMesh_var aVar =
2093           SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2094         if ( !aVar->_is_nil() )
2095           SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
2096       }
2097       myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
2098     }
2099
2100     // assign hypotheses
2101     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
2102     {
2103       int aNewHypIndex = currentHyp( dim, hypType );
2104       int anOldHypIndex = -1;
2105
2106       // remove old hypotheses
2107       if ( myObjHyps[ dim ][ hypType ].count() > 0 )
2108       {
2109         anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
2110                               myExistingHyps[ dim ][ hypType ] );
2111         if ( aNewHypIndex != anOldHypIndex || // different hyps
2112              anOldHypIndex == -1 )            // hyps of different algos
2113         {
2114           SMESH::RemoveHypothesisOrAlgorithmOnMesh
2115             ( pObj, myObjHyps[ dim ][ hypType ].first().first );
2116           myObjHyps[ dim ][ hypType ].clear();
2117         }
2118       }
2119
2120       // assign new hypotheses
2121       if ( aNewHypIndex != anOldHypIndex && aNewHypIndex != -1 )
2122       {
2123         SMESH::SMESH_Mesh_var aMeshVar =
2124           SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2125         bool isMesh = !aMeshVar->_is_nil();
2126         if ( isMesh )
2127         {
2128           SMESH::AddHypothesisOnMesh
2129             (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2130         }
2131         else
2132         {
2133           SMESH::SMESH_subMesh_var aVar =
2134             SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
2135           if ( !aVar->_is_nil() )
2136             SMESH::AddHypothesisOnSubMesh
2137               ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
2138         }
2139       }
2140       // reread all hypotheses of mesh if necessary
2141       QStringList anExisting;
2142       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
2143     }
2144   }
2145
2146   return true;
2147 }
2148
2149 //================================================================================
2150 /*!
2151  * \brief Verifies whether given operator is valid for this one
2152   * \param theOtherOp - other operation
2153   * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
2154 *
2155 * method redefined from base class verifies whether given operator is valid for
2156 * this one (i.e. can be started "above" this operator). In current implementation method
2157 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
2158 * elements.
2159 */
2160 //================================================================================
2161 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
2162 {
2163   return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
2164 }
2165
2166 //================================================================================
2167 /*!
2168  * \brief SLOT. Is called when the user selects a way of geometry selection
2169   * \param theByMesh - true if the user wants to find geometry by mesh element
2170  */
2171 //================================================================================
2172
2173 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
2174 {
2175   if ( theByMesh ) {
2176     if ( !myShapeByMeshOp ) {
2177       myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
2178       connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2179               SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2180       connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2181               SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2182     }
2183     // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2184     QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
2185     if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
2186       SMESH::SMESH_Mesh_var aMeshVar =
2187         SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
2188       if ( !aMeshVar->_is_nil() ) {
2189         myDlg->hide(); // stop processing selection
2190         myShapeByMeshOp->setModule( getSMESHGUI() );
2191         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2192         myShapeByMeshOp->SetMesh( aMeshVar );
2193         myShapeByMeshOp->start();
2194       }
2195     }
2196   }
2197 }
2198
2199 //================================================================================
2200 /*!
2201  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2202  */
2203 //================================================================================
2204
2205 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
2206 {
2207   if ( myShapeByMeshOp == op ) {
2208     SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006  IPAL13980 - Object Browser update added
2209     myDlg->show();
2210     // Select a found geometry object
2211     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2212     if ( !aGeomVar->_is_nil() )
2213     {
2214       QString ID = aGeomVar->GetStudyEntry();
2215       if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
2216         selectObject( aGeomSO );
2217         selectionDone();
2218       }
2219     }
2220   }
2221 }
2222
2223 //================================================================================
2224 /*!
2225  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2226  */
2227 //================================================================================
2228
2229 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
2230 {
2231   if ( myShapeByMeshOp == op && myDlg ) {
2232     myDlg->show();
2233   }
2234 }
2235
2236 //================================================================================
2237 /*!
2238  * \brief Selects a SObject
2239   * \param theSObj - the SObject to select
2240  */
2241 //================================================================================
2242
2243 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
2244 {
2245   if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
2246     SALOME_ListIO anIOList;
2247     if ( theSObj ) {
2248       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2249         ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
2250       anIOList.Append( anIO );
2251     }
2252     sm->setSelectedObjects( anIOList, false );
2253   }
2254 }