b311480e |
1 | // Created on: 2004-06-22 |
2 | // Created by: STV |
3 | // Copyright (c) 2004-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | #include <V3d_ColorScale.ixx> |
22 | |
23 | #include <V3d_View.hxx> |
24 | #include <V3d_LayerMgr.hxx> |
25 | |
26 | #include <Visual3d_View.hxx> |
27 | #include <Visual3d_Layer.hxx> |
28 | #include <Visual3d_ViewManager.hxx> |
29 | |
30 | #include <Aspect_Window.hxx> |
31 | #include <Aspect_ColorMap.hxx> |
32 | #include <Aspect_ColorMapEntry.hxx> |
33 | #include <Aspect_SequenceOfColor.hxx> |
34 | #include <Aspect_TypeOfColorScaleData.hxx> |
35 | #include <Aspect_TypeOfColorScalePosition.hxx> |
36 | |
37 | #include <TCollection_AsciiString.hxx> |
38 | #include <TColStd_SequenceOfExtendedString.hxx> |
aff395a3 |
39 | #include <Font_NameOfFont.hxx> |
7fd59977 |
40 | |
41 | V3d_ColorScale::V3d_ColorScale( const Handle(V3d_LayerMgr)& aMgr ) |
42 | : Aspect_ColorScale(), |
43 | myLayerMgr( aMgr.operator->() ), |
44 | myDisplay( Standard_False ) |
45 | { |
46 | } |
47 | |
48 | void V3d_ColorScale::Display() |
49 | { |
50 | myDisplay = Standard_True; |
51 | UpdateColorScale(); |
52 | } |
53 | |
54 | void V3d_ColorScale::Erase() |
55 | { |
56 | myDisplay = Standard_False; |
57 | UpdateColorScale(); |
58 | } |
59 | |
60 | Standard_Boolean V3d_ColorScale::IsDisplayed() const |
61 | { |
62 | return myDisplay; |
63 | } |
64 | |
65 | void V3d_ColorScale::UpdateColorScale() |
66 | { |
67 | myLayerMgr->Compute(); |
68 | } |
69 | |
70 | void V3d_ColorScale::PaintRect( const Standard_Integer X, const Standard_Integer Y, |
71 | const Standard_Integer W, const Standard_Integer H, |
72 | const Quantity_Color& aColor, const Standard_Boolean aFilled ) |
73 | { |
74 | const Handle(Visual3d_Layer) &theLayer = myLayerMgr->Overlay(); |
75 | if ( theLayer.IsNull() ) |
76 | return; |
77 | |
78 | theLayer->SetColor( aColor ); |
79 | if ( aFilled ) |
80 | theLayer->DrawRectangle( X, Y, W, H ); |
81 | else { |
82 | theLayer->SetLineAttributes( Aspect_TOL_SOLID, 0.5 ); |
83 | theLayer->BeginPolyline(); |
84 | theLayer->AddVertex( X, Y, Standard_False ); |
85 | theLayer->AddVertex( X, Y + H, Standard_True ); |
86 | theLayer->AddVertex( X + W, Y + H, Standard_True ); |
87 | theLayer->AddVertex( X + W, Y, Standard_True ); |
88 | theLayer->AddVertex( X, Y, Standard_True ); |
89 | theLayer->ClosePrimitive(); |
90 | } |
91 | } |
92 | |
93 | void V3d_ColorScale::PaintText( const TCollection_ExtendedString& aText, |
94 | const Standard_Integer X, const Standard_Integer Y, |
95 | const Quantity_Color& aColor ) |
96 | { |
97 | const Handle(Visual3d_Layer) &theLayer = myLayerMgr->Overlay(); |
98 | if ( theLayer.IsNull() ) |
99 | return; |
100 | |
101 | theLayer->SetColor( aColor ); |
aff395a3 |
102 | theLayer->SetTextAttributes( Font_NOF_ASCII_MONO, Aspect_TODT_NORMAL, aColor ); |
7fd59977 |
103 | TCollection_AsciiString theText( aText.ToExtString(), '?' ); |
104 | Standard_Integer aTextH = GetTextHeight(); |
105 | Standard_Integer aWidth, anAscent, aDescent; |
106 | TextSize(aText, aTextH, aWidth, anAscent, aDescent); |
107 | theLayer->DrawText( theText.ToCString(), X, Y + anAscent, aTextH); |
108 | } |
109 | |
110 | Standard_Integer V3d_ColorScale::TextWidth( const TCollection_ExtendedString& aText ) const |
111 | { |
112 | Standard_Integer aWidth, anAscent, aDescent; |
113 | TextSize(aText, GetTextHeight(), aWidth, anAscent, aDescent); |
114 | return aWidth; |
115 | } |
116 | |
117 | Standard_Integer V3d_ColorScale::TextHeight( const TCollection_ExtendedString& aText ) const |
118 | { |
119 | Standard_Integer aWidth, anAscent, aDescent; |
120 | TextSize(aText, GetTextHeight(), aWidth, anAscent, aDescent); |
121 | return anAscent+aDescent; |
122 | } |
123 | |
124 | void V3d_ColorScale::TextSize (const TCollection_ExtendedString& AText, const Standard_Integer AHeight, Standard_Integer& AWidth, Standard_Integer& AnAscent, Standard_Integer& ADescent) const |
125 | { |
126 | const Handle(Visual3d_Layer) &theLayer = myLayerMgr->Overlay(); |
127 | if ( !theLayer.IsNull() ) { |
128 | Standard_Real aWidth, anAscent, aDescent; |
129 | TCollection_AsciiString theText( AText.ToExtString(), '?' ); |
130 | theLayer->TextSize(theText.ToCString(),AHeight,aWidth,anAscent,aDescent); |
131 | AWidth = (Standard_Integer)aWidth; |
132 | AnAscent = (Standard_Integer)anAscent; |
133 | ADescent = (Standard_Integer)aDescent; |
134 | } |
135 | else { |
136 | AWidth=AnAscent=ADescent=0; |
137 | } |
138 | } |
139 | |
140 | void V3d_ColorScale::DrawScale () |
141 | { |
142 | const Handle(V3d_View) &theView = myLayerMgr->View(); |
143 | if ( theView.IsNull() ) |
144 | return; |
145 | |
146 | const Handle(Aspect_Window) &theWin = theView->Window(); |
147 | if ( theWin.IsNull() ) |
148 | return; |
149 | |
150 | Standard_Integer WinWidth( 0 ), WinHeight( 0 ); |
151 | theWin->Size( WinWidth, WinHeight ); |
152 | |
153 | const Standard_Integer X = RealToInt(GetXPosition() * WinWidth); |
154 | const Standard_Integer Y = RealToInt(GetYPosition() * WinHeight); |
155 | |
156 | const Standard_Integer W = RealToInt(GetWidth() * WinWidth); |
157 | const Standard_Integer H = RealToInt(GetHeight() * WinHeight); |
158 | |
159 | Aspect_ColorScale::DrawScale( theView->BackgroundColor(), X, Y, W, H ); |
160 | } |