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