0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / Draw / Draw_Display.cxx
1 // Created on: 1991-07-15
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Draw_Color.hxx>
19 #include <Draw_Display.hxx>
20 #include <ElCLib.hxx>
21 #include <gp_Circ.hxx>
22 #include <gp_Circ2d.hxx>
23 #include <gp_Pnt.hxx>
24 #include <gp_Pnt2d.hxx>
25
26 extern Standard_Boolean Draw_Bounds;
27
28
29 //=======================================================================
30 //function : DrawMarker
31 //purpose  : 
32 //=======================================================================
33
34 void Draw_Display::DrawMarker (const gp_Pnt& pt, 
35                                const Draw_MarkerShape S, 
36                                const Standard_Integer Size)
37 {
38   gp_Pnt2d p;
39   Project(pt,p);
40   DrawMarker(p,S,Size);
41 }
42
43 //=======================================================================
44 //function : DrawMarker
45 //purpose  : 
46 //=======================================================================
47
48 void Draw_Display::DrawMarker (const gp_Pnt2d& pt, 
49                                const Draw_MarkerShape S, 
50                                const Standard_Integer ISize)
51 {
52   Draw_Bounds = Standard_False;
53
54   gp_Pnt2d p1 = pt;
55   gp_Pnt2d p2 = p1;
56   gp_Circ2d C;
57   Standard_Real Size = ((Standard_Real) ISize) / Zoom();
58   
59   switch (S) {
60     
61   case Draw_Square :
62     p1.Translate(gp_Vec2d(-Size,-Size));
63     p2.Translate(gp_Vec2d( Size,-Size));
64     Draw(p1,p2);
65     p1.Translate(gp_Vec2d(2*Size,2*Size));
66     Draw(p1,p2);
67     p2.Translate(gp_Vec2d(-2*Size,2*Size));
68     Draw(p1,p2);
69     p1.Translate(gp_Vec2d(-2*Size,-2*Size));
70     Draw(p1,p2);
71     break;
72
73   case Draw_Losange :
74     p1.Translate(gp_Vec2d(-Size,0));
75     p2.Translate(gp_Vec2d( 0,Size));
76     Draw(p1,p2);
77     p1.Translate(gp_Vec2d(2*Size,0));
78     Draw(p1,p2);
79     p2.Translate(gp_Vec2d(0,-2*Size));
80     Draw(p1,p2);
81     p1.Translate(gp_Vec2d(-2*Size,0));
82     Draw(p1,p2);
83     break;
84
85   case Draw_X :
86     p1.Translate(gp_Vec2d(-Size,-Size));
87     p2.Translate(gp_Vec2d( Size,Size));
88     Draw(p1,p2);
89     p1.Translate(gp_Vec2d(2*Size,0));
90     p2.Translate(gp_Vec2d(-2*Size,0));
91     Draw(p1,p2);
92     break;
93
94   case Draw_Plus :
95     p1.Translate(gp_Vec2d(-Size,0));
96     p2.Translate(gp_Vec2d( Size,0));
97     Draw(p1,p2);
98     p1.Translate(gp_Vec2d(Size,Size));
99     p2.Translate(gp_Vec2d(-Size,-Size));
100     Draw(p1,p2);
101     break;
102     
103   case Draw_Circle :
104 //    gp_Circ2d C;
105     C.SetRadius(ISize);
106     C.SetLocation(pt);
107     Draw(C, 0, 2*M_PI, Standard_False);
108     break;
109   default:
110     break;
111     
112   }
113   Draw_Bounds = Standard_True;
114   MoveTo(pt);
115 }
116
117 //=======================================================================
118 //function : DrawMarker
119 //purpose  : 
120 //=======================================================================
121
122 void Draw_Display::DrawMarker (const gp_Pnt& pt, 
123                                const Draw_MarkerShape S, 
124                                const Standard_Real Size)
125 {
126   gp_Pnt2d p;
127   Project(pt,p);
128   DrawMarker(p,S,Size);
129 }
130
131 //=======================================================================
132 //function : DrawMarker
133 //purpose  : 
134 //=======================================================================
135
136 void Draw_Display::DrawMarker (const gp_Pnt2d& pt, 
137                                const Draw_MarkerShape S, 
138                                const Standard_Real R)
139 {
140   switch (S) {
141   case Draw_Square :
142   case Draw_Losange :
143   case Draw_X :
144   case Draw_Plus :
145   case Draw_Circle :
146     {
147       Standard_Integer I = (Standard_Integer ) R;
148       if(!I) return;
149       DrawMarker(pt, S, I);
150       break;
151     }
152   case Draw_CircleZoom :
153     if(R == 0.0) return;
154     gp_Circ2d C;
155     C.SetRadius(R);
156     C.SetLocation(pt);
157     // if the circus is too small, a "plus" is drawn to mark the point 
158     Standard_Boolean b = (R * Zoom()) > 2;
159     if(b)
160       Draw(C, 0, 2*M_PI);
161     else
162       DrawMarker(pt, Draw_Plus);
163   }
164   Draw_Bounds = Standard_True;
165   MoveTo(pt);
166 }
167
168 #define MAXPNT 200
169 #define DEFLECTION 5
170
171 //=======================================================================
172 //function : Draw
173 //purpose  : 
174 //=======================================================================
175
176 void Draw_Display::Draw(const gp_Circ& C, const Standard_Real A1,const Standard_Real A3,
177                         const Standard_Boolean ModifyWithZoom)
178 {
179   Standard_Real A2 = A3;
180   while (A2 < A1) A2 += 2*M_PI;
181   
182   Standard_Real angle = DEFLECTION / (C.Radius() * Zoom());
183   Standard_Integer n = (Standard_Integer )( (A2 - A1) / angle);
184   if (n > MAXPNT) {
185     angle = (A2 - A1) / MAXPNT;
186     n = MAXPNT;
187   }
188   if (n <= 6) {
189     angle = (A2 - A1) / 6;
190     n = 6;
191   }
192   Standard_Real c = 2*Cos(angle);
193   
194   gp_Circ Cloc(C);
195   if(!ModifyWithZoom) {
196     Standard_Integer ISize = (Standard_Integer )( Cloc.Radius() / Zoom());
197     Cloc.SetRadius(ISize);
198   }
199   
200   gp_Pnt PC = Cloc.Location();
201   gp_Pnt P = ElCLib::Value(A1,Cloc);
202   MoveTo(P);
203   gp_Vec V1(PC,P);
204   P = ElCLib::Value(A1+angle,Cloc);
205   gp_Vec V2(PC,P);
206   DrawTo(P);
207   gp_Vec V;
208
209   for (Standard_Integer i = 2; i < n; i++) {
210     V = c * V2 - V1;
211     V1 = V2;
212     V2 = V;
213     DrawTo(PC.Translated(V));
214   }
215   
216   P = ElCLib::Value(A2,Cloc);
217   DrawTo(P);
218 }
219
220 //=======================================================================
221 //function : Draw
222 //purpose  : 
223 //=======================================================================
224
225 void Draw_Display::Draw(const gp_Circ2d& C, const Standard_Real A1, const Standard_Real A3,
226                         const Standard_Boolean ModifyWithZoom)
227 {
228   Standard_Real A2 = A3;
229   while (A2 < A1) A2 += 2*M_PI;
230   
231   Standard_Real angle = DEFLECTION / (C.Radius() * Zoom());
232   Standard_Integer n = (Standard_Integer )( (A2 - A1) / angle);
233   if (n > MAXPNT) {
234     angle = (A2 - A1) / MAXPNT;
235     n = MAXPNT;
236   }
237   else if (n <= 6) {
238     angle = (A2 - A1) / 6;
239     n = 6;
240   }
241   Standard_Real c = 2*Cos(angle);
242   
243   gp_Circ2d Cloc(C);
244   if(!ModifyWithZoom) {// the effet of zoom is cancelled to follow
245     Standard_Real Size = Cloc.Radius() / Zoom();
246     Cloc.SetRadius(Size);
247   }
248   
249   gp_Pnt2d PC = Cloc.Location();
250   gp_Pnt2d P = ElCLib::Value(A1,Cloc);
251   MoveTo(P);
252   gp_Vec2d V1(PC,P);
253   P = ElCLib::Value(A1+angle,Cloc);
254   gp_Vec2d V2(PC,P);
255   DrawTo(P);
256   gp_Vec2d V;
257
258   for (Standard_Integer i = 2; i < n; i++) {
259     V = c * V2 - V1;
260     V1 = V2;
261     V2 = V;
262     DrawTo(PC.Translated(V));
263   }
264   
265   P = ElCLib::Value(A2,Cloc);
266   DrawTo(P);
267 }
268
269
270 //=======================================================================
271 //function : Project
272 //purpose  : 
273 //=======================================================================
274
275 gp_Pnt2d Draw_Display::Project(const gp_Pnt& p) const
276 {
277   gp_Pnt2d pt;
278   Project(p,pt);
279   return pt;
280 }