smesh/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx

907 lines
29 KiB
C++
Raw Normal View History

2009-02-17 10:27:49 +05:00
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:48:31 +05:00
//
2009-02-17 10:27:49 +05:00
// Copyright (C) 2003-2007 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
//
2009-02-17 10:27:49 +05:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-12-01 15:48:31 +05:00
//
2009-02-17 10:27:49 +05:00
// SMESH SMESHGUI : GUI for SMESH component
// File : SMESHGUI_ClippingDlg.cxx
// Author : Nicolas REJNERI, Open CASCADE S.A.S.
// SMESH includes
2004-12-01 15:48:31 +05:00
//
#include "SMESHGUI_ClippingDlg.h"
#include "SMESHGUI.h"
#include "SMESHGUI_Utils.h"
#include "SMESHGUI_VTKUtils.h"
2009-02-17 10:27:49 +05:00
#include "SMESHGUI_SpinBox.h"
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
#include <SMESH_Actor.h>
#include <SMESH_ActorUtils.h>
2009-02-17 10:27:49 +05:00
// SALOME GUI includes
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <SUIT_OverrideCursor.h>
#include <SUIT_MessageBox.h>
#include <SUIT_ResourceMgr.h>
2009-02-17 10:27:49 +05:00
#include <SALOME_ListIO.hxx>
2009-02-17 10:27:49 +05:00
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
2009-02-17 10:27:49 +05:00
#include <SVTK_ViewWindow.h>
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
// Qt includes
#include <QLabel>
#include <QPushButton>
#include <QComboBox>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QKeyEvent>
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
// VTK includes
2004-12-01 15:48:31 +05:00
#include <vtkMath.h>
2009-02-17 10:27:49 +05:00
#include <vtkPlane.h>
2004-12-01 15:48:31 +05:00
#include <vtkDataSet.h>
#include <vtkDataSetMapper.h>
#include <vtkPlaneSource.h>
#include <vtkProperty.h>
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
#define SPACING 6
#define MARGIN 11
2004-12-01 15:48:31 +05:00
class OrientedPlane: public vtkPlane
{
SVTK_ViewWindow* myViewWindow;
2004-12-01 15:48:31 +05:00
vtkDataSetMapper* myMapper;
2004-12-01 15:48:31 +05:00
public:
static OrientedPlane *New()
{
2004-12-01 15:48:31 +05:00
return new OrientedPlane();
}
static OrientedPlane *New(SVTK_ViewWindow* theViewWindow)
{
return new OrientedPlane(theViewWindow);
2004-12-01 15:48:31 +05:00
}
vtkTypeMacro (OrientedPlane, vtkPlane);
2004-12-01 15:48:31 +05:00
SMESH::Orientation myOrientation;
float myDistance;
double myAngle[2];
vtkPlaneSource* myPlaneSource;
SALOME_Actor *myActor;
void SetOrientation (SMESH::Orientation theOrientation) { myOrientation = theOrientation; }
SMESH::Orientation GetOrientation() { return myOrientation; }
void SetDistance (float theDistance) { myDistance = theDistance; }
float GetDistance() { return myDistance; }
2004-12-01 15:48:31 +05:00
void ShallowCopy (OrientedPlane* theOrientedPlane)
{
2004-12-01 15:48:31 +05:00
SetNormal(theOrientedPlane->GetNormal());
SetOrigin(theOrientedPlane->GetOrigin());
myOrientation = theOrientedPlane->GetOrientation();
myDistance = theOrientedPlane->GetDistance();
myAngle[0] = theOrientedPlane->myAngle[0];
myAngle[1] = theOrientedPlane->myAngle[1];
myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
}
protected:
OrientedPlane(SVTK_ViewWindow* theViewWindow):
myViewWindow(theViewWindow),
2004-12-01 15:48:31 +05:00
myOrientation(SMESH::XY),
myDistance(0.5)
2004-12-01 15:48:31 +05:00
{
Init();
myViewWindow->AddActor(myActor);
2004-12-01 15:48:31 +05:00
}
OrientedPlane():
myOrientation(SMESH::XY),
myViewWindow(NULL),
myDistance(0.5)
2004-12-01 15:48:31 +05:00
{
Init();
}
void Init()
{
2004-12-01 15:48:31 +05:00
myPlaneSource = vtkPlaneSource::New();
myAngle[0] = myAngle[1] = 0.0;
// Create and display actor
myMapper = vtkDataSetMapper::New();
myMapper->SetInput(myPlaneSource->GetOutput());
2004-12-01 15:48:31 +05:00
myActor = SALOME_Actor::New();
myActor->VisibilityOff();
myActor->PickableOff();
myActor->SetInfinitive(true);
myActor->SetMapper(myMapper);
2004-12-01 15:48:31 +05:00
vtkFloatingPointType anRGB[3];
2005-06-27 17:29:58 +06:00
vtkProperty* aProp = vtkProperty::New();
SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
2004-12-01 15:48:31 +05:00
aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
aProp->SetOpacity(0.75);
myActor->SetProperty(aProp);
2004-12-01 15:48:31 +05:00
aProp->Delete();
2004-12-01 15:48:31 +05:00
vtkProperty* aBackProp = vtkProperty::New();
2005-06-27 17:29:58 +06:00
SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
2004-12-01 15:48:31 +05:00
aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
aBackProp->SetOpacity(0.75);
myActor->SetBackfaceProperty(aBackProp);
2004-12-01 15:48:31 +05:00
aBackProp->Delete();
}
~OrientedPlane(){
myViewWindow->RemoveActor(myActor);
2004-12-01 15:48:31 +05:00
myActor->Delete();
myMapper->RemoveAllInputs();
myMapper->Delete();
// commented: porting to vtk 5.0
// myPlaneSource->UnRegisterAllOutputs();
2004-12-01 15:48:31 +05:00
myPlaneSource->Delete();
};
2004-12-01 15:48:31 +05:00
private:
// Not implemented.
OrientedPlane (const OrientedPlane&);
void operator= (const OrientedPlane&);
2004-12-01 15:48:31 +05:00
};
struct TSetVisiblity {
2004-12-01 15:48:31 +05:00
TSetVisiblity(int theIsVisible): myIsVisible(theIsVisible){}
void operator()(SMESH::TVTKPlane& theOrientedPlane){
theOrientedPlane->myActor->SetVisibility(myIsVisible);
}
int myIsVisible;
};
2009-02-17 10:27:49 +05:00
//=================================================================================
// used in SMESHGUI::restoreVisualParameters() to avoid
// declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
//=================================================================================
void SMESHGUI_ClippingDlg::AddPlane (SMESH_Actor* theActor,
SVTK_ViewWindow* theViewWindow,
SMESH::Orientation theOrientation,
double theDistance,
vtkFloatingPointType theAngle[2])
{
OrientedPlane* aPlane = OrientedPlane::New(theViewWindow);
aPlane->myAngle[0] = theAngle[0];
aPlane->myAngle[1] = theAngle[1];
aPlane->SetOrientation(theOrientation);
aPlane->SetDistance(theDistance);
vtkFloatingPointType aNormal[3];
vtkFloatingPointType aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
{
static double aCoeff = vtkMath::Pi()/180.0;
vtkFloatingPointType anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
vtkFloatingPointType aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
switch (theOrientation) {
case SMESH::XY:
aDir[0][1] = anU[0];
aDir[0][2] = aV[0];
aDir[1][0] = anU[1];
aDir[1][2] = aV[1];
break;
case SMESH::YZ:
aDir[0][2] = anU[0];
aDir[0][0] = aV[0];
aDir[1][1] = anU[1];
aDir[1][0] = aV[1];
break;
case SMESH::ZX:
aDir[0][0] = anU[0];
aDir[0][1] = aV[0];
aDir[1][2] = anU[1];
aDir[1][1] = aV[1];
break;
}
vtkMath::Cross(aDir[1],aDir[0],aNormal);
vtkMath::Normalize(aNormal);
vtkMath::Cross(aNormal,aDir[1],aDir[0]);
}
// ???
theActor->SetPlaneParam(aNormal, theDistance, aPlane);
vtkDataSet* aDataSet = theActor->GetInput();
vtkFloatingPointType *aPnt = aDataSet->GetCenter();
vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
vtkFloatingPointType aDel = aDataSet->GetLength()/2.0;
vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
{aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
aPnt[1] - aDelta[0][1] - aDelta[1][1],
aPnt[2] - aDelta[0][2] - aDelta[1][2]};
vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
aPnt01[1] + aNormal[1],
aPnt01[2] + aNormal[2]};
vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
aPnt[1] - aDelta[0][1] + aDelta[1][1],
aPnt[2] - aDelta[0][2] + aDelta[1][2]};
vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
aPnt11[1] + aNormal[1],
aPnt11[2] + aNormal[2]};
vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
aPnt[1] + aDelta[0][1] - aDelta[1][1],
aPnt[2] + aDelta[0][2] - aDelta[1][2]};
vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
aPnt21[1] + aNormal[1],
aPnt21[2] + aNormal[2]};
vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
theActor->AddClippingPlane(aPlane);
aPlane->Delete();
}
//=================================================================================
// used in SMESHGUI::restoreVisualParameters() to avoid
// declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
//=================================================================================
void SMESHGUI_ClippingDlg::GetPlaneParam (SMESH_Actor* theActor,
int thePlaneIndex,
SMESH::Orientation& theOrientation,
double& theDistance,
vtkFloatingPointType* theAngle)
{
if (vtkPlane* aPln = theActor->GetClippingPlane(thePlaneIndex)) {
if (OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aPln)) {
theOrientation = aPlane->GetOrientation();
theDistance = aPlane->GetDistance();
theAngle[0] = aPlane->myAngle[0];
theAngle[1] = aPlane->myAngle[1];
}
}
}
2004-12-01 15:48:31 +05:00
//=================================================================================
// class : SMESHGUI_ClippingDlg()
// purpose :
2004-12-01 15:48:31 +05:00
//
//=================================================================================
2009-02-17 10:27:49 +05:00
SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule ):
QDialog( SMESH::GetDesktop(theModule) ),
mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
mySMESHGUI(theModule)
2004-12-01 15:48:31 +05:00
{
2009-02-17 10:27:49 +05:00
setModal( false );
setAttribute( Qt::WA_DeleteOnClose, true );
setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
setSizeGripEnabled(true);
QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
2004-12-01 15:48:31 +05:00
// Controls for selecting, creating, deleting planes
2009-02-17 10:27:49 +05:00
QGroupBox* GroupPlanes = new QGroupBox(tr("Clipping planes"), this);
QHBoxLayout* GroupPlanesLayout = new QHBoxLayout(GroupPlanes);
GroupPlanesLayout->setSpacing(SPACING);
GroupPlanesLayout->setMargin(MARGIN);
ComboBoxPlanes = new QComboBox(GroupPlanes);
buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
GroupPlanesLayout->addWidget(ComboBoxPlanes);
GroupPlanesLayout->addStretch();
GroupPlanesLayout->addWidget(buttonNew);
GroupPlanesLayout->addWidget(buttonDelete);
2004-12-01 15:48:31 +05:00
// Controls for defining plane parameters
2009-02-17 10:27:49 +05:00
QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
GroupParametersLayout->setSpacing(SPACING);
GroupParametersLayout->setMargin(MARGIN);
2009-02-17 10:27:49 +05:00
TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
2009-02-17 10:27:49 +05:00
ComboBoxOrientation = new QComboBox(GroupParameters);
2009-02-17 10:27:49 +05:00
TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
2009-02-17 10:27:49 +05:00
SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
2009-02-17 10:27:49 +05:00
TextLabelRot1 = new QLabel(tr("Rotation around X (Y to Z):"), GroupParameters);
2009-02-17 10:27:49 +05:00
SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
2009-02-17 10:27:49 +05:00
TextLabelRot2 = new QLabel(tr("Rotation around Y (X to Z):"), GroupParameters);
SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
2004-12-01 15:48:31 +05:00
PreviewCheckBox = new QCheckBox(tr("Show preview"), GroupParameters);
PreviewCheckBox->setChecked(true);
AutoApplyCheckBox = new QCheckBox(tr("Auto Apply"), GroupParameters);
AutoApplyCheckBox->setChecked(false);
2009-02-17 10:27:49 +05:00
GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
GroupParametersLayout->addWidget(PreviewCheckBox, 4, 0);
GroupParametersLayout->addWidget(AutoApplyCheckBox, 4, 1);
2004-12-01 15:48:31 +05:00
// Controls for "Ok", "Apply" and "Close" button
2009-02-17 10:27:49 +05:00
QGroupBox* GroupButtons = new QGroupBox(this);
QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
GroupButtonsLayout->setSpacing(SPACING);
GroupButtonsLayout->setMargin(MARGIN);
buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
buttonOk->setAutoDefault(true);
buttonOk->setDefault(true);
buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
buttonApply->setAutoDefault(true);
buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
buttonCancel->setAutoDefault(true);
buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
buttonHelp->setAutoDefault(true);
GroupButtonsLayout->addWidget(buttonOk);
GroupButtonsLayout->addSpacing(10);
GroupButtonsLayout->addWidget(buttonApply);
GroupButtonsLayout->addSpacing(10);
GroupButtonsLayout->addStretch();
GroupButtonsLayout->addWidget(buttonCancel);
GroupButtonsLayout->addWidget(buttonHelp);
SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
2004-12-01 15:48:31 +05:00
// Initial state
SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, 3);
SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, 3);
SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, 3);
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
ComboBoxOrientation->addItem(tr("|| X-Y"));
ComboBoxOrientation->addItem(tr("|| Y-Z"));
ComboBoxOrientation->addItem(tr("|| Z-X"));
2004-12-01 15:48:31 +05:00
SpinBoxDistance->SetValue(0.5);
myActor = 0;
myIsSelectPlane = false;
onSelectionChanged();
myHelpFileName = "clipping_page.html";
2004-12-01 15:48:31 +05:00
// signals and slots connections :
connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
2009-02-17 10:27:49 +05:00
connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
2004-12-01 15:48:31 +05:00
/* to close dialog if study frame change */
connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(ClickOnCancel()));
2004-12-01 15:48:31 +05:00
this->show();
}
//=================================================================================
// function : ~SMESHGUI_ClippingDlg()
// purpose :
//=================================================================================
SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
{
// no need to delete child widgets, Qt does it all for us
std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
2009-02-17 10:27:49 +05:00
if (mySMESHGUI)
if (SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(mySMESHGUI))
SMESH::RenderViewWindow(aViewWindow);
}
double SMESHGUI_ClippingDlg::getDistance() const
{
return SpinBoxDistance->GetValue();
}
void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
{
SpinBoxDistance->SetValue( theDistance );
}
double SMESHGUI_ClippingDlg::getRotation1() const
{
return SpinBoxRot1->GetValue();
}
double SMESHGUI_ClippingDlg::getRotation2() const
{
return SpinBoxRot2->GetValue();
2004-12-01 15:48:31 +05:00
}
//=======================================================================
// function : ClickOnApply()
// purpose :
//=======================================================================
2004-12-01 15:48:31 +05:00
void SMESHGUI_ClippingDlg::ClickOnApply()
{
if (!myActor)
return;
if (SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(mySMESHGUI)) {
SUIT_OverrideCursor wc;
QWidget *aCurrWid = this->focusWidget();
aCurrWid->clearFocus();
aCurrWid->setFocus();
myActor->RemoveAllClippingPlanes();
2004-12-01 15:48:31 +05:00
SMESH::TPlanes::iterator anIter = myPlanes.begin();
2009-02-17 10:27:49 +05:00
for ( ; anIter != myPlanes.end(); anIter++) {
OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
2004-12-01 15:48:31 +05:00
anOrientedPlane->ShallowCopy(anIter->GetPointer());
myActor->AddClippingPlane(anOrientedPlane);
2004-12-01 15:48:31 +05:00
anOrientedPlane->Delete();
}
2005-01-20 11:25:54 +05:00
SMESH::RenderViewWindow(aViewWindow);
2004-12-01 15:48:31 +05:00
}
}
//=======================================================================
// function : ClickOnOk()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::ClickOnOk()
{
ClickOnApply();
ClickOnCancel();
2004-12-01 15:48:31 +05:00
}
//=======================================================================
// function : ClickOnCancel()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::ClickOnCancel()
{
close();
}
//=================================================================================
// function : ClickOnHelp()
// purpose :
//=================================================================================
void SMESHGUI_ClippingDlg::ClickOnHelp()
{
LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
if (app)
app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
else {
QString platform;
#ifdef WIN32
platform = "winapplication";
#else
platform = "application";
#endif
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
arg(app->resourceMgr()->stringValue("ExternalBrowser",
platform)).
arg(myHelpFileName));
}
}
2004-12-01 15:48:31 +05:00
//=================================================================================
// function : onSelectionChanged()
// purpose : Called when selection is changed
//=================================================================================
void SMESHGUI_ClippingDlg::onSelectionChanged()
{
if (SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(mySMESHGUI)) {
const SALOME_ListIO& aList = mySelector->StoredIObjects();
if (aList.Extent() > 0) {
Handle(SALOME_InteractiveObject) IOS = aList.First();
2004-12-01 15:48:31 +05:00
myActor = SMESH::FindActorByEntry(IOS->getEntry());
if (myActor) {
2004-12-01 15:48:31 +05:00
std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
myPlanes.clear();
vtkIdType anId = 0, anEnd = myActor->GetNumberOfClippingPlanes();
2009-02-17 10:27:49 +05:00
for ( ; anId < anEnd; anId++) {
if (vtkImplicitFunction* aFunction = myActor->GetClippingPlane(anId)) {
if(OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)){
OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
SMESH::TVTKPlane aTVTKPlane(anOrientedPlane);
anOrientedPlane->Delete();
aTVTKPlane->ShallowCopy(aPlane);
myPlanes.push_back(aTVTKPlane);
}
2004-12-01 15:48:31 +05:00
}
}
2004-12-01 15:48:31 +05:00
std::for_each(myPlanes.begin(),myPlanes.end(),
TSetVisiblity(PreviewCheckBox->isChecked()));
}
}
SMESH::RenderViewWindow(aViewWindow);
2004-12-01 15:48:31 +05:00
}
Sinchronize();
}
//=======================================================================
// function : onSelectPlane()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
{
2004-12-01 15:48:31 +05:00
if (!myActor || myPlanes.empty())
return;
2004-12-01 15:48:31 +05:00
OrientedPlane* aPlane = myPlanes[theIndex].GetPointer();
2004-12-01 15:48:31 +05:00
// Orientation
SMESH::Orientation anOrientation = aPlane->GetOrientation();
2005-01-20 11:25:54 +05:00
// Rotations
2004-12-01 15:48:31 +05:00
double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
// Set plane parameters in the dialog
myIsSelectPlane = true;
setDistance(aPlane->GetDistance());
setRotation(aRot[0], aRot[1]);
switch (anOrientation) {
case SMESH::XY:
2009-02-17 10:27:49 +05:00
ComboBoxOrientation->setCurrentIndex(0);
2004-12-01 15:48:31 +05:00
onSelectOrientation(0);
break;
case SMESH::YZ:
2009-02-17 10:27:49 +05:00
ComboBoxOrientation->setCurrentIndex(1);
2004-12-01 15:48:31 +05:00
onSelectOrientation(1);
break;
case SMESH::ZX:
2009-02-17 10:27:49 +05:00
ComboBoxOrientation->setCurrentIndex(2);
2004-12-01 15:48:31 +05:00
onSelectOrientation(2);
break;
}
myIsSelectPlane = false;
}
//=======================================================================
// function : ClickOnNew()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::ClickOnNew()
{
if (!myActor)
return;
if(SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(mySMESHGUI)){
OrientedPlane* aPlane = OrientedPlane::New(aViewWindow);
SMESH::TVTKPlane aTVTKPlane(aPlane);
myPlanes.push_back(aTVTKPlane);
2004-12-01 15:48:31 +05:00
if (PreviewCheckBox->isChecked())
aTVTKPlane->myActor->VisibilityOn();
Sinchronize();
SetCurrentPlaneParam();
}
2004-12-01 15:48:31 +05:00
}
//=======================================================================
// function : ClickOnDelete()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::ClickOnDelete()
{
if (!myActor || myPlanes.empty())
return;
2009-02-17 10:27:49 +05:00
int aPlaneIndex = ComboBoxPlanes->currentIndex();
2004-12-01 15:48:31 +05:00
SMESH::TPlanes::iterator anIter = myPlanes.begin() + aPlaneIndex;
anIter->GetPointer()->myActor->SetVisibility(false);
myPlanes.erase(anIter);
2004-12-01 15:48:31 +05:00
if(AutoApplyCheckBox->isChecked())
ClickOnApply();
Sinchronize();
SMESH::RenderViewWindow(SMESH::GetCurrentVtkView());
2004-12-01 15:48:31 +05:00
}
//=======================================================================
// function : onSelectOrientation()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
2004-12-01 15:48:31 +05:00
{
if (myPlanes.empty())
return;
2004-12-01 15:48:31 +05:00
if (theItem == 0) {
TextLabelRot1->setText(tr("Rotation around X (Y to Z):"));
TextLabelRot2->setText(tr("Rotation around Y (X to Z):"));
2004-12-01 15:48:31 +05:00
}
else if (theItem == 1) {
TextLabelRot1->setText(tr("Rotation around Y (Z to X):"));
TextLabelRot2->setText(tr("Rotation around Z (Y to X):"));
2004-12-01 15:48:31 +05:00
}
else if (theItem == 2) {
TextLabelRot1->setText(tr("Rotation around Z (X to Y):"));
TextLabelRot2->setText(tr("Rotation around X (Z to Y):"));
2004-12-01 15:48:31 +05:00
}
2004-12-01 15:48:31 +05:00
if((QComboBox*)sender() == ComboBoxOrientation)
SetCurrentPlaneParam();
}
//=======================================================================
// function : Sinchronize()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::Sinchronize()
{
int aNbPlanes = myPlanes.size();
ComboBoxPlanes->clear();
2004-12-01 15:48:31 +05:00
QString aName;
for(int i = 1; i<=aNbPlanes; i++) {
2004-12-01 15:48:31 +05:00
aName = QString(tr("Plane# %1")).arg(i);
2009-02-17 10:27:49 +05:00
ComboBoxPlanes->addItem(aName);
2004-12-01 15:48:31 +05:00
}
2004-12-01 15:48:31 +05:00
int aPos = ComboBoxPlanes->count() - 1;
2009-02-17 10:27:49 +05:00
ComboBoxPlanes->setCurrentIndex(aPos);
2004-12-01 15:48:31 +05:00
bool anIsControlsEnable = (aPos >= 0);
if (anIsControlsEnable) {
2004-12-01 15:48:31 +05:00
onSelectPlane(aPos);
} else {
2009-02-17 10:27:49 +05:00
ComboBoxPlanes->addItem(tr("No planes"));
2004-12-01 15:48:31 +05:00
SpinBoxRot1->SetValue(0.0);
SpinBoxRot2->SetValue(0.0);
SpinBoxDistance->SetValue(0.5);
}
buttonDelete->setEnabled(anIsControlsEnable);
buttonApply->setEnabled(anIsControlsEnable);
PreviewCheckBox->setEnabled(anIsControlsEnable);
AutoApplyCheckBox->setEnabled(anIsControlsEnable);
ComboBoxOrientation->setEnabled(anIsControlsEnable);
SpinBoxDistance->setEnabled(anIsControlsEnable);
SpinBoxRot1->setEnabled(anIsControlsEnable);
SpinBoxRot2->setEnabled(anIsControlsEnable);
}
//=======================================================================
// function : setRotation()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
2004-12-01 15:48:31 +05:00
{
SpinBoxRot1->SetValue(theRot1);
SpinBoxRot2->SetValue(theRot2);
}
//=======================================================================
// function : SetCurrentPlaneParam()
2004-12-01 15:48:31 +05:00
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
2004-12-01 15:48:31 +05:00
{
if (myPlanes.empty() || myIsSelectPlane)
2004-12-01 15:48:31 +05:00
return;
2009-02-17 10:27:49 +05:00
int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
2004-12-01 15:48:31 +05:00
OrientedPlane* aPlane = myPlanes[aCurPlaneIndex].GetPointer();
vtkFloatingPointType aNormal[3];
2004-12-01 15:48:31 +05:00
SMESH::Orientation anOrientation;
vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
{
2004-12-01 15:48:31 +05:00
static double aCoeff = vtkMath::Pi()/180.0;
vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
2004-12-01 15:48:31 +05:00
aPlane->myAngle[0] = aRot[0];
aPlane->myAngle[1] = aRot[1];
vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
2004-12-01 15:48:31 +05:00
aV[0] = aRot[0] > 0? aV[0]: -aV[0];
aV[1] = aRot[1] > 0? aV[1]: -aV[1];
2009-02-17 10:27:49 +05:00
switch (ComboBoxOrientation->currentIndex()) {
case 0:
anOrientation = SMESH::XY;
2004-12-01 15:48:31 +05:00
aDir[0][1] = anU[0];
aDir[0][2] = aV[0];
aDir[1][0] = anU[1];
aDir[1][2] = aV[1];
break;
case 1:
anOrientation = SMESH::YZ;
2004-12-01 15:48:31 +05:00
aDir[0][2] = anU[0];
aDir[0][0] = aV[0];
aDir[1][1] = anU[1];
aDir[1][0] = aV[1];
break;
case 2:
anOrientation = SMESH::ZX;
2004-12-01 15:48:31 +05:00
aDir[0][0] = anU[0];
aDir[0][1] = aV[0];
aDir[1][2] = anU[1];
aDir[1][1] = aV[1];
break;
}
vtkMath::Cross(aDir[1],aDir[0],aNormal);
vtkMath::Normalize(aNormal);
vtkMath::Cross(aNormal,aDir[1],aDir[0]);
}
2004-12-01 15:48:31 +05:00
aPlane->SetOrientation(anOrientation);
aPlane->SetDistance(getDistance());
2004-12-01 15:48:31 +05:00
myActor->SetPlaneParam(aNormal, getDistance(), aPlane);
vtkDataSet* aDataSet = myActor->GetInput();
vtkFloatingPointType *aPnt = aDataSet->GetCenter();
2004-12-01 15:48:31 +05:00
vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
vtkFloatingPointType aDel = aDataSet->GetLength()/2.0;
2004-12-01 15:48:31 +05:00
vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
{aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
2004-12-01 15:48:31 +05:00
vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
aPnt[1] - aDelta[0][1] - aDelta[1][1],
aPnt[2] - aDelta[0][2] - aDelta[1][2]};
vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
aPnt01[1] + aNormal[1],
aPnt01[2] + aNormal[2]};
2004-12-01 15:48:31 +05:00
vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
aPnt[1] - aDelta[0][1] + aDelta[1][1],
aPnt[2] - aDelta[0][2] + aDelta[1][2]};
vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
aPnt11[1] + aNormal[1],
aPnt11[2] + aNormal[2]};
2004-12-01 15:48:31 +05:00
vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
aPnt[1] + aDelta[0][1] - aDelta[1][1],
aPnt[2] + aDelta[0][2] - aDelta[1][2]};
vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
aPnt21[1] + aNormal[1],
aPnt21[2] + aNormal[2]};
2004-12-01 15:48:31 +05:00
vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
2004-12-01 15:48:31 +05:00
vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
2004-12-01 15:48:31 +05:00
if(AutoApplyCheckBox->isChecked())
ClickOnApply();
SMESH::RenderViewWindow(SMESH::GetCurrentVtkView());
}
2004-12-01 15:48:31 +05:00
//=======================================================================
// function : OnPreviewToggle()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
{
2004-12-01 15:48:31 +05:00
std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled));
SMESH::RenderViewWindow(SMESH::GetCurrentVtkView());
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : keyPressEvent()
// purpose :
//=================================================================================
void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
{
QDialog::keyPressEvent( e );
if ( e->isAccepted() )
return;
2009-02-17 10:27:49 +05:00
if ( e->key() == Qt::Key_F1 ) {
e->accept();
ClickOnHelp();
}
}