0027957: Visualization, AIS_InteractiveContext - protect from displaying the same...
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
index cc7a130..bd57553 100644 (file)
@@ -1138,6 +1138,8 @@ void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const S
           break;
         }
       }
+
+      aCurrentContext->RemoveAll (Standard_False);
       if(isRemoveDriver)
       {
         ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
@@ -8168,7 +8170,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       case Graphic3d_RM_RAYTRACING:    theDI << "raytrace ";      break;
     }
     theDI << "\n";
-    theDI << "msaa:         " <<  aParams.NbMsaaSamples << "\n";
+    theDI << "msaa:         " <<  aParams.NbMsaaSamples                               << "\n";
     theDI << "rayDepth:     " <<  aParams.RaytracingDepth                             << "\n";
     theDI << "fsaa:         " << (aParams.IsAntialiasingEnabled       ? "on" : "off") << "\n";
     theDI << "shadows:      " << (aParams.IsShadowEnabled             ? "on" : "off") << "\n";
@@ -8176,6 +8178,8 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
     theDI << "gleam:        " << (aParams.IsTransparentShadowEnabled  ? "on" : "off") << "\n";
     theDI << "GI:           " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
     theDI << "blocked RNG:  " << (aParams.CoherentPathTracingMode     ? "on" : "off") << "\n";
+    theDI << "iss:          " << (aParams.AdaptiveScreenSampling      ? "on" : "off") << "\n";
+    theDI << "iss debug:    " << (aParams.ShowSamplingTiles           ? "on" : "off") << "\n";
     theDI << "shadingModel: ";
     switch (aView->ShadingModel())
     {
@@ -8401,6 +8405,38 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       }
       aParams.CoherentPathTracingMode = toEnable;
     }
+    else if (aFlag == "-iss")
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+        && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.AdaptiveScreenSampling = toEnable;
+    }
+    else if (aFlag == "-issd")
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+        && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.ShowSamplingTiles = toEnable;
+    }
     else if (aFlag == "-env")
     {
       if (toPrint)
@@ -8488,6 +8524,23 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
         return 1;
       }
     }
+    else if (aFlag == "-rebuildglsl"
+          || aFlag == "-rebuild")
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+          && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.RebuildRayTracingShaders = toEnable;
+    }
     else
     {
       std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
@@ -8991,6 +9044,133 @@ static int VManipulator (Draw_Interpretor& theDi,
   return 0;
 }
 
+//===============================================================================================
+//function : parseColor
+//purpose  :
+//===============================================================================================
+static Standard_Boolean parseColor (ViewerTest_CmdParser& theParser,
+                                    const std::string&    theOptionName,
+                                    Quantity_Color&       theColor)
+{
+  std::string aColorArg = theParser.Arg (theOptionName, 0);
+  if (std::isdigit (aColorArg[0]))
+  {
+    Graphic3d_Vec3d aColor = theParser.ArgVec3d (theOptionName);
+    if (aColor.x() < 0.0 || aColor.x() > 1.0
+      || aColor.y() < 0.0 || aColor.y() > 1.0
+      || aColor.z() < 0.0 || aColor.z() > 1.0)
+    {
+      std::cerr << "Error: RGB color values should be within range 0..1!\n";
+      return Standard_False;
+    }
+    theColor.SetValues (aColor.x(), aColor.y(), aColor.z(), Quantity_TOC_RGB);
+  }
+  else
+  {
+    Quantity_NameOfColor aName = Quantity_NOC_BLACK;
+    if (!Quantity_Color::ColorFromName (aColorArg.c_str(), aName))
+    {
+      std::cerr << "Name: " << theParser.Arg (theOptionName, 0)
+                << " does not correspond to any color in Quantity_NameOfColor!"
+                << std::endl;
+      return Standard_False;
+    }
+    theColor.SetValues (aName);
+  }
+
+  return Standard_True;
+}
+
+//===============================================================================================
+//function : VSelectionProperties
+//purpose  :
+//===============================================================================================
+static int VSelectionProperties (Draw_Interpretor& theDi,
+                                 Standard_Integer  theArgsNb,
+                                 const char**      theArgVec)
+{
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    std::cerr << "No active viewer!\n";
+    return 1;
+  }
+
+  ViewerTest_CmdParser aCmd;
+
+  aCmd.AddOption ("autoActivate");
+  aCmd.AddOption ("pixTol");
+
+  aCmd.AddOption ("selColor");
+  aCmd.AddOption ("hiColor");
+  aCmd.AddOption ("selTransp");
+  aCmd.AddOption ("hiTransp");
+
+  aCmd.AddOption ("print");
+
+  aCmd.Parse (theArgsNb, theArgVec);
+
+  if (aCmd.HasOption ("help"))
+  {
+    theDi.PrintHelp (theArgVec[0]);
+    return 0;
+  }
+
+  if (aCmd.HasOption ("autoActivate", 1, Standard_False))
+  {
+    aCtx->SetAutoActivateSelection (aCmd.ArgBool ("autoActivate"));
+  }
+  if (aCmd.HasOption ("pixTol", 1, Standard_False))
+  {
+    aCtx->SetPixelTolerance (aCmd.ArgInt ("pixTol"));
+  }
+
+  Handle(Graphic3d_HighlightStyle)& aHiStyle = aCtx->ChangeHighlightStyle();
+  Handle(Graphic3d_HighlightStyle)& aSelStyle = aCtx->ChangeSelectionStyle();
+  Standard_Boolean toRedraw = Standard_False;
+  if (aCmd.HasOption ("selColor"))
+  {
+    Quantity_Color aNewColor;
+    if (!parseColor (aCmd, "selColor", aNewColor))
+      return 1;
+    aSelStyle->SetColor (aNewColor);
+    toRedraw = Standard_True;
+  }
+  if (aCmd.HasOption ("hiColor"))
+  {
+    Quantity_Color aNewColor;
+    if (!parseColor (aCmd, "hiColor", aNewColor))
+      return 1;
+    aHiStyle->SetColor (aNewColor);
+  }
+  if (aCmd.HasOption ("selTransp"))
+  {
+    aSelStyle->SetTransparency (aCmd.ArgFloat ("selTransp"));
+    toRedraw = Standard_True;
+  }
+  if (aCmd.HasOption ("hiTransp"))
+  {
+    aHiStyle->SetTransparency (aCmd.ArgFloat ("hiTransp"));
+  }
+
+  if (aCmd.HasOption ("print") || theArgsNb == 1)
+  {
+    theDi << "Auto-activation                : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
+    theDi << "Selection pixel tolerance      : " << aCtx->MainSelector()->PixelTolerance() << "\n";
+    theDi << "Selection color                : " << Quantity_Color::StringName (aCtx->SelectionStyle()->Color().Name()) << "\n";
+    theDi << "Dynamic highlight color        : " << Quantity_Color::StringName (aCtx->HighlightStyle()->Color().Name()) << "\n";
+    theDi << "Selection transparency         : " << aCtx->SelectionStyle()->Transparency() << "\n";
+    theDi << "Dynamic highlight transparency : " << aCtx->HighlightStyle()->Transparency() << "\n";
+  }
+
+  if (aCtx->NbSelected() != 0 && toRedraw)
+  {
+    aCtx->HilightSelected (Standard_True);
+  }
+
+  return 0;
+}
+
 //=======================================================================
 //function : ViewerCommands
 //purpose  :
@@ -9500,6 +9680,9 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "\n      '-gi           on|off'  Enables/disables global illumination effects"
     "\n      '-brng         on|off'  Enables/disables blocked RNG (fast coherent PT)"
     "\n      '-env          on|off'  Enables/disables environment map background"
+    "\n      '-iss          on|off'  Enables/disables adaptive screen sampling (PT mode)"
+    "\n      '-issd         on|off'  Shows screen sampling distribution in ISS mode"
+    "\n      '-rebuildGlsl  on|off'  Rebuild Ray-Tracing GLSL programs (for debugging)"
     "\n      '-shadingModel model'   Controls shading model from enumeration"
     "\n                              color, flat, gouraud, phong"
     "\n      '-resolution   value'   Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
@@ -9547,6 +9730,18 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
       "\n      '-zoomable {0|1}'                 - set zoom persistence",
     __FILE__, VManipulator, group);
 
+  theCommands.Add("vselprops",
+    "\n    vselprops [options]"
+    "\n    Customizes selection and dynamic highlight parameters for the whole interactive context:"
+    "\n    -autoActivate {0|1}     : disables|enables default computation and activation of global selection mode"
+    "\n    -pixTol    value        : sets up pixel tolerance"
+    "\n    -selColor  {name|r g b} : sets selection color"
+    "\n    -hiColor   {name|r g b} : sets dynamic highlight color"
+    "\n    -selTransp value        : sets transparency coefficient for selection"
+    "\n    -hiTransp  value        : sets transparency coefficient for dynamic highlight"
+    "\n    -print                  : prints current state of all mentioned parameters",
+    __FILE__, VSelectionProperties, group);
+
 #if defined(_WIN32)
   theCommands.Add("vprogressive",
     "vprogressive",