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"
33 #include "SUIT_ResourceMgr.h"
35 #include <qgroupbox.h>
36 #include <qpushbutton.h>
37 #include <qcheckbox.h>
44 #define DEFAULT_VAL 10
48 * Class : SMESHGUI_PrecisionDlg
49 * Description : Dialog to specify precision of mesh quality controls
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)
60 setCaption(tr("CAPTION"));
62 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
64 QFrame* aMainFrame = createMainFrame (this);
65 QFrame* aBtnFrame = createButtonFrame(this);
67 aDlgLay->addWidget(aMainFrame);
68 aDlgLay->addWidget(aBtnFrame);
70 aDlgLay->setStretchFactor(aMainFrame, 1);
72 setMinimumWidth((int)(QFontMetrics(font()).width(tr("CAPTION")) * 1.5));
77 //=======================================================================
78 // name : SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg
79 // Purpose : Destructor
80 //=======================================================================
81 SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg()
85 //=======================================================================
86 // name : SMESHGUI_PrecisionDlg::createButtonFrame
87 // Purpose : Create frame containing buttons
88 //=======================================================================
89 QFrame* SMESHGUI_PrecisionDlg::createButtonFrame (QWidget* theParent)
91 QGroupBox* aGrp = new QGroupBox (1, Qt::Vertical, theParent);
92 aGrp->setFrameStyle(QFrame::NoFrame);
93 aGrp->setInsideMargin(0);
95 myOKBtn = new QPushButton (tr("SMESH_BUT_OK"), aGrp);
97 QLabel* aLbl = new QLabel (aGrp);
98 aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
100 myCancelBtn = new QPushButton (tr("SMESH_BUT_CANCEL"), aGrp);
102 connect(myOKBtn, SIGNAL(clicked()), SLOT(onOk()));
103 connect(myCancelBtn, SIGNAL(clicked()), SLOT(onClose()));
108 //=======================================================================
109 // name : SMESHGUI_PrecisionDlg:: createMainFrame
110 // Purpose : Create frame containing dialog's input fields
111 //=======================================================================
112 QFrame* SMESHGUI_PrecisionDlg::createMainFrame (QWidget* theParent)
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);
119 connect(myNotUseChk, SIGNAL(toggled(bool)), SLOT(onNotUse()));
124 //=======================================================================
125 // name : SMESHGUI_PrecisionDlg::Init
126 // Purpose : Initialize dialog fields
127 //=======================================================================
128 void SMESHGUI_PrecisionDlg::Init()
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);
138 mySpinBox->setValue(isOk ? aVal : DEFAULT_VAL);
139 myNotUseChk->setChecked(!isOk);
143 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
144 aSMESHGUI->SetActiveDialogBox((QDialog*)this);
145 connect(aSMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
148 //=======================================================================
149 // name : SMESHGUI_PrecisionDlg::onOk
150 // Purpose : SLOT. Called when OK button pressed
151 //=======================================================================
152 void SMESHGUI_PrecisionDlg::onOk()
154 SUIT_ResourceMgr* mgr = SMESHGUI::resourceMgr();
155 if (myNotUseChk->isChecked()) {
157 mgr->remove("SMESH", "ControlsPrecision");
159 SMESH::SetControlsPrecision(-1);
161 mySpinBox->clearFocus();
162 int aVal = mySpinBox->value();
164 mgr->setValue("SMESH", "ControlsPrecision", QString("%1").arg(aVal));
166 SMESH::SetControlsPrecision(aVal);
169 disconnect(SMESHGUI::GetSMESHGUI(), 0, this, 0);
170 SMESHGUI::GetSMESHGUI()->ResetState() ;
174 //=======================================================================
175 // name : SMESHGUI_PrecisionDlg::onClose
176 // Purpose : SLOT. Called when "Cancel" button pressed
177 //=======================================================================
178 void SMESHGUI_PrecisionDlg::onClose()
180 disconnect(SMESHGUI::GetSMESHGUI(), 0, this, 0);
184 //=======================================================================
185 // name : SMESHGUI_PrecisionDlg::closeEvent
187 //=======================================================================
188 void SMESHGUI_PrecisionDlg::closeEvent (QCloseEvent*)
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()
199 mySpinBox->setEnabled(!myNotUseChk->isChecked());