Salome HOME
30456da215a4be62bc60003d20d096d4ffaddda0
[modules/gui.git] / src / OCCViewer / OCCViewer_AxialScaleDlg.cxx
1 // Copyright (C) 2007-2023  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 #include "OCCViewer_ViewModel.h"
24
25 #include <QtxDoubleSpinBox.h>
26
27 #include <QGroupBox>
28 #include <QLabel>
29 #include <QPushButton>
30 #include <QVBoxLayout>
31 #include <QHBoxLayout>
32
33 /*!
34   \class OCCViewer_AxialScaleDlg
35   \brief Dialog allowing to assign parameters of axes scaling
36 */
37
38 /*!
39   \brief Constructor
40   \param view - view window
41   \param parent - parent widget
42 */
43 OCCViewer_AxialScaleDlg::OCCViewer_AxialScaleDlg( OCCViewer_ViewWindow* view, OCCViewer_Viewer* model )
44   : QDialog( view ),
45     myView( view ),
46     myModel( model )
47 {
48   setWindowTitle( tr( "DLG_SCALING" ) );
49   setModal( false );
50   setSizeGripEnabled( true );
51
52   // Create layout for this dialog
53   QVBoxLayout* layoutDlg = new QVBoxLayout( this );
54   layoutDlg->setSpacing( 6 );
55   layoutDlg->setMargin( 11 );
56
57   // Create croup box with grid layout
58   QGroupBox* aGroupBox = new QGroupBox( this );
59   QHBoxLayout* aHBoxLayout = new QHBoxLayout( aGroupBox );
60   aHBoxLayout->setMargin( 11 );
61   aHBoxLayout->setSpacing( 6 );
62
63   // "X" scaling
64   QLabel* TextLabelX = new QLabel( tr( "LBL_X" ), aGroupBox );
65   m_sbXcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
66   m_sbXcoeff->setMinimumWidth( 80 );
67   m_sbXcoeff->setValue( 1.0 );
68
69   // "Y" scaling
70   QLabel* TextLabelY = new QLabel( tr( "LBL_Y" ), aGroupBox );
71   m_sbYcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
72   m_sbYcoeff->setMinimumWidth( 80 );
73   m_sbYcoeff->setValue( 1.0 );
74
75   // "Z" scaling
76   QLabel* TextLabelZ = new QLabel( tr( "LBL_Z" ), aGroupBox );
77   m_sbZcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
78   m_sbZcoeff->setMinimumWidth( 80 );
79   m_sbZcoeff->setValue( 1.0 );
80
81   // Create <Reset> button
82   m_bReset = new QPushButton( tr( "&Reset" ), aGroupBox );
83
84   // Layout widgets in the group box
85   aHBoxLayout->addWidget( TextLabelX );
86   aHBoxLayout->addWidget( m_sbXcoeff );
87   aHBoxLayout->addWidget( TextLabelY );
88   aHBoxLayout->addWidget( m_sbYcoeff );
89   aHBoxLayout->addWidget( TextLabelZ );
90   aHBoxLayout->addWidget( m_sbZcoeff );
91   aHBoxLayout->addSpacing( 10 );
92   aHBoxLayout->addWidget( m_bReset );
93
94   // OK, CANCEL, Apply button
95   QGroupBox* aGroupBox2 = new QGroupBox( this );
96   QHBoxLayout* aHBoxLayout2 = new QHBoxLayout( aGroupBox2 );
97   aHBoxLayout2->setMargin( 11 );
98   aHBoxLayout2->setSpacing( 6 );
99   // Create <OK> button
100   QPushButton* m_bOk = new QPushButton( tr( "O&K" ), aGroupBox2 );
101   m_bOk->setDefault( true );
102   m_bOk->setAutoDefault( true );
103   // Create <Apply> button
104   QPushButton* m_bApply = new QPushButton( tr( "&Apply" ), aGroupBox2 );
105   m_bApply->setAutoDefault( true );
106   // Create <Cancel> button
107   QPushButton* m_bCancel = new QPushButton( tr( "&Cancel" ), aGroupBox2 );
108   m_bCancel->setAutoDefault( true );
109
110   // Layout buttons
111   aHBoxLayout2->addWidget( m_bOk );
112   aHBoxLayout2->addWidget( m_bApply );
113   aHBoxLayout2->addSpacing( 10 );
114   aHBoxLayout2->addStretch();
115   aHBoxLayout2->addWidget( m_bCancel );
116
117   // Layout top level widgets
118   layoutDlg->addWidget( aGroupBox );
119   layoutDlg->addWidget( aGroupBox2 );
120
121   // signals and slots connections
122   connect( m_bCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
123   connect( m_bOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
124   connect( m_bApply,  SIGNAL( clicked() ), this, SLOT( apply() ) );
125   connect( m_bReset,  SIGNAL( clicked() ), this, SLOT( reset() ) );
126
127   connect( view,      SIGNAL( Hide( QHideEvent* ) ), this, SLOT( hide() ) );
128
129   resize( minimumSizeHint() );
130 }
131
132 /*!
133   \brief Destructor
134 */
135 OCCViewer_AxialScaleDlg::~OCCViewer_AxialScaleDlg()
136 {
137   myModel = 0;
138 }
139
140 /*!
141   \brief Update widgets values from the view
142 */
143 void OCCViewer_AxialScaleDlg::Update()
144 {
145   // Get values from the OCC view
146   double aScaleFactor[3];
147   myView->getViewPort()->getAxialScale( aScaleFactor[0], aScaleFactor[1], aScaleFactor[2] );
148   m_sbXcoeff->setValue( aScaleFactor[0] );
149   m_sbYcoeff->setValue( aScaleFactor[1] );
150   m_sbZcoeff->setValue( aScaleFactor[2] );
151 }
152
153 /*!
154   \brief Called when <OK> button is pressed
155 */
156 void OCCViewer_AxialScaleDlg::accept()
157 {
158   if ( apply() )
159     QDialog::accept();
160 }
161
162 /*!
163   \brief Called when <Apply> button is pressed
164 */
165 bool OCCViewer_AxialScaleDlg::apply()
166 {
167   double aScaleFactor[3] = { m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value() };
168   myView->getViewPort()->setAxialScale( aScaleFactor[0], aScaleFactor[1], aScaleFactor[2] );
169   
170   if( myModel && !myModel->getViewer3d().IsNull() ){
171     myModel->getViewer3d()->Update();
172   }
173   
174   return true;
175 }
176
177 /*!
178   \brief Called when <Reset> button is pressed
179 */
180 void OCCViewer_AxialScaleDlg::reset()
181 {
182   m_bReset->setFocus();
183   m_sbXcoeff->setValue( 1.0 );
184   m_sbYcoeff->setValue( 1.0 );
185   m_sbZcoeff->setValue( 1.0 );
186 }