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