Salome HOME
5024a235edc4b8fc712a5a1947610112e5623582
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_PrecisionDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : SMESHGUI_PrecisionDlg.cxx
25 //  Author : Sergey LITONIN
26 //  Module : SMESH
27
28 #include "SMESHGUI_PrecisionDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_VTKUtils.h"
32
33 #include "SUIT_ResourceMgr.h"
34
35 #include <qgroupbox.h>
36 #include <qpushbutton.h>
37 #include <qcheckbox.h>
38 #include <qspinbox.h>
39 #include <qlayout.h>
40 #include <qlabel.h>
41
42 #define SPACING 5
43 #define MARGIN  10
44 #define DEFAULT_VAL 10
45 #define RANGE 128
46
47 /*!
48  *  Class       : SMESHGUI_PrecisionDlg
49  *  Description : Dialog to specify precision of mesh quality controls
50  */
51
52 //=======================================================================
53 // name    : SMESHGUI_PrecisionDlg::SMESHGUI_PrecisionDlg
54 // Purpose : Constructor
55 //=======================================================================
56 SMESHGUI_PrecisionDlg::SMESHGUI_PrecisionDlg (QWidget* theParent)
57      : QDialog(theParent, "SMESHGUI_PrecisionDlg", true,
58                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
59 {
60   setCaption(tr("CAPTION"));
61
62   QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
63
64   QFrame* aMainFrame = createMainFrame  (this);
65   QFrame* aBtnFrame  = createButtonFrame(this);
66
67   aDlgLay->addWidget(aMainFrame);
68   aDlgLay->addWidget(aBtnFrame);
69
70   aDlgLay->setStretchFactor(aMainFrame, 1);
71
72   setMinimumWidth((int)(QFontMetrics(font()).width(tr("CAPTION")) * 1.5));
73
74   Init();
75 }
76
77 //=======================================================================
78 // name    : SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg
79 // Purpose : Destructor
80 //=======================================================================
81 SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg()
82 {
83 }
84
85 //=======================================================================
86 // name    : SMESHGUI_PrecisionDlg::createButtonFrame
87 // Purpose : Create frame containing buttons
88 //=======================================================================
89 QFrame* SMESHGUI_PrecisionDlg::createButtonFrame (QWidget* theParent)
90 {
91   QGroupBox* aGrp = new QGroupBox (1, Qt::Vertical, theParent);
92   aGrp->setFrameStyle(QFrame::NoFrame);
93   aGrp->setInsideMargin(0);
94
95   myOKBtn = new QPushButton (tr("SMESH_BUT_OK"), aGrp);
96
97   QLabel* aLbl = new QLabel (aGrp);
98   aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
99
100   myCancelBtn = new QPushButton (tr("SMESH_BUT_CANCEL"), aGrp);
101
102   connect(myOKBtn, SIGNAL(clicked()), SLOT(onOk()));
103   connect(myCancelBtn, SIGNAL(clicked()), SLOT(onClose()));
104
105   return aGrp;
106 }
107
108 //=======================================================================
109 // name    : SMESHGUI_PrecisionDlg:: createMainFrame
110 // Purpose : Create frame containing dialog's input fields
111 //=======================================================================
112 QFrame* SMESHGUI_PrecisionDlg::createMainFrame (QWidget* theParent)
113 {
114   QGroupBox* aGrp = new QGroupBox(2, Qt::Horizontal, theParent);
115   new QLabel (tr("PRECISION"), aGrp);
116   mySpinBox = new QSpinBox (0, RANGE, 1, aGrp);
117   myNotUseChk = new QCheckBox (tr("NOT_USE"), aGrp);
118
119   connect(myNotUseChk, SIGNAL(toggled(bool)), SLOT(onNotUse()));
120
121   return aGrp;
122 }
123
124 //=======================================================================
125 // name    : SMESHGUI_PrecisionDlg::Init
126 // Purpose : Initialize dialog fields
127 //=======================================================================
128 void SMESHGUI_PrecisionDlg::Init()
129 {
130   bool isOk = false;
131   int aVal = DEFAULT_VAL;
132   SUIT_ResourceMgr* mgr = SMESHGUI::resourceMgr();
133   if (mgr && mgr->hasValue("SMESH", "ControlsPrecision")) {
134     QString aStr = mgr->stringValue("SMESH", "ControlsPrecision");
135     aVal = aStr.toInt(&isOk);
136   }
137
138   mySpinBox->setValue(isOk ? aVal : DEFAULT_VAL);
139   myNotUseChk->setChecked(!isOk);
140
141   onNotUse();
142
143   SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
144   aSMESHGUI->SetActiveDialogBox((QDialog*)this);
145   connect(aSMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
146 }
147
148 //=======================================================================
149 // name    : SMESHGUI_PrecisionDlg::onOk
150 // Purpose : SLOT. Called when OK button pressed
151 //=======================================================================
152 void SMESHGUI_PrecisionDlg::onOk()
153 {
154   SUIT_ResourceMgr* mgr = SMESHGUI::resourceMgr();
155   if (myNotUseChk->isChecked()) {
156     if (mgr) {
157       mgr->remove("SMESH", "ControlsPrecision");
158     }
159     SMESH::SetControlsPrecision(-1);
160   } else {
161     mySpinBox->clearFocus();
162     int aVal = mySpinBox->value();
163     if (mgr) {
164       mgr->setValue("SMESH", "ControlsPrecision", QString("%1").arg(aVal));
165     }
166     SMESH::SetControlsPrecision(aVal);
167   }
168
169   disconnect(SMESHGUI::GetSMESHGUI(), 0, this, 0);
170   SMESHGUI::GetSMESHGUI()->ResetState() ;
171   accept();
172 }
173
174 //=======================================================================
175 // name    : SMESHGUI_PrecisionDlg::onClose
176 // Purpose : SLOT. Called when "Cancel" button pressed
177 //=======================================================================
178 void SMESHGUI_PrecisionDlg::onClose()
179 {
180   disconnect(SMESHGUI::GetSMESHGUI(), 0, this, 0);
181   reject();
182 }
183
184 //=======================================================================
185 // name    : SMESHGUI_PrecisionDlg::closeEvent
186 // Purpose :
187 //=======================================================================
188 void SMESHGUI_PrecisionDlg::closeEvent (QCloseEvent*)
189 {
190   onClose();
191 }
192
193 //=======================================================================
194 // name    : SMESHGUI_PrecisionDlg::onNotUse
195 // Purpose : SLOT. Called when state of "Do not use" check box changed
196 //=======================================================================
197 void SMESHGUI_PrecisionDlg::onNotUse()
198 {
199   mySpinBox->setEnabled(!myNotUseChk->isChecked());
200 }