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