1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

0027573: AIS_ColorScale::FindColor does not take into account custom colors

Modified AIS_ColorScale::FindColor (Standard_Real, Quantity_Color&) to take into account custom colors
This commit is contained in:
aba
2016-08-02 14:48:45 +03:00
committed by bugmaster
parent 8cea17de84
commit d5514578e8
4 changed files with 109 additions and 2 deletions

View File

@@ -501,6 +501,32 @@ Standard_Integer AIS_ColorScale::HueFromValue (const Standard_Integer theValue,
Standard_Boolean AIS_ColorScale::FindColor (const Standard_Real theValue,
Quantity_Color& theColor) const
{
if (theValue < myMin || theValue > myMax || myMax < myMin)
{
theColor = Quantity_Color();
return Standard_False;
}
if (GetColorType() == Aspect_TOCSD_USER)
{
Standard_Integer anIndex = 0;
if (Abs (myMax - myMin) > Precision::Approximation())
{
anIndex = (theValue - myMin < Precision::Confusion())
? 1
: Standard_Integer (Ceiling (( theValue - myMin ) / ( (myMax - myMin) / myInterval)));
}
if (anIndex <= 0 || anIndex > myColors.Length())
{
theColor = Quantity_Color();
return Standard_False;
}
theColor = myColors.Value (anIndex);
return Standard_True;
}
return FindColor (theValue, myMin, myMax, myInterval, theColor);
}

View File

@@ -44,6 +44,7 @@ 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;
//! Calculate color according passed value; returns true if value is in range or false, if isn't
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;
@@ -280,13 +281,13 @@ private:
Standard_Real myMax;
TCollection_ExtendedString myTitle;
TCollection_AsciiString myFormat;
Standard_Integer myInterval;
Standard_Integer myInterval; //! Number of intervals
Aspect_TypeOfColorScaleData myColorType;
Aspect_TypeOfColorScaleData myLabelType;
Standard_Boolean myAtBorder;
Standard_Boolean myReversed;
Standard_Boolean myIsLogarithmic;
Aspect_SequenceOfColor myColors;
Aspect_SequenceOfColor myColors; //! Sequence of custom colors
TColStd_SequenceOfExtendedString myLabels;
Aspect_TypeOfColorScalePosition myLabelPos;
Aspect_TypeOfColorScalePosition myTitlePos;

View File

@@ -3986,6 +3986,27 @@ static int VColorScale (Draw_Interpretor& theDI,
aCS->SetColorType (Aspect_TOCSD_AUTO);
aCS->SetLabelType (Aspect_TOCSD_AUTO);
}
else if (aFlag == "-findcolor")
{
if (anArgIter + 1 >= theArgNb)
{
std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
return 1;
}
TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
if (!anArg1.IsRealValue())
{
std::cout << "Error: the value should be real!\n";
return 1;
}
Quantity_Color aColor;
aCS->FindColor (anArg1.RealValue(), aColor);
theDI << Quantity_Color::StringName (aColor.Name());
return 0;
}
else
{
std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";