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