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