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