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