Salome HOME
Copyright update: 2016
[modules/gui.git] / src / OCCViewer / OCCViewer_AxialScaleDlg.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "OCCViewer_AxialScaleDlg.h"
21 #include "OCCViewer_ViewWindow.h"
22 #include "OCCViewer_ViewPort3d.h"
23
24 #include <QtxDoubleSpinBox.h>
25
26 #include <QGroupBox>
27 #include <QLabel>
28 #include <QPushButton>
29 #include <QVBoxLayout>
30 #include <QHBoxLayout>
31
32 /*!
33   \class OCCViewer_AxialScaleDlg
34   \brief Dialog allowing to assign parameters of axes scaling
35 */
36
37 /*!
38   \brief Constructor
39   \param view - view window
40   \param parent - parent widget
41 */
42 OCCViewer_AxialScaleDlg::OCCViewer_AxialScaleDlg( OCCViewer_ViewWindow* view )
43   : QDialog( view ),
44     myView( view )
45 {
46   setWindowTitle( tr( "DLG_SCALING" ) );
47   setModal( false );
48   setSizeGripEnabled( true );
49
50   // Create layout for this dialog
51   QVBoxLayout* layoutDlg = new QVBoxLayout( this );
52   layoutDlg->setSpacing( 6 );
53   layoutDlg->setMargin( 11 );
54
55   // Create croup box with grid layout
56   QGroupBox* aGroupBox = new QGroupBox( this );
57   QHBoxLayout* aHBoxLayout = new QHBoxLayout( aGroupBox );
58   aHBoxLayout->setMargin( 11 );
59   aHBoxLayout->setSpacing( 6 );
60
61   // "X" scaling
62   QLabel* TextLabelX = new QLabel( tr( "LBL_X" ), aGroupBox );
63   m_sbXcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
64   m_sbXcoeff->setMinimumWidth( 80 );
65   m_sbXcoeff->setValue( 1.0 );
66
67   // "Y" scaling
68   QLabel* TextLabelY = new QLabel( tr( "LBL_Y" ), aGroupBox );
69   m_sbYcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
70   m_sbYcoeff->setMinimumWidth( 80 );
71   m_sbYcoeff->setValue( 1.0 );
72
73   // "Z" scaling
74   QLabel* TextLabelZ = new QLabel( tr( "LBL_Z" ), aGroupBox );
75   m_sbZcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
76   m_sbZcoeff->setMinimumWidth( 80 );
77   m_sbZcoeff->setValue( 1.0 );
78
79   // Create <Reset> button
80   m_bReset = new QPushButton( tr( "&Reset" ), aGroupBox );
81
82   // Layout widgets in the group box
83   aHBoxLayout->addWidget( TextLabelX );
84   aHBoxLayout->addWidget( m_sbXcoeff );
85   aHBoxLayout->addWidget( TextLabelY );
86   aHBoxLayout->addWidget( m_sbYcoeff );
87   aHBoxLayout->addWidget( TextLabelZ );
88   aHBoxLayout->addWidget( m_sbZcoeff );
89   aHBoxLayout->addSpacing( 10 );
90   aHBoxLayout->addWidget( m_bReset );
91
92   // OK, CANCEL, Apply button
93   QGroupBox* aGroupBox2 = new QGroupBox( this );
94   QHBoxLayout* aHBoxLayout2 = new QHBoxLayout( aGroupBox2 );
95   aHBoxLayout2->setMargin( 11 );
96   aHBoxLayout2->setSpacing( 6 );
97   // Create <OK> button
98   QPushButton* m_bOk = new QPushButton( tr( "O&K" ), aGroupBox2 );
99   m_bOk->setDefault( true );
100   m_bOk->setAutoDefault( true );
101   // Create <Apply> button
102   QPushButton* m_bApply = new QPushButton( tr( "&Apply" ), aGroupBox2 );
103   m_bApply->setAutoDefault( true );
104   // Create <Cancel> button
105   QPushButton* m_bCancel = new QPushButton( tr( "&Cancel" ), aGroupBox2 );
106   m_bCancel->setAutoDefault( true );
107
108   // Layout buttons
109   aHBoxLayout2->addWidget( m_bOk );
110   aHBoxLayout2->addWidget( m_bApply );
111   aHBoxLayout2->addSpacing( 10 );
112   aHBoxLayout2->addStretch();
113   aHBoxLayout2->addWidget( m_bCancel );
114
115   // Layout top level widgets
116   layoutDlg->addWidget( aGroupBox );
117   layoutDlg->addWidget( aGroupBox2 );
118
119   // signals and slots connections
120   connect( m_bCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
121   connect( m_bOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
122   connect( m_bApply,  SIGNAL( clicked() ), this, SLOT( apply() ) );
123   connect( m_bReset,  SIGNAL( clicked() ), this, SLOT( reset() ) );
124
125   connect( view,      SIGNAL( Hide( QHideEvent* ) ), this, SLOT( hide() ) );
126
127   resize( minimumSizeHint() );
128 }
129
130 /*!
131   \brief Destructor
132 */
133 OCCViewer_AxialScaleDlg::~OCCViewer_AxialScaleDlg()
134 {
135 }
136
137 /*!
138   \brief Update widgets values from the view
139 */
140 void OCCViewer_AxialScaleDlg::Update()
141 {
142   // Get values from the OCC view
143   double aScaleFactor[3];
144   myView->getViewPort()->getAxialScale( aScaleFactor[0], aScaleFactor[1], aScaleFactor[2] );
145   m_sbXcoeff->setValue( aScaleFactor[0] );
146   m_sbYcoeff->setValue( aScaleFactor[1] );
147   m_sbZcoeff->setValue( aScaleFactor[2] );
148 }
149
150 /*!
151   \brief Called when <OK> button is pressed
152 */
153 void OCCViewer_AxialScaleDlg::accept()
154 {
155   if ( apply() )
156     QDialog::accept();
157 }
158
159 /*!
160   \brief Called when <Apply> button is pressed
161 */
162 bool OCCViewer_AxialScaleDlg::apply()
163 {
164   double aScaleFactor[3] = { m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value() };
165   myView->getViewPort()->setAxialScale( aScaleFactor[0], aScaleFactor[1], aScaleFactor[2] );
166   return true;
167 }
168
169 /*!
170   \brief Called when <Reset> button is pressed
171 */
172 void OCCViewer_AxialScaleDlg::reset()
173 {
174   m_bReset->setFocus();
175   m_sbXcoeff->setValue( 1.0 );
176   m_sbYcoeff->setValue( 1.0 );
177   m_sbZcoeff->setValue( 1.0 );
178 }