]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_MeshOp.cxx
Salome HOME
ca7b9efb2995d72af3ce8725e4112ee5c69f1087
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 /**
21 *  SMESH SMESHGUI
22 *
23 *  Copyright (C) 2005  CEA/DEN, EDF R&D
24 *
25 *
26 *
27 *  File   : SMESHGUI_MeshOp.h
28 *  Author : Sergey LITONIN
29 *  Module : SMESHGUI
30 */
31
32 #include "SMESHGUI_MeshOp.h"
33 #include "SMESHGUI_MeshDlg.h"
34 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include "SMESH_TypeFilter.hxx"
36 #include "SMESHGUI.h"
37
38 #include "SMESHGUI_HypothesesUtils.h"
39 #include "SMESHGUI_Hypotheses.h"
40 #include "SMESHGUI_Utils.h"
41 #include "SMESHGUI_GEOMGenUtils.h"
42 #include "SMESHGUI_VTKUtils.h"
43
44 #include "SMESH_TypeFilter.hxx"
45 #include "SMESH_NumberFilter.hxx"
46
47 #include "GEOM_SelectionFilter.h"
48 #include "GEOMBase.h"
49 #include "GeometryGUI.h"
50
51 #include "SalomeApp_Tools.h"
52 #include "SALOMEDSClient_Study.hxx"
53 #include "SALOMEDSClient_AttributeIOR.hxx"
54 #include "SALOMEDSClient_AttributeName.hxx"
55 #include "SALOMEDS_SComponent.hxx"
56 #include "SALOMEDS_SObject.hxx"
57
58 #include "LightApp_SelectionMgr.h"
59 #include "LightApp_UpdateFlags.h"
60 #include "SUIT_MessageBox.h"
61 #include "SUIT_Desktop.h"
62 #include "SUIT_OverrideCursor.h"
63 #include "SALOME_InteractiveObject.hxx"
64 #include "SALOME_ListIO.hxx"
65
66 #include "utilities.h"
67
68 #include <qstringlist.h>
69 #include <qlineedit.h>
70
71 #include <TopoDS_Shape.hxx>
72 #include <TopExp_Explorer.hxx>
73
74 enum { GLOBAL_ALGO_TAG        =3,
75        GLOBAL_HYPO_TAG        =2,
76        LOCAL_ALGO_TAG         =2,
77        LOCAL_HYPO_TAG         =1,
78        SUBMESH_ON_EDGE_TAG    =5,
79        SUBMESH_ON_WIRE_TAG    =6,
80        SUBMESH_ON_FACE_TAG    =7,
81        SUBMESH_ON_SHELL_TAG   =8,
82        SUBMESH_ON_SOLID_TAG   =9,
83        SUBMESH_ON_COMPOUND_TAG=10 };
84        
85 //================================================================================
86 /*!
87  * \brief Constructor
88   * \param theToCreate - if this parameter is true then operation is used for creation,
89   * for editing otherwise
90  *
91  * Initialize operation
92 */
93 //================================================================================
94 SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh )
95 : SMESHGUI_SelectionOp(),
96   myToCreate( theToCreate ),
97   myIsMesh( theIsMesh ),
98   myDlg( 0 ),
99   myShapeByMeshOp( 0 )
100 {
101   if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
102     GeometryGUI::InitGeomGen();
103 }
104
105 //================================================================================
106 /*!
107  * \brief Destructor
108 */
109 //================================================================================
110 SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
111 {
112   if ( myDlg )
113     delete myDlg;
114 }
115
116 //================================================================================
117 /*!
118  * \brief Gets dialog of this operation
119   * \retval LightApp_Dialog* - pointer to dialog of this operation
120 */
121 //================================================================================
122 LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
123 {
124   return myDlg;
125 }
126
127 //================================================================================
128 /*!
129  * \brief Creates or edits mesh
130   * \retval bool - TRUE if operation is performed successfully, FALSE otherwise
131  *
132  * Virtual slot redefined from the base class called when "Apply" button is clicked
133  * creates or edits mesh
134  */
135 //================================================================================
136 bool SMESHGUI_MeshOp::onApply()
137 {
138   if( isStudyLocked() )
139     return false;
140
141   QString aMess;
142   if ( !isValid( aMess ) )
143   {
144     dlg()->show();
145     if ( aMess != "" )
146       SUIT_MessageBox::warn1( myDlg,
147         tr( "SMESH_WRN_WARNING" ), aMess, tr( "SMESH_BUT_OK" ) );
148     return false;
149   }
150
151   bool aResult = false;
152   aMess = "";
153   try
154   {
155     if ( myToCreate && myIsMesh )
156       aResult = createMesh( aMess );
157     if ( myToCreate && !myIsMesh )
158       aResult = createSubMesh( aMess );
159     else if ( !myToCreate )
160       aResult = editMeshOrSubMesh( aMess );
161     if ( aResult )
162       update( UF_ObjBrowser | UF_Model );
163   }
164   catch ( const SALOME::SALOME_Exception& S_ex )
165   {
166     SalomeApp_Tools::QtCatchCorbaException( S_ex );
167     aResult = false;
168   }
169   catch ( ... )
170   {
171     aResult = false;
172   }
173
174   if ( aResult )
175   {
176     if ( myToCreate )
177       setDefaultName();
178   }
179   else
180   {
181     if ( aMess == "" )
182       aMess = tr( "SMESH_OPERATION_FAILED" );
183     SUIT_MessageBox::warn1( myDlg,
184       tr( "SMESH_ERROR" ), aMess, tr( "SMESH_BUT_OK" ) );
185   }
186
187   return aResult;
188 }
189
190 //================================================================================
191 /*!
192  * \brief Creates dialog if necessary and shows it
193  *
194  * Virtual method redefined from base class called when operation is started creates
195  * dialog if necessary and shows it, activates selection
196  */
197 //================================================================================
198 void SMESHGUI_MeshOp::startOperation()
199 {
200   if( !myDlg )
201   {
202     myDlg = new SMESHGUI_MeshDlg( myToCreate, myIsMesh );
203     for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
204     {
205       connect( myDlg->tab( i ), SIGNAL( createHyp( const int, const int ) ),
206               this, SLOT( onCreateHyp( const int, const int ) ) );
207       connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
208               this, SLOT( onEditHyp( const int, const int ) ) );
209       connect( myDlg->tab( i ), SIGNAL( selectAlgo( const int ) ),
210               this, SLOT( onAlgoSelected( const int ) ) );
211     }
212     connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
213     connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool )));
214
215     if ( myToCreate ) 
216       if ( myIsMesh ) myHelpFileName = "/files/constructing_meshes.htm";
217       else myHelpFileName = "/files/constructing_submeshes.htm";
218     else myHelpFileName = "files/reassigning_hypotheses_and_algorithms.htm";
219   }
220   SMESHGUI_SelectionOp::startOperation();
221
222   // iterate through dimensions and get available algoritms,
223   // set them to the dialog
224   _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
225   for ( int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++ )
226   {
227     SMESHGUI_MeshTab* aTab = myDlg->tab( i );
228     QStringList hypList;
229     // clear available hypotheses
230     aTab->setAvailableHyps( MainHyp, hypList );
231     aTab->setAvailableHyps( AddHyp, hypList );
232     aTab->setExistingHyps( MainHyp, hypList );
233     aTab->setExistingHyps( AddHyp, hypList );
234     myExistingHyps[ i ][ MainHyp ].clear();
235     myExistingHyps[ i ][ AddHyp ].clear();
236     // set algos
237     availableHyps( i, Algo, hypList, myAvailableHypData[i][Algo] );
238     aTab->setAvailableHyps( Algo, hypList );
239   }
240   if ( myToCreate )
241   {
242     setDefaultName();
243     myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
244   }
245   else
246     myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
247
248   myDlg->setHypoSets( SMESH::GetHypothesesSets() );
249
250   myDlg->setCurrentTab( SMESH::DIM_3D );
251   myDlg->show();
252
253   selectionDone();
254
255   myIgnoreAlgoSelection = false;
256 }
257
258 //================================================================================
259 /*!
260  * \brief Creates selection filter
261   * \param theId - identifier of current selection widget
262   * \retval SUIT_SelectionFilter* - pointer to the created filter or null
263  *
264  * Creates selection filter in accordance with identifier of current selection widget
265  */
266 //================================================================================
267 SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
268 {
269   if ( theId == SMESHGUI_MeshDlg::Geom )
270   {
271 //     TColStd_MapOfInteger allTypesMap;
272 //     for ( int i = 0; i < 10; i++ )
273 //       allTypesMap.Add( i );
274 //     return new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 0, allTypesMap );
275     return new GEOM_SelectionFilter( (SalomeApp_Study*)study(), true );
276   }
277   else if ( theId == SMESHGUI_MeshDlg::Obj && !myToCreate )
278     return new SMESH_TypeFilter( MESHorSUBMESH );
279   else if ( theId == SMESHGUI_MeshDlg::Mesh )
280     return new SMESH_TypeFilter( MESH );
281   else
282     return 0;
283 }
284
285 //================================================================================
286 /*!
287  * \brief check if selected shape is a subshape of the shape to mesh
288   * \retval bool - check result
289  */
290 //================================================================================
291
292 bool SMESHGUI_MeshOp::isSubshapeOk() const
293 {
294   if ( !myToCreate || myIsMesh ) // not submesh creation
295     return false;
296
297   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
298   QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
299   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
300   _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
301   if ( pMesh && pGeom ) {
302     SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
303     if ( !mesh->_is_nil() ) {
304       GEOM::GEOM_Object_var mainGeom, subGeom;
305       mainGeom = mesh->GetShapeToMesh();
306       subGeom  = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
307       if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
308         TopoDS_Shape mainShape, subShape;
309         if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
310              GEOMBase::GetShape( subGeom, subShape ) )
311         {
312           int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
313           if ( index > 0 ) {
314             // 1 is index of mainShape itself
315             return index > 1; // it is a subshape
316           }
317           // is it a group?
318           GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
319           _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
320           if ( !geomGen->_is_nil() && aStudy ) {
321             GEOM::GEOM_IGroupOperations_var op =
322               geomGen->GetIGroupOperations( aStudy->StudyId() );
323             if ( ! op->_is_nil() ) {
324               GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
325               if ( !mainObj->_is_nil() )
326                 return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
327             }
328           }
329         }
330       }
331     }
332   }
333   return false;
334 }
335
336 //================================================================================
337 /*!
338  * \brief find an existing submesh by the selected shape
339   * \retval _PTR(SObject) - the found submesh SObject
340  */
341 //================================================================================
342
343 _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
344 {
345   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
346   QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
347   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
348   _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
349   if ( pMesh && pGeom ) {
350     GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
351     if ( !geom->_is_nil() ) {
352       int tag = -1;
353       switch ( geom->GetShapeType() ) {
354       case GEOM::EDGE:     tag = SUBMESH_ON_EDGE_TAG    ; break;
355       case GEOM::WIRE:     tag = SUBMESH_ON_WIRE_TAG    ; break;
356       case GEOM::FACE:     tag = SUBMESH_ON_FACE_TAG    ; break;
357       case GEOM::SHELL:    tag = SUBMESH_ON_SHELL_TAG   ; break;
358       case GEOM::SOLID:    tag = SUBMESH_ON_SOLID_TAG   ; break;
359       case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
360       default:;
361       }
362       _PTR(GenericAttribute) anAttr;
363       _PTR(SObject) aSubmeshRoot;
364       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
365       if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
366       {
367         _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
368         for (; smIter->More(); smIter->Next() )
369         {
370           _PTR(SObject) aSmObj = smIter->Value();
371           if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
372             continue;
373           _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
374           for (; anIter1->More(); anIter1->Next()) {
375             _PTR(SObject) pGeom2 = anIter1->Value();
376             if ( pGeom2->ReferencedObject( pGeom2 ) &&
377                  pGeom2->GetID() == pGeom->GetID() )
378               return aSmObj;
379           }
380         }
381       }
382     }     
383   }
384   return _PTR(SObject)();
385 }
386
387 //================================================================================
388 /*!
389  * \brief Updates dialog's look and feel
390  *
391  * Virtual method redefined from the base class updates dialog's look and feel
392  */
393 //================================================================================
394 void SMESHGUI_MeshOp::selectionDone()
395 {
396   if ( !dlg()->isShown() )
397     return;
398
399   SMESHGUI_SelectionOp::selectionDone();
400
401   try
402   {
403     // Enable tabs according to shape dimension
404
405     int shapeDim = 3;
406
407     GEOM::GEOM_Object_var aGeomVar;
408     QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
409     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
410     if ( pGeom ) {
411       aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
412     }
413     else {
414       QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
415       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
416       aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
417     }
418     if ( !aGeomVar->_is_nil() ) {
419       shapeDim = 0;
420       switch ( aGeomVar->GetShapeType() ) {
421       case GEOM::SOLID:
422       case GEOM::SHELL:  shapeDim = 3; break;
423       case GEOM::FACE:   shapeDim = 2; break;
424       case GEOM::WIRE:   
425       case GEOM::EDGE:   shapeDim = 1; break;
426       case GEOM::VERTEX: shapeDim = 0; break;
427       default:
428         TopoDS_Shape aShape;
429         if ( GEOMBase::GetShape(aGeomVar, aShape)) {
430           TopExp_Explorer exp( aShape, TopAbs_SHELL );
431           if ( exp.More() )
432             shapeDim = 3;
433           else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
434             shapeDim = 2;
435           else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
436             shapeDim = 1;
437           else
438             shapeDim = 0;
439         }
440       }
441     }
442     myDlg->setMaxHypoDim( shapeDim );
443
444
445     if ( !myToCreate ) // edition: read hypotheses
446     {
447       QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
448       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
449       if ( pObj != 0 )
450       {
451         SMESH::SMESH_subMesh_var aVar =
452           SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
453         myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() );
454         myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide();
455         myDlg->updateGeometry();
456         myDlg->adjustSize();
457         readMesh();
458       }
459       else
460         myDlg->reset();
461
462     }
463     else if ( !myIsMesh ) // submesh creation
464     {
465       // if a submesh on the selected shape already exist, pass to submesh edition mode
466       if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) {
467         SMESH::SMESH_subMesh_var sm = 
468           SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pSubmesh );
469         bool editSubmesh = ( !sm->_is_nil() &&
470                              SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ),
471                                                          tr( "EDIT_SUBMESH_QUESTION"),
472                                                          tr( "SMESH_BUT_YES" ),
473                                                          tr( "SMESH_BUT_NO" ), 1, 0, 0 ));
474         if ( editSubmesh )
475         {
476           selectionMgr()->clearFilters();
477           selectObject( pSubmesh );
478           SMESHGUI::GetSMESHGUI()->switchToOperation(704);
479           return;
480         }
481         else
482         {
483           myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
484           selectObject( _PTR(SObject)() );
485           selectionDone();
486         }
487       }
488
489       // enable/disable popup for choice of geom selection way
490       bool enable = false;
491       QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
492       if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
493         SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
494         if ( !mesh->_is_nil() )
495           enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
496       }
497       myDlg->setGeomPopupEnabled( enable );
498     }
499   }
500   catch ( const SALOME::SALOME_Exception& S_ex )
501   {
502     SalomeApp_Tools::QtCatchCorbaException( S_ex );
503   }
504   catch ( ... )
505   {
506   }
507 }
508
509 //================================================================================
510 /*!
511  * \brief Verifies validity of input data
512   * \param theMess - Output parameter intended for returning error message
513   * \retval bool  - TRUE if input data is valid, false otherwise
514  *
515  * Verifies validity of input data. This method is called when "Apply" or "OK" button
516  * is pressed before mesh creation or editing.
517  */
518 //================================================================================
519 bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
520 {
521   // Selected object to be  edited
522   if ( !myToCreate && myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ) == "" )
523   {
524     theMess = tr( "THERE_IS_NO_OBJECT_FOR_EDITING" );
525     return false;
526   }
527
528   // Name
529   QString aMeshName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
530   aMeshName = aMeshName.stripWhiteSpace();
531   if ( aMeshName == "" )
532   {
533     theMess = myIsMesh ? tr( "NAME_OF_MESH_IS_EMPTY" ) : tr( "NAME_OF_SUBMESH_IS_EMPTY" );
534     return false;
535   }
536
537   // Imported mesh, if create sub-mesh or edit mesh
538   if ( !myToCreate || ( myToCreate && !myIsMesh ))
539   {
540     QString aMeshEntry = myDlg->selectedObject
541       ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
542     if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
543       SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
544       if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) {
545         theMess = tr( "IMPORTED_MESH" );
546         return false;
547       }
548     }
549   }
550
551   // Geom
552   if ( myToCreate )
553   {
554     QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
555     if ( aGeomEntry == "" )
556     {
557       theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
558       return false;
559     }
560     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
561     if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
562     {
563       theMess = tr( "GEOMETRY_OBJECT_IS_NULL" );
564       return false;
565     }
566
567     // Mesh
568     if ( !myIsMesh ) // i.e sub-mesh creation,
569     {
570       QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
571       if ( aMeshEntry == "" )
572       {
573         theMess = tr( "MESH_IS_NOT_DEFINED" );
574         return false;
575       }
576       _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
577       if ( !pMesh || SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() )->_is_nil() )
578       {
579         theMess = tr( "MESH_IS_NULL" );
580         return false;
581       }
582       if ( !isSubshapeOk() )
583       {
584         theMess = tr( "INVALID_SUBSHAPE" );
585         return false;
586       }
587     }
588   }
589     
590   return true;
591 }
592
593 //================================================================================
594 /*!
595  * \brief check compatibility of the algorithm and another algorithm or hypothesis
596   * \param theAlgoData - algorithm data
597   * \param theHypData - hypothesis data
598   * \param theHypType - hypothesis type
599   * \param theHypTypeName - hypothesis type name, must be provided if 2-nd arg is not algo
600   * \retval bool - check result
601  */
602 //================================================================================
603
604 static bool isCompatible(const HypothesisData* theAlgoData,
605                          const HypothesisData* theHypData,
606                          const int             theHypType)
607 {
608   if ( !theAlgoData )
609     return true;
610
611   if ( theHypType == SMESHGUI_MeshOp::Algo )
612     return SMESH::IsCompatibleAlgorithm( theAlgoData, theHypData );
613
614   bool isOptional;
615   return ( SMESH::IsAvailableHypothesis( theAlgoData, theHypData->TypeName, isOptional ));
616 }
617
618 //================================================================================
619 /*!
620  * \brief Gets available hypotheses or algorithms
621   * \param theDim - specifies dimension of returned hypotheses/algorifms
622   * \param theHypType - specifies whether algorims or hypotheses or additional ones
623   * are retrieved (possible values are in HypType enumeration)
624   * \param theHyps - Output list of hypotheses' names
625   * \param theAlgoData - to select hypos able to be used by this algo (optional)
626  *
627  * Gets available hypotheses or algorithm in accordance with input parameters
628  */
629 //================================================================================
630 void SMESHGUI_MeshOp::availableHyps( const int       theDim,
631                                      const int       theHypType,
632                                      QStringList&    theHyps,
633                                      THypDataList&   theDataList,
634                                      HypothesisData* theAlgoData ) const
635 {
636   theDataList.clear();
637   theHyps.clear();
638   bool isAlgo = ( theHypType == Algo );
639   bool isAux  = ( theHypType == AddHyp );
640   QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, theDim, isAux );
641
642   QStringList::const_iterator anIter;
643   for ( anIter = aHypTypeNameList.begin(); anIter != aHypTypeNameList.end(); ++anIter )
644   {
645     HypothesisData* aData = SMESH::GetHypothesisData( *anIter );
646     if ( isCompatible ( theAlgoData, aData, theHypType )) {
647       theDataList.append( aData );
648       theHyps.append( aData->Label );
649     }
650   }
651 }
652
653 //================================================================================
654 /*!
655  * \brief Gets existing hypotheses or algorithms
656   * \param theDim - specifies dimension of returned hypotheses/algorifms
657   * \param theHypType - specifies whether algorims or hypotheses or additional ones
658   * are retrieved (possible values are in HypType enumeration)
659   * \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
660   * \param theDataList - output list of hypotheses data
661   * \param theHyps - output list of names.
662   * \param theHypVars - output list of variables.
663   * \param theAlgoData - to select hypos able to be used by this algo (optional)
664  *
665  * Gets existing (i.e. already created) hypotheses or algorithm in accordance with
666  * input parameters
667  */
668 //================================================================================
669 void SMESHGUI_MeshOp::existingHyps( const int theDim,
670                                     const int theHypType,
671                                     _PTR(SObject) theFather,
672                                     QStringList& theHyps,
673                                     QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars,
674                                     HypothesisData* theAlgoData)
675 {
676   // Clear hypoheses list
677   theHyps.clear();
678   theHypVars.clear();
679
680   if ( !theFather )
681     return;
682
683   const bool isAux  = ( theHypType == AddHyp );
684
685   _PTR(SObject)          aHypRoot;
686   _PTR(GenericAttribute) anAttr;
687   _PTR(AttributeName)    aName;
688   _PTR(AttributeIOR)     anIOR;
689
690   bool isMesh = !_CAST( SComponent, theFather );
691   int aPart = -1;
692   if ( isMesh )
693     aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG;
694   else
695     aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG;
696
697   if ( theFather->FindSubObject( aPart, aHypRoot ) )
698   {
699     _PTR(ChildIterator) anIter =
700       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
701     for (; anIter->More(); anIter->Next() )
702     {
703       _PTR(SObject) anObj = anIter->Value();
704       if ( isMesh ) // i.e. mesh or submesh
705       {
706         _PTR(SObject) aRefObj;
707         if ( anObj->ReferencedObject( aRefObj ) )
708           anObj = aRefObj;
709         else
710           continue;
711       }
712       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
713       {
714         aName = anAttr;
715         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
716         if ( !CORBA::is_nil( aVar ) )
717         {
718           SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
719           if ( !aHypVar->_is_nil() )
720           {
721             QString aHypType( aHypVar->GetName() );
722             HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
723             if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
724                  ( isCompatible ( theAlgoData, aData, theHypType )) &&
725                  ( isAux == aData->IsAux ))
726             {
727               //theDataList.append( aData );
728               theHyps.append( aName->Value().c_str() );
729               theHypVars.append( aHypVar );
730             }
731           }
732         }
733       }
734     }
735   }
736 }
737
738 //================================================================================
739 /*!
740  * \brief If create or edit a submesh, return a hypothesis holding parameters used
741  *        to mesh a subshape
742   * \param aHypType - The hypothesis type name
743   * \param aServerLib - Server library name
744   * \param hypData - The structure holding the hypothesis type etc.
745   * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values
746  */
747 //================================================================================
748
749 SMESH::SMESH_Hypothesis_var
750 SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
751                                           const QString& aServerLib ) const
752 {
753   if ( aHypType.isEmpty() || aServerLib.isEmpty() )
754     return SMESH::SMESH_Hypothesis::_nil();
755
756   const int nbColonsInMeshEntry = 3;
757   bool isSubMesh = myToCreate ?
758     !myIsMesh :
759     myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry; 
760
761   if ( isSubMesh )
762   {
763     // get mesh and geom object
764     SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
765     GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
766
767     QString anEntry = myDlg->selectedObject
768       ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
769     if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() ))
770     {
771       CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject();
772       if ( myToCreate ) // mesh and geom may be selected
773       {
774         aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj );
775         anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
776         if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() ))
777           aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
778       }
779       else // edition: sub-mesh may be selected
780       {
781         SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj );
782         if ( !sm->_is_nil() ) {
783           aMeshVar = sm->GetFather();
784           aGeomVar = sm->GetSubShape();
785         }
786       }
787     }
788
789     if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
790       return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType,
791                                                                     aServerLib,
792                                                                     aMeshVar,
793                                                                     aGeomVar );
794   }
795   return SMESH::SMESH_Hypothesis::_nil();
796 }
797
798 //================================================================================
799 /*!
800  * \Brief Returns tab dimention  
801   * \param tab - the tab in the dlg
802   * \param dlg - my dialogue
803   * \retval int - dimention
804  */
805 //================================================================================
806
807 static int getTabDim (const QObject* tab, SMESHGUI_MeshDlg* dlg )
808 {
809   int aDim = -1;
810   for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
811     if (tab == dlg->tab(i))
812       aDim = i;
813   return aDim;
814 }
815
816 //================================================================================
817 /*!
818  * \brief Create hypothesis
819   * \param theHypType - hypothesis category (main or additional)
820   * \param theIndex - index of type of hypothesis to be cerated
821  *
822  * Specifies dimension of hypothesis to be created (using sender() method),
823  * specifies its type and calls method for hypothesis creation
824  */
825 //================================================================================
826 void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
827 {
828   // Specifies dimension of hypothesis to be created
829   int aDim = getTabDim( sender(), myDlg );
830   if (aDim == -1)
831     return;
832
833   // Specifies type of hypothesis to be created
834   THypDataList& dataList = myAvailableHypData[ aDim ][ theHypType ];
835   if (theIndex < 0 || theIndex >= dataList.count())
836     return;
837   QString aHypTypeName = dataList[ theIndex ]->TypeName;
838
839   // Create hypothesis
840   createHypothesis(aDim, theHypType, aHypTypeName);
841 }
842
843 //================================================================================
844 /*!
845  *  Create hypothesis and update dialog.
846  *  \param theDim - dimension of hypothesis to be created
847  *  \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
848  *  \param theTypeName - specifies hypothesis to be created
849  */
850 //================================================================================
851 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
852                                         const int theType,
853                                         const QString& theTypeName)
854 {
855   HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
856   if (!aData)
857     return;
858
859   // existing hypos
860   int nbHyp = myExistingHyps[theDim][theType].count();
861
862   QString aClientLibName = aData->ClientLibName;
863   if (aClientLibName == "") {
864     // Call hypothesis creation server method (without GUI)
865     SMESH::CreateHypothesis(theTypeName, aData->Label, false);
866   } else {
867     // Get hypotheses creator client (GUI)
868     SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
869
870     // Create hypothesis
871     if (aCreator) {
872       // When create or edit a submesh, try to initialize a new hypothesis
873       // with values used to mesh a subshape
874       SMESH::SMESH_Hypothesis_var initParamHyp =
875         getInitParamsHypothesis(theTypeName, aData->ServerLibName);
876       aCreator->create(initParamHyp, myDlg);
877     } else {
878       SMESH::CreateHypothesis(theTypeName, aData->Label, false);
879     }
880   }
881
882   _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
883
884   HypothesisData* algoData = hypData( theDim, Algo, currentHyp( theDim, Algo ));
885   QStringList aNewHyps;
886   existingHyps(theDim, theType, aFather, aNewHyps, myExistingHyps[theDim][theType], algoData);
887   if (aNewHyps.count() > nbHyp) {
888     for (int i = nbHyp; i < aNewHyps.count(); i++)
889       myDlg->tab(theDim)->addHyp(theType, aNewHyps[i]);
890   }
891 }
892
893 //================================================================================
894 /*!
895  * \brief Calls plugin methods for hypothesis editing
896   * \param theHypType - specifies whether main hypothesis or additional one
897   * is edited
898   * \param theIndex - index of existing hypothesis
899  *
900  * Calls plugin methods for hypothesis editing
901  */
902 //================================================================================
903 void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
904 {
905   // Speicfies dimension of hypothesis to be created
906   int aDim = getTabDim( sender(), myDlg );
907   if (aDim == -1)
908     return;
909
910   QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
911   if ( theIndex < 0 || theIndex >= aList.count() )
912     return;
913   SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex ];
914   if ( aHyp->_is_nil() )
915     return;
916
917   char* aTypeName = aHyp->GetName();
918   SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
919   if ( aCreator )
920     aCreator->edit( aHyp.in(), dlg() );
921 }
922
923 //================================================================================
924 /*!
925  * \brief access to hypothesis data 
926   * \param theDim - hyp dimension
927   * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
928   * \param theIndex - index in the list
929   * \retval HypothesisData* - result data, may be 0
930  */
931 //================================================================================
932
933 HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
934                                           const int theHypType,
935                                           const int theIndex)
936 {
937   if ( theDim     > -1 && theDim     < 3 &&
938        theHypType > -1 && theHypType < NbHypTypes &&
939        theIndex   > -1 && theIndex   < myAvailableHypData[ theDim ][ theHypType ].count() )
940     return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
941   return 0;
942 }
943
944 //================================================================================
945 /*!
946  * \brief Set available algos and hypos according to the selected algorithm
947   * \param theIndex - algorithm index
948  */
949 //================================================================================
950
951 void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
952                                       const int theDim )
953 {
954   if ( myIgnoreAlgoSelection )
955     return;
956
957   int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
958   if (aDim == -1)
959     return;
960
961   // find highest available dimension, all algos of this dimension are available for choice
962   int aTopDim = -1;
963   for (int i = SMESH::DIM_1D; i <= SMESH::DIM_3D; i++)
964     if (isAccessibleDim( i ))
965       aTopDim = i;
966   if (aTopDim == -1)
967     return;
968
969   const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
970
971   HypothesisData* algoData = hypData( aDim, Algo, theIndex );
972   HypothesisData* algoByDim[3];
973   algoByDim[ aDim ] = algoData;
974
975   QStringList anAvailable;
976   if ( !algoData ) { // all algos becomes available
977     availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
978     myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
979   }
980
981   // check that algorithms of other dimentions are compatible with
982   // the selected one
983
984    // 2 loops: backward and forward from algo dimension
985   for ( int forward = false; forward <= true; ++forward )
986   {
987     int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
988     if ( !forward ) {
989       dim = aDim - 1; lastDim = SMESH::DIM_1D; dir = -1;
990     }
991     HypothesisData* prevAlgo = algoData;
992     bool noCompatible = false;
993     for ( ; dim * dir <= lastDim * dir ; dim += dir )
994     {
995       if ( !isAccessibleDim( dim ))
996         continue;
997       if ( noCompatible ) { // the selected algo has no compatible ones
998         anAvailable.clear();
999         myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1000         myAvailableHypData[dim][Algo].clear();
1001         algoByDim[ dim ] = 0;
1002         continue;
1003       }
1004       // get currently selected algo
1005       int algoIndex = currentHyp( dim, Algo );
1006       HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
1007       if ( curAlgo ) { // some algo selected
1008         if ( !isCompatible( prevAlgo, curAlgo, Algo ))
1009           curAlgo = 0;
1010       }
1011       // set new available algoritms
1012       availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
1013       HypothesisData* soleCompatible = 0;
1014       if ( anAvailable.count() == 1 )
1015         soleCompatible = myAvailableHypData[dim][Algo][0];
1016       if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
1017         availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
1018       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
1019       noCompatible = anAvailable.isEmpty();
1020
1021       // restore previously selected algo
1022       algoIndex = myAvailableHypData[dim][Algo].findIndex( curAlgo );
1023       if ( !isSubmesh && algoIndex < 0 && soleCompatible )
1024         // select the sole compatible algo
1025         algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
1026       setCurrentHyp( dim, Algo, algoIndex );
1027
1028       // remember current algo
1029       prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
1030     }
1031   }
1032
1033   // set hypotheses corresponding to the found algoritms
1034
1035   _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1036
1037   for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1038   {
1039     if ( !isAccessibleDim( dim ))
1040       continue;
1041     for ( int type = MainHyp; type < NbHypTypes; type++ )
1042     {
1043       myAvailableHypData[ dim ][ type ].clear();
1044       QStringList anAvailable, anExisting;
1045
1046       HypothesisData* curAlgo = algoByDim[ dim ];
1047       int hypIndex = currentHyp( dim, type );
1048
1049       SMESH::SMESH_Hypothesis_var curHyp;
1050       if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
1051         curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
1052
1053       if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
1054         // try to find algo by selected hypothesis in order to keep it selected
1055         bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
1056         QString curHypType = curHyp->GetName();
1057         if ( !algoDeselectedByUser &&
1058              myObjHyps[ dim ][ type ].count() > 0 &&
1059              curHypType == myObjHyps[ dim ][ type ][ 0 ]->GetName())
1060         {
1061           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1062           for ( int i = 0 ; i < myAvailableHypData[ dim ][ Algo ].count(); ++i ) {
1063             curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
1064             if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
1065               break;
1066             else
1067               curAlgo = 0;
1068           }
1069         }
1070       }
1071       // get hyps compatible with curAlgo
1072       if ( curAlgo )
1073       {
1074         // check if a selected hyp is compatible with the curAlgo
1075         if ( !curHyp->_is_nil() ) {
1076           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
1077           if ( !isCompatible( curAlgo, hypData, type ))
1078             curHyp = SMESH::SMESH_Hypothesis::_nil();
1079         }
1080         existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
1081         availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
1082       }
1083       // set list of hypotheses
1084       myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
1085       myDlg->tab( dim )->setExistingHyps( type, anExisting );
1086
1087       // set current existing hypothesis
1088       if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
1089         hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
1090       else
1091         hypIndex = -1;
1092       if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
1093         // none is yet selected => select the sole existing if it is not optional
1094         QString hypTypeName = myExistingHyps[ dim ][ type ][ 0 ]->GetName();
1095         bool isOptional = true;
1096         if ( algoByDim[ dim ] &&
1097              SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
1098              !isOptional )
1099           hypIndex = 0;
1100       }
1101       setCurrentHyp( dim, type, hypIndex );
1102     }
1103   }
1104 }
1105
1106 //================================================================================
1107 /*!
1108  * \brief Creates and selects hypothesis of hypotheses set 
1109  * \param theSetName - The name of hypotheses set
1110  */
1111 //================================================================================
1112 void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
1113 {
1114   HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
1115   if (!aHypoSet) return;
1116
1117   for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
1118     bool isAlgo = (aHypType == Algo);
1119
1120     // clear all hyps
1121     for (int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++)
1122       setCurrentHyp(dim, aHypType, -1);
1123
1124     // set hyps from the set
1125     QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
1126     for (int i = 0, n = aHypoList->count(); i < n; i++) {
1127       const QString& aHypoTypeName = (*aHypoList)[ i ];
1128       HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
1129       if (!aHypData)
1130         continue;
1131
1132       int aDim = aHypData->Dim[0];
1133       // create or/and set
1134       if (isAlgo) {
1135         QStringList tmp;
1136         availableHyps( aDim, Algo, tmp, myAvailableHypData[aDim][Algo] );
1137         int index = myAvailableHypData[aDim][Algo].findIndex( aHypData );
1138         setCurrentHyp( aDim, Algo, index );
1139         onAlgoSelected( index, aDim );
1140       }
1141       else {
1142         bool mainHyp = true;
1143         int index = myAvailableHypData[aDim][MainHyp].findIndex( aHypData );
1144         if ( index < 0 ) {
1145           mainHyp = false;
1146           index = myAvailableHypData[aDim][AddHyp].findIndex( aHypData );
1147         }
1148         if (index >= 0)
1149           createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
1150       }
1151     } // loop on hypos in the set
1152   } // loop on algo/hypo
1153 }
1154
1155 //================================================================================
1156 /*!
1157  * \brief Creates mesh
1158   * \param theMess - Output parameter intended for returning error message
1159   * \retval bool  - TRUE if mesh is created, FALSE otherwise
1160  *
1161  * Creates mesh
1162  */
1163 //================================================================================
1164 bool SMESHGUI_MeshOp::createMesh( QString& theMess )
1165 {
1166   theMess = "";
1167
1168   QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1169   _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1170   GEOM::GEOM_Object_var aGeomVar =
1171     GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1172
1173   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1174   if ( aSMESHGen->_is_nil() )
1175     return false;
1176
1177   SUIT_OverrideCursor aWaitCursor;
1178
1179   // create mesh
1180   SMESH::SMESH_Mesh_var aMeshVar = aSMESHGen->CreateMesh( aGeomVar );
1181   if ( aMeshVar->_is_nil() )
1182     return false;
1183   _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
1184   if ( aMeshSO )
1185     SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1186
1187   for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1188   {
1189     if ( !isAccessibleDim( aDim )) continue;
1190
1191     // assign hypotheses
1192     for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1193     {
1194       int aHypIndex = currentHyp( aDim, aHypType );
1195       if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1196       {
1197         SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1198         if ( !aHypVar->_is_nil() )
1199           SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
1200       }
1201     }
1202     // find or create algorithm
1203     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1204     if ( !anAlgoVar->_is_nil() )
1205       SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1206   }
1207   return true;
1208 }
1209
1210 //================================================================================
1211 /*!
1212  * \brief Creates sub-mesh
1213   * \param theMess - Output parameter intended for returning error message
1214   * \retval bool  - TRUE if sub-mesh is created, FALSE otherwise
1215  *
1216  * Creates sub-mesh
1217  */
1218 //================================================================================
1219 bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
1220 {
1221   theMess = "";
1222
1223   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1224   if ( aSMESHGen->_is_nil() )
1225     return false;
1226
1227   // get mesh object
1228   QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1229   _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
1230   SMESH::SMESH_Mesh_var aMeshVar =
1231     SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1232
1233   // get geom object
1234   QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
1235   _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
1236   GEOM::GEOM_Object_var aGeomVar =
1237     GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
1238
1239   SUIT_OverrideCursor aWaitCursor;
1240
1241   // create sub-mesh
1242   QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
1243   SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
1244
1245   for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
1246   {
1247     if ( !isAccessibleDim( aDim )) continue;
1248
1249     // find or create algorithm
1250     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
1251     if ( !anAlgoVar->_is_nil() )
1252       SMESH::AddHypothesisOnSubMesh( aSubMeshVar, anAlgoVar );
1253     // assign hypotheses
1254     for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
1255     {
1256       int aHypIndex = currentHyp( aDim, aHypType );
1257       if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
1258       {
1259         SMESH::SMESH_Hypothesis_var aHypVar =
1260           myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
1261         if ( !aHypVar->_is_nil() )
1262           SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
1263       }
1264     }
1265   }
1266
1267   // deselect geometry: next submesh sould be created on other subshape
1268   myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
1269   selectObject( _PTR(SObject)() );
1270   selectionDone();
1271
1272   return true;
1273 }
1274
1275 //================================================================================
1276 /*!
1277  * \brief Gets current hypothesis or algorithms
1278   * \param theDim - dimension of hypothesis or algorithm
1279   * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1280   * \retval int - current hypothesis or algorithms
1281  *
1282  * Gets current hypothesis or algorithms
1283  */
1284 //================================================================================
1285 int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
1286 {
1287   return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
1288 }
1289
1290 //================================================================================
1291 /*!
1292  * \brief Returns true if hypotheses of given dim can be assigned
1293   * \param theDim - hypotheses dimension
1294   * \retval bool - result
1295  */
1296 //================================================================================
1297 bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim ) const
1298 {
1299   return myDlg->tab( theDim )->isEnabled();
1300 }
1301
1302 //================================================================================
1303 /*!
1304  * \brief Sets current hypothesis or algorithms
1305   * \param theDim - dimension of hypothesis or algorithm
1306   * \param theHypType - Type of hypothesis (Algo, MainHyp, AddHyp)
1307   * \param theIndex - Index of hypothesis
1308  *
1309  * Gets current hypothesis or algorithms
1310  */
1311 //================================================================================
1312 void SMESHGUI_MeshOp::setCurrentHyp( const int theDim,
1313                                      const int theHypType,
1314                                      const int theIndex )
1315 {
1316   myIgnoreAlgoSelection = true;
1317   myDlg->tab( theDim )->setCurrentHyp( theHypType, theIndex + 1 );
1318   myIgnoreAlgoSelection = false;
1319 }
1320
1321 //================================================================================
1322 /*!
1323  * \brief Generates default and sets mesh/submesh name
1324  *
1325  * Generates and sets default mesh/submesh name(Mesh_1, Mesh_2, etc.)
1326  */
1327 //================================================================================
1328 void SMESHGUI_MeshOp::setDefaultName() const
1329 {
1330   QString aResName;
1331
1332   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1333   int i = 1;
1334   QString aPrefix = tr( myIsMesh ? "SMESH_OBJECT_MESH" : "SMESH_SUBMESH" ) + "_";
1335   _PTR(SObject) anObj;
1336   do
1337   {
1338     aResName = aPrefix + QString::number( i++ );
1339     anObj = aStudy->FindObject( aResName.latin1() );
1340   }
1341   while ( anObj );
1342
1343   QLineEdit* aControl = ( QLineEdit* )myDlg->objectWg(
1344     SMESHGUI_MeshDlg::Obj, SMESHGUI_MeshDlg::Control );
1345   aControl->setText( aResName );
1346 }
1347
1348 //================================================================================
1349 /*!
1350  * \brief Gets algorithm or creates it if necessary
1351   * \param theDim - specifies dimension of returned hypotheses/algorifms
1352   * \retval SMESH::SMESH_Hypothesis_var - algorithm
1353  *
1354  * Gets algorithm or creates it if necessary
1355  */
1356 //================================================================================
1357 SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
1358 {
1359   SMESH::SMESH_Hypothesis_var anAlgoVar;
1360
1361   // get type of the selected algo
1362   int aHypIndex = currentHyp( theDim, Algo );
1363   THypDataList& dataList = myAvailableHypData[ theDim ][ Algo ];
1364   if ( aHypIndex < 0 || aHypIndex >= dataList.count())
1365     return anAlgoVar;
1366   QString aHypName = dataList[ aHypIndex ]->TypeName;
1367
1368   // get existing algoritms
1369   _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
1370   QStringList tmp;
1371   existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
1372
1373   // look for anexisting algo of such a type
1374   QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
1375   QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
1376   for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
1377   {
1378     SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1379     if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1380     {
1381       anAlgoVar = aHypVar;
1382       break;
1383     }
1384   }
1385
1386   if (anAlgoVar->_is_nil()) {
1387     HypothesisData* aHypData = SMESH::GetHypothesisData( aHypName );
1388     if (aHypData) {
1389       QString aClientLibName = aHypData->ClientLibName;
1390       if (aClientLibName == "") {
1391         // Call hypothesis creation server method (without GUI)
1392         SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1393       } else {
1394         // Get hypotheses creator client (GUI)
1395         SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
1396
1397         // Create algorithm
1398         if (aCreator)
1399           aCreator->create(true, myDlg);
1400         else
1401           SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
1402       }
1403       QStringList tmpList;
1404       _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
1405       existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
1406     }
1407
1408     QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
1409     for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
1410     {
1411       SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
1412       if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
1413       {
1414         anAlgoVar = aHypVar;
1415         break;
1416       }
1417     }
1418   }
1419
1420   return anAlgoVar._retn();
1421 }
1422
1423 //================================================================================
1424 /*!
1425  * \brief Reads parameters of edited mesh and assigns them to the dialog
1426  *
1427  * Reads parameters of edited mesh and assigns them to the dialog (called when
1428  * mesh is edited only)
1429  */
1430 //================================================================================
1431 void SMESHGUI_MeshOp::readMesh()
1432 {
1433   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1434   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1435   if ( !pObj )
1436     return;
1437
1438   // Get name of mesh if current object is sub-mesh
1439   SMESH::SMESH_subMesh_var aSubMeshVar =
1440       SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
1441   if ( !aSubMeshVar->_is_nil() )
1442   {
1443     SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
1444     if ( !aMeshVar->_is_nil() )
1445     {
1446       _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
1447       QString aMeshName = name( aMeshSO );
1448       myDlg->setObjectText( SMESHGUI_MeshDlg::Mesh, aMeshName );
1449     }
1450   }
1451
1452   // Get name of geometry object
1453   GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
1454   if ( !aGeomVar->_is_nil() )
1455   {
1456     _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
1457     QString aShapeName = name( aGeomSO );
1458     myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
1459   }
1460
1461   // Get hypotheses and algorithms assigned to the mesh/sub-mesh
1462   QStringList anExisting;
1463   for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1464   {
1465     // get algorithm
1466     existingHyps( dim, Algo, pObj, anExisting, myObjHyps[ dim ][ Algo ] );
1467     // find algo index among available ones
1468     int aHypIndex = -1;
1469     if ( myObjHyps[ dim ][ Algo ].count() > 0 )
1470     {
1471       SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
1472       QString aHypTypeName = aVar->GetName();
1473       HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
1474       aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
1475 //       if ( aHypIndex < 0 && algoData ) {
1476 //         // assigned algo is incompatible with other algorithms
1477 //         myAvailableHypData[ dim ][ Algo ].push_back( algoData );
1478 //         aHypIndex = myAvailableHypData[ dim ][ hypType ].count() - 1;
1479 //       }
1480     }
1481     setCurrentHyp( dim, Algo, aHypIndex );
1482     // set existing and available hypothesis according to the selected algo
1483     onAlgoSelected( aHypIndex, dim );
1484   }
1485
1486   // get hypotheses
1487   bool hypWithoutAlgo = false;
1488   for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1489   {
1490     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1491     {
1492       // get hypotheses
1493       existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1494       // find index of requered hypothesis among existing ones for this dimension and type
1495       int aHypIndex = -1;
1496       if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
1497         aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1498                           myExistingHyps[ dim ][ hypType ] );
1499         if ( aHypIndex < 0 ) {
1500           // assigned hypothesis is incompatible with the algorithm
1501           if ( currentHyp( dim, Algo ) < 0 )
1502           { // none algo selected; it is edition for sure, of submesh maybe
1503             hypWithoutAlgo = true;
1504             myExistingHyps[ dim ][ hypType ].push_back( myObjHyps[ dim ][ hypType ].first() );
1505             aHypIndex = myExistingHyps[ dim ][ hypType ].count() - 1;
1506             myDlg->tab( dim )->setExistingHyps( hypType, anExisting );
1507           }
1508         }
1509       }
1510       setCurrentHyp( dim, hypType, aHypIndex );
1511     }
1512   }
1513   // make available other hyps of same type as one without algo
1514   if ( hypWithoutAlgo )
1515     onAlgoSelected( currentHyp( 0, Algo ), 0 );
1516 }
1517
1518 //================================================================================
1519 /*!
1520  * \brief Gets name of object
1521   * \param theSO - SObject
1522   * \retval QString - name of object
1523  *
1524  * Gets name of object
1525  */
1526 //================================================================================
1527 QString SMESHGUI_MeshOp::name( _PTR(SObject) theSO ) const
1528 {
1529   QString aResName;
1530   if ( theSO )
1531   {
1532     _PTR(GenericAttribute) anAttr;
1533     _PTR(AttributeName)    aNameAttr;
1534     if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
1535     {
1536       aNameAttr = anAttr;
1537       aResName = aNameAttr->Value().c_str();
1538     }
1539   }
1540   return aResName;
1541 }
1542
1543 //================================================================================
1544 /*!
1545  * \brief Finds hypothesis in input list
1546   * \param theHyp - hypothesis to be found
1547   * \param theHypList - input list of hypotheses
1548   * \retval int - index of hypothesis or -1 if it is not found
1549  *
1550  * Finds position of hypothesis in input list
1551  */
1552 //================================================================================
1553 int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
1554                            const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
1555 {
1556   int aRes = -1;
1557   if ( !theHyp->_is_nil() )
1558   {
1559     int i = 0;
1560     QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
1561     for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
1562     {
1563       if ( theHyp->_is_equivalent( *anIter ) )
1564       {
1565         aRes = i;
1566         break;
1567       }
1568       i++;
1569     }
1570   }
1571   return aRes;
1572 }
1573
1574 //================================================================================
1575 /*!
1576  * \brief Edits mesh or sub-mesh
1577   * \param theMess - Output parameter intended for returning error message
1578   * \retval bool  - TRUE if mesh is edited succesfully, FALSE otherwise
1579  *
1580  * Assigns new name hypotheses and algoriths to the mesh or sub-mesh
1581  */
1582 //================================================================================
1583 bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
1584 {
1585   theMess = "";
1586
1587   SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1588   if ( aSMESHGen->_is_nil() )
1589     return false;
1590
1591   QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
1592   _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
1593   if ( !pObj )
1594     return false;
1595
1596   SUIT_OverrideCursor aWaitCursor;
1597
1598   // Set new name
1599   SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
1600
1601   // Assign new hypotheses and algorithms
1602   for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1603   {
1604     if ( !isAccessibleDim( dim )) continue;
1605
1606     // find or create algorithm
1607     bool toDelete = false, toAdd = true;
1608     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
1609     if ( anAlgoVar->_is_nil() ) {
1610       toAdd = false;
1611     }
1612     if ( myObjHyps[ dim ][ Algo ].count() > 0 ) {
1613       SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
1614       if ( toAdd ) {
1615         if ( strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) == 0 ) {
1616           toAdd = false;
1617         } else {
1618           toDelete = true;
1619         }
1620       } else {
1621         toDelete = true;
1622       }
1623     }
1624     // remove old algorithm
1625     if ( toDelete ) {
1626       SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first() );
1627       myObjHyps[ dim ][ Algo ].clear();
1628     }
1629
1630     // assign new algorithm
1631     if ( toAdd ) {
1632       SMESH::SMESH_Mesh_var aMeshVar =
1633         SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1634       bool isMesh = !aMeshVar->_is_nil();
1635       if ( isMesh ) {
1636         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
1637       } else {
1638         SMESH::SMESH_subMesh_var aVar =
1639           SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1640         if ( !aVar->_is_nil() )
1641           SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
1642       }
1643       myObjHyps[ dim ][ Algo ].append( anAlgoVar );
1644     }
1645
1646     // assign hypotheses
1647     for ( int hypType = MainHyp; hypType <= AddHyp; hypType++ )
1648     {
1649       int aNewHypIndex = currentHyp( dim, hypType );
1650       int anOldHypIndex = -1;
1651       if ( myObjHyps[ dim ][ hypType ].count() > 0 )
1652         anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
1653                               myExistingHyps[ dim ][ hypType ] );
1654       if ( aNewHypIndex != anOldHypIndex )
1655       {
1656         // remove old hypotheses
1657         if ( anOldHypIndex >= 0 ) {
1658           SMESH::RemoveHypothesisOrAlgorithmOnMesh(
1659             pObj, myExistingHyps[ dim ][ hypType ][ anOldHypIndex ] );
1660           myObjHyps[ dim ][ hypType ].clear();
1661         }
1662
1663         // assign new hypotheses
1664         if ( aNewHypIndex != -1 )
1665         {
1666           SMESH::SMESH_Mesh_var aMeshVar =
1667               SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1668           bool isMesh = !aMeshVar->_is_nil();
1669           if ( isMesh )
1670           {
1671             SMESH::AddHypothesisOnMesh(
1672               aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1673           }
1674           else
1675           {
1676             SMESH::SMESH_subMesh_var aVar =
1677               SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
1678             if ( !aVar->_is_nil() )
1679               SMESH::AddHypothesisOnSubMesh(
1680                 aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
1681           }
1682         }
1683         // reread all hypotheses of mesh if necessary
1684         QStringList anExisting;
1685         existingHyps( dim, hypType, pObj, anExisting, myObjHyps[ dim ][ hypType ] );
1686       }
1687     }
1688   }
1689
1690   return true;
1691 }
1692
1693 //================================================================================
1694 /*!
1695  * \brief Verifies whether given operator is valid for this one
1696   * \param theOtherOp - other operation
1697   * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
1698 *
1699 * method redefined from base class verifies whether given operator is valid for
1700 * this one (i.e. can be started "above" this operator). In current implementation method
1701 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
1702 * elements.
1703 */
1704 //================================================================================
1705 bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const
1706 {
1707   return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" );
1708 }
1709
1710 //================================================================================
1711 /*!
1712  * \brief SLOT. Is called when the user selects a way of geometry selection
1713   * \param theByMesh - true if the user wants to find geometry by mesh element
1714  */
1715 //================================================================================
1716
1717 void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
1718 {
1719   if ( theByMesh ) {
1720     if ( !myShapeByMeshOp ) {
1721       myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
1722       connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1723               SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1724       connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1725               SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1726     }
1727     // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1728     QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
1729     if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
1730       SMESH::SMESH_Mesh_var aMeshVar =
1731         SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
1732       if ( !aMeshVar->_is_nil() ) {
1733         myDlg->hide(); // stop processing selection
1734         myShapeByMeshOp->setModule( getSMESHGUI() );
1735         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1736         myShapeByMeshOp->SetMesh( aMeshVar );
1737         myShapeByMeshOp->start();
1738       }
1739     }
1740   }
1741 }
1742
1743 //================================================================================
1744 /*!
1745  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1746  */
1747 //================================================================================
1748
1749 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
1750 {
1751   if ( myShapeByMeshOp == op ) {
1752     myDlg->show();
1753     // Select a found geometry object
1754     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1755     if ( !aGeomVar->_is_nil() )
1756     {
1757       QString ID = aGeomVar->GetStudyEntry();
1758       if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.latin1() )) {
1759         selectObject( aGeomSO );
1760         selectionDone();
1761       }
1762     }
1763   }
1764 }
1765
1766 //================================================================================
1767 /*!
1768  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1769  */
1770 //================================================================================
1771
1772 void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
1773 {
1774   if ( myShapeByMeshOp == op && myDlg ) {
1775     myDlg->show();
1776   }
1777 }
1778
1779 //================================================================================
1780 /*!
1781  * \brief Selects a SObject
1782   * \param theSObj - the SObject to select
1783  */
1784 //================================================================================
1785
1786 void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
1787 {
1788   if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
1789     SALOME_ListIO anIOList;
1790     if ( theSObj ) {
1791       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1792         ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
1793       anIOList.Append( anIO );
1794     }
1795     sm->setSelectedObjects( anIOList, false );
1796   }
1797 }