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