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