]> OCCT Git - occt.git/commitdiff
0025775: "Default Gradient Background" in V3d_Viewer has no effect in new created...
authorapl <apl@opencascade.com>
Tue, 21 Jul 2015 18:29:09 +0000 (21:29 +0300)
committerbugmaster <bugmaster@opencascade.com>
Tue, 28 Jul 2015 14:59:30 +0000 (17:59 +0300)
src/V3d/V3d_View.cxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/bugs/vis/bug25775 [new file with mode: 0644]

index 53a1184183f7a6e7e31166c19c045d281329fa6b..745a3eb2c139406bf7445fab749375f791b05959 100644 (file)
@@ -308,6 +308,7 @@ void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
   // SetWindow carries out SetRatio and modifies
   MyView->SetContext(MyViewContext) ;
   MyView->SetBackground(MyBackground) ;
+  MyView->SetGradientBackground (MyGradientBackground, Standard_False);
   MyViewer->SetViewOn(this) ;
   MyView->Redraw() ;
 }
index 315ee0bc991211d4f004dbba15bfba08334c4bdb..3bfc9cf2986f5a6f55db7adc5ec7ec2d2b3825ae 100644 (file)
@@ -196,6 +196,14 @@ static OpenGl_Caps ViewerTest_myDefaultCaps;
 
 static void OSWindowSetup();
 
+static struct
+{
+  Quantity_Color FlatColor;
+  Quantity_Color GradientColor1;
+  Quantity_Color GradientColor2;
+  Aspect_GradientFillMethod FillMethod;
+} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
+
 //==============================================================================
 //  EVENT GLOBAL VARIABLES
 //==============================================================================
@@ -637,10 +645,10 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
     toCreateViewer = Standard_True;
     TCollection_ExtendedString NameOfWindow("Viewer3D");
     a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
-
-    NameOfWindow = TCollection_ExtendedString("Collector");
-
-    a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
+    a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
+    a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
+                                           ViewerTest_DefaultBackground.GradientColor2,
+                                           ViewerTest_DefaultBackground.FillMethod);
   }
 
   // AIS context setup
@@ -2910,6 +2918,57 @@ static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char**
   return 0;
 }
 
+//==============================================================================
+//function : VSetDefaultBg
+//purpose  : Set default viewer background fill color
+//==============================================================================
+static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
+{
+  if (theArgNb != 4
+   && theArgNb != 8)
+  {
+    std::cout << "Error: wrong syntax! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  ViewerTest_DefaultBackground.FillMethod =
+    theArgNb == 4 ? Aspect_GFM_NONE
+                  : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
+
+  if (theArgNb == 4)
+  {
+    Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
+    Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
+    Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
+    ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
+  }
+  else
+  {
+    Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
+    Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
+    Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
+    ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
+
+    Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
+    Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
+    Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
+    ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
+  }
+
+  for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
+       anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
+  {
+    const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
+    aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
+    aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
+                                         ViewerTest_DefaultBackground.GradientColor2,
+                                         ViewerTest_DefaultBackground.FillMethod);
+  }
+
+  return 0;
+}
+
 //==============================================================================
 //function : VScale
 //purpose  : View Scaling
@@ -8904,6 +8963,11 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
   theCommands.Add("vsetcolorbg",
     "vsetcolorbg     : vsetcolorbg r g b : Set background color",
     __FILE__,VSetColorBg,group);
+  theCommands.Add("vsetdefaultbg",
+    "vsetdefaultbg r g b\n"
+    "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
+    "\n\t\t: Set default viewer background fill color (flat/gradient).",
+    __FILE__,VSetDefaultBg,group);
   theCommands.Add("vscale",
     "vscale          : vscale X Y Z",
     __FILE__,VScale,group);
diff --git a/tests/bugs/vis/bug25775 b/tests/bugs/vis/bug25775
new file mode 100644 (file)
index 0000000..fa8dd32
--- /dev/null
@@ -0,0 +1,25 @@
+puts "========"
+puts "OCC25775"
+puts "========"
+puts ""
+################################################################
+# "Default Gradient Backgound" in V3d_Viewer has no effect in new created V3d_View.
+################################################################
+
+pload ALL
+vsetdefaultbg 0 0 0 64 64 64 1
+vinit View1 w=400 h=400
+if { [checkcolor 399 100 0.25 0.25 0.25] != 1 } {
+  puts "Error: bug with default gradient color is reproduced."
+}
+
+vinit View2 w=400 h=400
+if { [checkcolor 399 100 0.25 0.25 0.25] != 1 } {
+  puts "Error: bug with default gradient color is reproduced."
+}
+
+vsetdefaultbg 128 128 128
+vinit View3
+if { [checkcolor 100 100 0.5 0.5 0.5] != 1 } {
+  puts "Error: bug with default background color is reproduced."
+}