1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_PrecisionDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_PrecisionDlg.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Utils.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_ResourceMgr.h"
37 #include <qgroupbox.h>
38 #include <qpushbutton.h>
39 #include <qcheckbox.h>
46 #define DEFAULT_VAL 10
50 * Class : SMESHGUI_PrecisionDlg
51 * Description : Dialog to specify precision of mesh quality controls
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 )
63 setCaption(tr("CAPTION"));
65 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
67 QFrame* aMainFrame = createMainFrame (this);
68 QFrame* aBtnFrame = createButtonFrame(this);
70 aDlgLay->addWidget(aMainFrame);
71 aDlgLay->addWidget(aBtnFrame);
73 aDlgLay->setStretchFactor(aMainFrame, 1);
75 setMinimumWidth((int)(QFontMetrics(font()).width(tr("CAPTION")) * 1.5));
80 //=======================================================================
81 // name : SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg
82 // Purpose : Destructor
83 //=======================================================================
84 SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg()
88 //=======================================================================
89 // name : SMESHGUI_PrecisionDlg::createButtonFrame
90 // Purpose : Create frame containing buttons
91 //=======================================================================
92 QFrame* SMESHGUI_PrecisionDlg::createButtonFrame (QWidget* theParent)
94 QGroupBox* aGrp = new QGroupBox (1, Qt::Vertical, theParent);
95 aGrp->setFrameStyle(QFrame::NoFrame);
96 aGrp->setInsideMargin(0);
98 myOKBtn = new QPushButton (tr("SMESH_BUT_OK"), aGrp);
100 QLabel* aLbl = new QLabel (aGrp);
101 aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
103 myCancelBtn = new QPushButton (tr("SMESH_BUT_CANCEL"), aGrp);
105 connect(myOKBtn, SIGNAL(clicked()), SLOT(onOk()));
106 connect(myCancelBtn, SIGNAL(clicked()), SLOT(onClose()));
111 //=======================================================================
112 // name : SMESHGUI_PrecisionDlg:: createMainFrame
113 // Purpose : Create frame containing dialog's input fields
114 //=======================================================================
115 QFrame* SMESHGUI_PrecisionDlg::createMainFrame (QWidget* theParent)
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);
122 connect(myNotUseChk, SIGNAL(toggled(bool)), SLOT(onNotUse()));
127 //=======================================================================
128 // name : SMESHGUI_PrecisionDlg::Init
129 // Purpose : Initialize dialog fields
130 //=======================================================================
131 void SMESHGUI_PrecisionDlg::Init()
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);
141 mySpinBox->setValue(isOk ? aVal : DEFAULT_VAL);
142 myNotUseChk->setChecked(!isOk);
146 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
147 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
150 //=======================================================================
151 // name : SMESHGUI_PrecisionDlg::onOk
152 // Purpose : SLOT. Called when OK button pressed
153 //=======================================================================
154 void SMESHGUI_PrecisionDlg::onOk()
156 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
157 if (myNotUseChk->isChecked()) {
159 mgr->remove("SMESH", "controls_precision");
161 SMESH::SetControlsPrecision(-1);
163 mySpinBox->clearFocus();
164 int aVal = mySpinBox->value();
166 mgr->setValue("SMESH", "controls_precision", QString("%1").arg(aVal));
168 SMESH::SetControlsPrecision(aVal);
171 disconnect(mySMESHGUI, 0, this, 0);
172 mySMESHGUI->ResetState() ;
176 //=======================================================================
177 // name : SMESHGUI_PrecisionDlg::onClose
178 // Purpose : SLOT. Called when "Cancel" button pressed
179 //=======================================================================
180 void SMESHGUI_PrecisionDlg::onClose()
182 disconnect( mySMESHGUI, 0, this, 0);
186 //=======================================================================
187 // name : SMESHGUI_PrecisionDlg::closeEvent
189 //=======================================================================
190 void SMESHGUI_PrecisionDlg::closeEvent (QCloseEvent*)
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()
201 mySpinBox->setEnabled(!myNotUseChk->isChecked());