1 // Created on: 1994-02-03
2 // Created by: Jean Marc LACHAUME
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Draw_Appli.hxx>
19 #include <Draw_Color.hxx>
20 #include <Draw_ColorKind.hxx>
21 #include <Draw_Display.hxx>
22 #include <Draw_Grid.hxx>
24 #include <gp_Trsf.hxx>
25 #include <Standard_Type.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(Draw_Grid,Draw_Drawable3D)
29 static Standard_Real MinimumStep = 1.e-3 ;
30 static Standard_Real Ratio = 200.0 ;
32 extern Draw_Viewer dout;
34 //=======================================================================
35 // Function : Draw_Grid
36 // Purpose : Constructor.
37 //=======================================================================
39 Draw_Grid::Draw_Grid () :
43 myIsActive (Standard_False)
47 //=======================================================================
49 // Purpose : Sets the steps along the X, Y & Z axis.
50 //=======================================================================
52 void Draw_Grid::Steps (const Standard_Real StepX,
53 const Standard_Real StepY,
54 const Standard_Real StepZ)
56 myStepX = Abs (StepX) ;
57 myStepY = Abs (StepY) ;
58 myStepZ = Abs (StepZ) ;
59 myIsActive = myStepX > MinimumStep
60 && myStepY > MinimumStep
61 && myStepZ > MinimumStep ;
64 //=======================================================================
66 // Purpose : Displays the grid.
67 //=======================================================================
69 void Draw_Grid::DrawOn (Draw_Display& Out) const
71 if (!myIsActive) return ;
73 Standard_Integer xmin, xmax, ymin, ymax ;
74 Standard_Integer IndexX, IndexY ;
75 Standard_Real StepX, StepY ;
76 Standard_Integer MinIndexX, MaxIndexX, MinIndexY, MaxIndexY ;
77 Standard_Real Offset ;
78 Standard_Real zoom, Xmin, Xmax, Ymin, Ymax ;
82 Standard_Integer IdtView ;
85 IdtView = Out.ViewId () ;
86 if (!dout.HasView (IdtView)) return ;
87 Type = dout.GetType (IdtView) ;
89 case 'X' : StepX = myStepX ; break ;
90 case 'Y' : StepX = myStepY ; break ;
91 case 'Z' : StepX = myStepZ ; break ;
92 default : StepX = 0.0 ; break ;
95 case 'X' : StepY = myStepX ; break ;
96 case 'Y' : StepY = myStepY ; break ;
97 case 'Z' : StepY = myStepZ ; break ;
98 default : StepY = 0.0 ; break ;
101 if (StepX > MinimumStep && StepY > MinimumStep) {
103 dout.GetFrame (IdtView, xmin, ymin, xmax, ymax) ;
104 dout.GetTrsf (IdtView, T) ; T.Invert () ;
105 zoom = dout.Zoom (IdtView) ;
107 Xmin = ((Standard_Real) xmin) / zoom ;
108 Xmax = ((Standard_Real) xmax) / zoom ;
109 Ymin = ((Standard_Real) ymin) / zoom ;
110 Ymax = ((Standard_Real) ymax) / zoom ;
112 Offset = Min (Xmax - Xmin, Ymax - Ymin) / Ratio ;
114 MinIndexX = (Standard_Integer) (Xmin / StepX) ;
115 MaxIndexX = (Standard_Integer) (Xmax / StepX) ;
116 MinIndexY = (Standard_Integer) (Ymin / StepY) ;
117 MaxIndexY = (Standard_Integer) (Ymax / StepY) ;
119 for (IndexX = MinIndexX ; IndexX <= MaxIndexX ; IndexX++) {
120 for (IndexY = MinIndexY ; IndexY <= MaxIndexY ; IndexY++) {
121 Standard_Real X = ((Standard_Real) IndexX) * StepX ;
122 Standard_Real Y = ((Standard_Real) IndexY) * StepY ;
124 Pnt1.SetCoord (X - Offset, Y, 0.0) ; Pnt1.Transform (T) ;
125 Pnt2.SetCoord (X + Offset, Y, 0.0) ; Pnt2.Transform (T) ;
126 Out.SetColor (Draw_Color (Draw_bleu)) ;
127 Out.Draw (Pnt1, Pnt2) ;
129 Pnt1.SetCoord (X, Y - Offset, 0.0) ; Pnt1.Transform (T) ;
130 Pnt2.SetCoord (X, Y + Offset, 0.0) ; Pnt2.Transform (T) ;
131 Out.SetColor (Draw_Color (Draw_bleu)) ;
132 Out.Draw (Pnt1, Pnt2) ;