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