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