- anIsOk = ComputeClippingPlaneParameters( aNormal,
- thePlane->RelativeMode.Distance,
- aBounds,
- anOrigin,
- theView3d );
- if( !anIsOk )
- return;
-
- thePlane->Dx = aNormal[0];
- thePlane->Dy = aNormal[1];
- thePlane->Dz = aNormal[2];
- thePlane->X = anOrigin[0];
- thePlane->Y = anOrigin[1];
- thePlane->Z = anOrigin[2];
+ aRelativeBounds.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
+
+ double aLength = aZmax - aZmin;
+ double aDistance = aZmax;
+
+ double aRelativeDistance = aLength > 0.01 ? aDistance / aLength : 0.0;
+ aRelativeDistance = qMin( aRelativeDistance, aLength );
+ aRelativeDistance = qMax( aRelativeDistance, 0.0 );
+ theDistance = aRelativeDistance;
+}
+
+/*!
+ Compute clipping plane size base point and normal
+ */
+
+void clipPlaneParams(OCCViewer_ClipPlane& theClipPlane, Handle(AIS_InteractiveContext) theContext,
+ double& theSize, gp_Pnt& theBasePnt, gp_Dir& theNormal, double defaultSize) {
+ double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
+ aXMin = aYMin = aZMin = DBL_MAX;
+ aXMax = aYMax = aZMax = -DBL_MAX;
+
+ getMinMaxFromContext(theContext,defaultSize,aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
+ double aSize = 50;
+
+ double aNormalX = 0.0;
+ double aNormalY = 0.0;
+ double aNormalZ = 0.0;
+ theClipPlane.OrientationToXYZ( aNormalX, aNormalY, aNormalZ );
+ gp_Pnt aBasePnt( theClipPlane.X, theClipPlane.Y, theClipPlane.Z );
+ gp_Dir aNormal( aNormalX, aNormalY, aNormalZ );
+
+ // compute clipping plane size
+ gp_Pnt aCenter = gp_Pnt( ( aXMin + aXMax ) / 2, ( aYMin + aYMax ) / 2, ( aZMin + aZMax ) / 2 );
+ double aDiag = aCenter.Distance( gp_Pnt( aXMax, aYMax, aZMax ) )*2;
+ aSize = aDiag * 1.1;
+
+ // compute clipping plane center ( redefine the base point )
+ IntAna_IntConicQuad intersector = IntAna_IntConicQuad();
+
+ intersector.Perform( gp_Lin( aCenter, aNormal), gp_Pln( aBasePnt, aNormal), Precision::Confusion() );
+
+ if ( intersector.IsDone() && intersector.NbPoints() == 1 )
+ aBasePnt = intersector.Point( 1 );
+
+ theSize = aSize;
+ theBasePnt = aBasePnt;
+ theNormal = aNormal;