0029395: Visualization, V3d_View - Grid disappears forever after enabling RayTracing
[occt.git] / src / V3d / V3d_CircularGrid.cxx
index 23a55ab..567cb88 100644 (file)
@@ -20,7 +20,6 @@
 #include <Graphic3d_AspectMarker3d.hxx>
 #include <Graphic3d_Group.hxx>
 #include <Graphic3d_Structure.hxx>
-#include <Graphic3d_Vertex.hxx>
 #include <Quantity_Color.hxx>
 #include <Standard_Type.hxx>
 #include <TColgp_SequenceOfPnt.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(V3d_CircularGrid,Aspect_CircularGrid)
 
-/*----------------------------------------------------------------------*/
-/*
- * Constant
- */
 #define DIVISION 8
-#define MYMINMAX 25.
 #define MYFACTOR 50.
 
+//! Dummy implementation of Graphic3d_Structure overriding ::Compute() method for handling Device Lost.
+class V3d_CircularGrid::CircularGridStructure : public Graphic3d_Structure
+{
+public:
+  //! Main constructor.
+  CircularGridStructure (const Handle(Graphic3d_StructureManager)& theManager, V3d_CircularGrid* theGrid)
+  : Graphic3d_Structure (theManager), myGrid (theGrid) {}
+
+  //! Override method initiating recomputing in V3d_CircularGrid.
+  virtual void Compute() Standard_OVERRIDE
+  {
+    GraphicClear (Standard_False);
+    myGrid->myGroup = NewGroup();
+    myGrid->myCurAreDefined = Standard_False;
+    myGrid->UpdateDisplay();
+  }
+
+private:
+  V3d_CircularGrid* myGrid;
+};
+
 /*----------------------------------------------------------------------*/
 
 V3d_CircularGrid::V3d_CircularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
 : Aspect_CircularGrid (1.,8),
-  myStructure (new Graphic3d_Structure (aViewer->StructureManager())),
-  myGroup (myStructure->NewGroup()),
   myViewer (aViewer),
-  myCurAreDefined (Standard_False)
+  myCurAreDefined (Standard_False),
+  myToComputePrs (Standard_False)
 {
   myColor = aColor;
   myTenthColor = aTenthColor;
 
+  myStructure = new CircularGridStructure (aViewer->StructureManager(), this);
+  myGroup = myStructure->NewGroup();
   myStructure->SetInfiniteState (Standard_True);
 
   const Standard_Real step = 10.;
@@ -57,6 +73,15 @@ V3d_CircularGrid::V3d_CircularGrid (const V3d_ViewerPointer& aViewer, const Quan
   SetRadiusStep (step);
 }
 
+V3d_CircularGrid::~V3d_CircularGrid()
+{
+  myGroup.Nullify();
+  if (!myStructure.IsNull())
+  {
+    myStructure->Erase();
+  }
+}
+
 void V3d_CircularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
 {
   if( myColor != aColor || myTenthColor != aTenthColor ) {
@@ -71,6 +96,7 @@ void V3d_CircularGrid::Display ()
 {
   myStructure->SetDisplayPriority (1);
   myStructure->Display();
+  UpdateDisplay();
 }
 
 void V3d_CircularGrid::Erase () const
@@ -144,10 +170,9 @@ void V3d_CircularGrid::UpdateDisplay ()
     myCurViewPlane = ThePlane;
   }
 
-  switch (DrawMode())
+  switch (myDrawMode)
   {
-    default:
-    //case Aspect_GDM_Points:
+    case Aspect_GDM_Points:
       DefinePoints ();
       myCurDrawMode = Aspect_GDM_Points;
       break;
@@ -155,11 +180,9 @@ void V3d_CircularGrid::UpdateDisplay ()
       DefineLines ();
       myCurDrawMode = Aspect_GDM_Lines;
       break;
-#ifdef IMP210100
     case Aspect_GDM_None:
       myCurDrawMode = Aspect_GDM_None;
       break;
-#endif
   }
   myCurAreDefined = Standard_True;
 }
@@ -172,11 +195,18 @@ void V3d_CircularGrid::DefineLines ()
                                   || myCurDrawMode != Aspect_GDM_Lines
                                   || aDivision != myCurDivi
                                   || aStep     != myCurStep;
-  if (!toUpdate)
+  if (!toUpdate
+   && !myToComputePrs)
+  {
+    return;
+  }
+  else if (!myStructure->IsDisplayed())
   {
+    myToComputePrs = Standard_True;
     return;
   }
 
+  myToComputePrs = Standard_False;
   myGroup->Clear ();
 
   const Standard_Integer Division = (Standard_Integer )( (aDivision >= DIVISION ? aDivision : DIVISION));
@@ -235,6 +265,10 @@ void V3d_CircularGrid::DefineLines ()
 
   myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0);
   myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision;
+
+  // update bounding box
+  myStructure->CalculateBoundBox();
+  myViewer->StructureManager()->Update (myStructure->GetZLayer());
 }
 
 void V3d_CircularGrid::DefinePoints ()
@@ -245,11 +279,18 @@ void V3d_CircularGrid::DefinePoints ()
                                   || myCurDrawMode != Aspect_GDM_Points
                                   || aDivision != myCurDivi
                                   || aStep     != myCurStep;
-  if (!toUpdate)
+  if (!toUpdate
+   && !myToComputePrs)
   {
     return;
   }
+  else if (!myStructure->IsDisplayed())
+  {
+    myToComputePrs = Standard_True;
+    return;
+  }
 
+  myToComputePrs = Standard_False;
   myGroup->Clear ();
 
   Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
@@ -283,6 +324,10 @@ void V3d_CircularGrid::DefinePoints ()
   myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0);
 
   myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision;
+
+  // update bounding box
+  myStructure->CalculateBoundBox();
+  myViewer->StructureManager()->Update (myStructure->GetZLayer());
 }
 
 void V3d_CircularGrid::GraphicValues (Standard_Real& theRadius, Standard_Real& theOffSet) const