Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/visu.git] / src / VISUGUI / VisuGUI_CutLinesDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : VisuGUI_CutLinesDlg.cxx
8 //  Author : VSV
9 //  Module : VISU
10
11 #include "VisuGUI_CutLinesDlg.h"
12 #include "VISU_CutLines_i.hh"
13
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16
17 #include <qlayout.h>
18 #include <qhbox.h>
19 #include <qtabwidget.h>
20 #include <qhgroupbox.h>
21
22 using namespace std;
23
24 VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg()
25     : QDialog(  QAD_Application::getDesktop(), "VisuGUI_CutLinesDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
26 {
27   setCaption( "Cut Lines Definition" );
28   setSizeGripEnabled( true );
29   
30   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
31   aMainLayout->setSpacing(5);
32   
33   hasInit = false; 
34   
35   // Tab pane
36   QTabWidget* aTabPane = new QTabWidget(this);
37
38   // Plane of lines
39   QFrame* aPlanePane = new QFrame(this);
40   QVBoxLayout* aPlaneLayout = new QVBoxLayout( aPlanePane, 5, 6 ); 
41     
42   mySelPlane = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aPlanePane);
43   mySelPlane->setInsideSpacing( 5 );
44   mySelPlane->setInsideMargin( 5 );
45     
46   QRadioButton* aBxy = new QRadioButton( tr( "|| X-Y" ), mySelPlane);  // 0
47   QRadioButton* aByz = new QRadioButton( tr( "|| Y-Z" ), mySelPlane);  // 1
48   QRadioButton* aBzx = new QRadioButton( tr( "|| Z-X" ), mySelPlane);  // 2
49   aBzx->setChecked(true);
50
51   aPlaneLayout->addWidget( mySelPlane );
52    
53   QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
54   aRotBox->setColumnLayout(2, Qt::Horizontal );
55
56   myRotXLbl = new QLabel( tr( "LBL_ROT_X" ), aRotBox);
57   myRotXSpn = new QAD_SpinBoxDbl( aRotBox, -45, 45, 5 );
58   myRotXSpn->setValue( 0 );
59   myRotYLbl = new QLabel( tr( "LBL_ROT_Y" ), aRotBox );
60   myRotYSpn = new QAD_SpinBoxDbl( aRotBox, -45, 45, 5 );
61   myRotYSpn->setValue( 0 );
62
63   aPlaneLayout->addWidget( aRotBox );
64     
65   QHGroupBox* aBaseBox = new QHGroupBox( tr( "Base plane position" ), aPlanePane );
66   myBasePlanePos = new QLineEdit (aBaseBox);
67   mydvalidator = new QDoubleValidator(this);
68   mydvalidator->setDecimals(32);
69   myBasePlanePos->setValidator(mydvalidator);
70
71   myCBSetDef = new QCheckBox(tr("Set default"),aBaseBox);
72   
73   aPlaneLayout->addWidget( aBaseBox );
74   
75   QHBox* aPosBox = new QHBox(aPlanePane);
76   aPosBox->setSpacing(5);
77   QLabel* aPosLbl = new QLabel( tr( "LBL_POS" ), aPosBox );
78   myPosSpn = new QAD_SpinBoxDbl( aPosBox, 0, 1, 0.1 );
79   myPosSpn->setValue( 0.5 );  
80   aPlaneLayout->addWidget( aPosBox );
81   aPlaneLayout->addStretch();
82
83   aTabPane->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
84   
85   // Number of lines
86   QFrame* aLinesPane = new QFrame(this);
87   QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane, 5, 6 ); 
88   
89   mySelPlane2 = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aLinesPane);
90   mySelPlane2->setInsideSpacing( 5 );
91   mySelPlane2->setInsideMargin( 5 );
92  
93   QRadioButton* aBxy2 = new QRadioButton( tr( "|| X-Y" ), mySelPlane2);  // 0
94   QRadioButton* aByz2 = new QRadioButton( tr( "|| Y-Z" ), mySelPlane2);  // 1
95   QRadioButton* aBzx2 = new QRadioButton( tr( "|| Z-X" ), mySelPlane2);  // 2
96   aBzx2->setEnabled(false);
97   aByz2->setChecked(true);
98   aLinesLayout->addWidget( mySelPlane2 );
99
100   QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
101   aRotBox2->setColumnLayout(2, Qt::Horizontal );
102   
103   myRotXLbl2 = new QLabel( tr( "LBL_ROT_X" ), aRotBox2);
104   myRotXSpn2 = new QAD_SpinBoxDbl( aRotBox2, -45, 45, 5 );
105   myRotXSpn2->setValue( 0 );
106   myRotYLbl2 = new QLabel( tr( "LBL_ROT_Y" ), aRotBox2 );
107   myRotYSpn2 = new QAD_SpinBoxDbl( aRotBox2, -45, 45, 5 );
108   myRotYSpn2->setValue( 0 );
109   aLinesLayout->addWidget( aRotBox2 );
110
111   QHBox* aNbBox = new QHBox(aLinesPane);
112   aNbBox->setSpacing(5);
113   QLabel* aNbLbl = new QLabel( tr( "LBL_NB_PLANS" ), aNbBox );
114   myNbSpn = new QAD_SpinBoxDbl( aNbBox, 1, 100, 1 );
115   myNbSpn->setValue( 10 );  
116  
117   aLinesLayout->addWidget( aNbBox );
118
119   myPosTable = new QTable(aLinesPane, "Positions of cut planes" );
120   myPosTable->setMaximumHeight( 227 );
121   myPosTable->setMinimumWidth( 294 );
122   myPosTable->setNumCols(2);
123   myPosTable->setNumRows(0);
124   
125   QHeader *th = myPosTable->horizontalHeader();
126   th->setLabel( 0, "Position" );
127   th->setLabel( 1, "Set default" );
128
129   aLinesLayout->addWidget( myPosTable );
130
131   QHBox* aPosBox2 = new QHBox(aLinesPane);
132   aPosBox2->setSpacing(5);
133   QLabel* aPosLbl2 = new QLabel( tr( "LBL_POS" ), aPosBox2 );
134   myPosSpn2 = new QAD_SpinBoxDbl( aPosBox2, 0, 1, 0.1 );
135   myPosSpn2->setValue( 0.5 );  
136   aLinesLayout->addWidget( aPosBox2 );
137   aLinesLayout->addStretch();
138  
139   aTabPane->addTab( aLinesPane, tr("LBL_LINES_CUT") );
140
141   aMainLayout->addWidget(aTabPane);
142
143   // Dialog buttons
144   QHBox* aBtnBox = new QHBox(this);
145   QHBoxLayout* aBtnLayout = (QHBoxLayout*) aBtnBox->layout(); 
146   aBtnLayout->setAutoAdd( false );
147   aBtnLayout->setSpacing( 5 );
148
149   QPushButton* aOkBtn = new QPushButton(tr( "VISU_BUT_OK" ),  aBtnBox);
150   aOkBtn->setAutoDefault( TRUE );
151   aOkBtn->setDefault( true );
152   aBtnLayout->addWidget(aOkBtn);
153  
154   aBtnLayout->addStretch();
155   
156   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
157   aBtnLayout->addWidget(aCloseBtn);
158    
159   aMainLayout->addWidget(aBtnBox);
160
161   myCutLines = NULL;
162   
163   // signals and slots connections
164   connect(mySelPlane, SIGNAL(clicked(int)), this, SLOT(onPlaneSelect(int)));
165   connect(myCBSetDef , SIGNAL( toggled(bool) ), this , SLOT( setBaseDefault() ) );
166   connect(myPosSpn , SIGNAL( valueChanged( double ) ), this , SLOT( setBaseDefault() ) );
167   connect(mySelPlane2, SIGNAL(clicked(int)), this, SLOT(onCutSelect(int)));
168   connect( myNbSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
169   connect( th, SIGNAL( clicked(int)), this, SLOT( setDefault(int) ) );
170   connect( myPosSpn2, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
171
172   connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
173   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
174
175 }
176
177 /*!
178   Destructor
179 */
180 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
181 {
182   if(myCutLines) delete myCutLines; 
183 }
184
185 //------------------------------------------------------------------------------
186 void VisuGUI_CutLinesDlg::initFromPrsObject(VISU::CutLines_i* thePrs) {
187
188   myRotXSpn->setValue(thePrs->GetRotateX()*180./PI);
189   myRotYSpn->setValue(thePrs->GetRotateY()*180./PI);
190   myPosSpn->setValue(thePrs->GetDisplacement());
191   setOrientation(thePrs->GetOrientationType());
192   
193   myNbSpn->setValue( thePrs->GetNbLines() );  
194   myRotXSpn2->setValue(thePrs->GetRotateX2()*180./PI);
195   myRotYSpn2->setValue(thePrs->GetRotateY2()*180./PI);
196   myPosSpn2->setValue(thePrs->GetDisplacement2());
197   setOrientation2(thePrs->GetOrientationType2());
198
199   hasInit = true;
200   myCutLines = new VISU::CutLines_i(thePrs->GetResult(),false);
201   myCutLines->SameAs(thePrs);
202   myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) );
203   myCBSetDef->setChecked(thePrs->IsDefault());
204   DrawTable();
205 }
206
207
208 //------------------------------------------------------------------------------
209 void VisuGUI_CutLinesDlg::storeToPrsObject(VISU::CutLines_i* thePrs) {
210   
211   thePrs->SetOrientationType(getOrientaion());
212   thePrs->SetRotateX(myRotXSpn->value()*PI/180.);
213   thePrs->SetRotateY(myRotYSpn->value()*PI/180.);
214   thePrs->SetDisplacement(myPosSpn->value());
215   thePrs->SetNbLines((int)myNbSpn->value());
216  
217   thePrs->SetOrientationType2(getOrientaion(false));
218   thePrs->SetRotateX2(myRotXSpn2->value()*PI/180.);
219   thePrs->SetRotateY2(myRotYSpn2->value()*PI/180.);
220   thePrs->SetDisplacement2(myPosSpn2->value());
221   
222   if (!myCBSetDef->isChecked())
223     thePrs->SetBasePlanePosition(myBasePlanePos->text().toDouble());
224   else thePrs->SetDefault();
225   
226   for (int i = 0; i < (int)myNbSpn->value(); ++i) 
227     {
228       if (!((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked())
229         thePrs->SetLinePosition( i, ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->text().toDouble() );
230       else thePrs->SetDefaultPosition(i);
231     }
232 }
233
234 //------------------------------------------------------------------------------
235 void VisuGUI_CutLinesDlg::onPlaneSelect(int theId) {
236   for (int i = 0; i < mySelPlane2->count(); i++)
237     mySelPlane2->find(i)->setEnabled(true);
238   QButton* aBtn = mySelPlane2->find(theId);
239   aBtn->setEnabled(false);
240   switch (theId) {
241   case 0:
242     myRotXLbl->setText( tr("LBL_ROT_X"));
243     myRotYLbl->setText( tr("LBL_ROT_Y"));
244     ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);    
245     onCutSelect(1);
246     break;
247   case 1:
248     myRotXLbl->setText( tr("LBL_ROT_Y"));
249     myRotYLbl->setText( tr("LBL_ROT_Z"));
250     ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);    
251     onCutSelect(2);
252     break;
253   case 2:
254     myRotXLbl->setText( tr("LBL_ROT_Z"));
255     myRotYLbl->setText( tr("LBL_ROT_X"));
256     ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
257     onCutSelect(0);
258   }
259   setBaseDefault();
260 }
261
262 //------------------------------------------------------------------------------
263 void VisuGUI_CutLinesDlg::onCutSelect(int theId) {
264   switch (theId) {
265   case 0:
266     myRotXLbl2->setText( tr("LBL_ROT_X"));
267     myRotYLbl2->setText( tr("LBL_ROT_Y"));
268     break;
269   case 1:
270     myRotXLbl2->setText( tr("LBL_ROT_Y"));
271     myRotYLbl2->setText( tr("LBL_ROT_Z"));
272     break;
273   case 2:
274     myRotXLbl2->setText( tr("LBL_ROT_Z"));
275     myRotYLbl2->setText( tr("LBL_ROT_X"));
276   }
277   DrawTable();
278 }
279
280 //------------------------------------------------------------------------------
281 void VisuGUI_CutLinesDlg::setBaseDefault() {
282
283   if (!hasInit) return;
284   
285   if ( myCBSetDef->isChecked() )
286     {
287       if (!myCutLines->IsDefault()) myCutLines->SetDefault();
288       myCutLines->SetOrientationType(getOrientaion());
289       myCutLines->SetDisplacement(myPosSpn->value());
290       myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) );
291       myBasePlanePos->setEnabled(false);
292     }
293   else myBasePlanePos->setEnabled(true);   
294
295 }
296
297 //------------------------------------------------------------------------------
298 void VisuGUI_CutLinesDlg::DrawTable()
299 {
300   if (!hasInit) return;
301
302   int aNbRows = myPosTable->numRows();
303   int aNbPlanes = (int)myNbSpn->value();  
304   
305   if (aNbRows>0)
306     for (int i = 0; i < aNbRows; ++i) 
307       {
308         if (!((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked())
309           myCutLines->SetLinePosition( i, ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->text().toDouble() );
310       }
311   
312   myCutLines->SetNbLines(aNbPlanes);
313   myCutLines->SetDisplacement2(myPosSpn2->value());
314   myCutLines->SetOrientationType2(getOrientaion(false));
315
316   if (aNbRows < aNbPlanes)
317     {
318       if (aNbRows == 0) myPosTable->setNumRows(aNbPlanes);
319       else myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
320       
321       QHeader *vh = myPosTable->verticalHeader();
322       QString str;
323
324       for (int i = aNbRows; i < myPosTable->numRows(); ++i) 
325         {
326           QLineEdit *editline = new QLineEdit( myPosTable );
327           editline->setValidator(mydvalidator);
328           myPosTable->setCellWidget( i, 0, editline );
329                   
330           QCheckBox *checkbox = new QCheckBox( myPosTable );
331           myPosTable->setCellWidget(i, 1, checkbox );
332           connect(checkbox , SIGNAL( clicked() ), this , SLOT( setDefault() ) );
333           
334           str = str.setNum(i+1);
335           str.prepend ("Plane# ");
336           vh->setLabel( i, str );
337         }
338     }
339   else if (aNbRows > aNbPlanes)
340     for (int i = aNbRows-1; myPosTable->numRows() != aNbPlanes; --i )
341       myPosTable->removeRow(i);
342   
343   for (int i = 0; i < myPosTable->numRows(); ++i) 
344     {
345       ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setText( QString::number(myCutLines->GetLinePosition(i)) );
346       
347       if (myCutLines->IsDefaultPosition(i)) 
348         {
349           ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->setChecked(true);
350           ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(false);
351         }
352     }
353 }
354
355 //------------------------------------------------------------------------------
356 void VisuGUI_CutLinesDlg::setDefault(int all)
357 {
358   if (all == 0) return;
359
360   if (all == 1)
361     for (int i = 0; i < (int)myNbSpn->value(); ++i) 
362       ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->setChecked(true);
363   
364   for (int i = 0; i < (int)myNbSpn->value(); ++i) 
365     {
366       if ( ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked() )
367         {
368           myCutLines->SetDefaultPosition(i);
369           ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setText( QString::number(myCutLines->GetLinePosition(i)) );
370           ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(false);
371         }
372       else ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(true); 
373     }
374 }
375
376 //------------------------------------------------------------------------------
377 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion(bool IsBasePlane)
378 {
379   QHButtonGroup* aBG;
380   
381   if (IsBasePlane)
382     aBG = mySelPlane;
383   else
384     aBG = mySelPlane2;
385
386   VISU::CutPlanes::Orientation orient;
387   switch (aBG->id(aBG->selected())) {
388   case 0:
389     orient = VISU::CutPlanes::XY;
390     break;
391   case 1:
392     orient = VISU::CutPlanes::YZ;
393     break;
394   case 2:
395     orient = VISU::CutPlanes::ZX;
396   }
397   return orient;
398 }
399
400 //------------------------------------------------------------------------------
401 void VisuGUI_CutLinesDlg::setOrientation( const VISU::CutPlanes::Orientation  orient)
402 {
403   switch (orient) {
404   case VISU::CutPlanes::XY:
405     ((QRadioButton*)mySelPlane->find(0))->setChecked(true);
406     onPlaneSelect(0);
407     break;
408   case VISU::CutPlanes::YZ:
409     ((QRadioButton*)mySelPlane->find(1))->setChecked(true);
410     onPlaneSelect(1);
411     break;
412   case VISU::CutPlanes::ZX:      
413     ((QRadioButton*)mySelPlane->find(2))->setChecked(true);
414     onPlaneSelect(2);
415   }
416 }
417
418 //------------------------------------------------------------------------------
419 void VisuGUI_CutLinesDlg::setOrientation2( const VISU::CutPlanes::Orientation  orient )
420 {
421   switch (orient) {
422   case VISU::CutPlanes::XY:
423     ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
424     onCutSelect(0);
425     break;
426   case VISU::CutPlanes::YZ:
427     ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);
428     onCutSelect(1);
429     break;
430   case VISU::CutPlanes::ZX:      
431     ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);
432     onCutSelect(2);
433   }
434 }