Modified AIS_ColorScale::FindColor (Standard_Real, Quantity_Color&) to take into account custom colors
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);
}
//! 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;
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;
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";
--- /dev/null
+puts "============"
+puts "0027573"
+puts "AIS_ColorScale::FindColor does not take into account custom colors."
+puts "============"
+puts ""
+
+vclose all
+vinit
+vclear
+vaxo
+
+vcolorscale cs -demo
+vcolorscale cs -range 0 20 5
+
+# Set user-defined colors and labels for color scale
+vcolorscale cs -colors white red green blue1 gray
+
+# Check the first interval border color
+if {[vcolorscale cs -findcolor 0] != "WHITE"} {
+ puts "ERROR: Find color result for the first segment is wrong!"
+}
+
+# Check first-second intervals border
+if {[vcolorscale cs -findcolor 4] != "WHITE"} {
+ puts "ERROR: Find color result for the first segment border is wrong!"
+}
+
+# Check the second interval color
+if {[vcolorscale cs -findcolor 5] != "RED"} {
+ puts "ERROR: Find color result for the second segment is wrong!"
+}
+
+# Check the second interval color
+if {[vcolorscale cs -findcolor 9] != "GREEN"} {
+ puts "ERROR: Find color result for the third segment is wrong!"
+}
+
+# Check the last interval border color
+if {[vcolorscale cs -findcolor 20] != "GRAY"} {
+ puts "ERROR: Find color result for the last segment is wrong!"
+}
+
+# Check negative value limits
+vcolorscale cs -range -5 5 5
+
+if {[vcolorscale cs -findcolor -5] != "WHITE"} {
+ puts "ERROR: Find color result for the first segment is wrong!"
+}
+
+if {[vcolorscale cs -findcolor 0] != "GREEN"} {
+ puts "ERROR: Find color result for the middle segment is wrong!"
+}
+
+if {[vcolorscale cs -findcolor 5] != "GRAY"} {
+ puts "ERROR: Find color result for the last segment is wrong!"
+}
+
+# Dump result
+set only_screen 1
\ No newline at end of file