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"
29 #include "QAD_Config.h"
31 #include "SMESHGUI_VTKUtils.h"
33 #include <qgroupbox.h>
34 #include <qpushbutton.h>
35 #include <qcheckbox.h>
42 #define DEFAULT_VAL 10
46 Class : SMESHGUI_PrecisionDlg
47 Description : Dialog to specify precision of mesh quality controls
50 //=======================================================================
51 // name : SMESHGUI_PrecisionDlg::SMESHGUI_PrecisionDlg
52 // Purpose : Constructor
53 //=======================================================================
54 SMESHGUI_PrecisionDlg::SMESHGUI_PrecisionDlg( QWidget* theParent )
55 : QDialog( theParent, "SMESHGUI_PrecisionDlg", true,
56 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
58 setCaption( tr( "CAPTION" ) );
60 QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
62 QFrame* aMainFrame = createMainFrame ( this );
63 QFrame* aBtnFrame = createButtonFrame( this );
65 aDlgLay->addWidget( aMainFrame );
66 aDlgLay->addWidget( aBtnFrame );
68 aDlgLay->setStretchFactor( aMainFrame, 1 );
70 setMinimumWidth( (int)( QFontMetrics( font() ).width( tr( "CAPTION" ) ) * 1.5 ) );
76 //=======================================================================
77 // name : SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg
78 // Purpose : Destructor
79 //=======================================================================
80 SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg()
84 //=======================================================================
85 // name : SMESHGUI_PrecisionDlg::createButtonFrame
86 // Purpose : Create frame containing buttons
87 //=======================================================================
88 QFrame* SMESHGUI_PrecisionDlg::createButtonFrame( QWidget* theParent )
90 QGroupBox* aGrp = new QGroupBox( 1, Qt::Vertical, theParent );
91 aGrp->setFrameStyle( QFrame::NoFrame );
92 aGrp->setInsideMargin( 0 );
94 myOKBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aGrp );
96 QLabel* aLbl = new QLabel( aGrp );
97 aLbl->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
99 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), aGrp );
101 connect( myOKBtn, SIGNAL( clicked() ), SLOT( onOk() ) );
102 connect( myCancelBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
107 //=======================================================================
108 // name : SMESHGUI_PrecisionDlg:: createMainFrame
109 // Purpose : Create frame containing dialog's input fields
110 //=======================================================================
111 QFrame* SMESHGUI_PrecisionDlg::createMainFrame( QWidget* theParent )
113 QGroupBox* aGrp = new QGroupBox( 2, Qt::Horizontal, theParent );
114 new QLabel( tr( "PRECISION" ), aGrp );
115 mySpinBox = new QSpinBox( 0, RANGE, 1, aGrp );
116 myNotUseChk = new QCheckBox( tr( "NOT_USE" ), aGrp );
118 connect( myNotUseChk, SIGNAL( toggled( bool ) ), SLOT( onNotUse() ) );
123 //=======================================================================
124 // name : SMESHGUI_PrecisionDlg::Init
125 // Purpose : Initialize dialog fields
126 //=======================================================================
127 void SMESHGUI_PrecisionDlg::Init()
129 if ( QAD_CONFIG->hasSetting( "SMESH:ControlsPrecision" ) )
131 QString aStr = QAD_CONFIG->getSetting( "SMESH:ControlsPrecision" );
133 int aVal = aStr.toInt( &isOk );
134 mySpinBox->setValue( isOk ? aVal : DEFAULT_VAL );
135 myNotUseChk->setChecked( !isOk );
139 mySpinBox->setValue( DEFAULT_VAL );
140 myNotUseChk->setChecked( true );
145 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
146 aSMESHGUI->SetActiveDialogBox( ( QDialog* )this ) ;
147 connect( aSMESHGUI, 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 if ( myNotUseChk->isChecked() )
158 QAD_CONFIG->removeSettings( "SMESH:ControlsPrecision" );
159 SMESH::SetControlsPrecision( -1 );
163 mySpinBox->clearFocus();
164 int aVal = mySpinBox->value();
165 QAD_CONFIG->addSetting( "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 // function : SMESHGUI_PrecisionDlg::closeEvent()
187 //=================================================================================
188 void SMESHGUI_PrecisionDlg::closeEvent( QCloseEvent* )
193 //=======================================================================
194 // name : SMESHGUI_PrecisionDlg::onClose
195 // Purpose : SLOT. Called when state of "Do not use" check box changed
196 //=======================================================================
197 void SMESHGUI_PrecisionDlg::onNotUse()
199 mySpinBox->setEnabled( !myNotUseChk->isChecked() );