1 // Created on: 2004-06-22
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <V3d_ColorScale.ixx>
18 #include <V3d_View.hxx>
19 #include <V3d_LayerMgr.hxx>
21 #include <Visual3d_View.hxx>
22 #include <Visual3d_Layer.hxx>
23 #include <Visual3d_ViewManager.hxx>
25 #include <Aspect_Window.hxx>
26 #include <Aspect_SequenceOfColor.hxx>
27 #include <Aspect_TypeOfColorScaleData.hxx>
28 #include <Aspect_TypeOfColorScalePosition.hxx>
30 #include <TCollection_AsciiString.hxx>
31 #include <TColStd_SequenceOfExtendedString.hxx>
32 #include <Font_NameOfFont.hxx>
34 V3d_ColorScale::V3d_ColorScale (const Handle(V3d_LayerMgr)& theMgr)
35 : Aspect_ColorScale(),
36 myLayerMgr( theMgr.operator->() ),
37 myDisplay( Standard_False )
41 void V3d_ColorScale::Display()
43 myDisplay = Standard_True;
47 void V3d_ColorScale::Erase()
49 myDisplay = Standard_False;
53 Standard_Boolean V3d_ColorScale::IsDisplayed() const
58 void V3d_ColorScale::UpdateColorScale()
60 myLayerMgr->Compute();
63 void V3d_ColorScale::PaintRect (const Standard_Integer theX, const Standard_Integer theY,
64 const Standard_Integer theWidth, const Standard_Integer theHeight,
65 const Quantity_Color& theColor, const Standard_Boolean theFilled)
67 const Handle(Visual3d_Layer) &theLayer = myLayerMgr->Overlay();
68 if (theLayer.IsNull())
71 theLayer->SetColor (theColor);
73 theLayer->DrawRectangle (theX, theY, theWidth, theHeight);
75 theLayer->SetLineAttributes( Aspect_TOL_SOLID, 0.5 );
76 theLayer->BeginPolyline();
77 theLayer->AddVertex (theX, theY, Standard_False);
78 theLayer->AddVertex (theX, theY + theHeight, Standard_True);
79 theLayer->AddVertex (theX + theWidth, theY + theHeight, Standard_True);
80 theLayer->AddVertex (theX + theWidth, theY, Standard_True);
81 theLayer->AddVertex (theX, theY, Standard_True);
82 theLayer->ClosePrimitive();
86 void V3d_ColorScale::PaintText (const TCollection_ExtendedString& theText,
87 const Standard_Integer theX, const Standard_Integer theY,
88 const Quantity_Color& theColor)
90 const Handle(Visual3d_Layer) &theLayer = myLayerMgr->Overlay();
91 if (theLayer.IsNull())
94 theLayer->SetColor (theColor);
95 theLayer->SetTextAttributes (Font_NOF_ASCII_MONO, Aspect_TODT_NORMAL, theColor);
96 TCollection_AsciiString aText (theText.ToExtString(), '?');
97 Standard_Integer aTextH = GetTextHeight();
98 Standard_Integer aWidth, anAscent, aDescent;
99 TextSize (theText, aTextH, aWidth, anAscent, aDescent);
100 theLayer->DrawText (aText.ToCString(), theX, theY + anAscent, aTextH);
103 Standard_Integer V3d_ColorScale::TextWidth (const TCollection_ExtendedString& theText) const
105 Standard_Integer aWidth, anAscent, aDescent;
106 TextSize (theText, GetTextHeight(), aWidth, anAscent, aDescent);
110 Standard_Integer V3d_ColorScale::TextHeight (const TCollection_ExtendedString& theText) const
112 Standard_Integer aWidth, anAscent, aDescent;
113 TextSize (theText, GetTextHeight(), aWidth, anAscent, aDescent);
114 return anAscent+aDescent;
117 void V3d_ColorScale::TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const
119 const Handle(Visual3d_Layer) &theLayer = myLayerMgr->Overlay();
120 if (!theLayer.IsNull()) {
121 Standard_Real aWidth, anAscent, aDescent;
122 TCollection_AsciiString aText (theText.ToExtString(), '?');
123 theLayer->TextSize (aText.ToCString(),theHeight,aWidth,anAscent,aDescent);
124 theWidth = (Standard_Integer)aWidth;
125 theAscent = (Standard_Integer)anAscent;
126 theDescent = (Standard_Integer)aDescent;
129 theWidth=theAscent=theDescent=0;
133 void V3d_ColorScale::DrawScale ()
135 const Handle(V3d_View) &theView = myLayerMgr->View();
136 if (theView.IsNull())
139 const Handle(Aspect_Window) &theWin = theView->Window();
143 Standard_Integer WinWidth( 0 ), WinHeight( 0 );
144 theWin->Size (WinWidth, WinHeight);
146 const Standard_Integer X = RealToInt (GetXPosition() * WinWidth);
147 const Standard_Integer Y = RealToInt (GetYPosition() * WinHeight);
149 const Standard_Integer W = RealToInt (GetWidth() * WinWidth);
150 const Standard_Integer H = RealToInt (GetHeight() * WinHeight);
152 Aspect_ColorScale::DrawScale (theView->BackgroundColor(), X, Y, W, H);