smesh/src/SMESHGUI/SMESHGUI_PrecisionDlg.cxx

201 lines
6.5 KiB
C++
Raw Normal View History

2004-12-01 15:48:31 +05:00
// SMESH SMESHGUI : GUI for SMESH component
//
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
2004-12-01 15:48:31 +05:00
// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
//
//
//
// File : SMESHGUI_PrecisionDlg.cxx
// Author : Sergey LITONIN
// Module : SMESH
#include "SMESHGUI_PrecisionDlg.h"
2004-12-01 15:48:31 +05:00
#include "SMESHGUI.h"
#include "SMESHGUI_VTKUtils.h"
#include "SUIT_ResourceMgr.h"
2004-12-01 15:48:31 +05:00
#include <qgroupbox.h>
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qspinbox.h>
#include <qlayout.h>
#include <qlabel.h>
#define SPACING 5
2004-12-01 15:48:31 +05:00
#define MARGIN 10
#define DEFAULT_VAL 10
#define RANGE 128
/*!
* Class : SMESHGUI_PrecisionDlg
* Description : Dialog to specify precision of mesh quality controls
*/
2004-12-01 15:48:31 +05:00
//=======================================================================
// name : SMESHGUI_PrecisionDlg::SMESHGUI_PrecisionDlg
// Purpose : Constructor
//=======================================================================
SMESHGUI_PrecisionDlg::SMESHGUI_PrecisionDlg (QWidget* theParent)
: QDialog(theParent, "SMESHGUI_PrecisionDlg", true,
WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
2004-12-01 15:48:31 +05:00
{
setCaption(tr("CAPTION"));
2004-12-01 15:48:31 +05:00
QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
2004-12-01 15:48:31 +05:00
QFrame* aMainFrame = createMainFrame (this);
QFrame* aBtnFrame = createButtonFrame(this);
2004-12-01 15:48:31 +05:00
aDlgLay->addWidget(aMainFrame);
aDlgLay->addWidget(aBtnFrame);
2004-12-01 15:48:31 +05:00
aDlgLay->setStretchFactor(aMainFrame, 1);
2004-12-01 15:48:31 +05:00
setMinimumWidth((int)(QFontMetrics(font()).width(tr("CAPTION")) * 1.5));
2004-12-01 15:48:31 +05:00
Init();
}
//=======================================================================
// name : SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg
// Purpose : Destructor
//=======================================================================
SMESHGUI_PrecisionDlg::~SMESHGUI_PrecisionDlg()
{
}
//=======================================================================
// name : SMESHGUI_PrecisionDlg::createButtonFrame
// Purpose : Create frame containing buttons
//=======================================================================
QFrame* SMESHGUI_PrecisionDlg::createButtonFrame (QWidget* theParent)
2004-12-01 15:48:31 +05:00
{
QGroupBox* aGrp = new QGroupBox (1, Qt::Vertical, theParent);
aGrp->setFrameStyle(QFrame::NoFrame);
aGrp->setInsideMargin(0);
2004-12-01 15:48:31 +05:00
myOKBtn = new QPushButton (tr("SMESH_BUT_OK"), aGrp);
2004-12-01 15:48:31 +05:00
QLabel* aLbl = new QLabel (aGrp);
aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
2004-12-01 15:48:31 +05:00
myCancelBtn = new QPushButton (tr("SMESH_BUT_CANCEL"), aGrp);
2004-12-01 15:48:31 +05:00
connect(myOKBtn, SIGNAL(clicked()), SLOT(onOk()));
connect(myCancelBtn, SIGNAL(clicked()), SLOT(onClose()));
2004-12-01 15:48:31 +05:00
return aGrp;
}
//=======================================================================
// name : SMESHGUI_PrecisionDlg:: createMainFrame
// Purpose : Create frame containing dialog's input fields
//=======================================================================
QFrame* SMESHGUI_PrecisionDlg::createMainFrame (QWidget* theParent)
2004-12-01 15:48:31 +05:00
{
QGroupBox* aGrp = new QGroupBox(2, Qt::Horizontal, theParent);
new QLabel (tr("PRECISION"), aGrp);
mySpinBox = new QSpinBox (0, RANGE, 1, aGrp);
myNotUseChk = new QCheckBox (tr("NOT_USE"), aGrp);
2004-12-01 15:48:31 +05:00
connect(myNotUseChk, SIGNAL(toggled(bool)), SLOT(onNotUse()));
2004-12-01 15:48:31 +05:00
return aGrp;
}
//=======================================================================
// name : SMESHGUI_PrecisionDlg::Init
// Purpose : Initialize dialog fields
//=======================================================================
void SMESHGUI_PrecisionDlg::Init()
{
bool isOk = false;
int aVal = DEFAULT_VAL;
SUIT_ResourceMgr* mgr = SMESHGUI::resourceMgr();
if (mgr && mgr->hasValue("SMESH", "ControlsPrecision")) {
QString aStr = mgr->stringValue("SMESH", "ControlsPrecision");
aVal = aStr.toInt(&isOk);
2004-12-01 15:48:31 +05:00
}
mySpinBox->setValue(isOk ? aVal : DEFAULT_VAL);
myNotUseChk->setChecked(!isOk);
2004-12-01 15:48:31 +05:00
onNotUse();
SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
aSMESHGUI->SetActiveDialogBox((QDialog*)this);
connect(aSMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
2004-12-01 15:48:31 +05:00
}
//=======================================================================
// name : SMESHGUI_PrecisionDlg::onOk
// Purpose : SLOT. Called when OK button pressed
//=======================================================================
void SMESHGUI_PrecisionDlg::onOk()
{
SUIT_ResourceMgr* mgr = SMESHGUI::resourceMgr();
if (myNotUseChk->isChecked()) {
if (mgr) {
mgr->remove("SMESH", "ControlsPrecision");
}
SMESH::SetControlsPrecision(-1);
} else {
2004-12-01 15:48:31 +05:00
mySpinBox->clearFocus();
int aVal = mySpinBox->value();
if (mgr) {
mgr->setValue("SMESH", "ControlsPrecision", QString("%1").arg(aVal));
}
SMESH::SetControlsPrecision(aVal);
2004-12-01 15:48:31 +05:00
}
disconnect(SMESHGUI::GetSMESHGUI(), 0, this, 0);
2004-12-01 15:48:31 +05:00
SMESHGUI::GetSMESHGUI()->ResetState() ;
accept();
}
//=======================================================================
// name : SMESHGUI_PrecisionDlg::onClose
// Purpose : SLOT. Called when "Cancel" button pressed
//=======================================================================
void SMESHGUI_PrecisionDlg::onClose()
{
disconnect(SMESHGUI::GetSMESHGUI(), 0, this, 0);
2004-12-01 15:48:31 +05:00
reject();
}
//=======================================================================
// name : SMESHGUI_PrecisionDlg::closeEvent
// Purpose :
//=======================================================================
void SMESHGUI_PrecisionDlg::closeEvent (QCloseEvent*)
2004-12-01 15:48:31 +05:00
{
onClose();
}
//=======================================================================
// name : SMESHGUI_PrecisionDlg::onNotUse
2004-12-01 15:48:31 +05:00
// Purpose : SLOT. Called when state of "Do not use" check box changed
//=======================================================================
void SMESHGUI_PrecisionDlg::onNotUse()
{
mySpinBox->setEnabled(!myNotUseChk->isChecked());
2004-12-01 15:48:31 +05:00
}