1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-21 10:13:43 +03:00

0028004: Visualization, AIS_ColorScale - allow defining labels list not equal to intervals list

Cosmetics, code clean up.

AIS_ColorScale now draw labels using Graphic3d_VTA_CENTER
vertical alignment flag, instead of incorrect own alignment logic.
The color bar now adds margin on the top simmetrical to the bottom.

AIS_ColorScale::SetSmoothTransition() - added new property
for displaying colorscale with smooth transition between color intervals.

AIS_ColorScale::SetHueRange() - added new property defining the hue angles
corresponding to minimal and maximum values on the color scale.

AIS_ColorScale::SetLabels() now allows setting the sequence of free labels,
which number does not match the number of intervals.
In this case the labels will be displayed at positions of virtual
intervals corresponding to the number of labels.
This commit is contained in:
kgv 2016-12-22 12:39:13 +03:00 committed by apn
parent 09a4804444
commit 4b3d6eb1d2
5 changed files with 1175 additions and 920 deletions

File diff suppressed because it is too large Load Diff

View File

@ -33,8 +33,43 @@
//! Colors and labels can be either defined automatically or set by the user. //! Colors and labels can be either defined automatically or set by the user.
//! Automatic labels are calculated from numerical limits of the scale, //! Automatic labels are calculated from numerical limits of the scale,
//! its type (logarithmic or plain), and formatted by specified format string. //! its type (logarithmic or plain), and formatted by specified format string.
class AIS_ColorScale : public AIS_InteractiveObject
{
DEFINE_STANDARD_RTTIEXT(AIS_ColorScale, AIS_InteractiveObject)
public:
class AIS_ColorScale : public AIS_InteractiveObject { //! 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,
const Graphic3d_Vec3d& theColorHlsMin,
const Graphic3d_Vec3d& theColorHlsMax,
Quantity_Color& theColor);
//! Calculate color according passed value; returns true if value is in range or false, if isn't
static Standard_Boolean FindColor (const Standard_Real theValue,
const Standard_Real theMin,
const Standard_Real theMax,
const Standard_Integer theColorsCount,
Quantity_Color& theColor)
{
return FindColor (theValue, theMin, theMax, theColorsCount,
Graphic3d_Vec3d (230.0, 1.0, 1.0),
Graphic3d_Vec3d (0.0, 1.0, 1.0),
theColor);
}
//! Shift hue into valid range.
//! Lightness and Saturation should be specified in valid range [0.0, 1.0],
//! however Hue might be given out of Quantity_Color range to specify desired range for interpolation.
static Standard_Real hueToValidRange (const Standard_Real theHue)
{
Standard_Real aHue = theHue;
while (aHue < 0.0) { aHue += 360.0; }
while (aHue > 360.0) { aHue -= 360.0; }
return aHue;
}
public: public:
@ -44,38 +79,111 @@ public:
//! Calculate color according passed value; returns true if value is in range or false, if isn't //! 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 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 //! Returns minimal value of color scale, 0.0 by default.
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); Standard_Real GetMin() const { return myMin; }
//! Returns minimal value of color scale; //! Sets the minimal value of color scale.
Standard_EXPORT Standard_Real GetMin() const { return myMin; } void SetMin (const Standard_Real theMin) { SetRange (theMin, GetMax()); }
//! Returns maximal value of color scale; //! Returns maximal value of color scale, 1.0 by default.
Standard_EXPORT Standard_Real GetMax() const { return myMax; } Standard_Real GetMax() const { return myMax; }
//! Returns minimal and maximal values of color scale; //! Sets the maximal value of color scale.
Standard_EXPORT void GetRange (Standard_Real& theMin, Standard_Real& theMax) const; void SetMax (const Standard_Real theMax) { SetRange (GetMin(), theMax); }
//! Returns the type of labels; //! Returns minimal and maximal values of color scale, 0.0 to 1.0 by default.
void GetRange (Standard_Real& theMin, Standard_Real& theMax) const
{
theMin = myMin;
theMax = myMax;
}
//! Sets the minimal and maximal value of color scale.
//! Note that values order will be ignored - the minimum and maximum values will be swapped if needed.
//! ::SetReversed() should be called to swap displaying order.
Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
//! Returns the hue angle corresponding to minimum value, 230 by default (blue).
Standard_Real HueMin() const { return myColorHlsMin[0]; }
//! Returns the hue angle corresponding to maximum value, 0 by default (red).
Standard_Real HueMax() const { return myColorHlsMax[0]; }
//! Returns the hue angle range corresponding to minimum and maximum values, 230 to 0 by default (blue to red).
void HueRange (Standard_Real& theMinAngle,
Standard_Real& theMaxAngle) const
{
theMinAngle = myColorHlsMin[0];
theMaxAngle = myColorHlsMax[0];
}
//! Sets hue angle range corresponding to minimum and maximum values.
//! The valid angle range is [0, 360], see Quantity_Color and Quantity_TOC_HLS for more details.
void SetHueRange (const Standard_Real theMinAngle,
const Standard_Real theMaxAngle)
{
myColorHlsMin[0] = theMinAngle;
myColorHlsMax[0] = theMaxAngle;
}
//! Returns color range corresponding to minimum and maximum values, blue to red by default.
void ColorRange (Quantity_Color& theMinColor,
Quantity_Color& theMaxColor) const
{
theMinColor.SetValues (hueToValidRange (myColorHlsMin[0]), myColorHlsMin[1], myColorHlsMin[2], Quantity_TOC_HLS);
theMaxColor.SetValues (hueToValidRange (myColorHlsMin[0]), myColorHlsMin[1], myColorHlsMin[2], Quantity_TOC_HLS);
}
//! Sets color range corresponding to minimum and maximum values.
void SetColorRange (const Quantity_Color& theMinColor,
const Quantity_Color& theMaxColor)
{
theMinColor.Values (myColorHlsMin[0], myColorHlsMin[1], myColorHlsMin[2], Quantity_TOC_HLS);
theMaxColor.Values (myColorHlsMax[0], myColorHlsMax[1], myColorHlsMax[2], Quantity_TOC_HLS);
}
//! Returns the type of labels, Aspect_TOCSD_AUTO by default.
//! Aspect_TOCSD_AUTO - labels as boundary values for intervals //! Aspect_TOCSD_AUTO - labels as boundary values for intervals
//! Aspect_TOCSD_USER - user specified label is used //! Aspect_TOCSD_USER - user specified label is used
Standard_EXPORT Aspect_TypeOfColorScaleData GetLabelType() const { return myLabelType; } Aspect_TypeOfColorScaleData GetLabelType() const { return myLabelType; }
//! Returns the type of colors; //! Sets the type of labels.
//! Aspect_TOCSD_AUTO - labels as boundary values for intervals
//! Aspect_TOCSD_USER - user specified label is used
void SetLabelType (const Aspect_TypeOfColorScaleData theType) { myLabelType = theType; }
//! Returns the type of colors, Aspect_TOCSD_AUTO by default.
//! Aspect_TOCSD_AUTO - value between Red and Blue //! Aspect_TOCSD_AUTO - value between Red and Blue
//! Aspect_TOCSD_USER - user specified color from color map //! Aspect_TOCSD_USER - user specified color from color map
Standard_EXPORT Aspect_TypeOfColorScaleData GetColorType() const { return myColorType; } Aspect_TypeOfColorScaleData GetColorType() const { return myColorType; }
//! Returns the number of color scale intervals; //! Sets the type of colors.
Standard_EXPORT Standard_Integer GetNumberOfIntervals() const { return myInterval; } //! Aspect_TOCSD_AUTO - value between Red and Blue
//! Aspect_TOCSD_USER - user specified color from color map
void SetColorType (const Aspect_TypeOfColorScaleData theType) { myColorType = theType; }
//! Returns the color scale title string; //! Returns the number of color scale intervals, 10 by default.
Standard_EXPORT TCollection_ExtendedString GetTitle() const { return myTitle; } Standard_Integer GetNumberOfIntervals() const { return myNbIntervals; }
//! Returns the format for numbers. //! Sets the number of color scale intervals.
Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
//! Returns the color scale title string, empty string by default.
const TCollection_ExtendedString& GetTitle() const { return myTitle; }
//! Sets the color scale title string.
void SetTitle (const TCollection_ExtendedString& theTitle) { myTitle = theTitle; }
//! Returns the format for numbers, "%.4g" by default.
//! The same like format for function printf(). //! The same like format for function printf().
//! Used if GetLabelType() is TOCSD_AUTO; //! Used if GetLabelType() is TOCSD_AUTO;
Standard_EXPORT TCollection_AsciiString GetFormat() const { return myFormat; } const TCollection_AsciiString& GetFormat() const { return myFormat; }
//! Returns the format of text.
const TCollection_AsciiString& Format() const { return myFormat; }
//! Sets the color scale auto label format specification.
void SetFormat (const TCollection_AsciiString& theFormat) { myFormat = theFormat; }
//! Returns the user specified label with index theIndex. //! Returns the user specified label with index theIndex.
//! Index is in range from 1 to GetNumberOfIntervals() or to //! Index is in range from 1 to GetNumberOfIntervals() or to
@ -83,134 +191,154 @@ public:
//! Returns empty string if label not defined. //! Returns empty string if label not defined.
Standard_EXPORT TCollection_ExtendedString GetLabel (const Standard_Integer theIndex) const; Standard_EXPORT TCollection_ExtendedString GetLabel (const Standard_Integer theIndex) const;
//! Returns the user specified color from color map with index <anIndex> (starts at 1). //! Returns the user specified color from color map with index (starts at 1).
//! Returns default color if index is out of range in color map. //! Returns default color if index is out of range in color map.
Standard_EXPORT Quantity_Color GetIntervalColor (const Standard_Integer theIndex) const; Standard_EXPORT Quantity_Color GetIntervalColor (const Standard_Integer theIndex) const;
//! Sets the color of the specified interval.
//! Note that list is automatically resized to include specified index.
//! @param theColor color value to set
//! @param theIndex index in range [1, GetNumberOfIntervals()];
//! appended to the end of list if -1 is specified
Standard_EXPORT void SetIntervalColor (const Quantity_Color& theColor, const Standard_Integer theIndex);
//! Returns the user specified labels. //! Returns the user specified labels.
Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const; Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
//! Returns the user specified labels.
const TColStd_SequenceOfExtendedString& Labels() const { return myLabels; }
//! Sets the color scale labels.
//! The length of the sequence should be equal to GetNumberOfIntervals() or to GetNumberOfIntervals() + 1 if IsLabelAtBorder() is true.
//! If length of the sequence does not much the number of intervals,
//! then these labels will be considered as "free" and will be located
//! at the virtual intervals corresponding to the number of labels
//! (with flag IsLabelAtBorder() having the same effect as in normal case).
Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
//! Returns the user specified colors. //! Returns the user specified colors.
Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const; Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const;
//! Returns the position of labels concerning color filled rectangles. //! Returns the user specified colors.
Standard_EXPORT Aspect_TypeOfColorScalePosition GetLabelPosition() const { return myLabelPos; } const Aspect_SequenceOfColor& GetColors() const { return myColors; }
//! Returns the position of color scale title.
Standard_EXPORT Aspect_TypeOfColorScalePosition GetTitlePosition() const { return myTitlePos; }
//! Returns true if the labels and colors used in reversed order.
Standard_EXPORT Standard_Boolean IsReversed() const { return myReversed; }
//! Returns true if the labels are placed at border of color intervals.
Standard_EXPORT Standard_Boolean IsLabelAtBorder() const { return myAtBorder; }
//! Returns true if the color scale has logarithmic intervals
Standard_Boolean IsLogarithmic() const { return myIsLogarithmic; }
//! 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 is in range from 1 to GetNumberOfIntervals() or to
//! GetNumberOfIntervals() + 1 if IsLabelAtBorder() is true.
Standard_EXPORT void SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer anIndex);
//! Sets the color of the specified interval.
//! Index is in range from 1 to GetNumberOfIntervals().
Standard_EXPORT void SetIntervalColor (const Quantity_Color& theColor, const Standard_Integer theIndex);
//! Sets the color scale labels.
//! The length of the sequence should be equal to GetNumberOfIntervals() or to
//! GetNumberOfIntervals() + 1 if IsLabelAtBorder() is true.
Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
//! Sets the color scale colors. //! Sets the color scale colors.
//! The length of the sequence should be equal to GetNumberOfIntervals(). //! The length of the sequence should be equal to GetNumberOfIntervals().
Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq); Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
//! Returns the position of labels concerning color filled rectangles, Aspect_TOCSP_RIGHT by default.
Aspect_TypeOfColorScalePosition GetLabelPosition() const { return myLabelPos; }
//! Sets the color scale labels position relative to color bar. //! Sets the color scale labels position relative to color bar.
Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos); void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos) { myLabelPos = thePos; }
//! Returns the position of color scale title, Aspect_TOCSP_LEFT by default.
Aspect_TypeOfColorScalePosition GetTitlePosition() const { return myTitlePos; }
//! Sets the color scale title position. //! Sets the color scale title position.
Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos); Standard_DEPRECATED("AIS_ColorScale::SetTitlePosition() has no effect!")
void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos) { myTitlePos = thePos; }
//! Returns TRUE if the labels and colors used in reversed order, FALSE by default.
//! - Normal, bottom-up order with Minimal value on the Bottom and Maximum value on Top.
//! - Reversed, top-down order with Maximum value on the Bottom and Minimum value on Top.
Standard_Boolean IsReversed() const { return myIsReversed; }
//! Sets true if the labels and colors used in reversed order. //! Sets true if the labels and colors used in reversed order.
Standard_EXPORT void SetReversed (const Standard_Boolean theReverse); void SetReversed (const Standard_Boolean theReverse) { myIsReversed = theReverse; }
//! Sets true if the labels are placed at border of color intervals (true by default). //! Return TRUE if color transition between neighbor intervals
//! should be linearly interpolated, FALSE by default.
Standard_Boolean IsSmoothTransition() const { return myIsSmooth; }
//! Setup smooth color transition.
void SetSmoothTransition (const Standard_Boolean theIsSmooth) { myIsSmooth = theIsSmooth; }
//! Returns TRUE if the labels are placed at border of color intervals, TRUE by default.
//! The automatically generated label will show value exactly on the current position:
//! - value connecting two neighbor intervals (TRUE)
//! - value in the middle of interval (FALSE)
Standard_Boolean IsLabelAtBorder() const { return myIsLabelAtBorder; }
//! Sets true if the labels are placed at border of color intervals (TRUE by default).
//! If set to False, labels will be drawn at color intervals rather than at borders. //! If set to False, labels will be drawn at color intervals rather than at borders.
Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn); void SetLabelAtBorder (const Standard_Boolean theOn) { myIsLabelAtBorder = theOn; }
//! Returns TRUE if the color scale has logarithmic intervals, FALSE by default.
Standard_Boolean IsLogarithmic() const { return myIsLogarithmic; }
//! Sets true if the color scale has logarithmic intervals. //! Sets true if the color scale has logarithmic intervals.
void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; }; void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; }
//! Returns the size of color bar. //! Sets the color scale label at index.
Standard_EXPORT void GetSize (Standard_Integer& theBreadth, Standard_Integer& theHeight) const; //! Note that list is automatically resized to include specified index.
//! @param theLabel new label text
//! @param theIndex index in range [1, GetNumberOfIntervals()] or [1, GetNumberOfIntervals() + 1] if IsLabelAtBorder() is true;
//! label is appended to the end of list if negative index is specified
Standard_EXPORT void SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer theIndex);
//! Returns the breadth of color bar. //! Returns the size of color bar, 0 and 0 by default
Standard_EXPORT Standard_Integer GetBreadth() const { return myBreadth; } //! (e.g. should be set by user explicitly before displaying).
void GetSize (Standard_Integer& theBreadth, Standard_Integer& theHeight) const
//! Returns the height of color bar. {
Standard_EXPORT Standard_Integer GetHeight() const { return myHeight; } theBreadth = myBreadth;
theHeight = myHeight;
}
//! Sets the size of color bar. //! Sets the size of color bar.
Standard_EXPORT void SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight); void SetSize (const Standard_Integer theBreadth, const Standard_Integer theHeight)
{
myBreadth = theBreadth;
myHeight = theHeight;
}
//! Returns the breadth of color bar, 0 by default
//! (e.g. should be set by user explicitly before displaying).
Standard_Integer GetBreadth() const { return myBreadth; }
//! Sets the width of color bar. //! Sets the width of color bar.
Standard_EXPORT void SetBreadth (const Standard_Integer theBreadth); void SetBreadth (const Standard_Integer theBreadth) { myBreadth = theBreadth; }
//! Returns the height of color bar, 0 by default
//! (e.g. should be set by user explicitly before displaying).
Standard_Integer GetHeight() const { return myHeight; }
//! Sets the height of color bar. //! Sets the height of color bar.
Standard_EXPORT void SetHeight (const Standard_Integer theHeight); void SetHeight (const Standard_Integer theHeight) { myHeight = theHeight; }
//! Returns the position of color scale. //! Returns the bottom-left position of color scale, 0x0 by default.
Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const; void GetPosition (Standard_Real& theX, Standard_Real& theY) const
{
//! Returns the X position of color scale. theX = myXPos;
Standard_EXPORT Standard_Integer GetXPosition() const { return myXPos; } theY = myYPos;
}
//! Returns the height of color scale.
Standard_EXPORT Standard_Integer GetYPosition() const { return myYPos; }
//! Sets the position of color scale. //! Sets the position of color scale.
Standard_EXPORT void SetPosition (const Standard_Integer theX, const Standard_Integer theY); void SetPosition (const Standard_Integer theX, const Standard_Integer theY)
{
myXPos = theX;
myYPos = theY;
}
//! Sets the X position of color scale. //! Returns the left position of color scale, 0 by default.
Standard_EXPORT void SetXPosition (const Standard_Integer theX); Standard_Integer GetXPosition() const { return myXPos; }
//! Sets the Y position of color scale. //! Sets the left position of color scale.
Standard_EXPORT void SetYPosition (const Standard_Integer theY); void SetXPosition (const Standard_Integer theX) { myXPos = theX; }
//! Returns the height of text of color scale. //! Returns the bottom position of color scale, 0 by default.
Standard_EXPORT Standard_Integer GetTextHeight() const { return myTextHeight; } Standard_Integer GetYPosition() const { return myYPos; }
//! Sets the bottom position of color scale.
void SetYPosition (const Standard_Integer theY) { myYPos = theY; }
//! Returns the font height of text labels, 20 by default.
Standard_Integer GetTextHeight() const { return myTextHeight; }
//! Sets the height of text of color scale. //! Sets the height of text of color scale.
Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; } void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; }
public:
//! Returns the width of text. //! Returns the width of text.
//! @param theText [in] the text of which to calculate width. //! @param theText [in] the text of which to calculate width.
@ -220,33 +348,25 @@ public:
//! @param theText [in] the text of which to calculate height. //! @param theText [in] the text of which to calculate height.
Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const; Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const;
Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const; Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText,
const Standard_Integer theHeight,
Standard_Integer& theWidth,
Standard_Integer& theAscent,
Standard_Integer& theDescent) const;
public:
DEFINE_STANDARD_RTTIEXT(AIS_ColorScale,AIS_InteractiveObject) //! Return true if specified display mode is supported.
virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
protected: //! Compute presentation.
Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode) Standard_OVERRIDE;
//! Draws a frame. //! Compute selection - not implemented for color scale.
//! @param theX [in] the X coordinate of frame position. virtual void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
//! @param theY [in] the Y coordinate of frame position. const Standard_Integer /*aMode*/) Standard_OVERRIDE {}
//! @param theWidth [in] the width of frame.
//! @param theHeight [in] the height of frame.
//! @param theColor [in] the color of frame.
Standard_EXPORT void drawFrame (const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theX, const Standard_Integer theY,
const Standard_Integer theWidth, const Standard_Integer theHeight,
const Quantity_Color& theColor);
//! 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 void drawText (const Handle(Prs3d_Presentation)& thePresentation,
const TCollection_ExtendedString& theText,
const Standard_Integer theX, const Standard_Integer theY,
const Quantity_Color& theColor);
private: private:
@ -255,47 +375,86 @@ private:
//! @param theHeight [out] the height of color scale. //! @param theHeight [out] the height of color scale.
void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const; void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode) Standard_OVERRIDE;
void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
const Standard_Integer /*aMode*/) Standard_OVERRIDE
{}
//! Returns the format of text.
TCollection_AsciiString Format() const;
//! Returns the upper value of given interval, or minimum for theIndex = 0. //! Returns the upper value of given interval, or minimum for theIndex = 0.
Standard_Real GetIntervalValue (const Standard_Integer theIndex) const; Standard_Real GetIntervalValue (const Standard_Integer theIndex) const;
//! Returns the color's hue for the given value in the given interval. //! Returns the color for the given value in the given interval.
//! @param theValue [in] the current value of interval. //! @param theValue [in] the current value of interval
//! @param theMin [in] the min value of interval. //! @param theMin [in] the min value of interval
//! @param theMax [in] the max value of interval. //! @param theMax [in] the max value of interval
static Standard_Integer HueFromValue (const Standard_Integer theValue, const Standard_Integer theMin, const Standard_Integer theMax); Quantity_Color colorFromValue (const Standard_Real theValue,
const Standard_Real theMin,
const Standard_Real theMax) const;
//! Initialize text aspect for drawing the labels.
void updateTextAspect();
//! Simple alias for Prs3d_Text::Draw().
//! @param theGroup [in] presentation group
//! @param theText [in] text to draw
//! @param theX [in] X coordinate of text position
//! @param theY [in] Y coordinate of text position
//! @param theVertAlignment [in] text vertical alignment
void drawText (const Handle(Graphic3d_Group)& theGroup,
const TCollection_ExtendedString& theText,
const Standard_Integer theX, const Standard_Integer theY,
const Graphic3d_VerticalTextAlignment theVertAlignment);
//! Determine the maximum text label width in pixels.
Standard_Integer computeMaxLabelWidth (const TColStd_SequenceOfExtendedString& theLabels) const;
//! Draw labels.
void drawLabels (const Handle(Prs3d_Presentation)& thePrs,
const TColStd_SequenceOfExtendedString& theLabels,
const Standard_Integer theBarBottom,
const Standard_Integer theBarHeight,
const Standard_Integer theMaxLabelWidth,
const Standard_Integer theColorBreadth);
//! Draw a color bar.
void drawColorBar (const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theBarBottom,
const Standard_Integer theBarHeight,
const Standard_Integer theMaxLabelWidth,
const Standard_Integer theColorBreadth);
//! Draw a frame.
//! @param theX [in] the X coordinate of frame position.
//! @param theY [in] the Y coordinate of frame position.
//! @param theWidth [in] the width of frame.
//! @param theHeight [in] the height of frame.
//! @param theColor [in] the color of frame.
void drawFrame (const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theX, const Standard_Integer theY,
const Standard_Integer theWidth, const Standard_Integer theHeight,
const Quantity_Color& theColor);
private: private:
Standard_Real myMin; Standard_Real myMin; //!< values range - minimal value
Standard_Real myMax; Standard_Real myMax; //!< values range - maximal value
TCollection_ExtendedString myTitle; Graphic3d_Vec3d myColorHlsMin; //!< HLS color corresponding to minimum value
TCollection_AsciiString myFormat; Graphic3d_Vec3d myColorHlsMax; //!< HLS color corresponding to maximum value
Standard_Integer myInterval; //! Number of intervals TCollection_ExtendedString myTitle; //!< optional title string
Aspect_TypeOfColorScaleData myColorType; TCollection_AsciiString myFormat; //!< sprintf() format for generating label from value
Aspect_TypeOfColorScaleData myLabelType; Standard_Integer myNbIntervals; //!< number of intervals
Standard_Boolean myAtBorder; Aspect_TypeOfColorScaleData myColorType; //!< color type
Standard_Boolean myReversed; Aspect_TypeOfColorScaleData myLabelType; //!< label type
Standard_Boolean myIsLogarithmic; Standard_Boolean myIsLabelAtBorder; //!< at border
Aspect_SequenceOfColor myColors; //! Sequence of custom colors Standard_Boolean myIsReversed; //!< flag indicating reversed order
TColStd_SequenceOfExtendedString myLabels; Standard_Boolean myIsLogarithmic; //!< flag indicating logarithmic scale
Aspect_TypeOfColorScalePosition myLabelPos; Standard_Boolean myIsSmooth; //!< flag indicating smooth transition between the colors
Aspect_TypeOfColorScalePosition myTitlePos; Aspect_SequenceOfColor myColors; //!< sequence of custom colors
Standard_Integer myXPos; TColStd_SequenceOfExtendedString myLabels; //!< sequence of custom text labels
Standard_Integer myYPos; Aspect_TypeOfColorScalePosition myLabelPos; //!< label position relative to the color scale
Standard_Integer myBreadth; Aspect_TypeOfColorScalePosition myTitlePos; //!< title position
Standard_Integer myHeight; Standard_Integer myXPos; //!< left position
Standard_Integer myTextHeight; Standard_Integer myYPos; //!< bottom position
Quantity_Color myBgColor; Standard_Integer myBreadth; //!< color scale breadth
Standard_Integer myHeight; //!< height of the color scale
Standard_Integer mySpacing; //!< extra spacing between element
Standard_Integer myTextHeight; //!< label font height
}; };
#endif #endif

View File

@ -3428,38 +3428,6 @@ static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** arg
return 0; return 0;
} }
//==============================================================================
//function : VColorScale
//purpose : representation color scale
//==============================================================================
static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
const TCollection_AsciiString& theGreen,
const TCollection_AsciiString& theBlue,
Standard_Real& theRedValue,
Standard_Real& theGreenValue,
Standard_Real& theBlueValue)
{
if (!theRed.IsRealValue()
|| !theGreen.IsRealValue()
|| !theBlue.IsRealValue())
{
std::cout << "Error: RGB color values should be real!\n";
return Standard_True;
}
theRedValue = theRed .RealValue();
theGreenValue = theGreen.RealValue();
theBlueValue = theBlue .RealValue();
if (theRedValue < 0.0 || theRedValue > 1.0
|| theGreenValue < 0.0 || theGreenValue > 1.0
|| theBlueValue < 0.0 || theBlueValue > 1.0)
{
std::cout << "Error: RGB color values should be within range 0..1!\n";
return Standard_True;
}
return Standard_False;
}
static int VColorScale (Draw_Interpretor& theDI, static int VColorScale (Draw_Interpretor& theDI,
Standard_Integer theArgNb, Standard_Integer theArgNb,
const char** theArgVec) const char** theArgVec)
@ -3477,57 +3445,35 @@ static int VColorScale (Draw_Interpretor& theDI,
return 1; return 1;
} }
Handle(AIS_ColorScale) aCS; Handle(AIS_ColorScale) aColorScale;
// find object
Handle(AIS_InteractiveObject) anIObj;
if (GetMapOfAIS().IsBound2 (theArgVec[1])) if (GetMapOfAIS().IsBound2 (theArgVec[1]))
{ {
aCS = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); // find existing object
if (aCS.IsNull()) aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
if (aColorScale.IsNull())
{ {
std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n"; std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
return 1; return 1;
} }
} }
else
{
aCS = new AIS_ColorScale();
GetMapOfAIS().Bind (aCS,theArgVec[1]);
}
if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD)
{
aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
}
if (aCS->TransformPersistence().IsNull()
|| aCS->TransformPersistence()->Mode() != Graphic3d_TMF_2d)
{
aContext->SetTransformPersistence (aCS, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
}
Standard_Real aMinRange = aCS->GetMin();
Standard_Real aMaxRange = aCS->GetMax();
Standard_Integer aBreadth = aCS->GetBreadth();
Standard_Integer aHeight = aCS->GetHeight();
Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
Standard_Integer aTextHeight = aCS->GetTextHeight();
Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
Standard_Integer aPosX = aCS->GetXPosition();
Standard_Integer aPosY = aCS->GetYPosition();
ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
if (theArgNb <= 2) if (theArgNb <= 2)
{ {
if (aColorScale.IsNull())
{
std::cout << "Syntax error: colorscale with a given name does not exist.\n";
return 1;
}
theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n" theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
<< "Min range: " << aMinRange << "\n" << "Min range: " << aColorScale->GetMin() << "\n"
<< "Max range: " << aMaxRange << "\n" << "Max range: " << aColorScale->GetMax() << "\n"
<< "Number of intervals: " << aNbIntervals << "\n" << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
<< "Text height: " << aTextHeight << "\n" << "Text height: " << aColorScale->GetTextHeight() << "\n"
<< "Color scale position: " << aPosX <<" "<< aPosY<< "\n" << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
<< "Color scale title: " << aCS->GetTitle() << "\n" << "Color scale title: " << aColorScale->GetTitle() << "\n"
<< "Label position: "; << "Label position: ";
switch (aLabPosition) switch (aColorScale->GetLabelPosition())
{ {
case Aspect_TOCSP_NONE: case Aspect_TOCSP_NONE:
theDI << "None\n"; theDI << "None\n";
@ -3545,6 +3491,14 @@ static int VColorScale (Draw_Interpretor& theDI,
return 0; return 0;
} }
if (aColorScale.IsNull())
{
aColorScale = new AIS_ColorScale();
aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
}
ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter) for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
{ {
Standard_CString anArg = theArgVec[anArgIter]; Standard_CString anArg = theArgVec[anArgIter];
@ -3562,28 +3516,23 @@ static int VColorScale (Draw_Interpretor& theDI,
return 1; return 1;
} }
TCollection_AsciiString anArg1 (theArgVec[++anArgIter]); const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
TCollection_AsciiString anArg2 (theArgVec[++anArgIter]); const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
TCollection_AsciiString anArg3 (theArgVec[++anArgIter]); const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
if (!anArg1.IsRealValue()) if (!aRangeMin.IsRealValue()
|| !aRangeMax.IsRealValue())
{ {
std::cout << "Error: the minRange value should be real!\n"; std::cout << "Error: the range values should be real!\n";
return 1; return 1;
} }
else if (!anArg2.IsRealValue()) else if (!aNbIntervals.IsIntegerValue())
{
std::cout << "Error: the maxRange value should be real!\n";
return 1;
}
else if (!anArg3.IsIntegerValue())
{ {
std::cout << "Error: the number of intervals should be integer!\n"; std::cout << "Error: the number of intervals should be integer!\n";
return 1; return 1;
} }
aMinRange = anArg1.RealValue(); aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
aMaxRange = anArg2.RealValue(); aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
aNbIntervals = anArg3.IntegerValue();
} }
else if (aFlag == "-font") else if (aFlag == "-font")
{ {
@ -3599,7 +3548,7 @@ static int VColorScale (Draw_Interpretor& theDI,
return 1; return 1;
} }
aTextHeight = aFontArg.IntegerValue(); aColorScale->SetTextHeight (aFontArg.IntegerValue());
anArgIter += 1; anArgIter += 1;
} }
else if (aFlag == "-textpos") else if (aFlag == "-textpos")
@ -3609,8 +3558,10 @@ static int VColorScale (Draw_Interpretor& theDI,
std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
return 1; return 1;
} }
TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]); TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
aTextPosArg.LowerCase(); aTextPosArg.LowerCase();
Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
if (aTextPosArg == "none") if (aTextPosArg == "none")
{ {
aLabPosition = Aspect_TOCSP_NONE; aLabPosition = Aspect_TOCSP_NONE;
@ -3632,6 +3583,7 @@ static int VColorScale (Draw_Interpretor& theDI,
std::cout << "Error: unknown position '" << aTextPosArg << "'!\n"; std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
return 1; return 1;
} }
aColorScale->SetLabelPosition (aLabPosition);
} }
else if (aFlag == "-logarithmic" else if (aFlag == "-logarithmic"
|| aFlag == "-log") || aFlag == "-log")
@ -3641,13 +3593,71 @@ static int VColorScale (Draw_Interpretor& theDI,
std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
return 1; return 1;
} }
Standard_Boolean IsLog; Standard_Boolean IsLog;
if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog)) if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
{ {
std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
return 1; return 1;
} }
aCS->SetLogarithmic (IsLog); aColorScale->SetLogarithmic (IsLog);
}
else if (aFlag == "-huerange"
|| aFlag == "-hue")
{
if (anArgIter + 2 >= theArgNb)
{
std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
return 1;
}
const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
aColorScale->SetHueRange (aHueMin, aHueMax);
}
else if (aFlag == "-colorrange")
{
Quantity_Color aColorMin, aColorMax;
Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
theArgVec + (anArgIter + 1),
aColorMin);
anArgIter += aNbParsed1;
Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
theArgVec + (anArgIter + 1),
aColorMax);
anArgIter += aNbParsed2;
if (aNbParsed1 == 0
|| aNbParsed2 == 0)
{
std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
return 1;
}
aColorScale->SetColorRange (aColorMin, aColorMax);
}
else if (aFlag == "-reversed"
|| aFlag == "-inverted"
|| aFlag == "-topdown"
|| aFlag == "-bottomup")
{
Standard_Boolean toEnable = Standard_True;
if (anArgIter + 1 < theArgNb
&& ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
{
++anArgIter;
}
aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
}
else if (aFlag == "-smooth"
|| aFlag == "-smoothtransition")
{
Standard_Boolean toEnable = Standard_True;
if (anArgIter + 1 < theArgNb
&& ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
{
++anArgIter;
}
aColorScale->SetSmoothTransition (toEnable);
} }
else if (aFlag == "-xy") else if (aFlag == "-xy")
{ {
@ -3657,20 +3667,20 @@ static int VColorScale (Draw_Interpretor& theDI,
return 1; return 1;
} }
TCollection_AsciiString aX (theArgVec[++anArgIter]); const TCollection_AsciiString anX (theArgVec[++anArgIter]);
TCollection_AsciiString aY (theArgVec[++anArgIter]); const TCollection_AsciiString anY (theArgVec[++anArgIter]);
if (!aX.IsIntegerValue() if (!anX.IsIntegerValue()
|| !aY.IsIntegerValue()) || !anY.IsIntegerValue())
{ {
std::cout << "Error: coordinates should be integer values!\n"; std::cout << "Error: coordinates should be integer values!\n";
return 1; return 1;
} }
aPosX = aX.IntegerValue(); aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
aPosY = aY.IntegerValue();
} }
else if (aFlag == "-width" else if (aFlag == "-width"
|| aFlag == "-w") || aFlag == "-w"
|| aFlag == "-breadth")
{ {
if (anArgIter + 1 >= theArgNb) if (anArgIter + 1 >= theArgNb)
{ {
@ -3678,14 +3688,13 @@ static int VColorScale (Draw_Interpretor& theDI,
return 1; return 1;
} }
TCollection_AsciiString aW (theArgVec[++anArgIter]); const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
if (!aW.IsIntegerValue()) if (!aBreadth.IsIntegerValue())
{ {
std::cout << "Error: a width should be an integer value!\n"; std::cout << "Error: a width should be an integer value!\n";
return 1; return 1;
} }
aColorScale->SetBreadth (aBreadth.IntegerValue());
aBreadth = aW.IntegerValue();
} }
else if (aFlag == "-height" else if (aFlag == "-height"
|| aFlag == "-h") || aFlag == "-h")
@ -3696,75 +3705,56 @@ static int VColorScale (Draw_Interpretor& theDI,
return 1; return 1;
} }
TCollection_AsciiString aH (theArgVec[++anArgIter]); const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
if (!aH.IsIntegerValue()) if (!aHeight.IsIntegerValue())
{ {
std::cout << "Error: a width should be an integer value!\n"; std::cout << "Error: a width should be an integer value!\n";
return 1; return 1;
} }
aColorScale->SetHeight (aHeight.IntegerValue());
aHeight = aH.IntegerValue();
} }
else if (aFlag == "-color") else if (aFlag == "-color")
{ {
if (aCS->GetColorType() != Aspect_TOCSD_USER) if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
{ {
std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n"; std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
return 1; return 1;
} }
else if (anArgIter + 2 >= theArgNb)
Quantity_NameOfColor aColorName;
if (anArgIter + 4 >= theArgNb)
{
if (anArgIter + 2 >= theArgNb)
{ {
std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
return 1; return 1;
} }
else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
{
std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
return 1;
}
}
TCollection_AsciiString anInd (theArgVec[anArgIter + 1]); const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
if (!anInd.IsIntegerValue()) if (!anInd.IsIntegerValue())
{ {
std::cout << "Error: Index value should be integer!\n"; std::cout << "Error: Index value should be integer!\n";
return 1; return 1;
} }
const Standard_Integer anIndex = anInd.IntegerValue();
Standard_Integer anIndex = anInd.IntegerValue(); if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
if (anIndex <= 0 || anIndex > aNbIntervals)
{ {
std::cout << "Error: Index value should be within range 1.." << aNbIntervals <<"!\n"; std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
return 1; return 1;
} }
if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName)) Quantity_Color aColor;
{ Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
aCS->SetIntervalColor (Quantity_Color (aColorName), anIndex); theArgVec + (anArgIter + 1),
aCS->SetColorType (Aspect_TOCSD_USER); aColor);
anArgIter += 2; if (aNbParsed == 0)
continue;
}
TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
Standard_Real aRedValue,aGreenValue, aBlueValue;
if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
{ {
std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
return 1; return 1;
} }
aCS->SetIntervalColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex); aColorScale->SetIntervalColor (aColor, anIndex);
aCS->SetColorType (Aspect_TOCSD_USER); aColorScale->SetColorType (Aspect_TOCSD_USER);
anArgIter += 4; anArgIter += aNbParsed;
} }
else if (aFlag == "-label") else if (aFlag == "-label")
{ {
if (aCS->GetColorType() != Aspect_TOCSD_USER) if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
{ {
std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n"; std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
return 1; return 1;
@ -3776,90 +3766,115 @@ static int VColorScale (Draw_Interpretor& theDI,
} }
Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]); Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
if (anIndex <= 0 || anIndex > aNbIntervals+1) if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
{ {
std::cout << "Error: Index value should be within range 1.." << aNbIntervals+1 <<"!\n"; std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
return 1; return 1;
} }
TCollection_ExtendedString aText (theArgVec[anArgIter + 2]); TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
aCS->SetLabel (aText, anIndex); aColorScale->SetLabel (aText, anIndex);
aCS->SetLabelType (Aspect_TOCSD_USER); aColorScale->SetLabelType (Aspect_TOCSD_USER);
anArgIter += 2; anArgIter += 2;
} }
else if (aFlag == "-labelat"
|| aFlag == "-labat"
|| aFlag == "-labelatborder"
|| aFlag == "-labatborder"
|| aFlag == "-labelatcenter"
|| aFlag == "-labatcenter")
{
Standard_Boolean toEnable = Standard_True;
if (aFlag == "-labelat"
|| aFlag == "-labat")
{
Standard_Integer aLabAtBorder = -1;
if (++anArgIter >= theArgNb)
{
TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
anAtBorder.LowerCase();
if (anAtBorder == "border")
{
aLabAtBorder = 1;
}
else if (anAtBorder == "center")
{
aLabAtBorder = 0;
}
}
if (aLabAtBorder == -1)
{
std::cout << "Syntax error at argument '" << anArg << "'!\n";
return 1;
}
toEnable = (aLabAtBorder == 1);
}
else if (anArgIter + 1 < theArgNb
&& ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
{
++anArgIter;
}
aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
|| aFlag == "-labatcenter"
? !toEnable
: toEnable);
}
else if (aFlag == "-colors") else if (aFlag == "-colors")
{ {
Aspect_SequenceOfColor aSeq; Aspect_SequenceOfColor aSeq;
if (anArgIter + aNbIntervals + 1 > theArgNb) for (;;)
{ {
std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " Quantity_Color aColor;
<< aNbIntervals << " intervals\n"; Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
return 1; theArgVec + (anArgIter + 1),
} aColor);
if (aNbParsed == 0)
Standard_Integer aColorIter = anArgIter + 1;
while (aColorIter < theArgNb)
{
if (theArgVec[aColorIter][0] == '-')
{ {
break; break;
} }
anArgIter += aNbParsed;
else if (theArgVec[aColorIter][0] >= 97 aSeq.Append (aColor);
&& theArgVec[aColorIter][0] <= 122)
{
Quantity_NameOfColor aColorName;
if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
{
std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
return 1;
} }
aSeq.Append (Quantity_Color (aColorName)); if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
aColorIter++;
anArgIter++;
}
else
{
TCollection_AsciiString aRed (theArgVec[aColorIter]);
TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
Standard_Real aRedValue,aGreenValue, aBlueValue;
if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
{
return 1;
}
aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
aColorIter += 3;
anArgIter += 3;
}
}
if (aSeq.Length() < aNbIntervals)
{ {
std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
<< aNbIntervals << " intervals\n"; << aColorScale->GetNumberOfIntervals() << " intervals\n";
return 1; return 1;
} }
aCS->SetColors (aSeq); aColorScale->SetColors (aSeq);
aCS->SetColorType (Aspect_TOCSD_USER); aColorScale->SetColorType (Aspect_TOCSD_USER);
} }
else if (aFlag == "-labels") else if (aFlag == "-labels"
|| aFlag == "-freelabels")
{ {
if (anArgIter + aNbIntervals + 1 >= theArgNb) if (anArgIter + 1 >= theArgNb)
{ {
std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1) std::cout << "Syntax error at argument '" << anArg << "'!\n";
<< " text labels for " << aNbIntervals << " intervals.\n"; return 1;
}
Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
? aColorScale->GetNumberOfIntervals() + 1
: aColorScale->GetNumberOfIntervals();
if (aFlag == "-freelabels")
{
++anArgIter;
aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
}
if (anArgIter + aNbLabels >= theArgNb)
{
std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
return 1; return 1;
} }
TColStd_SequenceOfExtendedString aSeq; TColStd_SequenceOfExtendedString aSeq;
for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1) for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
{ {
aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter])); aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
} }
aCS->SetLabels (aSeq); aColorScale->SetLabels (aSeq);
aCS->SetLabelType (Aspect_TOCSD_USER); aColorScale->SetLabelType (Aspect_TOCSD_USER);
anArgIter += aSeq.Length();
} }
else if (aFlag == "-title") else if (aFlag == "-title")
{ {
@ -3874,29 +3889,31 @@ static int VColorScale (Draw_Interpretor& theDI,
{ {
TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]); TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
aSecondArg.LowerCase(); aSecondArg.LowerCase();
Standard_DISABLE_DEPRECATION_WARNINGS
if (aSecondArg == "none") if (aSecondArg == "none")
{ {
aCS->SetTitlePosition (Aspect_TOCSP_NONE); aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
isTwoArgs = Standard_True; isTwoArgs = Standard_True;
} }
else if (aSecondArg == "left") else if (aSecondArg == "left")
{ {
aCS->SetTitlePosition (Aspect_TOCSP_LEFT); aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
isTwoArgs = Standard_True; isTwoArgs = Standard_True;
} }
else if (aSecondArg == "right") else if (aSecondArg == "right")
{ {
aCS->SetTitlePosition (Aspect_TOCSP_RIGHT); aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
isTwoArgs = Standard_True; isTwoArgs = Standard_True;
} }
else if (aSecondArg == "center") else if (aSecondArg == "center")
{ {
aCS->SetTitlePosition (Aspect_TOCSP_CENTER); aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
isTwoArgs = Standard_True; isTwoArgs = Standard_True;
} }
Standard_ENABLE_DEPRECATION_WARNINGS
} }
aCS->SetTitle (theArgVec[anArgIter + 1]); aColorScale->SetTitle (theArgVec[anArgIter + 1]);
if (isTwoArgs) if (isTwoArgs)
{ {
anArgIter += 1; anArgIter += 1;
@ -3906,17 +3923,15 @@ static int VColorScale (Draw_Interpretor& theDI,
else if (aFlag == "-demoversion" else if (aFlag == "-demoversion"
|| aFlag == "-demo") || aFlag == "-demo")
{ {
aPosX = 0; aColorScale->SetPosition (0, 0);
aPosY = 0; aColorScale->SetTextHeight (16);
aTextHeight = 16; aColorScale->SetRange (0.0, 100.0);
aMinRange = 0.0; aColorScale->SetNumberOfIntervals (10);
aMaxRange = 100; aColorScale->SetBreadth (0);
aNbIntervals = 10; aColorScale->SetHeight (0);
aBreadth = 0; aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
aHeight = 0; aColorScale->SetColorType (Aspect_TOCSD_AUTO);
aLabPosition = Aspect_TOCSP_RIGHT; aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
aCS->SetColorType (Aspect_TOCSD_AUTO);
aCS->SetLabelType (Aspect_TOCSD_AUTO);
} }
else if (aFlag == "-findcolor") else if (aFlag == "-findcolor")
{ {
@ -3935,7 +3950,7 @@ static int VColorScale (Draw_Interpretor& theDI,
} }
Quantity_Color aColor; Quantity_Color aColor;
aCS->FindColor (anArg1.RealValue(), aColor); aColorScale->FindColor (anArg1.RealValue(), aColor);
theDI << Quantity_Color::StringName (aColor.Name()); theDI << Quantity_Color::StringName (aColor.Name());
return 0; return 0;
} }
@ -3945,29 +3960,19 @@ static int VColorScale (Draw_Interpretor& theDI,
return 1; return 1;
} }
} }
if (!aBreadth || !aHeight)
{
Standard_Integer aWinWidth, aWinHeight;
aView->Window()->Size (aWinWidth, aWinHeight);
if (!aBreadth)
{
aBreadth = aWinWidth;
}
if (!aHeight)
{
aHeight = aWinHeight;
}
}
aCS->SetSize (aBreadth, aHeight);
aCS->SetPosition (aPosX, aPosY);
aCS->SetTextHeight (aTextHeight);
aCS->SetRange (aMinRange, aMaxRange);
aCS->SetNumberOfIntervals (aNbIntervals);
aCS->SetLabelPosition (aLabPosition);
// aCS->SetColor (aView->BackgroundColor().Invert());
aCS->SetToUpdate();
aContext->Display (aCS);
Standard_Integer aWinWidth = 0, aWinHeight = 0;
aView->Window()->Size (aWinWidth, aWinHeight);
if (aColorScale->GetBreadth() == 0)
{
aColorScale->SetBreadth (aWinWidth);
}
if (aColorScale->GetHeight() == 0)
{
aColorScale->SetHeight (aWinHeight);
}
aColorScale->SetToUpdate();
ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
return 0; return 0;
} }
@ -10341,22 +10346,35 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
" : notice that EMF format requires patched gl2ps", " : notice that EMF format requires patched gl2ps",
__FILE__,VExport,group); __FILE__,VExport,group);
theCommands.Add("vcolorscale", theCommands.Add("vcolorscale",
"vcolorscale : vcolorscale name [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos " "vcolorscale name [-noupdate|-update] [-demo]"
"Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n" "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
"-demo/-demoversion draw a demoversion of color scale.\n" "\n\t\t: [-font HeightFont=20]"
"-show/display display color scale.\n" "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
"-hide/erase erase color scale.\n" "\n\t\t: [-smoothTransition {on|off}=off]"
"Please note that -show/-hide option must be the first argument!\n" "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
"-color Index R G B: set color for indexed interval\n" "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
"-color Index ColorName: set color for indexed interval\n" "\n\t\t: [-textpos {left|right|center|none}=right]"
"-colors R G B R G B ...: set colors for all intervals\n" "\n\t\t: [-labelAtBorder {on|off}=on]"
"-colors ColorName1 ColorName2 ...: set colors for all intervals\n" "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
"-colors supports both color names and rgb values in one call\n" "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
"-label Index Text: set label for indexed interval\n" "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
"-labels Text Text Text ...: set labels for all intervals\n" "\n\t\t: [-xy Left=0 Bottom=0]"
"-title Title [Position]: set the title for color scale with certain position. Default position = center;\n" "\n\t\t: -demo - displays a color scale with demonstratio values"
"Available text positions: left, right, center, none;\n", "\n\t\t: -colors - set colors for all intervals"
__FILE__,VColorScale,group); "\n\t\t: -color - set color for specific interval"
"\n\t\t: -textpos - horizontal label position relative to color scale bar"
"\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
"\n\t\t: at border means the value inbetween neighbor intervals,"
"\n\t\t: at center means the center value within current interval"
"\n\t\t: -labels - set labels for all intervals"
"\n\t\t: -freeLabels - same as -labels but does not require"
"\n\t\t: matching the number of intervals"
"\n\t\t: -label - set label for specific interval"
"\n\t\t: -title - set title"
"\n\t\t: -reversed - setup smooth color transition between intervals"
"\n\t\t: -smoothTransition - swap colorscale direction"
"\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
__FILE__, VColorScale, group);
theCommands.Add("vgraduatedtrihedron", theCommands.Add("vgraduatedtrihedron",
"vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
"\t[-namefont Name] [-valuesfont Name]\n" "\t[-namefont Name] [-valuesfont Name]\n"

View File

@ -4,29 +4,27 @@ puts "Display customized colorscale."
puts "============" puts "============"
puts "" puts ""
vinit View1
vclear vclear
vinit View1
vaxo vaxo
# create default color scale # create default color scale
vcolorscale cs -demo vcolorscale cs1 -demo -xy 0 0
vdump ${imagedir}/${casename}_1.png foreach {y aColor} {20 RED 60 DARKORANGE1 100 GOLD 140 GREENYELLOW 180 CHARTREUSE2 220 GREEN 250 MEDIUMSPRINGGREEN 290 CYAN1 330 DODGERBLUE1 370 BLUE1} { if { [vreadpixel 15 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
# reduce color scale range and number of intervals # reduce color scale range and number of intervals
vcolorscale cs -range 0 20 5 vcolorscale cs2 -range 0 20 5 -xy 60 0
vdump ${imagedir}/${casename}_2.png foreach {y aColor} {40 RED 120 YELLOW 200 GREEN 280 CYAN2 350 BLUE1} { if { [vreadpixel 75 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
# set user-defined colors and labels for color scale # set user-defined colors and labels for color scale
vcolorscale cs -colors white 0 0 1 green 1 0 0 1 1 1 -labels start 1 2 3 4 end vcolorscale cs3 -range 0 20 5 -colors white 0 0 1 green 1 0 0 1 1 1 -labels start 1 2 3 4 end -xy 120 0
vdump ${imagedir}/${casename}_3.png foreach {y aColor} {40 WHITE 120 RED 200 GREEN 280 BLUE1 350 WHITE} { if { [vreadpixel 135 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
# change colors of first and last intervals # change colors of first and last intervals
vcolorscale cs -color 1 0.42 0.35 0.8 vcolorscale cs4 -range 0 20 5 -colors white 0 0 1 green 1 0 0 1 1 1 -labels start 1 2 3 4 end -xy 200 0
vcolorscale cs -color 5 pink vcolorscale cs4 -color 1 0.42 0.35 0.8
vcolorscale cs4 -color 5 pink
# change last label vcolorscale cs4 -label 6 "last"
vcolorscale cs -label 6 "last" vcolorscale cs4 -title "My color scale"
foreach {y aColor} {60 PINK 120 RED 200 GREEN 280 BLUE1 350 SLATEBLUE} { if { [vreadpixel 215 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
# set a title for color scale vdump ${imagedir}/${casename}.png
vcolorscale cs -title "My color scale"
vdump ${imagedir}/${casename}_4.png

31
tests/bugs/vis/bug28004 Normal file
View File

@ -0,0 +1,31 @@
puts "============"
puts "OCC28004"
puts "Visualization, AIS_ColorScale - allow defining labels list not equal to intervals list"
puts "============"
puts ""
vclear
vinit View1
vaxo
# create default color scale
vcolorscale cs1 -demo -smooth 0 -xy 0 0
vcolorscale cs2 -demo -smooth 1 -xy 60 0
foreach {y aColor} {20 RED 60 DARKORANGE1 100 GOLD 140 GREENYELLOW 180 CHARTREUSE2 220 GREEN 250 MEDIUMSPRINGGREEN 290 CYAN1 330 DODGERBLUE1 370 BLUE1} { if { [vreadpixel 15 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
foreach {y aColor} {20 RED 60 DARKORANGE1 100 GOLD 140 GREENYELLOW 180 CHARTREUSE2 220 GREEN 250 MEDIUMSPRINGGREEN 290 CYAN1 330 DODGERBLUE1 370 BLUE1} { if { [vreadpixel 15 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
# reduce color scale range and number of intervals
vcolorscale cs3 -range 0 20 5 -font 16 -colors white 0 0 1 green 1 0 0 1 1 1 -labels start 1 2 3 4 end -smooth 0 -xy 120 0
vcolorscale cs4 -range 0 20 5 -font 16 -colors white 0 0 1 green 1 0 0 1 1 1 -labels start 1 2 3 4 end -smooth 1 -xy 180 0
foreach {y aColor} {40 WHITE 120 RED 200 GREEN 280 BLUE1 350 WHITE} { if { [vreadpixel 135 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
# color scale with overridden hue range
vcolorscale cs5 -demo -smooth 0 -hueRange 300 130 -xy 240 0
vcolorscale cs6 -demo -smooth 1 -hueRange 300 130 -xy 300 0
foreach {y aColor} {20 GREEN 60 SPRINGGREEN 100 CYAN2 140 TURQUOISE2 180 DODGERBLUE1 220 BLUE1 250 BLUE1 290 BLUEVIOLET 330 PURPLE 370 MAGENTA1} { if { [vreadpixel 245 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
foreach {y aColor} {20 GREEN 60 SPRINGGREEN 100 CYAN2 140 TURQUOISE2 180 DODGERBLUE1 220 DODGERBLUE2 250 BLUE1 290 BLUE1 330 PURPLE 370 MAGENTA2} { if { [vreadpixel 315 $y rgb name] != "$aColor" } { puts "Error: wrong color at $y" } }
# free labels
vcolorscale cs7 -demo -smooth 0 -colorRange BLACK WHITE -xy 360 0 -freeLabels 3 l1 l2 l3
vdump ${imagedir}/${casename}.png