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
30 #include "VisuGUI_CutPlanesDlg.h"
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
38 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg()
39 : QDialog( QAD_Application::getDesktop(), "VisuGUI_CutPlanesDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
41 setCaption( tr( "Cut Planes Definition" ) );
42 setSizeGripEnabled( TRUE );
44 QGridLayout* TopLayout = new QGridLayout( this );
45 TopLayout->setSpacing( 6 );
46 TopLayout->setMargin( 11 );
48 QButtonGroup* SelPlane = new QButtonGroup( tr( "Orientation" ), this, "SelPlane" );
49 SelPlane->setTitle( tr( "Orientation" ) );
50 SelPlane->setColumnLayout(0, Qt::Vertical );
51 SelPlane->layout()->setSpacing( 0 );
52 SelPlane->layout()->setMargin( 0 );
53 QGridLayout* SelPlaneLayout = new QGridLayout( SelPlane->layout() );
54 SelPlaneLayout->setAlignment( Qt::AlignTop );
55 SelPlaneLayout->setSpacing( 6 );
56 SelPlaneLayout->setMargin( 11 );
58 RBzx = new QRadioButton( tr( "// Z-X" ), SelPlane, "RBzx" );
59 RByz = new QRadioButton( tr( "// Y-Z" ), SelPlane, "RByz" );
60 RBxy = new QRadioButton( tr( "// X-Y" ), SelPlane, "RBxy" );
61 SelPlaneLayout->addWidget( RBxy, 0, 0 );
62 SelPlaneLayout->addWidget( RByz, 0, 1 );
63 SelPlaneLayout->addWidget( RBzx, 0, 2 );
65 QLabel* LabelPosi_3 = new QLabel( tr( "Number of planes:" ), this, "LabelPosi_3" );
67 nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
68 nbPlan->setValue( 1 );
69 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
71 QGroupBox* GBrot = new QGroupBox( tr( "Rotations" ), this, "GBrot" );
72 GBrot->setColumnLayout(0, Qt::Vertical );
73 GBrot->layout()->setSpacing( 0 );
74 GBrot->layout()->setMargin( 0 );
75 QGridLayout* GBrotLayout = new QGridLayout( GBrot->layout() );
76 GBrotLayout->setAlignment( Qt::AlignTop );
77 GBrotLayout->setSpacing( 6 );
78 GBrotLayout->setMargin( 11 );
80 LabelRot1 = new QLabel( tr( "Rotation around X (Y to Z):" ), GBrot, "LabelRot1" );
81 GBrotLayout->addWidget( LabelRot1, 0, 0 );
83 Rot1 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
85 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86 GBrotLayout->addWidget( Rot1, 0, 1 );
88 LabelRot2 = new QLabel( tr( "Rotation around Y (Z to X):" ), GBrot, "LabelRot2" );
89 GBrotLayout->addWidget( LabelRot2, 1, 0 );
91 Rot2 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
93 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94 GBrotLayout->addWidget( Rot2, 1, 1 );
96 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
97 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
98 GroupButtons->setTitle( tr( "" ) );
99 GroupButtons->setColumnLayout(0, Qt::Vertical );
100 GroupButtons->layout()->setSpacing( 0 );
101 GroupButtons->layout()->setMargin( 0 );
102 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
103 GroupButtonsLayout->setAlignment( Qt::AlignTop );
104 GroupButtonsLayout->setSpacing( 6 );
105 GroupButtonsLayout->setMargin( 11 );
107 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
108 buttonOk->setAutoDefault( TRUE );
109 buttonOk->setDefault( TRUE );
110 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
111 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
113 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons, "buttonCancel" );
114 buttonCancel->setAutoDefault( TRUE );
115 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
117 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
118 myPosSpn = new QAD_SpinBoxDbl( this, 0, 1, 0.1 );
121 TopLayout->addMultiCellWidget( SelPlane, 0, 0, 0, 1 );
122 TopLayout->addWidget( LabelPosi_3, 1, 0 );
123 TopLayout->addWidget( nbPlan, 1, 1 );
124 TopLayout->addMultiCellWidget( GBrot, 2, 2, 0, 1 );
125 TopLayout->addWidget(aPosLbl, 3, 0 );
126 TopLayout->addWidget(myPosSpn, 3, 1 );
127 TopLayout->addMultiCellWidget( GroupButtons, 4, 4, 0, 1 );
129 // signals and slots connections
130 connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
132 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
133 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
139 RBxy->setChecked( true );
140 orientationChanged( 0 );
146 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
151 void VisuGUI_CutPlanesDlg::initFromPrsObject(VISU::CutPlanes_i* thePrs) {
152 setNbPlanes(thePrs->GetNbPlanes());
153 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
154 setPlanePos(thePrs->GetOrientationType());
155 myPosSpn->setValue(thePrs->GetDisplacement());
158 void VisuGUI_CutPlanesDlg::storeToPrsObject(VISU::CutPlanes_i* thePrs) {
159 thePrs->SetNbPlanes(getNbPlanes());
160 thePrs->SetRotateX(getRotation1()*PI/180.);
161 thePrs->SetRotateY(getRotation2()*PI/180.);
162 thePrs->SetOrientationType(getOrientaion());
163 thePrs->SetDisplacement(myPosSpn->value());
168 Called when orientation is changed
170 void VisuGUI_CutPlanesDlg::orientationChanged( int )
172 if ( RBxy->isChecked() ) {
173 LabelRot1->setText( tr( "Rotation around X (Y to Z):" ) );
174 LabelRot2->setText( tr( "Rotation around Y (Z to X):" ) );
175 } else if ( RByz->isChecked() ) {
176 LabelRot1->setText( tr( "Rotation around Y (Z to X):" ) );
177 LabelRot2->setText( tr( "Rotation around Z (X to Y):" ) );
179 LabelRot1->setText( tr( "Rotation around Z (X to Y):" ) );
180 LabelRot2->setText( tr( "Rotation around X (Y to Z):" ) );
187 Sets bounds ( must be called first )
189 void VisuGUI_CutPlanesDlg::setBounds( const double x1, const double x2,
190 const double y1, const double y2,
191 const double z1, const double z2 )
193 X1 = min( x1, x2 ); X2 = max( x1, x2 );
194 Y1 = min( y1, y2 ); Y2 = max( y1, y2 );
195 Z1 = min( z1, z2 ); Z2 = max( z1, z2 );
196 orientationChanged( 0 );
202 void VisuGUI_CutPlanesDlg::setNbPlanes( const int nbp )
204 nbPlan->setValue( nbp );
210 int VisuGUI_CutPlanesDlg::getNbPlanes()
212 return nbPlan->value();
216 Sets planes orientation and position
218 void VisuGUI_CutPlanesDlg::setPlanePos( const VISU::CutPlanes::Orientation orient/*, const double pos1, const double pos2 */)
220 if ( orient == VISU::CutPlanes::XY ) // xy
221 RBxy->setChecked( true );
222 else if ( orient == VISU::CutPlanes::YZ ) // yz
223 RByz->setChecked( true );
225 RBzx->setChecked( true );
226 orientationChanged( 0 );
231 Gets planes orientation
233 VISU::CutPlanes::Orientation VisuGUI_CutPlanesDlg::getOrientaion()
235 VISU::CutPlanes::Orientation orient;
236 if ( RBxy->isChecked() ) // xy
237 orient = VISU::CutPlanes::XY;
238 if ( RByz->isChecked() ) // yz
239 orient = VISU::CutPlanes::YZ;
240 if ( RBzx->isChecked() ) // zx
241 orient = VISU::CutPlanes::ZX;
249 void VisuGUI_CutPlanesDlg::setRotation( const double r1, const double r2 )
251 Rot1->setValue( r1 );
252 Rot2->setValue( r2 );
256 Gets plane rotation 1
258 double VisuGUI_CutPlanesDlg::getRotation1()
260 return Rot1->value();
264 Gets plane rotation 2
266 double VisuGUI_CutPlanesDlg::getRotation2()
268 return Rot2->value();