From 32ca771129cf170c0f094182d77edda967bec5f6 Mon Sep 17 00:00:00 2001
From: kgv <kgv@opencascade.com>
Date: Mon, 14 May 2018 19:25:16 +0300
Subject: [PATCH] 0029768: Visualization, TKOpenGl - structure is entirely
 clipped by suppressed clipping

OpenGl_Structure::Render(), added missing check for disabled state of the plane.
vclipplane command has been extended with new option -setOverrideGlobal.
---
 src/OpenGl/OpenGl_Structure.cxx              |  2 +-
 src/ViewerTest/ViewerTest_ViewerCommands.cxx | 15 +++++++++----
 tests/bugs/vis/bug29768                      | 23 ++++++++++++++++++++
 3 files changed, 35 insertions(+), 5 deletions(-)
 create mode 100644 tests/bugs/vis/bug29768

diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx
index bfb99381fd..60b5aec151 100644
--- a/src/OpenGl/OpenGl_Structure.cxx
+++ b/src/OpenGl/OpenGl_Structure.cxx
@@ -605,7 +605,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con
       for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More(); aPlaneIt.Next())
       {
         const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
-        if (!aPlane->IsOn())
+        if (aPlaneIt.IsDisabled())
         {
           continue;
         }
diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx
index d1c8f2ebc7..8fea4aacac 100644
--- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx
+++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx
@@ -8681,10 +8681,12 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
       return 0;
     }
     else if (aChangeArg == "-set"
-          || aChangeArg == "-unset")
+          || aChangeArg == "-unset"
+          || aChangeArg == "-setoverrideglobal")
     {
       // set / unset plane command
-      Standard_Boolean toSet = aChangeArg == "-set";
+      const Standard_Boolean toSet            = aChangeArg.StartsWith ("-set");
+      const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
       Standard_Integer anIt = 1;
       for (; anIt < aNbChangeArgs; ++anIt)
       {
@@ -8694,7 +8696,8 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
         {
           break;
         }
-        else if (ViewerTest_myViews.IsBound1 (anEntityName))
+        else if (!toOverrideGlobal
+               && ViewerTest_myViews.IsBound1 (anEntityName))
         {
           Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
           if (toSet)
@@ -8718,6 +8721,10 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
           {
             aIObj->RemoveClipPlane (aClipPlane);
           }
+          if (!aIObj->ClipPlanes().IsNull())
+          {
+            aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
+          }
         }
         else
         {
@@ -12387,7 +12394,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
   theCommands.Add("vclipplane",
               "vclipplane planeName [{0|1}]"
       "\n\t\t:   [-equation A B C D]"
-      "\n\t\t:   [-set|-unset [objects|views]]"
+      "\n\t\t:   [-set|-unset|-setOverrideGlobal [objects|views]]"
       "\n\t\t:   [-maxPlanes]"
       "\n\t\t:   [-capping {0|1}]"
       "\n\t\t:     [-color R G B] [-hatch {on|off|ID}]"
diff --git a/tests/bugs/vis/bug29768 b/tests/bugs/vis/bug29768
new file mode 100644
index 0000000000..6c48badf13
--- /dev/null
+++ b/tests/bugs/vis/bug29768
@@ -0,0 +1,23 @@
+puts "============"
+puts "0029768: Visualization, TKOpenGl - structure is entirely clipped by suppressed clipping"
+puts "============"
+puts ""
+
+vclear
+vinit View1
+vaxo
+vpoint p0 0 0 0
+vzbufftrihedron
+box b0 0 0 0 1 1 1
+box b1 3 0 0 1 1 1
+vdisplay -dispMode 1 b0 b1
+vsetcolor b0 RED
+vsetcolor b1 GREEN
+vfit
+
+vclipplane pv  equation -1 0 0  0.5 -set
+vclipplane pb0 equation  0 1 0 -0.5 -set b0
+vclipplane pb1 equation  0 1 0 -0.5 -setOverrideGlobal b1
+
+if { [vreadpixel 300 200 rgb name] != "GREEN3" } { puts "Error: box b1 is fully clipped" }
+vdump $imagedir/${casename}.png