0022972: Eliminate macro definitions that has compiler-provided analogs (WNT and...
[occt.git] / src / Draw / Draw_Grid.cxx
CommitLineData
b311480e 1// Created on: 1994-02-03
2// Created by: Jean Marc LACHAUME
3// Copyright (c) 1994-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
18#include <Draw_Appli.hxx>
7fd59977 19#include <Draw_Color.hxx>
42cf5bc1 20#include <Draw_ColorKind.hxx>
21#include <Draw_Display.hxx>
22#include <Draw_Grid.hxx>
23#include <gp_Pnt.hxx>
24#include <gp_Trsf.hxx>
25#include <Standard_Type.hxx>
7fd59977 26
27static Standard_Real MinimumStep = 1.e-3 ;
28static Standard_Real Ratio = 200.0 ;
29
7fd59977 30extern Draw_Viewer dout;
7fd59977 31
32//=======================================================================
33// Function : Draw_Grid
34// Purpose : Constructor.
35//=======================================================================
36
37Draw_Grid::Draw_Grid () :
38 myStepX (0.0) ,
39 myStepY (0.0) ,
40 myStepZ (0.0) ,
41 myIsActive (Standard_False)
42{
43}
44
45//=======================================================================
46// Function : Steps
47// Purpose : Sets the steps along the X, Y & Z axis.
48//=======================================================================
49
50void Draw_Grid::Steps (const Standard_Real StepX,
51 const Standard_Real StepY,
52 const Standard_Real StepZ)
53{
54 myStepX = Abs (StepX) ;
55 myStepY = Abs (StepY) ;
56 myStepZ = Abs (StepZ) ;
57 myIsActive = myStepX > MinimumStep
58 && myStepY > MinimumStep
59 && myStepZ > MinimumStep ;
60}
61
62//=======================================================================
63// Function : DrawOn
64// Purpose : Displays the grid.
65//=======================================================================
66
67void Draw_Grid::DrawOn (Draw_Display& Out) const
68{
69 if (!myIsActive) return ;
70
71 Standard_Integer xmin, xmax, ymin, ymax ;
72 Standard_Integer IndexX, IndexY ;
73 Standard_Real StepX, StepY ;
74 Standard_Integer MinIndexX, MaxIndexX, MinIndexY, MaxIndexY ;
75 Standard_Real Offset ;
76 Standard_Real zoom, Xmin, Xmax, Ymin, Ymax ;
77 gp_Trsf T ;
78 gp_Pnt Pnt1, Pnt2 ;
79
80 Standard_Integer IdtView ;
81 char *Type ;
82
83 IdtView = Out.ViewId () ;
84 if (!dout.HasView (IdtView)) return ;
85 Type = dout.GetType (IdtView) ;
86 switch (*(Type+1)) {
87 case 'X' : StepX = myStepX ; break ;
88 case 'Y' : StepX = myStepY ; break ;
89 case 'Z' : StepX = myStepZ ; break ;
90 default : StepX = 0.0 ; break ;
91 }
92 switch (*(Type+3)) {
93 case 'X' : StepY = myStepX ; break ;
94 case 'Y' : StepY = myStepY ; break ;
95 case 'Z' : StepY = myStepZ ; break ;
96 default : StepY = 0.0 ; break ;
97 }
98
99 if (StepX > MinimumStep && StepY > MinimumStep) {
100
101 dout.GetFrame (IdtView, xmin, ymin, xmax, ymax) ;
102 dout.GetTrsf (IdtView, T) ; T.Invert () ;
103 zoom = dout.Zoom (IdtView) ;
104
105 Xmin = ((Standard_Real) xmin) / zoom ;
106 Xmax = ((Standard_Real) xmax) / zoom ;
107 Ymin = ((Standard_Real) ymin) / zoom ;
108 Ymax = ((Standard_Real) ymax) / zoom ;
109
110 Offset = Min (Xmax - Xmin, Ymax - Ymin) / Ratio ;
111
112 MinIndexX = (Standard_Integer) (Xmin / StepX) ;
113 MaxIndexX = (Standard_Integer) (Xmax / StepX) ;
114 MinIndexY = (Standard_Integer) (Ymin / StepY) ;
115 MaxIndexY = (Standard_Integer) (Ymax / StepY) ;
116
117 for (IndexX = MinIndexX ; IndexX <= MaxIndexX ; IndexX++) {
118 for (IndexY = MinIndexY ; IndexY <= MaxIndexY ; IndexY++) {
119 Standard_Real X = ((Standard_Real) IndexX) * StepX ;
120 Standard_Real Y = ((Standard_Real) IndexY) * StepY ;
121
122 Pnt1.SetCoord (X - Offset, Y, 0.0) ; Pnt1.Transform (T) ;
123 Pnt2.SetCoord (X + Offset, Y, 0.0) ; Pnt2.Transform (T) ;
124 Out.SetColor (Draw_Color (Draw_bleu)) ;
125 Out.Draw (Pnt1, Pnt2) ;
126
127 Pnt1.SetCoord (X, Y - Offset, 0.0) ; Pnt1.Transform (T) ;
128 Pnt2.SetCoord (X, Y + Offset, 0.0) ; Pnt2.Transform (T) ;
129 Out.SetColor (Draw_Color (Draw_bleu)) ;
130 Out.Draw (Pnt1, Pnt2) ;
131 }
132 }
133
134 }
135}