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