1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File : GEOMToolsGUI_DeflectionDlg.cxx
24 #include "GEOMToolsGUI_DeflectionDlg.h"
25 #include <GeometryGUI.h>
26 #include <GEOM_Constants.h>
27 #include <LightApp_Application.h>
28 #include <SalomeApp_DoubleSpinBox.h>
30 #include <SUIT_MessageBox.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_Tools.h>
36 #include <QPushButton>
38 #include <QGridLayout>
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)
51 setObjectName("GEOMToolsGUI_DeflectionDlg");
54 setWindowTitle(tr("GEOM_DEFLECTION_TLT"));
55 setSizeGripEnabled(true);
56 QGridLayout* MyDialogLayout = new QGridLayout(this);
57 MyDialogLayout->setSpacing(6);
58 MyDialogLayout->setMargin(11);
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);
68 QLabel* TextLabel1 = new QLabel (GroupC1);
69 TextLabel1->setObjectName("TextLabel1");
70 TextLabel1->setText(tr("GEOM_DEFLECTION"));
71 GroupC1Layout->addWidget(TextLabel1, 0, 0);
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 ) ) );
88 SpinBox->setObjectName("SpinBoxU");
89 SpinBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
90 SpinBox->setValue(1.0e-04);
91 GroupC1Layout->addWidget(SpinBox, 0, 1);
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);
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);
108 GroupButtonsLayout->addItem(new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
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);
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 /***************************************************************/
123 MyDialogLayout->addWidget(GroupC1, 0, 0);
124 MyDialogLayout->addWidget(GroupButtons, 1, 0);
126 myHelpFileName = "deflection_page.html";
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()));
133 // Move widget on the botton right corner of main widget
134 SUIT_Tools::centerWidget(this, parent);
137 //=================================================================================
138 // function : ~GEOMToolsGUI_DeflectionDlg()
139 // purpose : Destroys the object and frees any allocated resources
140 //=================================================================================
141 GEOMToolsGUI_DeflectionDlg::~GEOMToolsGUI_DeflectionDlg()
143 // no need to delete child widgets, Qt does it all for us
146 double GEOMToolsGUI_DeflectionDlg::getTheDC() const
148 return SpinBox->text().toDouble();
151 void GEOMToolsGUI_DeflectionDlg::setTheDC (const double v)
153 SpinBox->setValue(v);
156 //=================================================================================
157 // function : ClickOnHelp()
159 //=================================================================================
160 void GEOMToolsGUI_DeflectionDlg::ClickOnHelp()
162 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
164 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>(app->module("Geometry"));
165 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
170 platform = "winapplication";
172 platform = "application";
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"));
182 //=================================================================================
183 // function : keyPressEvent()
185 //=================================================================================
186 void GEOMToolsGUI_DeflectionDlg::keyPressEvent (QKeyEvent* e)
188 QDialog::keyPressEvent(e);
192 if (e->key() == Qt::Key_F1) {