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