1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : VisuGUI_CutLinesDlg.cxx
11 #include "VisuGUI_CutLinesDlg.h"
12 #include "VISU_CutLines_i.hh"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
19 #include <qtabwidget.h>
20 #include <qhgroupbox.h>
24 VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg()
25 : QDialog( QAD_Application::getDesktop(), "VisuGUI_CutLinesDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
27 setCaption( "Cut Lines Definition" );
28 setSizeGripEnabled( true );
30 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
31 aMainLayout->setSpacing(5);
36 QTabWidget* aTabPane = new QTabWidget(this);
39 QFrame* aPlanePane = new QFrame(this);
40 QVBoxLayout* aPlaneLayout = new QVBoxLayout( aPlanePane, 5, 6 );
42 mySelPlane = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aPlanePane);
43 mySelPlane->setInsideSpacing( 5 );
44 mySelPlane->setInsideMargin( 5 );
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);
51 aPlaneLayout->addWidget( mySelPlane );
53 QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
54 aRotBox->setColumnLayout(2, Qt::Horizontal );
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 );
63 aPlaneLayout->addWidget( aRotBox );
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);
71 myCBSetDef = new QCheckBox(tr("Set default"),aBaseBox);
73 aPlaneLayout->addWidget( aBaseBox );
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();
83 aTabPane->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
86 QFrame* aLinesPane = new QFrame(this);
87 QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane, 5, 6 );
89 mySelPlane2 = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aLinesPane);
90 mySelPlane2->setInsideSpacing( 5 );
91 mySelPlane2->setInsideMargin( 5 );
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 );
100 QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
101 aRotBox2->setColumnLayout(2, Qt::Horizontal );
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 );
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 );
117 aLinesLayout->addWidget( aNbBox );
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);
125 QHeader *th = myPosTable->horizontalHeader();
126 th->setLabel( 0, "Position" );
127 th->setLabel( 1, "Set default" );
129 aLinesLayout->addWidget( myPosTable );
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();
139 aTabPane->addTab( aLinesPane, tr("LBL_LINES_CUT") );
141 aMainLayout->addWidget(aTabPane);
144 QHBox* aBtnBox = new QHBox(this);
145 QHBoxLayout* aBtnLayout = (QHBoxLayout*) aBtnBox->layout();
146 aBtnLayout->setAutoAdd( false );
147 aBtnLayout->setSpacing( 5 );
149 QPushButton* aOkBtn = new QPushButton(tr( "VISU_BUT_OK" ), aBtnBox);
150 aOkBtn->setAutoDefault( TRUE );
151 aOkBtn->setDefault( true );
152 aBtnLayout->addWidget(aOkBtn);
154 aBtnLayout->addStretch();
156 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
157 aBtnLayout->addWidget(aCloseBtn);
159 aMainLayout->addWidget(aBtnBox);
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( ) ) );
172 connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
173 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
180 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
182 if(myCutLines) delete myCutLines;
185 //------------------------------------------------------------------------------
186 void VisuGUI_CutLinesDlg::initFromPrsObject(VISU::CutLines_i* thePrs) {
188 myRotXSpn->setValue(thePrs->GetRotateX()*180./PI);
189 myRotYSpn->setValue(thePrs->GetRotateY()*180./PI);
190 myPosSpn->setValue(thePrs->GetDisplacement());
191 setOrientation(thePrs->GetOrientationType());
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());
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());
208 //------------------------------------------------------------------------------
209 void VisuGUI_CutLinesDlg::storeToPrsObject(VISU::CutLines_i* thePrs) {
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());
217 thePrs->SetOrientationType2(getOrientaion(false));
218 thePrs->SetRotateX2(myRotXSpn2->value()*PI/180.);
219 thePrs->SetRotateY2(myRotYSpn2->value()*PI/180.);
220 thePrs->SetDisplacement2(myPosSpn2->value());
222 if (!myCBSetDef->isChecked())
223 thePrs->SetBasePlanePosition(myBasePlanePos->text().toDouble());
224 else thePrs->SetDefault();
226 for (int i = 0; i < (int)myNbSpn->value(); ++i)
228 if (!((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked())
229 thePrs->SetLinePosition( i, ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->text().toDouble() );
230 else thePrs->SetDefaultPosition(i);
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);
242 myRotXLbl->setText( tr("LBL_ROT_X"));
243 myRotYLbl->setText( tr("LBL_ROT_Y"));
244 ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);
248 myRotXLbl->setText( tr("LBL_ROT_Y"));
249 myRotYLbl->setText( tr("LBL_ROT_Z"));
250 ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);
254 myRotXLbl->setText( tr("LBL_ROT_Z"));
255 myRotYLbl->setText( tr("LBL_ROT_X"));
256 ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
262 //------------------------------------------------------------------------------
263 void VisuGUI_CutLinesDlg::onCutSelect(int theId) {
266 myRotXLbl2->setText( tr("LBL_ROT_X"));
267 myRotYLbl2->setText( tr("LBL_ROT_Y"));
270 myRotXLbl2->setText( tr("LBL_ROT_Y"));
271 myRotYLbl2->setText( tr("LBL_ROT_Z"));
274 myRotXLbl2->setText( tr("LBL_ROT_Z"));
275 myRotYLbl2->setText( tr("LBL_ROT_X"));
280 //------------------------------------------------------------------------------
281 void VisuGUI_CutLinesDlg::setBaseDefault() {
283 if (!hasInit) return;
285 if ( myCBSetDef->isChecked() )
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);
293 else myBasePlanePos->setEnabled(true);
297 //------------------------------------------------------------------------------
298 void VisuGUI_CutLinesDlg::DrawTable()
300 if (!hasInit) return;
302 int aNbRows = myPosTable->numRows();
303 int aNbPlanes = (int)myNbSpn->value();
306 for (int i = 0; i < aNbRows; ++i)
308 if (!((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked())
309 myCutLines->SetLinePosition( i, ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->text().toDouble() );
312 myCutLines->SetNbLines(aNbPlanes);
313 myCutLines->SetDisplacement2(myPosSpn2->value());
314 myCutLines->SetOrientationType2(getOrientaion(false));
316 if (aNbRows < aNbPlanes)
318 if (aNbRows == 0) myPosTable->setNumRows(aNbPlanes);
319 else myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
321 QHeader *vh = myPosTable->verticalHeader();
324 for (int i = aNbRows; i < myPosTable->numRows(); ++i)
326 QLineEdit *editline = new QLineEdit( myPosTable );
327 editline->setValidator(mydvalidator);
328 myPosTable->setCellWidget( i, 0, editline );
330 QCheckBox *checkbox = new QCheckBox( myPosTable );
331 myPosTable->setCellWidget(i, 1, checkbox );
332 connect(checkbox , SIGNAL( clicked() ), this , SLOT( setDefault() ) );
334 str = str.setNum(i+1);
335 str.prepend ("Plane# ");
336 vh->setLabel( i, str );
339 else if (aNbRows > aNbPlanes)
340 for (int i = aNbRows-1; myPosTable->numRows() != aNbPlanes; --i )
341 myPosTable->removeRow(i);
343 for (int i = 0; i < myPosTable->numRows(); ++i)
345 ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setText( QString::number(myCutLines->GetLinePosition(i)) );
347 if (myCutLines->IsDefaultPosition(i))
349 ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->setChecked(true);
350 ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(false);
355 //------------------------------------------------------------------------------
356 void VisuGUI_CutLinesDlg::setDefault(int all)
358 if (all == 0) return;
361 for (int i = 0; i < (int)myNbSpn->value(); ++i)
362 ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->setChecked(true);
364 for (int i = 0; i < (int)myNbSpn->value(); ++i)
366 if ( ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked() )
368 myCutLines->SetDefaultPosition(i);
369 ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setText( QString::number(myCutLines->GetLinePosition(i)) );
370 ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(false);
372 else ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(true);
376 //------------------------------------------------------------------------------
377 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion(bool IsBasePlane)
386 VISU::CutPlanes::Orientation orient;
387 switch (aBG->id(aBG->selected())) {
389 orient = VISU::CutPlanes::XY;
392 orient = VISU::CutPlanes::YZ;
395 orient = VISU::CutPlanes::ZX;
400 //------------------------------------------------------------------------------
401 void VisuGUI_CutLinesDlg::setOrientation( const VISU::CutPlanes::Orientation orient)
404 case VISU::CutPlanes::XY:
405 ((QRadioButton*)mySelPlane->find(0))->setChecked(true);
408 case VISU::CutPlanes::YZ:
409 ((QRadioButton*)mySelPlane->find(1))->setChecked(true);
412 case VISU::CutPlanes::ZX:
413 ((QRadioButton*)mySelPlane->find(2))->setChecked(true);
418 //------------------------------------------------------------------------------
419 void VisuGUI_CutLinesDlg::setOrientation2( const VISU::CutPlanes::Orientation orient )
422 case VISU::CutPlanes::XY:
423 ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
426 case VISU::CutPlanes::YZ:
427 ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);
430 case VISU::CutPlanes::ZX:
431 ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);