1 // Created on: 2015-02-03
2 // Copyright (c) 2015 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <AIS_ColorScale.hxx>
16 #include <AIS_InteractiveContext.hxx>
17 #include <Aspect_TypeOfColorScaleData.hxx>
18 #include <Aspect_TypeOfColorScalePosition.hxx>
19 #include <Aspect_Window.hxx>
20 #include <Geom_Line.hxx>
21 #include <GeomAdaptor_Curve.hxx>
22 #include <Graphic3d_ArrayOfPolygons.hxx>
23 #include <Graphic3d_ArrayOfPolylines.hxx>
24 #include <Graphic3d_AspectFillArea3d.hxx>
25 #include <Graphic3d_AspectText3d.hxx>
26 #include <Graphic3d_GraphicDriver.hxx>
27 #include <Graphic3d_ArrayOfTriangles.hxx>
28 #include <Prs3d_LineAspect.hxx>
29 #include <Prs3d_Root.hxx>
30 #include <Prs3d_ShadingAspect.hxx>
31 #include <Prs3d_Text.hxx>
32 #include <Prs3d_TextAspect.hxx>
33 #include <SelectMgr_EntityOwner.hxx>
34 #include <SelectMgr_Selection.hxx>
35 #include <Select3D_SensitiveBox.hxx>
36 #include <Select3D_SensitiveSegment.hxx>
37 #include <StdPrs_Curve.hxx>
38 #include <V3d_Viewer.hxx>
39 #include <V3d_View.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(AIS_ColorScale,AIS_InteractiveObject)
44 //=======================================================================
45 //function : AIS_ColorScale
47 //=======================================================================
48 AIS_ColorScale::AIS_ColorScale() :
54 myColorType (Aspect_TOCSD_AUTO),
55 myLabelType (Aspect_TOCSD_AUTO),
56 myAtBorder (Standard_True),
57 myReversed (Standard_False),
58 myIsLogarithmic (Standard_False),
59 myLabelPos (Aspect_TOCSP_RIGHT),
60 myTitlePos (Aspect_TOCSP_CENTER),
69 //=======================================================================
72 //=======================================================================
73 void AIS_ColorScale::GetRange (Standard_Real& theMin, Standard_Real& theMax) const
79 //=======================================================================
82 //=======================================================================
83 TCollection_ExtendedString AIS_ColorScale::GetLabel (const Standard_Integer theIndex) const
85 if (GetLabelType() == Aspect_TOCSD_USER)
87 if (theIndex <= 0 || theIndex > myLabels.Length())
91 return myLabels.Value (theIndex);
94 // value to be shown depends on label position
95 Standard_Real aVal = IsLabelAtBorder() ? GetIntervalValue (theIndex - 1) :
96 0.5 * (GetIntervalValue (theIndex - 1) + GetIntervalValue (theIndex));
98 const TCollection_AsciiString aFormat = Format();
99 Standard_Character aBuf[1024];
100 sprintf (aBuf, aFormat.ToCString(), aVal);
101 return TCollection_ExtendedString (aBuf);
104 //=======================================================================
105 //function : GetIntervalColor
107 //=======================================================================
108 Quantity_Color AIS_ColorScale::GetIntervalColor (const Standard_Integer theIndex) const
110 if (GetColorType() == Aspect_TOCSD_USER)
112 if (theIndex <= 0 || theIndex > myColors.Length())
114 return Quantity_Color();
116 return myColors.Value (theIndex);
119 return Quantity_Color (HueFromValue (theIndex - 1, 0, GetNumberOfIntervals() - 1), 1.0, 1.0, Quantity_TOC_HLS);
122 //=======================================================================
123 //function : GetLabels
125 //=======================================================================
126 void AIS_ColorScale::GetLabels (TColStd_SequenceOfExtendedString& theLabels) const
129 for (Standard_Integer i = 1; i <= myLabels.Length(); i++)
130 theLabels.Append (myLabels.Value (i));
133 //=======================================================================
134 //function : GetColors
136 //=======================================================================
137 void AIS_ColorScale::GetColors (Aspect_SequenceOfColor& theColors) const
140 for (Standard_Integer i = 1; i <= myColors.Length(); i++)
141 theColors.Append (myColors.Value (i));
144 //=======================================================================
147 //=======================================================================
148 void AIS_ColorScale::SetMin (const Standard_Real theMin)
150 SetRange (theMin, GetMax());
153 //=======================================================================
156 //=======================================================================
157 void AIS_ColorScale::SetMax (const Standard_Real theMax)
159 SetRange (GetMin(), theMax);
162 //=======================================================================
163 //function : SetRange
165 //=======================================================================
166 void AIS_ColorScale::SetRange (const Standard_Real theMin, const Standard_Real theMax)
168 if (myMin == theMin && myMax == theMax)
171 myMin = Min (theMin, theMax);
172 myMax = Max (theMin, theMax);
175 //=======================================================================
176 //function : SetLabelType
178 //=======================================================================
179 void AIS_ColorScale::SetLabelType (const Aspect_TypeOfColorScaleData theType)
181 if (myLabelType == theType)
184 myLabelType = theType;
187 //=======================================================================
188 //function : SetColorType
190 //=======================================================================
191 void AIS_ColorScale::SetColorType (const Aspect_TypeOfColorScaleData theType)
193 if (myColorType == theType)
196 myColorType = theType;
199 //=======================================================================
200 //function : SetNumberOfIntervals
202 //=======================================================================
203 void AIS_ColorScale::SetNumberOfIntervals (const Standard_Integer theNum)
205 if (myInterval == theNum || theNum < 1)
211 //=======================================================================
212 //function : SetTitle
214 //=======================================================================
215 void AIS_ColorScale::SetTitle (const TCollection_ExtendedString& theTitle)
217 if (myTitle == theTitle)
223 //=======================================================================
224 //function : SetFormat
226 //=======================================================================
227 void AIS_ColorScale::SetFormat (const TCollection_AsciiString& theFormat)
229 if (myFormat == theFormat)
232 myFormat = theFormat;
235 //=======================================================================
236 //function : SetLabel
238 //=======================================================================
239 void AIS_ColorScale::SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer theIndex)
241 Standard_Integer i = (theIndex <= 0 ? myLabels.Length() + 1 : theIndex);
242 while (i > myLabels.Length())
243 myLabels.Append (TCollection_ExtendedString());
244 myLabels.SetValue (i, theLabel);
247 //=======================================================================
248 //function : SetIntervalColor
250 //=======================================================================
251 void AIS_ColorScale::SetIntervalColor (const Quantity_Color& theColor, const Standard_Integer theIndex)
253 Standard_Integer i = (theIndex <= 0 ? myColors.Length() + 1 : theIndex);
254 while (i > myColors.Length())
255 myColors.Append (Quantity_Color());
256 myColors.SetValue (i, theColor);
259 //=======================================================================
260 //function : SetLabels
262 //=======================================================================
263 void AIS_ColorScale::SetLabels (const TColStd_SequenceOfExtendedString& theSeq)
266 for (Standard_Integer i = 1; i <= theSeq.Length(); i++)
267 myLabels.Append (theSeq.Value (i));
270 //=======================================================================
271 //function : SetColors
273 //=======================================================================
274 void AIS_ColorScale::SetColors (const Aspect_SequenceOfColor& theSeq)
277 for (Standard_Integer i = 1; i <= theSeq.Length(); i++)
278 myColors.Append (theSeq.Value (i));
281 //=======================================================================
282 //function : SetLabelPosition
284 //=======================================================================
285 void AIS_ColorScale::SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos)
287 if (myLabelPos == thePos)
293 //=======================================================================
294 //function : SetTitlePosition
296 //=======================================================================
297 void AIS_ColorScale::SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos)
299 if (myTitlePos == thePos)
305 //=======================================================================
306 //function : SetReversed
308 //=======================================================================
309 void AIS_ColorScale::SetReversed (const Standard_Boolean theReverse)
311 if (myReversed == theReverse)
314 myReversed = theReverse;
317 //=======================================================================
318 //function : SetLabelAtBorder
320 //=======================================================================
321 void AIS_ColorScale::SetLabelAtBorder (const Standard_Boolean theOn)
323 if (myAtBorder == theOn)
329 //=======================================================================
330 //function : GetPosition
332 //=======================================================================
333 void AIS_ColorScale::GetPosition (Standard_Real& theX, Standard_Real& theY) const
339 //=======================================================================
340 //function : SetPosition
342 //=======================================================================
343 void AIS_ColorScale::SetPosition (const Standard_Integer theX, const Standard_Integer theY)
345 if (myXPos == theX && myYPos == theY)
352 //=======================================================================
353 //function : SetXPosition
355 //=======================================================================
356 void AIS_ColorScale::SetXPosition (const Standard_Integer theX)
358 SetPosition (theX, GetYPosition());
361 //=======================================================================
362 //function : SetYPosition
364 //=======================================================================
365 void AIS_ColorScale::SetYPosition (const Standard_Integer theY)
367 SetPosition (GetXPosition(), theY);
370 //=======================================================================
373 //=======================================================================
374 void AIS_ColorScale::GetSize (Standard_Integer& theBreadth, Standard_Integer& theHeight) const
376 theBreadth = myBreadth;
377 theHeight = myHeight;
380 //=======================================================================
383 //=======================================================================
384 void AIS_ColorScale::SetSize (const Standard_Integer theBreadth, const Standard_Integer theHeight)
386 if (myBreadth == theBreadth && myHeight == theHeight)
389 myBreadth = theBreadth;
390 myHeight = theHeight;
393 //=======================================================================
394 //function : SetBreadth
396 //=======================================================================
397 void AIS_ColorScale::SetBreadth (const Standard_Integer theWidth)
399 SetSize (theWidth, GetHeight());
402 //=======================================================================
403 //function : SetHeight
405 //=======================================================================
406 void AIS_ColorScale::SetHeight (const Standard_Integer theHeight)
408 SetSize (GetBreadth(), theHeight);
411 //=======================================================================
412 //function : SizeHint
414 //=======================================================================
415 void AIS_ColorScale::SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const
417 Standard_Integer aNum = GetNumberOfIntervals();
419 Standard_Integer aSpacer = 5;
420 Standard_Integer aTextWidth = 0;
421 Standard_Integer aTextHeight = TextHeight ("");
422 Standard_Integer aColorWidth = 20;
424 if (GetLabelPosition() != Aspect_TOCSP_NONE)
426 for (Standard_Integer idx = (IsLabelAtBorder() ? 0 : 1); idx <= aNum; idx++)
427 aTextWidth = Max (aTextWidth, TextWidth (GetLabel (idx)));
430 Standard_Integer aScaleWidth = 0;
431 Standard_Integer aScaleHeight = 0;
433 aScaleWidth = aColorWidth + aTextWidth + ( aTextWidth ? 3 : 2 ) * aSpacer;
434 aScaleHeight = (Standard_Integer)( 1.5 * ( aNum + (IsLabelAtBorder() ? 2 : 1) ) * aTextHeight );
436 Standard_Integer aTitleWidth = 0;
437 Standard_Integer aTitleHeight = 0;
438 if (GetTitle().Length())
440 aTitleHeight = TextHeight (GetTitle()) + aSpacer;
441 aTitleWidth = TextWidth (GetTitle()) + 10;
444 theWidth = Max (aTitleWidth, aScaleWidth);
445 theHeight = aScaleHeight + aTitleHeight;
448 //=======================================================================
451 //=======================================================================
452 TCollection_AsciiString AIS_ColorScale::Format() const
457 //=======================================================================
458 //function : GetIntervalValue
460 //=======================================================================
461 Standard_Real AIS_ColorScale::GetIntervalValue (const Standard_Integer theIndex) const
463 if (GetNumberOfIntervals() <= 0)
468 Standard_Real aMin = myMin > 0 ? myMin : 1.0;
469 Standard_Real aDivisor = std::pow (myMax/aMin, 1.0/myInterval);
470 return aMin*std::pow (aDivisor,theIndex);
473 Standard_Real aNum = 0;
474 if (GetNumberOfIntervals() > 0)
475 aNum = GetMin() + theIndex * ( Abs (GetMax() - GetMin()) / GetNumberOfIntervals() );
479 //=======================================================================
480 //function : HueFromValue
482 //=======================================================================
483 Standard_Integer AIS_ColorScale::HueFromValue (const Standard_Integer theValue,
484 const Standard_Integer theMin, const Standard_Integer theMax)
486 Standard_Integer aMinLimit (0), aMaxLimit (230);
488 Standard_Integer aHue = aMaxLimit;
489 if (theMin != theMax)
490 aHue = (Standard_Integer)( aMaxLimit - ( aMaxLimit - aMinLimit ) * ( theValue - theMin ) / ( theMax - theMin ) );
492 aHue = Min (Max (aMinLimit, aHue), aMaxLimit);
497 //=======================================================================
498 //function : FindColor
500 //=======================================================================
501 Standard_Boolean AIS_ColorScale::FindColor (const Standard_Real theValue,
502 Quantity_Color& theColor) const
504 return FindColor (theValue, myMin, myMax, myInterval, theColor);
507 //=======================================================================
508 //function : FindColor
510 //=======================================================================
511 Standard_Boolean AIS_ColorScale::FindColor (const Standard_Real theValue,
512 const Standard_Real theMin,
513 const Standard_Real theMax,
514 const Standard_Integer theColorsCount,
515 Quantity_Color& theColor)
517 if (theValue < theMin || theValue > theMax || theMax < theMin)
518 return Standard_False;
522 Standard_Real anIntervNumber = 0;
523 if(Abs (theMax-theMin) > Precision::Approximation())
524 anIntervNumber = Floor (Standard_Real (theColorsCount) * ( theValue - theMin ) / ( theMax - theMin ));
526 Standard_Integer anInterv = Standard_Integer (anIntervNumber);
528 theColor = Quantity_Color (HueFromValue (anInterv, 0, theColorsCount - 1), 1.0, 1.0, Quantity_TOC_HLS);
530 return Standard_True;
534 //=======================================================================
537 //=======================================================================
538 void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
539 const Handle(Prs3d_Presentation)& thePresentation,
540 const Standard_Integer /*theMode*/)
542 Handle(V3d_Viewer) aViewer= GetContext()->CurrentViewer();
543 aViewer->InitActiveViews();
544 Standard_Integer aNum = GetNumberOfIntervals();
545 Aspect_TypeOfColorScalePosition aLabPos = GetLabelPosition();
547 Standard_Integer aSpacer = 5;
548 Standard_Integer aTextWidth = 0;
549 Standard_Integer aTextHeight = myTextHeight;
550 Standard_Boolean toDrawLabel = GetLabelPosition() != Aspect_TOCSP_NONE;
551 TCollection_ExtendedString aTitle = GetTitle();
552 Standard_Integer aTitleHeight = aSpacer;
553 Quantity_Color aFgColor (hasOwnColor ? myOwnColor : Quantity_NOC_WHITE);
558 aTitleHeight += myTextHeight + aSpacer;
559 DrawText (thePresentation, aTitle, (Standard_Integer)myXPos + aSpacer, myHeight - ((Standard_Integer)myYPos - 2 * aSpacer + aTitleHeight), aFgColor);
562 Standard_Boolean toReverse = IsReversed();
564 Aspect_SequenceOfColor aColors;
565 for (Standard_Integer i = 1; i <= aNum; i++)
569 aColors.Prepend (GetIntervalColor (i));
573 aColors.Append (GetIntervalColor (i));
577 TColStd_SequenceOfExtendedString aLabels;
578 Standard_Integer aLabCount = IsLabelAtBorder() ? aNum + 1 : aNum;
579 for (Standard_Integer i = 1; i <= aLabCount; i++)
583 aLabels.Prepend (GetLabel (i));
587 aLabels.Append (GetLabel (i));
592 for (Standard_Integer i = 1; i <= aLabels.Length(); i++)
593 aTextWidth = Max (aTextWidth, TextWidth (aLabels.Value (i)));
595 Standard_Integer aSpc = ( myHeight - ( ( Min (aLabCount, 2) + Abs (aLabCount - aNum - 1) ) * aTextHeight ) - aTitleHeight );
596 Standard_Real aVal = aSpc != 0 ? 1.0 * ( aLabCount - Min (aLabCount, 0) ) * aTextHeight / aSpc : 0;
597 Standard_Real anIPart;
598 Standard_Real anFPart = modf (aVal, &anIPart);
599 Standard_Integer aFilter = (Standard_Integer)anIPart + ( anFPart != 0 ? 1 : 0 );
601 Standard_Real aStep = 1.0 * ( myHeight - (aLabCount - aNum + Abs (aLabCount - aNum - 1)) * aTextHeight - aTitleHeight ) / aNum;
603 Standard_Integer anAscent = 0;
604 Standard_Integer aColorBreadth = Max (5, Min (20, myBreadth - aTextWidth - 3 * aSpacer));
605 if (aLabPos == Aspect_TOCSP_CENTER || !toDrawLabel)
606 aColorBreadth += aTextWidth;
609 Standard_Integer aX = (Standard_Integer)myXPos + aSpacer;
610 if (aLabPos == Aspect_TOCSP_LEFT)
611 aX += aTextWidth + ( aTextWidth ? 1 : 0 ) * aSpacer;
613 Standard_Real anOffset = 1.0 * aTextHeight / 2 * ( aLabCount - aNum + Abs (aLabCount - aNum - 1) );
614 anOffset += 2*aSpacer;
615 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
616 Handle (Graphic3d_ArrayOfTriangles) aPrim;
617 Standard_Integer anEdgesPerColor = 6;
618 Standard_Integer aVerticiesPerColor = 4;
619 aPrim = new Graphic3d_ArrayOfTriangles (aColors.Length()*aVerticiesPerColor, aColors.Length()*anEdgesPerColor, 0, 1);
620 Standard_Integer aVertIndex = 1;
621 for (Standard_Integer i = 1; i <= aColors.Length() && aStep > 0; i++)
623 Standard_Integer aY = (Standard_Integer)( myYPos + ( i - 1 )* aStep + anOffset );
624 Standard_Integer aColorHeight = (Standard_Integer)( myYPos + ( i ) * aStep + anOffset ) - aY;
625 aPrim->AddVertex (gp_Pnt (aX, aY, 0.0), aColors.Value( i ));
626 aPrim->AddVertex (gp_Pnt (aX+aColorBreadth, aY, 0.0), aColors.Value( i ));
627 aPrim->AddVertex (gp_Pnt (aX, aY+aColorHeight, 0.0), aColors.Value( i ));
628 aPrim->AddVertex (gp_Pnt (aX+aColorBreadth, aY+aColorHeight, 0.0), aColors.Value( i ));
629 aPrim->AddEdge(aVertIndex);
630 aPrim->AddEdge(aVertIndex+1);
631 aPrim->AddEdge(aVertIndex+2);
632 aPrim->AddEdge(aVertIndex+1);
633 aPrim->AddEdge(aVertIndex+2);
634 aPrim->AddEdge(aVertIndex+3);
637 aGroup->AddPrimitiveArray (aPrim);
640 DrawFrame (thePresentation, aX - 1, (Standard_Integer)(myYPos + anOffset - 1), aColorBreadth + 2, (Standard_Integer)(aColors.Length() * aStep + 2), aFgColor);
643 anOffset = 1.0 * Abs (aLabCount - aNum - 1) * ( aStep - aTextHeight ) / 2 + 1.0 * Abs (aLabCount - aNum - 1) * aTextHeight / 2;
644 anOffset += 2*aSpacer;
645 if (toDrawLabel && aLabels.Length() && aFilter > 0)
647 Standard_Integer i1 = 0;
648 Standard_Integer i2 = aLabCount - 1;
649 Standard_Integer aLast1( i1 ), aLast2( i2 );
650 aX = (Standard_Integer)myXPos + aSpacer;
653 case Aspect_TOCSP_NONE:
654 case Aspect_TOCSP_LEFT:
656 case Aspect_TOCSP_CENTER:
657 aX += ( aColorBreadth - aTextWidth ) / 2;
659 case Aspect_TOCSP_RIGHT:
660 aX += aColorBreadth + aSpacer;
663 while (i2 - i1 >= aFilter || ( i2 == 0 && i1 == 0 ))
665 Standard_Integer aPos1 = i1;
666 Standard_Integer aPos2 = aLabCount - 1 - i2;
667 if (aFilter && !( aPos1 % aFilter ))
669 DrawText (thePresentation, aLabels.Value (i1 + 1), aX, (Standard_Integer)( myYPos + i1 * aStep + anAscent + anOffset ), aFgColor);
672 if (aFilter && !( aPos2 % aFilter ))
674 DrawText (thePresentation, aLabels.Value (i2 + 1), aX, (Standard_Integer)( myYPos + i2 * aStep + anAscent + anOffset ), aFgColor);
680 Standard_Integer aPos = i1;
681 Standard_Integer i0 = -1;
682 while (aPos <= i2 && i0 == -1)
684 if (aFilter && !( aPos % aFilter ) && Abs (aPos - aLast1) >= aFilter && Abs (aPos - aLast2) >= aFilter)
690 DrawText (thePresentation, aLabels.Value (i0 + 1), aX, (Standard_Integer)( myYPos + i0 * aStep + anAscent + anOffset ), aFgColor);
694 //=======================================================================
695 //function : DrawFrame
697 //=======================================================================
698 void AIS_ColorScale::DrawFrame (const Handle(Prs3d_Presentation)& thePresentation,
699 const Standard_Integer theX, const Standard_Integer theY,
700 const Standard_Integer theWidth, const Standard_Integer theHeight,
701 const Quantity_Color& theColor)
703 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
704 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
705 aPrim->AddVertex (theX,theY,0.0);
706 aPrim->AddVertex (theX+theWidth,theY,0.0);
707 aPrim->AddVertex (theX+theWidth,theY+theHeight,0.0);
708 aPrim->AddVertex (theX,theY+theHeight,0.0);
709 aPrim->AddVertex (theX,theY,0.0);
710 Handle(Prs3d_LineAspect) anAspect =
711 new Prs3d_LineAspect (theColor, Aspect_TOL_SOLID, 1.0);
712 anAspect->SetColor (theColor);
713 aGroup->SetPrimitivesAspect (anAspect->Aspect());
714 aGroup->AddPrimitiveArray (aPrim);
717 //=======================================================================
718 //function : DrawText
720 //=======================================================================
721 void AIS_ColorScale::DrawText (const Handle(Prs3d_Presentation)& thePresentation,
722 const TCollection_ExtendedString& theText,
723 const Standard_Integer theX, const Standard_Integer theY,
724 const Quantity_Color& theColor)
726 if (!myDrawer->HasOwnTextAspect())
728 myDrawer->SetTextAspect (new Prs3d_TextAspect());
729 *myDrawer->TextAspect()->Aspect() = *myDrawer->Link()->TextAspect()->Aspect();
731 Handle(Prs3d_TextAspect) anAspect = myDrawer->TextAspect();
732 anAspect->SetColor (theColor);
733 anAspect->SetHeight (myTextHeight);
734 anAspect->SetHorizontalJustification (Graphic3d_HTA_LEFT);
735 anAspect->SetVerticalJustification (Graphic3d_VTA_BOTTOM);
736 anAspect->Aspect()->SetTextZoomable (Standard_True);
737 anAspect->Aspect()->SetTextAngle (0.0);
738 anAspect->Aspect()->SetTextFontAspect (Font_FA_Regular);
739 Prs3d_Text::Draw (thePresentation, anAspect, theText,gp_Pnt (theX,theY,0.0));
742 //=======================================================================
743 //function : TextWidth
745 //=======================================================================
746 Standard_Integer AIS_ColorScale::TextWidth (const TCollection_ExtendedString& theText) const
748 Standard_Integer aWidth, anAscent, aDescent;
749 TextSize (theText, GetTextHeight(), aWidth, anAscent, aDescent);
753 //=======================================================================
754 //function : TextHeight
756 //=======================================================================
757 Standard_Integer AIS_ColorScale::TextHeight (const TCollection_ExtendedString& theText) const
759 Standard_Integer aWidth, anAscent, aDescent;
760 TextSize (theText, GetTextHeight(), aWidth, anAscent, aDescent);
761 return anAscent+aDescent;
764 //=======================================================================
765 //function : TextSize
767 //=======================================================================
768 void AIS_ColorScale::TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const
770 const Handle(Graphic3d_CView)& aView = GetContext()->CurrentViewer()->ActiveView()->View();
771 Standard_ShortReal aWidth(10.0), anAscent(1.0), aDescent(1.0);
772 TCollection_AsciiString aText (theText.ToExtString(), '?');
773 GetContext()->CurrentViewer()->Driver()->TextSize (aView, aText.ToCString(), (Standard_ShortReal)theHeight, aWidth, anAscent, aDescent);
774 theWidth = (Standard_Integer)aWidth;
775 theAscent = (Standard_Integer)anAscent;
776 theDescent = (Standard_Integer)aDescent;