summaryrefslogtreecommitdiff
path: root/src/Draw/Draw_Display.cxx
blob: e37c9449c0aadf43af6c3876bf7e4f198f082ba1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// Copyright: 	Matra-Datavision 1991
// File:	Draw_Display.cxx
// Created:	Mon Jul 15 10:58:59 1991
// Author:	Arnaud BOUZY
//		<adn>
 

#include <Draw_Display.ixx>
#include <ElCLib.hxx>

extern Standard_Boolean Draw_Bounds;


//=======================================================================
//function : DrawMarker
//purpose  : 
//=======================================================================

void Draw_Display::DrawMarker (const gp_Pnt& pt, 
			       const Draw_MarkerShape S, 
			       const Standard_Integer Size)
{
  gp_Pnt2d p;
  Project(pt,p);
  DrawMarker(p,S,Size);
}

//=======================================================================
//function : DrawMarker
//purpose  : 
//=======================================================================

void Draw_Display::DrawMarker (const gp_Pnt2d& pt, 
			       const Draw_MarkerShape S, 
			       const Standard_Integer ISize)
{
  Draw_Bounds = Standard_False;

  gp_Pnt2d p1 = pt;
  gp_Pnt2d p2 = p1;
  gp_Circ2d C;
  Standard_Real Size = ((Standard_Real) ISize) / Zoom();
  
  switch (S) {
    
  case Draw_Square :
    p1.Translate(gp_Vec2d(-Size,-Size));
    p2.Translate(gp_Vec2d( Size,-Size));
    Draw(p1,p2);
    p1.Translate(gp_Vec2d(2*Size,2*Size));
    Draw(p1,p2);
    p2.Translate(gp_Vec2d(-2*Size,2*Size));
    Draw(p1,p2);
    p1.Translate(gp_Vec2d(-2*Size,-2*Size));
    Draw(p1,p2);
    break;

  case Draw_Losange :
    p1.Translate(gp_Vec2d(-Size,0));
    p2.Translate(gp_Vec2d( 0,Size));
    Draw(p1,p2);
    p1.Translate(gp_Vec2d(2*Size,0));
    Draw(p1,p2);
    p2.Translate(gp_Vec2d(0,-2*Size));
    Draw(p1,p2);
    p1.Translate(gp_Vec2d(-2*Size,0));
    Draw(p1,p2);
    break;

  case Draw_X :
    p1.Translate(gp_Vec2d(-Size,-Size));
    p2.Translate(gp_Vec2d( Size,Size));
    Draw(p1,p2);
    p1.Translate(gp_Vec2d(2*Size,0));
    p2.Translate(gp_Vec2d(-2*Size,0));
    Draw(p1,p2);
    break;

  case Draw_Plus :
    p1.Translate(gp_Vec2d(-Size,0));
    p2.Translate(gp_Vec2d( Size,0));
    Draw(p1,p2);
    p1.Translate(gp_Vec2d(Size,Size));
    p2.Translate(gp_Vec2d(-Size,-Size));
    Draw(p1,p2);
    break;
    
  case Draw_Circle :
//    gp_Circ2d C;
    C.SetRadius(ISize);
    C.SetLocation(pt);
    Draw(C, 0, 2*PI, Standard_False);
    break;
#ifndef DEB
  default:
    break;
#endif
    
  }
  Draw_Bounds = Standard_True;
  MoveTo(pt);
}

//=======================================================================
//function : DrawMarker
//purpose  : 
//=======================================================================

void Draw_Display::DrawMarker (const gp_Pnt& pt, 
			       const Draw_MarkerShape S, 
			       const Standard_Real Size)
{
  gp_Pnt2d p;
  Project(pt,p);
  DrawMarker(p,S,Size);
}

//=======================================================================
//function : DrawMarker
//purpose  : 
//=======================================================================

void Draw_Display::DrawMarker (const gp_Pnt2d& pt, 
			       const Draw_MarkerShape S, 
			       const Standard_Real R)
{
  switch (S) {
  case Draw_Square :
  case Draw_Losange :
  case Draw_X :
  case Draw_Plus :
  case Draw_Circle :
    {
      Standard_Integer I = (Standard_Integer ) R;
      if(!I) return;
      DrawMarker(pt, S, I);
      break;
    }
  case Draw_CircleZoom :
    if(R == 0.0) return;
    gp_Circ2d C;
    C.SetRadius(R);
    C.SetLocation(pt);
    // if the circus is too small, a "plus" is drawn to mark the point 
    Standard_Boolean b = (R * Zoom()) > 2;
    if(b)
      Draw(C, 0, 2*PI);
    else
      DrawMarker(pt, Draw_Plus);
  }
  Draw_Bounds = Standard_True;
  MoveTo(pt);
}

#define MAXPNT 200
#define DEFLECTION 5

//=======================================================================
//function : Draw
//purpose  : 
//=======================================================================

void Draw_Display::Draw(const gp_Circ& C, const Standard_Real A1,const Standard_Real A3,
			const Standard_Boolean ModifyWithZoom)
{
  Standard_Real A2 = A3;
  while (A2 < A1) A2 += 2*PI;
  
  Standard_Real angle = DEFLECTION / (C.Radius() * Zoom());
  Standard_Integer n = (Standard_Integer )( (A2 - A1) / angle);
  if (n > MAXPNT) {
    angle = (A2 - A1) / MAXPNT;
    n = MAXPNT;
  }
  if (n <= 6) {
    angle = (A2 - A1) / 6;
    n = 6;
  }
  Standard_Real c = 2*Cos(angle);
  
  gp_Circ Cloc(C);
  if(!ModifyWithZoom) {
    Standard_Integer ISize = (Standard_Integer )( Cloc.Radius() / Zoom());
    Cloc.SetRadius(ISize);
  }
  
  gp_Pnt PC = Cloc.Location();
  gp_Pnt P = ElCLib::Value(A1,Cloc);
  MoveTo(P);
  gp_Vec V1(PC,P);
  P = ElCLib::Value(A1+angle,Cloc);
  gp_Vec V2(PC,P);
  DrawTo(P);
  gp_Vec V;

  for (Standard_Integer i = 2; i < n; i++) {
    V = c * V2 - V1;
    V1 = V2;
    V2 = V;
    DrawTo(PC.Translated(V));
  }
  
  P = ElCLib::Value(A2,Cloc);
  DrawTo(P);
}

//=======================================================================
//function : Draw
//purpose  : 
//=======================================================================

void Draw_Display::Draw(const gp_Circ2d& C, const Standard_Real A1, const Standard_Real A3,
			const Standard_Boolean ModifyWithZoom)
{
  Standard_Real A2 = A3;
  while (A2 < A1) A2 += 2*PI;
  
  Standard_Real angle = DEFLECTION / (C.Radius() * Zoom());
  Standard_Integer n = (Standard_Integer )( (A2 - A1) / angle);
  if (n > MAXPNT) {
    angle = (A2 - A1) / MAXPNT;
    n = MAXPNT;
  }
  else if (n <= 6) {
    angle = (A2 - A1) / 6;
    n = 6;
  }
  Standard_Real c = 2*Cos(angle);
  
  gp_Circ2d Cloc(C);
  if(!ModifyWithZoom) {// the effet of zoom is cancelled to follow
    Standard_Real Size = Cloc.Radius() / Zoom();
    Cloc.SetRadius(Size);
  }
  
  gp_Pnt2d PC = Cloc.Location();
  gp_Pnt2d P = ElCLib::Value(A1,Cloc);
  MoveTo(P);
  gp_Vec2d V1(PC,P);
  P = ElCLib::Value(A1+angle,Cloc);
  gp_Vec2d V2(PC,P);
  DrawTo(P);
  gp_Vec2d V;

  for (Standard_Integer i = 2; i < n; i++) {
    V = c * V2 - V1;
    V1 = V2;
    V2 = V;
    DrawTo(PC.Translated(V));
  }
  
  P = ElCLib::Value(A2,Cloc);
  DrawTo(P);
}


//=======================================================================
//function : Project
//purpose  : 
//=======================================================================

gp_Pnt2d Draw_Display::Project(const gp_Pnt& p) const
{
  gp_Pnt2d pt;
  Project(p,pt);
  return pt;
}