0030430: Draw - command testgrid in parallel mode hangs if DRAW is launched without GUI
[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
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(Draw_Grid,Draw_Drawable3D)
28
7fd59977 29static Standard_Real MinimumStep = 1.e-3 ;
30static Standard_Real Ratio = 200.0 ;
31
7fd59977 32extern Draw_Viewer dout;
7fd59977 33
34//=======================================================================
35// Function : Draw_Grid
36// Purpose : Constructor.
37//=======================================================================
38
39Draw_Grid::Draw_Grid () :
40 myStepX (0.0) ,
41 myStepY (0.0) ,
42 myStepZ (0.0) ,
43 myIsActive (Standard_False)
44{
45}
46
47//=======================================================================
48// Function : Steps
49// Purpose : Sets the steps along the X, Y & Z axis.
50//=======================================================================
51
52void Draw_Grid::Steps (const Standard_Real StepX,
53 const Standard_Real StepY,
54 const Standard_Real StepZ)
55{
56 myStepX = Abs (StepX) ;
57 myStepY = Abs (StepY) ;
58 myStepZ = Abs (StepZ) ;
59 myIsActive = myStepX > MinimumStep
60 && myStepY > MinimumStep
61 && myStepZ > MinimumStep ;
62}
63
64//=======================================================================
65// Function : DrawOn
66// Purpose : Displays the grid.
67//=======================================================================
68
69void Draw_Grid::DrawOn (Draw_Display& Out) const
70{
71 if (!myIsActive) return ;
72
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 ;
79 gp_Trsf T ;
80 gp_Pnt Pnt1, Pnt2 ;
81
82 Standard_Integer IdtView ;
83 char *Type ;
84
85 IdtView = Out.ViewId () ;
86 if (!dout.HasView (IdtView)) return ;
87 Type = dout.GetType (IdtView) ;
88 switch (*(Type+1)) {
89 case 'X' : StepX = myStepX ; break ;
90 case 'Y' : StepX = myStepY ; break ;
91 case 'Z' : StepX = myStepZ ; break ;
92 default : StepX = 0.0 ; break ;
93 }
94 switch (*(Type+3)) {
95 case 'X' : StepY = myStepX ; break ;
96 case 'Y' : StepY = myStepY ; break ;
97 case 'Z' : StepY = myStepZ ; break ;
98 default : StepY = 0.0 ; break ;
99 }
100
101 if (StepX > MinimumStep && StepY > MinimumStep) {
102
103 dout.GetFrame (IdtView, xmin, ymin, xmax, ymax) ;
104 dout.GetTrsf (IdtView, T) ; T.Invert () ;
105 zoom = dout.Zoom (IdtView) ;
106
107 Xmin = ((Standard_Real) xmin) / zoom ;
108 Xmax = ((Standard_Real) xmax) / zoom ;
109 Ymin = ((Standard_Real) ymin) / zoom ;
110 Ymax = ((Standard_Real) ymax) / zoom ;
111
112 Offset = Min (Xmax - Xmin, Ymax - Ymin) / Ratio ;
113
114 MinIndexX = (Standard_Integer) (Xmin / StepX) ;
115 MaxIndexX = (Standard_Integer) (Xmax / StepX) ;
116 MinIndexY = (Standard_Integer) (Ymin / StepY) ;
117 MaxIndexY = (Standard_Integer) (Ymax / StepY) ;
118
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 ;
123
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) ;
128
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) ;
133 }
134 }
135
136 }
137}