Back to index

salome-gui  6.5.0
OCCViewer_AxialScaleDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "OCCViewer_AxialScaleDlg.h"
00021 #include "OCCViewer_ViewWindow.h"
00022 #include "OCCViewer_ViewPort3d.h"
00023 
00024 #include <QtxDoubleSpinBox.h>
00025 
00026 #include <QGroupBox>
00027 #include <QLabel>
00028 #include <QPushButton>
00029 #include <QVBoxLayout>
00030 #include <QHBoxLayout>
00031 
00042 OCCViewer_AxialScaleDlg::OCCViewer_AxialScaleDlg( OCCViewer_ViewWindow* view )
00043   : QDialog( view ),
00044     myView( view )
00045 {
00046   setWindowTitle( tr( "DLG_SCALING" ) );
00047   setModal( false );
00048   setSizeGripEnabled( true );
00049 
00050   // Create layout for this dialog
00051   QVBoxLayout* layoutDlg = new QVBoxLayout( this );
00052   layoutDlg->setSpacing( 6 );
00053   layoutDlg->setMargin( 11 );
00054 
00055   // Create croup box with grid layout
00056   QGroupBox* aGroupBox = new QGroupBox( this );
00057   QHBoxLayout* aHBoxLayout = new QHBoxLayout( aGroupBox );
00058   aHBoxLayout->setMargin( 11 );
00059   aHBoxLayout->setSpacing( 6 );
00060 
00061   // "X" scaling
00062   QLabel* TextLabelX = new QLabel( tr( "LBL_X" ), aGroupBox );
00063   m_sbXcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
00064   m_sbXcoeff->setMinimumWidth( 80 );
00065   m_sbXcoeff->setValue( 1.0 );
00066 
00067   // "Y" scaling
00068   QLabel* TextLabelY = new QLabel( tr( "LBL_Y" ), aGroupBox );
00069   m_sbYcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
00070   m_sbYcoeff->setMinimumWidth( 80 );
00071   m_sbYcoeff->setValue( 1.0 );
00072 
00073   // "Z" scaling
00074   QLabel* TextLabelZ = new QLabel( tr( "LBL_Z" ), aGroupBox );
00075   m_sbZcoeff = new QtxDoubleSpinBox( 1e-7, RealLast(), 0.1, aGroupBox );
00076   m_sbZcoeff->setMinimumWidth( 80 );
00077   m_sbZcoeff->setValue( 1.0 );
00078 
00079   // Create <Reset> button
00080   m_bReset = new QPushButton( tr( "&Reset" ), aGroupBox );
00081 
00082   // Layout widgets in the group box
00083   aHBoxLayout->addWidget( TextLabelX );
00084   aHBoxLayout->addWidget( m_sbXcoeff );
00085   aHBoxLayout->addWidget( TextLabelY );
00086   aHBoxLayout->addWidget( m_sbYcoeff );
00087   aHBoxLayout->addWidget( TextLabelZ );
00088   aHBoxLayout->addWidget( m_sbZcoeff );
00089   aHBoxLayout->addSpacing( 10 );
00090   aHBoxLayout->addWidget( m_bReset );
00091 
00092   // OK, CANCEL, Apply button
00093   QGroupBox* aGroupBox2 = new QGroupBox( this );
00094   QHBoxLayout* aHBoxLayout2 = new QHBoxLayout( aGroupBox2 );
00095   aHBoxLayout2->setMargin( 11 );
00096   aHBoxLayout2->setSpacing( 6 );
00097   // Create <OK> button
00098   QPushButton* m_bOk = new QPushButton( tr( "O&K" ), aGroupBox2 );
00099   m_bOk->setDefault( true );
00100   m_bOk->setAutoDefault( true );
00101   // Create <Apply> button
00102   QPushButton* m_bApply = new QPushButton( tr( "&Apply" ), aGroupBox2 );
00103   m_bApply->setAutoDefault( true );
00104   // Create <Cancel> button
00105   QPushButton* m_bCancel = new QPushButton( tr( "&Cancel" ), aGroupBox2 );
00106   m_bCancel->setAutoDefault( true );
00107 
00108   // Layout buttons
00109   aHBoxLayout2->addWidget( m_bOk );
00110   aHBoxLayout2->addWidget( m_bApply );
00111   aHBoxLayout2->addSpacing( 10 );
00112   aHBoxLayout2->addStretch();
00113   aHBoxLayout2->addWidget( m_bCancel );
00114 
00115   // Layout top level widgets
00116   layoutDlg->addWidget( aGroupBox );
00117   layoutDlg->addWidget( aGroupBox2 );
00118 
00119   // signals and slots connections
00120   connect( m_bCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00121   connect( m_bOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
00122   connect( m_bApply,  SIGNAL( clicked() ), this, SLOT( apply() ) );
00123   connect( m_bReset,  SIGNAL( clicked() ), this, SLOT( reset() ) );
00124 
00125   connect( view,      SIGNAL( Hide( QHideEvent* ) ), this, SLOT( hide() ) );
00126 
00127   resize( minimumSizeHint() );
00128 }
00129 
00133 OCCViewer_AxialScaleDlg::~OCCViewer_AxialScaleDlg()
00134 {
00135 }
00136 
00140 void OCCViewer_AxialScaleDlg::Update()
00141 {
00142   // Get values from the OCC view
00143   double aScaleFactor[3];
00144   myView->getViewPort()->getAxialScale( aScaleFactor[0], aScaleFactor[1], aScaleFactor[2] );
00145   m_sbXcoeff->setValue( aScaleFactor[0] );
00146   m_sbYcoeff->setValue( aScaleFactor[1] );
00147   m_sbZcoeff->setValue( aScaleFactor[2] );
00148 }
00149 
00153 void OCCViewer_AxialScaleDlg::accept()
00154 {
00155   if ( apply() )
00156     QDialog::accept();
00157 }
00158 
00162 bool OCCViewer_AxialScaleDlg::apply()
00163 {
00164   double aScaleFactor[3] = { m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value() };
00165   myView->getViewPort()->setAxialScale( aScaleFactor[0], aScaleFactor[1], aScaleFactor[2] );
00166   return true;
00167 }
00168 
00172 void OCCViewer_AxialScaleDlg::reset()
00173 {
00174   m_bReset->setFocus();
00175   m_sbXcoeff->setValue( 1.0 );
00176   m_sbYcoeff->setValue( 1.0 );
00177   m_sbZcoeff->setValue( 1.0 );
00178 }