mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +03:00
0025785: Visualization - introduce AIS_ColorScale presentation for Color Scale
Color scale is implemented on AIS. Draw command vcolorscale now works with AIS_ColorScale. In a qt sample VoxelDemo there was added a field AIS_ColorScale myColorsScale to control a color scale. Method displayColorScale and other methods were changed in order to work with this field.
This commit is contained in:
@@ -1,637 +0,0 @@
|
||||
// Created on: 2004-06-22
|
||||
// Created by: STV
|
||||
// Copyright (c) 2004-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <Aspect_ColorScale.hxx>
|
||||
#include <Aspect_SequenceOfColor.hxx>
|
||||
#include <Aspect_TypeOfColorScaleData.hxx>
|
||||
#include <Aspect_TypeOfColorScalePosition.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <Quantity_Color.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <TColStd_SequenceOfExtendedString.hxx>
|
||||
|
||||
#include <stdio.h>
|
||||
Aspect_ColorScale::Aspect_ColorScale()
|
||||
: MMgt_TShared(),
|
||||
myMin( 0.0 ),
|
||||
myMax( 1.0 ),
|
||||
myTitle( "" ),
|
||||
myFormat( "%.4g" ),
|
||||
myInterval( 10 ),
|
||||
myColorType( Aspect_TOCSD_AUTO ),
|
||||
myLabelType( Aspect_TOCSD_AUTO ),
|
||||
myAtBorder( Standard_True ),
|
||||
myReversed( Standard_False ),
|
||||
myLabelPos( Aspect_TOCSP_RIGHT ),
|
||||
myTitlePos( Aspect_TOCSP_CENTER ),
|
||||
myXPos( 0 ),
|
||||
myYPos( 0 ),
|
||||
myWidth( 0.2 ),
|
||||
myHeight( 1 ),
|
||||
myTextHeight(20)
|
||||
{
|
||||
}
|
||||
|
||||
Standard_Real Aspect_ColorScale::GetMin() const
|
||||
{
|
||||
return myMin;
|
||||
}
|
||||
|
||||
Standard_Real Aspect_ColorScale::GetMax() const
|
||||
{
|
||||
return myMax;
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::GetRange (Standard_Real& theMin, Standard_Real& theMax) const
|
||||
{
|
||||
theMin = myMin;
|
||||
theMax = myMax;
|
||||
}
|
||||
|
||||
Aspect_TypeOfColorScaleData Aspect_ColorScale::GetLabelType() const
|
||||
{
|
||||
return myLabelType;
|
||||
}
|
||||
|
||||
Aspect_TypeOfColorScaleData Aspect_ColorScale::GetColorType() const
|
||||
{
|
||||
return myColorType;
|
||||
}
|
||||
|
||||
Standard_Integer Aspect_ColorScale::GetNumberOfIntervals() const
|
||||
{
|
||||
return myInterval;
|
||||
}
|
||||
|
||||
TCollection_ExtendedString Aspect_ColorScale::GetTitle() const
|
||||
{
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
TCollection_AsciiString Aspect_ColorScale::GetFormat() const
|
||||
{
|
||||
return myFormat;
|
||||
}
|
||||
|
||||
TCollection_ExtendedString Aspect_ColorScale::GetLabel (const Standard_Integer theIndex) const
|
||||
{
|
||||
if (GetLabelType() == Aspect_TOCSD_USER)
|
||||
{
|
||||
if (theIndex < 0
|
||||
|| theIndex >= myLabels.Length())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return myLabels.Value (theIndex + 1);
|
||||
}
|
||||
|
||||
const Standard_Real aVal = GetNumber (theIndex);
|
||||
const TCollection_AsciiString aFormat = Format();
|
||||
Standard_Character aBuf[1024];
|
||||
sprintf (aBuf, aFormat.ToCString(), aVal);
|
||||
return TCollection_ExtendedString (aBuf);
|
||||
}
|
||||
|
||||
Quantity_Color Aspect_ColorScale::GetColor (const Standard_Integer theIndex) const
|
||||
{
|
||||
if (GetColorType() == Aspect_TOCSD_USER)
|
||||
{
|
||||
if (theIndex < 0
|
||||
|| theIndex >= myColors.Length())
|
||||
{
|
||||
return Quantity_Color();
|
||||
}
|
||||
|
||||
return myColors.Value (theIndex + 1);
|
||||
}
|
||||
return Quantity_Color (HueFromValue (theIndex, 0, GetNumberOfIntervals() - 1), 1.0, 1.0, Quantity_TOC_HLS);
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::GetLabels (TColStd_SequenceOfExtendedString& theLabels) const
|
||||
{
|
||||
theLabels.Clear();
|
||||
for (Standard_Integer i = 1; i <= myLabels.Length(); i++)
|
||||
theLabels.Append (myLabels.Value (i));
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::GetColors (Aspect_SequenceOfColor& theColors) const
|
||||
{
|
||||
theColors.Clear();
|
||||
for (Standard_Integer i = 1; i <= myColors.Length(); i++)
|
||||
theColors.Append (myColors.Value (i));
|
||||
}
|
||||
|
||||
Aspect_TypeOfColorScalePosition Aspect_ColorScale::GetLabelPosition() const
|
||||
{
|
||||
return myLabelPos;
|
||||
}
|
||||
|
||||
Aspect_TypeOfColorScalePosition Aspect_ColorScale::GetTitlePosition() const
|
||||
{
|
||||
return myTitlePos;
|
||||
}
|
||||
|
||||
Standard_Boolean Aspect_ColorScale::IsReversed() const
|
||||
{
|
||||
return myReversed;
|
||||
}
|
||||
|
||||
Standard_Boolean Aspect_ColorScale::IsLabelAtBorder() const
|
||||
{
|
||||
return myAtBorder;
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetMin (const Standard_Real theMin)
|
||||
{
|
||||
SetRange (theMin, GetMax());
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetMax (const Standard_Real theMax)
|
||||
{
|
||||
SetRange (GetMin(), theMax);
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetRange (const Standard_Real theMin, const Standard_Real theMax)
|
||||
{
|
||||
if (myMin == theMin && myMax == theMax)
|
||||
return;
|
||||
|
||||
myMin = Min( theMin, theMax );
|
||||
myMax = Max( theMin, theMax );
|
||||
|
||||
if (GetColorType() == Aspect_TOCSD_AUTO)
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetLabelType (const Aspect_TypeOfColorScaleData theType)
|
||||
{
|
||||
if (myLabelType == theType)
|
||||
return;
|
||||
|
||||
myLabelType = theType;
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetColorType (const Aspect_TypeOfColorScaleData theType)
|
||||
{
|
||||
if (myColorType == theType)
|
||||
return;
|
||||
|
||||
myColorType = theType;
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetNumberOfIntervals (const Standard_Integer theNum)
|
||||
{
|
||||
if (myInterval == theNum || theNum < 1)
|
||||
return;
|
||||
|
||||
myInterval = theNum;
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetTitle (const TCollection_ExtendedString& theTitle)
|
||||
{
|
||||
if (myTitle == theTitle)
|
||||
return;
|
||||
|
||||
myTitle = theTitle;
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetFormat (const TCollection_AsciiString& theFormat)
|
||||
{
|
||||
if (myFormat == theFormat)
|
||||
return;
|
||||
|
||||
myFormat = theFormat;
|
||||
if (GetLabelType() == Aspect_TOCSD_AUTO)
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer theIndex)
|
||||
{
|
||||
Standard_Boolean changed = Standard_False;
|
||||
Standard_Integer i = theIndex < 0 ? myLabels.Length() + 1 : theIndex + 1;
|
||||
if (i <= myLabels.Length()) {
|
||||
changed = myLabels.Value (i) != theLabel;
|
||||
myLabels.SetValue (i, theLabel);
|
||||
}
|
||||
else {
|
||||
changed = Standard_True;
|
||||
while (i > myLabels.Length())
|
||||
myLabels.Append (TCollection_ExtendedString());
|
||||
myLabels.SetValue (i, theLabel);
|
||||
}
|
||||
if (changed)
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetColor (const Quantity_Color& theColor, const Standard_Integer theIndex)
|
||||
{
|
||||
Standard_Boolean changed = Standard_False;
|
||||
Standard_Integer i = theIndex < 0 ? myColors.Length() + 1 : theIndex + 1;
|
||||
if (i <= myColors.Length()) {
|
||||
changed = myColors.Value (i) != theColor;
|
||||
myColors.SetValue (i, theColor);
|
||||
}
|
||||
else {
|
||||
changed = Standard_True;
|
||||
while ( i > myColors.Length() )
|
||||
myColors.Append (Quantity_Color());
|
||||
myColors.SetValue (i, theColor);
|
||||
}
|
||||
if (changed)
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetLabels (const TColStd_SequenceOfExtendedString& theSeq)
|
||||
{
|
||||
myLabels.Clear();
|
||||
for (Standard_Integer i = 1; i <= theSeq.Length(); i++)
|
||||
myLabels.Append (theSeq.Value (i));
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetColors (const Aspect_SequenceOfColor& theSeq)
|
||||
{
|
||||
myColors.Clear();
|
||||
for (Standard_Integer i = 1; i <= theSeq.Length(); i++)
|
||||
myColors.Append (theSeq.Value (i));
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos)
|
||||
{
|
||||
if (myLabelPos == thePos)
|
||||
return;
|
||||
|
||||
myLabelPos = thePos;
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos)
|
||||
{
|
||||
if (myTitlePos == thePos)
|
||||
return;
|
||||
|
||||
myTitlePos = thePos;
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetReversed (const Standard_Boolean theReverse)
|
||||
{
|
||||
if (myReversed == theReverse)
|
||||
return;
|
||||
|
||||
myReversed = theReverse;
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetLabelAtBorder (const Standard_Boolean theOn)
|
||||
{
|
||||
if (myAtBorder == theOn)
|
||||
return;
|
||||
|
||||
myAtBorder = theOn;
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::GetPosition (Standard_Real& theX, Standard_Real& theY) const
|
||||
{
|
||||
theX = myXPos;
|
||||
theY = myYPos;
|
||||
}
|
||||
|
||||
Standard_Real Aspect_ColorScale::GetXPosition() const
|
||||
{
|
||||
return myXPos;
|
||||
}
|
||||
|
||||
Standard_Real Aspect_ColorScale::GetYPosition() const
|
||||
{
|
||||
return myYPos;
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetPosition (const Standard_Real theX, const Standard_Real theY)
|
||||
{
|
||||
if (myXPos == theX && myYPos == theY)
|
||||
return;
|
||||
|
||||
myXPos = theX;
|
||||
myYPos = theY;
|
||||
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetXPosition (const Standard_Real theX)
|
||||
{
|
||||
SetPosition (theX, GetYPosition());
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetYPosition (const Standard_Real theY)
|
||||
{
|
||||
SetPosition (GetXPosition(), theY);
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::GetSize (Standard_Real& theWidth, Standard_Real& theHeight) const
|
||||
{
|
||||
theWidth = myWidth;
|
||||
theHeight = myHeight;
|
||||
}
|
||||
|
||||
Standard_Real Aspect_ColorScale::GetWidth() const
|
||||
{
|
||||
return myWidth;
|
||||
}
|
||||
|
||||
Standard_Real Aspect_ColorScale::GetHeight() const
|
||||
{
|
||||
return myHeight;
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetSize (const Standard_Real theWidth, const Standard_Real theHeight)
|
||||
{
|
||||
if (myWidth == theWidth && myHeight == theHeight)
|
||||
return;
|
||||
|
||||
myWidth = theWidth;
|
||||
myHeight = theHeight;
|
||||
|
||||
UpdateColorScale();
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetWidth (const Standard_Real theWidth)
|
||||
{
|
||||
SetSize (theWidth, GetHeight());
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetHeight (const Standard_Real theHeight)
|
||||
{
|
||||
SetSize (GetWidth(), theHeight);
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const
|
||||
{
|
||||
Standard_Integer num = GetNumberOfIntervals();
|
||||
|
||||
Standard_Integer spacer = 5;
|
||||
Standard_Integer textWidth = 0;
|
||||
Standard_Integer textHeight = TextHeight ("");
|
||||
Standard_Integer colorWidth = 20;
|
||||
|
||||
if (GetLabelPosition() != Aspect_TOCSP_NONE)
|
||||
for (Standard_Integer idx = 0; idx < num; idx++)
|
||||
textWidth = Max (textWidth, TextWidth (GetLabel (idx + 1)));
|
||||
|
||||
Standard_Integer scaleWidth = 0;
|
||||
Standard_Integer scaleHeight = 0;
|
||||
|
||||
Standard_Integer titleWidth = 0;
|
||||
Standard_Integer titleHeight = 0;
|
||||
|
||||
if (IsLabelAtBorder()) {
|
||||
num++;
|
||||
if (GetTitle().Length())
|
||||
titleHeight += 10;
|
||||
}
|
||||
|
||||
scaleWidth = colorWidth + textWidth + ( textWidth ? 3 : 2 ) * spacer;
|
||||
scaleHeight = (Standard_Integer)( 1.5 * ( num + 1 ) * textHeight );
|
||||
|
||||
if (GetTitle().Length()) {
|
||||
titleHeight = TextHeight (GetTitle()) + spacer;
|
||||
titleWidth = TextWidth (GetTitle()) + 10;
|
||||
}
|
||||
|
||||
theWidth = Max (titleWidth, scaleWidth);
|
||||
theHeight = scaleHeight + titleHeight;
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::DrawScale ( const Quantity_Color& theBgColor,
|
||||
const Standard_Integer theX, const Standard_Integer theY,
|
||||
const Standard_Integer theWidth, const Standard_Integer theHeight)
|
||||
{
|
||||
if (!BeginPaint())
|
||||
return;
|
||||
|
||||
Standard_Integer num = GetNumberOfIntervals();
|
||||
Aspect_TypeOfColorScalePosition labPos = GetLabelPosition();
|
||||
|
||||
Standard_Integer spacer = 5;
|
||||
Standard_Integer textWidth = 0;
|
||||
Standard_Integer textHeight = TextHeight ("");
|
||||
|
||||
Standard_Boolean drawLabel = GetLabelPosition() != Aspect_TOCSP_NONE;
|
||||
|
||||
TCollection_ExtendedString aTitle = GetTitle();
|
||||
|
||||
Standard_Integer titleHeight = 0;
|
||||
|
||||
Standard_Integer aGray = (Standard_Integer)(255 * ( theBgColor.Red() * 11 + theBgColor.Green() * 16 + theBgColor.Blue() * 5 ) / 32);
|
||||
Quantity_Color aFgColor (aGray < 128 ? Quantity_NOC_WHITE : Quantity_NOC_BLACK);
|
||||
|
||||
// Draw title
|
||||
if (aTitle.Length()) {
|
||||
titleHeight = TextHeight (aTitle) + 2 * spacer;
|
||||
PaintText (aTitle, theX + spacer, theY + spacer, aFgColor);
|
||||
}
|
||||
|
||||
Standard_Boolean reverse = IsReversed();
|
||||
|
||||
Aspect_SequenceOfColor colors;
|
||||
TColStd_SequenceOfExtendedString labels;
|
||||
for (int idx = 0; idx < num; idx++) {
|
||||
if (reverse) {
|
||||
colors.Append (GetColor (idx));
|
||||
labels.Append (GetLabel (idx));
|
||||
}
|
||||
else {
|
||||
colors.Prepend (GetColor (idx));
|
||||
labels.Prepend (GetLabel (idx));
|
||||
}
|
||||
}
|
||||
|
||||
if (IsLabelAtBorder()) {
|
||||
if (reverse)
|
||||
labels.Append (GetLabel (num));
|
||||
else
|
||||
labels.Prepend (GetLabel (num));
|
||||
}
|
||||
|
||||
if (drawLabel)
|
||||
for (Standard_Integer i = 1; i <= labels.Length(); i++)
|
||||
textWidth = Max (textWidth, TextWidth (labels.Value (i)));
|
||||
|
||||
Standard_Integer lab = labels.Length();
|
||||
|
||||
Standard_Real spc = ( theHeight - ( ( Min (lab, 2) + Abs (lab - num - 1) ) * textHeight ) - titleHeight );
|
||||
Standard_Real val = spc != 0 ? 1.0 * ( lab - Min (lab, 1) ) * textHeight / spc : 0;
|
||||
Standard_Real iPart;
|
||||
Standard_Real fPart = modf (val, &iPart);
|
||||
Standard_Integer filter = (Standard_Integer)iPart + ( fPart != 0 ? 1 : 0 );
|
||||
|
||||
Standard_Real step = 1.0 * ( theHeight - ( lab - num + Abs (lab - num - 1) ) * textHeight - titleHeight ) / num;
|
||||
|
||||
Standard_Integer ascent = 0;
|
||||
Standard_Integer colorWidth = Max (5, Min (20, theWidth - textWidth - 3 * spacer));
|
||||
if (labPos == Aspect_TOCSP_CENTER || !drawLabel)
|
||||
colorWidth = theWidth - 2 * spacer;
|
||||
|
||||
// Draw colors
|
||||
Standard_Integer x = theX + spacer;
|
||||
if (labPos == Aspect_TOCSP_LEFT)
|
||||
x += textWidth + ( textWidth ? 1 : 0 ) * spacer;
|
||||
|
||||
Standard_Real offset = 1.0 * textHeight / 2 * ( lab - num + Abs (lab - num - 1) ) + titleHeight;
|
||||
for (Standard_Integer ci = 1; ci <= colors.Length() && step > 0; ci++ ) {
|
||||
Standard_Integer y = (Standard_Integer)( theY + ( ci - 1 )* step + offset);
|
||||
Standard_Integer h = (Standard_Integer)( theY + ( ci ) * step + offset ) - y;
|
||||
PaintRect (x, y, colorWidth, h, colors.Value (ci), Standard_True);
|
||||
}
|
||||
|
||||
if (step > 0)
|
||||
PaintRect (x - 1, (Standard_Integer)(theY + offset - 1), colorWidth + 2, (Standard_Integer)(colors.Length() * step + 2), aFgColor);
|
||||
|
||||
// Draw labels
|
||||
offset = 1.0 * Abs (lab - num - 1) * ( step - textHeight ) / 2 + 1.0 * Abs (lab - num - 1) * textHeight / 2;
|
||||
offset += titleHeight;
|
||||
if (drawLabel && labels.Length() && filter > 0) {
|
||||
Standard_Integer i1 = 0;
|
||||
Standard_Integer i2 = lab - 1;
|
||||
Standard_Integer last1 (i1), last2 (i2);
|
||||
x = theX + spacer;
|
||||
switch ( labPos ) {
|
||||
case Aspect_TOCSP_NONE:
|
||||
case Aspect_TOCSP_LEFT:
|
||||
break;
|
||||
case Aspect_TOCSP_CENTER:
|
||||
x += ( colorWidth - textWidth ) / 2;
|
||||
break;
|
||||
case Aspect_TOCSP_RIGHT:
|
||||
x += colorWidth + spacer;
|
||||
break;
|
||||
}
|
||||
while (i2 - i1 >= filter || ( i2 == 0 && i1 == 0 )) {
|
||||
Standard_Integer pos1 = i1;
|
||||
Standard_Integer pos2 = lab - 1 - i2;
|
||||
if (filter && !( pos1 % filter )) {
|
||||
PaintText (labels.Value (i1 + 1), x, (Standard_Integer)( theY + i1 * step + ascent + offset ), aFgColor);
|
||||
last1 = i1;
|
||||
}
|
||||
if (filter && !( pos2 % filter )) {
|
||||
PaintText (labels.Value (i2 + 1), x, (Standard_Integer)( theY + i2 * step + ascent + offset ), aFgColor);
|
||||
last2 = i2;
|
||||
}
|
||||
i1++;
|
||||
i2--;
|
||||
}
|
||||
Standard_Integer pos = i1;
|
||||
Standard_Integer i0 = -1;
|
||||
while (pos <= i2 && i0 == -1) {
|
||||
if (filter && !( pos % filter ) && Abs (pos - last1) >= filter && Abs (pos - last2) >= filter)
|
||||
i0 = pos;
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (i0 != -1)
|
||||
PaintText (labels.Value (i0 + 1), x, (Standard_Integer)( theY + i0 * step + ascent + offset ), aFgColor);
|
||||
}
|
||||
|
||||
EndPaint();
|
||||
}
|
||||
|
||||
Standard_Boolean Aspect_ColorScale::BeginPaint()
|
||||
{
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
Standard_Boolean Aspect_ColorScale::EndPaint()
|
||||
{
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::UpdateColorScale()
|
||||
{
|
||||
}
|
||||
|
||||
TCollection_AsciiString Aspect_ColorScale::Format() const
|
||||
{
|
||||
return GetFormat();
|
||||
}
|
||||
|
||||
Standard_Real Aspect_ColorScale::GetNumber (const Standard_Integer theIndex) const
|
||||
{
|
||||
Standard_Real aNum = 0;
|
||||
if (GetNumberOfIntervals() > 0)
|
||||
aNum = GetMin() + theIndex * ( Abs (GetMax() - GetMin()) / GetNumberOfIntervals() );
|
||||
return aNum;
|
||||
}
|
||||
|
||||
Standard_Integer Aspect_ColorScale::HueFromValue (const Standard_Integer theValue,
|
||||
const Standard_Integer theMin, const Standard_Integer theMax)
|
||||
{
|
||||
Standard_Integer minLimit (0), maxLimit (230);
|
||||
|
||||
Standard_Integer aHue = maxLimit;
|
||||
if (theMin != theMax)
|
||||
aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( theValue - theMin ) / ( theMax - theMin ) );
|
||||
|
||||
aHue = Min (Max (minLimit, aHue), maxLimit);
|
||||
|
||||
return aHue;
|
||||
}
|
||||
|
||||
Standard_Integer Aspect_ColorScale::GetTextHeight() const {
|
||||
return myTextHeight;
|
||||
}
|
||||
|
||||
void Aspect_ColorScale::SetTextHeight (const Standard_Integer theHeight) {
|
||||
myTextHeight = theHeight;
|
||||
UpdateColorScale ();
|
||||
}
|
||||
|
||||
|
||||
Standard_Boolean Aspect_ColorScale::FindColor (const Standard_Real theValue,
|
||||
Quantity_Color& theColor) const
|
||||
{
|
||||
return FindColor (theValue, myMin, myMax, myInterval, theColor);
|
||||
}
|
||||
|
||||
|
||||
Standard_Boolean Aspect_ColorScale::FindColor (const Standard_Real theValue,
|
||||
const Standard_Real theMin,
|
||||
const Standard_Real theMax,
|
||||
const Standard_Integer theColorsCount,
|
||||
Quantity_Color& theColor)
|
||||
{
|
||||
if(theValue<theMin || theValue>theMax || theMax<theMin)
|
||||
return Standard_False;
|
||||
|
||||
else
|
||||
{
|
||||
Standard_Real IntervNumber = 0;
|
||||
if(Abs (theMax-theMin) > Precision::Approximation())
|
||||
IntervNumber = Floor (Standard_Real( theColorsCount ) * ( theValue - theMin ) / ( theMax - theMin ));
|
||||
|
||||
Standard_Integer Interv = Standard_Integer (IntervNumber);
|
||||
|
||||
theColor = Quantity_Color (HueFromValue (Interv, 0, theColorsCount - 1), 1.0, 1.0, Quantity_TOC_HLS);
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
}
|
@@ -1,302 +0,0 @@
|
||||
// Created on: 2004-06-22
|
||||
// Created by: STV
|
||||
// Copyright (c) 2004-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Aspect_ColorScale_HeaderFile
|
||||
#define _Aspect_ColorScale_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
#include <Standard_Real.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
#include <Aspect_TypeOfColorScaleData.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Aspect_SequenceOfColor.hxx>
|
||||
#include <TColStd_SequenceOfExtendedString.hxx>
|
||||
#include <Aspect_TypeOfColorScalePosition.hxx>
|
||||
#include <MMgt_TShared.hxx>
|
||||
class Quantity_Color;
|
||||
class TCollection_ExtendedString;
|
||||
class TCollection_AsciiString;
|
||||
|
||||
|
||||
class Aspect_ColorScale;
|
||||
DEFINE_STANDARD_HANDLE(Aspect_ColorScale, MMgt_TShared)
|
||||
|
||||
//! Defines a color scale for viewer.
|
||||
class Aspect_ColorScale : public MMgt_TShared
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
//! Calculate color according passed value; returns true if value is in range or false, if isn't
|
||||
Standard_EXPORT Standard_Boolean FindColor (const Standard_Real theValue, Quantity_Color& theColor) const;
|
||||
|
||||
Standard_EXPORT static Standard_Boolean FindColor (const Standard_Real theValue, const Standard_Real theMin, const Standard_Real theMax, const Standard_Integer theColorsCount, Quantity_Color& theColor);
|
||||
|
||||
//! Returns minimal value of color scale;
|
||||
Standard_EXPORT Standard_Real GetMin() const;
|
||||
|
||||
//! Returns maximal value of color scale;
|
||||
Standard_EXPORT Standard_Real GetMax() const;
|
||||
|
||||
//! Returns minimal and maximal values of color scale;
|
||||
Standard_EXPORT void GetRange (Standard_Real& theMin, Standard_Real& theMax) const;
|
||||
|
||||
//! Returns the type of labels;
|
||||
//! Aspect_TOCSD_AUTO - labels as boundary values for intervals
|
||||
//! Aspect_TOCSD_USER - user specified label is used
|
||||
Standard_EXPORT Aspect_TypeOfColorScaleData GetLabelType() const;
|
||||
|
||||
//! Returns the type of colors;
|
||||
//! Aspect_TOCSD_AUTO - value between Red and Blue
|
||||
//! Aspect_TOCSD_USER - user specified color from color map
|
||||
Standard_EXPORT Aspect_TypeOfColorScaleData GetColorType() const;
|
||||
|
||||
//! Returns the number of color scale intervals;
|
||||
Standard_EXPORT Standard_Integer GetNumberOfIntervals() const;
|
||||
|
||||
//! Returns the color scale title string;
|
||||
Standard_EXPORT TCollection_ExtendedString GetTitle() const;
|
||||
|
||||
//! Returns the format for numbers.
|
||||
//! The same like format for function printf().
|
||||
//! Used if GetLabelType() is TOCSD_AUTO;
|
||||
Standard_EXPORT TCollection_AsciiString GetFormat() const;
|
||||
|
||||
//! Returns the user specified label with index <anIndex>.
|
||||
//! Returns empty string if label not defined.
|
||||
Standard_EXPORT TCollection_ExtendedString GetLabel (const Standard_Integer theIndex) const;
|
||||
|
||||
//! Returns the user specified color from color map with index <anIndex>.
|
||||
//! Returns default color if index out of range in color map.
|
||||
Standard_EXPORT Quantity_Color GetColor (const Standard_Integer theIndex) const;
|
||||
|
||||
//! Returns the user specified labels.
|
||||
Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
|
||||
|
||||
//! Returns the user specified colors.
|
||||
Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const;
|
||||
|
||||
//! Returns the position of labels concerning color filled rectangles.
|
||||
Standard_EXPORT Aspect_TypeOfColorScalePosition GetLabelPosition() const;
|
||||
|
||||
//! Returns the position of color scale title.
|
||||
Standard_EXPORT Aspect_TypeOfColorScalePosition GetTitlePosition() const;
|
||||
|
||||
//! Returns true if the labels and colors used in reversed order.
|
||||
Standard_EXPORT Standard_Boolean IsReversed() const;
|
||||
|
||||
//! Returns true if the labels placed at border of color filled rectangles.
|
||||
Standard_EXPORT Standard_Boolean IsLabelAtBorder() const;
|
||||
|
||||
//! Sets the minimal value of color scale.
|
||||
Standard_EXPORT void SetMin (const Standard_Real theMin);
|
||||
|
||||
//! Sets the maximal value of color scale.
|
||||
Standard_EXPORT void SetMax (const Standard_Real theMax);
|
||||
|
||||
//! Sets the minimal and maximal value of color scale.
|
||||
Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
|
||||
|
||||
//! Sets the type of labels.
|
||||
//! Aspect_TOCSD_AUTO - labels as boundary values for intervals
|
||||
//! Aspect_TOCSD_USER - user specified label is used
|
||||
Standard_EXPORT void SetLabelType (const Aspect_TypeOfColorScaleData theType);
|
||||
|
||||
//! Sets the type of colors.
|
||||
//! Aspect_TOCSD_AUTO - value between Red and Blue
|
||||
//! Aspect_TOCSD_USER - user specified color from color map
|
||||
Standard_EXPORT void SetColorType (const Aspect_TypeOfColorScaleData theType);
|
||||
|
||||
//! Sets the number of color scale intervals.
|
||||
Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
|
||||
|
||||
//! Sets the color scale title string.
|
||||
Standard_EXPORT void SetTitle (const TCollection_ExtendedString& theTitle);
|
||||
|
||||
//! Sets the color scale auto label format specification.
|
||||
Standard_EXPORT void SetFormat (const TCollection_AsciiString& theFormat);
|
||||
|
||||
//! Sets the color scale label at index. Index started from 1.
|
||||
Standard_EXPORT void SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer anIndex = -1);
|
||||
|
||||
//! Sets the color scale color at index. Index started from 1.
|
||||
Standard_EXPORT void SetColor (const Quantity_Color& theColor, const Standard_Integer theIndex = -1);
|
||||
|
||||
//! Sets the color scale labels.
|
||||
Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
|
||||
|
||||
//! Sets the color scale colors.
|
||||
Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
|
||||
|
||||
//! Sets the color scale labels position concerning color filled rectangles.
|
||||
Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos);
|
||||
|
||||
//! Sets the color scale title position.
|
||||
Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos);
|
||||
|
||||
//! Sets true if the labels and colors used in reversed order.
|
||||
Standard_EXPORT void SetReversed (const Standard_Boolean theReverse);
|
||||
|
||||
//! Sets true if the labels placed at border of color filled rectangles.
|
||||
Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
|
||||
|
||||
//! Returns the size of color scale.
|
||||
Standard_EXPORT void GetSize (Standard_Real& theWidth, Standard_Real& theHeight) const;
|
||||
|
||||
//! Returns the width of color scale.
|
||||
Standard_EXPORT Standard_Real GetWidth() const;
|
||||
|
||||
//! Returns the height of color scale.
|
||||
Standard_EXPORT Standard_Real GetHeight() const;
|
||||
|
||||
//! Sets the size of color scale.
|
||||
Standard_EXPORT void SetSize (const Standard_Real theWidth, const Standard_Real theHeight);
|
||||
|
||||
//! Sets the width of color scale.
|
||||
Standard_EXPORT void SetWidth (const Standard_Real theWidth);
|
||||
|
||||
//! Sets the height of color scale.
|
||||
Standard_EXPORT void SetHeight (const Standard_Real theHeight);
|
||||
|
||||
//! Returns the position of color scale.
|
||||
Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const;
|
||||
|
||||
//! Returns the X position of color scale.
|
||||
Standard_EXPORT Standard_Real GetXPosition() const;
|
||||
|
||||
//! Returns the height of color scale.
|
||||
Standard_EXPORT Standard_Real GetYPosition() const;
|
||||
|
||||
//! Sets the position of color scale.
|
||||
Standard_EXPORT void SetPosition (const Standard_Real theX, const Standard_Real theY);
|
||||
|
||||
//! Sets the X position of color scale.
|
||||
Standard_EXPORT void SetXPosition (const Standard_Real theX);
|
||||
|
||||
//! Sets the Y position of color scale.
|
||||
Standard_EXPORT void SetYPosition (const Standard_Real theY);
|
||||
|
||||
//! Returns the height of text of color scale.
|
||||
Standard_EXPORT Standard_Integer GetTextHeight() const;
|
||||
|
||||
//! Sets the height of text of color scale.
|
||||
Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight);
|
||||
|
||||
//! Draws a rectangle.
|
||||
//! @param theX [in] the X coordinate of rectangle position.
|
||||
//! @param theY [in] the Y coordinate of rectangle position.
|
||||
//! @param theWidth [in] the width of rectangle.
|
||||
//! @param theHeight [in] the height of rectangle.
|
||||
//! @param theColor [in] the color of rectangle.
|
||||
//! @param theFilled [in] defines if rectangle must be filled.
|
||||
Standard_EXPORT virtual void PaintRect (const Standard_Integer theX, const Standard_Integer theY, const Standard_Integer theWidth, const Standard_Integer theHeight, const Quantity_Color& theColor, const Standard_Boolean theFilled = Standard_False) = 0;
|
||||
|
||||
//! Draws a text.
|
||||
//! @param theText [in] the text to draw.
|
||||
//! @param theX [in] the X coordinate of text position.
|
||||
//! @param theY [in] the Y coordinate of text position.
|
||||
//! @param theColor [in] the color of text.
|
||||
Standard_EXPORT virtual void PaintText (const TCollection_ExtendedString& theText, const Standard_Integer theX, const Standard_Integer theY, const Quantity_Color& theColor) = 0;
|
||||
|
||||
//! Returns the width of text.
|
||||
//! @param theText [in] the text of which to calculate width.
|
||||
Standard_EXPORT virtual Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const = 0;
|
||||
|
||||
//! Returns the height of text.
|
||||
//! @param theText [in] the text of which to calculate height.
|
||||
Standard_EXPORT virtual Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_RTTI(Aspect_ColorScale,MMgt_TShared)
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
//! Default constructor.
|
||||
Standard_EXPORT Aspect_ColorScale();
|
||||
|
||||
//! Returns the size of color scale.
|
||||
//! @param theWidth [out] the width of color scale.
|
||||
//! @param theHeight [out] the height of color scale.
|
||||
Standard_EXPORT void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
|
||||
|
||||
//! updates color scale parameters.
|
||||
Standard_EXPORT virtual void UpdateColorScale();
|
||||
|
||||
//! Draws color scale.
|
||||
//! @param theBgColor [in] background color
|
||||
//! @param theX [in] the X coordinate of color scale position.
|
||||
//! @param theY [in] the Y coordinate of color scale position.
|
||||
//! @param theWidth [in] the width of color scale.
|
||||
//! @param theHeight [in] the height of color scale.
|
||||
Standard_EXPORT void DrawScale (const Quantity_Color& theBgColor, const Standard_Integer theX, const Standard_Integer theY, const Standard_Integer theWidth, const Standard_Integer theHeight);
|
||||
|
||||
Standard_EXPORT virtual Standard_Boolean BeginPaint();
|
||||
|
||||
Standard_EXPORT virtual Standard_Boolean EndPaint();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
//! Returns the format of text.
|
||||
Standard_EXPORT TCollection_AsciiString Format() const;
|
||||
|
||||
//! Returns the value of given interval.
|
||||
Standard_EXPORT Standard_Real GetNumber (const Standard_Integer theIndex) const;
|
||||
|
||||
//! Returns the color's hue for the given value in the given interval.
|
||||
//! @param theValue [in] the current value of interval.
|
||||
//! @param theMin [in] the min value of interval.
|
||||
//! @param theMax [in] the max value of interval.
|
||||
Standard_EXPORT static Standard_Integer HueFromValue (const Standard_Integer theValue, const Standard_Integer theMin, const Standard_Integer theMax);
|
||||
|
||||
Standard_Real myMin;
|
||||
Standard_Real myMax;
|
||||
TCollection_ExtendedString myTitle;
|
||||
TCollection_AsciiString myFormat;
|
||||
Standard_Integer myInterval;
|
||||
Aspect_TypeOfColorScaleData myColorType;
|
||||
Aspect_TypeOfColorScaleData myLabelType;
|
||||
Standard_Boolean myAtBorder;
|
||||
Standard_Boolean myReversed;
|
||||
Aspect_SequenceOfColor myColors;
|
||||
TColStd_SequenceOfExtendedString myLabels;
|
||||
Aspect_TypeOfColorScalePosition myLabelPos;
|
||||
Aspect_TypeOfColorScalePosition myTitlePos;
|
||||
Standard_Real myXPos;
|
||||
Standard_Real myYPos;
|
||||
Standard_Real myWidth;
|
||||
Standard_Real myHeight;
|
||||
Standard_Integer myTextHeight;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _Aspect_ColorScale_HeaderFile
|
@@ -13,8 +13,6 @@ Aspect_BadAccess.hxx
|
||||
Aspect_CircularGrid.cxx
|
||||
Aspect_CircularGrid.hxx
|
||||
Aspect_CLayer2d.hxx
|
||||
Aspect_ColorScale.cxx
|
||||
Aspect_ColorScale.hxx
|
||||
Aspect_Convert.hxx
|
||||
Aspect_Display.hxx
|
||||
Aspect_DisplayConnection.cxx
|
||||
|
Reference in New Issue
Block a user