+ 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] = { 0.,0.,0. };
+ double aRotation1 = 0, aRotation2 = 0;
+ 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; }
+
+ SpinSliderRotation1->setValue( qRound( aRot[0] ) );
+ SpinSliderRotation2->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;
+
+ SpinSliderDistance->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 );