Salome HOME
32107f1f87094a042c529397b3d2e273fdeb4d46
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_EditHypothesesDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_EditHypothesesDlg.cxx
3 //  Created   : Fri Aug 02 09:14:56 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11 #include "SMESHGUI_EditHypothesesDlg.h"
12 #include "SMESHGUI.h"
13 #include "SALOME_ListIteratorOfListIO.hxx"
14
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "utilities.h"
18
19 // QT Includes
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
22 #include <qlabel.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
26 #include <qlayout.h>
27 #include <qvariant.h>
28 #include <qtooltip.h>
29 #include <qwhatsthis.h>
30 #include <qimage.h>
31 #include <qpixmap.h>
32
33 //VRV: porting on Qt 3.0.5
34 #if QT_VERSION >= 0x030005
35 #include <qlistbox.h>
36 #endif
37 //VRV: porting on Qt 3.0.5
38
39 //=================================================================================
40 // class    : SMESHGUI_EditHypothesesDlg()
41 // purpose  : Constructs a SMESHGUI_EditHypothesesDlg which is a child of 'parent', with the 
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 SMESHGUI_EditHypothesesDlg::SMESHGUI_EditHypothesesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
47     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
48 {
49     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_EDIT_MESH")));
50     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
51     if ( !name )
52         setName( "SMESHGUI_EditHypothesesDlg" );
53     resize( 417, 573 ); 
54     setCaption( tr( "SMESH_EDIT_HYPOTHESES"  ) );
55     setSizeGripEnabled( TRUE );
56     SMESHGUI_EditHypothesesDlgLayout = new QGridLayout( this ); 
57     SMESHGUI_EditHypothesesDlgLayout->setSpacing( 6 );
58     SMESHGUI_EditHypothesesDlgLayout->setMargin( 11 );
59
60     /***************************************************************/
61     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
62     GroupConstructors->setTitle( tr( "SMESH_HYPOTHESES"  ) );
63     GroupConstructors->setExclusive( TRUE );
64     GroupConstructors->setColumnLayout(0, Qt::Vertical );
65     GroupConstructors->layout()->setSpacing( 0 );
66     GroupConstructors->layout()->setMargin( 0 );
67     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
68     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
69     GroupConstructorsLayout->setSpacing( 6 );
70     GroupConstructorsLayout->setMargin( 11 );
71     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
72     Constructor1->setText( tr( ""  ) );
73     Constructor1->setPixmap( image1 );
74     Constructor1->setChecked( TRUE );
75     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
76     Constructor1->setMinimumSize( QSize( 50, 0 ) );
77     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
78     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
79     GroupConstructorsLayout->addItem( spacer, 0, 1 );
80     SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupConstructors, 0, 0 );
81     
82     /***************************************************************/
83     GroupButtons = new QGroupBox( this, "GroupButtons" );
84     GroupButtons->setGeometry( QRect( 10, 10, 281, 96 ) ); 
85     GroupButtons->setTitle( tr( ""  ) );
86     GroupButtons->setColumnLayout(0, Qt::Vertical );
87     GroupButtons->layout()->setSpacing( 0 );
88     GroupButtons->layout()->setMargin( 0 );
89     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
90     GroupButtonsLayout->setAlignment( Qt::AlignTop );
91     GroupButtonsLayout->setSpacing( 6 );
92     GroupButtonsLayout->setMargin( 11 );
93     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
94     buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
95     buttonCancel->setAutoDefault( TRUE );
96     buttonCancel->setDefault( TRUE );
97     buttonCancel->setEnabled( TRUE ) ;
98     
99     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
100     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
101     buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
102     buttonApply->setAutoDefault( TRUE );
103     buttonApply->setDefault( FALSE );
104     buttonApply->setEnabled( FALSE ) ;
105     
106     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
107     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
108     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
109     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
110     buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
111     
112     buttonOk->setAutoDefault( TRUE );
113     buttonOk->setDefault( FALSE );
114     buttonOk->setEnabled( FALSE ) ;
115     
116     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
117     SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupButtons, 5, 0 );
118
119     /***************************************************************/
120     GroupC1 = new QGroupBox( this, "GroupC1" );
121     GroupC1->setTitle( tr( "SMESH_ARGUMENTS"  ) );
122     GroupC1->setMinimumSize( QSize( 0, 0 ) );
123     GroupC1->setFrameShape( QGroupBox::Box );
124     GroupC1->setFrameShadow( QGroupBox::Sunken );
125     GroupC1->setColumnLayout(0, Qt::Vertical );
126     GroupC1->layout()->setSpacing( 0 );
127     GroupC1->layout()->setMargin( 0 );
128     GroupC1Layout = new QGridLayout( GroupC1->layout() );
129     GroupC1Layout->setAlignment( Qt::AlignTop );
130     GroupC1Layout->setSpacing( 6 );
131     GroupC1Layout->setMargin( 11 );
132
133     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
134     TextLabelC1A1->setText( tr( "SMESH_OBJECT_MESHorSUBMESH"  ) );
135     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
136     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
137     TextLabelC1A1->setFrameShadow( QLabel::Plain );
138     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
139     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
140     SelectButtonC1A1->setText( tr( ""  ) );
141     SelectButtonC1A1->setPixmap( image0 );
142     SelectButtonC1A1->setToggleButton( FALSE );
143     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
144     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
145     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
146
147     TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
148     TextLabelC1A2->setText( tr( "SMESH_OBJECT_GEOM"  ) );
149     TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
150     TextLabelC1A2->setFrameShape( QLabel::NoFrame );
151     TextLabelC1A2->setFrameShadow( QLabel::Plain );
152     GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
153     SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
154     SelectButtonC1A2->setText( tr( ""  ) );
155     SelectButtonC1A2->setPixmap( image0 );
156     SelectButtonC1A2->setToggleButton( FALSE );
157     GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
158     LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
159     GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
160
161     GroupHypotheses = new QGroupBox( this, "GroupHypotheses" );
162     GroupHypotheses->setTitle( tr( "SMESH_HYPOTHESES"  ) );
163     GroupHypotheses->setColumnLayout(0, Qt::Vertical );
164     GroupHypotheses->layout()->setSpacing( 0 );
165     GroupHypotheses->layout()->setMargin( 0 );
166     grid_3 = new QGridLayout( GroupHypotheses->layout() );
167     grid_3->setGeometry( QRect( 12, 18, 139, 110 ) ); 
168     grid_3->setAlignment( Qt::AlignTop );
169     grid_3->setSpacing( 6 );
170     grid_3->setMargin( 11 );
171
172     hbox_2 = new QHBoxLayout; 
173     hbox_2->setSpacing( 6 );
174     hbox_2->setMargin( 0 );
175
176     vbox = new QVBoxLayout; 
177     vbox->setSpacing( 6 );
178     vbox->setMargin( 0 );
179
180     TextHypDefinition = new QLabel( GroupHypotheses, "TextHypDefinition" );
181     TextHypDefinition->setText( tr( "SMESH_AVAILABLE"  ) );
182     vbox->addWidget( TextHypDefinition );
183
184     ListHypDefinition = new QListBox( GroupHypotheses, "ListHypDefinition" );
185     ListHypDefinition->setMinimumSize( 100, 50);
186 //      ListHypDefinition->setRowMode(4);
187 //      ListHypDefinition->setRowMode( QListBox::FixedNumber );
188 //    ListHypDefinition->setLineWidth( 4 );
189 //      ListHypDefinition->setColumnMode( QListBox::Variable );
190 //      ListHypDefinition->setVariableHeight( FALSE );
191 //      ListHypDefinition->insertItem( tr( "New Item" ) );
192     vbox->addWidget( ListHypDefinition );
193     hbox_2->addLayout( vbox );
194
195     vbox_2 = new QVBoxLayout; 
196     vbox_2->setSpacing( 6 );
197     vbox_2->setMargin( 0 );
198
199     TextHypAssignation = new QLabel( GroupHypotheses, "TextHypAssignation" );
200     TextHypAssignation->setText( tr( "SMESH_EDIT_USED"  ) );
201     vbox_2->addWidget( TextHypAssignation );
202
203     ListHypAssignation = new QListBox( GroupHypotheses, "ListHypAssignation" );
204     ListHypAssignation->setMinimumSize( 100, 50);
205 //      ListHypAssignation->setRowMode(4); 
206 //      ListHypAssignation->setRowMode( QListBox::FixedNumber );
207 //    ListHypAssignation->setLineWidth( 4 );
208 //      ListHypAssignation->setColumnMode( QListBox::Variable );
209 //      ListHypAssignation->setVariableHeight( FALSE );
210 //      ListHypAssignation->insertItem( tr( "New Item" ) );
211     vbox_2->addWidget( ListHypAssignation );
212     hbox_2->addLayout( vbox_2 );
213
214     grid_3->addLayout( hbox_2, 0, 0 );
215
216     SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupHypotheses, 2, 0 );
217
218     GroupAlgorithms = new QGroupBox( this, "GroupAlgorithms" );
219     GroupAlgorithms->setTitle( tr( "SMESH_ADD_ALGORITHM"  ) );
220     GroupAlgorithms->setColumnLayout(0, Qt::Vertical );
221     GroupAlgorithms->layout()->setSpacing( 0 );
222     GroupAlgorithms->layout()->setMargin( 0 );
223     grid_4 = new QGridLayout( GroupAlgorithms->layout() );
224     grid_4->setGeometry( QRect( 12, 18, 139, 110 ) ); 
225     grid_4->setAlignment( Qt::AlignTop );
226     grid_4->setSpacing( 6 );
227     grid_4->setMargin( 11 );
228
229     hbox_3 = new QHBoxLayout; 
230     hbox_3->setSpacing( 6 );
231     hbox_3->setMargin( 0 );
232
233     vbox_3 = new QVBoxLayout; 
234     vbox_3->setSpacing( 6 );
235     vbox_3->setMargin( 0 );
236
237     TextAlgoDefinition = new QLabel( GroupAlgorithms, "TextAlgoDefinition" );
238     TextAlgoDefinition->setText( tr( "SMESH_AVAILABLE"  ) );
239     vbox_3->addWidget( TextAlgoDefinition );
240
241     ListAlgoDefinition = new QListBox( GroupAlgorithms, "ListAlgoDefinition" );
242     ListAlgoDefinition->setMinimumSize( 100, 50);
243 //      ListAlgoDefinition->setRowMode(4);
244 //      ListAlgoDefinition->setRowMode( QListBox::FixedNumber );
245 //    ListAlgoDefinition->setLineWidth( 4 );
246 //      ListAlgoDefinition->setColumnMode( QListBox::Variable );
247 //      ListAlgoDefinition->setVariableHeight( FALSE );
248 //      ListAlgoDefinition->insertItem( tr( "New Item" ) );
249     vbox_3->addWidget( ListAlgoDefinition );
250     hbox_3->addLayout( vbox_3 );
251
252     vbox_4 = new QVBoxLayout; 
253     vbox_4->setSpacing( 6 );
254     vbox_4->setMargin( 0 );
255
256     TextAlgoAssignation = new QLabel( GroupAlgorithms, "TextAlgoAssignation" );
257     TextAlgoAssignation->setText( tr( "SMESH_EDIT_USED"  ) );
258     vbox_4->addWidget( TextAlgoAssignation );
259
260     ListAlgoAssignation = new QListBox( GroupAlgorithms, "ListAlgoAssignation" );
261     ListAlgoAssignation ->setMinimumSize( 100, 50);
262 //      ListAlgoAssignation->setRowMode(4);
263 //      ListAlgoAssignation->setRowMode( QListBox::FixedNumber );
264 //    ListAlgoAssignation->setLineWidth( 4 );
265 //      ListAlgoAssignation->setColumnMode( QListBox::Variable );
266 //      ListAlgoAssignation->setVariableHeight( FALSE );
267 //      ListAlgoAssignation->insertItem( tr( "New Item" ) );
268     vbox_4->addWidget( ListAlgoAssignation );
269     hbox_3->addLayout( vbox_4 );
270
271     grid_4->addLayout( hbox_3, 0, 0 );
272     SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupAlgorithms, 3, 0 );
273
274     SMESHGUI_EditHypothesesDlgLayout->addWidget( GroupC1, 1, 0 );
275     /***************************************************************/
276
277     Init(Sel) ;
278
279 }
280
281
282 //=================================================================================
283 // function : ~SMESHGUI_EditHypothesesDlg()
284 // purpose  : Destroys the object and frees any allocated resources
285 //=================================================================================
286 SMESHGUI_EditHypothesesDlg::~SMESHGUI_EditHypothesesDlg()
287 {
288     // no need to delete child widgets, Qt does it all for us
289 }
290
291
292 //=================================================================================
293 // function : Init()
294 // purpose  :
295 //=================================================================================
296 void SMESHGUI_EditHypothesesDlg::Init( SALOME_Selection* Sel )
297 {
298   GroupC1->show();
299   myConstructorId = 0 ;
300   Constructor1->setChecked( TRUE );
301   myEditCurrentArgument = LineEditC1A1 ;        
302   mySelection = Sel;
303   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
304   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
305
306   InitHypDefinition();
307   InitAlgoDefinition();
308
309   InitHypAssignation();
310   InitAlgoAssignation();
311
312   myGeomFilter = new SALOME_TypeFilter( "GEOM" );
313   myMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
314
315   myGeomShape = GEOM::GEOM_Shape::_nil();
316   myMesh = SMESH::SMESH_Mesh::_nil();
317   mySubMesh = SMESH::SMESH_subMesh::_nil();
318
319   /* signals and slots connections */
320   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
321   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
322
323   connect( SelectButtonC1A1, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
324   connect( SelectButtonC1A2, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
325
326   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
327   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
328   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
329  
330   connect( ListHypAssignation, SIGNAL( clicked(QListBoxItem*) ), this, SLOT( removeItem(QListBoxItem*) ) );
331   connect( ListAlgoAssignation, SIGNAL( clicked(QListBoxItem*) ), this, SLOT( removeItem(QListBoxItem*) ) );
332  
333   connect( ListHypDefinition, SIGNAL( clicked(QListBoxItem*) ), this, SLOT( addItem(QListBoxItem*) ) );
334   connect( ListAlgoDefinition, SIGNAL( clicked(QListBoxItem*) ), this, SLOT( addItem(QListBoxItem*) ) );
335
336   int x, y ;
337   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
338   this->move( x, y ) ;
339   this->show() ; 
340   SelectionIntoArgument();
341
342   return ;
343 }
344
345
346 //=================================================================================
347 // function : ConstructorsClicked()
348 // purpose  : Radio button management
349 //=================================================================================
350 void SMESHGUI_EditHypothesesDlg::ConstructorsClicked(int constructorId)
351 {
352   return ;
353 }
354
355 //=================================================================================
356 // function : ClickOnCancel()
357 // purpose  :
358 //=================================================================================
359 void SMESHGUI_EditHypothesesDlg::ClickOnCancel()
360 {
361   disconnect( mySelection, 0, this, 0 );
362   mySMESHGUI->ResetState() ;
363   mySelection->ClearFilters() ;
364   reject() ;
365   return ;
366 }
367
368
369 //=================================================================================
370 // function : SelectionIntoArgument()
371 // purpose  : Called when selection as changed or other case
372 //=================================================================================
373 void SMESHGUI_EditHypothesesDlg::SelectionIntoArgument()
374 {
375   myEditCurrentArgument->setText("") ;
376   QString aString = ""; 
377
378   int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
379
380   switch (myConstructorId) 
381     {
382     case 0:
383       {
384         if ( myEditCurrentArgument == LineEditC1A1 ) {
385           if ( nbSel != 1 ) {
386             myOkHypothesis = false;
387             myOkAlgorithm = false;
388             myMesh = SMESH::SMESH_Mesh::_nil();
389             mySubMesh = SMESH::SMESH_subMesh::_nil();
390             InitHypAssignation();
391             InitAlgoAssignation();
392             InitGeom();
393             return ;
394           } else {
395             Standard_Boolean testResult ;
396             Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
397             myMesh = mySMESHGUI->ConvertIOinMesh(IO, testResult) ;
398             if( !testResult ) {
399               myMesh = SMESH::SMESH_Mesh::_nil();
400
401               mySubMesh = mySMESHGUI->ConvertIOinSubMesh(IO, testResult) ;
402               if( !testResult ) {
403                 mySubMesh = SMESH::SMESH_subMesh::_nil();
404                 InitHypAssignation();
405                 InitAlgoAssignation();
406                 InitGeom();
407                 return ;
408               }
409             }
410             InitHypAssignation();
411             InitAlgoAssignation();
412             InitGeom();
413           }
414         } else if ( myEditCurrentArgument == LineEditC1A2 ) {
415           if ( nbSel != 1 ) {
416             myOkHypothesis = false;
417             myOkAlgorithm = false;
418             myGeomShape = GEOM::GEOM_Shape::_nil();
419             InitHypAssignation();
420             InitAlgoAssignation();
421             InitGeom();
422             return ;
423           } else {
424             Standard_Boolean testResult ;
425             Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
426             myGeomShape = mySMESHGUI->ConvertIOinGEOMShape(IO, testResult) ;
427             if( !testResult ) {
428               myGeomShape = GEOM::GEOM_Shape::_nil();
429               InitHypAssignation();
430               InitAlgoAssignation();
431               InitGeom();
432               return ;
433             }
434             InitHypAssignation();
435             InitAlgoAssignation();
436             InitGeom();     
437           }
438         } 
439         break;
440       }
441     }
442   
443   myEditCurrentArgument->setText(aString) ;
444 }
445
446
447 //=================================================================================
448 // function : SetEditCurrentArgument()
449 // purpose  :
450 //=================================================================================
451 void SMESHGUI_EditHypothesesDlg::SetEditCurrentArgument()
452 {
453   QPushButton* send = (QPushButton*)sender();
454   switch (myConstructorId)
455     {
456     case 0: /* default constructor */
457       { 
458         if(send == SelectButtonC1A1) {
459           LineEditC1A1->setFocus() ;
460           myEditCurrentArgument = LineEditC1A1;
461           mySelection->ClearFilters() ;   
462           mySelection->AddFilter(myMeshOrSubMeshFilter) ;
463         } else if (send == SelectButtonC1A2) {
464           LineEditC1A2->setFocus() ;
465           myEditCurrentArgument = LineEditC1A2;
466           mySelection->ClearFilters() ;
467           mySelection->AddFilter(myGeomFilter) ;
468         } 
469         SelectionIntoArgument() ;
470         break;
471       }
472     }
473   return ;
474 }
475
476 //=================================================================================
477 // function : DeactivateActiveDialog()
478 // purpose  :
479 //=================================================================================
480 void SMESHGUI_EditHypothesesDlg::DeactivateActiveDialog()
481 {
482   if ( GroupConstructors->isEnabled() ) {
483     disconnect( mySelection, 0, this, 0 );
484     GroupConstructors->setEnabled(false) ;
485     GroupC1->setEnabled(false) ;
486     GroupButtons->setEnabled(false) ;
487   }
488 }
489
490
491 //=================================================================================
492 // function : ActivateThisDialog()
493 // purpose  :
494 //=================================================================================
495 void SMESHGUI_EditHypothesesDlg::ActivateThisDialog()
496 {
497   mySMESHGUI->EmitSignalDeactivateDialog() ;   
498   GroupConstructors->setEnabled(true) ;
499   GroupC1->setEnabled(true) ;
500   GroupButtons->setEnabled(true) ;
501   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
502   return ;
503 }
504
505
506 //=================================================================================
507 // function : enterEvent()
508 // purpose  :
509 //=================================================================================
510 void SMESHGUI_EditHypothesesDlg::enterEvent(QEvent* e)
511 {
512   if ( GroupConstructors->isEnabled() )
513     return ;  
514   ActivateThisDialog() ;
515   return ;
516 }
517
518
519 //=================================================================================
520 // function : closeEvent()
521 // purpose  :
522 //=================================================================================
523 void SMESHGUI_EditHypothesesDlg::closeEvent( QCloseEvent* e )
524 {
525   this->ClickOnCancel() ;
526   return ;
527 }
528
529 //=================================================================================
530 // function : TextChangedInLineEdit()
531 // purpose  :
532 //=================================================================================
533 void SMESHGUI_EditHypothesesDlg::TextChangedInLineEdit(const QString& newText)
534 {  
535   QLineEdit* send = (QLineEdit*)sender();
536   QString newT = strdup(newText) ;
537   
538   return ;
539 }
540
541 void SMESHGUI_EditHypothesesDlg::removeItem(QListBoxItem* i)
542 {
543   if (!i) return;
544
545   SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
546   int index = ListHypAssignation->index( i );
547   if ( index != -1 ) {
548     if (mapNameIOR.find( string(i->text()) ) != mapNameIOR.end()) {
549       SMESH::SMESH_Hypothesis_var Hyp = 
550         SMESH::SMESH_Hypothesis::_narrow( myStudyAPI.StringToIOR( mapNameIOR[ string(i->text()) ].c_str() ) );
551   
552       if ( !myMesh->_is_nil() ) {
553         SALOMEDS::SObject_var aMesh = myStudyAPI.FindMesh(myMesh);
554         mySMESHGUI->RemoveHypothesisOrAlgorithmOnMesh(aMesh, Hyp);
555         //      mySMESHGUI->GetStudyAPI().ModifiedMesh( aMesh, false );
556         mySMESHGUI->GetActiveStudy()->updateObjBrowser();
557       }
558       if ( !mySubMesh->_is_nil() ) {
559         SALOMEDS::SObject_var aSubMesh = myStudyAPI.FindSubMesh(mySubMesh);
560         mySMESHGUI->RemoveHypothesisOrAlgorithmOnMesh(aSubMesh, Hyp);
561         //      mySMESHGUI->GetStudyAPI().ModifiedMesh( aSubMesh, false );
562         mySMESHGUI->GetActiveStudy()->updateObjBrowser();
563       }
564       
565       ListHypAssignation->removeItem( index );
566     }
567     return;
568   } 
569   index = ListAlgoAssignation->index( i );
570   if ( index != -1 ) {
571     if (mapNameIOR.find( string(i->text()) ) != mapNameIOR.end()) {
572       SMESH::SMESH_Hypothesis_var Hyp = 
573         SMESH::SMESH_Hypothesis::_narrow( myStudyAPI.StringToIOR(mapNameIOR[ string(i->text()) ].c_str()) );
574       
575       if ( !myMesh->_is_nil() ) {
576         SALOMEDS::SObject_var aMesh = myStudyAPI.FindMesh(myMesh);
577         mySMESHGUI->RemoveHypothesisOrAlgorithmOnMesh(aMesh, Hyp);
578         //      mySMESHGUI->GetStudyAPI().ModifiedMesh( aMesh, false );
579         mySMESHGUI->GetActiveStudy()->updateObjBrowser();
580       }
581       if ( !mySubMesh->_is_nil() ) {
582         SALOMEDS::SObject_var aSubMesh = myStudyAPI.FindSubMesh(mySubMesh);
583         mySMESHGUI->RemoveHypothesisOrAlgorithmOnMesh(aSubMesh, Hyp);
584         //      mySMESHGUI->GetStudyAPI().ModifiedMesh( aSubMesh, false );
585         mySMESHGUI->GetActiveStudy()->updateObjBrowser();
586       }
587
588       ListAlgoAssignation->removeItem( index );
589     } 
590   }
591 }
592
593
594 //=================================================================================
595 // function : addItem()
596 // purpose  :
597 //=================================================================================
598 void SMESHGUI_EditHypothesesDlg::addItem(QListBoxItem* i)
599 {
600   if (!i) return;
601
602   SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
603   if ( ListHypDefinition->findItem( i->text() ) ) {
604     if ( !ListHypAssignation->findItem( i->text() ) ) {
605       ListHypAssignation->insertItem( i->text() );
606       
607       if (mapNameIOR.find( string(i->text()) ) != mapNameIOR.end()) {
608         SMESH::SMESH_Hypothesis_var Hyp = 
609           SMESH::SMESH_Hypothesis::_narrow( myStudyAPI.StringToIOR(mapNameIOR[ string(i->text()) ].c_str()) );
610       
611         if ( !myMesh->_is_nil() )
612           mySMESHGUI->AddHypothesisOnMesh(myMesh, Hyp);
613         if ( !mySubMesh->_is_nil() )
614           mySMESHGUI->AddHypothesisOnSubMesh(mySubMesh, Hyp);
615       }
616     }
617     return;
618   }
619   if ( ListAlgoDefinition->findItem( i->text() ) ) {
620     if ( !ListAlgoAssignation->findItem( i->text() ) ) {
621       ListAlgoAssignation->insertItem( i->text() );
622       
623       if (mapNameIOR.find( string(i->text()) ) != mapNameIOR.end()) {
624         SMESH::SMESH_Hypothesis_var Hyp = 
625           SMESH::SMESH_Hypothesis::_narrow( myStudyAPI.StringToIOR(mapNameIOR[ string(i->text()) ].c_str()) );
626       
627         if ( !myMesh->_is_nil() )
628           mySMESHGUI->AddAlgorithmOnMesh(myMesh, Hyp);
629         if ( !mySubMesh->_is_nil() )
630           mySMESHGUI->AddAlgorithmOnSubMesh(mySubMesh, Hyp);
631       }
632     }
633   }
634   mySMESHGUI->GetActiveStudy()->updateObjBrowser();
635 }
636
637
638 //=================================================================================
639 // function : InitHypDefinition()
640 // purpose  :
641 //=================================================================================
642 void SMESHGUI_EditHypothesesDlg::InitHypDefinition()
643 {
644   SALOMEDS::SComponent_var father = mySMESHGUI->GetStudy()->FindComponent("MESH");
645   SALOMEDS::SObject_var           HypothesisRoot;
646   SALOMEDS::GenericAttribute_var  anAttr;
647   SALOMEDS::AttributeName_var     aName;
648   SALOMEDS::AttributeIOR_var      anIOR;
649
650   int Tag_HypothesisRoot = 1;
651   if (father->FindSubObject (1, HypothesisRoot)) {
652     SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(HypothesisRoot);
653     for (; it->More();it->Next()) {
654       SALOMEDS::SObject_var Obj = it->Value();
655       if (Obj->FindAttribute(anAttr, "AttributeName") ) {
656         aName = SALOMEDS::AttributeName::_narrow(anAttr);
657         ListHypDefinition->insertItem(aName->Value());
658         
659         if (Obj->FindAttribute(anAttr, "AttributeIOR")) {
660           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
661           mapNameIOR[ aName->Value() ] = anIOR->Value();
662         }
663       }
664     }
665   }
666 }
667
668 //=================================================================================
669 // function : InitHypAssignation()
670 // purpose  :
671 //=================================================================================
672 void SMESHGUI_EditHypothesesDlg::InitHypAssignation()
673 {
674   MESSAGE ( " InitHypAssignation " << myMesh->_is_nil() )
675   MESSAGE ( " InitHypAssignation " << mySubMesh->_is_nil() )
676   ListHypAssignation->clear();
677   SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
678   int Tag_RefOnAppliedHypothesis = 2;
679   SALOMEDS::SObject_var             AHR, aRef;
680   SALOMEDS::GenericAttribute_var    anAttr;
681   SALOMEDS::AttributeName_var       aName;
682
683   if ( !myMesh->_is_nil() ) {
684     SALOMEDS::SObject_var aMesh = myStudyAPI.FindMesh( myMesh );
685     if ( aMesh->FindSubObject (2, AHR)) {
686       SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(AHR);
687       for (; it->More();it->Next()) {
688         SALOMEDS::SObject_var Obj = it->Value();
689         if ( Obj->ReferencedObject(aRef) ) {
690           if (aRef->FindAttribute(anAttr, "AttributeName") ) {
691               aName = SALOMEDS::AttributeName::_narrow(anAttr);
692             ListHypAssignation->insertItem(aName->Value());
693           }
694         }
695       }
696     }
697   }
698   if ( !mySubMesh->_is_nil() ) {
699     SALOMEDS::SObject_var aSubMesh = myStudyAPI.FindSubMesh( mySubMesh );
700     if ( aSubMesh->FindSubObject (2, AHR)) {
701       SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(AHR);
702       for (; it->More();it->Next()) {
703         SALOMEDS::SObject_var Obj = it->Value();
704         if ( Obj->ReferencedObject(aRef) ) {
705           if (aRef->FindAttribute(anAttr, "AttributeName") ) {
706             aName = SALOMEDS::AttributeName::_narrow(anAttr);
707             ListHypAssignation->insertItem(aName->Value());
708           }
709         }
710       }
711     }    
712   }
713 }
714
715 //=================================================================================
716 // function : InitAlgoDefinition()
717 // purpose  :
718 //=================================================================================
719 void SMESHGUI_EditHypothesesDlg::InitAlgoDefinition()
720 {
721   SALOMEDS::SComponent_var father = mySMESHGUI->GetStudy()->FindComponent("MESH");
722   SALOMEDS::SObject_var          AlgorithmsRoot;
723   SALOMEDS::GenericAttribute_var anAttr;
724   SALOMEDS::AttributeName_var    aName;
725   SALOMEDS::AttributeIOR_var     anIOR;
726
727   int Tag_AlgorithmsRoot = 2;
728   if (father->FindSubObject (2, AlgorithmsRoot)) {
729     SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(AlgorithmsRoot);
730     for (; it->More();it->Next()) {
731       SALOMEDS::SObject_var Obj = it->Value();
732       if (Obj->FindAttribute(anAttr, "AttributeName") ) {
733         aName = SALOMEDS::AttributeName::_narrow(anAttr);
734         ListAlgoDefinition->insertItem(aName->Value());
735
736         if (Obj->FindAttribute(anAttr, "AttributeIOR")) {
737           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
738           mapNameIOR[ aName->Value() ] = anIOR->Value();
739         }
740       }
741     }
742   }
743 }
744
745
746 //=================================================================================
747 // function : InitAlgoAssignation()
748 // purpose  :
749 //=================================================================================
750 void SMESHGUI_EditHypothesesDlg::InitAlgoAssignation()
751 {
752   MESSAGE ( " InitAlgoAssignation " << myMesh->_is_nil() )
753   MESSAGE ( " InitAlgoAssignation " << mySubMesh->_is_nil() )
754   ListAlgoAssignation->clear();
755   SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
756   int Tag_RefOnAppliedAlgorithms = 3;
757   SALOMEDS::SObject_var             AHR, aRef;
758   SALOMEDS::GenericAttribute_var    anAttr;
759   SALOMEDS::AttributeName_var       aName;
760   
761   if ( !myMesh->_is_nil() ) {
762     SALOMEDS::SObject_var aMesh = myStudyAPI.FindMesh( myMesh );
763     if ( aMesh->FindSubObject (3, AHR) ) {
764       SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(AHR);
765       for (; it->More();it->Next()) {
766         SALOMEDS::SObject_var Obj = it->Value();
767         if ( Obj->ReferencedObject(aRef) ) {
768           if (aRef->FindAttribute(anAttr, "AttributeName") ) {
769             aName = SALOMEDS::AttributeName::_narrow(anAttr);
770             ListAlgoAssignation->insertItem(aName->Value());
771           }
772         }
773       }
774     }
775   }
776   if ( !mySubMesh->_is_nil() ) {
777     SALOMEDS::SObject_var aSubMesh = myStudyAPI.FindSubMesh( mySubMesh );
778     if ( aSubMesh->FindSubObject (3, AHR) ) {
779       SALOMEDS::ChildIterator_var it = mySMESHGUI->GetStudy()->NewChildIterator(AHR);
780       for (; it->More();it->Next()) {
781         SALOMEDS::SObject_var Obj = it->Value();
782         if ( Obj->ReferencedObject(aRef) ) {
783           if (aRef->FindAttribute(anAttr, "AttributeName") ) {
784             aName = SALOMEDS::AttributeName::_narrow(anAttr);
785             ListAlgoAssignation->insertItem(aName->Value());
786           }
787         }
788       }
789     }
790   }
791 }
792
793 //=================================================================================
794 // function : InitGeom()
795 // purpose  :
796 //=================================================================================
797 void SMESHGUI_EditHypothesesDlg::InitGeom()
798 {
799   LineEditC1A2->setText("") ;
800   SMESHGUI_StudyAPI myStudyAPI = mySMESHGUI->GetStudyAPI();
801
802   if ( !myMesh->_is_nil() ) {
803     SALOMEDS::SObject_var aMesh = myStudyAPI.FindMesh( myMesh );
804     if ( !aMesh->_is_nil() )
805       myGeomShape = myStudyAPI.GetShapeOnMeshOrSubMesh(aMesh);
806   }
807   if ( !mySubMesh->_is_nil() ) {
808     SALOMEDS::SObject_var aSubMesh = myStudyAPI.FindSubMesh( mySubMesh );
809     if ( !aSubMesh->_is_nil() )
810       myGeomShape = myStudyAPI.GetShapeOnMeshOrSubMesh(aSubMesh);
811   }
812   
813   SALOMEDS::GenericAttribute_var    anAttr;
814   SALOMEDS::AttributeName_var       aName;
815   if ( !myGeomShape->_is_nil() && (!myMesh->_is_nil() || !mySubMesh->_is_nil()) ) {
816     SALOMEDS::SObject_var aSO = mySMESHGUI->GetStudy()->FindObjectIOR( myGeomShape->Name() );
817     if ( !aSO->_is_nil() ) {
818       if (aSO->FindAttribute(anAttr, "AttributeName") ) {
819         aName = SALOMEDS::AttributeName::_narrow(anAttr);
820         LineEditC1A2->setText( QString(aName->Value()) ) ;
821       }
822     }
823   }
824 }