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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
#define PRO3730
#define WTO0006 //GG_221196
// Ne pas transformer les cercles pleins en arc de cercles
// presque pleins a EPSILON pres car dans ce cas les
// JAP ne peuvent plus tracer leur drapeaux !!!
#define BUC50076//GG_231097/090298
// Attention aux transformations de type MIRROR
// car dans ce cas il faut inverser le parcours de l'arc et
// surtout ne pas annuler la translation dans la matrice!
#define G002 //Add new DrawElement(), DrawVertex() methods
#define VERTEXMARKER 2
#define DEFAULTMARKERSIZE 3.0
#define MAXPOINTS 1023
#include <Graphic2d_Circle.ixx>
#include <Quantity_PlaneAngle.hxx>
#include <TShort_Array1OfShortReal.hxx>
#include <gp_Trsf2d.hxx>
#include <Graphic2d_Primitive.pxx>
Graphic2d_Circle::Graphic2d_Circle
(const Handle(Graphic2d_GraphicObject)& aGraphicObject,
const Quantity_Length X, const Quantity_Length Y, const Quantity_Length Radius)
: Graphic2d_Line(aGraphicObject) {
myX = Standard_ShortReal(X);
myY = Standard_ShortReal(Y);
myRadius = Standard_ShortReal(Radius);
if ( myRadius <= ShortRealEpsilon ())
Graphic2d_CircleDefinitionError::Raise ("The radius = 0.");
DoMinMax();
myFirstAngle = 0.;
mySecondAngle = Standard_ShortReal(2.*Standard_PI);
myisArc = Standard_False;
myNumOfElem = MAXPOINTS + 1;
myNumOfVert = 3;
}
Graphic2d_Circle::Graphic2d_Circle
(const Handle(Graphic2d_GraphicObject)& aGraphicObject,
const Quantity_Length X, const Quantity_Length Y,
const Quantity_Length Radius, const Quantity_PlaneAngle Alpha,
const Quantity_PlaneAngle Beta)
: Graphic2d_Line(aGraphicObject) {
myX = Standard_ShortReal(X);
myY = Standard_ShortReal(Y);
myRadius = Standard_ShortReal(Radius);
myisArc = Standard_True;
if (myRadius <= ShortRealEpsilon ())
Graphic2d_CircleDefinitionError::Raise ("The radius = 0.");
myNumOfElem = MAXPOINTS + 1;
myNumOfVert = 3;
#ifdef PRO3730
Standard_ShortReal TwoPI = Standard_ShortReal(2.*Standard_PI);
myFirstAngle = Standard_ShortReal (Alpha);
mySecondAngle = Standard_ShortReal (Beta);
while( myFirstAngle < 0. ) myFirstAngle += TwoPI;
while( myFirstAngle > 2.*Standard_PI ) myFirstAngle -= TwoPI;
while( mySecondAngle < 0. ) mySecondAngle += TwoPI;
while( mySecondAngle > 2.*Standard_PI ) mySecondAngle -= TwoPI;
if( mySecondAngle < myFirstAngle ) mySecondAngle += TwoPI;
if ( (mySecondAngle - myFirstAngle < ShortRealEpsilon()) ||
(mySecondAngle - myFirstAngle >= TwoPI) ) {
myFirstAngle = 0.;
mySecondAngle = TwoPI;
DoMinMax();
} else {
Standard_ShortReal Acur,Xcur,Ycur,Xsav;
myMinX = myMaxX = Standard_ShortReal(Cos(myFirstAngle));
myMinY = myMaxY = Standard_ShortReal(Sin(myFirstAngle));
Xcur = Standard_ShortReal(Cos(mySecondAngle));
Ycur = Standard_ShortReal(Sin(mySecondAngle));
myMinX = myMinX < Xcur ? myMinX : Xcur;
myMaxX = myMaxX < Xcur ? Xcur : myMaxX;
myMinY = myMinY < Ycur ? myMinY : Ycur;
myMaxY = myMaxY < Ycur ? Ycur : myMaxY;
for( Acur = 0.,Xcur = 1.,Ycur = 0.;
Acur < mySecondAngle; Acur += Standard_ShortReal(Standard_PI/2.) ) {
if( Acur > myFirstAngle ) {
myMinX = ( myMinX < Xcur ? myMinX : Xcur );
myMaxX = ( myMaxX < Xcur ? Xcur : myMaxX );
myMinY = ( myMinY < Ycur ? myMinY : Ycur );
myMaxY = ( myMaxY < Ycur ? Ycur : myMaxY );
}
Xsav = Xcur ;Xcur = -Ycur; Ycur = Xsav;
}
myMinX = myX + myRadius * myMinX;
myMaxX = myX + myRadius * myMaxX;
myMinY = myY + myRadius * myMinY;
myMaxY = myY + myRadius * myMaxY;
}
#else
DoMinMax();
#endif
}
void Graphic2d_Circle :: Center ( Quantity_Length& X,Quantity_Length& Y ) const {
X = Quantity_Length(myX);
Y = Quantity_Length(myY);
}
Quantity_Length Graphic2d_Circle :: Radius ( ) const {
return Quantity_Length(myRadius);
}
Quantity_PlaneAngle Graphic2d_Circle :: FirstAngle ( ) const {
return Quantity_PlaneAngle(myFirstAngle);
}
Quantity_PlaneAngle Graphic2d_Circle :: SecondAngle ( ) const {
return Quantity_PlaneAngle(mySecondAngle);
}
void Graphic2d_Circle::SetCenter( const Quantity_Length X,
const Quantity_Length Y ) {
myX = Standard_ShortReal( X );
myY = Standard_ShortReal( Y );
DoMinMax();
}
void Graphic2d_Circle::SetRadius( const Quantity_Length theR ) {
myRadius = Standard_ShortReal( theR );
DoMinMax();
}
void Graphic2d_Circle::SetAngles( const Quantity_PlaneAngle Alpha,
const Quantity_PlaneAngle Beta ) {
myFirstAngle = Standard_ShortReal( Alpha );
mySecondAngle = Standard_ShortReal( Beta );
}
void Graphic2d_Circle::Draw (const Handle(Graphic2d_Drawer)& aDrawer) {
Standard_Boolean IsIn = Standard_False;
if (! myGOPtr->IsTransformed ())
IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY);
else {
Standard_ShortReal minx, miny, maxx, maxy;
MinMax(minx,maxx,miny,maxy);
IsIn = aDrawer->IsIn (minx,maxx,miny,maxy);
}
if (IsIn) {
DrawLineAttrib(aDrawer);
Standard_ShortReal a, b, c, e, f;
a = myX; b = myY; c = myRadius;
e = myFirstAngle; f = mySecondAngle;
if (myGOPtr->IsTransformed ()) {
gp_GTrsf2d aTrsf = myGOPtr->Transform ();
Standard_Real A, B;
Standard_Real X0, Y0, X1, Y1, X2, Y2, E, F;
A = Standard_Real (a); B = Standard_Real (b);
E = Standard_Real (e); F = Standard_Real (f);
aTrsf.Transforms (A, B);
a = Standard_ShortReal (A); b = Standard_ShortReal (B);
if( Abs(f-e) < Standard_ShortReal(2.*Standard_PI) ) {
// To calculate new aperture angles
// the calculation is done on the trigonometric circle
// and in this case the translation is not taken into account
// except for transformations of type Mirror
// with negative determinant.
#ifndef BUC50076
aTrsf.SetValue (1, 3, 0.0);
aTrsf.SetValue (2, 3, 0.0);
#endif
X1 = Cos (E); Y1 = Sin (E);
X2 = Cos (F); Y2 = Sin (F);
aTrsf.Transforms (X1, Y1);
aTrsf.Transforms (X2, Y2);
#ifdef BUC50076
X0 = Y0 = 0.;
aTrsf.Transforms (X0, Y0);
X1 -= X0; Y1 -= Y0;
X2 -= X0; Y2 -= Y0;
#endif
c = myRadius * Standard_ShortReal(Sqrt(X1*X1 + Y1*Y1));
e = Standard_ShortReal(atan2(Y1,X1));
f = Standard_ShortReal(atan2(Y2,X2));
#ifdef BUC50076
if( aTrsf.IsNegative() ) {
Standard_ShortReal t = e; e = f; f = t;
}
#endif
}
}
if (myTypeOfPolygonFilling == Graphic2d_TOPF_EMPTY) {
aDrawer->MapArcFromTo(a, b, c, e, f);
} else {
aDrawer->MapPolyArcFromTo(a, b, c, e, f);
}
}
}
#ifdef G002
void Graphic2d_Circle::DrawElement( const Handle(Graphic2d_Drawer)& aDrawer,
const Standard_Integer anIndex) {
Standard_Boolean IsIn = Standard_False;
if (! myGOPtr->IsTransformed ())
IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY);
else {
Standard_ShortReal minx, miny, maxx, maxy;
MinMax(minx,maxx,miny,maxy);
IsIn = aDrawer->IsIn (minx,maxx,miny,maxy);
}
if ( IsIn ) {
DrawLineAttrib(aDrawer);
if ( anIndex > 0 && anIndex <= MAXPOINTS + 1 ) {
Standard_ShortReal teta = Abs( mySecondAngle - myFirstAngle ) / MAXPOINTS;
Standard_ShortReal Xp = Standard_ShortReal(myX + myRadius * Cos(myFirstAngle + teta*(anIndex-1))),
Yp = Standard_ShortReal(myY + myRadius * Sin(myFirstAngle + teta*(anIndex-1)));
Standard_Real A, B, C, D;
Standard_ShortReal a = myX, b = myY, c = Xp, d = Yp;
if ( myGOPtr->IsTransformed() ) {
gp_GTrsf2d aTrsf = myGOPtr->Transform ();
A = Standard_Real(a);
B = Standard_Real(b);
C = Standard_Real(c);
D = Standard_Real(d);
aTrsf.Transforms (A, B);
aTrsf.Transforms (C, D);
a = Standard_ShortReal(A);
b = Standard_ShortReal(B);
c = Standard_ShortReal(C);
d = Standard_ShortReal(D);
}
aDrawer->MapSegmentFromTo( a, b, c, d );
}
}
}
void Graphic2d_Circle::DrawVertex( const Handle(Graphic2d_Drawer)& aDrawer,
const Standard_Integer anIndex) {
Standard_Boolean IsIn = Standard_False;
if ( ! myGOPtr->IsTransformed() )
IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
else {
Standard_ShortReal minx, miny, maxx, maxy;
MinMax( minx, maxx, miny, maxy );
IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
}
if ( IsIn ) {
if ( anIndex > 0 && anIndex < 4) {
DrawMarkerAttrib( aDrawer );
Standard_ShortReal X=0.,Y=0.;
if ( anIndex == 1 ) {
X = myX; Y = myY;
} else if ( anIndex == 2 ) {
X = Standard_ShortReal( myX + myRadius *Cos( myFirstAngle ) );
Y = Standard_ShortReal( myY + myRadius *Sin( myFirstAngle ) );
} else if ( anIndex == 3 ) {
X = Standard_ShortReal( myX + myRadius *Cos( mySecondAngle ) );
Y = Standard_ShortReal( myY + myRadius *Sin( mySecondAngle ) );
}
if ( myGOPtr->IsTransformed() ) {
gp_GTrsf2d aTrsf = myGOPtr->Transform ();
Standard_Real A, B;
A = Standard_Real( X );
B = Standard_Real( Y );
aTrsf.Transforms (A, B);
X = Standard_ShortReal( A );
Y = Standard_ShortReal( B );
}
aDrawer->MapMarkerFromTo( VERTEXMARKER, X, Y,
DEFAULTMARKERSIZE,DEFAULTMARKERSIZE, 0.0 );
}
} // end if IsIn is true
}
#endif
Standard_Boolean Graphic2d_Circle::Pick (const Standard_ShortReal X,
const Standard_ShortReal Y,
const Standard_ShortReal aPrecision,
const Handle(Graphic2d_Drawer)& /*aDrawer*/) {
Standard_Boolean found = Standard_False;
Standard_ShortReal SRX = X, SRY = Y;
if ( IsInMinMax( X, Y, aPrecision) ) {
if ( myGOPtr->IsTransformed() ) {
gp_GTrsf2d aTrsf = ( myGOPtr->Transform () ).Inverted ();
Standard_Real RX = Standard_Real (SRX), RY = Standard_Real (SRY);
aTrsf.Transforms( RX, RY );
SRX = Standard_ShortReal( RX );
SRY = Standard_ShortReal( RY );
}
#ifdef G002
if ( Graphic2d_Primitive::IsOn( SRX, SRY, myX, myY, aPrecision) ) {
SetPickedIndex(-1);
return Standard_True;
} else {
if ( myisArc ) {
Standard_ShortReal x1 = Standard_ShortReal(myRadius *Cos( myFirstAngle ) + myX),
y1 = Standard_ShortReal(myRadius *Sin( myFirstAngle ) + myY),
x2 = Standard_ShortReal(myRadius *Cos( mySecondAngle ) + myX),
y2 = Standard_ShortReal(myRadius *Sin( mySecondAngle ) + myY);
if ( Graphic2d_Primitive::IsOn( SRX, SRY, x1, y1, aPrecision) ) {
SetPickedIndex(-2);
return Standard_True;
} else if ( Graphic2d_Primitive::IsOn( SRX, SRY, x2, y2, aPrecision) ) {
SetPickedIndex(-3);
return Standard_True;
}
}
Standard_ShortReal alpha = Abs( mySecondAngle - myFirstAngle );
TShort_Array1OfShortReal Xpoint(1,MAXPOINTS+1);
TShort_Array1OfShortReal Ypoint(1,MAXPOINTS+1);
Standard_ShortReal teta = alpha / MAXPOINTS;
for ( Standard_Integer i = 1; i<= MAXPOINTS+1; i++) {
Xpoint(i) = Standard_ShortReal(myX + myRadius * Cos(myFirstAngle + teta*(i-1)));
Ypoint(i) = Standard_ShortReal(myY + myRadius * Sin(myFirstAngle + teta*(i-1)));
if ( Graphic2d_Primitive::IsOn( SRX, SRY, Xpoint(i), Ypoint(i), aPrecision) ) {
SetPickedIndex(i);
return Standard_True;
}
}
if ( myTypeOfPolygonFilling != Graphic2d_TOPF_EMPTY )
found = Abs( Sqrt((myX - SRX)*(myX - SRX) + (myY - SRY)*(myY - SRY)))
< myRadius;
if ( !found )
found = Abs( Sqrt( (myX - SRX)*(myX - SRX) + (myY - SRY)*(myY - SRY))
- myRadius ) < aPrecision;
if ( found )
SetPickedIndex( 0 );
}
#else
if ( myTypeOfPolygonFilling != Graphic2d_TOPF_EMPTY )
found = Abs( Sqrt((myX - SRX)*(myX - SRX) + (myY - SRY)*(myY - SRY)))
< myRadius;
if ( !found )
found = Abs( Sqrt( (myX - SRX)*(myX - SRX) + (myY - SRY)*(myY - SRY))
- myRadius ) < aPrecision;
#endif
}
return found;
}
void Graphic2d_Circle::DoMinMax() {
myMinX = myX - myRadius; myMinY = myY - myRadius;
myMaxX = myX + myRadius; myMaxY = myY + myRadius;
}
void Graphic2d_Circle::Save(Aspect_FStream& aFStream) const
{
*aFStream << "Graphic2d_Circle" << endl;
*aFStream << myX << ' ' << myY << endl;
*aFStream << myRadius << endl;
*aFStream << myisArc << endl;
if (myisArc)
*aFStream << myFirstAngle << ' ' << mySecondAngle << endl;
Graphic2d_Line::Save(aFStream);
}
void Graphic2d_Circle::Retrieve(Aspect_IFStream& anIFStream,
const Handle(Graphic2d_GraphicObject)& aGraphicObject)
{
Quantity_Length X, Y, Rad;
Quantity_PlaneAngle Ang1, Ang2;
int isArc;
Handle(Graphic2d_Circle) theCir;
*anIFStream >> X >> Y;
*anIFStream >> Rad;
*anIFStream >> isArc;
if (isArc)
{
*anIFStream >> Ang1 >> Ang2;
theCir = new Graphic2d_Circle(aGraphicObject, X, Y, Rad, Ang1, Ang2);
}
else
theCir = new Graphic2d_Circle(aGraphicObject, X, Y, Rad);
((Handle (Graphic2d_Line))theCir)->Retrieve(anIFStream);
}
|