Salome HOME
Adjust to CVS HEAD modifications
[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 #include "SMESHGUI_Utils.h"
33
34 #include "SUIT_Desktop.h"
35 #include "SUIT_ResourceMgr.h"
36
37 #include <qgroupbox.h>
38 #include <qpushbutton.h>
39 #include <qcheckbox.h>
40 #include <qspinbox.h>
41 #include <qlayout.h>
42 #include <qlabel.h>
43
44 #define SPACING 5
45 #define MARGIN  10
46 #define DEFAULT_VAL 10
47 #define RANGE 128
48
49 /*!
50  *  Class       : SMESHGUI_PrecisionDlg
51  *  Description : Dialog to specify precision of mesh quality controls
52  */
53
54 //=======================================================================
55 // name    : SMESHGUI_PrecisionDlg::SMESHGUI_PrecisionDlg
56 // Purpose : Constructor
57 //=======================================================================
58 SMESHGUI_PrecisionDlg::SMESHGUI_PrecisionDlg ( SMESHGUI* theModule )
59      : QDialog( SMESH::GetDesktop( theModule ), "SMESHGUI_PrecisionDlg", true,
60                 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
61      mySMESHGUI( theModule )
62 {
63   setCaption(tr("CAPTION"));
64
65   QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
66
67   QFrame* aMainFrame = createMainFrame  (this);
68   QFrame* aBtnFrame  = createButtonFrame(this);
69
70   aDlgLay->addWidget(aMainFrame);
71   aDlgLay->addWidget(aBtnFrame);
72
73   aDlgLay->setStretchFactor(aMainFrame, 1);
74
75   setMinimumWidth((int)(QFontMetrics(font()).width(tr("CAPTION")) * 1.5));
76
77   Init();
78 }
79
80 //=======================================================================
81 // name    : SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg
82 // Purpose : Destructor
83 //=======================================================================
84 SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg()
85 {
86 }
87
88 //=======================================================================
89 // name    : SMESHGUI_PrecisionDlg::createButtonFrame
90 // Purpose : Create frame containing buttons
91 //=======================================================================
92 QFrame* SMESHGUI_PrecisionDlg::createButtonFrame (QWidget* theParent)
93 {
94   QGroupBox* aGrp = new QGroupBox (1, Qt::Vertical, theParent);
95   aGrp->setFrameStyle(QFrame::NoFrame);
96   aGrp->setInsideMargin(0);
97
98   myOKBtn = new QPushButton (tr("SMESH_BUT_OK"), aGrp);
99
100   QLabel* aLbl = new QLabel (aGrp);
101   aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
102
103   myCancelBtn = new QPushButton (tr("SMESH_BUT_CANCEL"), aGrp);
104
105   connect(myOKBtn, SIGNAL(clicked()), SLOT(onOk()));
106   connect(myCancelBtn, SIGNAL(clicked()), SLOT(onClose()));
107
108   return aGrp;
109 }
110
111 //=======================================================================
112 // name    : SMESHGUI_PrecisionDlg:: createMainFrame
113 // Purpose : Create frame containing dialog's input fields
114 //=======================================================================
115 QFrame* SMESHGUI_PrecisionDlg::createMainFrame (QWidget* theParent)
116 {
117   QGroupBox* aGrp = new QGroupBox(2, Qt::Horizontal, theParent);
118   new QLabel (tr("PRECISION"), aGrp);
119   mySpinBox = new QSpinBox (0, RANGE, 1, aGrp);
120   myNotUseChk = new QCheckBox (tr("NOT_USE"), aGrp);
121
122   connect(myNotUseChk, SIGNAL(toggled(bool)), SLOT(onNotUse()));
123
124   return aGrp;
125 }
126
127 //=======================================================================
128 // name    : SMESHGUI_PrecisionDlg::Init
129 // Purpose : Initialize dialog fields
130 //=======================================================================
131 void SMESHGUI_PrecisionDlg::Init()
132 {
133   bool isOk = false;
134   int aVal = DEFAULT_VAL;
135   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
136   if (mgr && mgr->hasValue("SMESH", "controls_precision")) {
137     QString aStr = mgr->stringValue("SMESH", "controls_precision");
138     aVal = aStr.toInt(&isOk);
139   }
140
141   mySpinBox->setValue(isOk ? aVal : DEFAULT_VAL);
142   myNotUseChk->setChecked(!isOk);
143
144   onNotUse();
145
146   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
147   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
148 }
149
150 //=======================================================================
151 // name    : SMESHGUI_PrecisionDlg::onOk
152 // Purpose : SLOT. Called when OK button pressed
153 //=======================================================================
154 void SMESHGUI_PrecisionDlg::onOk()
155 {
156   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
157   if (myNotUseChk->isChecked()) {
158     if (mgr) {
159       mgr->remove("SMESH", "controls_precision");
160     }
161     SMESH::SetControlsPrecision(-1);
162   } else {
163     mySpinBox->clearFocus();
164     int aVal = mySpinBox->value();
165     if (mgr) {
166       mgr->setValue("SMESH", "controls_precision", QString("%1").arg(aVal));
167     }
168     SMESH::SetControlsPrecision(aVal);
169   }
170
171   disconnect(mySMESHGUI, 0, this, 0);
172   mySMESHGUI->ResetState() ;
173   accept();
174 }
175
176 //=======================================================================
177 // name    : SMESHGUI_PrecisionDlg::onClose
178 // Purpose : SLOT. Called when "Cancel" button pressed
179 //=======================================================================
180 void SMESHGUI_PrecisionDlg::onClose()
181 {
182   disconnect( mySMESHGUI, 0, this, 0);
183   reject();
184 }
185
186 //=======================================================================
187 // name    : SMESHGUI_PrecisionDlg::closeEvent
188 // Purpose :
189 //=======================================================================
190 void SMESHGUI_PrecisionDlg::closeEvent (QCloseEvent*)
191 {
192   onClose();
193 }
194
195 //=======================================================================
196 // name    : SMESHGUI_PrecisionDlg::onNotUse
197 // Purpose : SLOT. Called when state of "Do not use" check box changed
198 //=======================================================================
199 void SMESHGUI_PrecisionDlg::onNotUse()
200 {
201   mySpinBox->setEnabled(!myNotUseChk->isChecked());
202 }