0023510: Integration of test grid "vis" into the new testing system
[occt.git] / src / V2d / V2d_CircularGraphicGrid.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18// Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
19#define PRO10288 //GG 240398/090798 (PRO13334)
20// Permettre un pas de rayon < 2 MM
21
22#define OCC192 // jfa 27/02/2002
23// for right display of rotated grid
24
25#include <V2d_CircularGraphicGrid.ixx>
26#include <Aspect_Driver.hxx>
27
28V2d_CircularGraphicGrid::V2d_CircularGraphicGrid(
29 const Handle(Graphic2d_GraphicObject)& aGraphicObject,
30 const Standard_Real X,
31 const Standard_Real Y,
32 const Standard_Real alpha,
33 const Standard_Real step,
34 const Standard_Integer aDivision,
35 const Standard_Integer PointsColorIndex)
36
37:Graphic2d_Primitive(aGraphicObject),
38OX((Standard_ShortReal)X),
39OY((Standard_ShortReal)Y),
40angle((Standard_ShortReal)alpha),
41Step((Standard_ShortReal)step),
42Division(aDivision),
43DrawMode(Aspect_GDM_Lines),
44myPointsColorIndex(PointsColorIndex)
45{
46
47}
48
49void V2d_CircularGraphicGrid::Draw(const Handle(Graphic2d_Drawer)& aDrawer){
50
51 Standard_ShortReal XF, YF, SF, XT, YT, STANDARD, ZF;
52 aDrawer->Values (XF, YF, SF, XT, YT, STANDARD, ZF);
53 Standard_Real w,h;
54 aDrawer->Driver()->WorkSpace(w,h);
55 Standard_ShortReal Coef =
56 (Standard_ShortReal) ((w < h) ? w/Sqrt( w*w + h*h) : h/Sqrt( w*w + h*h)) ;
57
58
59 Standard_Real d = Sqrt ( (OX-XF) * (OX-XF) + (OY-YF) * (OY-YF) );
60 Standard_Integer n1,n;
61 Standard_Real thestep = Step;
62 if(d <= SF/Coef) {
63 n1 = 1;
64 n = (Standard_Integer )( ((Abs (OX-XF) > Abs (OY-YF) ? Abs (OX-XF) :Abs (OY-YF)) + SF /Coef)/thestep +1);
65 }
66 else {
67 n1 = (Standard_Integer )( (d - SF/Coef) /thestep);
68 n = Standard_Integer ( SF / thestep/Coef ) *2 + 1;
69 }
70#ifdef PRO10288
71 while ( n > 200) {
72#else
73 while ( n > 100) {
74#endif
75 thestep = thestep * 10.;
76 if(d <= SF/Coef) {
77 n1 = 1;
78 n = (Standard_Integer )( ((Abs (OX-XF) > Abs (OY-YF) ? Abs (OX-XF) :Abs (OY-YF)) + SF /Coef)/thestep +1);
79 }
80 else {
81 n1 = (Standard_Integer )( (d - SF/Coef) /thestep);
82 n = Standard_Integer ( SF / thestep/Coef ) *2 + 1;
83 }
84 }
85// cout << "XF=" << XF << " YF =" << YF << " SF=" << SF
86// << " n1 = " << n1 << " n= " << n << endl << flush;
87 Standard_ShortReal xc = Standard_ShortReal(OX);
88 Standard_ShortReal yc = Standard_ShortReal(OY);
89 Standard_ShortReal ds = Standard_ShortReal(thestep);
90 Standard_ShortReal s= Standard_ShortReal(n1)*ds;
91 switch (DrawMode){
92 case Aspect_GDM_Points: {
93 aDrawer->SetMarkerAttrib (myPointsColorIndex,0,0);
94 aDrawer->MapMarkerFromTo(0,xc,yc,Standard_ShortReal(0.001),Standard_ShortReal(0.001),0.);
95 for (Standard_Integer k=1; k<=n; k++) {
96 DrawCircle(aDrawer,xc,yc,s,Standard_True);
97 s+=ds;
98 }
99 break;
100 }
101 case Aspect_GDM_Lines:
102 default:
103 {
104 aDrawer->SetLineAttrib (myColorIndex,0,0);
105 for (Standard_Integer i=1; i<=n; i++) {
106 DrawCircle(aDrawer,xc,yc,s,Standard_False);
107 s+=ds;
108 }
c6541a0c 109 Standard_Real a = M_PI / Standard_Real(Division);
7fd59977 110 for (Standard_Integer j=1; j<= Division; j++) {
111 aDrawer->MapInfiniteLineFromTo(OX,OY ,
112 Standard_ShortReal(Cos(angle+Standard_Real(j)*a)),
113 Standard_ShortReal(Sin(angle+Standard_Real(j)*a)));
114 }
115 }
116 }
117}
118
119Standard_Boolean V2d_CircularGraphicGrid::Pick(const Standard_ShortReal X,
120 const Standard_ShortReal Y,
121 const Standard_ShortReal aPrecision,
122 const Handle(Graphic2d_Drawer)& aDrawer) {
123return Standard_False;
124}
125void V2d_CircularGraphicGrid::SetDrawMode (const Aspect_GridDrawMode aDrawMode) {
126 DrawMode = aDrawMode;
127}
128
129void V2d_CircularGraphicGrid::DrawCircle
130 (const Handle(Graphic2d_Drawer)& aDrawer,
131 const Standard_ShortReal myX,
132 const Standard_ShortReal myY,
133 const Standard_ShortReal myRadius,
134 const Standard_Boolean DrawPoints) const {
135
136 Standard_ShortReal Def;
137 Standard_ShortReal Coeff;
138 Aspect_TypeOfDeflection Type;
139 aDrawer->DrawPrecision(Def,Coeff,Type);
140 Standard_Real val;
141 if(myRadius > Def)
142 val = Max( 0.0044 , Min (0.7854 , 2. * ACos(1.-Def/myRadius)));
143 else
c6541a0c 144 val = 0.7854; // = PI / 4.
7fd59977 145 Standard_Integer nbpoints;
146 if(DrawPoints) {
147 nbpoints = Division *2;
148 }
149 else {
c6541a0c 150 nbpoints = Standard_Integer(Abs (2 * M_PI) / val) + 2;
7fd59977 151 }
152
c6541a0c 153 Standard_ShortReal teta = Standard_ShortReal(Abs(2 * M_PI) / nbpoints);
7fd59977 154 Standard_ShortReal x1 = myRadius;
155 Standard_ShortReal y1 = 0;
156 Standard_ShortReal x2,y2,x3,y3;
157 Standard_ShortReal cosin = Standard_ShortReal(Cos(teta));
158 x2 = Standard_ShortReal(myRadius * Cos(teta));
159 y2 = Standard_ShortReal(myRadius * Sin(teta));
160
161#ifdef OCC192
162 Standard_ShortReal x_alpha, y_alpha;
163 Standard_ShortReal cos_alpha = Cos(angle), sin_alpha = Sin(angle);
164#endif
165 if(DrawPoints) {
166#ifdef OCC192
167 x_alpha = x1*cos_alpha - y1*sin_alpha; // rotate on <angle> radians
168 y_alpha = x1*sin_alpha + y1*cos_alpha; //
169 aDrawer->MapMarkerFromTo(0,x_alpha+myX,y_alpha+myY,Standard_ShortReal(0.001),Standard_ShortReal(0.001),0.);
170#else
171 aDrawer->MapMarkerFromTo(0,x1+myX,y1+myY,Standard_ShortReal(0.001),Standard_ShortReal(0.001),0.);
172 aDrawer->MapMarkerFromTo(0,x2+myX,y2+myY,Standard_ShortReal(0.001),Standard_ShortReal(0.001),0.);
173#endif
174 }
175 else {
176 aDrawer->MapSegmentFromTo(x1+myX,y1+myY,x2+myX,y2+myY);
177 }
178 for (Standard_Integer i = 3; i <= nbpoints+1; i++) {
179 x3 = 2*x2*cosin - x1;
180 y3 = 2*y2*cosin - y1;
181 if(DrawPoints) {
182#ifdef OCC192
183 x_alpha = x2*cos_alpha - y2*sin_alpha;
184 y_alpha = x2*sin_alpha + y2*cos_alpha;
185 aDrawer->MapMarkerFromTo(0,x_alpha+myX,y_alpha+myY,Standard_ShortReal(0.001),Standard_ShortReal(0.001),0.);
186#else
187 aDrawer->MapMarkerFromTo(0,x2+myX,y2+myY,Standard_ShortReal(0.001),Standard_ShortReal(0.001),0.);
188#endif
189 }
190 else {
191 aDrawer->MapSegmentFromTo(x2+myX,y2+myY,x3+myX,y3+myY);
192 }
193 x1 = x2; y1 = y2; x2 = x3; y2 = y3;
194 }
195 }
196
197void V2d_CircularGraphicGrid::Save(Aspect_FStream& aFStream) const
198{
199}
200