1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_CutPlanesDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_CutPlanesDlg.h"
30 #include "VISU_CutPlanes_i.hh"
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
36 #include <qcheckbox.h>
39 #include <qvalidator.h>
40 #include <qlineedit.h>
47 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg()
48 : QDialog( QAD_Application::getDesktop(), "VisuGUI_CutPlanesDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
50 setCaption( tr( "Cut Planes Definition" ) );
51 setSizeGripEnabled( TRUE );
53 QGridLayout* TopLayout = new QGridLayout( this );
54 TopLayout->setSpacing( 6 );
55 TopLayout->setMargin( 11 );
57 QButtonGroup* SelPlane = new QButtonGroup( tr( "Orientation" ), this, "SelPlane" );
58 SelPlane->setTitle( tr( "Orientation" ) );
59 SelPlane->setColumnLayout(0, Qt::Vertical );
60 SelPlane->layout()->setSpacing( 0 );
61 SelPlane->layout()->setMargin( 0 );
62 QGridLayout* SelPlaneLayout = new QGridLayout( SelPlane->layout() );
63 SelPlaneLayout->setAlignment( Qt::AlignTop );
64 SelPlaneLayout->setSpacing( 6 );
65 SelPlaneLayout->setMargin( 11 );
67 RBzx = new QRadioButton( tr( "// Z-X" ), SelPlane, "RBzx" );
68 RByz = new QRadioButton( tr( "// Y-Z" ), SelPlane, "RByz" );
69 RBxy = new QRadioButton( tr( "// X-Y" ), SelPlane, "RBxy" );
70 SelPlaneLayout->addWidget( RBxy, 0, 0 );
71 SelPlaneLayout->addWidget( RByz, 0, 1 );
72 SelPlaneLayout->addWidget( RBzx, 0, 2 );
74 QLabel* LabelPosi_3 = new QLabel( tr( "Number of planes:" ), this, "LabelPosi_3" );
76 nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
77 nbPlan->setValue( 1 );
78 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
80 myPosTable = new QTable(this, "Positions of planes" );
81 myPosTable->setMaximumHeight( 227 );
82 myPosTable->setMinimumWidth( 294 );
83 //myPosTable->setGeometry( QRect( 11, 98, 289, 325 ) );
84 myPosTable->setNumCols(2);
85 myPosTable->setNumRows(0);
87 QHeader *th = myPosTable->horizontalHeader();
88 th->setLabel( 0, "Position" );
89 th->setLabel( 1, "Set default" );
91 QGroupBox* GBrot = new QGroupBox( tr( "Rotations" ), this, "GBrot" );
92 GBrot->setColumnLayout(0, Qt::Vertical );
93 GBrot->layout()->setSpacing( 0 );
94 GBrot->layout()->setMargin( 0 );
95 QGridLayout* GBrotLayout = new QGridLayout( GBrot->layout() );
96 GBrotLayout->setAlignment( Qt::AlignTop );
97 GBrotLayout->setSpacing( 6 );
98 GBrotLayout->setMargin( 11 );
100 LabelRot1 = new QLabel( tr( "Rotation around X (Y to Z):" ), GBrot, "LabelRot1" );
101 GBrotLayout->addWidget( LabelRot1, 0, 0 );
103 Rot1 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
105 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
106 GBrotLayout->addWidget( Rot1, 0, 1 );
108 LabelRot2 = new QLabel( tr( "Rotation around Y (Z to X):" ), GBrot, "LabelRot2" );
109 GBrotLayout->addWidget( LabelRot2, 1, 0 );
111 Rot2 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
113 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
114 GBrotLayout->addWidget( Rot2, 1, 1 );
116 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
117 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
118 GroupButtons->setTitle( tr( "" ) );
119 GroupButtons->setColumnLayout(0, Qt::Vertical );
120 GroupButtons->layout()->setSpacing( 0 );
121 GroupButtons->layout()->setMargin( 0 );
122 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
123 GroupButtonsLayout->setAlignment( Qt::AlignTop );
124 GroupButtonsLayout->setSpacing( 6 );
125 GroupButtonsLayout->setMargin( 11 );
127 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
128 buttonOk->setAutoDefault( TRUE );
129 buttonOk->setDefault( TRUE );
130 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
131 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
133 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons, "buttonCancel" );
134 buttonCancel->setAutoDefault( TRUE );
135 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
137 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
138 myPosSpn = new QAD_SpinBoxDbl( this, 0, 1, 0.1 );
140 th->setStyle("QStyle::CE_PushButton");
143 TopLayout->addMultiCellWidget( SelPlane, 0, 0, 0, 1 );
144 TopLayout->addMultiCellWidget( GBrot, 1, 1, 0, 1 );
145 TopLayout->addWidget( LabelPosi_3, 2, 0 );
146 TopLayout->addWidget( nbPlan, 2, 1 );
147 TopLayout->addMultiCellWidget( myPosTable, 3, 3, 0, 1 );
148 TopLayout->setRowStretch ( 3, 3 );
149 TopLayout->addWidget(aPosLbl, 4, 0 );
150 TopLayout->addWidget(myPosSpn, 4, 1 );
151 TopLayout->addMultiCellWidget( GroupButtons, 5, 5, 0, 1 );
153 // signals and slots connections
154 connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
155 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
156 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
157 connect( RBzx, SIGNAL( toggled(bool)), this, SLOT( DrawTable( ) ) );
158 connect( RByz, SIGNAL( toggled(bool)), this, SLOT( DrawTable( ) ) );
159 connect( RBxy, SIGNAL( toggled(bool)), this, SLOT( DrawTable( ) ) );
160 connect( th, SIGNAL( clicked(int)), this, SLOT( setDefault(int) ) );
162 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
163 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
172 RByz->setChecked( true );
173 orientationChanged( 0 );
179 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
181 if(myCutPlanes) delete myCutPlanes;
185 void VisuGUI_CutPlanesDlg::initFromPrsObject(VISU::CutPlanes_i* thePrs) {
186 setNbPlanes(thePrs->GetNbPlanes());
187 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
188 setPlanePos(thePrs->GetOrientationType());
189 myPosSpn->setValue(thePrs->GetDisplacement());
192 myCutPlanes = new VISU::CutPlanes_i(thePrs->GetResult(),false);
193 myCutPlanes->SameAs(thePrs);
197 void VisuGUI_CutPlanesDlg::storeToPrsObject(VISU::CutPlanes_i* thePrs) {
198 thePrs->SetNbPlanes(getNbPlanes());
199 thePrs->SetRotateX(getRotation1()*PI/180.);
200 thePrs->SetRotateY(getRotation2()*PI/180.);
201 thePrs->SetOrientationType(getOrientaion());
202 thePrs->SetDisplacement(myPosSpn->value());
203 for (int i = 0; i < getNbPlanes(); ++i)
205 if (!((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked())
206 thePrs->SetPlanePosition( i, ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->text().toDouble() );
207 else thePrs->SetDefault(i);
212 Called when orientation is changed
214 void VisuGUI_CutPlanesDlg::orientationChanged( int )
216 if ( RBxy->isChecked() ) {
217 LabelRot1->setText( tr( "Rotation around X (Y to Z):" ) );
218 LabelRot2->setText( tr( "Rotation around Y (Z to X):" ) );
219 } else if ( RByz->isChecked() ) {
220 LabelRot1->setText( tr( "Rotation around Y (Z to X):" ) );
221 LabelRot2->setText( tr( "Rotation around Z (X to Y):" ) );
223 LabelRot1->setText( tr( "Rotation around Z (X to Y):" ) );
224 LabelRot2->setText( tr( "Rotation around X (Y to Z):" ) );
231 Sets bounds ( must be called first )
233 void VisuGUI_CutPlanesDlg::setBounds( const double x1, const double x2,
234 const double y1, const double y2,
235 const double z1, const double z2 )
237 X1 = min( x1, x2 ); X2 = max( x1, x2 );
238 Y1 = min( y1, y2 ); Y2 = max( y1, y2 );
239 Z1 = min( z1, z2 ); Z2 = max( z1, z2 );
240 orientationChanged( 0 );
246 void VisuGUI_CutPlanesDlg::setNbPlanes( const int nbp )
248 nbPlan->setValue( nbp );
254 int VisuGUI_CutPlanesDlg::getNbPlanes()
256 return nbPlan->value();
260 Sets planes orientation and position
262 void VisuGUI_CutPlanesDlg::setPlanePos( const VISU::CutPlanes::Orientation orient/*, const double pos1, const double pos2 */)
264 if ( orient == VISU::CutPlanes::XY ) // xy
265 RBxy->setChecked( true );
266 else if ( orient == VISU::CutPlanes::YZ ) // yz
267 RByz->setChecked( true );
269 RBzx->setChecked( true );
270 orientationChanged( 0 );
275 Gets planes orientation
277 VISU::CutPlanes::Orientation VisuGUI_CutPlanesDlg::getOrientaion()
279 VISU::CutPlanes::Orientation orient;
280 if ( RBxy->isChecked() ) // xy
281 orient = VISU::CutPlanes::XY;
282 if ( RByz->isChecked() ) // yz
283 orient = VISU::CutPlanes::YZ;
284 if ( RBzx->isChecked() ) // zx
285 orient = VISU::CutPlanes::ZX;
293 void VisuGUI_CutPlanesDlg::setRotation( const double r1, const double r2 )
295 Rot1->setValue( r1 );
296 Rot2->setValue( r2 );
300 Gets plane rotation 1
302 double VisuGUI_CutPlanesDlg::getRotation1()
304 return Rot1->value();
308 Gets plane rotation 2
310 double VisuGUI_CutPlanesDlg::getRotation2()
312 return Rot2->value();
316 Draw the table of planes positions
319 void VisuGUI_CutPlanesDlg::DrawTable()
321 if (!hasInit) return;
323 int aNbRows = myPosTable->numRows();
324 int aNbPlanes = getNbPlanes();
327 for (int i = 0; i < aNbRows; ++i)
329 if (!((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked())
330 myCutPlanes->SetPlanePosition( i, ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->text().toDouble() );
333 myCutPlanes->SetNbPlanes(aNbPlanes);
334 myCutPlanes->SetDisplacement(myPosSpn->value());
335 myCutPlanes->SetOrientationType(getOrientaion());
337 if (aNbRows < aNbPlanes)
339 if (aNbRows == 0) myPosTable->setNumRows(aNbPlanes);
340 else myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
342 QHeader *vh = myPosTable->verticalHeader();
345 QDoubleValidator *dvalidator = new QDoubleValidator(myPosTable);
346 dvalidator->setDecimals(32);
348 for (int i = aNbRows; i < myPosTable->numRows(); ++i)
350 QLineEdit *editline = new QLineEdit( myPosTable );
351 editline->setValidator(dvalidator);
352 myPosTable->setCellWidget( i, 0, editline );
354 QCheckBox *checkbox = new QCheckBox( myPosTable );
355 myPosTable->setCellWidget(i, 1, checkbox );
356 connect(checkbox , SIGNAL( clicked() ), this , SLOT( setDefault() ) );
358 str = str.setNum(i+1);
359 str.prepend ("Plane# ");
360 vh->setLabel( i, str );
363 else if (aNbRows > aNbPlanes)
364 for (int i = aNbRows-1; myPosTable->numRows() != aNbPlanes; --i )
365 myPosTable->removeRow(i);
367 for (int i = 0; i < myPosTable->numRows(); ++i)
369 ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setText( QString::number(myCutPlanes->GetPlanePosition(i)) );
371 if (myCutPlanes->IsDefault(i))
373 ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->setChecked(true);
374 ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(false);
379 void VisuGUI_CutPlanesDlg::setDefault(int all)
381 if (all == 0) return;
384 for (int i = 0; i < getNbPlanes(); ++i)
385 ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->setChecked(true);
387 for (int i = 0; i < getNbPlanes(); ++i)
389 if ( ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked() )
391 myCutPlanes->SetDefault(i);
392 ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setText( QString::number(myCutPlanes->GetPlanePosition(i)) );
393 ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(false);
395 else ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(true);