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