+
+ 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; }
+
+ 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();