Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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(QtxAction* theAction,
48                        SVTK_MainWindow* theParent,
49                        const char* theName):
50   SVTK_DialogBase(theAction,
51                   theParent, 
52                   theName),
53   m_MainWindow(theParent)
54 {
55   setCaption(tr("DLG_TITLE"));
56   setSizeGripEnabled(TRUE);
57
58   // Create layout for this dialog
59   QGridLayout* layoutDlg = new QGridLayout (this);
60   layoutDlg->setSpacing(6);
61   layoutDlg->setMargin(11);
62
63   // Create croup box with grid layout
64   QGroupBox* aGroupBox = new QGroupBox(this, "GroupBox");
65   QHBoxLayout* aHBoxLayout = new QHBoxLayout(aGroupBox);
66   aHBoxLayout->setMargin(11);
67   aHBoxLayout->setSpacing(6);
68
69   // "X" scaling
70   QLabel* TextLabelX = new QLabel (tr("LBL_X"), aGroupBox, "TextLabelX");
71   TextLabelX->setFixedWidth(15);
72   m_sbXcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, aGroupBox);
73   m_sbXcoeff->setMinimumWidth(80);
74   m_sbXcoeff->setValue(1.0);
75
76   // "Y" scaling
77   QLabel* TextLabelY = new QLabel (tr("LBL_Y"), aGroupBox, "TextLabelY");
78   TextLabelY->setFixedWidth(15);
79   m_sbYcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, aGroupBox);
80   m_sbYcoeff->setMinimumWidth(80);
81   m_sbYcoeff->setValue(1.0);
82
83   // "Z" scaling
84   QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), aGroupBox, "TextLabelZ");
85   TextLabelZ->setFixedWidth(15);
86   m_sbZcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, aGroupBox);
87   m_sbZcoeff->setMinimumWidth(80);
88   m_sbZcoeff->setValue(1.0);
89
90   // Create <Reset> button
91   m_bReset = new QPushButton(tr("&Reset"), aGroupBox, "m_bReset");
92
93   // Layout widgets in the group box
94   aHBoxLayout->addWidget(TextLabelX);
95   aHBoxLayout->addWidget(m_sbXcoeff);
96   aHBoxLayout->addWidget(TextLabelY);
97   aHBoxLayout->addWidget(m_sbYcoeff);
98   aHBoxLayout->addWidget(TextLabelZ);
99   aHBoxLayout->addWidget(m_sbZcoeff);
100   //aHBoxLayout->addStretch();
101   aHBoxLayout->addWidget(m_bReset);
102
103   // OK, CANCEL, Apply button
104   QGroupBox* aGroupBox2 = new QGroupBox(this);
105   QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox2);
106   aHBoxLayout2->setMargin(11);
107   aHBoxLayout2->setSpacing(6);
108   // Create <OK> button
109   QPushButton* m_bOk = new QPushButton(tr("O&K"), aGroupBox2, "m_bOk");
110   m_bOk->setDefault(TRUE);
111   m_bOk->setAutoDefault(TRUE);
112   // Create <Apply> button
113   QPushButton* m_bApply = new QPushButton(tr("&Apply"), aGroupBox2, "m_bApply");
114   m_bApply->setAutoDefault(TRUE);
115   // Create <Cancel> button
116   QPushButton* m_bCancel = new QPushButton(tr("&Cancel"), aGroupBox2, "m_bCancel");
117   m_bCancel->setAutoDefault(TRUE);
118
119   // Layout buttons
120   aHBoxLayout2->addWidget(m_bOk);
121   aHBoxLayout2->addWidget(m_bApply);
122   aHBoxLayout2->addStretch();
123   aHBoxLayout2->addWidget(m_bCancel);
124
125   // Layout top level widgets
126   layoutDlg->addWidget(aGroupBox,0,0);
127   layoutDlg->addWidget(aGroupBox2,1,0);
128
129   // signals and slots connections
130   connect(m_bCancel, SIGNAL(clicked()), this, SLOT(onClickClose()));
131   connect(m_bOk,     SIGNAL(clicked()), this, SLOT(onClickOk()));
132   connect(m_bApply,  SIGNAL(clicked()), this, SLOT(onClickApply()));
133   connect(m_bReset,  SIGNAL(clicked()), this, SLOT(onClickReset()));
134
135   this->resize(100, this->sizeHint().height());
136 }
137
138 /*
139  *  Destroys the object and frees any allocated resources
140  */
141 SVTK_NonIsometricDlg
142 ::~SVTK_NonIsometricDlg()
143 {
144   // no need to delete child widgets, Qt does it all for us
145 }
146
147 void 
148 SVTK_NonIsometricDlg
149 ::Update()
150 {
151   // Get values from the VTK view
152   double aScaleFactor[3];
153   m_MainWindow->GetScale(aScaleFactor);
154   m_sbXcoeff->setValue(aScaleFactor[0]);
155   m_sbYcoeff->setValue(aScaleFactor[1]);
156   m_sbZcoeff->setValue(aScaleFactor[2]);
157 }
158
159 void 
160 SVTK_NonIsometricDlg
161 ::onClickOk()
162 {
163   //apply changes
164   onClickApply();
165   //Close dialog
166   accept();
167 }
168
169 void
170 SVTK_NonIsometricDlg
171 ::onClickApply()
172 {
173   double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()};
174   m_MainWindow->SetScale(aScale);
175 }
176
177 void
178 SVTK_NonIsometricDlg
179 ::onClickReset()
180 {
181   m_bReset->setFocus();
182   m_sbXcoeff->setValue(1.0);
183   m_sbYcoeff->setValue(1.0);
184   m_sbZcoeff->setValue(1.0);
185 }
186
187 void 
188 SVTK_NonIsometricDlg
189 ::onClickClose()
190 {
191   reject();
192 }