From 243146628b86ca970eb907a8291b901fc49cb442 Mon Sep 17 00:00:00 2001 From: jfa Date: Tue, 24 May 2005 11:45:28 +0000 Subject: [PATCH] IPAL8817: T1.5: Incorrect position of the clipping plane preview when a presentation is translated --- src/VISUGUI/VisuGUI_ClippingDlg.cxx | 148 +++++++++++++++------------- 1 file changed, 78 insertions(+), 70 deletions(-) diff --git a/src/VISUGUI/VisuGUI_ClippingDlg.cxx b/src/VISUGUI/VisuGUI_ClippingDlg.cxx index 1da1a797..d579747b 100644 --- a/src/VISUGUI/VisuGUI_ClippingDlg.cxx +++ b/src/VISUGUI/VisuGUI_ClippingDlg.cxx @@ -65,7 +65,7 @@ namespace VISU { } } -void RangeStepAndValidator (QAD_SpinBoxDbl* theSpinBox, double min, double max, + void RangeStepAndValidator (QAD_SpinBoxDbl* theSpinBox, double min, double max, double step, unsigned short decimals) { theSpinBox->setRange(min, max); @@ -76,7 +76,7 @@ void RangeStepAndValidator (QAD_SpinBoxDbl* theSpinBox, double min, double max, //======================================================================= //class : OrientedPlane -//purpose : +//purpose : //======================================================================= class OrientedPlane: public vtkPlane @@ -84,7 +84,7 @@ class OrientedPlane: public vtkPlane QAD_Study* myStudy; QAD_StudyFrame* myStudyFrame; VTKViewer_ViewFrame* myViewFrame; - + vtkDataSetMapper* myMapper; public: @@ -95,15 +95,15 @@ public: return new OrientedPlane(theStudy); } vtkTypeMacro(OrientedPlane, vtkPlane); - - + + VISU::Orientation myOrientation; float myDistance; double myAngle[2]; vtkPlaneSource* myPlaneSource; SALOME_Actor *myActor; - + void SetOrientation(VISU::Orientation theOrientation) {myOrientation = theOrientation;} VISU::Orientation GetOrientation() {return myOrientation;} @@ -156,7 +156,7 @@ protected: // Create and display actor myMapper = vtkDataSetMapper::New(); myMapper->SetInput( myPlaneSource->GetOutput() ); - + myActor = SALOME_Actor::New(); myActor->VisibilityOff(); myActor->PickableOff(); @@ -172,7 +172,7 @@ protected: aProp->SetOpacity(0.75); myActor->SetProperty( aProp ); aProp->Delete(); - + vtkProperty* aBackProp = vtkProperty::New(); anRGB[0] = VISU::GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.; anRGB[1] = VISU::GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.; @@ -197,10 +197,10 @@ protected: myPlaneSource->UnRegisterAllOutputs(); myPlaneSource->Delete(); }; - + private: // Not implemented. - OrientedPlane(const OrientedPlane&); + OrientedPlane(const OrientedPlane&); void operator=(const OrientedPlane&); }; @@ -214,7 +214,7 @@ struct TSetVisiblity { //================================================================================= // class : VisuGUI_ClippingDlg() -// purpose : +// purpose : // //================================================================================= VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (QWidget* parent, @@ -228,7 +228,7 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (QWidget* parent, setName( "VisuGUI_ClippingDlg" ); setCaption( tr( "VISU_CLIPPING_TITLE" ) ); setSizeGripEnabled( TRUE ); - QGridLayout* VisuGUI_ClippingDlgLayout = new QGridLayout( this ); + QGridLayout* VisuGUI_ClippingDlgLayout = new QGridLayout( this ); VisuGUI_ClippingDlgLayout->setSpacing( 6 ); VisuGUI_ClippingDlgLayout->setMargin( 11 ); @@ -243,17 +243,17 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (QWidget* parent, GroupPlanesLayout->setAlignment( Qt::AlignTop ); GroupPlanesLayout->setSpacing( 6 ); GroupPlanesLayout->setMargin( 11 ); - + ComboBoxPlanes = new QComboBox(GroupPlanes, "ComboBoxPlanes"); GroupPlanesLayout->addWidget( ComboBoxPlanes, 0, 0 ); - + QSpacerItem* spacerGP = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); GroupPlanesLayout->addItem( spacerGP, 0, 1 ); - + buttonNew = new QPushButton( GroupPlanes, "buttonNew" ); buttonNew->setText( tr( "VISU_BUT_NEW" ) ); GroupPlanesLayout->addWidget( buttonNew, 0, 2 ); - + buttonDelete = new QPushButton( GroupPlanes, "buttonDelete" ); buttonDelete->setText( tr( "VISU_BUT_DELETE" ) ); GroupPlanesLayout->addWidget( buttonDelete, 0, 3 ); @@ -288,7 +288,7 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (QWidget* parent, QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) ); - GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); + GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); GroupButtons->setTitle( tr( "" ) ); GroupButtons->setColumnLayout(0, Qt::Vertical ); GroupButtons->layout()->setSpacing( 0 ); @@ -318,7 +318,7 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (QWidget* parent, VisuGUI_ClippingDlgLayout->addWidget( PreviewCheckBox, 2, 0 ); VisuGUI_ClippingDlgLayout->addWidget( AutoApplyCheckBox, 2, 1 ); VisuGUI_ClippingDlgLayout->addMultiCellWidget( GroupButtons, 3, 3, 0, 1 ); - + // mySelection = SALOME_Selection::Selection( VisuGUI::GetVisuGUI()->GetActiveStudy()->getSelection()); // Initial state @@ -335,7 +335,7 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (QWidget* parent, myPrs3d = 0; myIsSelectPlane = false; onSelectionChanged(); - + // signals and slots connections : connect( ComboBoxPlanes, SIGNAL( activated( int )), this, SLOT( onSelectPlane( int ) ) ); connect( buttonNew, SIGNAL( clicked() ), this, SLOT( ClickOnNew() ) ); @@ -348,7 +348,7 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (QWidget* parent, connect( SpinBoxIJKIndex, SIGNAL( valueChanged( int )), this, SLOT( SetCurrentPlaneIJKParam())); connect( CheckBoxIJKPlaneReverse, SIGNAL(toggled(bool)), this, SLOT( SetCurrentPlaneIJKParam())); connect( TabPane, SIGNAL( currentChanged ( QWidget* )), this, SLOT( onTabChanged( QWidget* ))); - + connect( PreviewCheckBox, SIGNAL( toggled( bool )), this, SLOT( OnPreviewToggle( bool ) ) ); connect( AutoApplyCheckBox, SIGNAL( toggled( bool )), this, SLOT( ClickOnApply() ) ); connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); @@ -382,7 +382,7 @@ VisuGUI_ClippingDlg::~VisuGUI_ClippingDlg() //======================================================================= //function : createParamsTab -//purpose : +//purpose : //======================================================================= QWidget* VisuGUI_ClippingDlg::createParamsTab() @@ -392,14 +392,14 @@ QWidget* VisuGUI_ClippingDlg::createParamsTab() GroupParametersLayout->setAlignment( Qt::AlignTop ); GroupParametersLayout->setSpacing( 6 ); GroupParametersLayout->setMargin( 11 ); - + TextLabelOrientation = new QLabel( GroupParameters, "TextLabelOrientation" ); TextLabelOrientation->setText( tr("TXT_ORIENTATION") ); GroupParametersLayout->addWidget( TextLabelOrientation, 0, 0 ); - + ComboBoxOrientation = new QComboBox(GroupParameters, "ComboBoxOrientation"); GroupParametersLayout->addWidget( ComboBoxOrientation, 0, 1 ); - + TextLabelDistance = new QLabel( GroupParameters, "TextLabelDistance" ); TextLabelDistance->setText( tr("VISU_DISTANCE") ); GroupParametersLayout->addWidget( TextLabelDistance, 1, 0 ); @@ -413,11 +413,11 @@ QWidget* VisuGUI_ClippingDlg::createParamsTab() SpinBoxRot1 = new QAD_SpinBoxDbl( GroupParameters, "SpinBoxRot1" ); GroupParametersLayout->addWidget( SpinBoxRot1, 2, 1 ); - + TextLabelRot2 = new QLabel( GroupParameters, "TextLabelRot2" ); TextLabelRot2->setText( tr("Rotation around Y (X to Z):") ); GroupParametersLayout->addWidget( TextLabelRot2, 3, 0 ); - + SpinBoxRot2 = new QAD_SpinBoxDbl( GroupParameters, "SpinBoxRot2" ); GroupParametersLayout->addWidget( SpinBoxRot2, 3, 1 ); @@ -426,7 +426,7 @@ QWidget* VisuGUI_ClippingDlg::createParamsTab() //======================================================================= //function : createIJKParamsTab -//purpose : +//purpose : //======================================================================= QWidget* VisuGUI_ClippingDlg::createIJKParamsTab() @@ -438,19 +438,19 @@ QWidget* VisuGUI_ClippingDlg::createIJKParamsTab() IJKParametersLayout->setSpacing( 6 ); IJKParametersLayout->setMargin( 11 ); - // Axis group + // Axis group ButtonGroupIJKAxis = new QHButtonGroup( QObject::tr( "Axis" ), WidgetIJKTab); new QRadioButton( QObject::tr( "I" ), ButtonGroupIJKAxis); // 0 new QRadioButton( QObject::tr( "J" ), ButtonGroupIJKAxis); // 1 new QRadioButton( QObject::tr( "K" ), ButtonGroupIJKAxis); // 2 ButtonGroupIJKAxis->setButton(0); - // Index + // Index TextLabelIJKIndex = new QLabel( WidgetIJKTab, "TextLabelIJKIndex" ); TextLabelIJKIndex->setText( tr( "Index (from 0 to 0)" )); SpinBoxIJKIndex = new QSpinBox( WidgetIJKTab, "SpinBoxIJKIndex"); - // Orientation + // Orientation CheckBoxIJKPlaneReverse = new QCheckBox( tr("Reverse normal"), WidgetIJKTab); CheckBoxIJKPlaneReverse->setChecked(false); @@ -473,7 +473,7 @@ void VisuGUI_ClippingDlg::ClickOnApply() if (VisuGUI::GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { QAD_WaitCursor wc; - + myPrs3d->RemoveAllClippingPlanes(); VISU::TPlanes::iterator anIter = myPlanes.begin(); @@ -521,6 +521,9 @@ void VisuGUI_ClippingDlg::onSelectionChanged() std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false)); myPlanes.clear(); + float anOffset [3]; + myPrs3d->GetOffset(anOffset); + vtkIdType anId = 0, anEnd = myPrs3d->GetNumberOfClippingPlanes(); for (; anId < anEnd; anId++) { if (vtkImplicitFunction* aFunction = myPrs3d->GetClippingPlane(anId)) { @@ -529,6 +532,7 @@ void VisuGUI_ClippingDlg::onSelectionChanged() VISU::TVTKPlane aTVTKPlane(anOrientedPlane); anOrientedPlane->Delete(); aTVTKPlane->ShallowCopy(aPlane); + aTVTKPlane->myActor->SetPosition(anOffset); myPlanes.push_back(aTVTKPlane); } } @@ -551,15 +555,15 @@ void VisuGUI_ClippingDlg::onSelectionChanged() // purpose : //======================================================================= void VisuGUI_ClippingDlg::onSelectPlane(int theIndex) -{ +{ if (!myPrs3d || myPlanes.empty()) return; OrientedPlane* aPlane = myPlanes[theIndex].GetPointer(); - + // Orientation VISU::Orientation anOrientation = aPlane->GetOrientation(); - + // Rotations double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]}; @@ -592,11 +596,15 @@ void VisuGUI_ClippingDlg::ClickOnNew() { if (!myPrs3d) return; - + OrientedPlane* aPlane = OrientedPlane::New(VisuGUI::GetActiveStudy()); VISU::TVTKPlane aTVTKPlane(aPlane); myPlanes.push_back(aTVTKPlane); + float anOffset [3]; + myPrs3d->GetOffset(anOffset); + aTVTKPlane->myActor->SetPosition(anOffset); + if (PreviewCheckBox->isChecked()) aTVTKPlane->myActor->VisibilityOn(); @@ -612,13 +620,13 @@ void VisuGUI_ClippingDlg::ClickOnDelete() { if (!myPrs3d || myPlanes.empty()) return; - + int aPlaneIndex = ComboBoxPlanes->currentItem(); - + VISU::TPlanes::iterator anIter = myPlanes.begin() + aPlaneIndex; anIter->GetPointer()->myActor->SetVisibility(false); myPlanes.erase(anIter); - + if(AutoApplyCheckBox->isChecked()) ClickOnApply(); @@ -636,7 +644,7 @@ void VisuGUI_ClippingDlg::onSelectOrientation(int theItem) { if (myPlanes.empty()) return; - + if (theItem == 0) { TextLabelRot1->setText( tr( "Rotation around X (Y to Z):") ); TextLabelRot2->setText( tr( "Rotation around Y (X to Z):" ) ); @@ -649,7 +657,7 @@ void VisuGUI_ClippingDlg::onSelectOrientation(int theItem) TextLabelRot1->setText( tr( "Rotation around Z (X to Y):" ) ); TextLabelRot2->setText( tr( "Rotation around X (Z to Y):" ) ); } - + if((QComboBox*)sender() == ComboBoxOrientation) SetCurrentPlaneParam(); } @@ -662,16 +670,16 @@ void VisuGUI_ClippingDlg::Sinchronize() { int aNbPlanes = myPlanes.size(); ComboBoxPlanes->clear(); - + QString aName; for(int i = 1; i<=aNbPlanes ; i++){ aName = QString(tr("Plane# %1")).arg(i); ComboBoxPlanes->insertItem(aName); } - + int aPos = ComboBoxPlanes->count() - 1; ComboBoxPlanes->setCurrentItem(aPos); - + bool anIsControlsEnable = (aPos >= 0); if(anIsControlsEnable){ onSelectPlane(aPos); @@ -715,15 +723,15 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneParam() { if (myPlanes.empty() || myIsSelectPlane) return; - + int aCurPlaneIndex = ComboBoxPlanes->currentItem(); - + OrientedPlane* aPlane = myPlanes[aCurPlaneIndex].GetPointer(); - + float aNormal[3]; VISU::Orientation anOrientation; float aDir[3][3] = {{0, 0, 0}, {0, 0, 0}}; - { + { static double aCoeff = vtkMath::Pi()/180.0; float aRot[2] = {getRotation1(), getRotation2()}; @@ -734,10 +742,10 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneParam() float aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])}; aV[0] = aRot[0] > 0? aV[0]: -aV[0]; aV[1] = aRot[1] > 0? aV[1]: -aV[1]; - + switch (ComboBoxOrientation->currentItem()) { - case 0: - anOrientation = VISU::XY; + case 0: + anOrientation = VISU::XY; aDir[0][1] = anU[0]; aDir[0][2] = aV[0]; @@ -746,8 +754,8 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneParam() aDir[1][2] = aV[1]; break; - case 1: - anOrientation = VISU::YZ; + case 1: + anOrientation = VISU::YZ; aDir[0][2] = anU[0]; aDir[0][0] = aV[0]; @@ -756,8 +764,8 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneParam() aDir[1][0] = aV[1]; break; - case 2: - anOrientation = VISU::ZX; + case 2: + anOrientation = VISU::ZX; aDir[0][0] = anU[0]; aDir[0][1] = aV[0]; @@ -772,10 +780,10 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneParam() vtkMath::Normalize(aNormal); vtkMath::Cross(aNormal,aDir[1],aDir[0]); } - + aPlane->SetOrientation(anOrientation); aPlane->SetDistance(getDistance()); - + myPrs3d->SetPlaneParam(aNormal, 1. - getDistance(), aPlane); vtkDataSet* aDataSet = myPrs3d->GetInput(); @@ -788,27 +796,27 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneParam() {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}}; float aParam, aPnt0[3], aPnt1[3], aPnt2[3]; - float aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0], - aPnt[1] - aDelta[0][1] - aDelta[1][1], + float 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]}; - float aPnt02[3] = {aPnt01[0] + aNormal[0], - aPnt01[1] + aNormal[1], + float aPnt02[3] = {aPnt01[0] + aNormal[0], + aPnt01[1] + aNormal[1], aPnt01[2] + aNormal[2]}; vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0); - float aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0], - aPnt[1] - aDelta[0][1] + aDelta[1][1], + float 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]}; - float aPnt12[3] = {aPnt11[0] + aNormal[0], - aPnt11[1] + aNormal[1], + float aPnt12[3] = {aPnt11[0] + aNormal[0], + aPnt11[1] + aNormal[1], aPnt11[2] + aNormal[2]}; vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1); - float aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0], - aPnt[1] + aDelta[0][1] - aDelta[1][1], + float 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]}; - float aPnt22[3] = {aPnt21[0] + aNormal[0], - aPnt21[1] + aNormal[1], + float aPnt22[3] = {aPnt21[0] + aNormal[0], + aPnt21[1] + aNormal[1], aPnt21[2] + aNormal[2]}; vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2); @@ -827,7 +835,7 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneParam() //======================================================================= //function : onTabChanged -//purpose : +//purpose : //======================================================================= void VisuGUI_ClippingDlg::onTabChanged( QWidget* newTab) @@ -849,7 +857,7 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneIJKParam() VISU::Result_i* result = myPrs3d ? myPrs3d->GetResult() : 0; if ( !result ) return; - + // get axis data int i, axId = ButtonGroupIJKAxis->id ( ButtonGroupIJKAxis->selected() ); VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axId; -- 2.39.2