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