2 // les methodes qui "tirent" GEOMLIGHT disparaissent
4 // Reinitialiser les parametres de vue dans tous les cas
5 // PRO14041 //GG_150698
6 // Reinitialiser la taille de la zone visualisable dans tous
9 #define G002 //GG 28/04/00 Add protection on MinMax() methods
10 // Add perf improvment when the used transient
11 // 05/05/00 inherits from the current drawer.
12 // Add DrawElement() DrawVertex() methods.
14 #define OCC402 // SAV 14/11/01 Added DrawPickedElements() - highlights picked elements.
16 #include <Graphic2d_TransientManager.ixx>
17 #include <Graphic2d_Drawer.hxx>
18 #include <Graphic2d_DisplayList.hxx>
19 #include <TShort_Array1OfShortReal.hxx>
20 #include <Aspect_Window.hxx>
21 #include <Graphic2d_Primitive.pxx>
22 #include <gp_Pnt2d.hxx>
24 #include <Graphic2d_View.hxx>
26 #define MAXPOINTS 1024
27 #define MAXSEGMENTS 1024
29 Graphic2d_TransientManager::Graphic2d_TransientManager (
30 const Handle(Graphic2d_View)& aView) :
31 myPView(aView.operator->()),
32 myTrsf(),myCompositeTrsf(),
33 myTypeOfComposition(Graphic2d_TOC_REPLACE),
34 myDrawingIsStarted(Standard_False),
35 myTrsfIsDefined(Standard_False),
36 myMappingIsEnable(Standard_True),
37 myTypeOfPrimitive(Aspect_TOP_UNKNOWN)
41 Graphic2d_TransientManager::Graphic2d_TransientManager (
42 const Graphic2d_ViewPtr& aView) :
44 myTrsf(),myCompositeTrsf(),
45 myTypeOfComposition(Graphic2d_TOC_REPLACE),
46 myDrawingIsStarted(Standard_False),
47 myTrsfIsDefined(Standard_False),
48 myMappingIsEnable(Standard_True),
49 myTypeOfPrimitive(Aspect_TOP_UNKNOWN)
53 //=======================================================================
54 Standard_Boolean Graphic2d_TransientManager::BeginDraw(
55 const Handle(Aspect_WindowDriver)& aDriver,
56 const Standard_Boolean ClearBefore) {
57 Standard_Boolean status = Standard_True;
58 Standard_Boolean reset_minmax = Standard_True;
60 if( myDrawingIsStarted ) return Standard_False;
62 if( myDriver == aDriver ) {
64 status = RestoreArea(aDriver);
65 } else reset_minmax = Standard_False;
69 Handle(Graphic2d_Drawer) theDrawer = myPView->Drawer();
70 Handle(Graphic2d_Drawer) theDrawer1 = this;
71 if ( theDrawer1 != theDrawer )
74 Standard_ShortReal XF, YF, SF, XT, YT, ST, ZF;
75 theDrawer->Values(XF, YF, SF, XT, YT, ST, ZF);
76 Graphic2d_Drawer::SetValues(XF, YF, SF, XT, YT, ST, ZF);
78 Standard_ShortReal DP, DC;
79 Aspect_TypeOfDeflection TD;
81 theDrawer->DrawPrecision(DP,DC,TD);
82 Graphic2d_Drawer::SetDrawPrecision(DP,DC,TD);
84 Standard_ShortReal TP = theDrawer->TextPrecision();
85 Graphic2d_Drawer::SetTextPrecision(TP);
88 Graphic2d_Drawer::SetDriver(aDriver);
91 aDriver->BeginDraw(Standard_False,0);
93 this->EnableMinMax(Standard_True,reset_minmax);
95 myDrawingIsStarted = Standard_True;
96 myTrsfIsDefined = Standard_False;
97 myTypeOfPrimitive = Aspect_TOP_UNKNOWN;
102 //=======================================================================
103 Standard_Boolean Graphic2d_TransientManager::BeginDraw(
104 const Handle(Aspect_WindowDriver)& aDriver,
105 const Handle(Graphic2d_ViewMapping)& aViewMapping,
106 const Standard_Real aXPosition,
107 const Standard_Real aYPosition,
108 const Standard_Real aScale,
109 const Standard_Boolean ClearBefore) {
110 Standard_Boolean status = Standard_True;
111 Standard_Boolean reset_minmax = Standard_True;
113 if( myDrawingIsStarted ) return Standard_False;
115 if( myDriver == aDriver ) {
117 status = RestoreArea(aDriver);
118 } else reset_minmax = Standard_False;
120 Graphic2d_Drawer::SetDriver(aDriver);
122 // Set new drawer attributes
124 Handle(Graphic2d_Drawer) theDrawer = myPView->Drawer();
125 Handle(Graphic2d_Drawer) theDrawer1 = this;
126 if( theDrawer1 != theDrawer )
129 Standard_Real XCenter, YCenter, Size;
131 aViewMapping->ViewMapping(XCenter, YCenter, Size);
132 Graphic2d_Drawer::SetValues (XCenter, YCenter, Size,
133 aXPosition, aYPosition, aScale, aViewMapping->Zoom());
134 Standard_ShortReal DP, DC;
135 Aspect_TypeOfDeflection TD;
137 theDrawer->DrawPrecision(DP,DC,TD);
138 Graphic2d_Drawer::SetDrawPrecision(DP,DC,TD);
140 Standard_ShortReal TP = theDrawer->TextPrecision();
141 Graphic2d_Drawer::SetTextPrecision(TP);
143 // Begin new graphics
144 aDriver->BeginDraw(Standard_False,0);
146 this->EnableMinMax(Standard_True,reset_minmax);
148 myDrawingIsStarted = Standard_True;
149 myTrsfIsDefined = Standard_False;
150 myTypeOfPrimitive = Aspect_TOP_UNKNOWN;
155 //=======================================================================
156 void Graphic2d_TransientManager::EndDraw(const Standard_Boolean Synchronize) {
158 if( myDrawingIsStarted ) {
159 myDriver->EndDraw(Synchronize) ;
160 myDrawingIsStarted = Standard_False;
161 this->EnableMinMax(Standard_False,Standard_False);
165 //=======================================================================
166 Standard_Boolean Graphic2d_TransientManager::Restore(
167 const Handle(Aspect_WindowDriver)& aDriver) {
168 Standard_Boolean status = Standard_True;
170 if(( status = aDriver->Window()->BackingStore() )) {
171 // Restore the front view from the back
172 aDriver->Window()->Restore();
173 } else { // Redraw the View
180 //=======================================================================
181 Standard_Boolean Graphic2d_TransientManager::RestoreArea(
182 const Handle(Aspect_WindowDriver)& aDriver) {
183 Standard_Integer pxmin,pymin,pxmax,pymax;
184 Standard_Boolean status = Standard_True;
186 if( this->MinMax(pxmin,pxmax,pymin,pymax) ) {
187 if(( status = aDriver->Window()->BackingStore() )) {
188 // Restore the front view area from the back
189 aDriver->Window()->RestoreArea((pxmin+pxmax)/2,(pymin+pymax)/2,
190 pxmax-pxmin+10,pymax-pymin+10);
191 } else { // Redraw the View
195 this->EnableMinMax(Standard_True,Standard_True);
202 //=======================================================================
203 void Graphic2d_TransientManager::Redraw(
204 const Handle(Aspect_WindowDriver)& aDriver) {
206 Handle(Graphic2d_DisplayList) theDisplayList = myPView->DisplayList();
207 Handle(Graphic2d_GraphicObject) theGraphicObject;
208 Handle(Graphic2d_Drawer) theDrawer = myPView->Drawer();
211 aDriver->BeginDraw(Standard_True);
212 aDriver->Window()->Clear();
213 for (i=1; i<=theDisplayList->Length(); i++) {
214 theGraphicObject = theDisplayList->Value(i);
215 theGraphicObject->Redraw (theDrawer);
220 //=======================================================================
221 void Graphic2d_TransientManager::Destroy () {
224 //=======================================================================
225 void Graphic2d_TransientManager::Draw (
226 const Handle(Graphic2d_Primitive) &aPrimitive) {
228 Graphic2d_TransientDefinitionError_Raise_if (
229 !myDrawingIsStarted,"Drawing must be started before");
231 Graphic2d_TransientDefinitionError_Raise_if (
232 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
234 if( myTrsfIsDefined ) {
235 Handle(Graphic2d_GraphicObject) theGO =
236 aPrimitive->PGraphicObject();
237 gp_GTrsf2d theOldTrsf = theGO->Transform();
238 if( theGO->IsTransformed() && // Sets the new transformation
239 (myTypeOfComposition != Graphic2d_TOC_REPLACE) ) {
240 gp_GTrsf2d theNewTrsf = myCompositeTrsf.Multiplied(theOldTrsf);
241 theGO->SetTransform(theNewTrsf);
243 theGO->SetTransform(myTrsf);
245 aPrimitive->Draw(this);
246 theGO->SetTransform(theOldTrsf); // Restore the old
248 aPrimitive->Draw(this);
252 //=======================================================================
253 void Graphic2d_TransientManager::Draw (
254 const Handle(Graphic2d_GraphicObject) &aGraphicObject) {
256 Graphic2d_TransientDefinitionError_Raise_if (
257 !myDrawingIsStarted,"Drawing must be started before");
259 Graphic2d_TransientDefinitionError_Raise_if (
260 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
262 if( myTrsfIsDefined ) {
263 gp_GTrsf2d theOldTrsf = aGraphicObject->Transform();
264 if( aGraphicObject->IsTransformed() && // Sets the new transformation
265 (myTypeOfComposition != Graphic2d_TOC_REPLACE) ) {
266 gp_GTrsf2d theNewTrsf = myCompositeTrsf.Multiplied(theOldTrsf);
267 aGraphicObject->SetTransform(theNewTrsf);
269 aGraphicObject->SetTransform(myTrsf);
271 aGraphicObject->Redraw(this);
272 aGraphicObject->SetTransform(theOldTrsf); // Restore the old
274 aGraphicObject->Redraw(this);
279 //=======================================================================
280 void Graphic2d_TransientManager::DrawElement (
281 const Handle(Graphic2d_Primitive) &aPrimitive,
282 const Standard_Integer anIndex) {
284 Graphic2d_TransientDefinitionError_Raise_if (
285 !myDrawingIsStarted,"Drawing must be started before");
287 Graphic2d_TransientDefinitionError_Raise_if (
288 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
290 if( myTrsfIsDefined ) {
291 Handle(Graphic2d_GraphicObject) theGO =
292 aPrimitive->PGraphicObject();
293 gp_GTrsf2d theOldTrsf = theGO->Transform();
294 if( theGO->IsTransformed() && // Sets the new transformation
295 (myTypeOfComposition != Graphic2d_TOC_REPLACE) ) {
296 gp_GTrsf2d theNewTrsf = myCompositeTrsf.Multiplied(theOldTrsf);
297 theGO->SetTransform(theNewTrsf);
299 theGO->SetTransform(myTrsf);
301 aPrimitive->DrawElement(this,anIndex);
302 theGO->SetTransform(theOldTrsf); // Restore the old
304 aPrimitive->DrawElement(this,anIndex);
310 //=======================================================================
311 void Graphic2d_TransientManager
312 ::DrawPickedElements( const Handle(Graphic2d_Primitive) &aPrimitive )
315 Graphic2d_TransientDefinitionError_Raise_if(
316 !myDrawingIsStarted,"Drawing must be started before" );
318 Graphic2d_TransientDefinitionError_Raise_if(
319 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
321 if( myTrsfIsDefined ) {
322 Handle(Graphic2d_GraphicObject) theGO =
323 aPrimitive->PGraphicObject();
324 gp_GTrsf2d theOldTrsf = theGO->Transform();
325 if( theGO->IsTransformed() && // Sets the new transformation
326 (myTypeOfComposition != Graphic2d_TOC_REPLACE) ) {
327 gp_GTrsf2d theNewTrsf = myCompositeTrsf.Multiplied(theOldTrsf);
328 theGO->SetTransform(theNewTrsf);
330 theGO->SetTransform(myTrsf);
332 aPrimitive->DrawPickedElements( this );
333 theGO->SetTransform(theOldTrsf); // Restore the old
335 aPrimitive->DrawPickedElements( this );
340 //=======================================================================
341 void Graphic2d_TransientManager::DrawVertex (
342 const Handle(Graphic2d_Primitive) &aPrimitive,
343 const Standard_Integer anIndex) {
345 Graphic2d_TransientDefinitionError_Raise_if (
346 !myDrawingIsStarted,"Drawing must be started before");
348 Graphic2d_TransientDefinitionError_Raise_if (
349 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
351 if( myTrsfIsDefined ) {
352 Handle(Graphic2d_GraphicObject) theGO =
353 aPrimitive->PGraphicObject();
354 gp_GTrsf2d theOldTrsf = theGO->Transform();
355 if( theGO->IsTransformed() && // Sets the new transformation
356 (myTypeOfComposition != Graphic2d_TOC_REPLACE) ) {
357 gp_GTrsf2d theNewTrsf = myCompositeTrsf.Multiplied(theOldTrsf);
358 theGO->SetTransform(theNewTrsf);
360 theGO->SetTransform(myTrsf);
362 aPrimitive->DrawVertex(this,anIndex);
363 theGO->SetTransform(theOldTrsf); // Restore the old
365 aPrimitive->DrawVertex(this,anIndex);
370 //=======================================================================
371 void Graphic2d_TransientManager::BeginPrimitive (
372 const Aspect_TypeOfPrimitive aType,
373 const Standard_Integer aSize) {
375 Graphic2d_TransientDefinitionError_Raise_if (
376 !myDrawingIsStarted,"Drawing must be started before");
378 Graphic2d_TransientDefinitionError_Raise_if (
379 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"A primitive is already open");
380 myTypeOfPrimitive = aType;
382 switch (myTypeOfPrimitive) {
383 case Aspect_TOP_UNKNOWN:
385 case Aspect_TOP_POLYLINE:
386 myDriver->BeginPolyline((aSize > 0) ? aSize : MAXPOINTS);
388 case Aspect_TOP_POLYGON:
389 myDriver->BeginPolygon((aSize > 0) ? aSize : MAXPOINTS);
391 case Aspect_TOP_SEGMENTS:
392 myDriver->BeginSegments();
394 case Aspect_TOP_ARCS:
395 myDriver->BeginArcs();
397 case Aspect_TOP_POLYARCS:
398 myDriver->BeginPolyArcs();
400 case Aspect_TOP_POINTS:
401 myDriver->BeginPoints();
403 case Aspect_TOP_MARKERS:
404 myDriver->BeginMarkers();
409 //=======================================================================
410 void Graphic2d_TransientManager::ClosePrimitive () {
412 Graphic2d_TransientDefinitionError_Raise_if (
413 !myDrawingIsStarted,"Drawing must be started before");
415 Graphic2d_TransientDefinitionError_Raise_if (
416 (myTypeOfPrimitive == Aspect_TOP_UNKNOWN),"A primitive is not open");
417 myDriver->ClosePrimitive();
419 myTypeOfPrimitive = Aspect_TOP_UNKNOWN;
422 //=======================================================================
423 void Graphic2d_TransientManager::DrawSegment (
424 const Standard_Real X1,
425 const Standard_Real Y1,
426 const Standard_Real X2,
427 const Standard_Real Y2) {
429 Graphic2d_TransientDefinitionError_Raise_if (
430 !myDrawingIsStarted,"Drawing must be started before");
432 Graphic2d_TransientDefinitionError_Raise_if (
433 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN) &&
434 (myTypeOfPrimitive != Aspect_TOP_SEGMENTS),"Bad primitive type");
436 Standard_ShortReal x1 = Standard_ShortReal(X1),
437 y1 = Standard_ShortReal(Y1),
438 x2 = Standard_ShortReal(X2),
439 y2 = Standard_ShortReal(Y2);
440 if( myTrsfIsDefined ) {
441 Standard_Real U = x1, V = y1;
442 myTrsf.Transforms(U,V);
443 x1 = Standard_ShortReal(U); y1 = Standard_ShortReal(V);
445 myTrsf.Transforms(U,V);
446 x2 = Standard_ShortReal(U); y2 = Standard_ShortReal(V);
448 if( myMappingIsEnable )
449 Graphic2d_Drawer::MapSegmentFromTo(x1,y1,x2,y2);
451 Graphic2d_Drawer::DrawSegment(x1,y1,x2,y2);
455 //=======================================================================
456 void Graphic2d_TransientManager::DrawInfiniteLine (
457 const Standard_Real X,
458 const Standard_Real Y,
459 const Standard_Real Dx,
460 const Standard_Real Dy) {
462 Graphic2d_TransientDefinitionError_Raise_if (
463 !myDrawingIsStarted,"Drawing must be started before");
465 Graphic2d_TransientDefinitionError_Raise_if (
466 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
468 Standard_ShortReal x = Standard_ShortReal(X),
469 y = Standard_ShortReal(Y),
470 dx = Standard_ShortReal(Dx),
471 dy = Standard_ShortReal(Dy);
472 if( myTrsfIsDefined ) {
473 Standard_Real U = x,V = y;
474 myTrsf.Transforms(U,V);
475 x = Standard_ShortReal(U); y = Standard_ShortReal(V);
477 myTrsf.Transforms(U,V);
478 dx = Standard_ShortReal(U) - x; dy = Standard_ShortReal(V) - y;
480 if( myMappingIsEnable )
481 Graphic2d_Drawer::MapInfiniteLineFromTo(x,y,dx,dy);
483 Graphic2d_Drawer::DrawInfiniteLine(x,y,dx,dy);
486 //=======================================================================
487 void Graphic2d_TransientManager::DrawArc(
488 const Standard_Real Xc,
489 const Standard_Real Yc,
490 const Standard_Real aRadius,
491 const Standard_Real Angle1,
492 const Standard_Real Angle2) {
494 Graphic2d_TransientDefinitionError_Raise_if (
495 !myDrawingIsStarted,"Drawing must be started before");
497 Graphic2d_TransientDefinitionError_Raise_if (
498 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN) &&
499 (myTypeOfPrimitive != Aspect_TOP_ARCS),"Bad primitive type");
501 Standard_ShortReal xc = Standard_ShortReal(Xc),
502 yc = Standard_ShortReal(Yc),
503 r = Standard_ShortReal(aRadius),
504 a1 = Standard_ShortReal(Angle1),
505 a2 = Standard_ShortReal(Angle2);
506 if( myTrsfIsDefined ) {
507 Standard_Real U = xc,V = yc;
508 myTrsf.Transforms(U,V);
509 xc = Standard_ShortReal(U); yc = Standard_ShortReal(V);
510 U = r * Cos(a1); V = r * Sin(a1);
511 myTrsf.Transforms(U,V); U -= Standard_Real(xc); V -= Standard_Real(yc);
512 r = Standard_ShortReal(Sqrt( U*U + V*V )) ;
513 Standard_ShortReal a = Standard_ShortReal(atan2(U,V));
514 a2 += a - a1; a1 = a;
516 if( myMappingIsEnable )
517 Graphic2d_Drawer::MapArcFromTo(xc,yc,r,a1,a2);
519 Graphic2d_Drawer::DrawArc(xc,yc,r,a1,a2);
522 //=======================================================================
523 void Graphic2d_TransientManager::DrawPolyArc(
524 const Standard_Real Xc,
525 const Standard_Real Yc,
526 const Standard_Real aRadius,
527 const Standard_Real Angle1,
528 const Standard_Real Angle2) {
530 Graphic2d_TransientDefinitionError_Raise_if (
531 !myDrawingIsStarted,"Drawing must be started before");
533 Graphic2d_TransientDefinitionError_Raise_if (
534 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN) &&
535 (myTypeOfPrimitive != Aspect_TOP_POLYARCS),"Bad primitive type");
537 Standard_ShortReal xc = Standard_ShortReal(Xc),
538 yc = Standard_ShortReal(Yc),
539 r = Standard_ShortReal(aRadius),
540 a1 = Standard_ShortReal(Angle1),
541 a2 = Standard_ShortReal(Angle2);
542 if( myTrsfIsDefined ) {
543 Standard_Real U = xc,V = yc;
544 myTrsf.Transforms(U,V);
545 xc = Standard_ShortReal(U); yc = Standard_ShortReal(V);
546 U = r * Cos(a1); V = r * Sin(a1);
547 myTrsf.Transforms(U,V); U -= Standard_Real(xc); V -= Standard_Real(yc);
548 r = Standard_ShortReal(Sqrt( U*U + V*V )) ;
549 Standard_ShortReal a = Standard_ShortReal(atan2(U,V));
550 a2 += a - a1; a1 = a;
552 if( myMappingIsEnable )
553 Graphic2d_Drawer::MapPolyArcFromTo(xc,yc,r,a1,a2);
555 Graphic2d_Drawer::DrawPolyArc(xc,yc,r,a1,a2);
558 //=======================================================================
559 void Graphic2d_TransientManager::DrawPoint (
560 const Standard_Real X, const Standard_Real Y) {
562 Graphic2d_TransientDefinitionError_Raise_if (
563 !myDrawingIsStarted,"Drawing must be started before");
565 Graphic2d_TransientDefinitionError_Raise_if (
566 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN) &&
567 (myTypeOfPrimitive != Aspect_TOP_POLYLINE) &&
568 (myTypeOfPrimitive != Aspect_TOP_POLYGON) &&
569 (myTypeOfPrimitive != Aspect_TOP_MARKERS),"Bad primitive type");
571 Standard_ShortReal x = Standard_ShortReal(X), y = Standard_ShortReal(Y);
572 if( myTrsfIsDefined ) {
573 Standard_Real U = x,V = y;
574 myTrsf.Transforms(U,V);
575 x = Standard_ShortReal(U); y = Standard_ShortReal(V);
577 if( myMappingIsEnable )
578 Graphic2d_Drawer::MapMarkerFromTo(0,x,y,0.,0.,0.);
580 Graphic2d_Drawer::DrawMarker(0,x,y,0.,0.,0.);
583 //=======================================================================
584 void Graphic2d_TransientManager::DrawMarker(
585 const Standard_Integer anIndex,
586 const Standard_Real X,
587 const Standard_Real Y,
588 const Standard_Real aWidth,
589 const Standard_Real anHeight,
590 const Standard_Real anAngle) {
592 Graphic2d_TransientDefinitionError_Raise_if (
593 !myDrawingIsStarted,"Drawing must be started before");
595 Graphic2d_TransientDefinitionError_Raise_if (
596 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN) &&
597 (myTypeOfPrimitive != Aspect_TOP_MARKERS),"Bad primitive type");
599 Standard_ShortReal x = Standard_ShortReal(X),
600 y = Standard_ShortReal(Y),
601 w = Standard_ShortReal(aWidth),
602 h = Standard_ShortReal(anHeight),
603 a = Standard_ShortReal(anAngle);
604 if( myTrsfIsDefined ) {
605 Standard_Real U = x,V = y;
606 myTrsf.Transforms(U,V);
607 x = Standard_ShortReal(U); y = Standard_ShortReal(V);
609 if( myMappingIsEnable )
610 Graphic2d_Drawer::MapMarkerFromTo(anIndex,x,y,w,h,a);
612 Graphic2d_Drawer::DrawMarker(anIndex,x,y,w,h,a);
615 //=======================================================================
616 void Graphic2d_TransientManager::DrawText(
617 const TCollection_ExtendedString& aText,
618 const Standard_Real X,
619 const Standard_Real Y,
620 const Standard_Real anAngle,
621 const Standard_Real aDeltax,
622 const Standard_Real aDeltay,
623 const Aspect_TypeOfText aType,
624 const Graphic2d_TypeOfAlignment anAlignment) {
626 Graphic2d_TransientDefinitionError_Raise_if (
627 !myDrawingIsStarted,"Drawing must be started before");
629 Graphic2d_TransientDefinitionError_Raise_if (
630 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
632 Standard_ShortReal x = Standard_ShortReal(X),
633 y = Standard_ShortReal(Y),
634 a = Standard_ShortReal(anAngle);
635 Standard_ShortReal dx = Standard_ShortReal(0.),
636 dy = Standard_ShortReal(0.),
637 ox = Standard_ShortReal(aDeltax),
638 oy = Standard_ShortReal(aDeltay);
640 if( anAlignment != Graphic2d_TOA_LEFT ) {
641 Standard_ShortReal tw,th,txo,tyo;
642 if( Graphic2d_Drawer::GetTextSize(aText,tw,th,txo,tyo) ) {
643 switch( anAlignment ) {
644 case Graphic2d_TOA_LEFT:
645 dx = Standard_ShortReal(0.); dy = Standard_ShortReal(0.);
647 case Graphic2d_TOA_RIGHT:
650 case Graphic2d_TOA_CENTER:
651 dx = Standard_ShortReal(-tw/2.); dy = 0.;
653 case Graphic2d_TOA_TOPLEFT:
654 dx = 0.; dy = tyo-th;
656 case Graphic2d_TOA_TOPRIGHT:
657 dx = -tw; dy = tyo-th;
659 case Graphic2d_TOA_TOPCENTER:
660 dx = Standard_ShortReal(-tw/2.); dy = Standard_ShortReal(tyo-th);
662 case Graphic2d_TOA_MEDIUMLEFT:
663 dx = 0.; dy = Standard_ShortReal((tyo-th)/2.);
665 case Graphic2d_TOA_MEDIUMRIGHT:
666 dx = Standard_ShortReal(-tw); dy = Standard_ShortReal((tyo-th)/2.);
668 case Graphic2d_TOA_MEDIUMCENTER:
669 dx = Standard_ShortReal(-tw/2.); dy = Standard_ShortReal((tyo-th)/2.);
671 case Graphic2d_TOA_BOTTOMLEFT:
674 case Graphic2d_TOA_BOTTOMRIGHT:
677 case Graphic2d_TOA_BOTTOMCENTER:
678 dx = Standard_ShortReal(-tw/2.); dy = tyo;
684 if( myTrsfIsDefined ) {
685 Standard_Real U = x,V = y;
686 myTrsf.Transforms(U,V);
687 x = Standard_ShortReal(U); y = Standard_ShortReal(V);
688 U = Cos(a); V = Sin(a);
689 myTrsf.Transforms(U,V); U -= Standard_Real(x); V -= Standard_Real(y);
690 a = Standard_ShortReal(atan2(U,V));
693 Standard_ShortReal ax = dx, ay = dy;
694 Standard_Real cosa = Cos (a);
695 Standard_Real sina = Sin (a);
696 dx = Standard_ShortReal(XROTATE(ax,ay));
697 dy = Standard_ShortReal(YROTATE(ax,ay));
699 if( myMappingIsEnable )
700 Graphic2d_Drawer::MapTextFromTo(aText,x+dx,y+dy,a,ox,oy,aType);
702 Graphic2d_Drawer::DrawText(aText,x+ox+dx,y+oy+dy,a,aType);
705 //=======================================================================
706 void Graphic2d_TransientManager::DrawPolyText(
707 const TCollection_ExtendedString& aText,
708 const Standard_Real X,
709 const Standard_Real Y,
710 const Standard_Real anAngle,
711 const Standard_Real aMargin,
712 const Standard_Real aDeltax,
713 const Standard_Real aDeltay,
714 const Aspect_TypeOfText aType,
715 const Graphic2d_TypeOfAlignment anAlignment) {
717 Graphic2d_TransientDefinitionError_Raise_if (
718 !myDrawingIsStarted,"Drawing must be started before");
720 Graphic2d_TransientDefinitionError_Raise_if (
721 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
723 Standard_ShortReal x = Standard_ShortReal(X), y = Standard_ShortReal(Y),
724 a = Standard_ShortReal(anAngle), m = Standard_ShortReal(aMargin);
725 Standard_ShortReal dx = 0., dy = 0., ox = Standard_ShortReal(aDeltax), oy = Standard_ShortReal(aDeltay);
727 if( anAlignment != Graphic2d_TOA_LEFT ) {
728 Standard_ShortReal tw,th,txo,tyo;
729 if( Graphic2d_Drawer::GetTextSize(aText,tw,th,txo,tyo) ) {
730 switch( anAlignment ) {
731 case Graphic2d_TOA_LEFT:
734 case Graphic2d_TOA_RIGHT:
737 case Graphic2d_TOA_CENTER:
738 dx = Standard_ShortReal(-tw/2.); dy = 0.;
740 case Graphic2d_TOA_TOPLEFT:
741 dx = 0.; dy = tyo-th;
743 case Graphic2d_TOA_TOPRIGHT:
744 dx = -tw; dy = tyo-th;
746 case Graphic2d_TOA_TOPCENTER:
747 dx = Standard_ShortReal(-tw/2.); dy = tyo-th;
749 case Graphic2d_TOA_MEDIUMLEFT:
750 dx = 0.; dy = Standard_ShortReal((tyo-th)/2.);
752 case Graphic2d_TOA_MEDIUMRIGHT:
753 dx = -tw; dy = Standard_ShortReal((tyo-th)/2.);
755 case Graphic2d_TOA_MEDIUMCENTER:
756 dx = Standard_ShortReal(-tw/2.); dy = Standard_ShortReal((tyo-th)/2.);
758 case Graphic2d_TOA_BOTTOMLEFT:
761 case Graphic2d_TOA_BOTTOMRIGHT:
764 case Graphic2d_TOA_BOTTOMCENTER:
765 dx = Standard_ShortReal(-tw/2.); dy = tyo;
771 if( myTrsfIsDefined ) {
772 Standard_Real U = x,V = y;
773 myTrsf.Transforms(U,V);
774 x = Standard_ShortReal(U); y = Standard_ShortReal(V);
775 U = Cos(a); V = Sin(a);
776 myTrsf.Transforms(U,V); U -= Standard_Real(x); V -= Standard_Real(y);
777 a = Standard_ShortReal(atan2(U,V));
780 Standard_ShortReal ax = dx, ay = dy;
781 Standard_Real cosa = Cos (a);
782 Standard_Real sina = Sin (a);
783 dx = Standard_ShortReal(XROTATE(ax,ay));
784 dy = Standard_ShortReal(YROTATE(ax,ay));
786 if( myMappingIsEnable )
787 Graphic2d_Drawer::MapPolyTextFromTo(aText,x+dx,y+dy,a,m,ox,oy,aType);
789 Graphic2d_Drawer::DrawPolyText(aText,x+ox+dx,y+oy+dy,a,m,aType);
792 //=======================================================================
793 void Graphic2d_TransientManager::DrawFramedText(
794 const TCollection_ExtendedString& aText,
795 const Standard_Real X,
796 const Standard_Real Y,
797 const Standard_Real anAngle,
798 const Standard_Real aMargin,
799 const Standard_Real aDeltax,
800 const Standard_Real aDeltay,
801 const Aspect_TypeOfText aType,
802 const Graphic2d_TypeOfAlignment anAlignment) {
804 Graphic2d_TransientDefinitionError_Raise_if (
805 !myDrawingIsStarted,"Drawing must be started before");
807 Graphic2d_TransientDefinitionError_Raise_if (
808 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
810 Standard_ShortReal x = Standard_ShortReal(X),
811 y = Standard_ShortReal(Y),
812 a = Standard_ShortReal(anAngle),
813 m = Standard_ShortReal(aMargin);
814 Standard_ShortReal dx = 0., dy = 0.,
815 ox = Standard_ShortReal(aDeltax), oy = Standard_ShortReal(aDeltay);
817 if( anAlignment != Graphic2d_TOA_LEFT ) {
818 Standard_ShortReal tw,th,txo,tyo;
819 if( Graphic2d_Drawer::GetTextSize(aText,tw,th,txo,tyo) ) {
820 switch( anAlignment ) {
821 case Graphic2d_TOA_LEFT:
824 case Graphic2d_TOA_RIGHT:
827 case Graphic2d_TOA_CENTER:
828 dx = Standard_ShortReal(-tw/2.); dy = 0.;
830 case Graphic2d_TOA_TOPLEFT:
831 dx = 0.; dy = tyo-th;
833 case Graphic2d_TOA_TOPRIGHT:
834 dx = -tw; dy = tyo-th;
836 case Graphic2d_TOA_TOPCENTER:
837 dx = Standard_ShortReal(-tw/2.); dy = tyo-th;
839 case Graphic2d_TOA_MEDIUMLEFT:
840 dx = 0.; dy = Standard_ShortReal((tyo-th)/2.);
842 case Graphic2d_TOA_MEDIUMRIGHT:
843 dx = -tw; dy = Standard_ShortReal((tyo-th)/2.);
845 case Graphic2d_TOA_MEDIUMCENTER:
846 dx = Standard_ShortReal(-tw/2.); dy = Standard_ShortReal((tyo-th)/2.);
848 case Graphic2d_TOA_BOTTOMLEFT:
851 case Graphic2d_TOA_BOTTOMRIGHT:
854 case Graphic2d_TOA_BOTTOMCENTER:
855 dx = Standard_ShortReal(-tw/2.); dy = tyo;
861 if( myTrsfIsDefined ) {
862 Standard_Real U = x,V = y;
863 myTrsf.Transforms(U,V);
864 x = Standard_ShortReal(U); y = Standard_ShortReal(V);
865 U = Cos(a); V = Sin(a);
866 myTrsf.Transforms(U,V); U -= Standard_Real(x); V -= Standard_Real(y);
867 a = Standard_ShortReal(atan2(U,V));
870 Standard_ShortReal ax = dx, ay = dy;
871 Standard_Real cosa = Cos (a);
872 Standard_Real sina = Sin (a);
873 dx = Standard_ShortReal(XROTATE(ax,ay));
874 dy = Standard_ShortReal(YROTATE(ax,ay));
876 if( myMappingIsEnable )
877 Graphic2d_Drawer::MapFramedTextFromTo(aText,x+dx,y+dy,a,m,ox,oy,aType);
879 Graphic2d_Drawer::DrawFramedText(aText,x+ox+dx,y+oy+dy,a,m,aType);
882 //=======================================================================
883 void Graphic2d_TransientManager::SetTextAttrib(
884 const Standard_Integer ColorIndex,
885 const Standard_Integer FontIndex,
886 const Standard_Real aSlant,
887 const Standard_Real aHScale,
888 const Standard_Real aWScale,
889 const Standard_Boolean isUnderlined,
890 const Standard_Boolean isZoomable) {
892 Graphic2d_TransientDefinitionError_Raise_if (
893 !myDrawingIsStarted,"Drawing must be started before");
895 Graphic2d_TransientDefinitionError_Raise_if (
896 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
898 Standard_ShortReal sl = Standard_ShortReal(aSlant),
899 hsc = (aHScale > 0.) ? Standard_ShortReal(aHScale) : Standard_ShortReal(1.0);
900 Standard_ShortReal wsc = (aWScale > 0.) ? Standard_ShortReal(aWScale) : hsc;
902 if( myTrsfIsDefined ) {
903 hsc *= Standard_ShortReal((myTrsf(1,1) + myTrsf(2,2))/2.);
904 wsc *= Standard_ShortReal((myTrsf(1,1) + myTrsf(2,2))/2.);
907 hsc *= Graphic2d_Drawer::Scale(); wsc *= Graphic2d_Drawer::Scale();
909 Graphic2d_Drawer::SetTextAttrib(ColorIndex,FontIndex,sl,hsc,wsc,isUnderlined);
913 //=======================================================================
914 void Graphic2d_TransientManager::SetHidingTextAttrib(
915 const Standard_Integer ColorIndex,
916 const Standard_Integer HidingColorIndex,
917 const Standard_Integer FrameColorIndex,
918 const Standard_Integer FrameWidthIndex,
919 const Standard_Integer FontIndex,
920 const Standard_Real aSlant,
921 const Standard_Real aHScale,
922 const Standard_Real aWScale,
923 const Standard_Boolean isUnderlined,
924 const Standard_Boolean isZoomable) {
926 Graphic2d_TransientDefinitionError_Raise_if (
927 !myDrawingIsStarted,"Drawing must be started before");
929 Graphic2d_TransientDefinitionError_Raise_if (
930 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
932 Standard_ShortReal sl = Standard_ShortReal(aSlant),
933 hsc = (aHScale > 0.) ? Standard_ShortReal(aHScale) : Standard_ShortReal(1.0);
934 Standard_ShortReal wsc = (aWScale > 0.) ? Standard_ShortReal(aWScale) : hsc;
935 if( myTrsfIsDefined ) {
936 hsc *= Standard_ShortReal((myTrsf(1,1) + myTrsf(2,2))/2.);
937 wsc *= Standard_ShortReal((myTrsf(1,1) + myTrsf(2,2))/2.);
940 hsc *= Graphic2d_Drawer::Scale(); wsc *= Graphic2d_Drawer::Scale();
942 Graphic2d_Drawer::SetHidingTextAttrib(ColorIndex,HidingColorIndex,
943 FrameColorIndex,FrameWidthIndex,FontIndex,sl,hsc,wsc,isUnderlined);
946 //=======================================================================
947 void Graphic2d_TransientManager::SetFramedTextAttrib(
948 const Standard_Integer ColorIndex,
949 const Standard_Integer FrameColorIndex,
950 const Standard_Integer FrameWidthIndex,
951 const Standard_Integer FontIndex,
952 const Standard_Real aSlant,
953 const Standard_Real aHScale,
954 const Standard_Real aWScale,
955 const Standard_Boolean isUnderlined,
956 const Standard_Boolean isZoomable) {
958 Graphic2d_TransientDefinitionError_Raise_if (
959 !myDrawingIsStarted,"Drawing must be started before");
961 Graphic2d_TransientDefinitionError_Raise_if (
962 (myTypeOfPrimitive != Aspect_TOP_UNKNOWN),"Bad primitive type");
964 Standard_ShortReal sl = Standard_ShortReal(aSlant), hsc = (aHScale > 0.) ? Standard_ShortReal(aHScale) : Standard_ShortReal(1.0);
965 Standard_ShortReal wsc = (aWScale > 0.) ? Standard_ShortReal(aWScale) : hsc;
966 if( myTrsfIsDefined ) {
967 hsc *= Standard_ShortReal((myTrsf(1,1) + myTrsf(2,2))/2.);
968 wsc *= Standard_ShortReal((myTrsf(1,1) + myTrsf(2,2))/2.);
971 hsc *= Graphic2d_Drawer::Scale(); wsc *= Graphic2d_Drawer::Scale();
973 Graphic2d_Drawer::SetFramedTextAttrib(ColorIndex,FrameColorIndex,
974 FrameWidthIndex,FontIndex,sl,hsc,wsc,isUnderlined);
977 //=======================================================================
978 void Graphic2d_TransientManager::SetTransform (
979 const gp_GTrsf2d& aTrsf,
980 const Graphic2d_TypeOfComposition aType) {
982 if( myDrawingIsStarted ) {
983 Standard_Real re = RealEpsilon ();
984 if( !myTrsfIsDefined || (aType == Graphic2d_TOC_REPLACE) ) {
987 myTrsf = aTrsf.Multiplied(myTrsf);
989 myTypeOfComposition = aType;
990 myCompositeTrsf = aTrsf;
992 (Abs (myCompositeTrsf.Value (1, 1) - 1.0) > re) ||
993 (Abs (myCompositeTrsf.Value (1, 2) - 0.0) > re) ||
994 (Abs (myCompositeTrsf.Value (1, 3) - 0.0) > re) ||
995 (Abs (myCompositeTrsf.Value (2, 1) - 0.0) > re) ||
996 (Abs (myCompositeTrsf.Value (2, 2) - 1.0) > re) ||
997 (Abs (myCompositeTrsf.Value (2, 3) - 0.0) > re);
999 Graphic2d_TransientDefinitionError::Raise ("Drawing must be started");
1003 //=======================================================================
1004 void Graphic2d_TransientManager::SetMapping(const Standard_Boolean aStatus) {
1006 myMappingIsEnable = aStatus;
1009 //=======================================================================
1010 void Graphic2d_TransientManager::EnableMinMax(const Standard_Boolean aStatus,
1011 const Standard_Boolean Reset) {
1012 myMinMaxIsActivated = aStatus;
1014 myMinX = myMinY = ShortRealLast();
1015 myMaxX = myMaxY = ShortRealFirst();
1019 //=======================================================================
1020 Standard_Boolean Graphic2d_TransientManager::MinMax (
1021 Standard_Real &XMin, Standard_Real &YMin,
1022 Standard_Real &XMax, Standard_Real &YMax) const {
1025 if( myMaxX < myMinX || myMaxY < myMinY ) return Standard_False;
1027 Standard_ShortReal xmin = Max(myMinX,Standard_ShortReal(0.));
1028 Standard_ShortReal ymin = Max(myMinY,Standard_ShortReal(0.));
1029 Standard_ShortReal xmax = Min(myMaxX,mySpaceWidth);
1030 Standard_ShortReal ymax = Min(myMaxY,mySpaceHeight);
1032 if( xmax > xmin && ymax > ymin ) {
1033 Standard_ShortReal uxmin,uymin,uxmax,uymax;
1034 Graphic2d_Drawer::UnMapFromTo(xmin,ymin,uxmin,uymin);
1035 Graphic2d_Drawer::UnMapFromTo(xmax,ymax,uxmax,uymax);
1036 XMin = uxmin; YMin = uymin; XMax = uxmax; YMax = uymax;
1037 return Standard_True;
1039 XMin = YMin = RealLast();
1040 XMax = YMax = RealFirst();
1041 return Standard_False;
1045 //=======================================================================
1046 Standard_Boolean Graphic2d_TransientManager::MinMax(
1047 Standard_Integer &aMinX,
1048 Standard_Integer &aMaxX,
1049 Standard_Integer &aMinY,
1050 Standard_Integer &aMaxY)const
1052 if (! myDriverIsDefined)
1053 Graphic2d_TransientDefinitionError::Raise ("No defined driver");
1055 if( myMaxX < myMinX || myMaxY < myMinY ) return Standard_False;
1058 Standard_ShortReal xmin = Max(myMinX,Standard_ShortReal(0.));
1059 Standard_ShortReal ymin = Max(myMinY,Standard_ShortReal(0.));
1060 Standard_ShortReal xmax = Min(myMaxX,mySpaceWidth);
1061 Standard_ShortReal ymax = Min(myMaxY,mySpaceHeight);
1063 myDriver->Convert(xmin,ymin,aMinX,aMaxY);
1064 myDriver->Convert(xmax,ymax,aMaxX,aMinY);
1065 if( aMaxX > aMinX && aMaxY > aMinY ) return Standard_True;
1066 else return Standard_False;