Salome HOME
NRI : Merge from V1_2.
[modules/visu.git] / src / VISUGUI / VisuGUI_CutPlanesDlg.cxx
1 //  VISU VISUGUI : GUI of VISU 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   : VisuGUI_CutPlanesDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND 
26 //  Module : VISU
27 //  $Header$
28
29 using namespace std;
30 #include "VisuGUI_CutPlanesDlg.h"
31 #include <qlayout.h>
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
34
35 /*!
36   Constructor
37 */
38 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg()
39     : QDialog(  QAD_Application::getDesktop(), "VisuGUI_CutPlanesDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
40 {
41   setCaption( tr( "Cut Planes Definition" ) );
42   setSizeGripEnabled( TRUE );
43
44   QGridLayout* TopLayout = new QGridLayout( this ); 
45   TopLayout->setSpacing( 6 );
46   TopLayout->setMargin( 11 );
47  
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 );
57
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 );
64
65   QLabel* LabelPosi_3 = new QLabel( tr( "Number of planes:" ), this, "LabelPosi_3" );
66
67   nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
68   nbPlan->setValue( 1 );
69   nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
70
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 );
79
80   LabelRot1 = new QLabel( tr( "Rotation around X (Y to Z):" ), GBrot, "LabelRot1" );
81   GBrotLayout->addWidget( LabelRot1, 0, 0 );
82
83   Rot1 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
84   Rot1->setValue( 0 );
85   Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86   GBrotLayout->addWidget( Rot1, 0, 1 );
87
88   LabelRot2 = new QLabel( tr( "Rotation around Y (Z to X):" ), GBrot, "LabelRot2" );
89   GBrotLayout->addWidget( LabelRot2, 1, 0 );
90   
91   Rot2 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
92   Rot2->setValue( 0 );
93   Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94   GBrotLayout->addWidget( Rot2, 1, 1 );
95
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 );
106
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 );
112
113   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons, "buttonCancel" );
114   buttonCancel->setAutoDefault( TRUE );
115   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
116
117   QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
118   myPosSpn = new QAD_SpinBoxDbl( this, 0, 1, 0.1 );
119
120   // layouting
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 );
128
129   // signals and slots connections
130   connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
131   
132   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
133   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
134
135   // default values
136   X1 = 0; X2 = 0;
137   Y1 = 0; Y2 = 0;
138   Z1 = 0; Z2 = 0;
139   RBxy->setChecked( true );
140   orientationChanged( 0 );
141 }
142
143 /*!
144   Destructor
145 */
146 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
147 {
148 }
149
150
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());
156 }
157
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());
164   thePrs->Update();
165 }
166
167 /*!
168   Called when orientation is changed
169 */
170 void VisuGUI_CutPlanesDlg::orientationChanged( int )
171 {
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):" ) );
178   } else { 
179     LabelRot1->setText( tr( "Rotation around Z (X to Y):" ) );
180     LabelRot2->setText( tr( "Rotation around X (Y to Z):" ) );
181   }
182 }
183
184
185
186 /*!
187   Sets bounds ( must be called first )
188 */
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 )
192 {
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 );
197 }
198
199 /*!
200   Sets nb of planes
201 */
202 void VisuGUI_CutPlanesDlg::setNbPlanes( const int nbp )
203 {
204   nbPlan->setValue( nbp );
205 }
206
207 /*!
208   Gets nb of planes
209 */
210 int VisuGUI_CutPlanesDlg::getNbPlanes()
211 {
212   return nbPlan->value();
213 }
214
215 /*!
216   Sets planes orientation and position
217 */
218 void VisuGUI_CutPlanesDlg::setPlanePos( const VISU::CutPlanes::Orientation  orient/*, const double pos1, const double pos2 */)
219 {
220   if ( orient == VISU::CutPlanes::XY )           // xy
221     RBxy->setChecked( true );
222   else if ( orient == VISU::CutPlanes::YZ )       // yz
223     RByz->setChecked( true );
224   else                         // zx
225     RBzx->setChecked( true );
226   orientationChanged( 0 );
227 }
228
229
230 /*!
231   Gets planes orientation
232 */
233 VISU::CutPlanes::Orientation VisuGUI_CutPlanesDlg::getOrientaion()
234 {
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;
242   return orient;
243 }
244
245
246 /*!
247   Sets planes rotation
248 */
249 void VisuGUI_CutPlanesDlg::setRotation( const double r1, const double r2 )
250 {
251   Rot1->setValue( r1 );
252   Rot2->setValue( r2 );
253 }
254
255 /*!
256   Gets plane rotation 1
257 */
258 double VisuGUI_CutPlanesDlg::getRotation1()
259 {
260   return Rot1->value();
261 }
262
263 /*!
264   Gets plane rotation 2
265 */
266 double VisuGUI_CutPlanesDlg::getRotation2()
267 {
268   return Rot2->value();
269 }