geom/src/OperationGUI/OperationGUI_ChamferDlg.cxx

958 lines
32 KiB
C++
Raw Normal View History

2009-02-13 17:16:39 +05:00
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
2004-01-07 20:46:21 +05:00
//
2009-02-13 17:16:39 +05:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2009-02-13 17:16:39 +05:00
//
// 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
//
2009-02-13 17:16:39 +05:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-01-07 20:46:21 +05:00
//
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : OperationGUI_ChamferDlg.cxx
// Author : Damien COQUERET, Open CASCADE S.A.S.
2004-01-07 20:46:21 +05:00
//
#include "OperationGUI_ChamferDlg.h"
2009-02-13 17:16:39 +05:00
#include <QtxDoubleSpinBox.h>
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_ViewWindow.h>
#include <SUIT_ViewManager.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <OCCViewer_ViewModel.h>
// OCCT Includes
#include <TColStd_MapOfInteger.hxx>
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_Types.hxx>
2004-06-16 21:24:55 +06:00
2004-01-07 20:46:21 +05:00
//=================================================================================
// class : OperationGUI_ChamferDlg()
2004-12-01 15:39:14 +05:00
// purpose : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
2004-01-07 20:46:21 +05:00
// name 'name' and widget flags set to 'f'.
// The dialog will by default be modeless, unless you set 'modal' to
// TRUE to construct a modal dialog.
//=================================================================================
2009-02-13 17:16:39 +05:00
OperationGUI_ChamferDlg::OperationGUI_ChamferDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
: GEOMBase_Skeleton(theGeometryGUI, parent, false),
myInitial(true)
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_ALL")));
QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_EDGE_FROM_FACE")));
QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_FACE")));
QPixmap image4 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_EDGE")));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle(tr("GEOM_CHAMFER_TITLE"));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
/***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHAMFER"));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
mainFrame()->RadioButton1->setIcon(image1);
mainFrame()->RadioButton2->setIcon(image2);
mainFrame()->RadioButton3->setIcon(image3);
mainFrame()->RadioButton4->show();
mainFrame()->RadioButton4->setIcon(image4);
2004-12-01 15:39:14 +05:00
// Create first group
2009-02-13 17:16:39 +05:00
myGrp1 = new QGroupBox(tr("GEOM_CHAMFER_ALL"), centralWidget());
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
QGridLayout* aLayout = new QGridLayout(myGrp1);
aLayout->setMargin(9); aLayout->setSpacing(6);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp1, aLayout, MainObj1);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
int row = aLayout->rowCount();
aLayout->addWidget(new QLabel(tr("D"), myGrp1), row, 0);
aLayout->addWidget((mySpinBox[ SpinBox1 ] = new SalomeApp_DoubleSpinBox(myGrp1)), row++, 2);
aLayout->setRowStretch(row, 10);
2004-12-01 15:39:14 +05:00
// Create second group
2009-02-13 17:16:39 +05:00
myGrp2 = new QGroupBox(tr("GEOM_CHAMFER_EDGES"), centralWidget());
2009-02-13 17:16:39 +05:00
aLayout = new QGridLayout(myGrp2);
aLayout->setMargin(9); aLayout->setSpacing(6);
2009-02-13 17:16:39 +05:00
createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp2, aLayout, MainObj2);
createSelWg(tr("FACE_1"), iconSelect, myGrp2, aLayout, Face1);
createSelWg(tr("FACE_2"), iconSelect, myGrp2, aLayout, Face2);
2009-02-13 17:16:39 +05:00
createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"), myGrp2, aLayout, RadioButton21, SpinBox21, SpinBox22);
createRadioWg(tr("GEOM_D"), tr("GEOM_ANGLE"), myGrp2, aLayout, RadioButton22, SpinBox23, SpinBox24);
2009-02-13 17:16:39 +05:00
aLayout->setRowStretch(aLayout->rowCount(), 10);
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
// Create third group
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
myGrp3 = new QGroupBox(tr("GEOM_CHAMFER_FACES"), centralWidget());
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
aLayout = new QGridLayout(myGrp3);
aLayout->setMargin(9); aLayout->setSpacing(6);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp3, aLayout, MainObj3);
createSelWg(tr("SELECTED_FACES"), iconSelect, myGrp3, aLayout, Faces);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"), myGrp3, aLayout, RadioButton31, SpinBox31, SpinBox32);
createRadioWg(tr("GEOM_D"), tr("GEOM_ANGLE"), myGrp3, aLayout, RadioButton32, SpinBox33, SpinBox34);
2009-02-13 17:16:39 +05:00
aLayout->setRowStretch(aLayout->rowCount(), 10);
// Create fourth group
2009-02-13 17:16:39 +05:00
myGrp4 = new QGroupBox(tr("GEOM_CHAMFER_EDGE"), centralWidget());
2009-02-13 17:16:39 +05:00
aLayout = new QGridLayout(myGrp4);
aLayout->setMargin(9); aLayout->setSpacing(6);
2009-02-13 17:16:39 +05:00
createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp4, aLayout, MainObj4);
createSelWg(tr("SELECTED_EDGE"), iconSelect, myGrp4, aLayout, Edges);
2009-02-13 17:16:39 +05:00
createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"), myGrp4, aLayout, RadioButton41, SpinBox41, SpinBox42);
createRadioWg(tr("GEOM_D"), tr("GEOM_ANGLE"), myGrp4, aLayout, RadioButton42, SpinBox43, SpinBox44);
2009-02-13 17:16:39 +05:00
aLayout->setRowStretch(aLayout->rowCount(), 10);
2004-12-01 15:39:14 +05:00
// Add groups to layout
2009-02-13 17:16:39 +05:00
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6);
layout->addWidget(myGrp1);
layout->addWidget(myGrp2);
layout->addWidget(myGrp3);
layout->addWidget(myGrp4);
/***************************************************************/
2004-12-01 15:39:14 +05:00
// Set range of spinboxes
double SpecificStep = 10.0;
2009-02-13 17:16:39 +05:00
QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIter;
for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter) {
if (anIter.key() == SpinBox44 || anIter.key() == SpinBox34 || anIter.key() == SpinBox24)
initSpinBox(anIter.value(), 0.001, 89.999, 5, 0);
else
initSpinBox(anIter.value(), 0.001, COORD_MAX, SpecificStep, 3);
}
2004-01-07 20:46:21 +05:00
setHelpFileName("chamfer_operation_page.html");
2009-02-13 17:16:39 +05:00
// Initialisation
Init();
2009-02-13 17:16:39 +05:00
myRadioButton[ RadioButton21 ]->click();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ~OperationGUI_ChamferDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
2004-12-01 15:39:14 +05:00
{
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void OperationGUI_ChamferDlg::Init()
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
// Set Initial values of spinboxes
QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIter;
for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter)
anIter.value()->setValue(5);
// Clear line edits
QMap< int, QLineEdit* >::iterator anIterLE;
for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
anIterLE.value()->setText("");
myShape = GEOM::GEOM_Object::_nil();
myFaces.Clear();
myEdges.Clear();
myFace[ Face1 ] = -1;
myFace[ Face2 ] = -1;
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
// signals and slots connections
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
// main buttons
2009-02-13 17:16:39 +05:00
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk() ));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
// group box
2009-02-13 17:16:39 +05:00
connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
// push buttons
QMap< int, QPushButton* >::iterator anIterBtn;
2009-02-13 17:16:39 +05:00
for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
connect(anIterBtn.value(), SIGNAL(clicked()),
this, SLOT(SetEditCurrentArgument()));
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
// line edits
QMap< int, QLineEdit* >::iterator anIterLE2;
2009-02-13 17:16:39 +05:00
for (anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2)
connect(anIterLE2.value(), SIGNAL(returnPressed()),
this, SLOT(LineEditReturnPressed()));
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
// spin boxes
2009-02-13 17:16:39 +05:00
QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIterSpin;
for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
connect(anIterSpin.value(), SIGNAL(valueChanged(double)),
this, SLOT(ValueChangedInSpinBox(double)));
2004-01-07 20:46:21 +05:00
// radio buttons
QMap< int, QRadioButton* >::iterator anIterRadio;
2009-02-13 17:16:39 +05:00
for (anIterRadio = myRadioButton.begin(); anIterRadio != myRadioButton.end(); ++anIterRadio)
connect(anIterRadio.value(), SIGNAL(clicked()),
this, SLOT(RadioButtonPressed()));
2009-02-13 17:16:39 +05:00
initName(tr("GEOM_CHAMFER"));
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
myConstructorId = -1;
ConstructorsClicked(0);
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ConstructorsClicked()
// purpose : Radio button management
//=================================================================================
2009-02-13 17:16:39 +05:00
void OperationGUI_ChamferDlg::ConstructorsClicked (int constructorId)
2004-01-07 20:46:21 +05:00
{
2004-12-01 15:39:14 +05:00
// Activate next widget
2009-02-13 17:16:39 +05:00
if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
!= OCCViewer_Viewer::Type()) {
mainFrame()->RadioButton1->setChecked(true);
return;
}
if (myConstructorId == constructorId)
2004-12-01 15:39:14 +05:00
return;
2009-02-13 17:16:39 +05:00
//disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
2004-12-01 15:39:14 +05:00
// Get values from previous widget
2009-02-13 17:16:39 +05:00
QString D1 = "5", D2 = "5", D = "5", Angle = "5";
if (myConstructorId == 0)
D1 = D2 = mySpinBox[ SpinBox1 ]->text();
else if (myConstructorId == 1) {
D1 = mySpinBox[ SpinBox21 ]->text();
D2 = mySpinBox[ SpinBox22 ]->text();
D = mySpinBox[ SpinBox23 ]->text();
Angle = mySpinBox[ SpinBox24 ]->text();
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
else if (myConstructorId == 2) {
D1 = mySpinBox[ SpinBox31 ]->text();
D2 = mySpinBox[ SpinBox32 ]->text();
D = mySpinBox[ SpinBox33 ]->text();
Angle = mySpinBox[ SpinBox34 ]->text();
}
2009-02-13 17:16:39 +05:00
else if (myConstructorId == 3) {
D1 = mySpinBox[ SpinBox41 ]->text();
D2 = mySpinBox[ SpinBox42 ]->text();
D = mySpinBox[ SpinBox43 ]->text();
Angle = mySpinBox[ SpinBox44 ]->text();
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
myConstructorId = constructorId;
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
switch (constructorId) {
case 0:
myGrp2->hide();
myGrp3->hide();
myGrp4->hide();
myGrp1->show();
mySpinBox[ SpinBox1 ]->setText(D1);
2004-12-01 15:39:14 +05:00
break;
2009-02-13 17:16:39 +05:00
case 1:
myGrp1->hide();
myGrp3->hide();
myGrp4->hide();
myGrp2->show();
mySpinBox[ SpinBox21 ]->setText(D1);
mySpinBox[ SpinBox22 ]->setText(D2);
mySpinBox[ SpinBox23 ]->setText(D);
mySpinBox[ SpinBox24 ]->setText(Angle);
2004-12-01 15:39:14 +05:00
break;
2009-02-13 17:16:39 +05:00
case 2:
myGrp1->hide();
myGrp2->hide();
myGrp4->hide();
myGrp3->show();
mySpinBox[ SpinBox31 ]->setText(D1);
mySpinBox[ SpinBox32 ]->setText(D2);
mySpinBox[ SpinBox32 ]->setText(D2);
mySpinBox[ SpinBox33 ]->setText(D);
mySpinBox[ SpinBox34 ]->setText(Angle);
break;
2009-02-13 17:16:39 +05:00
case 3:
myGrp1->hide();
myGrp2->hide();
myGrp3->hide();
myGrp4->show();
mySpinBox[ SpinBox41 ]->setText(D1);
mySpinBox[ SpinBox42 ]->setText(D2);
mySpinBox[ SpinBox43 ]->setText(D);
mySpinBox[ SpinBox44 ]->setText(Angle);
2004-12-01 15:39:14 +05:00
break;
2009-02-13 17:16:39 +05:00
default:
2004-12-01 15:39:14 +05:00
break;
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
if (constructorId == 0) mySelBtn[ MainObj1 ]->click();
else if (constructorId == 1) mySelBtn[ MainObj2 ]->click();
else if (constructorId == 2) mySelBtn[ MainObj3 ]->click();
else mySelBtn[ MainObj4 ]->click();
2004-12-01 15:39:14 +05:00
enableWidgets();
2009-02-13 17:16:39 +05:00
if (myInitial) {
myInitial = false;
SelectionIntoArgument();
2004-06-16 21:24:55 +06:00
}
2009-02-13 17:16:39 +05:00
else {
if (!myShape->_is_nil()) {
myEditCurrentArgument->setText(GEOMBase::GetName(myShape));
GEOMBase_Skeleton::LineEditReturnPressed();
switch (getConstructorId()) {
case 1:
if (myFace[ Face1 ] == -1)
mySelBtn[ Face1 ]->click();
break;
case 2:
if (myFaces.Extent() == 0)
mySelBtn[ Faces ]->click();
break;
case 3:
if (myEdges.Extent() == 0)
mySelBtn[ Edges ]->click();
break;
default:
break;
}
}
else {
myEditCurrentArgument->setText("");
}
2004-06-16 21:24:55 +06:00
2009-02-13 17:16:39 +05:00
displayPreview();
}
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
qApp->processEvents();
updateGeometry();
resize(minimumSizeHint());
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void OperationGUI_ChamferDlg::ClickOnOk()
{
2009-02-13 17:16:39 +05:00
if (ClickOnApply())
2004-12-01 15:39:14 +05:00
ClickOnCancel();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
bool OperationGUI_ChamferDlg::ClickOnApply()
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
if (!onAccept())
2004-12-01 15:39:14 +05:00
return false;
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
initName();
2009-02-13 17:16:39 +05:00
// activate selection and connect selection manager
ConstructorsClicked(getConstructorId());
2004-12-01 15:39:14 +05:00
return true;
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : SelectionIntoArgument()
2009-02-13 17:16:39 +05:00
// purpose : Called when selection is changed or on dialog initialization or activation
2004-01-07 20:46:21 +05:00
//=================================================================================
void OperationGUI_ChamferDlg::SelectionIntoArgument()
{
2004-12-01 15:39:14 +05:00
erasePreview();
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText("");
2004-12-01 15:39:14 +05:00
// Get index of current selection focus
int aCurrFocus = -1;
QMap< int, QLineEdit* >::iterator anIter;
2009-02-13 17:16:39 +05:00
for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
if (myEditCurrentArgument == anIter.value()) {
2004-12-01 15:39:14 +05:00
aCurrFocus = anIter.key();
break;
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
}
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
// If selection of main object is activated
2009-02-13 17:16:39 +05:00
if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
myShape = GEOM::GEOM_Object::_nil();
if (aSelList.Extent() == 1) {
2004-12-01 15:39:14 +05:00
Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj =
2009-02-13 17:16:39 +05:00
GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if (aResult && !anObj->_is_nil()) {
2004-12-01 15:39:14 +05:00
myShape = anObj;
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
2004-12-01 15:39:14 +05:00
displayPreview();
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
}
enableWidgets();
}
// If face selection of second tab is activated
2009-02-13 17:16:39 +05:00
else if (aCurrFocus == Face1 || aCurrFocus == Face2)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
myFace[ aCurrFocus ] = -1;
if (aSelList.Extent() == 1) {
2004-12-01 15:39:14 +05:00
Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj =
2009-02-13 17:16:39 +05:00
GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if (aResult && !anObj->_is_nil()) {
2004-12-01 15:39:14 +05:00
TColStd_IndexedMapOfInteger anIndexes;
2009-02-13 17:16:39 +05:00
aSelMgr->GetIndexes(aSelList.First(), anIndexes);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if (anIndexes.Extent() == 1) {
int anIndex = anIndexes(1);
QString aFaceName = QString(GEOMBase::GetName(anObj)) + ":%1";
myEditCurrentArgument->setText(aFaceName.arg(anIndex));
2004-12-01 15:39:14 +05:00
myFace[ aCurrFocus ] = anIndex;
2009-02-13 17:16:39 +05:00
displayPreview();
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
}
}
}
// If face selection of third or fourth tab is activated
2009-02-13 17:16:39 +05:00
else if (aCurrFocus == Faces || aCurrFocus == Edges) {
if (aCurrFocus == Faces) myFaces.Clear();
else myEdges.Clear();
if (aSelList.Extent() == 1) {
2004-12-01 15:39:14 +05:00
Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj =
2009-02-13 17:16:39 +05:00
GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
if (aResult && !anObj->_is_nil()) {
TColStd_IndexedMapOfInteger anIndexes;
aSelMgr->GetIndexes(aSelList.First(), anIndexes);
if (anIndexes.Extent() > 0) {
QString aName;
if (anIndexes.Extent() == 1) {
int anIndex = anIndexes(1);
aName = QString(GEOMBase::GetName(anObj)) + QString(":%1").arg(anIndex);
}
else {
aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
}
myEditCurrentArgument->setText(aName);
int aConstructorId = getConstructorId();
if (aConstructorId == 2)
myFaces = anIndexes;
else if (aConstructorId == 3)
myEdges = anIndexes;
displayPreview();
}
2004-12-01 15:39:14 +05:00
}
}
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
// clear selection
if (aCurrFocus != Faces && aCurrFocus != Edges) {
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
myGeomGUI->getApp()->selectionMgr()->clearSelected();
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
this, SLOT(SelectionIntoArgument()));
}
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
switch (getConstructorId()) {
case 1:
if (aCurrFocus == MainObj2) {
if (!myShape->_is_nil() && myFace[ Face1 ] == -1)
mySelBtn[ Face1 ]->click();
}
else if (aCurrFocus == Face1) {
if (myFace[ Face1 ] != -1 && myFace[ Face2 ] == -1)
mySelBtn[ Face2 ]->click();
}
else if (aCurrFocus == Face2) {
if (myFace[ Face2 ] != -1 && myShape->_is_nil())
mySelBtn[ MainObj2 ]->click();
}
break;
case 2:
if (aCurrFocus == MainObj3) {
if (!myShape->_is_nil() && myFaces.Extent() == 0)
mySelBtn[ Faces ]->click();
}
break;
case 3:
if (aCurrFocus == MainObj4) {
if (!myShape->_is_nil() && myEdges.Extent() == 0)
mySelBtn[ Edges ]->click();
}
break;
default:
break;
}
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void OperationGUI_ChamferDlg::SetEditCurrentArgument()
{
2009-02-13 17:16:39 +05:00
QPushButton* send = (QPushButton*)sender();
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
QMap< int, QPushButton* >::iterator anIter;
2009-02-13 17:16:39 +05:00
for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
if (anIter.value() == send) {
2004-12-01 15:39:14 +05:00
mySelName[ anIter.key() ]->setFocus();
myEditCurrentArgument = mySelName[ anIter.key() ];
}
2009-02-13 17:16:39 +05:00
else {
anIter.value()->setDown(false);
mySelName[ anIter.key() ]->setEnabled(false);
}
}
// enable line edit
myEditCurrentArgument->setEnabled(true);
myEditCurrentArgument->setFocus();
// after setFocus(), because it will be setDown(false) when loses focus
send->setDown(true);
2004-06-16 21:24:55 +06:00
2004-12-01 15:39:14 +05:00
activateSelection();
2009-02-13 17:16:39 +05:00
// seems we need it only to avoid preview disappearing, caused by selection mode change
displayPreview();
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void OperationGUI_ChamferDlg::LineEditReturnPressed()
{
QLineEdit* send = (QLineEdit*)sender();
QMap< int, QLineEdit* >::iterator anIterLE;
for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
if (anIterLE.value() == send)
myEditCurrentArgument = anIterLE.value();
GEOMBase_Skeleton::LineEditReturnPressed();
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void OperationGUI_ChamferDlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
2009-02-13 17:16:39 +05:00
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
ConstructorsClicked( getConstructorId() );
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
void OperationGUI_ChamferDlg::enterEvent (QEvent*)
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
if (!mainFrame()->GroupConstructors->isEnabled())
2004-12-01 15:39:14 +05:00
this->ActivateThisDialog();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
2004-12-01 15:39:14 +05:00
// function : ValueChangedInSpinBox()
2004-01-07 20:46:21 +05:00
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
void OperationGUI_ChamferDlg::ValueChangedInSpinBox (double)
2004-12-01 15:39:14 +05:00
{
displayPreview();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
2004-12-01 15:39:14 +05:00
// function : createSelWg()
2004-01-07 20:46:21 +05:00
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
void OperationGUI_ChamferDlg::createSelWg (const QString& theLbl,
2004-12-01 15:39:14 +05:00
QPixmap& thePix,
QWidget* theParent,
2009-02-13 17:16:39 +05:00
QGridLayout* theLayout,
const int theId)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
QLabel* lab = new QLabel(theLbl, theParent);
mySelBtn[ theId ] = new QPushButton(theParent);
mySelBtn[ theId ]->setIcon(thePix);
mySelName[ theId ] = new QLineEdit(theParent);
mySelName[ theId ]->setReadOnly(true);
int row = theLayout->rowCount();
theLayout->addWidget(lab, row, 0);
theLayout->addWidget(mySelBtn[ theId ], row, 1);
theLayout->addWidget(mySelName[ theId ], row, 2, 1, 4); // take into account createRadioWg()
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
//=================================================================================
2009-02-13 17:16:39 +05:00
// function : createRadioWg()
2004-01-07 20:46:21 +05:00
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
void OperationGUI_ChamferDlg::createRadioWg(const QString& theLbl1,
const QString& theLbl2,
QWidget* theParent,
QGridLayout* theLayout,
const int theRbId,
const int theSpin1Id,
const int theSpin2Id)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
myRadioButton[ theRbId ] = new QRadioButton(theParent);
QLabel* lab1 = new QLabel(theLbl1, theParent);
QLabel* lab2 = new QLabel(theLbl2, theParent);
mySpinBox[ theSpin1Id ] = new SalomeApp_DoubleSpinBox(theParent);
mySpinBox[ theSpin2Id ] = new SalomeApp_DoubleSpinBox(theParent);
int row = theLayout->rowCount();
theLayout->addWidget(myRadioButton[ theRbId ], row, 0);
theLayout->addWidget(lab1, row, 2);
theLayout->addWidget(mySpinBox[ theSpin1Id ], row, 3);
theLayout->addWidget(lab2, row, 4);
theLayout->addWidget(mySpinBox[ theSpin2Id ], row, 5);
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : activateSelection
// purpose : Activate selection in accordance with myEditCurrentArgument
//=================================================================================
void OperationGUI_ChamferDlg::activateSelection()
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
if (!myShape->_is_nil() &&
(myEditCurrentArgument == mySelName[ Face1 ] ||
myEditCurrentArgument == mySelName[ Face2 ] ||
myEditCurrentArgument == mySelName[ Faces ])) {
localSelection(myShape, TopAbs_FACE);
}
else if (!myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ]) {
localSelection(myShape, TopAbs_EDGE);
}
else {
2004-12-01 15:39:14 +05:00
TColStd_MapOfInteger aMap;
2009-02-13 17:16:39 +05:00
aMap.Add(GEOM_SHELL);
aMap.Add(GEOM_SOLID);
aMap.Add(GEOM_COMPOUND);
globalSelection(aMap);
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
this, SLOT(SelectionIntoArgument()));
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : enableWidgets
// purpose : Enable widgets of faces in accordance with value of main object
//=================================================================================
void OperationGUI_ChamferDlg::enableWidgets()
{
int anId = getConstructorId();
bool toEnable = !myShape->_is_nil();
2009-02-13 17:16:39 +05:00
if (anId == 1)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
//mySelName[ Face1 ]->setEnabled(toEnable);
//mySelName[ Face2 ]->setEnabled(toEnable);
mySelBtn[ Face1 ]->setEnabled(toEnable);
mySelBtn[ Face2 ]->setEnabled(toEnable);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if (!toEnable)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
mySelName[ Face1 ]->setText("");
mySelName[ Face2 ]->setText("");
2004-12-01 15:39:14 +05:00
myFace[ Face1 ] = -1;
myFace[ Face2 ] = -1;
}
}
2009-02-13 17:16:39 +05:00
else if (anId == 2)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
//mySelName[ Faces ]->setEnabled(toEnable);
mySelBtn[ Faces ]->setEnabled(toEnable);
if (!toEnable) {
mySelName[ Faces ]->setText("");
myFaces.Clear();
}
}
2009-02-13 17:16:39 +05:00
else if (anId == 3) {
//mySelName[ Edges ]->setEnabled(toEnable);
mySelBtn[ Edges ]->setEnabled(toEnable);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if (!toEnable) {
mySelName[ Edges ]->setText("");
myEdges.Clear();
}
2004-12-01 15:39:14 +05:00
}
}
2004-01-07 20:46:21 +05:00
//=================================================================================
2004-12-01 15:39:14 +05:00
// function : createOperation
2004-01-07 20:46:21 +05:00
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
return getGeomEngine()->GetILocalOperations(getStudyId());
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
2004-12-01 15:39:14 +05:00
//=================================================================================
2009-02-13 17:16:39 +05:00
// function : isValid()
2004-12-01 15:39:14 +05:00
// purpose : Verify validity of input data
//=================================================================================
2009-02-13 17:16:39 +05:00
bool OperationGUI_ChamferDlg::isValid (QString& msg)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
bool ok = true;
switch (getConstructorId())
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
case 0:
ok = mySpinBox[ SpinBox1 ]->isValid( msg, !IsPreview() );
return !myShape->_is_nil() && ok;
case 1:
if (myRadioButton[ RadioButton21 ]->isChecked())
{
ok = mySpinBox[ SpinBox21 ]->isValid( msg, !IsPreview() ) && ok;
ok = mySpinBox[ SpinBox22 ]->isValid( msg, !IsPreview() ) && ok;
}
else
{
ok = mySpinBox[ SpinBox23 ]->isValid( msg, !IsPreview() ) && ok;
ok = mySpinBox[ SpinBox24 ]->isValid( msg, !IsPreview() ) && ok;
}
return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0 && ok;
case 2:
if (myRadioButton[ RadioButton31 ]->isChecked())
{
ok = mySpinBox[ SpinBox31 ]->isValid( msg, !IsPreview() ) && ok;
ok = mySpinBox[ SpinBox32 ]->isValid( msg, !IsPreview() ) && ok;
}
else
{
ok = mySpinBox[ SpinBox33 ]->isValid( msg, !IsPreview() ) && ok;
ok = mySpinBox[ SpinBox34 ]->isValid( msg, !IsPreview() ) && ok;
}
return !myShape->_is_nil() && myFaces.Extent() > 0 && ok;
case 3:
if (myRadioButton[ RadioButton41 ]->isChecked())
{
ok = mySpinBox[ SpinBox41 ]->isValid( msg, !IsPreview() ) && ok;
ok = mySpinBox[ SpinBox42 ]->isValid( msg, !IsPreview() ) && ok;
}
else
{
ok = mySpinBox[ SpinBox43 ]->isValid( msg, !IsPreview() ) && ok;
ok = mySpinBox[ SpinBox44 ]->isValid( msg, !IsPreview() ) && ok;
}
return !myShape->_is_nil() && myEdges.Extent() > 0 && ok;
2004-12-01 15:39:14 +05:00
default: return false;
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
bool OperationGUI_ChamferDlg::execute (ObjectList& objects)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
QStringList aParameters;
2004-12-01 15:39:14 +05:00
GEOM::GEOM_Object_var anObj;
2009-02-13 17:16:39 +05:00
bool flag = (myRadioButton[ RadioButton21 ]->isChecked() &&
myRadioButton[ RadioButton31 ]->isChecked() &&
myRadioButton[ RadioButton41 ]->isChecked());
2004-12-01 15:39:14 +05:00
int anId = getConstructorId();
2009-02-13 17:16:39 +05:00
if (anId == 0) {
anObj = GEOM::GEOM_ILocalOperations::_narrow(getOperation())->
MakeChamferAll(myShape, mySpinBox[ SpinBox1 ]->value());
if (!anObj->_is_nil())
aParameters << mySpinBox[ SpinBox1 ]->text();
}
else if (anId == 1) {
if (flag) {
anObj = GEOM::GEOM_ILocalOperations::_narrow(getOperation())->
MakeChamferEdge(myShape,
mySpinBox[ SpinBox21 ]->value(),
mySpinBox[ SpinBox22 ]->value(),
myFace[ Face1 ],
myFace[ Face2 ]);
if (!anObj->_is_nil())
{
aParameters << mySpinBox[ SpinBox21 ]->text();
aParameters << mySpinBox[ SpinBox22 ]->text();
}
}
else {
anObj = GEOM::GEOM_ILocalOperations::_narrow(getOperation())->
MakeChamferEdgeAD(myShape,
mySpinBox[ SpinBox23 ]->value(),
mySpinBox[ SpinBox24 ]->value() * PI180,
myFace[ Face1 ],
myFace[ Face2 ]);
if (!anObj->_is_nil())
{
aParameters << mySpinBox[ SpinBox23 ]->text();
aParameters << mySpinBox[ SpinBox24 ]->text();
}
}
2009-02-13 17:16:39 +05:00
}
else if (anId == 2)
2004-12-01 15:39:14 +05:00
{
GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
2009-02-13 17:16:39 +05:00
anArray->length(myFaces.Extent());
for (int i = 1, n = myFaces.Extent(); i <= n; i++)
anArray[ i - 1 ] = myFaces(i);
if (flag) {
anObj = GEOM::GEOM_ILocalOperations::_narrow(getOperation())->
MakeChamferFaces(myShape,
mySpinBox[ SpinBox31 ]->value(),
mySpinBox[ SpinBox32 ]->value(),
anArray);
if (!anObj->_is_nil())
{
aParameters << mySpinBox[ SpinBox31 ]->text();
aParameters << mySpinBox[ SpinBox32 ]->text();
}
}
else {
anObj = GEOM::GEOM_ILocalOperations::_narrow(getOperation())->
MakeChamferFacesAD(myShape,
mySpinBox[ SpinBox33 ]->value(),
mySpinBox[ SpinBox34 ]->value() * PI180,
anArray);
if (!anObj->_is_nil())
{
aParameters << mySpinBox[ SpinBox33 ]->text();
aParameters << mySpinBox[ SpinBox34 ]->text();
}
}
}
2009-02-13 17:16:39 +05:00
else if (anId == 3) {
GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
2009-02-13 17:16:39 +05:00
anArray->length(myEdges.Extent());
for (int i = 1, n = myEdges.Extent(); i <= n; i++)
anArray[ i - 1 ] = myEdges(i);
if (flag) {
anObj = GEOM::GEOM_ILocalOperations::_narrow(getOperation())->
MakeChamferEdges(myShape,
mySpinBox[ SpinBox41 ]->value(),
mySpinBox[ SpinBox42 ]->value(),
anArray);
if (!anObj->_is_nil())
{
aParameters << mySpinBox[ SpinBox41 ]->text();
aParameters << mySpinBox[ SpinBox42 ]->text();
}
}
else {
anObj = GEOM::GEOM_ILocalOperations::_narrow(getOperation())->
MakeChamferEdgesAD(myShape,
mySpinBox[ SpinBox43 ]->value(),
mySpinBox[ SpinBox44 ]->value() * PI180,
anArray);
if (!anObj->_is_nil())
{
aParameters << mySpinBox[ SpinBox43 ]->text();
aParameters << mySpinBox[ SpinBox44 ]->text();
}
}
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if (!anObj->_is_nil())
{
if (!IsPreview())
anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
objects.push_back(anObj._retn());
}
2004-12-01 15:39:14 +05:00
return true;
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
//=================================================================================
// function : RadioButtonPressed()
// purpose :
//=================================================================================
void OperationGUI_ChamferDlg::RadioButtonPressed()
{
const QObject* s = sender();
bool flag = s == myRadioButton[ RadioButton21 ] ||
s == myRadioButton[ RadioButton31 ] ||
s == myRadioButton[ RadioButton41 ];
myRadioButton[ RadioButton21 ]->blockSignals(true);
myRadioButton[ RadioButton22 ]->blockSignals(true);
myRadioButton[ RadioButton31 ]->blockSignals(true);
myRadioButton[ RadioButton32 ]->blockSignals(true);
myRadioButton[ RadioButton41 ]->blockSignals(true);
myRadioButton[ RadioButton42 ]->blockSignals(true);
myRadioButton[ RadioButton21 ]->setChecked(flag);
myRadioButton[ RadioButton31 ]->setChecked(flag);
myRadioButton[ RadioButton41 ]->setChecked(flag);
myRadioButton[ RadioButton22 ]->setChecked(!flag);
myRadioButton[ RadioButton32 ]->setChecked(!flag);
myRadioButton[ RadioButton42 ]->setChecked(!flag);
mySpinBox[ SpinBox21 ]->setEnabled(flag);
mySpinBox[ SpinBox22 ]->setEnabled(flag);
mySpinBox[ SpinBox31 ]->setEnabled(flag);
mySpinBox[ SpinBox32 ]->setEnabled(flag);
mySpinBox[ SpinBox41 ]->setEnabled(flag);
mySpinBox[ SpinBox42 ]->setEnabled(flag);
mySpinBox[ SpinBox23 ]->setEnabled(!flag);
mySpinBox[ SpinBox24 ]->setEnabled(!flag);
mySpinBox[ SpinBox33 ]->setEnabled(!flag);
mySpinBox[ SpinBox34 ]->setEnabled(!flag);
mySpinBox[ SpinBox43 ]->setEnabled(!flag);
mySpinBox[ SpinBox44 ]->setEnabled(!flag);
myRadioButton[ RadioButton21 ]->blockSignals(false);
myRadioButton[ RadioButton22 ]->blockSignals(false);
myRadioButton[ RadioButton31 ]->blockSignals(false);
myRadioButton[ RadioButton32 ]->blockSignals(false);
myRadioButton[ RadioButton41 ]->blockSignals(false);
myRadioButton[ RadioButton42 ]->blockSignals(false);
displayPreview();
}