]> OCCT Git - occt.git/commitdiff
0031547: Visualization - V3d_View creates V3d_Trihedron instance
authormkrylova <mkrylova@opencascade.com>
Thu, 31 Dec 2020 06:37:51 +0000 (09:37 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 22 Jan 2021 16:04:25 +0000 (19:04 +0300)
- moved creating of V3d_View::myTrihedron from constructor to first attempt of displaying or calling it;
- moved creating of V3d_Viewer::myRGrid and V3d_Viewer::myCGrid to to first attempt of displaying or calling them;
- renamed V3d_Viewer::IsActive() to V3d_Viewer::IsGridActive();
- redefined V3d_View::Trihedron() and V3d_Viewer::Grid() by adding new argument toCreate
for opportunity to check the existence of the objects without their recreating.

samples/mfc/standard/01_Geometry/src/GeometryDoc.cpp
samples/mfc/standard/Common/OCC_2dView.cpp
src/AIS/AIS_ViewController.cxx
src/QABugs/QABugs_6.cxx
src/V3d/V3d_View.cxx
src/V3d/V3d_View.hxx
src/V3d/V3d_View_4.cxx
src/V3d/V3d_Viewer.cxx
src/V3d/V3d_Viewer.hxx
src/V3d/V3d_Viewer_4.cxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx

index 70a18a6fd70a52339669e6299ceb23cf11ac7ae9..497f5244ed53c07f3779793d2126ab6b6a87da6d 100755 (executable)
@@ -255,7 +255,7 @@ void CGeometryDoc::MoveEvent2D(const Standard_Integer x,
                                const Standard_Integer y,
                                const Handle(V3d_View)& aView)
 {
-  if(aView->Viewer()->Grid()->IsActive())
+  if (aView->Viewer()->IsGridActive())
   {
     Standard_Real aGridX=0,aGridY=0,aGridZ=0;
     aView->ConvertToGrid(x,y,aGridX,aGridY,aGridZ);
index c77d2763c7f887ffbd86f389f9905ec0a925ffca..05da0188489aadebb3d9f412d3ee959e6cb0a21c 100755 (executable)
@@ -197,7 +197,7 @@ void OCC_2dView::OnBUTTONGridValues()
 void OCC_2dView::OnUpdateBUTTONGridValues(CCmdUI* pCmdUI) 
 {
   Handle(V3d_Viewer) aViewer = myView->Viewer();
-  pCmdUI-> Enable( aViewer->IsActive() );
+  pCmdUI-> Enable( aViewer->IsGridActive() );
 }
 
 void OCC_2dView::OnBUTTONGridCancel() 
@@ -211,7 +211,7 @@ void OCC_2dView::OnBUTTONGridCancel()
 void OCC_2dView::OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI) 
 {
   Handle(V3d_Viewer) aViewer = myView->Viewer();
-  pCmdUI-> Enable( aViewer->IsActive() );      
+  pCmdUI-> Enable( aViewer->IsGridActive() );
 }
 
 void OCC_2dView::OnSize(UINT nType, int cx, int cy)
index afa7400083c8fc38c4ef63b305bd841cc907d2d0..7dd9c08ce01af5b2f0f9fbfd6f1693fac1101e2b 100644 (file)
@@ -2707,7 +2707,7 @@ void AIS_ViewController::contextLazyMoveTo (const Handle(AIS_InteractiveContext)
 
   Handle(SelectMgr_EntityOwner) aNewPicked = theCtx->DetectedOwner();
 
-  if (theView->Viewer()->Grid()->IsActive()
+  if (theView->Viewer()->IsGridActive()
    && theView->Viewer()->GridEcho())
   {
     if (aNewPicked.IsNull())
index 2eeba16c59e193d0cabeb852b9e8ce795bd230ae..b34436b15df8f9aad004d585de72662c6e94532b 100644 (file)
@@ -101,7 +101,8 @@ static Standard_Integer OCC281bug (Draw_Interpretor& di, Standard_Integer argc,
   Handle(Graphic3d_AspectMarker3d) GridAsp = new Graphic3d_AspectMarker3d(AspectTypeOfMarker, Quantity_NOC_BLUE1, 10.);
   aViewer->SetGridEcho(GridAsp);
 
-  if (aViewer->IsActive()) {
+  if (aViewer->IsGridActive())
+  {
     if (aViewer->GridEcho()) {
       Standard_Real X,Y,Z;
       aView->ConvertToGrid(x,y,X,Y,Z);
index 42705dacefdee49c8df908919502f9ef93389fe4..e4b4164993334e00ba11036fbfbb557661b1feca 100644 (file)
@@ -68,7 +68,6 @@ V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView th
   MyViewer (theViewer.operator->()),
   SwitchSetFront (Standard_False),
   myZRotation (Standard_False),
-  myTrihedron (new V3d_Trihedron()),
   MyTrsf (1, 4, 1, 4)
 {
   myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
@@ -201,7 +200,7 @@ void V3d_View::SetWindow (const Handle(Aspect_Window)&  theWindow,
 //function : Remove
 //purpose  :
 //=============================================================================
-void V3d_View::Remove() const
+void V3d_View::Remove()
 {
   if (!MyGrid.IsNull())
   {
@@ -1571,41 +1570,48 @@ void V3d_View::WindowFit (const Standard_Integer theMinXp,
 //function : ConvertToGrid
 //purpose  :
 //=======================================================================
-void V3d_View::ConvertToGrid(const Standard_Integer Xp,
-                             const Standard_Integer Yp,
-                             Standard_Real& Xg,
-                             Standard_Real& Yg,
-                             Standard_Real& Zg) const
+void V3d_View::ConvertToGrid(const Standard_Integer theXp,
+                             const Standard_Integer theYp,
+                             Standard_Real& theXg,
+                             Standard_Real& theYg,
+                             Standard_Real& theZg) const
 {
-  Graphic3d_Vertex aVrp;
-  Standard_Real anX, anY, aZ;
-  Convert (Xp, Yp, anX, anY, aZ);
-  aVrp.SetCoord (anX, anY, aZ);
+  Graphic3d_Vec3d anXYZ;
+  Convert (theXp, theYp, anXYZ.x(), anXYZ.y(), anXYZ.z());
 
-  if( MyViewer->Grid()->IsActive() ) {
-    Graphic3d_Vertex aNewVrp = Compute (aVrp) ;
-    aNewVrp.Coord (Xg,Yg,Zg) ;
-  } else
-    aVrp.Coord (Xg,Yg,Zg) ;
+  Graphic3d_Vertex aVrp;
+  aVrp.SetCoord (anXYZ.x(), anXYZ.y(), anXYZ.z());
+  if (MyViewer->IsGridActive())
+  {
+    Graphic3d_Vertex aNewVrp = Compute (aVrp);
+    aNewVrp.Coord (theXg, theYg, theZg);
+  }
+  else
+  {
+    aVrp.Coord (theXg, theYg, theZg);
+  }
 }
 
 //=======================================================================
 //function : ConvertToGrid
 //purpose  :
 //=======================================================================
-void V3d_View::ConvertToGrid(const Standard_Real X,
-                             const Standard_Real Y,
-                             const Standard_Real Z,
-                             Standard_Real& Xg,
-                             Standard_Real& Yg,
-                             Standard_Real& Zg) const
+void V3d_View::ConvertToGrid(const Standard_Real theX,
+                             const Standard_Real theY,
+                             const Standard_Real theZ,
+                             Standard_Real& theXg,
+                             Standard_Real& theYg,
+                             Standard_Real& theZg) const
 {
-  if( MyViewer->Grid()->IsActive() ) {
-    Graphic3d_Vertex aVrp (X,Y,Z) ;
-    Graphic3d_Vertex aNewVrp = Compute (aVrp) ;
-    aNewVrp.Coord(Xg,Yg,Zg) ;
-  } else {
-    Xg = X; Yg = Y; Zg = Z;
+  if (MyViewer->IsGridActive())
+  {
+    Graphic3d_Vertex aVrp (theX, theY, theZ);
+    Graphic3d_Vertex aNewVrp = Compute (aVrp);
+    aNewVrp.Coord (theXg, theYg, theZg);
+  }
+  else
+  {
+    theXg = theX; theYg = theY; theZg = theZ;
   }
 }
 
index cf4b215f879c328166f8df00608d07a826359628..b8fc75e17c325b0e2989b3c250ac9701b1c25ee5 100644 (file)
@@ -128,7 +128,7 @@ public:
                                    const Standard_Integer theY2);
 
   //! Destroys the view.
-  Standard_EXPORT void Remove() const;
+  Standard_EXPORT void Remove();
 
   //! Deprecated, Redraw() should be used instead.
   Standard_EXPORT void Update() const;
@@ -287,7 +287,14 @@ public:
   Standard_EXPORT Standard_Boolean SetImmediateUpdate (const Standard_Boolean theImmediateUpdate);
 
   //! Returns trihedron object.
-  const Handle(V3d_Trihedron)& Trihedron() const { return myTrihedron; }
+  const Handle(V3d_Trihedron)& Trihedron (bool theToCreate = true)
+  {
+    if (myTrihedron.IsNull() && theToCreate)
+    {
+      myTrihedron = new V3d_Trihedron();
+    }
+    return myTrihedron;
+  }
 
   //! Customization of the ZBUFFER Triedron.
   //! XColor,YColor,ZColor - colors of axis
index cf779e835b983389d3809721cda26ac365733370..b120b29bbd6cc45d6571cc8677aa449c8d13bbff 100644 (file)
@@ -197,9 +197,8 @@ Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex& theVertex) const
                          + gp_Vec (aPnt0);
     return Graphic3d_Vertex (aResult.X(), aResult.Y(), aResult.Z());
   } 
-  else // IsCircular
+  else if (Handle(Aspect_CircularGrid) aCircleGrid = Handle(Aspect_CircularGrid)::DownCast (MyGrid))
   {
-    Handle(Aspect_CircularGrid) aCircleGrid = Handle(Aspect_CircularGrid)::DownCast (MyGrid);
     const Standard_Real anAlpha = M_PI / Standard_Real (aCircleGrid->DivisionNumber());
 
     // project point on plane to grid local space
@@ -217,6 +216,7 @@ Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex& theVertex) const
     const gp_Vec aResult = aGridX * aLocalX + aGridY * aLocalY + gp_Vec (aPnt0);
     return Graphic3d_Vertex (aResult.X(), aResult.Y(), aResult.Z());
   }
+  return Graphic3d_Vertex (0.0, 0.0, 0.0);
 }
 
 //=============================================================================
@@ -230,10 +230,11 @@ void V3d_View::ZBufferTriedronSetup(const Quantity_Color&  theXColor,
                                     const Standard_Real    theAxisDiametr,
                                     const Standard_Integer theNbFacettes)
 {
-  myTrihedron->SetArrowsColor   (theXColor, theYColor, theZColor);
-  myTrihedron->SetSizeRatio     (theSizeRatio);
-  myTrihedron->SetNbFacets      (theNbFacettes);
-  myTrihedron->SetArrowDiameter (theAxisDiametr);
+  const Handle(V3d_Trihedron)& aTrihedron = Trihedron (true);
+  aTrihedron->SetArrowsColor   (theXColor, theYColor, theZColor);
+  aTrihedron->SetSizeRatio     (theSizeRatio);
+  aTrihedron->SetNbFacets      (theNbFacettes);
+  aTrihedron->SetArrowDiameter (theAxisDiametr);
 }
 
 //=============================================================================
@@ -245,12 +246,13 @@ void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
                                 const Standard_Real theScale,
                                 const V3d_TypeOfVisualization theMode)
 {
-  myTrihedron->SetLabelsColor (theColor);
-  myTrihedron->SetScale       (theScale);
-  myTrihedron->SetPosition    (thePosition);
-  myTrihedron->SetWireframe   (theMode == V3d_WIREFRAME);
+  const Handle(V3d_Trihedron)& aTrihedron = Trihedron (true);
+  aTrihedron->SetLabelsColor (theColor);
+  aTrihedron->SetScale       (theScale);
+  aTrihedron->SetPosition    (thePosition);
+  aTrihedron->SetWireframe   (theMode == V3d_WIREFRAME);
 
-  myTrihedron->Display (*this);
+  aTrihedron->Display (*this);
 }
 
 //=============================================================================
@@ -259,7 +261,10 @@ void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
 //=============================================================================
 void V3d_View::TriedronErase()
 {
-  myTrihedron->Erase();
+  if (!myTrihedron.IsNull())
+  {
+    myTrihedron->Erase();
+  }
 }
 
 //=============================================================================
index 465038c84ccf267753fc460755441d2ec0e8cdf5..faea6acaac502bd1aff6b2130534ce712e3516a2 100644 (file)
@@ -58,8 +58,7 @@ V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver)
   myGridEcho (Standard_True),
   myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast())
 {
-  myRGrid = new V3d_RectangularGrid (this, Quantity_Color (Quantity_NOC_GRAY50), Quantity_Color (Quantity_NOC_GRAY70));
-  myCGrid = new V3d_CircularGrid    (this, Quantity_Color (Quantity_NOC_GRAY50), Quantity_Color (Quantity_NOC_GRAY70));
+  //
 }
 
 // ========================================================================
@@ -113,9 +112,11 @@ void V3d_Viewer::SetViewOn (const Handle(V3d_View)& theView)
   {
     theView->SetLightOn (anActiveLightIter.Value());
   }
-
-  theView->SetGrid (myPrivilegedPlane, Grid ());
-  theView->SetGridActivity (Grid ()->IsActive ());
+  if (Handle(Aspect_Grid) aGrid = Grid (false))
+  {
+    theView->SetGrid (myPrivilegedPlane, aGrid);
+    theView->SetGridActivity (aGrid->IsActive());
+  }
   if (theView->SetImmediateUpdate (Standard_False))
   {
     theView->Redraw();
@@ -454,10 +455,11 @@ void V3d_Viewer::SetDefaultLights()
 void V3d_Viewer::SetPrivilegedPlane (const gp_Ax3& thePlane)
 {
   myPrivilegedPlane = thePlane;
-  Grid()->SetDrawMode(Grid()->DrawMode());
+  Handle(Aspect_Grid) aGrid = Grid (true);
+  aGrid->SetDrawMode (aGrid->DrawMode()); // aGrid->UpdateDisplay();
   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
   {
-    anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, Grid());
+    anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, aGrid);
   }
 
   if (myDisplayPlane)
@@ -478,7 +480,7 @@ void V3d_Viewer::DisplayPrivilegedPlane (const Standard_Boolean theOnOff, const
   if (!myDisplayPlane)
   {
     if (!myPlaneStructure.IsNull())
-       {
+    {
       myPlaneStructure->Erase();
     }
     return;
index 8c869c8ffb3625122c092186a81206bb0425afe5..73c59c9af3d6ca9e81b1a56a937d92ad2106ac0f 100644 (file)
@@ -352,51 +352,61 @@ public: //! @name grid management
   
   //! Returns TRUE when grid echo must be displayed at hit point.
   Standard_Boolean GridEcho() const { return myGridEcho; }
-  
+
   //! Returns Standard_True if a grid is activated in <me>.
-  Standard_EXPORT Standard_Boolean IsActive() const;
-  
+  Standard_EXPORT Standard_Boolean IsGridActive();
+
   //! Returns the defined grid in <me>.
-  Standard_EXPORT Handle(Aspect_Grid) Grid() const;
+  Handle(Aspect_Grid) Grid (bool theToCreate = true) { return Grid (myGridType, theToCreate); }
+
+  //! Returns the defined grid in <me>.
+  Standard_EXPORT Handle(Aspect_Grid) Grid (Aspect_GridType theGridType, bool theToCreate = true);
 
   //! Returns the current grid type defined in <me>.
   Aspect_GridType GridType() const { return myGridType; }
-  
+
   //! Returns the current grid draw mode defined in <me>.
-  Standard_EXPORT Aspect_GridDrawMode GridDrawMode() const;
-  
+  Standard_EXPORT Aspect_GridDrawMode GridDrawMode();
+
   //! Returns the definition of the rectangular grid.
-  Standard_EXPORT void RectangularGridValues (Standard_Real& XOrigin, Standard_Real& YOrigin, Standard_Real& XStep, Standard_Real& YStep, Standard_Real& RotationAngle) const;
-  
+  Standard_EXPORT void RectangularGridValues (Standard_Real& theXOrigin, Standard_Real& theYOrigin,
+                                              Standard_Real& theXStep, Standard_Real& theYStep,
+                                              Standard_Real& theRotationAngle);
+
   //! Sets the definition of the rectangular grid.
   //! <XOrigin>, <YOrigin> defines the origin of the grid.
   //! <XStep> defines the interval between 2 vertical lines.
   //! <YStep> defines the interval between 2 horizontal lines.
   //! <RotationAngle> defines the rotation angle of the grid.
   Standard_EXPORT void SetRectangularGridValues (const Standard_Real XOrigin, const Standard_Real YOrigin, const Standard_Real XStep, const Standard_Real YStep, const Standard_Real RotationAngle);
-  
+
   //! Returns the definition of the circular grid.
-  Standard_EXPORT void CircularGridValues (Standard_Real& XOrigin, Standard_Real& YOrigin, Standard_Real& RadiusStep, Standard_Integer& DivisionNumber, Standard_Real& RotationAngle) const;
-  
+  Standard_EXPORT void CircularGridValues (Standard_Real& theXOrigin, Standard_Real& theYOrigin,
+                                           Standard_Real& theRadiusStep,
+                                           Standard_Integer& theDivisionNumber,
+                                           Standard_Real& theRotationAngle);
+
   //! Sets the definition of the circular grid.
   //! <XOrigin>, <YOrigin> defines the origin of the grid.
   //! <RadiusStep> defines the interval between 2 circles.
   //! <DivisionNumber> defines the section number of one half circle.
   //! <RotationAngle> defines the rotation angle of the grid.
   Standard_EXPORT void SetCircularGridValues (const Standard_Real XOrigin, const Standard_Real YOrigin, const Standard_Real RadiusStep, const Standard_Integer DivisionNumber, const Standard_Real RotationAngle);
-  
+
   //! Returns the location and the size of the grid.
-  Standard_EXPORT void CircularGridGraphicValues (Standard_Real& Radius, Standard_Real& OffSet) const;
-  
+  Standard_EXPORT void CircularGridGraphicValues (Standard_Real& theRadius,
+                                                  Standard_Real& theOffSet);
+
   //! Sets the location and the size of the grid.
   //! <XSize> defines the width of the grid.
   //! <YSize> defines the height of the grid.
   //! <OffSet> defines the displacement along the plane normal.
   Standard_EXPORT void SetCircularGridGraphicValues (const Standard_Real Radius, const Standard_Real OffSet);
-  
+
   //! Returns the location and the size of the grid.
-  Standard_EXPORT void RectangularGridGraphicValues (Standard_Real& XSize, Standard_Real& YSize, Standard_Real& OffSet) const;
-  
+  Standard_EXPORT void RectangularGridGraphicValues (Standard_Real& theXSize, Standard_Real& theYSize,
+                                                     Standard_Real& theOffSet);
+
   //! Sets the location and the size of the grid.
   //! <XSize> defines the width of the grid.
   //! <YSize> defines the height of the grid.
@@ -411,6 +421,10 @@ public: //! @name grid management
 
 public: //! @name deprecated methods
 
+  //! Returns Standard_True if a grid is activated in <me>.
+  Standard_DEPRECATED ("Deprecated method - IsGridActive() should be used instead")
+  Standard_Boolean IsActive() { return IsGridActive(); }
+
   //! Initializes an internal iterator on the active views.
   Standard_DEPRECATED ("Deprecated method - ActiveViews() should be used instead")
   void InitActiveViews() { myActiveViewsIterator.Initialize (myActiveViews); }
index ab93f3c23ba5eb9300bef32beecf294e183543c0..c7492d2c35ba60268095bfdcb69be142cff34621 100644 (file)
 // function : Grid
 // purpose  :
 // =======================================================================
-Handle(Aspect_Grid) V3d_Viewer::Grid() const
+Handle(Aspect_Grid) V3d_Viewer::Grid (Aspect_GridType theGridType, bool theToCreate)
 {
-  switch (myGridType)
+  switch (theGridType)
   {
-  case Aspect_GT_Circular:    return Handle(Aspect_Grid) (myCGrid);
-  case Aspect_GT_Rectangular: return Handle(Aspect_Grid) (myRGrid);
+    case Aspect_GT_Circular:
+    {
+      if (myCGrid.IsNull() && theToCreate)
+      {
+        myCGrid = new V3d_CircularGrid (this, Quantity_Color(Quantity_NOC_GRAY50), Quantity_Color(Quantity_NOC_GRAY70));
+      }
+      return Handle(Aspect_Grid) (myCGrid);
+    }
+    case Aspect_GT_Rectangular:
+    {
+      if (myRGrid.IsNull() && theToCreate)
+      {
+        myRGrid = new V3d_RectangularGrid (this, Quantity_Color(Quantity_NOC_GRAY50), Quantity_Color(Quantity_NOC_GRAY70));
+      }
+      return Handle(Aspect_Grid) (myRGrid);
+    }
   }
-  return Handle(Aspect_Grid) (myRGrid);
+  return Handle(Aspect_Grid)();
 }
 
 // =======================================================================
 // function : GridDrawMode
 // purpose  :
 // =======================================================================
-Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const
+Aspect_GridDrawMode V3d_Viewer::GridDrawMode()
 {
-  return Grid()->DrawMode();
+  Handle(Aspect_Grid) aGrid = Grid (false);
+  return !aGrid.IsNull() ? aGrid->DrawMode() : Aspect_GDM_Lines;
 }
 
 // =======================================================================
@@ -59,17 +74,22 @@ Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const
 void V3d_Viewer::ActivateGrid (const Aspect_GridType     theType,
                                const Aspect_GridDrawMode theMode)
 {
-  Grid()->Erase();
+  if (Handle(Aspect_Grid) anOldGrid = Grid (false))
+  {
+    anOldGrid->Erase();
+  }
+
   myGridType = theType;
-  Grid()->SetDrawMode (theMode);
+  Handle(Aspect_Grid) aGrid = Grid (true);
+  aGrid->SetDrawMode (theMode);
   if (theMode != Aspect_GDM_None)
   {
-    Grid()->Display();
+    aGrid->Display();
   }
-  Grid()->Activate();
+  aGrid->Activate();
   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
   {
-    anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, Grid());
+    anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, aGrid);
   }
 }
 
@@ -79,9 +99,16 @@ void V3d_Viewer::ActivateGrid (const Aspect_GridType     theType,
 // =======================================================================
 void V3d_Viewer::DeactivateGrid()
 {
-  Grid()->Erase();
+  Handle(Aspect_Grid) aGrid = Grid (false);
+  if (aGrid.IsNull())
+  {
+    return;
+  }
+
+  aGrid->Erase();
+  aGrid->Deactivate();
+
   myGridType = Aspect_GT_Rectangular;
-  Grid()->Deactivate();
   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
   {
     anActiveViewIter.Value()->SetGridActivity (Standard_False);
@@ -94,12 +121,13 @@ void V3d_Viewer::DeactivateGrid()
 }
 
 // =======================================================================
-// function : IsActive
+// function : IsGridActive
 // purpose  :
 // =======================================================================
-Standard_Boolean V3d_Viewer::IsActive() const
+Standard_Boolean V3d_Viewer::IsGridActive()
 {
-  return Grid()->IsActive();
+  Handle(Aspect_Grid) aGrid = Grid (false);
+  return !aGrid.IsNull() && aGrid->IsActive();
 }
 
 // =======================================================================
@@ -110,8 +138,9 @@ void V3d_Viewer::RectangularGridValues (Standard_Real& theXOrigin,
                                         Standard_Real& theYOrigin,
                                         Standard_Real& theXStep,
                                         Standard_Real& theYStep,
-                                        Standard_Real& theRotationAngle) const
+                                        Standard_Real& theRotationAngle)
 {
+  Grid (Aspect_GT_Rectangular, true);
   theXOrigin       = myRGrid->XOrigin();
   theYOrigin       = myRGrid->YOrigin();
   theXStep         = myRGrid->XStep();
@@ -129,6 +158,7 @@ void V3d_Viewer::SetRectangularGridValues (const Standard_Real theXOrigin,
                                            const Standard_Real theYStep,
                                            const Standard_Real theRotationAngle)
 {
+  Grid (Aspect_GT_Rectangular, true);
   myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
   {
@@ -144,8 +174,9 @@ void V3d_Viewer::CircularGridValues (Standard_Real& theXOrigin,
                                      Standard_Real& theYOrigin,
                                      Standard_Real& theRadiusStep,
                                      Standard_Integer& theDivisionNumber,
-                                     Standard_Real& theRotationAngle) const
+                                     Standard_Real& theRotationAngle)
 {
+  Grid (Aspect_GT_Circular, true);
   theXOrigin        = myCGrid->XOrigin();
   theYOrigin        = myCGrid->YOrigin();
   theRadiusStep     = myCGrid->RadiusStep();
@@ -163,6 +194,7 @@ void V3d_Viewer::SetCircularGridValues (const Standard_Real theXOrigin,
                                         const Standard_Integer theDivisionNumber,
                                         const Standard_Real theRotationAngle)
 {
+  Grid (Aspect_GT_Circular, true);
   myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
                           theDivisionNumber, theRotationAngle);
   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
@@ -177,8 +209,9 @@ void V3d_Viewer::SetCircularGridValues (const Standard_Real theXOrigin,
 // =======================================================================
 void V3d_Viewer::RectangularGridGraphicValues (Standard_Real& theXSize,
                                                Standard_Real& theYSize,
-                                               Standard_Real& theOffSet) const
+                                               Standard_Real& theOffSet)
 {
+  Grid (Aspect_GT_Rectangular, true);
   myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
 }
 
@@ -190,6 +223,7 @@ void V3d_Viewer::SetRectangularGridGraphicValues (const Standard_Real theXSize,
                                                   const Standard_Real theYSize,
                                                   const Standard_Real theOffSet)
 {
+  Grid (Aspect_GT_Rectangular, true);
   myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
 }
 
@@ -198,8 +232,9 @@ void V3d_Viewer::SetRectangularGridGraphicValues (const Standard_Real theXSize,
 // purpose  :
 // =======================================================================
 void V3d_Viewer::CircularGridGraphicValues (Standard_Real& theRadius,
-                                            Standard_Real& theOffSet) const
+                                            Standard_Real& theOffSet)
 {
+  Grid (Aspect_GT_Circular, true);
   myCGrid->GraphicValues (theRadius, theOffSet);
 }
 
@@ -210,6 +245,7 @@ void V3d_Viewer::CircularGridGraphicValues (Standard_Real& theRadius,
 void V3d_Viewer::SetCircularGridGraphicValues (const Standard_Real theRadius,
                                                const Standard_Real theOffSet)
 {
+  Grid (Aspect_GT_Circular, true);
   myCGrid->SetGraphicValues (theRadius, theOffSet);
 }
 
index 907a9afe5d5a366f06c4eb78d0521fcccd32b0e6..04c285ffd32abf4d8b2c955c724711c21370cd70 100644 (file)
@@ -7672,7 +7672,7 @@ static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
         return 1;
       }
 
-      const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
+      const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->IsGridActive()
                                        && aContext->CurrentViewer()->GridEcho();
       if (toEchoGrid)
       {