]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI_CommonDlg.cxx
Salome HOME
NRI : First integration.
[modules/geom.git] / src / GEOMGUI / GeometryGUI_CommonDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_CommonDlg.cxx
3 //  Created   :
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : OPEN CASCADE
8 //  $Header$
9
10 #include "GeometryGUI_CommonDlg.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 <qframe.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 #include <qevent.h>
31
32 //=================================================================================
33 // class    : GeometryGUI_CommonDlg()
34 // purpose  : Constructs a GeometryGUI_CommonDlg which is a child of 'parent', with the 
35 //            name 'name' and widget flags set to 'f'.
36 //            The dialog will by default be modeless, unless you set 'modal' to
37 //            TRUE to construct a modal dialog.
38 //=================================================================================
39 GeometryGUI_CommonDlg::GeometryGUI_CommonDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
40     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
41 {
42     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_COMMON")));
43     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
44
45     if ( !name )
46         setName( "GeometryGUI_CommonDlg" );
47     resize( 322, 220 ); 
48     setCaption( tr( "GEOM_COMMON_TITLE" ) );
49     setSizeGripEnabled( TRUE );
50
51     GeometryGUI_CommonDlgLayout = new QGridLayout( this ); 
52     GeometryGUI_CommonDlgLayout->setSpacing( 6 );
53     GeometryGUI_CommonDlgLayout->setMargin( 11 );
54
55     /***************************************************************/
56     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
57     GroupConstructors->setTitle( tr( "GEOM_COMMON"  ) );
58     GroupConstructors->setExclusive( TRUE );
59     GroupConstructors->setColumnLayout(0, Qt::Vertical );
60     GroupConstructors->layout()->setSpacing( 0 );
61     GroupConstructors->layout()->setMargin( 0 );
62     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
63     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
64     GroupConstructorsLayout->setSpacing( 6 );
65     GroupConstructorsLayout->setMargin( 11 );
66     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
67     GroupConstructorsLayout->addItem( spacer, 0, 1 );
68     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
69     Constructor1->setText( tr( ""  ) );
70     Constructor1->setPixmap( image0 );
71     Constructor1->setChecked( TRUE );
72     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
73     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
74     GeometryGUI_CommonDlgLayout->addWidget( GroupConstructors, 0, 0 );
75
76     /***************************************************************/
77     GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
78     GroupConstructor1->setTitle( tr( "GEOM_ARGUMENTS"  ) );
79     GroupConstructor1->setColumnLayout(0, Qt::Vertical );
80     GroupConstructor1->layout()->setSpacing( 0 );
81     GroupConstructor1->layout()->setMargin( 0 );
82     GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
83     GroupConstructor1Layout->setAlignment( Qt::AlignTop );
84     GroupConstructor1Layout->setSpacing( 6 );
85     GroupConstructor1Layout->setMargin( 11 );
86     LineEditC1A2Shape = new QLineEdit( GroupConstructor1, "LineEditC1A2Shape" );
87     LineEditC1A2Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Shape->sizePolicy().hasHeightForWidth() ) );
88     GroupConstructor1Layout->addWidget( LineEditC1A2Shape, 1, 2 );
89     LineEditC1A1Shape = new QLineEdit( GroupConstructor1, "LineEditC1A1Shape" );
90     LineEditC1A1Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Shape->sizePolicy().hasHeightForWidth() ) );
91     GroupConstructor1Layout->addWidget( LineEditC1A1Shape, 0, 2 );
92     SelectButtonC1A1Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A1Shape" );
93     SelectButtonC1A1Shape->setText( tr( ""  ) );
94     SelectButtonC1A1Shape->setPixmap( image1 );
95     GroupConstructor1Layout->addWidget( SelectButtonC1A1Shape, 0, 1 );
96     SelectButtonC1A2Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A2Shape" );
97     SelectButtonC1A2Shape->setText( tr( ""  ) );
98     SelectButtonC1A2Shape->setPixmap( image1 );
99     GroupConstructor1Layout->addWidget( SelectButtonC1A2Shape, 1, 1 );
100     TextLabelC1A2Shape = new QLabel( GroupConstructor1, "TextLabelC1A2Shape" );
101     TextLabelC1A2Shape->setText( tr( "GEOM_OBJECT_I"  ).arg("2") );
102     TextLabelC1A2Shape->setMinimumSize( QSize( 50, 0 ) );
103     TextLabelC1A2Shape->setFrameShape( QLabel::NoFrame );
104     TextLabelC1A2Shape->setFrameShadow( QLabel::Plain );
105     GroupConstructor1Layout->addWidget( TextLabelC1A2Shape, 1, 0 );
106     TextLabelC1A1Shape = new QLabel( GroupConstructor1, "TextLabelC1A1Shape" );
107     TextLabelC1A1Shape->setText( tr( "GEOM_OBJECT_I"  ).arg("1") );
108     TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
109     TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
110     TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
111     GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
112     GeometryGUI_CommonDlgLayout->addWidget( GroupConstructor1, 1, 0 );
113
114     /***************************************************************/
115     GroupButtons = new QGroupBox( this, "GroupButtons" );
116     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
117     GroupButtons->setTitle( tr( ""  ) );
118     GroupButtons->setColumnLayout(0, Qt::Vertical );
119     GroupButtons->layout()->setSpacing( 0 );
120     GroupButtons->layout()->setMargin( 0 );
121     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
122     GroupButtonsLayout->setAlignment( Qt::AlignTop );
123     GroupButtonsLayout->setSpacing( 6 );
124     GroupButtonsLayout->setMargin( 11 );
125     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
126     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
127     buttonCancel->setAutoDefault( TRUE );
128     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
129     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
130     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
131     buttonApply->setAutoDefault( TRUE );
132     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
133     QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
134     GroupButtonsLayout->addItem( spacer_1, 0, 2 );
135     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
136     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
137     buttonOk->setAutoDefault( TRUE );
138     buttonOk->setDefault( TRUE );
139     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
140     GeometryGUI_CommonDlgLayout->addWidget( GroupButtons, 2, 0 ); 
141
142     /* Initialisation */
143     Init( Sel ) ; 
144 }
145
146
147 //=================================================================================
148 // function : ~GeometryGUI_CommonDlg()
149 // purpose  : Destroys the object and frees any allocated resources
150 //=================================================================================
151 GeometryGUI_CommonDlg::~GeometryGUI_CommonDlg()
152 {  
153   /* no need to delete child widgets, Qt does it all for us */
154   this->destroy(TRUE, TRUE) ;
155 }
156
157
158
159 //=================================================================================
160 // function : Init()
161 // purpose  :
162 //=================================================================================
163 void GeometryGUI_CommonDlg::Init( SALOME_Selection* Sel )
164 {  
165   mySelection = Sel ;
166   myShape1.Nullify() ;
167   myShape2.Nullify() ;
168   myConstructorId = 0 ;
169   
170   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
171
172   GroupConstructor1->show();
173   myConstructorId = 0 ;
174   myEditCurrentArgument = LineEditC1A1Shape ;   
175   Constructor1->setChecked( TRUE );
176   myOkShape1 = myOkShape2 = false ;
177
178   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
179
180   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
181   myGeom = GEOM::GEOM_Gen::_narrow(comp);
182   
183   // TODO previous selection into argument
184
185   /* signals and slots connections */
186   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
187   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
188   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
189   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
190   connect( SelectButtonC1A1Shape, SIGNAL (clicked() ),  this, SLOT( SetEditCurrentArgument() ) ) ;
191   connect( SelectButtonC1A2Shape, SIGNAL (clicked() ),  this, SLOT( SetEditCurrentArgument() ) ) ;
192
193   connect( LineEditC1A1Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
194   connect( LineEditC1A2Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
195
196   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
197   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
198   /* to close dialog if study change */
199   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
200  
201   /* Move widget on the botton right corner of main widget */
202   int x, y ;
203   myGeomGUI->DefineDlgPosition( this, x, y ) ;
204   this->move( x, y ) ;
205   this->show() ; /* Displays Dialog */ 
206
207   return ;
208 }
209
210
211
212 //=================================================================================
213 // function : ConstructorsClicked()
214 // purpose  : Radio button management
215 //=================================================================================
216 void GeometryGUI_CommonDlg::ConstructorsClicked(int constructorId)
217 {
218   GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
219
220   switch (constructorId)
221     {
222     case 0:
223       {
224         GroupConstructor1->show();
225         myConstructorId = constructorId ;
226         myEditCurrentArgument = LineEditC1A1Shape ;
227         LineEditC1A2Shape->setText(tr("")) ;
228         Constructor1->setChecked( TRUE );
229         myOkShape1 =  myOkShape2 = false ;
230         break;
231       }
232     }
233  return ;
234 }
235
236 //=================================================================================
237 // function : ClickOnOk()
238 // purpose  :
239 //=================================================================================
240 void GeometryGUI_CommonDlg::ClickOnOk()
241 {
242   this->ClickOnApply() ;
243   this->ClickOnCancel() ;
244
245   return ;
246 }
247
248 //=================================================================================
249 // function : ClickOnApply()
250 // purpose  :
251 //=================================================================================
252 void GeometryGUI_CommonDlg::ClickOnApply()
253 {
254   switch(myConstructorId)
255     { 
256     case 0 :
257       {
258         if(myOkShape1 && myOkShape2) {    
259           myGeomGUI->MakeBooleanAndDisplay(myGeomShape1 ,myGeomShape2, 1 ) ;
260         }
261         break ;
262       }
263     }
264
265   // accept();
266   return ;
267 }
268
269
270 //=================================================================================
271 // function : ClickOnCancel()
272 // purpose  :
273 //=================================================================================
274 void GeometryGUI_CommonDlg::ClickOnCancel()
275 {
276   myGeomGUI->EraseSimulationShape() ;
277   disconnect( mySelection, 0, this, 0 );
278   myGeomGUI->ResetState() ;
279   reject() ;
280   return ;
281 }
282
283
284
285 //=================================================================================
286 // function : SelectionIntoArgument()
287 // purpose  : Called when selection has changed
288 //=================================================================================
289 void GeometryGUI_CommonDlg::SelectionIntoArgument()
290 {
291   myEditCurrentArgument->setText("") ;
292   QString aString = ""; /* name of future selection */
293
294   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
295   if ( nbSel != 1 ) {
296     switch (myConstructorId) 
297       {
298       case 0:
299         {
300           if ( myEditCurrentArgument == LineEditC1A1Shape ) {
301             myOkShape1 = false ;
302           }
303           else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
304             myOkShape2 = false ;
305           }
306           break ;
307         } 
308       }
309     return ;
310   }
311
312   /*  nbSel == 1  */ 
313   TopoDS_Shape S;
314   Standard_Boolean testResult ;
315   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;  
316   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
317     return ;  
318
319   if ( myEditCurrentArgument == LineEditC1A1Shape ) {
320     myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
321     if( !testResult )
322       return ;
323     myShape1 = S ;
324     LineEditC1A1Shape->setText(aString) ;
325     myOkShape1 = true ;
326   }    
327   else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
328     myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
329     if( !testResult )
330       return ;
331     myShape2 = S ;
332     LineEditC1A2Shape->setText(aString) ;
333     myOkShape2 = true ;
334   }
335   return ; 
336 }
337
338 //=================================================================================
339 // function : SetEditCurrentArgument()
340 // purpose  :
341 //=================================================================================
342 void GeometryGUI_CommonDlg::SetEditCurrentArgument()
343 {
344   QPushButton* send = (QPushButton*)sender();
345   switch (myConstructorId)
346     {
347     case 0: /* default constructor */
348       { 
349         if( send == SelectButtonC1A1Shape ) {
350           LineEditC1A1Shape->setFocus() ;
351           myEditCurrentArgument = LineEditC1A1Shape ;
352         }
353         else if(send == SelectButtonC1A2Shape) {
354           LineEditC1A2Shape->setFocus() ;
355           myEditCurrentArgument = LineEditC1A2Shape;
356         }
357         SelectionIntoArgument() ;
358         break;
359       }
360     }
361   return ;
362 }
363
364
365
366 //=================================================================================
367 // function : LineEditReturnPressed()
368 // purpose  :
369 //=================================================================================
370 void GeometryGUI_CommonDlg::LineEditReturnPressed()
371 {
372   QLineEdit* send = (QLineEdit*)sender();  
373   if( send == LineEditC1A1Shape )
374     myEditCurrentArgument = LineEditC1A1Shape ;
375   else if ( send == LineEditC1A2Shape )
376     myEditCurrentArgument = LineEditC1A2Shape ; 
377   else
378     return ;
379   
380   /* User name of object input management                          */
381   /* If successfull the selection is changed and signal emitted... */
382   /* so SelectionIntoArgument() is automatically called.           */
383   const QString objectUserName = myEditCurrentArgument->text() ;
384   QWidget* thisWidget = (QWidget*)this ;
385   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
386     myEditCurrentArgument->setText( objectUserName ) ;
387   }
388   return ;
389 }
390
391
392
393 //=================================================================================
394 // function : DeactivateActiveDialog()
395 // purpose  :
396 //=================================================================================
397 void GeometryGUI_CommonDlg::DeactivateActiveDialog()
398 {
399   if ( GroupConstructors->isEnabled() ) {
400     GroupConstructors->setEnabled(false) ;
401     GroupConstructor1->setEnabled(false) ;
402     GroupButtons->setEnabled(false) ;  
403     disconnect( mySelection, 0, this, 0 );
404     myGeomGUI->EraseSimulationShape() ;
405   }
406   return ;
407 }
408
409
410
411 //=================================================================================
412 // function : closeEvent()
413 // purpose  :
414 //=================================================================================
415 void GeometryGUI_CommonDlg::closeEvent( QCloseEvent* e )
416 {
417   this->ClickOnCancel() ; /* same than click on cancel button */
418 }
419
420
421 //=================================================================================
422 // function : enterEvent()
423 // purpose  : when mouse enter onto the QWidget
424 //=================================================================================
425 void GeometryGUI_CommonDlg::enterEvent( QEvent *  )
426 {
427   if ( GroupConstructors->isEnabled() )
428     return ;
429   ActivateThisDialog() ;
430 }
431
432
433
434 //=================================================================================
435 // function : ActivateThisDialog()
436 // purpose  :
437 //=================================================================================
438 void GeometryGUI_CommonDlg::ActivateThisDialog()
439 {
440   /* Emit a signal to deactivate any active dialog */
441   myGeomGUI->EmitSignalDeactivateDialog() ;
442   GroupConstructors->setEnabled(true) ;
443   GroupConstructor1->setEnabled(true) ;
444   GroupButtons->setEnabled(true) ;  
445   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
446   return ;
447 }