Salome HOME
Merge from OCC_development_generic_2006
[modules/gui.git] / src / SVTK / SVTK_NonIsometricDlg.cxx
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
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   : 
25 //  Author : 
26 //  Module : SALOME
27 //  $Header$
28
29 #include "SVTK_NonIsometricDlg.h"
30 #include "SVTK_MainWindow.h"
31 #include "SVTK_Renderer.h"
32
33 #include "QtxDblSpinBox.h"
34 #include "QtxAction.h"
35
36 #include <qgroupbox.h>
37 #include <qlabel.h>
38 #include <qpushbutton.h>
39 #include <qlayout.h>
40
41 using namespace std;
42
43 /*!
44   Constructor
45 */
46 SVTK_NonIsometricDlg
47 ::SVTK_NonIsometricDlg(SVTK_MainWindow* theParent,
48                        const char* theName,
49                        QtxAction* theAction):
50   QDialog(theParent, 
51           theName, 
52           false, 
53           WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
54   m_MainWindow(theParent),
55   m_Action(theAction)
56 {
57   setCaption(tr("DLG_TITLE"));
58   setSizeGripEnabled(TRUE);
59
60   // Create layout for this dialog
61   QGridLayout* layoutDlg = new QGridLayout (this);
62   layoutDlg->setSpacing(6);
63   layoutDlg->setMargin(11);
64
65   // Create croup box with grid layout
66   QGroupBox* GroupBox = new QGroupBox(this, "GroupBox");
67   QGridLayout* glGroupBox = new QGridLayout(GroupBox);
68   glGroupBox->setMargin(11);
69   glGroupBox->setSpacing(6);
70
71   // "X" scaling
72   QLabel* TextLabelX = new QLabel (tr("LBL_X"), GroupBox, "TextLabelX");
73   m_sbXcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox);
74   m_sbXcoeff->setMinimumWidth(80);
75   m_sbXcoeff->setValue(1.0);
76
77   // "Y" scaling
78   QLabel* TextLabelY = new QLabel (tr("LBL_Y"), GroupBox, "TextLabelY");
79   m_sbYcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox);
80   m_sbYcoeff->setMinimumWidth(80);
81   m_sbYcoeff->setValue(1.0);
82
83   // "Z" scaling
84   QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), GroupBox, "TextLabelZ");
85   m_sbZcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox);
86   m_sbZcoeff->setMinimumWidth(80);
87   m_sbZcoeff->setValue(1.0);
88
89   // Create <Reset> button
90   m_bReset = new QPushButton(tr("&Reset"), GroupBox, "m_bReset");
91
92   // Layout widgets in the group box
93   glGroupBox->addWidget(TextLabelX, 0, 0);
94   glGroupBox->addWidget(m_sbXcoeff, 0, 1);
95   glGroupBox->addWidget(TextLabelY, 0, 2);
96   glGroupBox->addWidget(m_sbYcoeff, 0, 3);
97   glGroupBox->addWidget(TextLabelZ, 0, 4);
98   glGroupBox->addWidget(m_sbZcoeff, 0, 5);
99   glGroupBox->addWidget(m_bReset,   0, 6);
100
101   // OK, CANCEL, Apply button
102   QGroupBox* aWgt = new QGroupBox(this);
103   QHBoxLayout* aHBoxLayout = new QHBoxLayout(aWgt);
104   aHBoxLayout->setMargin(11);
105   aHBoxLayout->setSpacing(6);
106   // Create <OK> button
107   QPushButton* m_bOk = new QPushButton(tr("O&K"), aWgt, "m_bOk");
108   m_bOk->setDefault(TRUE);
109   m_bOk->setAutoDefault(TRUE);
110   // Create <Apply> button
111   QPushButton* m_bApply = new QPushButton(tr("&Apply"), aWgt, "m_bApply");
112   m_bApply->setAutoDefault(TRUE);
113   // Create <Cancel> button
114   QPushButton* m_bCancel = new QPushButton(tr("&Cancel"), aWgt, "m_bCancel");
115   m_bCancel->setAutoDefault(TRUE);
116
117   // Layout buttons
118   aHBoxLayout->addWidget(m_bOk);
119   aHBoxLayout->addWidget(m_bApply);
120   aHBoxLayout->addStretch();
121   aHBoxLayout->addWidget(m_bCancel);
122
123   // Layout top level widgets
124   layoutDlg->addWidget(GroupBox,0,0);
125   layoutDlg->addWidget(aWgt,1,0);
126
127   // signals and slots connections
128   connect(m_bCancel, SIGNAL(clicked()), this, SLOT(onClickClose()));
129   connect(m_bOk,     SIGNAL(clicked()), this, SLOT(onClickOk()));
130   connect(m_bApply,  SIGNAL(clicked()), this, SLOT(onClickApply()));
131   connect(m_bReset,  SIGNAL(clicked()), this, SLOT(onClickReset()));
132
133   this->resize(100, this->sizeHint().height());
134 }
135
136 /*
137  *  Destroys the object and frees any allocated resources
138  */
139 SVTK_NonIsometricDlg
140 ::~SVTK_NonIsometricDlg()
141 {
142   // no need to delete child widgets, Qt does it all for us
143 }
144
145 void 
146 SVTK_NonIsometricDlg
147 ::Update()
148 {
149   // Get values from the VTK view
150   double aScaleFactor[3];
151   m_MainWindow->GetScale(aScaleFactor);
152   m_sbXcoeff->setValue(aScaleFactor[0]);
153   m_sbYcoeff->setValue(aScaleFactor[1]);
154   m_sbZcoeff->setValue(aScaleFactor[2]);
155 }
156
157 void 
158 SVTK_NonIsometricDlg
159 ::onClickOk()
160 {
161   //apply changes
162   onClickApply();
163   //Close dialog
164   accept();
165 }
166
167 void
168 SVTK_NonIsometricDlg
169 ::onClickApply()
170 {
171   double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()};
172   m_MainWindow->SetScale(aScale);
173 }
174
175 void
176 SVTK_NonIsometricDlg
177 ::onClickReset()
178 {
179   m_bReset->setFocus();
180   m_sbXcoeff->setValue(1.0);
181   m_sbYcoeff->setValue(1.0);
182   m_sbZcoeff->setValue(1.0);
183 }
184
185 void 
186 SVTK_NonIsometricDlg
187 ::onClickClose()
188 {
189   reject();
190
191   m_Action->setOn( false );
192 }
193
194 void 
195 SVTK_NonIsometricDlg
196 ::done( int r )
197 {
198   m_Action->setOn( false );
199   QDialog::done( r );
200 }