0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / Graphic2d / Graphic2d_Paragraph.cxx
CommitLineData
7fd59977 1/*=====================================================================
2
3 FONCTION :
4 ----------
5 Classe Graphic2d_Paragraph
6
7 TEST :
8 ------
9
10 Voir TestG2D/TestG21
11
7fd59977 12=====================================================================*/
13
14#define PRO12982 //GG_230498
81bba717 15// Take into account the underlining in calculation of
16// paragraph size.
7fd59977 17
18#define PRO11004 //GG_051197
81bba717 19// The contour of the paragraph is not rectangle
7fd59977 20
21#define PRO11005 //GG_131197
81bba717 22// Text can't be seen in mode Highlight.
7fd59977 23
24#define PRO11041 //GG_201197
81bba717 25// Modification of SetCurrentFont(...,aHScale,aWScale)
26// to parameterize the size of the text.
7fd59977 27
28#define PRO12320//GG_120297
81bba717 29// Compose texts depending on the summary height of the
30// chain of characters.
7fd59977 31
32#define PERF //GG_200898
33// The MinMax are now computed at the right time and no more
34// soon an attribute has change
35// (see the redefined method ComputeMinMax()).
36
37#include <Graphic2d_Paragraph.ixx>
38#include <Aspect_WindowDriver.hxx>
39#include <TShort_Array1OfShortReal.hxx>
40
41#include <Graphic2d_Primitive.pxx>
42
43#define MAXCOLUMN 16
44#define MAXROW 256
45#define MAXCOLOR 64
46#define MAXFONT 256
47#define MAXALIGNMENT 16
48#define MAXUNDERLINE 2
49#define TEXT_DESCRIPTOR(row,column,color,font,align,underline) \
50 ((column) | (row)*MAXCOLUMN | (color)*MAXCOLUMN*MAXROW | \
51 (font)*MAXCOLUMN*MAXROW*MAXCOLOR | \
52 (align)*MAXCOLUMN*MAXROW*MAXCOLOR*MAXFONT | \
53 (underline)*MAXCOLUMN*MAXROW*MAXCOLOR*MAXFONT*MAXALIGNMENT)
54#define TEXT_POSITION(descriptor) ((descriptor)&(MAXCOLUMN*MAXROW-1))
55#define TEXT_COLUMN(descriptor) ((descriptor)&(MAXCOLUMN-1))
56#define TEXT_ROW(descriptor) (((descriptor)/MAXCOLUMN)&(MAXROW-1))
57#define TEXT_COLOR(descriptor) (((descriptor)/(MAXCOLUMN*MAXROW))&(MAXCOLOR-1))
58#define TEXT_FONT(descriptor) (((descriptor)/(MAXCOLUMN*MAXROW*MAXCOLOR))&(MAXFONT-1))
59#define TEXT_ALIGNMENT(descriptor) (((descriptor)/(MAXCOLUMN*MAXROW*MAXCOLOR*MAXFONT))&(MAXALIGNMENT-1))
60#define TEXT_UNDERLINE(descriptor) (((descriptor)/(MAXCOLUMN*MAXROW*MAXCOLOR*MAXFONT*MAXALIGNMENT))&(MAXUNDERLINE-1))
61
62Graphic2d_Paragraph::Graphic2d_Paragraph
63 (const Handle(Graphic2d_GraphicObject)& aGraphicObject,
64 const Standard_Real X, const Standard_Real Y,
65 const Quantity_PlaneAngle anAngle,
66 const Aspect_CardinalPoints anOffset,
67 const Quantity_Factor aScale)
68 : Graphic2d_Primitive (aGraphicObject),
69 myX( Standard_ShortReal( X ) ),
70 myY( Standard_ShortReal( Y ) ),
71 myXoffset(0.),
72 myYoffset(0.),
73 myOffset(anOffset),
74 myWidth(0.),
75 myHeight(0.),
76 myAngle(Standard_ShortReal( anAngle )),
77 myScale(Standard_ShortReal( aScale )),
78 myTextStringList(),
79 myTextDescriptorList(),
80 myTextXpositionList(),
81 myTextYpositionList(),
82 myTextFheightList(),
83 myTextFoffsetList(),
84 myTextHScaleList(),
85 myTextWScaleList() {
86
c6541a0c
D
87 while (myAngle < 0.) myAngle += Standard_ShortReal( 2. * M_PI );
88 while (myAngle >= 2. * M_PI) myAngle -= Standard_ShortReal( 2. * M_PI );
7fd59977 89
90 SetZoomable() ;
91 SetSlant() ;
92 SetSpacing() ;
93 SetMargin() ;
94 SetFrameColorIndex() ;
95 SetFrameWidthIndex() ;
96 SetHidingColorIndex() ;
97 SetCurrentColorIndex() ;
98 SetCurrentFontIndex() ;
99 SetCurrentAlignment() ;
100 SetCurrentUnderline() ;
101}
102
103void Graphic2d_Paragraph::SetHidingColorIndex (const Standard_Integer anIndex)
104{
105
106 myHidingColorIndex = anIndex;
107
108}
109
110void Graphic2d_Paragraph::SetFrameColorIndex (const Standard_Integer anIndex) {
111
112 myFrameColorIndex = anIndex;
113
114}
115
116void Graphic2d_Paragraph::SetFrameWidthIndex (const Standard_Integer anIndex) {
117
118 myFrameWidthIndex = anIndex;
119
120}
121
122void Graphic2d_Paragraph::SetCurrentColorIndex (const Standard_Integer anIndex) {
123
124 myCurrentColorIndex = anIndex;
125
126}
127
128void Graphic2d_Paragraph::SetCurrentFontIndex (const Standard_Integer anIndex,const Quantity_Length aHScale,const Quantity_Length aWScale) {
129
130 myCurrentFontIndex = anIndex;
131 myCurrentFontHScale = (aHScale > 0.) ?
132 Standard_ShortReal( aHScale ) : Standard_ShortReal( 1. );
133 myCurrentFontWScale =
134 (aWScale > 0.) ? Standard_ShortReal( aWScale ) : myCurrentFontHScale;
135
136}
137
138void Graphic2d_Paragraph::SetCurrentAlignment (const Graphic2d_TypeOfAlignment anAlignment) {
139
140 myCurrentAlignment = anAlignment;
141}
142
143void Graphic2d_Paragraph::SetCurrentUnderline (const Standard_Boolean isUnderlined) {
144
145 myCurrentUnderline = isUnderlined;
146}
147
148void Graphic2d_Paragraph::SetSlant (const Quantity_PlaneAngle aSlant) {
149
150 mySlant = Standard_ShortReal( aSlant );
c6541a0c
D
151 while (mySlant < 0.) mySlant += Standard_ShortReal( 2. * M_PI );
152 while (mySlant >= 2. * M_PI) mySlant -= Standard_ShortReal( 2. * M_PI );
7fd59977 153}
154
155void Graphic2d_Paragraph::SetSpacing (const Quantity_Ratio aSpacing) {
156
157 mySpacing = Standard_ShortReal( aSpacing );
158#ifdef PERF
159 myMinX = myMinY = ShortRealLast ();
160 myMaxX = myMaxY = ShortRealFirst ();
161#else
162 Update();
163#endif
164}
165
166void Graphic2d_Paragraph::SetMargin (const Quantity_Length aMargin) {
167
168#ifdef PRO12982
169 myMargin = Standard_ShortReal( aMargin * myScale );
170#else
171 myMargin = Standard_ShortReal( aMargin );
172#endif
173#ifdef PERF
174 myMinX = myMinY = ShortRealLast ();
175 myMaxX = myMaxY = ShortRealFirst ();
176#else
177 Update();
178#endif
179}
180
181Standard_Boolean Graphic2d_Paragraph::IsZoomable () const {
182
183 return myIsZoomable;
184
185}
186
187void Graphic2d_Paragraph::SetZoomable (const Standard_Boolean aFlag) {
188
189 myIsZoomable = aFlag;
190#ifdef PERF
191 myMinX = myMinY = ShortRealLast ();
192 myMaxX = myMaxY = ShortRealFirst ();
193#else
194 Update();
195#endif
196}
197
198void Graphic2d_Paragraph::AddText (const TCollection_ExtendedString &aText,
199 const Standard_Integer aRow,
200 const Standard_Integer aColumn) {
201Standard_Integer i,length = myTextDescriptorList.Length() ;
202Standard_Integer row = (aRow > 0) ? Min(aRow,MAXROW-1) : MAXROW-1 ;
203Standard_Integer column = (aColumn > 0) ? Min(aColumn,MAXCOLUMN-1) : MAXCOLUMN-1 ;
204Standard_Integer descriptor = TEXT_DESCRIPTOR(row,column,myCurrentColorIndex,
205 myCurrentFontIndex,myCurrentAlignment,myCurrentUnderline) ;
206Standard_Integer the_position = TEXT_POSITION(descriptor) ;
207
208 for( i=1 ; i<=length ; i++ ) {
209 Standard_Integer cur_position =
210 TEXT_POSITION(myTextDescriptorList.Value(i)) ;
211 if( the_position == cur_position ) {
212 myTextDescriptorList.SetValue(i,descriptor) ;
213 myTextStringList.SetValue(i,aText) ;
214 myTextHScaleList.SetValue(i,myCurrentFontHScale);
215 myTextWScaleList.SetValue(i,myCurrentFontWScale);
216 return ;
217 }
218 if( the_position < cur_position ) break ;
219 }
220
221 if( i > length ) {
222 if( aRow <= 0 || aColumn <= 0 ) {
223 if( aRow <= 0 ) {
224 if( length > 0 ) {
225 row = TEXT_ROW(myTextDescriptorList.Value(length))+1 ;
226 row = Min(row,MAXROW-1) ;
227 } else {
228 row = 1 ;
229 }
230 }
231 if( aColumn <= 0 ) {
232 if( length > 0 ) {
233 if( row == TEXT_ROW(myTextDescriptorList.Value(length)) ) {
234 column = TEXT_COLUMN(myTextDescriptorList.Value(length))+1 ;
235 column = Min(column,MAXCOLUMN-1) ;
236 } else {
237 column = 1;
238 }
239 } else {
240 column = 1 ;
241 }
242 }
243 descriptor = TEXT_DESCRIPTOR(row,column,myCurrentColorIndex,
244 myCurrentFontIndex,myCurrentAlignment,myCurrentUnderline) ;
245 }
246 myTextDescriptorList.Append(descriptor) ;
247 myTextStringList.Append(aText) ;
248 myTextXpositionList.Append(0.) ;
249 myTextYpositionList.Append(0.) ;
250 myTextFheightList.Append(0.) ;
251 myTextFoffsetList.Append(0.) ;
252 myTextHScaleList.Append(myCurrentFontHScale) ;
253 myTextWScaleList.Append(myCurrentFontWScale) ;
254 } else {
255 if( aRow <= 0 || aColumn <= 0 ) {
256 if( aRow <= 0 ) {
257 if( i > 1 ) {
258 row = TEXT_ROW(myTextDescriptorList.Value(i-1))+1 ;
259 row = Min(row,MAXROW-1) ;
260 } else {
261 row = 1 ;
262 }
263 }
264 if( aColumn <= 0 ) {
265 if( i > 1 ) {
266 if( row == TEXT_ROW(myTextDescriptorList.Value(i-1)) ) {
267 column = TEXT_COLUMN(myTextDescriptorList.Value(i-1))+1 ;
268 column = Min(column,MAXCOLUMN-1) ;
269 } else {
270 column = 1;
271 }
272 } else {
273 column = 1 ;
274 }
275 }
276 descriptor = TEXT_DESCRIPTOR(row,column,myCurrentColorIndex,
277 myCurrentFontIndex,myCurrentAlignment,myCurrentUnderline) ;
278 }
279 myTextDescriptorList.InsertBefore(i,descriptor) ;
280 myTextStringList.InsertBefore(i,aText) ;
281 myTextXpositionList.InsertBefore(i,0.) ;
282 myTextYpositionList.InsertBefore(i,0.) ;
283 myTextFheightList.InsertBefore(i,0.) ;
284 myTextFoffsetList.InsertBefore(i,0.) ;
285 myTextHScaleList.InsertBefore(i,myCurrentFontHScale);
286 myTextWScaleList.InsertBefore(i,myCurrentFontWScale);
287 }
288#ifdef PERF
289 myMinX = myMinY = ShortRealLast ();
290 myMaxX = myMaxY = ShortRealFirst ();
291#else
292 Update();
293#endif
294
295}
296
297void Graphic2d_Paragraph::ChangeText (const TCollection_ExtendedString &aText,
298 const Standard_Integer aRow,
299 const Standard_Integer aColumn) {
300Standard_Integer i,length = myTextDescriptorList.Length() ;
6e6cd5d9 301
7fd59977 302Standard_Integer descriptor = TEXT_DESCRIPTOR(aRow,aColumn,0,0,0,0) ;
303Standard_Integer the_position = TEXT_POSITION(descriptor) ;
304
305 for( i=1 ; i<=length ; i++ ) {
306 Standard_Integer cur_position =
307 TEXT_POSITION(myTextDescriptorList.Value(i)) ;
308 if( the_position == cur_position ) {
309 myTextStringList.SetValue(i,aText) ;
310#ifdef PERF
311 myMinX = myMinY = ShortRealLast ();
312 myMaxX = myMaxY = ShortRealFirst ();
313#else
314 Update() ;
315#endif
316 return ;
317 }
318 }
319
320}
321
322void Graphic2d_Paragraph::Clear() {
323
324 myTextDescriptorList.Clear() ;
325 myTextStringList.Clear() ;
326 myTextXpositionList.Clear() ;
327 myTextYpositionList.Clear() ;
328 myTextFheightList.Clear() ;
329 myTextFoffsetList.Clear() ;
330 myTextHScaleList.Clear() ;
331 myTextWScaleList.Clear() ;
332#ifdef PERF
333 myMinX = myMinY = ShortRealLast ();
334 myMaxX = myMaxY = ShortRealFirst ();
335#else
336 Update();
337#endif
338}
339
340void Graphic2d_Paragraph::Draw (const Handle(Graphic2d_Drawer)& aDrawer) {
341//Standard_Integer descriptor,row = 0 ;
342Standard_Integer descriptor ;
343TCollection_ExtendedString atext ;
344Standard_ShortReal x = 0, y = 0, dx, dy,
345 sina = Standard_ShortReal( Sin(myAngle) ),
346 cosa = Standard_ShortReal( Cos(myAngle) );
347//Standard_Integer i,j,lrow,length = myTextDescriptorList.Length() ;
348Standard_Integer i,length = myTextDescriptorList.Length() ;
349Standard_Boolean IsIn = Standard_False;
350Standard_ShortReal hscale,wscale,scale = (myIsZoomable) ? myScale*aDrawer->Scale() : myScale;
351#ifdef PRO12982
352Standard_ShortReal rscale = 1.;
353#else
354Standard_ShortReal rscale = 1./myScale;
355#endif
356
357#ifdef PERF
358 if( (myMaxX < myMinX) || (myMaxY < myMinY) ) {
359 if( !ComputeMinMax() ) return;
360 }
361#else
362 if( myWidth <= 0. ) {
363 Update();
364 }
365#endif
366
367static TShort_Array1OfShortReal theXarray(1,5) ;
368static TShort_Array1OfShortReal theYarray(1,5) ;
369
370 // We have to draw frame without drawer's scaling
371 // because drawer's scale will betaken into consideration
372 // in MapPolylineFromTo(), MapPolygonFromTo().
373 // The same concerns test's position.
374 if (!myIsZoomable)
375 rscale = aDrawer->Scale();
376 if (! myGOPtr->IsTransformed ()) {
377 IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY);
378 if (IsIn) {
379 if( myFrameColorIndex > 0 || myHidingColorIndex >= 0 ) {
380 theXarray.SetValue(1,myX+XROTATE(myXoffset,myYoffset)/rscale) ;
381 theYarray.SetValue(1,myY+YROTATE(myXoffset,myYoffset)/rscale) ;
382 theXarray.SetValue(2,myX+XROTATE(myXoffset+myWidth,myYoffset)/rscale) ;
383 theYarray.SetValue(2,myY+YROTATE(myXoffset+myWidth,myYoffset)/rscale) ;
384 theXarray.SetValue(3,myX+XROTATE(myXoffset+myWidth,myYoffset-myHeight)/rscale) ;
385#ifdef PRO11004
386 theYarray.SetValue(3,myY+YROTATE(myXoffset+myWidth,myYoffset-myHeight)/rscale) ;
387#else
388 theYarray.SetValue(3,YROTATE(myXoffset+myWidth,myYoffset-myHeight)/rscale) ;
389#endif
390 theXarray.SetValue(4,myX+XROTATE(myXoffset,myYoffset-myHeight)/rscale) ;
391 theYarray.SetValue(4,myY+YROTATE(myXoffset,myYoffset-myHeight)/rscale) ;
392 theXarray.SetValue(5,myX+XROTATE(myXoffset,myYoffset)/rscale) ;
393 theYarray.SetValue(5,myY+YROTATE(myXoffset,myYoffset)/rscale) ;
394#ifdef PRO11005
395 if( myHidingColorIndex >= 0 ) {
396 aDrawer->SetHidingTextAttrib(-1,myHidingColorIndex,
397 myFrameColorIndex,myFrameWidthIndex,
398 -1,0.,1.,1.,Standard_False);
399 aDrawer->MapPolygonFromTo(theXarray, theYarray, 4);
400 } else {
401 aDrawer->SetFramedTextAttrib(-1,myFrameColorIndex,
402 myFrameWidthIndex,-1,0.,1.,1.,Standard_False);
403 aDrawer->MapPolylineFromTo(theXarray, theYarray, 5);
404 }
405#else
406 if( myHidingColorIndex >= 0 ) {
407 aDrawer->SetPolyAttrib(myHidingColorIndex,0,Standard_False) ;
408 aDrawer->MapPolygonFromTo(theXarray, theYarray, 4);
409 }
410 if( myFrameColorIndex > 0 ) {
411 aDrawer->SetLineAttrib(myFrameColorIndex,0,myFrameWidthIndex) ;
412 aDrawer->MapPolylineFromTo(theXarray, theYarray, 5);
413 }
414#endif
415 }
416 for( i=1 ; i<=length ; i++ ) {
417 descriptor = myTextDescriptorList.Value(i) ;
418 atext = myTextStringList.Value(i) ;
419 dx = myXoffset + myTextXpositionList.Value(i);
420 dy = myYoffset + myTextYpositionList.Value(i);
421 x = XROTATE(dx,dy)/rscale ; y = YROTATE(dx,dy)/rscale;
422 hscale = scale*myTextHScaleList.Value(i);
423 wscale = scale*myTextWScaleList.Value(i);
424 aDrawer->SetTextAttrib(TEXT_COLOR(descriptor),
425 TEXT_FONT(descriptor),mySlant,hscale,wscale,
426 TEXT_UNDERLINE(descriptor));
427 aDrawer->MapTextFromTo(atext,myX+x,myY+y,
428 myAngle,0.,0.,Aspect_TOT_SOLID);
429 }
430 }
431 } else {
432 gp_GTrsf2d aTrsf = myGOPtr->Transform ();
433 Standard_ShortReal minx,miny,maxx,maxy;
434 MinMax(minx,maxx,miny,maxy);
435 IsIn = aDrawer->IsIn (minx,maxx,miny,maxy);
436 if (IsIn) {
437 Standard_Real A = Standard_Real (myX);
438 Standard_Real B = Standard_Real (myY);
439 Standard_Real C = Standard_Real (myAngle);
440 Standard_Real cosa = Cos (C);
441 Standard_Real sina = Sin (C);
442
443 aTrsf.Transforms (A, B);
444
81bba717 445 // To calculate new aperture angles
446 // the calculation is done on trigonometric circle
447 // and in this case translation is not taken into account.
7fd59977 448 aTrsf.SetValue (1, 3, 0.0);
449 aTrsf.SetValue (2, 3, 0.0);
450 aTrsf.Transforms (cosa, sina);
451
452 Standard_ShortReal tscale = 1.;
453 Standard_ShortReal x0 = myXoffset;
454 Standard_ShortReal y0 = myYoffset;
455 Standard_ShortReal w = myWidth;
456 Standard_ShortReal h = myHeight;
457 C = atan2(sina,cosa);
458 Standard_ShortReal angle = Standard_ShortReal (C);
459 if ( myIsZoomable ) {
460 tscale = Standard_ShortReal( Sqrt(cosa*cosa + sina*sina) );
461 scale *= Standard_ShortReal( tscale );
462 x0 *= tscale; y0 *= tscale;
463 w *= tscale; h *= tscale;
464 }
465 cosa = Cos(C) ; sina = Sin(C) ;
466 if( myFrameColorIndex > 0 || myHidingColorIndex >= 0 ) {
467 dx = Standard_ShortReal( XROTATE(x0,y0)/rscale );
468 dy = Standard_ShortReal( YROTATE(x0,y0)/rscale );
469 theXarray.SetValue( 1, x + dx );
470 theYarray.SetValue( 1, y + dy );
471 dx = Standard_ShortReal( XROTATE(x0+w,y0)/rscale );
472 dy = Standard_ShortReal( YROTATE(x0+w,y0)/rscale );
473 theXarray.SetValue(2,x+dx) ; theYarray.SetValue(2,y+dy) ;
474 dx = Standard_ShortReal( XROTATE(x0+w,y0-h)/rscale );
475 dy = Standard_ShortReal( YROTATE(x0+w,y0-h)/rscale );
476 theXarray.SetValue(3,x+dx) ;
477 theYarray.SetValue(3,y+dy) ;
478 dx = Standard_ShortReal( XROTATE(x0,y0-h)/rscale );
479 dy = Standard_ShortReal( YROTATE(x0,y0-h)/rscale );
480 theXarray.SetValue(4,x+dx) ; theYarray.SetValue(4,y+dy) ;
481 dx = Standard_ShortReal( XROTATE(x0,y0)/rscale );
482 dy = Standard_ShortReal( YROTATE(x0,y0)/rscale );
483 theXarray.SetValue(5,x+dx) ; theYarray.SetValue(5,y+dy) ;
484#ifdef PRO11005
485 if( myHidingColorIndex >= 0 ) {
486 aDrawer->SetHidingTextAttrib(-1,myHidingColorIndex,
487 myFrameColorIndex,myFrameWidthIndex,
488 -1,0.,1.,1.,Standard_False);
489 aDrawer->MapPolygonFromTo(theXarray, theYarray, 4);
490 } else {
491 aDrawer->SetFramedTextAttrib(-1,myFrameColorIndex,
492 myFrameWidthIndex,-1,0.,1.,1.,Standard_False);
493 aDrawer->MapPolylineFromTo(theXarray, theYarray, 5);
494 }
495#else
496 if( myHidingColorIndex >= 0 ) {
497 aDrawer->SetPolyAttrib(myHidingColorIndex,0,Standard_False) ;
498 aDrawer->MapPolygonFromTo(theXarray, theYarray, 4);
499 }
500 if( myFrameColorIndex > 0 ) {
501 aDrawer->SetLineAttrib(myFrameColorIndex,0,myFrameWidthIndex) ;
502 aDrawer->MapPolylineFromTo(theXarray, theYarray, 5);
503 }
504#endif
505 }
506 Standard_ShortReal tx,ty;
507 for( i=1 ; i<=length ; i++ ) {
508 descriptor = myTextDescriptorList.Value(i) ;
509 atext = myTextStringList.Value(i) ;
510 dx = x0 + myTextXpositionList.Value(i)*tscale ;
511 dy = y0 + myTextYpositionList.Value(i)*tscale ;
512 tx = Standard_ShortReal( XROTATE(dx,dy)/rscale );
513 ty = Standard_ShortReal( YROTATE(dx,dy)/rscale );
514 hscale = scale*myTextHScaleList.Value(i) ;
515 wscale = scale*myTextWScaleList.Value(i) ;
516 aDrawer->SetTextAttrib(TEXT_COLOR(descriptor),
517 TEXT_FONT(descriptor),mySlant,hscale,wscale,
518 TEXT_UNDERLINE(descriptor));
519 aDrawer->MapTextFromTo(atext,x+tx,y+ty,
520 angle,0.,0.,Aspect_TOT_SOLID);
521 }
522 }
523 }
524}
525
526
527Standard_Boolean Graphic2d_Paragraph::Pick (const Standard_ShortReal X,
528 const Standard_ShortReal Y,
529 const Standard_ShortReal aPrecision,
530 const Handle(Graphic2d_Drawer)& aDrawer)
531{
532Standard_Boolean theStatus = Standard_False;
7fd59977 533Standard_ShortReal TX = X, TY = Y;
534
535 if (IsInMinMax (X, Y, aPrecision)) {
536 if (myGOPtr->IsTransformed ()) {
537 gp_GTrsf2d aTrsf = (myGOPtr->Transform ()).Inverted ();
538 Standard_Real RX = Standard_Real (X), RY = Standard_Real (Y);
539 aTrsf.Transforms (RX, RY);
540 TX = Standard_ShortReal (RX); TY = Standard_ShortReal (RY);
541 }
542
543 Standard_ShortReal cosa = Standard_ShortReal( Cos(-myAngle) );
544 Standard_ShortReal sina = Standard_ShortReal( Sin(-myAngle) );
545 Standard_ShortReal dx = TX-myX;
546 Standard_ShortReal dy = TY-myY;
547 Standard_ShortReal x = XROTATE(dx,dy);
548 Standard_ShortReal y = YROTATE(dx,dy);
549
550 theStatus = x >= myXoffset - aPrecision
551 && x <= myXoffset + myWidth + aPrecision
552 && y >= -myYoffset - aPrecision
553 && y <= myHeight -myYoffset + aPrecision;
554 }
555
556 return theStatus;
557}
558
559void Graphic2d_Paragraph::Size ( Quantity_Length &aWidth,
560 Quantity_Length &aHeight) const {
561 aWidth = myWidth;
562 aHeight = myHeight;
563
564}
565
566void Graphic2d_Paragraph::Position( Quantity_Length &X,
567 Quantity_Length &Y) const {
568
569 X = myX;
570 Y = myY;
571}
572
573Aspect_CardinalPoints Graphic2d_Paragraph::Offset( Quantity_Length &X,
574 Quantity_Length &Y) const {
575
576 X = myXoffset;
577 Y = myYoffset;
578
579 return myOffset;
580}
581
582Quantity_PlaneAngle Graphic2d_Paragraph::Angle() const {
583
584 return myAngle;
585}
586
587Quantity_PlaneAngle Graphic2d_Paragraph::Slant() const {
588
589 return mySlant;
590}
591
592Quantity_PlaneAngle Graphic2d_Paragraph::Spacing() const {
593
594 return mySpacing;
595}
596
597Quantity_PlaneAngle Graphic2d_Paragraph::Margin() const {
598
599 return myMargin;
600}
601
602Standard_Integer Graphic2d_Paragraph::HidingColorIndex() const {
603
604 return myHidingColorIndex;
605}
606
607Standard_Integer Graphic2d_Paragraph::FrameColorIndex() const {
608
609 return myFrameColorIndex;
610}
611
612Standard_Integer Graphic2d_Paragraph::FrameWidthIndex() const {
613
614 return myFrameWidthIndex;
615}
616
617TCollection_ExtendedString Graphic2d_Paragraph::Text(
618 const Standard_Integer aRank,
619 Standard_Integer &aRow,
620 Standard_Integer &aColumn,
621 Standard_Integer &aColorIndex,
622 Standard_Integer &aFontIndex,
623 Graphic2d_TypeOfAlignment &anAlignment) const {
624
625 if( aRank <= 0 || aRank > myTextDescriptorList.Length() ) {
626 Standard_OutOfRange::Raise ("Bad Text rank");
627 }
628
629 Standard_Integer descriptor = myTextDescriptorList.Value(aRank) ;
630 aRow = TEXT_ROW(descriptor) ;
631 aColumn = TEXT_COLUMN(descriptor) ;
632 aColorIndex = TEXT_COLOR(descriptor) ;
633 aFontIndex = TEXT_FONT(descriptor) ;
634 anAlignment = Graphic2d_TypeOfAlignment(TEXT_ALIGNMENT(descriptor)) ;
635
636 return myTextStringList.Value(aRank) ;
637}
638
639Standard_Boolean Graphic2d_Paragraph::TextSize ( const Standard_Integer aRank,
640 Quantity_Length &aWidth, Quantity_Length &aHeight,
641 Quantity_Length &anXoffset, Quantity_Length &anYoffset) const {
642 Handle(Graphic2d_Drawer) aDrawer = Drawer();
643
644 if( aRank <= 0 || aRank > myTextDescriptorList.Length() ) {
645 Standard_OutOfRange::Raise ("Bad Text rank");
646 }
647
648 if( !aDrawer.IsNull() && aDrawer->IsWindowDriver() ) {
649 Standard_Integer descriptor = myTextDescriptorList.Value(aRank) ;
650 Standard_ShortReal wscale,hscale,scale = (myIsZoomable) ?
651 myScale * aDrawer->Scale() : myScale;
652 Standard_ShortReal width,height,xoffset,yoffset;
653 TCollection_ExtendedString atext = myTextStringList.Value(aRank) ;
654 hscale = scale*myTextHScaleList.Value(aRank);
655 wscale = scale*myTextWScaleList.Value(aRank);
656 aDrawer->SetTextAttrib(TEXT_COLOR(descriptor),TEXT_FONT(descriptor),
657 mySlant,hscale,wscale,TEXT_UNDERLINE(descriptor));
658
659 aDrawer->GetTextSize(atext,width,height,xoffset,yoffset);
660 aWidth = width;
661 aHeight = height;
662 anXoffset = xoffset;
663 anYoffset = yoffset;
664 return Standard_True;
665 } else {
666 aWidth = aHeight = anXoffset = anYoffset = 0.;
667 return Standard_False;
668 }
669
670}
671
672Standard_Integer Graphic2d_Paragraph::Length() const {
673
674 return myTextStringList.Length();
675}
676
677Standard_Integer Graphic2d_Paragraph::MaxRow() const {
678Standard_Integer descriptor,i,n;
679
680 for( i=1,n=0 ; i<=myTextDescriptorList.Length() ; i++ ) {
681 descriptor = myTextDescriptorList.Value(i) ;
682 n = Max(n,TEXT_ROW(descriptor)) ;
683 }
684
685 return n;
686}
687
688Standard_Integer Graphic2d_Paragraph::MaxColumn() const {
689Standard_Integer descriptor,i,n;
690
691 for( i=1,n=0 ; i<=myTextDescriptorList.Length() ; i++ ) {
692 descriptor = myTextDescriptorList.Value(i) ;
693 n = Max(n,TEXT_COLUMN(descriptor)) ;
694 }
695
696 return n;
697}
698
699#ifdef PERF
700Standard_Boolean Graphic2d_Paragraph::ComputeMinMax() {
701#else
702void Graphic2d_Paragraph::Update() {
703#endif
704Handle(Graphic2d_Drawer) aDrawer = Drawer();
705Standard_Boolean status = Standard_False;
706
707 if( !aDrawer.IsNull() && aDrawer->IsWindowDriver() ) {
708 Standard_ShortReal rscale = 1.;
709 if (!myIsZoomable)
710 rscale = aDrawer->Scale();
711
712 Standard_Integer descriptor,row = 0 ;
713 TCollection_ExtendedString atext ;
714 Standard_ShortReal x, y, dx, dy,
715 sina = Standard_ShortReal( Sin(myAngle) ),
716 cosa = Standard_ShortReal( Cos(myAngle) );
717 Standard_Integer i,j,lrow,length = myTextDescriptorList.Length() ;
718 Standard_ShortReal hscale,wscale,scale =
719 (myIsZoomable) ? myScale*aDrawer->Scale() : myScale;
720 Standard_ShortReal twidth = 0.,theight = 0.,txoffset = 0.,tyoffset = 0.;
721 Standard_ShortReal lwidth = 0.,lheight = 0.,loffset = 0.;
722 myWidth = myHeight = 0. ;
81bba717 723 for( i=1,j=lrow=0 ; i<=length ; i++ ) { // Passe 1, gets texts minmax
7fd59977 724 descriptor = myTextDescriptorList.Value(i) ;
725 atext = myTextStringList.Value(i) ;
726 hscale = scale*myTextHScaleList.Value(i) ;
727 wscale = scale*myTextWScaleList.Value(i) ;
728 aDrawer->SetTextAttrib(TEXT_COLOR(descriptor),
729 TEXT_FONT(descriptor),mySlant,hscale,wscale,
730 TEXT_UNDERLINE(descriptor));
731 if( aDrawer->GetTextSize(atext,twidth,theight,txoffset,tyoffset) ) {
732#ifdef PRO12320
733 static TCollection_ExtendedString hletter("Hp");
734 Standard_ShortReal hwidth,hheight,hxoffset,hyoffset;
735 if(( status = aDrawer->GetTextSize(hletter,hwidth,hheight,
736 hxoffset,hyoffset) )) {
737 theight = Max(hheight-hyoffset,theight-tyoffset);
738 tyoffset = Max(hyoffset,tyoffset);
739 }
740#else
741 Standard_ShortReal fheight,fbheight,fslant;
742 aDrawer->GetFontSize(fheight,fbheight,fslant);
743 theight = fheight + fbheight; tyoffset = 0.;
744#endif //PRO12320
745 twidth += txoffset;
746 myTextXpositionList.SetValue(i,twidth) ;
747 if( row == TEXT_ROW(descriptor) ) {
748 lwidth += twidth ; lheight = Max(lheight,theight) ;
749 loffset = Max(loffset,tyoffset);
750 } else {
751 if( j > 0 ) {
752 if( j > 1 ) lheight += mySpacing*lheight*(row-lrow) ;
753#ifndef PRO12982
754 lheight -= loffset;
755#endif
756 myTextYpositionList.SetValue(j,lheight) ;
757 myWidth = Max(myWidth,lwidth) ;
758 myHeight += lheight ;
759 }
760 lwidth = twidth ; lheight = theight ; loffset = tyoffset;
761 lrow = row ; row = TEXT_ROW(descriptor) ; j = i ;
762 }
763 }
764 }
765
766 if( j > 0 ) {
767 if( j > 1 ) lheight += mySpacing*lheight*(row-lrow) ;
768#ifndef PRO12982
769 lheight -= loffset;
770#endif
771 myTextYpositionList.SetValue(j,lheight) ;
772 myWidth = Max(myWidth,lwidth) ;
773 myHeight += lheight ;
774#ifdef PRO12982
775 myHeight += loffset;
776#endif
777 }
778 myWidth += Standard_ShortReal( 2.*myMargin );
779 myHeight += Standard_ShortReal( 2.*myMargin );
780
781 x = myMargin ;
782 y = -myMargin ;
783 row = 0 ;
784 for( i=1 ; i<=length ; i++ ) { // Passe 2,sets texts position
785 descriptor = myTextDescriptorList.Value(i) ;
786 twidth = myTextXpositionList.Value(i) ;
787 if( row != TEXT_ROW(descriptor) ) {
788 theight = myTextYpositionList.Value(i) ;
789 x = myMargin ; y -= theight ;
790 row = TEXT_ROW(descriptor) ;
791 }
792 switch (TEXT_ALIGNMENT(descriptor)) {
793 case Graphic2d_TOA_TOPLEFT:
794 case Graphic2d_TOA_MEDIUMLEFT:
795 case Graphic2d_TOA_BOTTOMLEFT:
796 case Graphic2d_TOA_LEFT:
797 break ;
798 case Graphic2d_TOA_TOPCENTER:
799 case Graphic2d_TOA_MEDIUMCENTER:
800 case Graphic2d_TOA_BOTTOMCENTER:
801 case Graphic2d_TOA_CENTER:
802 x = Standard_ShortReal( (myWidth-twidth)/2. );
803 break ;
804 case Graphic2d_TOA_TOPRIGHT:
805 case Graphic2d_TOA_MEDIUMRIGHT:
806 case Graphic2d_TOA_BOTTOMRIGHT:
807 case Graphic2d_TOA_RIGHT:
808 x = myWidth-twidth-myMargin ;
809 break ;
810 }
811 myTextXpositionList.SetValue(i,x*rscale) ;
812 myTextYpositionList.SetValue(i,y*rscale) ;
813 x += twidth ;
814 }
815
816 switch (myOffset) {
817 case Aspect_CP_North:
818 myXoffset = Standard_ShortReal( -myWidth/2. ); myYoffset = 0. ;
819 break ;
820 case Aspect_CP_NorthEast:
821 myXoffset = -myWidth ; myYoffset = 0. ;
822 break ;
823 case Aspect_CP_East:
824 myXoffset = -myWidth ; myYoffset = Standard_ShortReal( myHeight/2. );
825 break ;
826 case Aspect_CP_SouthEast:
827 myXoffset = -myWidth ; myYoffset = myHeight ;
828 break ;
829 case Aspect_CP_South:
830 myXoffset = Standard_ShortReal( -myWidth/2. ); myYoffset = myHeight ;
831 break ;
832 case Aspect_CP_SouthWest:
833 myXoffset = 0. ; myYoffset = myHeight ;
834 break ;
835 case Aspect_CP_West:
836 myXoffset = 0.; myYoffset = Standard_ShortReal( myHeight/2. );
837 break ;
838 case Aspect_CP_NorthWest:
839 myXoffset = 0. ; myYoffset = 0. ;
840 break ;
841 case Aspect_CP_Center:
842 myXoffset = Standard_ShortReal( -myWidth/2. );
843 myYoffset = Standard_ShortReal( myHeight/2. );
844 }
845
846 myMinX = myMinY = ShortRealLast();
847 myMaxX = myMaxY = ShortRealFirst();
848
849 dx = XROTATE(myXoffset,myYoffset) ;
850 dy = YROTATE(myXoffset,myYoffset) ;
851 myMinX = Min(myMinX,myX+dx) ;
852 myMinY = Min(myMinY,myY+dy) ;
853 myMaxX = Max(myMaxX,myX+dx) ;
854 myMaxY = Max(myMaxY,myY+dy) ;
855
856 dx = XROTATE(myWidth+myXoffset,myYoffset) ;
857 dy = YROTATE(myWidth+myXoffset,myYoffset) ;
858 myMinX = Min(myMinX,myX+dx) ;
859 myMinY = Min(myMinY,myY+dy) ;
860 myMaxX = Max(myMaxX,myX+dx) ;
861 myMaxY = Max(myMaxY,myY+dy) ;
862
863 dx = XROTATE(myWidth+myXoffset,-myHeight+myYoffset) ;
864 dy = YROTATE(myWidth+myXoffset,-myHeight+myYoffset) ;
865 myMinX = Min(myMinX,myX+dx) ;
866 myMinY = Min(myMinY,myY+dy) ;
867 myMaxX = Max(myMaxX,myX+dx) ;
868 myMaxY = Max(myMaxY,myY+dy) ;
869
870 dx = XROTATE(myXoffset,-myHeight+myYoffset) ;
871 dy = YROTATE(myXoffset,-myHeight+myYoffset) ;
872 myMinX = Min(myMinX,myX+dx) ;
873 myMinY = Min(myMinY,myY+dy) ;
874 myMaxX = Max(myMaxX,myX+dx) ;
875 myMaxY = Max(myMaxY,myY+dy) ;
876
877 myXoffset *= rscale;
878 myYoffset *= rscale;
879 myWidth *= rscale;
880 myHeight *= rscale;
881 }
882#ifdef PERF
883 else {
884 cout << "*Graphic2d_Paragraph::ComputeMinMax() returns wrong values*" << endl;
885 }
886
887 return status;
888#endif
889
890
891}
892
893void Graphic2d_Paragraph::Save(Aspect_FStream& aFStream) const
894{
895}