Salome HOME
Copyright update 2022
[modules/gui.git] / src / SVTK / SVTK_NonIsometricDlg.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME VTKViewer : build VTK viewer into Salome desktop
24 //  File   : 
25 //  Author : 
26
27 #include "SVTK_NonIsometricDlg.h"
28 #include "SVTK_ViewWindow.h"
29 #include "SVTK_Renderer.h"
30
31 #include "QtxDoubleSpinBox.h"
32 #include "QtxAction.h"
33
34 #include <QGroupBox>
35 #include <QLabel>
36 #include <QPushButton>
37 #include <QGridLayout>
38
39 /*!
40   Constructor
41 */
42 SVTK_NonIsometricDlg
43 ::SVTK_NonIsometricDlg(QtxAction* theAction,
44                        SVTK_ViewWindow* theParent,
45                        const char* theName):
46   ViewerTools_DialogBase(theAction,
47                          theParent, 
48                          theName),
49   m_MainWindow(theParent)
50 {
51   setWindowTitle(tr("DLG_TITLE"));
52   setSizeGripEnabled(true);
53
54   // Create layout for this dialog
55   QGridLayout* layoutDlg = new QGridLayout (this);
56   layoutDlg->setSpacing(6);
57   layoutDlg->setMargin(11);
58
59   // Create croup box with grid layout
60   QGroupBox* aGroupBox = new QGroupBox(this);
61   aGroupBox->setObjectName("GroupBox");
62   QHBoxLayout* aHBoxLayout = new QHBoxLayout(aGroupBox);
63   aHBoxLayout->setMargin(11);
64   aHBoxLayout->setSpacing(6);
65
66   // "X" scaling
67   QLabel* TextLabelX = new QLabel (tr("LBL_X"), aGroupBox);
68   TextLabelX->setObjectName("TextLabelX");
69   TextLabelX->setFixedWidth(15);
70   m_sbXcoeff = new QtxDoubleSpinBox(-VTK_FLOAT_MAX, VTK_FLOAT_MAX, 0.1, aGroupBox);
71   m_sbXcoeff->setMinimumWidth(80);
72   m_sbXcoeff->setValue(1.0);
73
74   // "Y" scaling
75   QLabel* TextLabelY = new QLabel (tr("LBL_Y"), aGroupBox);
76   TextLabelY->setObjectName("TextLabelY");
77   TextLabelY->setFixedWidth(15);
78   m_sbYcoeff = new QtxDoubleSpinBox(-VTK_FLOAT_MAX, VTK_FLOAT_MAX, 0.1, aGroupBox);
79   m_sbYcoeff->setMinimumWidth(80);
80   m_sbYcoeff->setValue(1.0);
81
82   // "Z" scaling
83   QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), aGroupBox);
84   TextLabelZ->setObjectName("TextLabelZ");
85   TextLabelZ->setFixedWidth(15);
86   m_sbZcoeff = new QtxDoubleSpinBox(-VTK_FLOAT_MAX, VTK_FLOAT_MAX, 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);
92   m_bReset->setObjectName("m_bReset");
93
94   // Layout widgets in the group box
95   aHBoxLayout->addWidget(TextLabelX);
96   aHBoxLayout->addWidget(m_sbXcoeff);
97   aHBoxLayout->addWidget(TextLabelY);
98   aHBoxLayout->addWidget(m_sbYcoeff);
99   aHBoxLayout->addWidget(TextLabelZ);
100   aHBoxLayout->addWidget(m_sbZcoeff);
101   //aHBoxLayout->addStretch();
102   aHBoxLayout->addWidget(m_bReset);
103
104   // OK, CANCEL, Apply button
105   QGroupBox* aGroupBox2 = new QGroupBox(this);
106   QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox2);
107   aHBoxLayout2->setMargin(11);
108   aHBoxLayout2->setSpacing(6);
109   // Create <OK> button
110   QPushButton* m_bOk = new QPushButton(tr("O&K"), aGroupBox2);
111   m_bOk->setObjectName("m_bOk");
112   m_bOk->setDefault(true);
113   m_bOk->setAutoDefault(true);
114   // Create <Apply> button
115   QPushButton* m_bApply = new QPushButton(tr("&Apply"), aGroupBox2);
116   m_bApply->setObjectName("m_bApply");
117   m_bApply->setAutoDefault(true);
118   // Create <Cancel> button
119   QPushButton* m_bCancel = new QPushButton(tr("&Cancel"), aGroupBox2);
120   m_bCancel->setObjectName("m_bCancel");
121   m_bCancel->setAutoDefault(true);
122
123   // Layout buttons
124   aHBoxLayout2->addWidget(m_bOk);
125   aHBoxLayout2->addWidget(m_bApply);
126   aHBoxLayout2->addStretch();
127   aHBoxLayout2->addWidget(m_bCancel);
128
129   // Layout top level widgets
130   layoutDlg->addWidget(aGroupBox,0,0);
131   layoutDlg->addWidget(aGroupBox2,1,0);
132
133   // signals and slots connections
134   connect(m_bCancel, SIGNAL(clicked()), this, SLOT(onClickClose()));
135   connect(m_bOk,     SIGNAL(clicked()), this, SLOT(onClickOk()));
136   connect(m_bApply,  SIGNAL(clicked()), this, SLOT(onClickApply()));
137   connect(m_bReset,  SIGNAL(clicked()), this, SLOT(onClickReset()));
138
139   this->resize(100, this->sizeHint().height());
140 }
141
142 /*
143  *  Destroys the object and frees any allocated resources
144  */
145 SVTK_NonIsometricDlg
146 ::~SVTK_NonIsometricDlg()
147 {
148   // no need to delete child widgets, Qt does it all for us
149 }
150
151 void 
152 SVTK_NonIsometricDlg
153 ::Update()
154 {
155   // Get values from the VTK view
156   double aScaleFactor[3];
157   m_MainWindow->GetScale(aScaleFactor);
158   m_sbXcoeff->setValue(aScaleFactor[0]);
159   m_sbYcoeff->setValue(aScaleFactor[1]);
160   m_sbZcoeff->setValue(aScaleFactor[2]);
161 }
162
163 void 
164 SVTK_NonIsometricDlg
165 ::onClickOk()
166 {
167   //apply changes
168   onClickApply();
169   //Close dialog
170   accept();
171 }
172
173 void
174 SVTK_NonIsometricDlg
175 ::onClickApply()
176 {
177   double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()};
178   m_MainWindow->SetScale(aScale);
179 }
180
181 void
182 SVTK_NonIsometricDlg
183 ::onClickReset()
184 {
185   m_bReset->setFocus();
186   m_sbXcoeff->setValue(1.0);
187   m_sbYcoeff->setValue(1.0);
188   m_sbZcoeff->setValue(1.0);
189 }
190
191 void 
192 SVTK_NonIsometricDlg
193 ::onClickClose()
194 {
195   reject();
196 }