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