0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[occt.git] / src / OpenGl / OpenGl_Clipping.cxx
index edc9b71..a572df8 100755 (executable)
 
 #include <OpenGl_Clipping.hxx>
 
-#include <OpenGl_GlCore11.hxx>
-#include <OpenGl_Workspace.hxx>
-#include <OpenGl_Context.hxx>
+#include <OpenGl_ClippingIterator.hxx>
 
 // =======================================================================
-// function : OpenGl_ClippingIterator
+// function : OpenGl_Clipping
 // purpose  :
 // =======================================================================
-OpenGl_ClippingIterator::OpenGl_ClippingIterator (const OpenGl_Clipping& theClipping)
-: myDisabled  (&theClipping.myDisabledPlanes),
-  myCurrIndex (1)
-{
-  if (!theClipping.myPlanesGlobal.IsNull())
-  {
-    myIter1.Init (*theClipping.myPlanesGlobal);
-  }
-  if (!theClipping.myPlanesLocal.IsNull())
-  {
-    myIter2.Init (*theClipping.myPlanesLocal);
-  }
-}
-
-// =======================================================================
-// function : OpenGl_ClippingState
-// purpose  :
-// =======================================================================
-OpenGl_Clipping::OpenGl_Clipping ()
-: myNbClipping (0),
+OpenGl_Clipping::OpenGl_Clipping()
+: myCappedSubPlane (0),
+  myNbClipping (0),
   myNbCapping  (0),
+  myNbChains   (0),
   myNbDisabled (0)
 {}
 
@@ -51,32 +33,36 @@ OpenGl_Clipping::OpenGl_Clipping ()
 // function : Init
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::Init (const Standard_Integer )
+void OpenGl_Clipping::Init()
 {
   myPlanesGlobal.Nullify();
   myPlanesLocal.Nullify();
 
   myNbClipping = 0;
   myNbCapping  = 0;
+  myNbChains   = 0;
   myNbDisabled = 0;
+  myCappedSubPlane = 0;
+  myCappedChain.Nullify();
 }
 
 // =======================================================================
 // function : Reset
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::Reset (const Handle(OpenGl_Context)& theGlCtx,
-                             const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
+void OpenGl_Clipping::Reset (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
 {
   const Standard_Integer aStartIndex = myPlanesGlobal.IsNull() ? 1 : myPlanesGlobal->Size() + 1;
-  remove (theGlCtx, myPlanesLocal,  aStartIndex);
-  remove (theGlCtx, myPlanesGlobal, 1);
+  remove (myPlanesLocal,  aStartIndex);
+  remove (myPlanesGlobal, 1);
 
   myPlanesGlobal = thePlanes;
   myPlanesLocal.Nullify();
 
-  add (theGlCtx, thePlanes, 1);
+  add (thePlanes, 1);
   myNbDisabled = 0;
+  myCappedSubPlane = 0;
+  myCappedChain.Nullify();
 
   // Method ::add() implicitly extends myDisabledPlanes (NCollection_Vector::SetValue()),
   // however we do not reset myDisabledPlanes and mySkipFilter beforehand to avoid redundant memory re-allocations.
@@ -88,23 +74,21 @@ void OpenGl_Clipping::Reset (const Handle(OpenGl_Context)& theGlCtx,
 // function : SetLocalPlanes
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::SetLocalPlanes (const Handle(OpenGl_Context)& theGlCtx,
-                                      const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
+void OpenGl_Clipping::SetLocalPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
 {
   const Standard_Integer aStartIndex = myPlanesGlobal.IsNull() ? 1 : myPlanesGlobal->Size() + 1;
-  remove (theGlCtx, myPlanesLocal, aStartIndex);
+  remove (myPlanesLocal, aStartIndex);
 
   myPlanesLocal = thePlanes;
 
-  add (theGlCtx, thePlanes, aStartIndex);
+  add (thePlanes, aStartIndex);
 }
 
 // =======================================================================
 // function : add
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::add (const Handle(OpenGl_Context)& ,
-                           const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
+void OpenGl_Clipping::add (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
                            const Standard_Integer theStartIndex)
 {
   if (thePlanes.IsNull())
@@ -122,13 +106,15 @@ void OpenGl_Clipping::add (const Handle(OpenGl_Context)& ,
       continue;
     }
 
+    const Standard_Integer aNbSubPlanes = aPlane->NbChainNextPlanes();
+    myNbChains += 1;
     if (aPlane->IsCapping())
     {
-      ++myNbCapping;
+      myNbCapping += aNbSubPlanes;
     }
     else
     {
-      ++myNbClipping;
+      myNbClipping += aNbSubPlanes;
     }
   }
 }
@@ -137,8 +123,7 @@ void OpenGl_Clipping::add (const Handle(OpenGl_Context)& ,
 // function : remove
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::remove (const Handle(OpenGl_Context)& ,
-                              const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
+void OpenGl_Clipping::remove (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
                               const Standard_Integer theStartIndex)
 {
   if (thePlanes.IsNull())
@@ -156,13 +141,15 @@ void OpenGl_Clipping::remove (const Handle(OpenGl_Context)& ,
       continue;
     }
 
+    const Standard_Integer aNbSubPlanes = aPlane->NbChainNextPlanes();
+    myNbChains -= 1;
     if (aPlane->IsCapping())
     {
-      --myNbCapping;
+      myNbCapping -= aNbSubPlanes;
     }
     else
     {
-      --myNbClipping;
+      myNbClipping -= aNbSubPlanes;
     }
   }
 }
@@ -171,8 +158,7 @@ void OpenGl_Clipping::remove (const Handle(OpenGl_Context)& ,
 // function : SetEnabled
 // purpose  :
 // =======================================================================
-Standard_Boolean OpenGl_Clipping::SetEnabled (const Handle(OpenGl_Context)&  ,
-                                              const OpenGl_ClippingIterator& thePlane,
+Standard_Boolean OpenGl_Clipping::SetEnabled (const OpenGl_ClippingIterator& thePlane,
                                               const Standard_Boolean         theIsEnabled)
 {
   const Standard_Integer aPlaneIndex = thePlane.PlaneIndex();
@@ -183,15 +169,17 @@ Standard_Boolean OpenGl_Clipping::SetEnabled (const Handle(OpenGl_Context)&  ,
   }
 
   isDisabled = !theIsEnabled;
+  const Standard_Integer aNbSubPlanes = thePlane.Value()->NbChainNextPlanes();
   if (thePlane.Value()->IsCapping())
   {
-    myNbCapping += (theIsEnabled ? 1 : -1);
+    myNbCapping += (theIsEnabled ? aNbSubPlanes : -aNbSubPlanes);
   }
   else
   {
-    myNbClipping += (theIsEnabled ? 1 : -1);
+    myNbClipping += (theIsEnabled ? aNbSubPlanes : -aNbSubPlanes);
   }
-  myNbDisabled -= (theIsEnabled ? 1 : -1);
+  myNbChains   += (theIsEnabled ? 1 : -1);
+  myNbDisabled += (theIsEnabled ? -aNbSubPlanes : aNbSubPlanes);
   return Standard_True;
 }
 
@@ -199,7 +187,7 @@ Standard_Boolean OpenGl_Clipping::SetEnabled (const Handle(OpenGl_Context)&  ,
 // function : RestoreDisabled
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::RestoreDisabled (const Handle(OpenGl_Context)& )
+void OpenGl_Clipping::RestoreDisabled()
 {
   if (myNbDisabled == 0)
   {
@@ -217,13 +205,15 @@ void OpenGl_Clipping::RestoreDisabled (const Handle(OpenGl_Context)& )
 
     isDisabled = Standard_False;
     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIter.Value();
+    const Standard_Integer aNbSubPlanes = aPlane->NbChainNextPlanes();
+    myNbChains += 1;
     if (aPlane->IsCapping())
     {
-      ++myNbCapping;
+      myNbCapping += aNbSubPlanes;
     }
     else
     {
-      ++myNbClipping;
+      myNbClipping += aNbSubPlanes;
     }
   }
 }
@@ -232,7 +222,7 @@ void OpenGl_Clipping::RestoreDisabled (const Handle(OpenGl_Context)& )
 // function : DisableGlobal
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::DisableGlobal (const Handle(OpenGl_Context)& theGlCtx)
+void OpenGl_Clipping::DisableGlobal()
 {
   for (OpenGl_ClippingIterator aPlaneIter (*this); aPlaneIter.More(); aPlaneIter.Next())
   {
@@ -242,7 +232,7 @@ void OpenGl_Clipping::DisableGlobal (const Handle(OpenGl_Context)& theGlCtx)
       return;
     }
 
-    SetEnabled (theGlCtx, aPlaneIter, Standard_False);
+    SetEnabled (aPlaneIter, Standard_False);
   }
 }
 
@@ -250,38 +240,30 @@ void OpenGl_Clipping::DisableGlobal (const Handle(OpenGl_Context)& theGlCtx)
 // function : DisableAllExcept
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::DisableAllExcept (const Handle(OpenGl_Context)&  theGlCtx,
-                                        const OpenGl_ClippingIterator& thePlane)
+void OpenGl_Clipping::DisableAllExcept (const Handle(Graphic3d_ClipPlane)& theChain,
+                                        const Standard_Integer theSubPlaneIndex)
 {
-  for (OpenGl_ClippingIterator aPlaneIter (*this); aPlaneIter.More(); aPlaneIter.Next())
-  {
-    if (aPlaneIter.IsDisabled())
-    {
-      mySkipFilter.SetValue (aPlaneIter.PlaneIndex(), Standard_True);
-      continue;
-    }
-
-    const Standard_Boolean isOn = (aPlaneIter.PlaneIndex() == thePlane.PlaneIndex());
-    SetEnabled (theGlCtx, aPlaneIter, isOn);
-    mySkipFilter.SetValue (aPlaneIter.PlaneIndex(), Standard_False);
-  }
+  myCappedChain = theChain;
+  myCappedSubPlane = theSubPlaneIndex;
 }
 
 // =======================================================================
 // function : EnableAllExcept
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::EnableAllExcept (const Handle(OpenGl_Context)&  theGlCtx,
-                                       const OpenGl_ClippingIterator& thePlane)
+void OpenGl_Clipping::EnableAllExcept (const Handle(Graphic3d_ClipPlane)& theChain,
+                                       const Standard_Integer theSubPlaneIndex)
 {
-  for (OpenGl_ClippingIterator aPlaneIter (*this); aPlaneIter.More(); aPlaneIter.Next())
-  {
-    if (mySkipFilter.Value (aPlaneIter.PlaneIndex()))
-    {
-      continue;
-    }
+  myCappedChain = theChain;
+  myCappedSubPlane = -theSubPlaneIndex;
+}
 
-    const Standard_Boolean isOn = (aPlaneIter.PlaneIndex() != thePlane.PlaneIndex());
-    SetEnabled (theGlCtx, aPlaneIter, isOn);
-  }
+// =======================================================================
+// function : ResetCappingFilter
+// purpose  :
+// =======================================================================
+void OpenGl_Clipping::ResetCappingFilter()
+{
+  myCappedChain.Nullify();
+  myCappedSubPlane = 0;
 }