Back to index

salome-geom  6.5.0
GEOMToolsGUI_DeflectionDlg.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 //  GEOM GEOMGUI : GUI for Geometry component
00021 //  File   : GEOMToolsGUI_DeflectionDlg.cxx
00022 //  Author : OCC Team
00023 //
00024 #include "GEOMToolsGUI_DeflectionDlg.h"
00025 #include <GeometryGUI.h>
00026 #include <GEOM_Constants.h>
00027 #include <LightApp_Application.h>
00028 #include <SalomeApp_DoubleSpinBox.h>
00029 
00030 #include <SUIT_MessageBox.h>
00031 #include <SUIT_ResourceMgr.h>
00032 #include <SUIT_Session.h>
00033 #include <SUIT_Tools.h>
00034 
00035 #include <QLabel>
00036 #include <QPushButton>
00037 #include <QGroupBox>
00038 #include <QGridLayout>
00039 #include <QKeyEvent>
00040 
00041 //=================================================================================
00042 // class    : GEOMToolsGUI_DeflectionDlg()
00043 // purpose  : Constructs a GEOMToolsGUI_DeflectionDlg which is a child of 'parent', with the
00044 //            name 'name' and widget flags set to 'f'.
00045 //            The dialog will by default be modeless, unless you set 'modal' to
00046 //            TRUE to construct a modal dialog.
00047 //=================================================================================
00048 GEOMToolsGUI_DeflectionDlg::GEOMToolsGUI_DeflectionDlg (QWidget* parent)
00049   : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
00050 {
00051   setObjectName("GEOMToolsGUI_DeflectionDlg");
00052   setModal(true);
00053 
00054   setWindowTitle(tr("GEOM_DEFLECTION_TLT"));
00055   setSizeGripEnabled(TRUE);
00056   QGridLayout* MyDialogLayout = new QGridLayout(this);
00057   MyDialogLayout->setSpacing(6);
00058   MyDialogLayout->setMargin(11);
00059 
00060   /***************************************************************/
00061   QGroupBox* GroupC1 = new QGroupBox (this);
00062   GroupC1->setObjectName("GroupC1");
00063   QGridLayout* GroupC1Layout = new QGridLayout (GroupC1);
00064   GroupC1Layout->setAlignment(Qt::AlignTop);
00065   GroupC1Layout->setSpacing(6);
00066   GroupC1Layout->setMargin(11);
00067 
00068   QLabel* TextLabel1 = new QLabel (GroupC1);
00069   TextLabel1->setObjectName("TextLabel1");
00070   TextLabel1->setText(tr("GEOM_DEFLECTION"));
00071   GroupC1Layout->addWidget(TextLabel1, 0, 0);
00072 
00073   SpinBox = new SalomeApp_DoubleSpinBox (GroupC1);
00074   // Obtain precision from preferences
00075   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00076   const char* quantity = "parametric_precision";
00077   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 ); 
00078   SpinBox->setAcceptNames( false );
00079   SpinBox->setPrecision( aPrecision );
00080   SpinBox->setDecimals( aPrecision );
00081   SpinBox->setRange( DEFLECTION_MIN, 1.0 );
00082   SpinBox->setSingleStep( 1.0e-04 );
00083   // Add a hint for the user saying how to tune precision
00084   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
00085   SpinBox->setProperty( "validity_tune_hint", 
00086                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
00087   
00088   SpinBox->setObjectName("SpinBoxU");
00089   SpinBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
00090   SpinBox->setValue(1.0e-04);
00091   GroupC1Layout->addWidget(SpinBox, 0, 1);
00092 
00093   /***************************************************************/
00094   QGroupBox* GroupButtons = new QGroupBox (this);
00095   GroupButtons->setObjectName("GroupButtons");
00096   QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
00097   GroupButtonsLayout->setAlignment(Qt::AlignTop);
00098   GroupButtonsLayout->setSpacing(6);
00099   GroupButtonsLayout->setMargin(11);
00100 
00101   QPushButton* buttonOk = new QPushButton (GroupButtons);
00102   buttonOk->setObjectName("buttonOk");
00103   buttonOk->setText(tr("GEOM_BUT_OK"));
00104   buttonOk->setAutoDefault(TRUE);
00105   buttonOk->setDefault(TRUE);
00106   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
00107 
00108   GroupButtonsLayout->addItem(new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
00109 
00110   QPushButton* buttonCancel = new QPushButton (GroupButtons);
00111   buttonCancel->setObjectName("buttonCancel");
00112   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
00113   buttonCancel->setAutoDefault(TRUE);
00114   GroupButtonsLayout->addWidget(buttonCancel, 0, 1);
00115 
00116   QPushButton* buttonHelp = new QPushButton (GroupButtons);
00117   buttonHelp->setObjectName("buttonHelp");
00118   buttonHelp->setText(tr("GEOM_BUT_HELP"));
00119   buttonHelp->setAutoDefault(TRUE);
00120   GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
00121   /***************************************************************/
00122 
00123   MyDialogLayout->addWidget(GroupC1, 0, 0);
00124   MyDialogLayout->addWidget(GroupButtons, 1, 0);
00125 
00126   myHelpFileName = "deflection_page.html";
00127 
00128   // signals and slots connections
00129   connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
00130   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
00131   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00132 
00133   // Move widget on the botton right corner of main widget
00134   SUIT_Tools::centerWidget(this, parent);
00135 }
00136 
00137 //=================================================================================
00138 // function : ~GEOMToolsGUI_DeflectionDlg()
00139 // purpose  : Destroys the object and frees any allocated resources
00140 //=================================================================================
00141 GEOMToolsGUI_DeflectionDlg::~GEOMToolsGUI_DeflectionDlg()
00142 {
00143   // no need to delete child widgets, Qt does it all for us
00144 }
00145 
00146 double GEOMToolsGUI_DeflectionDlg::getTheDC() const
00147 {
00148   return SpinBox->text().toDouble();
00149 }
00150 
00151 void GEOMToolsGUI_DeflectionDlg::setTheDC (const double v)
00152 {
00153   SpinBox->setValue(v);
00154 }
00155 
00156 //=================================================================================
00157 // function : ClickOnHelp()
00158 // purpose  :
00159 //=================================================================================
00160 void GEOMToolsGUI_DeflectionDlg::ClickOnHelp()
00161 {
00162   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00163   if (app) {
00164     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>(app->module("Geometry"));
00165     app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
00166   }
00167   else {
00168     QString platform;
00169 #ifdef WIN32
00170     platform = "winapplication";
00171 #else
00172     platform = "application";
00173 #endif
00174     SUIT_MessageBox::warning
00175       (0, QObject::tr("WRN_WARNING"),
00176        QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00177        arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
00178        QObject::tr("BUT_OK"));
00179   }
00180 }
00181 
00182 //=================================================================================
00183 // function : keyPressEvent()
00184 // purpose  :
00185 //=================================================================================
00186 void GEOMToolsGUI_DeflectionDlg::keyPressEvent (QKeyEvent* e)
00187 {
00188   QDialog::keyPressEvent(e);
00189   if (e->isAccepted())
00190     return;
00191 
00192   if (e->key() == Qt::Key_F1) {
00193     e->accept();
00194     ClickOnHelp();
00195   }
00196 }