+
+/*!
+ SLOT on new button click: create a new clipping plane
+*/
+void SMESHGUI_ClippingDlg::ClickOnNew()
+{
+ if(myViewWindow) {
+ SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
+ SMESH::TPlane aTPlane(aPlane);
+ aPlane->PlaneMode = CurrentMode;
+ SMESH::TActorList anActorList;
+ VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
+ vtkActorCollection* anAllActors = aCopy.GetActors();
+ anAllActors->InitTraversal();
+ while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
+ if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
+ anActorList.push_back( anActor );
+
+ SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
+
+ myPlanes.push_back(aPlaneData);
+
+
+ std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
+ aPlane->myActor->SetVisibility( false );
+
+ bool anIsBlocked = ActorList->blockSignals( true );
+
+ SMESH::ComputeBounds( anActorList, myBounds );
+ myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
+ myBounds[3],myBounds[4],myBounds[5] );
+ synchronize();
+ SetCurrentPlaneParam();
+
+ ActorList->blockSignals( anIsBlocked );
+ }
+}
+
+/*!
+ SLOT on delete button click: Delete selected clipping plane
+*/
+void SMESHGUI_ClippingDlg::ClickOnDelete()
+{
+ if (myPlanes.empty())
+ return;
+
+ int aPlaneIndex = ComboBoxPlanes->currentIndex();
+
+ SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
+ SMESH::TPlaneData aPlaneData = *anIter;
+ aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
+ myPlanes.erase(anIter);
+
+ if(AutoApplyCheckBox->isChecked())
+ ClickOnApply();
+
+ synchronize();
+ SMESH::RenderViewWindow( myViewWindow );
+}
+
+/*!
+ Set current parameters of selected plane
+*/
+void SMESHGUI_ClippingDlg::onSelectPlane ( int theIndex )
+{
+ if ( myPlanes.empty() )
+ return;
+
+ SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
+ SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
+
+ myIsSelectPlane = true;
+ isOpenGLClipping->setChecked( aPlane->IsOpenGLClipping );
+
+ if ( aPlane->PlaneMode == SMESH::Absolute ) {
+ ModeStackedLayout->setCurrentIndex( 0 );
+ CurrentMode = SMESH::Absolute;
+ int anOrientation = aPlane->myAbsoluteOrientation;
+ // Set plane parameters in the dialog
+ double anOrigin[3], aDir[3];
+ anOrigin[0] = aPlane->X;
+ anOrigin[1] = aPlane->Y;
+ anOrigin[2] = aPlane->Z;
+ setOrigin( anOrigin );
+ aDir[0] = aPlane->Dx;
+ aDir[1] = aPlane->Dy;
+ aDir[2] = aPlane->Dz;
+ setDirection( aDir );
+ CBAbsoluteOrientation->setCurrentIndex( anOrientation );
+ onSelectAbsoluteOrientation( anOrientation );
+ }
+ else if ( aPlane->PlaneMode == SMESH::Relative ) {
+ ModeStackedLayout->setCurrentIndex( 1 );
+ CurrentMode = SMESH::Relative;
+ SMESH::Orientation anOrientation = aPlane->GetOrientation();
+ double aRot[2] = { aPlane->myAngle[0], aPlane->myAngle[1] };
+ // Set plane parameters in the dialog
+ setDistance( aPlane->GetDistance() );
+ setRotation( aRot[0], aRot[1] );
+ switch ( anOrientation ) {
+ case SMESH::XY:
+ CBRelativeOrientation->setCurrentIndex(0);
+ onSelectRelativeOrientation(0);
+ break;
+ case SMESH::YZ:
+ CBRelativeOrientation->setCurrentIndex(1);
+ onSelectRelativeOrientation(1);
+ break;
+ case SMESH::ZX:
+ CBRelativeOrientation->setCurrentIndex(2);
+ onSelectRelativeOrientation(2);
+ break;
+ }
+ }
+ myIsSelectPlane = false;
+ SMESH::ComputeBounds( aPlaneData.ActorList, myBounds );
+ myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
+ myBounds[3], myBounds[4], myBounds[5] );
+ SetCurrentPlaneParam();
+
+ // Actors
+ bool anIsBlocked = ActorList->blockSignals( true );
+ updateActorList();
+ ActorList->blockSignals( anIsBlocked );
+}
+
+/*!
+ SLOT: called on OpenGLClipping check box toggled
+*/
+void SMESHGUI_ClippingDlg::onIsOpenGLClipping( bool toggled )
+{
+ if ( myPlanes.empty() || myIsSelectPlane )
+ return;
+
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+ SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
+ SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
+ aPlaneData->IsOpenGLClipping = toggled;
+
+ if( AutoApplyCheckBox->isChecked() )
+ ClickOnApply();
+}
+
+/*!
+ SLOT: called on SelectAll check box toggled
+*/
+void SMESHGUI_ClippingDlg::onSelectAll( int theState )
+{
+ if( theState == Qt::PartiallyChecked ) {
+ SelectAllCheckBox->setCheckState( Qt::Checked );
+ return;
+ }
+
+ bool anIsBlocked = ActorList->blockSignals( true );
+ for( int i = 0, n = ActorList->count(); i < n; i++ ) {
+ if( QListWidgetItem* anItem = ActorList->item( i ) ) {
+ anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
+ updateActorItem( anItem, false, true );
+ }
+ }
+ SelectAllCheckBox->setTristate( false );
+ ActorList->blockSignals( anIsBlocked );
+ SetCurrentPlaneParam();
+}
+
+/*!
+ SLOT: called when actor item was changed
+*/
+void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
+{
+ updateActorItem( theItem, true, true );
+ SetCurrentPlaneParam();
+}
+
+/*!
+ Restore parameters of selected plane
+*/
+void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
+{
+ if ( myPlanes.empty() || myIsSelectPlane )
+ return;
+
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+
+ SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
+ SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
+
+ if ( aPlane->PlaneMode == SMESH::Absolute ) {
+ aPlane->myAbsoluteOrientation = CBAbsoluteOrientation->currentIndex();
+ aPlane->X = SpinBox_X->value();
+ aPlane->Y = SpinBox_Y->value();
+ aPlane->Z = SpinBox_Z->value();
+ aPlane->Dx = SpinBox_Dx->value();
+ aPlane->Dy = SpinBox_Dy->value();
+ aPlane->Dz = SpinBox_Dz->value();
+ }
+
+ double aNormal[3];
+ double aDir[2][3] = { {0, 0, 0}, {0, 0, 0} };
+ static double aCoeff = vtkMath::Pi()/180.0;
+
+ double aRot[2] = { getRotation1(), getRotation2() };
+ int anOrient;
+ if ( aPlane->PlaneMode == SMESH::Absolute )
+ anOrient = CBAbsoluteOrientation->currentIndex();
+ else if ( aPlane->PlaneMode == SMESH::Relative )
+ anOrient = CBRelativeOrientation->currentIndex() + 1;
+
+ if ( aPlane->PlaneMode == SMESH::Relative ) {
+ aPlane->myAngle[0] = aRot[0];
+ aPlane->myAngle[1] = aRot[1];
+ aPlane->SetOrientation( SMESH::Orientation( CBRelativeOrientation->currentIndex() ) );
+ aPlane->SetDistance( getDistance() );
+ }
+
+ if ( anOrient == 0 ) {
+ // compute a direction for plane in absolute mode
+ double znam = sqrt( aPlane->Dx*aPlane->Dx + aPlane->Dy*aPlane->Dy + aPlane->Dz*aPlane->Dz );
+ double aRotation = acos( aPlane->Dy/znam )/aCoeff;
+ if ( aPlane->Dy >= 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = 90.0 + aRotation;
+ else if ( aPlane->Dy >= 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 90.0 - aRotation;
+ else if ( aPlane->Dy < 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = aRotation - 90.0;
+ else if ( aPlane->Dy < 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 270.0 - aRotation;
+
+ aRotation = acos( aPlane->Dx/znam )/aCoeff;
+ if ( aPlane->Dx >= 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = 90.0 + aRotation;
+ else if ( aPlane->Dx >= 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 90.0 - aRotation;
+ else if ( aPlane->Dx < 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = aRotation - 90.0;
+ else if ( aPlane->Dx < 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 270.0 - aRotation;
+ }
+
+ // compute a normal
+ rotationToNormal( aRot, anOrient, aNormal, aDir );
+
+
+ SMESH::TActorList anActorList = aPlaneData.ActorList;
+
+ double aBounds[6];
+ double anOrigin[3];
+ double aDistance;
+ aDistance = getDistance();
+ if ( aPlane->PlaneMode == SMESH::Absolute ) {
+ aNormal[0] = aPlane->Dx;
+ aNormal[1] = aPlane->Dy;
+ aNormal[2] = aPlane->Dz;
+ }
+
+ bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
+ aNormal,
+ aDistance,
+ aBounds,
+ anOrigin );
+
+ if ( aPlane->PlaneMode == SMESH::Absolute ) {
+ anOrigin[0] = aPlane->X;
+ anOrigin[1] = aPlane->Y;
+ anOrigin[2] = aPlane->Z;
+ }
+
+ if( anIsOk ) {
+ aPlane->SetNormal( aNormal );
+ aPlane->SetOrigin( anOrigin );
+
+ double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
+ ( aBounds[2] + aBounds[3] ) / 2.,
+ ( aBounds[4] + aBounds[5] ) / 2. };
+
+ double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
+ pow( aBounds[3] - aBounds[2], 2 ) +
+ pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
+
+ double 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 } };
+ double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
+
+ double 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] };
+ double aPnt02[3] = { aPnt01[0] + aNormal[0],
+ aPnt01[1] + aNormal[1],
+ aPnt01[2] + aNormal[2] };
+ vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
+
+ double 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] };
+ double aPnt12[3] = { aPnt11[0] + aNormal[0],
+ aPnt11[1] + aNormal[1],
+ aPnt11[2] + aNormal[2] };
+ vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
+
+ double 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] };
+ double 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] );
+ aPlaneSource->Update();
+ }
+
+ setBoundsForPreviewWidget();
+
+ myPreviewWidget->SetOrigin( anOrigin );
+ myPreviewWidget->SetNormal( aNormal );
+
+ if(AutoApplyCheckBox->isChecked())
+ ClickOnApply();
+
+ SMESH::RenderViewWindow( myViewWindow );
+}
+
+/*!
+ Set current bounds for preview widget
+*/
+void SMESHGUI_ClippingDlg::setBoundsForPreviewWidget()
+{
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+ SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
+ SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
+ SMESH::TActorList anActorList = aPlaneData.ActorList;
+
+ double* anOrigin = aPlane->GetOrigin();
+
+ double aBounds[6];
+ SMESH::ComputeBounds( anActorList, aBounds );
+
+ bool isBoundsChanged = false;
+
+ if( myIsPreviewMoved ) {
+ // if widget has moved by hand the bounds can to minimize
+ if( anOrigin[0] > myBounds[0] && anOrigin[0] < aBounds[0] ) {
+ myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
+ if( anOrigin[0] < myBounds[1] && anOrigin[0] > aBounds[1] ) {
+ myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
+ if( anOrigin[1] > myBounds[2] && anOrigin[1] < aBounds[2] ) {
+ myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
+ if( anOrigin[1] < myBounds[3] && anOrigin[1] > aBounds[3] ) {
+ myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
+ if( anOrigin[2] > myBounds[4] && anOrigin[2] < aBounds[4] ) {
+ myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
+ if( anOrigin[2] < myBounds[5] && anOrigin[2] > aBounds[5] ) {
+ myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
+ }
+ else {
+ // if widget has moved by dialog data the bounds can to take necessary size
+ if( anOrigin[0] < aBounds[0] ) {
+ myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
+ if( anOrigin[0] > aBounds[1] ) {
+ myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
+ if( anOrigin[1] < aBounds[2] ) {
+ myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
+ if( anOrigin[1] > aBounds[3] ) {
+ myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
+ if( anOrigin[2] < aBounds[4] ) {
+ myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
+ if( anOrigin[2] > aBounds[5] ) {
+ myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
+ }
+
+ if( isBoundsChanged )
+ myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
+ myBounds[3],myBounds[4],myBounds[5] );
+ else if( !myIsPreviewMoved )
+ myPreviewWidget->PlaceWidget( aBounds[0],aBounds[1],aBounds[2],
+ aBounds[3],aBounds[4],aBounds[5] );
+
+}
+
+/*!
+ Convert absolute coordinates of plane to relative mode
+*/
+void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double theDir[3] )
+{
+ double aRot[2];
+
+ aRot[0] = getRotation1();
+ aRot[1] = getRotation2();
+
+ double eps = 0.0001;
+
+ int anOrientation = CBRelativeOrientation->currentIndex();
+ double aDirection[3];
+ double aRotation1, aRotation2;
+ switch( anOrientation ) {
+ case 0:
+ aDirection[0] = theDir[0] + eps;
+ aDirection[1] = theDir[1] + eps;
+ aDirection[2] = theDir[2] + eps;
+ aRotation1 = atan2( theDir[2], theDir[1] )*180.0/M_PI;
+ aRotation2 = atan2( theDir[2], theDir[0] )*180.0/M_PI;
+ break;
+ case 1:
+ aDirection[0] = theDir[1] + eps;
+ aDirection[1] = theDir[2] + eps;
+ aDirection[2] = theDir[0] + eps;
+ aRotation1 = atan2( theDir[0], theDir[2] )*180.0/M_PI;
+ aRotation2 = atan2( theDir[0], theDir[1] )*180.0/M_PI;
+ break;
+ case 2:
+ aDirection[0] = theDir[2] + eps;
+ aDirection[1] = theDir[0] + eps;
+ aDirection[2] = theDir[1] + eps;
+ aRotation1 = atan2( theDir[1], theDir[0] )*180.0/M_PI;
+ aRotation2 = atan2( theDir[1], theDir[2] )*180.0/M_PI;
+ break;
+ }
+
+ if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
+ aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
+ else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
+ aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 90.0; }
+ else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
+ aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
+ else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
+ aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 90.0; }
+ else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
+ aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 + 90.0; }
+ else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
+ aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
+ else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
+ aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 90.0; }
+ else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
+ aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
+ else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
+ aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
+ else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
+ aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 270.0; }
+ else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
+ aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
+ else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
+ aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
+ else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
+ aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 - 270.0; }
+ else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
+ aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
+ else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
+ aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
+ else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
+ aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
+
+ SliderRotation1HasMoved( qRound( aRot[0] ) );
+ SliderRotation1->setValue( qRound( aRot[0] ) );
+ SliderRotation2HasMoved( qRound( aRot[1] ) );
+ SliderRotation2->setValue( qRound( aRot[1] ) );
+
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+ const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
+ const SMESH::TActorList& anActorList = aPlaneData.ActorList;
+
+ double aBounds[6];
+ double aDist;
+ SMESH::ComputeBounds( anActorList, aBounds );
+ SMESH::PositionToDistance( aBounds, theDir, theOrigin, aDist );
+ aDist = 1.0 - aDist;
+ if( aDist>1.0 )
+ aDist = 1.0;
+ else if( aDist < 0.0 )
+ aDist = 0.0;
+
+ SliderDistanceHasMoved( qRound( aDist*100 ) );
+ SliderDistance->setValue( qRound( aDist*100 ) );
+ return;
+}
+
+/*!
+ SLOT: called on preview check box toggled
+*/
+void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
+{
+ std::for_each( myPlanes.begin(), myPlanes.end(), TSetVisibility( theIsToggled ) );
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+ SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
+ SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
+ aPlaneData->myActor->SetVisibility( false );
+ if( theIsToggled )
+ myPreviewWidget->On();
+ else
+ myPreviewWidget->Off();
+ SMESH::RenderViewWindow( myViewWindow );
+}
+
+/*!
+ SLOT: called on Auto Apply check box toggled
+*/
+void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
+{
+ if ( toggled ) ClickOnApply();
+}
+
+/*!
+ SLOT on ok button click: sets cutting plane and closes dialog
+*/
+void SMESHGUI_ClippingDlg::ClickOnOk()
+{
+ ClickOnApply();
+ accept();
+}
+
+
+/*!
+ SLOT on Apply button click: sets cutting plane and update viewer
+*/
+void SMESHGUI_ClippingDlg::ClickOnApply()
+{
+ if (myViewWindow) {
+ SUIT_OverrideCursor wc;
+
+ QWidget *aCurrWid = this->focusWidget();
+ aCurrWid->clearFocus();
+ aCurrWid->setFocus();
+
+ SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
+ SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
+
+ // clean memory allocated for planes
+ SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
+ for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
+ if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
+ aPlane->Delete();
+
+ aClippingPlaneInfoList.clear();
+
+ VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
+ vtkActorCollection* anAllActors = aCopy.GetActors();
+ anAllActors->InitTraversal();
+ while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
+ if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
+ anActor->RemoveAllClippingPlanes();
+
+ SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
+ for( ; anIter2 != myPlanes.end(); anIter2++ ) {
+ SMESH::TPlaneData aPlaneData = *anIter2;
+ SMESH::TPlane aPlane = aPlaneData.Plane;
+ SMESH::TActorList anActorList = aPlaneData.ActorList;
+
+ // the check is disabled to support planes with empty actor list
+ //if( anActorList.empty() )
+ // continue;
+
+ SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
+ anOrientedPlane->ShallowCopy(aPlane.GetPointer());
+ SMESH::TActorList::iterator anIter3 = anActorList.begin();
+ for( ; anIter3 != anActorList.end(); anIter3++ )
+ if( vtkActor* aVTKActor = *anIter3 )
+ if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
+ if( anOrientedPlane->IsOpenGLClipping )
+ anActor->AddOpenGLClippingPlane( anOrientedPlane->InvertPlane() );
+ else
+ anActor->AddClippingPlane( anOrientedPlane );
+ }
+
+ SMESH::ClippingPlaneInfo aClippingPlaneInfo;
+ aClippingPlaneInfo.Plane = anOrientedPlane;
+ aClippingPlaneInfo.ActorList = anActorList;
+
+ aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
+ }
+
+ SMESH_Actor* anSMESHActor;
+ anAllActors->InitTraversal();
+ while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
+ if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
+ anSMESHActor = anActor;
+ anActor->SetOpenGLClippingPlane();
+ }
+
+ SMESH::RenderViewWindow( myViewWindow );
+ }
+}
+
+/*!
+ SLOT on help button click: opens a help page
+*/
+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
+ SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
+ tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+ arg(app->resourceMgr()->stringValue("ExternalBrowser",
+ platform)).
+ arg(myHelpFileName));
+ }
+}
+
+/*!
+ SLOT: Called when value of slider distance change
+*/
+void SMESHGUI_ClippingDlg::SliderDistanceHasMoved( int value )
+{
+ double new_value = value/100.;
+ TLValueDistance->setText( QString("%1").arg( new_value ) );
+ SetCurrentPlaneParam();
+}
+
+/*!
+ SLOT: Called when value of slider rotation1 change
+*/
+void SMESHGUI_ClippingDlg::SliderRotation1HasMoved( int value )
+{
+ TLValueRotation1->setText( QString("%1\xB0").arg( value ) );
+ SetCurrentPlaneParam();
+}
+
+/*!
+ SLOT: Called when value of slider rotation2 change
+*/
+void SMESHGUI_ClippingDlg::SliderRotation2HasMoved( int value )
+{
+ TLValueRotation2->setText( QString("%1\xB0").arg( value ) );
+ SetCurrentPlaneParam();
+}
+
+void SMESHGUI_ClippingDlg::onSelectAbsoluteOrientation( int mode )
+{
+ bool isUserMode = (mode==0);
+
+ TextLabelX->setEnabled( isUserMode );
+ TextLabelY->setEnabled( isUserMode );
+ TextLabelZ->setEnabled( isUserMode );
+
+ SpinBox_X->setEnabled( isUserMode );
+ SpinBox_Y->setEnabled( isUserMode );
+ SpinBox_Z->setEnabled( isUserMode );
+
+ TextLabelDx->setEnabled( isUserMode );
+ TextLabelDy->setEnabled( isUserMode );
+ TextLabelDz->setEnabled( isUserMode );
+
+ SpinBox_Dx->setEnabled( isUserMode );
+ SpinBox_Dy->setEnabled( isUserMode );
+ SpinBox_Dz->setEnabled( isUserMode );
+
+ if ( isUserMode )
+ return;
+
+ double aDx = 0, aDy = 0, aDz = 0;
+
+ if ( mode == 1 )
+ {
+ aDz = 1;
+ TextLabelZ->setEnabled( true );
+ SpinBox_Z->setEnabled( true );
+ SpinBox_Z->setFocus();
+ }
+ else if ( mode == 2 )
+ {
+ aDx = 1;
+ TextLabelX->setEnabled( true );
+ SpinBox_X->setEnabled( true );
+ SpinBox_X->setFocus();
+ }
+ else if ( mode == 3 )
+ {
+ aDy = 1;
+ TextLabelY->setEnabled( true );
+ SpinBox_Y->setEnabled( true );
+ SpinBox_Y->setFocus();
+ }
+
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+ SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
+ SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
+
+ if ( aPlaneData->IsInvert == true ) {
+ aDx = -aDx; aDy = -aDy; aDz = -aDz;
+ }
+
+ myIsSelectPlane = true;
+ SpinBox_Dx->setValue( aDx );
+ SpinBox_Dy->setValue( aDy );
+ SpinBox_Dz->setValue( aDz );
+ myIsSelectPlane = false;
+
+ SetCurrentPlaneParam();
+}
+
+/*!
+ SLOT: called on orientation of clipping plane in relative mode changed
+*/
+void SMESHGUI_ClippingDlg::onSelectRelativeOrientation ( int theItem )
+{
+ if ( myPlanes.empty() )
+ return;
+
+ if ( theItem == 0 ) {
+ TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
+ TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
+ }
+ else if ( theItem == 1 ) {
+ TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
+ TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
+ }
+ else if ( theItem == 2 ) {
+ TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
+ TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
+ }
+
+ if( (QComboBox*)sender() == CBRelativeOrientation )
+ SetCurrentPlaneParam();
+}
+
+/*!
+ SLOT on reset button click: sets default values
+*/
+void SMESHGUI_ClippingDlg::onReset()
+{
+ myIsSelectPlane = true;
+ SpinBox_X->setValue(0);
+ SpinBox_Y->setValue(0);
+ SpinBox_Z->setValue(0);
+ myIsSelectPlane = false;
+
+ SetCurrentPlaneParam();
+}
+
+/*!
+ SLOT on invert button click: inverts normal of cutting plane
+*/
+void SMESHGUI_ClippingDlg::onInvert()
+{
+ double Dx = SpinBox_Dx->value();
+ double Dy = SpinBox_Dy->value();
+ double Dz = SpinBox_Dz->value();
+
+ myIsSelectPlane = true;
+ SpinBox_Dx->setValue( -Dx );
+ SpinBox_Dy->setValue( -Dy );
+ SpinBox_Dz->setValue( -Dz );
+ myIsSelectPlane = false;
+
+ if ( !myPlanes.empty() ) {
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+ SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
+ SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
+ aPlaneData->IsInvert = !aPlaneData->IsInvert;
+ }
+ SetCurrentPlaneParam();
+}
+