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