Salome HOME
NRI : Correction 1.1a version.
[modules/visu.git] / src / VISUGUI / VisuGUI_InitMeshDlg.cxx
1 using namespace std;
2 //  File      : VisuGUI_InitMeshDlg.cxx
3 //  Created   : Mon May 27 10:20:11 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : Visu
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11 #include "VisuGUI_InitMeshDlg.h"
12 #include "VisuGUI.h"
13
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
17
18 // QT Includes
19 #include <qbuttongroup.h>
20 #include <qgroupbox.h>
21 #include <qlabel.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
25 #include <qlayout.h>
26 #include <qvariant.h>
27 #include <qtooltip.h>
28 #include <qwhatsthis.h>
29 #include <qimage.h>
30 #include <qpixmap.h>
31
32
33 //=================================================================================
34 // class    : VisuGUI_InitMeshDlg()
35 // purpose  : Constructs a VisuGUI_InitMeshDlg which is a child of 'parent', with the 
36 //            name 'name' and widget flags set to 'f'.
37 //            The dialog will by default be modeless, unless you set 'modal' to
38 //            TRUE to construct a modal dialog.
39 //=================================================================================
40 VisuGUI_InitMeshDlg::VisuGUI_InitMeshDlg( QWidget* parent, const char* name, SALOME_Selection* Sel = 0, bool modal, WFlags fl )
41     : QDialog( parent, name, modal, fl )
42 {
43     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "VisuGUI",tr("ICON_DLG_INIT_MESH")));
44     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "VisuGUI",tr("ICON_SELECT")));
45     if ( !name )
46         setName( "VisuGUI_InitMeshDlg" );
47     resize( 303, 175 ); 
48     setCaption( tr( "Visu_INIT_MESH"  ) );
49     VisuGUI_InitMeshDlgLayout = new QGridLayout( this ); 
50     VisuGUI_InitMeshDlgLayout->setSpacing( 6 );
51     VisuGUI_InitMeshDlgLayout->setMargin( 11 );
52     
53     /***************************************************************/
54     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
55     GroupConstructors->setTitle( tr( "Visu_INIT"  ) );
56     GroupConstructors->setExclusive( TRUE );
57     GroupConstructors->setColumnLayout(0, Qt::Vertical );
58     GroupConstructors->layout()->setSpacing( 0 );
59     GroupConstructors->layout()->setMargin( 0 );
60     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
61     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
62     GroupConstructorsLayout->setSpacing( 6 );
63     GroupConstructorsLayout->setMargin( 11 );
64     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
65     Constructor1->setText( tr( ""  ) );
66     Constructor1->setPixmap( image1 );
67     Constructor1->setChecked( TRUE );
68     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
69     Constructor1->setMinimumSize( QSize( 50, 0 ) );
70     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
71     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
72     GroupConstructorsLayout->addItem( spacer, 0, 1 );
73     VisuGUI_InitMeshDlgLayout->addWidget( GroupConstructors, 0, 0 );
74     
75     /***************************************************************/
76     GroupButtons = new QGroupBox( this, "GroupButtons" );
77     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
78     GroupButtons->setTitle( tr( ""  ) );
79     GroupButtons->setColumnLayout(0, Qt::Vertical );
80     GroupButtons->layout()->setSpacing( 0 );
81     GroupButtons->layout()->setMargin( 0 );
82     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
83     GroupButtonsLayout->setAlignment( Qt::AlignTop );
84     GroupButtonsLayout->setSpacing( 6 );
85     GroupButtonsLayout->setMargin( 11 );
86     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
87     buttonCancel->setText( tr( "Visu_BUT_CLOSE"  ) );
88     buttonCancel->setAutoDefault( TRUE );
89     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
90     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
91     buttonApply->setText( tr( "Visu_BUT_APPLY"  ) );
92     buttonApply->setAutoDefault( TRUE );
93     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
94     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
96     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
97     buttonOk->setText( tr( "Visu_BUT_OK"  ) );
98     buttonOk->setAutoDefault( TRUE );
99     buttonOk->setDefault( TRUE );
100     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
101     VisuGUI_InitMeshDlgLayout->addWidget( GroupButtons, 2, 0 );
102
103     /***************************************************************/
104     GroupC1 = new QGroupBox( this, "GroupC1" );
105     GroupC1->setTitle( tr( "Visu_ARGUMENTS"  ) );
106     GroupC1->setMinimumSize( QSize( 0, 0 ) );
107     GroupC1->setFrameShape( QGroupBox::Box );
108     GroupC1->setFrameShadow( QGroupBox::Sunken );
109     GroupC1->setColumnLayout(0, Qt::Vertical );
110     GroupC1->layout()->setSpacing( 0 );
111     GroupC1->layout()->setMargin( 0 );
112     GroupC1Layout = new QGridLayout( GroupC1->layout() );
113     GroupC1Layout->setAlignment( Qt::AlignTop );
114     GroupC1Layout->setSpacing( 6 );
115     GroupC1Layout->setMargin( 11 );
116
117     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
118     TextLabelC1A1->setText( tr( "Visu_OBJECT_GEOM"  ) );
119     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
120     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
121     TextLabelC1A1->setFrameShadow( QLabel::Plain );
122     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
123     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
124     SelectButtonC1A1->setText( tr( ""  ) );
125     SelectButtonC1A1->setPixmap( image0 );
126     SelectButtonC1A1->setToggleButton( FALSE );
127     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
128     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
129     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
130
131     TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" );
132     TextLabel_NameMesh->setText( tr( "Visu_NAME"  ) );
133     GroupC1Layout->addWidget( TextLabel_NameMesh, 1, 0 );
134     LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
135     GroupC1Layout->addWidget( LineEdit_NameMesh, 1, 2 );
136
137     VisuGUI_InitMeshDlgLayout->addWidget( GroupC1, 1, 0 );
138     /***************************************************************/
139
140     Init(Sel) ;
141 }
142
143
144 //=================================================================================
145 // function : ~VisuGUI_InitMeshDlg()
146 // purpose  : Destroys the object and frees any allocated resources
147 //=================================================================================
148 VisuGUI_InitMeshDlg::~VisuGUI_InitMeshDlg()
149 {
150     // no need to delete child widgets, Qt does it all for us
151 }
152
153
154 //=================================================================================
155 // function : Init()
156 // purpose  :
157 //=================================================================================
158 void VisuGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
159 {
160   GroupC1->show();
161   myConstructorId = 0 ;
162   Constructor1->setChecked( TRUE );
163   myEditCurrentArgument = LineEditC1A1 ;        
164   mySelection = Sel;
165   myVisuGUI = VisuGUI::GetVisuGUI() ;
166   myVisuGUI->SetActiveDialogBox( (QDialog*)this ) ;
167
168   myGeomFilter = new SALOME_TypeFilter( "GEOM" );
169   mySelection->AddFilter( myGeomFilter );
170
171   myNameMesh = "Mesh";
172
173   /* signals and slots connections */
174   connect( buttonOk, SIGNAL( pressed() ),     this, SLOT( ClickOnOk() ) );
175   connect( buttonApply, SIGNAL( pressed() ), this, SLOT(ClickOnApply() ) );
176   connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( ClickOnCancel() ) ) ;
177   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
178
179   connect( SelectButtonC1A1, SIGNAL (pressed() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
180   connect( LineEdit_NameMesh, SIGNAL (textChanged(const QString&)  ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
181
182   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
183   connect( myVisuGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
184   connect( myVisuGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
185   
186 //  int x, y ;
187 //  myVisuGUI->DefineDlgPosition( this, x, y ) ;
188 //  this->move( x, y ) ;
189   this->show() ; 
190
191   return ;
192 }
193
194
195 //=================================================================================
196 // function : ConstructorsClicked()
197 // purpose  : Radio button management
198 //=================================================================================
199 void VisuGUI_InitMeshDlg::ConstructorsClicked(int constructorId)
200 {
201   return ;
202 }
203
204 //=================================================================================
205 // function : ClickOnOk()
206 // purpose  :
207 //=================================================================================
208 void VisuGUI_InitMeshDlg::ClickOnOk()
209 {
210   this->ClickOnApply() ;
211   this->ClickOnCancel() ;
212
213   return ;
214 }
215
216 //=================================================================================
217 // function : ClickOnApply()
218 // purpose  :
219 //=================================================================================
220 void VisuGUI_InitMeshDlg::ClickOnApply()
221 {
222   switch(myConstructorId)
223     { 
224     case 0 :
225       { 
226         if ( !myNameMesh.isEmpty() && !myNameMesh.isNull() && !myGeomShape->_is_nil() )
227           myVisuGUI->InitMesh( mySMeshMesh, myNameMesh ) ;
228         break ;
229       }
230     }
231 }
232
233
234 //=================================================================================
235 // function : ClickOnCancel()
236 // purpose  :
237 //=================================================================================
238 void VisuGUI_InitMeshDlg::ClickOnCancel()
239 {
240   mySelection->ClearFilters() ;
241   disconnect( mySelection, 0, this, 0 );
242   myVisuGUI->ResetState() ;
243   reject() ;
244   return ;
245 }
246
247
248 //=================================================================================
249 // function : SelectionIntoArgument()
250 // purpose  : Called when selection as changed or other case
251 //=================================================================================
252 void VisuGUI_InitMeshDlg::SelectionIntoArgument()
253 {
254   myEditCurrentArgument->setText("") ;
255   QString aString = ""; 
256   myGeomShape = GEOM::GEOM_Shape::_nil();
257
258   int nbSel = myVisuGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
259   if ( nbSel != 1 ) {
260     return ;
261   } else {
262     Standard_Boolean testResult ;
263     Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
264     myGeomShape = myVisuGUI->ConvertIOinGEOMShape(IO, testResult) ;
265     if( !testResult ) return ;
266   }
267   
268   myEditCurrentArgument->setText(aString) ;
269 }
270
271
272 //=================================================================================
273 // function : SetEditCurrentArgument()
274 // purpose  :
275 //=================================================================================
276 void VisuGUI_InitMeshDlg::SetEditCurrentArgument()
277 {
278   QPushButton* send = (QPushButton*)sender();
279   switch (myConstructorId)
280     {
281     case 0: /* default constructor */
282       { 
283         if(send == SelectButtonC1A1) {
284           LineEditC1A1->setFocus() ;
285           myEditCurrentArgument = LineEditC1A1;
286         }
287         SelectionIntoArgument() ;
288         break;
289       }
290     }
291   return ;
292 }
293
294 //=================================================================================
295 // function : DeactivateActiveDialog()
296 // purpose  :
297 //=================================================================================
298 void VisuGUI_InitMeshDlg::DeactivateActiveDialog()
299 {
300   if ( GroupConstructors->isEnabled() ) {
301     disconnect( mySelection, 0, this, 0 );
302     GroupConstructors->setEnabled(false) ;
303     GroupC1->setEnabled(false) ;
304     GroupButtons->setEnabled(false) ;
305   }
306 }
307
308
309 //=================================================================================
310 // function : ActivateThisDialog()
311 // purpose  :
312 //=================================================================================
313 void VisuGUI_InitMeshDlg::ActivateThisDialog()
314 {
315   myVisuGUI->EmitSignalDeactivateDialog() ;   
316   GroupConstructors->setEnabled(true) ;
317   GroupC1->setEnabled(true) ;
318   GroupButtons->setEnabled(true) ;
319   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
320   return ;
321 }
322
323
324 //=================================================================================
325 // function : enterEvent()
326 // purpose  :
327 //=================================================================================
328 void VisuGUI_InitMeshDlg::enterEvent(QEvent* e)
329 {
330   if ( GroupConstructors->isEnabled() )
331     return ;  
332   ActivateThisDialog() ;
333   return ;
334 }
335
336
337 //=================================================================================
338 // function : closeEvent()
339 // purpose  :
340 //=================================================================================
341 void VisuGUI_InitMeshDlg::closeEvent( QCloseEvent* e )
342 {
343   this->ClickOnCancel() ;
344   return ;
345 }
346
347 //=================================================================================
348 // function : TextChangedInLineEdit()
349 // purpose  :
350 //=================================================================================
351 void VisuGUI_InitMeshDlg::TextChangedInLineEdit(const QString& newText)
352 {  
353   QLineEdit* send = (QLineEdit*)sender();
354   QString newT = strdup(newText) ;
355   
356   if (send == LineEdit_NameMesh) {
357     myNameMesh = newText;
358   }
359   return ;
360 }