0024723: Not implemented methods in Visual3d and V3d
[occt.git] / src / V3d / V3d_View.cxx
index 028e1c8..eea29d8 100644 (file)
@@ -142,14 +142,6 @@ To solve the problem (for lack of a better solution) I make 2 passes.
 #include <Graphic3d_AspectMarker3d.hxx>
 #include <Graphic3d_GraphicDriver.hxx>
 
-// S3603
-#include <Aspect_GenericColorMap.hxx>
-#include <Aspect_TypeMap.hxx>
-#include <Aspect_WidthMap.hxx>
-#include <Aspect_MarkMap.hxx>
-#include <Aspect_FontMap.hxx>
-#include <Aspect.hxx>
-
 #define V3d_FLAG_COMPUTATION   0x00000004
 
 // Perspective
@@ -167,15 +159,12 @@ To solve the problem (for lack of a better solution) I make 2 passes.
 //purpose  :
 //=============================================================================
 V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
-  MyProjModel(V3d_TPM_SCREEN),
   MyViewer(VM.operator->()),
   MyActiveLights(),
   MyViewContext (),
   myActiveLightsIterator(),
   SwitchSetFront(Standard_False),
-  MyTrsf (1, 4, 1, 4),
-  myAutoZFitIsOn (Standard_True),
-  myAutoZFitScaleFactor (1.0)
+  MyTrsf (1, 4, 1, 4)
 {
   myImmediateUpdate = Standard_False;
   MyView = new Visual3d_View(MyViewer->Viewer());
@@ -274,7 +263,6 @@ V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
 //purpose  :
 //=============================================================================
 V3d_View::V3d_View(const Handle(V3d_Viewer)& theVM,const Handle(V3d_View)& theView) :
-  MyProjModel(V3d_TPM_SCREEN),
   MyViewer(theVM.operator->()),
   MyActiveLights(),
   MyViewContext (),
@@ -295,8 +283,7 @@ V3d_View::V3d_View(const Handle(V3d_Viewer)& theVM,const Handle(V3d_View)& theVi
   MyViewContext = aFromView->Context() ;
 
   SetCamera (new Graphic3d_Camera (theView->Camera()));
-  myAutoZFitIsOn        = theView->AutoZFitMode();
-  myAutoZFitScaleFactor = theView->AutoZFitScaleFactor();
+  View()->SetAutoZFitMode (theView->View()->AutoZFitMode(), theView->View()->AutoZFitScaleFactor());
 
   MyBackground = aFromView->Background() ;
   MyGradientBackground = aFromView->GradientBackground();
@@ -404,7 +391,7 @@ void V3d_View::Remove() const
 //=============================================================================
 void V3d_View::Update() const
 {
-  if( MyView->IsDefined() )  MyView->Update() ;
+  if( MyView->IsDefined() )  MyView->Update (Aspect_TOU_ASAP) ;
 }
 
 //=============================================================================
@@ -440,6 +427,24 @@ void V3d_View::Invalidate() const
   }
 }
 
+//=============================================================================
+//function : AutoZFit
+//purpose  :
+//=============================================================================
+void V3d_View::AutoZFit()
+{
+  View()->AutoZFit();
+}
+
+//=============================================================================
+//function : ZFitAll
+//purpose  :
+//=============================================================================
+void V3d_View::ZFitAll (const Standard_Real theScaleFactor)
+{
+  View()->ZFitAll (theScaleFactor);
+}
+
 //=============================================================================
 //function : Redraw
 //purpose  :
@@ -684,7 +689,7 @@ void V3d_View::SetFront()
     myCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
   myCamera->SetUp (gp_Dir (xu, yu, zu));
 
-  AutoZFit();
+  View()->AutoZFit();
 
   SwitchSetFront = !SwitchSetFront;
 
@@ -738,7 +743,7 @@ void V3d_View::Rotate (const Standard_Real ax,
 
   myCamera->Transform (aTrsf);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -793,7 +798,7 @@ void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Stan
 
   myCamera->Transform (aTrsf);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -869,7 +874,7 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
   myCamera->Transform (aRotation);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -904,7 +909,7 @@ void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
   myCamera->Transform (aRotation);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -952,7 +957,7 @@ void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standa
 
   myCamera->Transform (aTrsf);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1005,7 +1010,7 @@ void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start)
   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
   myCamera->Transform (aRotation);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1054,40 +1059,11 @@ void V3d_View::SetTwist(const Standard_Real angle)
   myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
   myCamera->Transform (aTrsf);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
 
-//=============================================================================
-//function : SetAutoZFitMode
-//purpose  :
-//=============================================================================
-void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn, const Standard_Real theScaleFactor)
-{
-  Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
-  myAutoZFitScaleFactor = theScaleFactor;
-  myAutoZFitIsOn = theIsOn;
-}
-
-//=============================================================================
-//function : AutoZFitMode
-//purpose  :
-//=============================================================================
-Standard_Boolean V3d_View::AutoZFitMode() const
-{
-  return myAutoZFitIsOn;
-}
-
-//=============================================================================
-//function : AutoZFitScaleFactor
-//purpose  :
-//=============================================================================
-Standard_Real V3d_View::AutoZFitScaleFactor () const
-{
-  return myAutoZFitScaleFactor;
-}
-
 //=============================================================================
 //function : SetEye
 //purpose  :
@@ -1101,7 +1077,7 @@ void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard
   myCamera->SetEye (gp_Pnt (X, Y, Z));
   SetTwist (aTwistBefore);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -1131,7 +1107,7 @@ void V3d_View::SetDepth(const Standard_Real Depth)
     myCamera->SetCenter (aCameraCenter);
   }
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1151,12 +1127,9 @@ void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Sta
 
   myCamera->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
 
-  if (MyProjModel == V3d_TPM_SCREEN)
-  {
-    SetTwist(aTwistBefore);
-  }
+  SetTwist(aTwistBefore);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -1198,7 +1171,7 @@ void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation )
 
   Panning (aPanX, aPanY);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1217,7 +1190,7 @@ void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_
 
   SetTwist (aTwistBefore);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -1261,7 +1234,7 @@ void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standar
 
   myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1304,7 +1277,7 @@ void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation )
 
   myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1344,7 +1317,7 @@ void V3d_View::Reset( const Standard_Boolean update )
     myCamera->CopyMappingData (aDefaultCamera);
     myCamera->CopyOrientationData (aDefaultCamera);
 
-    AutoZFit();
+    View()->AutoZFit();
   }
 
   SwitchSetFront = Standard_False;
@@ -1376,7 +1349,7 @@ void V3d_View::SetSize (const Standard_Real theSize)
 
   myCamera->SetScale (myCamera->Aspect() >= 1.0 ? theSize / myCamera->Aspect() : theSize);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1479,7 +1452,7 @@ void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
   myCamera->SetEye (myCamStartOpEye);
   myCamera->SetCenter (myCamStartOpCenter);
   myCamera->SetScale (myCamera->Scale() / Coef);
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1506,7 +1479,7 @@ void V3d_View::SetScale( const Standard_Real Coef )
     myCamera->SetScale (myCamera->Scale() / Coef);
   }
 
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1520,7 +1493,7 @@ void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, co
   V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
 
   myCamera->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
-  AutoZFit();
+  View()->AutoZFit();
 }
 
 //=============================================================================
@@ -1546,7 +1519,7 @@ void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean the
     return;
   }
 
-  AutoZFit();
+  View()->AutoZFit();
 
   if (myImmediateUpdate || theToUpdate)
   {
@@ -1554,173 +1527,6 @@ void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean the
   }
 }
 
-//=============================================================================
-//function : AutoZFit
-//purpose  :
-//=============================================================================
-void V3d_View::AutoZFit()
-{
-  if (!AutoZFitMode())
-  {
-    return;
-  }
-
-  ZFitAll (myAutoZFitScaleFactor);
-}
-
-//=============================================================================
-//function : ZFitAll
-//purpose  :
-//=============================================================================
-void V3d_View::ZFitAll (const Standard_Real theScaleFactor)
-{
-  Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
-
-  // Method changes ZNear and ZFar planes of camera so as to fit the graphical structures
-  // by their real boundaries (computed ignoring infinite flag) into the viewing volume.
-  // In addition to the graphical boundaries, the usual min max used for fitting perspective
-  // camera. To avoid numeric errors for perspective camera the negative ZNear values are
-  // fixed using tolerance distance, relative to boundaries size. The tolerance distance
-  // should be computed using information on boundaries of primary application actors,
-  // (e.g. representing the displayed model) - to ensure that they are not unreasonably clipped.
-
-  Standard_Real aMinMax[6];    // applicative min max boundaries
-  View()->MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2],
-                        aMinMax[3], aMinMax[4], aMinMax[5],
-                        Standard_False);
-
-  Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag).
-  View()->MinMaxValues (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
-                        aGraphicBB[3], aGraphicBB[4], aGraphicBB[5],
-                        Standard_True);
-
-  // Check if anything can be adjusted
-  Standard_Real aLim = (ShortRealLast() - 1.0);
-  if (Abs (aGraphicBB[0]) > aLim || Abs (aGraphicBB[1]) > aLim || Abs (aGraphicBB[2]) > aLim ||
-      Abs (aGraphicBB[3]) > aLim || Abs (aGraphicBB[4]) > aLim || Abs (aGraphicBB[5]) > aLim)
-  {
-    SetZSize (0.0);
-    ImmediateUpdate();
-    return;
-  }
-
-  // Measure depth of boundary points from camera eye
-  gp_Pnt aPntsToMeasure[16] =
-  {
-    gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[2]),
-    gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[5]),
-    gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[2]),
-    gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[5]),
-    gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[2]),
-    gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[5]),
-    gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[2]),
-    gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[5]),
-
-    gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2]),
-    gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[5]),
-    gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[2]),
-    gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[5]),
-    gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[2]),
-    gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[5]),
-    gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[2]),
-    gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[5])
-  };
-
-  // Camera eye plane
-  gp_Dir aCamDir = myCamera->Direction();
-  gp_Pnt aCamEye = myCamera->Eye();
-  gp_Pln aCamPln (aCamEye, aCamDir);
-
-  Standard_Real aModelMinDist   = RealLast();
-  Standard_Real aModelMaxDist   = RealFirst();
-  Standard_Real aGraphicMinDist = RealLast();
-  Standard_Real aGraphicMaxDist = RealFirst();
-
-  const gp_XYZ& anAxialScale = myCamera->AxialScale();
-
-  // Get minimum and maximum distances to the eye plane
-  for (Standard_Integer aPntIt = 0; aPntIt < 16; ++aPntIt)
-  {
-    gp_Pnt aMeasurePnt = aPntsToMeasure[aPntIt];
-
-    if (Abs (aMeasurePnt.X()) > aLim || Abs (aMeasurePnt.Y()) > aLim || Abs (aMeasurePnt.Z()) > aLim)
-    {
-      continue;
-    }
-
-    aMeasurePnt = gp_Pnt (aMeasurePnt.X() * anAxialScale.X(),
-                          aMeasurePnt.Y() * anAxialScale.Y(),
-                          aMeasurePnt.Z() * anAxialScale.Z());
-
-    Standard_Real aDistance = aCamPln.Distance (aMeasurePnt);
-
-    // Check if the camera is intruded into the scene
-    if (aCamDir.IsOpposite (gp_Vec (aCamEye, aMeasurePnt), M_PI * 0.5))
-    {
-      aDistance *= -1;
-    }
-
-    Standard_Real& aChangeMinDist = aPntIt >= 8 ? aGraphicMinDist : aModelMinDist;
-    Standard_Real& aChangeMaxDist = aPntIt >= 8 ? aGraphicMaxDist : aModelMaxDist;
-    aChangeMinDist = Min (aDistance, aChangeMinDist);
-    aChangeMaxDist = Max (aDistance, aChangeMaxDist);
-  }
-
-  // Compute depth of bounding box center
-  Standard_Real aMidDepth  = (aGraphicMinDist + aGraphicMaxDist) * 0.5;
-  Standard_Real aHalfDepth = (aGraphicMaxDist - aGraphicMinDist) * 0.5;
-
-  // ShortReal precision factor used to add meaningful tolerance to
-  // ZNear, ZFar values in order to avoid equality after type conversion
-  // to ShortReal matrices type.
-  const Standard_Real aPrecision = 1.0 / Pow (10.0, ShortRealDigits() - 1);
-
-  // Compute enlarged or shrank near and far z ranges
-  Standard_Real aZNear = aMidDepth - aHalfDepth * theScaleFactor;
-  Standard_Real aZFar  = aMidDepth + aHalfDepth * theScaleFactor;
-  aZNear              -= Abs (aZNear) * aPrecision;
-  aZFar               += Abs (aZFar)  * aPrecision;
-
-  if (!myCamera->IsOrthographic())
-  {
-    if (aZFar >= aPrecision)
-    {
-      // To avoid numeric errors... (See comments in the beginning of the method).
-      // Choose between model distance and graphical distance, as the model boundaries
-      // might be infinite if all structures have infinite flag.
-      const Standard_Real aGraphicDepth = aGraphicMaxDist >= aGraphicMinDist
-        ? aGraphicMaxDist - aGraphicMinDist : RealLast();
-
-      const Standard_Real aModelDepth = aModelMaxDist >= aModelMinDist
-        ? aModelMaxDist - aModelMinDist : RealLast();
-
-      const Standard_Real aMinDepth = Min (aModelDepth, aGraphicDepth);
-      const Standard_Real aZTolerance =
-        Max (Abs (aMinDepth) * aPrecision, aPrecision);
-
-      if (aZNear < aZTolerance)
-      {
-        aZNear = aZTolerance;
-      }
-    }
-    else // aZFar < aPrecision - Invalid case when both ZNear and ZFar are negative
-    {
-      aZNear = aPrecision;
-      aZFar  = aPrecision * 2.0;
-    }
-  }
-
-  // If range is too small
-  if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
-  {
-    aZFar = aZNear + Abs (aZFar) * aPrecision;
-  }
-
-  myCamera->SetZRange (aZNear, aZFar);
-
-  ImmediateUpdate();
-}
-
 //=============================================================================
 //function : DepthFitAll
 //purpose  :
@@ -1866,7 +1672,7 @@ void V3d_View::WindowFit (const Standard_Integer theMinXp,
 
     Translate (myCamera, aPanVec.X(), -aPanVec.Y());
     Scale (myCamera, aUSize, aVSize);
-    AutoZFit();
+    View()->AutoZFit();
   }
   else
   {
@@ -2117,7 +1923,7 @@ void V3d_View::Convert(const Standard_Real X,
   gp_Pnt aPoint = myCamera->Project (gp_Pnt (X, Y, Z));
 
   Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
-  Yp = RealToInt ((aPoint.Y() + 1) * 0.5 * aHeight);
+  Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight);
 }
 
 //=======================================================================
@@ -2819,7 +2625,7 @@ void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX,
   myCamera->SetScale (myCamera->Scale() / aCoef);
   Translate (myCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
 
-  AutoZFit();
+  View()->AutoZFit();
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -2875,7 +2681,7 @@ void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
   myCamera->SetAspect (aWinAspect);
   Translate (myCamera, (Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5);
   Scale (myCamera, aFitSizeU, aFitSizeV);
-  AutoZFit();
+  View()->AutoZFit();
 
   ImmediateUpdate();
 }
@@ -3112,7 +2918,7 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
 
   const Standard_Boolean toAutoUpdate = myImmediateUpdate;
   myImmediateUpdate = Standard_False;
-  AutoZFit();
+  View()->AutoZFit();
   myImmediateUpdate = toAutoUpdate;
 
   if (theToKeepAspect)
@@ -3337,7 +3143,7 @@ Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
   gp_Trsf aCenterTrsf;
   aCenterTrsf.SetTranslation (theCamera->Center(), aNewCenter);
   theCamera->Transform (aCenterTrsf);
-  theCamera->SetDistance (Max (aMatchDistance[5] + aMatchDistance[4], Precision::Confusion()));
+  theCamera->SetDistance (aMatchDistance[5] + aMatchDistance[4]);
 
   // Bounding box collapses to a point or thin line going in depth of the screen
   if (aViewSizeXv < theResolution && aViewSizeYv < theResolution)
@@ -3392,3 +3198,23 @@ void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera,
 
   theCamera->Transform (aPanTrsf);
 }
+
+// =======================================================================
+// function : IsCullingEnabled
+// purpose  :
+// =======================================================================
+Standard_Boolean V3d_View::IsCullingEnabled() const
+{
+  Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView();
+  return aView->IsCullingEnabled;
+}
+
+// =======================================================================
+// function : SetFrustumCulling
+// purpose  :
+// =======================================================================
+void V3d_View::SetFrustumCulling (const Standard_Boolean theToClip)
+{
+  Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView();
+  aView->IsCullingEnabled = theToClip;
+}