0027058: AIS_ColorScale defines methods SetColor and SetWidth hiding inherited methods
authorabv <abv@opencascade.com>
Sat, 9 Jan 2016 10:53:31 +0000 (13:53 +0300)
committerabv <abv@opencascade.com>
Mon, 11 Jan 2016 22:55:33 +0000 (01:55 +0300)
Interface of AIS_ColorScale is revised to make it more consistent:

- Methods SetBgColor()/GetBGColor(), and corresponding field, are removed. It was used to select white or black color for the color bar frame (by contrast). That color can now be set explicitly by inherited method SetColor().
- Own methods Get/SetColor() are renamed to Get/SetIntervalColor(), to avoid confusion with inherited method SetColor()
- Methods Get/SetWidth() are renamed to Get/SetBreadth(), to avoid confusion with inherited method SetWidth()
- Method Get/Set for labels and colors, and DRAW command vcolorscale, now all accept index starting at 1
- Comments added to explain indexation rules

src/AIS/AIS_ColorScale.cxx
src/AIS/AIS_ColorScale.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/bugs/vis/bug25136

index d773051..65042bb 100644 (file)
@@ -60,10 +60,9 @@ myLabelPos (Aspect_TOCSP_RIGHT),
 myTitlePos (Aspect_TOCSP_CENTER),
 myXPos (0),
 myYPos (0),
-myWidth (0),
+myBreadth (0),
 myHeight (0),
-myTextHeight(20),
-myBgColor (Quantity_NOC_BLACK)
+myTextHeight(20)
 {
 }
 
@@ -85,15 +84,17 @@ TCollection_ExtendedString AIS_ColorScale::GetLabel (const Standard_Integer theI
 {
   if (GetLabelType() == Aspect_TOCSD_USER)
   {
-    if (theIndex < 0
-     || theIndex >= myLabels.Length())
+    if (theIndex <= 0 || theIndex > myLabels.Length())
     {
       return "";
     }
-
-    return myLabels.Value (theIndex + 1);
+    return myLabels.Value (theIndex);
   }
-  Standard_Real aVal = IsLogarithmic() ? GetLogNumber(theIndex) : GetNumber (theIndex);
+
+  // value to be shown depends on label position
+  Standard_Real aVal = IsLabelAtBorder() ? GetIntervalValue (theIndex - 1) :
+                       0.5 * (GetIntervalValue (theIndex - 1) + GetIntervalValue (theIndex));
+
   const TCollection_AsciiString aFormat = Format();
   Standard_Character aBuf[1024];
   sprintf (aBuf, aFormat.ToCString(), aVal);
@@ -101,22 +102,21 @@ TCollection_ExtendedString AIS_ColorScale::GetLabel (const Standard_Integer theI
 }
 
 //=======================================================================
-//function : GetColor
+//function : GetIntervalColor
 //purpose  :
 //=======================================================================
-Quantity_Color AIS_ColorScale::GetColor (const Standard_Integer theIndex) const
+Quantity_Color AIS_ColorScale::GetIntervalColor (const Standard_Integer theIndex) const
 {
   if (GetColorType() == Aspect_TOCSD_USER)
   {
-    if (theIndex < 0
-     || theIndex >= myColors.Length())
+    if (theIndex <= 0 || theIndex > myColors.Length())
     {
       return Quantity_Color();
     }
-
-    return myColors.Value (theIndex + 1);
+    return myColors.Value (theIndex);
   }
-  return Quantity_Color (HueFromValue (theIndex, 0, GetNumberOfIntervals() - 1), 1.0, 1.0, Quantity_TOC_HLS);
+
+  return Quantity_Color (HueFromValue (theIndex - 1, 0, GetNumberOfIntervals() - 1), 1.0, 1.0, Quantity_TOC_HLS);
 }
 
 //=======================================================================
@@ -238,36 +238,22 @@ void AIS_ColorScale::SetFormat (const TCollection_AsciiString& theFormat)
 //=======================================================================
 void AIS_ColorScale::SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer theIndex)
 {
-  Standard_Integer i = theIndex < 0 ? myLabels.Length() + 1 : theIndex + 1;
-  if (i <= myLabels.Length())
-  {
-    myLabels.SetValue (i, theLabel);
-  }
-  else
-  {
-    while (i > myLabels.Length())
-      myLabels.Append (TCollection_ExtendedString());
-    myLabels.SetValue (i, theLabel);
-  }
+  Standard_Integer i = (theIndex <= 0 ? myLabels.Length() + 1 : theIndex);
+  while (i > myLabels.Length())
+    myLabels.Append (TCollection_ExtendedString());
+  myLabels.SetValue (i, theLabel);
 }
 
 //=======================================================================
-//function : SetColor
+//function : SetIntervalColor
 //purpose  :
 //=======================================================================
-void AIS_ColorScale::SetColor (const Quantity_Color& theColor, const Standard_Integer theIndex)
+void AIS_ColorScale::SetIntervalColor (const Quantity_Color& theColor, const Standard_Integer theIndex)
 {
-  Standard_Integer i = theIndex < 0 ? myColors.Length() + 1 : theIndex + 1;
-  if (i <= myColors.Length())
-  {
-    myColors.SetValue (i, theColor);
-  }
-  else
-  {
-    while (i > myColors.Length())
-      myColors.Append (Quantity_Color());
-    myColors.SetValue (i, theColor);
-  }
+  Standard_Integer i = (theIndex <= 0 ? myColors.Length() + 1 : theIndex);
+  while (i > myColors.Length())
+    myColors.Append (Quantity_Color());
+  myColors.SetValue (i, theColor);
 }
 
 //=======================================================================
@@ -385,9 +371,9 @@ void AIS_ColorScale::SetYPosition (const Standard_Integer theY)
 //function : GetSize
 //purpose  :
 //=======================================================================
-void AIS_ColorScale::GetSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const
+void AIS_ColorScale::GetSize (Standard_Integer& theBreadth, Standard_Integer& theHeight) const
 {
-  theWidth = myWidth;
+  theBreadth = myBreadth;
   theHeight = myHeight;
 }
 
@@ -395,20 +381,20 @@ void AIS_ColorScale::GetSize (Standard_Integer& theWidth, Standard_Integer& theH
 //function : SetSize
 //purpose  :
 //=======================================================================
-void AIS_ColorScale::SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight)
+void AIS_ColorScale::SetSize (const Standard_Integer theBreadth, const Standard_Integer theHeight)
 {
-  if (myWidth == theWidth && myHeight == theHeight)
+  if (myBreadth == theBreadth && myHeight == theHeight)
     return;
 
-  myWidth = theWidth;
+  myBreadth = theBreadth;
   myHeight = theHeight;
 }
 
 //=======================================================================
-//function : SetWidth
+//function : SetBreadth
 //purpose  :
 //=======================================================================
-void AIS_ColorScale::SetWidth (const Standard_Integer theWidth)
+void AIS_ColorScale::SetBreadth (const Standard_Integer theWidth)
 {
   SetSize (theWidth, GetHeight());
 }
@@ -419,7 +405,7 @@ void AIS_ColorScale::SetWidth (const Standard_Integer theWidth)
 //=======================================================================
 void AIS_ColorScale::SetHeight (const Standard_Integer theHeight)
 {
-  SetSize (GetWidth(), theHeight);
+  SetSize (GetBreadth(), theHeight);
 }
 
 //=======================================================================
@@ -436,25 +422,19 @@ void AIS_ColorScale::SizeHint (Standard_Integer& theWidth, Standard_Integer& the
   Standard_Integer aColorWidth = 20;
 
   if (GetLabelPosition() != Aspect_TOCSP_NONE)
-    for (Standard_Integer idx = 0; idx < aNum; idx++)
-      aTextWidth = Max (aTextWidth, TextWidth (GetLabel (idx + 1)));
+  {
+    for (Standard_Integer idx = (IsLabelAtBorder() ? 0 : 1); idx <= aNum; idx++)
+      aTextWidth = Max (aTextWidth, TextWidth (GetLabel (idx)));
+  }
 
   Standard_Integer aScaleWidth = 0;
   Standard_Integer aScaleHeight = 0;
 
-  Standard_Integer aTitleWidth = 0;
-  Standard_Integer aTitleHeight = 0;
-
-  if (IsLabelAtBorder())
-  {
-    aNum++;
-    if (GetTitle().Length())
-      aTitleHeight += 10;
-  }
-
   aScaleWidth = aColorWidth + aTextWidth + ( aTextWidth ? 3 : 2 ) * aSpacer;
-  aScaleHeight = (Standard_Integer)( 1.5 * ( aNum + 1 ) * aTextHeight );
+  aScaleHeight = (Standard_Integer)( 1.5 * ( aNum + (IsLabelAtBorder() ? 2 : 1) ) * aTextHeight );
 
+  Standard_Integer aTitleWidth = 0;
+  Standard_Integer aTitleHeight = 0;
   if (GetTitle().Length())
   {
     aTitleHeight = TextHeight (GetTitle()) + aSpacer;
@@ -475,30 +455,25 @@ TCollection_AsciiString AIS_ColorScale::Format() const
 }
 
 //=======================================================================
-//function : GetNumber
+//function : GetIntervalValue
 //purpose  :
 //=======================================================================
-Standard_Real AIS_ColorScale::GetNumber (const Standard_Integer theIndex) const
+Standard_Real AIS_ColorScale::GetIntervalValue (const Standard_Integer theIndex) const
 {
-  Standard_Real aNum = 0;
-  if (GetNumberOfIntervals() > 0)
-    aNum = GetMin() + theIndex * ( Abs (GetMax() - GetMin()) / GetNumberOfIntervals() );
-  return aNum;
-}
+  if (GetNumberOfIntervals() <= 0)
+    return 0.;
 
-//=======================================================================
-//function : GetLogNumber
-//purpose  :
-//=======================================================================
-Standard_Real AIS_ColorScale::GetLogNumber (const Standard_Integer theIndex) const
-{
-  if (GetNumberOfIntervals() > 0)
+  if (IsLogarithmic())
   {
     Standard_Real aMin = myMin > 0 ? myMin : 1.0;
     Standard_Real aDivisor = std::pow (myMax/aMin, 1.0/myInterval);
     return aMin*std::pow (aDivisor,theIndex);
   }
-  return 0;
+
+  Standard_Real aNum = 0;
+  if (GetNumberOfIntervals() > 0)
+    aNum = GetMin() + theIndex * ( Abs (GetMax() - GetMin()) / GetNumberOfIntervals() );
+  return aNum;
 }
 
 //=======================================================================
@@ -566,7 +541,6 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr
 {
   Handle(V3d_Viewer) aViewer= GetContext()->CurrentViewer();
   aViewer->InitActiveViews();
-  Quantity_Color aBgColor = myBgColor;
   Standard_Integer aNum = GetNumberOfIntervals();
   Aspect_TypeOfColorScalePosition aLabPos = GetLabelPosition();
 
@@ -576,8 +550,7 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr
   Standard_Boolean toDrawLabel = GetLabelPosition() != Aspect_TOCSP_NONE;
   TCollection_ExtendedString aTitle = GetTitle();
   Standard_Integer aTitleHeight = aSpacer;
-  Standard_Integer aGray = (Standard_Integer)(255 * ( aBgColor.Red() * 11 + aBgColor.Green() * 16 + aBgColor.Blue() * 5 ) / 32);
-  Quantity_Color aFgColor (aGray < 128 ? Quantity_NOC_WHITE : Quantity_NOC_BLACK);
+  Quantity_Color aFgColor (hasOwnColor ? myOwnColor : Quantity_NOC_WHITE);
 
   // Draw title
   if (aTitle.Length())
@@ -589,35 +562,36 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr
   Standard_Boolean toReverse = IsReversed();
 
   Aspect_SequenceOfColor aColors;
-  TColStd_SequenceOfExtendedString aLabels;
-  for (Standard_Integer i = 0; i < aNum; i++)
+  for (Standard_Integer i = 1; i <= aNum; i++)
   {
     if (toReverse)
     {
-      aColors.Prepend (GetColor (i));
-      aLabels.Prepend (GetLabel (i));
+      aColors.Prepend (GetIntervalColor (i));
     }
     else
     {
-      aColors.Append (GetColor (i));
-      aLabels.Append (GetLabel (i));
+      aColors.Append (GetIntervalColor (i));
     }
   }
 
-  if (IsLabelAtBorder())
+  TColStd_SequenceOfExtendedString aLabels;
+  Standard_Integer aLabCount = IsLabelAtBorder() ? aNum + 1 : aNum;
+  for (Standard_Integer i = 1; i <= aLabCount; i++)
   {
     if (toReverse)
-      aLabels.Prepend (GetLabel (aNum));
+    {
+      aLabels.Prepend (GetLabel (i));
+    }
     else
-      aLabels.Append (GetLabel (aNum));
+    {
+      aLabels.Append (GetLabel (i));
+    }
   }
 
   if (toDrawLabel)
     for (Standard_Integer i = 1; i <= aLabels.Length(); i++)
       aTextWidth = Max (aTextWidth, TextWidth (aLabels.Value (i)));
 
-  Standard_Integer aLabCount = aLabels.Length();
-
   Standard_Integer aSpc = ( myHeight - ( ( Min (aLabCount, 2) + Abs (aLabCount - aNum - 1) ) * aTextHeight ) - aTitleHeight );
   Standard_Real aVal = aSpc != 0 ? 1.0 * ( aLabCount - Min (aLabCount, 0) ) * aTextHeight / aSpc : 0;
   Standard_Real anIPart;
@@ -627,9 +601,9 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr
   Standard_Real aStep = 1.0 * ( myHeight - (aLabCount - aNum + Abs (aLabCount - aNum - 1)) * aTextHeight - aTitleHeight ) / aNum;
 
   Standard_Integer anAscent = 0;
-  Standard_Integer aColorWidth = Max (5, Min (20, myWidth - aTextWidth - 3 * aSpacer));
+  Standard_Integer aColorBreadth = Max (5, Min (20, myBreadth - aTextWidth - 3 * aSpacer));
   if (aLabPos == Aspect_TOCSP_CENTER || !toDrawLabel)
-    aColorWidth += aTextWidth;
+    aColorBreadth += aTextWidth;
 
   // Draw colors
   Standard_Integer aX = (Standard_Integer)myXPos + aSpacer;
@@ -649,9 +623,9 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr
     Standard_Integer aY = (Standard_Integer)( myYPos + ( i - 1 )* aStep + anOffset );
     Standard_Integer aColorHeight = (Standard_Integer)( myYPos + ( i ) * aStep + anOffset ) - aY;
     aPrim->AddVertex (gp_Pnt (aX, aY, 0.0), aColors.Value( i ));
-    aPrim->AddVertex (gp_Pnt (aX+aColorWidth, aY, 0.0), aColors.Value( i ));
+    aPrim->AddVertex (gp_Pnt (aX+aColorBreadth, aY, 0.0), aColors.Value( i ));
     aPrim->AddVertex (gp_Pnt (aX, aY+aColorHeight, 0.0), aColors.Value( i ));
-    aPrim->AddVertex (gp_Pnt (aX+aColorWidth, aY+aColorHeight, 0.0), aColors.Value( i ));
+    aPrim->AddVertex (gp_Pnt (aX+aColorBreadth, aY+aColorHeight, 0.0), aColors.Value( i ));
     aPrim->AddEdge(aVertIndex);
     aPrim->AddEdge(aVertIndex+1);
     aPrim->AddEdge(aVertIndex+2);
@@ -663,7 +637,7 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr
   aGroup->AddPrimitiveArray (aPrim);
 
   if (aStep > 0)
-    DrawFrame (thePresentation, aX - 1, (Standard_Integer)(myYPos + anOffset - 1), aColorWidth + 2, (Standard_Integer)(aColors.Length() * aStep + 2), aFgColor);
+    DrawFrame (thePresentation, aX - 1, (Standard_Integer)(myYPos + anOffset - 1), aColorBreadth + 2, (Standard_Integer)(aColors.Length() * aStep + 2), aFgColor);
 
   // Draw Labels
   anOffset = 1.0 * Abs (aLabCount - aNum - 1) * ( aStep - aTextHeight ) / 2 + 1.0 * Abs (aLabCount - aNum - 1) * aTextHeight / 2;
@@ -680,10 +654,10 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr
       case Aspect_TOCSP_LEFT:
         break;
       case Aspect_TOCSP_CENTER:
-        aX += ( aColorWidth - aTextWidth ) / 2;
+        aX += ( aColorBreadth - aTextWidth ) / 2;
         break;
       case Aspect_TOCSP_RIGHT:
-        aX += aColorWidth + aSpacer;
+        aX += aColorBreadth + aSpacer;
         break;
     }
     while (i2 - i1 >= aFilter || ( i2 == 0 && i1 == 0 ))
@@ -733,7 +707,8 @@ void AIS_ColorScale::DrawFrame (const Handle(Prs3d_Presentation)& thePresentatio
   aPrim->AddVertex (theX+theWidth,theY+theHeight,0.0);
   aPrim->AddVertex (theX,theY+theHeight,0.0);
   aPrim->AddVertex (theX,theY,0.0);
-  Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (theColor, Aspect_TOL_SOLID, 1.0);
+  Handle(Prs3d_LineAspect) anAspect = 
+    new Prs3d_LineAspect (theColor, Aspect_TOL_SOLID, 1.0);
   anAspect->SetColor (theColor);
   aGroup->SetPrimitivesAspect (anAspect->Aspect());
   aGroup->AddPrimitiveArray (aPrim);
index 2cd703d..2976714 100644 (file)
 #include <TCollection_ExtendedString.hxx>
 #include <TColStd_SequenceOfExtendedString.hxx>
 
+//! Class for drawing a custom color scale.
+//!
+//! The color scale consists of rectangular color bar (composed of fixed
+//! number of color intervals), optional labels, and title.
+//! The labels can be positioned either at the boundaries of the intervals,
+//! or at the middle of each interval.
+//! Colors and labels can be either defined automatically or set by the user.
+//! Automatic labels are calculated from numerical limits of the scale,
+//! its type (logarithmic or plain), and formatted by specified format string.
 
-//! Class for drawing a custom color scale
 class AIS_ColorScale : public AIS_InteractiveObject {
 
 public:
@@ -68,13 +76,15 @@ public:
   //! Used if GetLabelType() is TOCSD_AUTO;
   Standard_EXPORT TCollection_AsciiString GetFormat() const { return myFormat; }
 
-  //! Returns the user specified label with index <anIndex>.
+  //! Returns the user specified label with index theIndex.
+  //! Index is in range from 1 to GetNumberOfIntervals() or to
+  //! GetNumberOfIntervals() + 1 if IsLabelAtBorder() is true.
   //! 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 color from color map with index <anIndex> (starts at 1).
+  //! Returns default color if index is out of range in color map.
+  Standard_EXPORT Quantity_Color GetIntervalColor (const Standard_Integer theIndex) const;
 
   //! Returns the user specified labels.
   Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
@@ -91,7 +101,7 @@ public:
   //! Returns true if the labels and colors used in reversed order.
   Standard_EXPORT Standard_Boolean IsReversed() const { return myReversed; }
 
-  //! Returns true if the labels placed at border of color filled rectangles.
+  //! 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
@@ -125,19 +135,25 @@ public:
   //! 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 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 scale color at index. Index started from 1.
-  Standard_EXPORT void SetColor (const Quantity_Color& theColor, const Standard_Integer theIndex = -1);
+  //! 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.
+  //! The length of the sequence should be equal to GetNumberOfIntervals().
   Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
 
-  //! Sets the color scale labels position concerning color filled rectangles.
+  //! Sets the color scale labels position relative to color bar.
   Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos);
 
   //! Sets the color scale title position.
@@ -146,36 +162,31 @@ public:
   //! 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.
+  //! 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.
   Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
 
   //! Sets true if the color scale has logarithmic intervals.
   void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; };
 
-  //! Returns the size of color scale.
-  Standard_EXPORT void GetSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
+  //! Returns the size of color bar.
+  Standard_EXPORT void GetSize (Standard_Integer& theBreadth, Standard_Integer& theHeight) const;
 
-  //! Returns the width of color scale.
-  Standard_EXPORT Standard_Integer GetWidth() const { return myWidth; }
+  //! Returns the breadth of color bar.
+  Standard_EXPORT Standard_Integer GetBreadth() const { return myBreadth; }
 
-  //! Returns the height of color scale.
+  //! Returns the height of color bar.
   Standard_EXPORT Standard_Integer GetHeight() const { return myHeight; }
 
-  //! Returns the background color of color scale.
-  const Quantity_Color& GetBgColor() const { return myBgColor; }
-
-  //! Sets the size of color scale.
+  //! Sets the size of color bar.
   Standard_EXPORT void SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
 
-  //! Sets the width of color scale.
-  Standard_EXPORT void SetWidth (const Standard_Integer theWidth);
+  //! Sets the width of color bar.
+  Standard_EXPORT void SetBreadth (const Standard_Integer theBreadth);
 
-  //! Sets the height of color scale.
+  //! Sets the height of color bar.
   Standard_EXPORT void SetHeight (const Standard_Integer theHeight);
 
-  //! Sets the background color of color scale.
-  void SetBGColor (const Quantity_Color& theBgColor) { myBgColor = theBgColor; };
-
   //! Returns the position of color scale.
   Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const;
 
@@ -254,11 +265,8 @@ private:
   //! Returns the format of text.
   TCollection_AsciiString Format() const;
 
-  //! Returns the value of given interval.
-  Standard_Real GetNumber (const Standard_Integer theIndex) const;
-
-  //! Returns the value of given logarithmic interval.
-  Standard_Real GetLogNumber (const Standard_Integer theIndex) const;
+  //! Returns the upper value of given interval, or minimum for theIndex = 0.
+  Standard_Real GetIntervalValue (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.
@@ -284,7 +292,7 @@ private:
   Aspect_TypeOfColorScalePosition myTitlePos;
   Standard_Integer myXPos;
   Standard_Integer myYPos;
-  Standard_Integer myWidth;
+  Standard_Integer myBreadth;
   Standard_Integer myHeight;
   Standard_Integer myTextHeight;
   Quantity_Color myBgColor;
index acc7fa6..298a33e 100644 (file)
@@ -3507,7 +3507,7 @@ static int VColorScale (Draw_Interpretor& theDI,
 
   Standard_Real                   aMinRange    = aCS->GetMin();
   Standard_Real                   aMaxRange    = aCS->GetMax();
-  Standard_Integer                aWidth       = aCS->GetWidth();
+  Standard_Integer                aBreadth     = aCS->GetBreadth();
   Standard_Integer                aHeight      = aCS->GetHeight();
   Standard_Integer                aNbIntervals = aCS->GetNumberOfIntervals();
   Standard_Integer                aTextHeight  = aCS->GetTextHeight();
@@ -3685,7 +3685,7 @@ static int VColorScale (Draw_Interpretor& theDI,
         return 1;
       }
 
-      aWidth = aW.IntegerValue();
+      aBreadth = aW.IntegerValue();
     }
     else if (aFlag == "-height"
           || aFlag == "-h")
@@ -3736,16 +3736,15 @@ static int VColorScale (Draw_Interpretor& theDI,
       }
 
       Standard_Integer anIndex = anInd.IntegerValue();
-      if (anIndex < 0
-       || anIndex > aNbIntervals - 1)
+      if (anIndex <= 0 || anIndex > aNbIntervals)
       {
-        std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n";
+        std::cout << "Error: Index value should be within range 1.." << aNbIntervals <<"!\n";
         return 1;
       }
 
       if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
       {
-        aCS->SetColor    (Quantity_Color (aColorName), anIndex);
+        aCS->SetIntervalColor (Quantity_Color (aColorName), anIndex);
         aCS->SetColorType (Aspect_TOCSD_USER);
         anArgIter += 2;
         continue;
@@ -3759,7 +3758,7 @@ static int VColorScale (Draw_Interpretor& theDI,
       {
         return 1;
       }
-      aCS->SetColor     (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
+      aCS->SetIntervalColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
       aCS->SetColorType (Aspect_TOCSD_USER);
       anArgIter += 4;
     }
@@ -3777,10 +3776,9 @@ static int VColorScale (Draw_Interpretor& theDI,
       }
 
       Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
-      if (anIndex < 0
-       || anIndex > aNbIntervals)
+      if (anIndex <= 0 || anIndex > aNbIntervals+1)
       {
-        std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n";
+        std::cout << "Error: Index value should be within range 1.." << aNbIntervals+1 <<"!\n";
         return 1;
       }
 
@@ -3914,7 +3912,7 @@ static int VColorScale (Draw_Interpretor& theDI,
       aMinRange    = 0.0;
       aMaxRange    = 100;
       aNbIntervals = 10;
-      aWidth       = 0;
+      aBreadth     = 0;
       aHeight      = 0;
       aLabPosition = Aspect_TOCSP_RIGHT;
       aCS->SetColorType (Aspect_TOCSD_AUTO);
@@ -3926,26 +3924,26 @@ static int VColorScale (Draw_Interpretor& theDI,
       return 1;
     }
   }
-  if (!aWidth || !aHeight)
+  if (!aBreadth || !aHeight)
   {
     Standard_Integer aWinWidth, aWinHeight;
     aView->Window()->Size (aWinWidth, aWinHeight);
-    if (!aWidth)
+    if (!aBreadth)
     {
-      aWidth = aWinWidth;
+      aBreadth = aWinWidth;
     }
     if (!aHeight)
     {
       aHeight = aWinHeight;
     }
   }
-  aCS->SetSize              (aWidth, aHeight);
+  aCS->SetSize              (aBreadth, aHeight);
   aCS->SetPosition          (aPosX, aPosY);
   aCS->SetTextHeight        (aTextHeight);
   aCS->SetRange             (aMinRange, aMaxRange);
   aCS->SetNumberOfIntervals (aNbIntervals);
   aCS->SetLabelPosition     (aLabPosition);
-  aCS->SetBGColor           (aView->BackgroundColor());
+//  aCS->SetColor             (aView->BackgroundColor().Invert());
   aCS->SetToUpdate();
   aContext->Display (aCS);
 
index 9a6cc34..c9a0930 100644 (file)
@@ -21,11 +21,11 @@ vcolorscale cs -colors white 0 0 1 green 1 0 0 1 1 1 -labels start 1 2 3 4 end
 vdump ${imagedir}/${casename}_3.png
 
 # change colors of first and last intervals
-vcolorscale cs -color 0 0.42 0.35 0.8
-vcolorscale cs -color 4 pink
+vcolorscale cs -color 1 0.42 0.35 0.8
+vcolorscale cs -color 5 pink
 
 # change last label
-vcolorscale cs -label 5 "last"
+vcolorscale cs -label 6 "last"
 
 # set a title for color scale
 vcolorscale cs -title "My color scale"