Salome HOME
Fix problem of change transparency operation: initial transparency is set incorrectly...
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_DeflectionDlg.cxx
1 //  Copyright (C) 2007-2010  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.
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 //  GEOM GEOMGUI : GUI for Geometry component
21 //  File   : GEOMToolsGUI_DeflectionDlg.cxx
22 //  Author : OCC Team
23 //
24 #include "GEOMToolsGUI_DeflectionDlg.h"
25 #include <GeometryGUI.h>
26 #include <LightApp_Application.h>
27 #include <SalomeApp_DoubleSpinBox.h>
28
29 #include <SUIT_MessageBox.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Tools.h>
33
34 #include <QLabel>
35 #include <QPushButton>
36 #include <QGroupBox>
37 #include <QGridLayout>
38 #include <QKeyEvent>
39
40 //=================================================================================
41 // class    : GEOMToolsGUI_DeflectionDlg()
42 // purpose  : Constructs a GEOMToolsGUI_DeflectionDlg which is a child of 'parent', with the
43 //            name 'name' and widget flags set to 'f'.
44 //            The dialog will by default be modeless, unless you set 'modal' to
45 //            TRUE to construct a modal dialog.
46 //=================================================================================
47 GEOMToolsGUI_DeflectionDlg::GEOMToolsGUI_DeflectionDlg (QWidget* parent)
48   : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
49 {
50   setObjectName("GEOMToolsGUI_DeflectionDlg");
51   setModal(true);
52
53   setWindowTitle(tr("GEOM_DEFLECTION_TLT"));
54   setSizeGripEnabled(TRUE);
55   QGridLayout* MyDialogLayout = new QGridLayout(this);
56   MyDialogLayout->setSpacing(6);
57   MyDialogLayout->setMargin(11);
58
59   /***************************************************************/
60   QGroupBox* GroupC1 = new QGroupBox (this);
61   GroupC1->setObjectName("GroupC1");
62   QGridLayout* GroupC1Layout = new QGridLayout (GroupC1);
63   GroupC1Layout->setAlignment(Qt::AlignTop);
64   GroupC1Layout->setSpacing(6);
65   GroupC1Layout->setMargin(11);
66
67   QLabel* TextLabel1 = new QLabel (GroupC1);
68   TextLabel1->setObjectName("TextLabel1");
69   TextLabel1->setText(tr("GEOM_DEFLECTION"));
70   GroupC1Layout->addWidget(TextLabel1, 0, 0);
71
72   SpinBox = new SalomeApp_DoubleSpinBox (GroupC1);
73   // Obtain precision from preferences
74   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
75   const char* quantity = "parametric_precision";
76   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 ); 
77   SpinBox->setAcceptNames( false );
78   SpinBox->setPrecision( aPrecision );
79   SpinBox->setDecimals( aPrecision );
80   SpinBox->setRange( DEFLECTION_MIN, 1.0 );
81   SpinBox->setSingleStep( 1.0e-04 );
82   // Add a hint for the user saying how to tune precision
83   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
84   SpinBox->setProperty( "validity_tune_hint", 
85                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
86   
87   SpinBox->setObjectName("SpinBoxU");
88   SpinBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
89   SpinBox->setValue(1.0e-04);
90   GroupC1Layout->addWidget(SpinBox, 0, 1);
91
92   /***************************************************************/
93   QGroupBox* GroupButtons = new QGroupBox (this);
94   GroupButtons->setObjectName("GroupButtons");
95   QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
96   GroupButtonsLayout->setAlignment(Qt::AlignTop);
97   GroupButtonsLayout->setSpacing(6);
98   GroupButtonsLayout->setMargin(11);
99
100   QPushButton* buttonOk = new QPushButton (GroupButtons);
101   buttonOk->setObjectName("buttonOk");
102   buttonOk->setText(tr("GEOM_BUT_OK"));
103   buttonOk->setAutoDefault(TRUE);
104   buttonOk->setDefault(TRUE);
105   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
106
107   GroupButtonsLayout->addItem(new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
108
109   QPushButton* buttonCancel = new QPushButton (GroupButtons);
110   buttonCancel->setObjectName("buttonCancel");
111   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
112   buttonCancel->setAutoDefault(TRUE);
113   GroupButtonsLayout->addWidget(buttonCancel, 0, 1);
114
115   QPushButton* buttonHelp = new QPushButton (GroupButtons);
116   buttonHelp->setObjectName("buttonHelp");
117   buttonHelp->setText(tr("GEOM_BUT_HELP"));
118   buttonHelp->setAutoDefault(TRUE);
119   GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
120   /***************************************************************/
121
122   MyDialogLayout->addWidget(GroupC1, 0, 0);
123   MyDialogLayout->addWidget(GroupButtons, 1, 0);
124
125   myHelpFileName = "deflection_page.html";
126
127   // signals and slots connections
128   connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
129   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
130   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
131
132   // Move widget on the botton right corner of main widget
133   SUIT_Tools::centerWidget(this, parent);
134 }
135
136 //=================================================================================
137 // function : ~GEOMToolsGUI_DeflectionDlg()
138 // purpose  : Destroys the object and frees any allocated resources
139 //=================================================================================
140 GEOMToolsGUI_DeflectionDlg::~GEOMToolsGUI_DeflectionDlg()
141 {
142   // no need to delete child widgets, Qt does it all for us
143 }
144
145 double GEOMToolsGUI_DeflectionDlg::getTheDC() const
146 {
147   return SpinBox->text().toDouble();
148 }
149
150 void GEOMToolsGUI_DeflectionDlg::setTheDC (const double v)
151 {
152   SpinBox->setValue(v);
153 }
154
155 //=================================================================================
156 // function : ClickOnHelp()
157 // purpose  :
158 //=================================================================================
159 void GEOMToolsGUI_DeflectionDlg::ClickOnHelp()
160 {
161   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
162   if (app) {
163     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>(app->module("Geometry"));
164     app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
165   }
166   else {
167     QString platform;
168 #ifdef WIN32
169     platform = "winapplication";
170 #else
171     platform = "application";
172 #endif
173     SUIT_MessageBox::warning
174       (0, QObject::tr("WRN_WARNING"),
175        QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
176        arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
177        QObject::tr("BUT_OK"));
178   }
179 }
180
181 //=================================================================================
182 // function : keyPressEvent()
183 // purpose  :
184 //=================================================================================
185 void GEOMToolsGUI_DeflectionDlg::keyPressEvent (QKeyEvent* e)
186 {
187   QDialog::keyPressEvent(e);
188   if (e->isAccepted())
189     return;
190
191   if (e->key() == Qt::Key_F1) {
192     e->accept();
193     ClickOnHelp();
194   }
195 }