Now 'vcolorscale' command works correctly with the active view. Changed types of some variables from Standard_Real to Standard_Integer. Added options to set the width or the height of color scale explicitly. Test case is added.
myTitlePos (Aspect_TOCSP_CENTER),
myXPos (0),
myYPos (0),
-myWidth (0.2),
-myHeight (1),
-myTextHeight(20)
+myWidth (0),
+myHeight (0),
+myTextHeight(20),
+myBgColor (Quantity_NOC_BLACK)
{
}
//function : SetPosition
//purpose :
//=======================================================================
-void AIS_ColorScale::SetPosition (const Standard_Real theX, const Standard_Real theY)
+void AIS_ColorScale::SetPosition (const Standard_Integer theX, const Standard_Integer theY)
{
if (myXPos == theX && myYPos == theY)
return;
//function : SetXPosition
//purpose :
//=======================================================================
-void AIS_ColorScale::SetXPosition (const Standard_Real theX)
+void AIS_ColorScale::SetXPosition (const Standard_Integer theX)
{
SetPosition (theX, GetYPosition());
}
//function : SetYPosition
//purpose :
//=======================================================================
-void AIS_ColorScale::SetYPosition (const Standard_Real theY)
+void AIS_ColorScale::SetYPosition (const Standard_Integer theY)
{
SetPosition (GetXPosition(), theY);
}
//function : GetSize
//purpose :
//=======================================================================
-void AIS_ColorScale::GetSize (Standard_Real& theWidth, Standard_Real& theHeight) const
+void AIS_ColorScale::GetSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const
{
theWidth = myWidth;
theHeight = myHeight;
//function : SetSize
//purpose :
//=======================================================================
-void AIS_ColorScale::SetSize (const Standard_Real theWidth, const Standard_Real theHeight)
+void AIS_ColorScale::SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight)
{
if (myWidth == theWidth && myHeight == theHeight)
return;
//function : SetWidth
//purpose :
//=======================================================================
-void AIS_ColorScale::SetWidth (const Standard_Real theWidth)
+void AIS_ColorScale::SetWidth (const Standard_Integer theWidth)
{
SetSize (theWidth, GetHeight());
}
//function : SetHeight
//purpose :
//=======================================================================
-void AIS_ColorScale::SetHeight (const Standard_Real theHeight)
+void AIS_ColorScale::SetHeight (const Standard_Integer theHeight)
{
SetSize (GetWidth(), theHeight);
}
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer /*theMode*/)
{
- Standard_Integer aWinWidth(0), aWinHeight(0);
Handle(V3d_Viewer) aViewer= GetContext()->CurrentViewer();
aViewer->InitActiveViews();
- aViewer->ActiveView()->Window()->Size (aWinWidth, aWinHeight);
- Quantity_Color aBgColor = aViewer->ActiveView()->BackgroundColor();
+ Quantity_Color aBgColor = myBgColor;
Standard_Integer aNum = GetNumberOfIntervals();
Aspect_TypeOfColorScalePosition aLabPos = GetLabelPosition();
if (aTitle.Length())
{
aTitleHeight += myTextHeight + aSpacer;
- DrawText (thePresentation, aTitle, (Standard_Integer)myXPos + aSpacer, aWinHeight - ((Standard_Integer)myYPos - 2 * aSpacer + aTitleHeight), aFgColor);
+ DrawText (thePresentation, aTitle, (Standard_Integer)myXPos + aSpacer, myHeight - ((Standard_Integer)myYPos - 2 * aSpacer + aTitleHeight), aFgColor);
}
Standard_Boolean toReverse = IsReversed();
Standard_Integer aLabCount = aLabels.Length();
- Standard_Real aSpc = ( aWinHeight - ( ( Min (aLabCount, 2) + Abs (aLabCount - aNum - 1) ) * aTextHeight ) - aTitleHeight );
+ 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;
Standard_Real anFPart = modf (aVal, &anIPart);
Standard_Integer aFilter = (Standard_Integer)anIPart + ( anFPart != 0 ? 1 : 0 );
- Standard_Real aStep = 1.0 * ( aWinHeight - (aLabCount - aNum + Abs (aLabCount - aNum - 1)) * aTextHeight - aTitleHeight ) / aNum;
+ 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, aWinWidth - aTextWidth - 3 * aSpacer));
+ Standard_Integer aColorWidth = Max (5, Min (20, myWidth - aTextWidth - 3 * aSpacer));
if (aLabPos == Aspect_TOCSP_CENTER || !toDrawLabel)
- aColorWidth = aWinWidth - 2 * aSpacer;
+ aColorWidth += aTextWidth;
// Draw colors
Standard_Integer aX = (Standard_Integer)myXPos + aSpacer;
Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
//! Returns the size of color scale.
- Standard_EXPORT void GetSize (Standard_Real& theWidth, Standard_Real& theHeight) const;
+ Standard_EXPORT void GetSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
//! Returns the width of color scale.
- Standard_EXPORT Standard_Real GetWidth() const { return myWidth; }
+ Standard_EXPORT Standard_Integer GetWidth() const { return myWidth; }
//! Returns the height of color scale.
- Standard_EXPORT Standard_Real GetHeight() const { return myHeight; }
+ 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.
- Standard_EXPORT void SetSize (const Standard_Real theWidth, const Standard_Real theHeight);
+ Standard_EXPORT void SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
//! Sets the width of color scale.
- Standard_EXPORT void SetWidth (const Standard_Real theWidth);
+ Standard_EXPORT void SetWidth (const Standard_Integer theWidth);
//! Sets the height of color scale.
- Standard_EXPORT void SetHeight (const Standard_Real theHeight);
+ 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;
//! Returns the X position of color scale.
- Standard_EXPORT Standard_Real GetXPosition() const { return myXPos; }
+ Standard_EXPORT Standard_Integer GetXPosition() const { return myXPos; }
//! Returns the height of color scale.
- Standard_EXPORT Standard_Real GetYPosition() const { return myYPos; }
+ Standard_EXPORT Standard_Integer GetYPosition() const { return myYPos; }
//! Sets the position of color scale.
- Standard_EXPORT void SetPosition (const Standard_Real theX, const Standard_Real theY);
+ Standard_EXPORT void SetPosition (const Standard_Integer theX, const Standard_Integer theY);
//! Sets the X position of color scale.
- Standard_EXPORT void SetXPosition (const Standard_Real theX);
+ Standard_EXPORT void SetXPosition (const Standard_Integer theX);
//! Sets the Y position of color scale.
- Standard_EXPORT void SetYPosition (const Standard_Real theY);
+ Standard_EXPORT void SetYPosition (const Standard_Integer theY);
//! Returns the height of text of color scale.
Standard_EXPORT Standard_Integer GetTextHeight() const { return myTextHeight; }
TColStd_SequenceOfExtendedString myLabels;
Aspect_TypeOfColorScalePosition myLabelPos;
Aspect_TypeOfColorScalePosition myTitlePos;
- Standard_Real myXPos;
- Standard_Real myYPos;
- Standard_Real myWidth;
- Standard_Real myHeight;
+ Standard_Integer myXPos;
+ Standard_Integer myYPos;
+ Standard_Integer myWidth;
+ Standard_Integer myHeight;
Standard_Integer myTextHeight;
+ Quantity_Color myBgColor;
};
#endif
{
aCS->SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt (-1,-1,0));
}
+ Standard_Integer aWinWidth, aWinHeight;
+ V->Window()->Size (aWinWidth, aWinHeight);
+ aCS->SetSize (aWinWidth, aWinHeight);
if ( !V.IsNull() ) {
if (mode == 0) {
aContext->Display (aCS);
Standard_Real aMinRange = aCS->GetMin();
Standard_Real aMaxRange = aCS->GetMax();
+ Standard_Integer aWidth = aCS->GetWidth();
+ Standard_Integer aHeight = aCS->GetHeight();
Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
Standard_Integer aTextHeight = aCS->GetTextHeight();
Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
- gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition());
+ Standard_Integer aPosX = aCS->GetXPosition();
+ Standard_Integer aPosY = aCS->GetYPosition();
ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
<< "Max range: " << aMaxRange << "\n"
<< "Number of intervals: " << aNbIntervals << "\n"
<< "Text height: " << aTextHeight << "\n"
- << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n"
+ << "Color scale position: " << aPosX <<" "<< aPosY<< "\n"
<< "Color scale title: " << aCS->GetTitle() << "\n"
<< "Label position: ";
switch (aLabPosition)
TCollection_AsciiString aX (theArgVec[++anArgIter]);
TCollection_AsciiString aY (theArgVec[++anArgIter]);
- if (!aX.IsRealValue()
- || !aY.IsRealValue())
+ if (!aX.IsIntegerValue()
+ || !aY.IsIntegerValue())
{
- std::cout << "Error: coordinates should be real values!\n";
+ std::cout << "Error: coordinates should be integer values!\n";
return 1;
}
- aPos.SetCoord (aX.RealValue(), aY.RealValue());
+ aPosX = aX.IntegerValue();
+ aPosY = aY.IntegerValue();
+ }
+ else if (aFlag == "-width"
+ || aFlag == "-w")
+ {
+ if (anArgIter + 1 >= theArgNb)
+ {
+ std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
+ return 1;
+ }
+
+ TCollection_AsciiString aW (theArgVec[++anArgIter]);
+ if (!aW.IsIntegerValue())
+ {
+ std::cout << "Error: a width should be an integer value!\n";
+ return 1;
+ }
+
+ aWidth = aW.IntegerValue();
+ }
+ else if (aFlag == "-height"
+ || aFlag == "-h")
+ {
+ if (anArgIter + 1 >= theArgNb)
+ {
+ std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
+ return 1;
+ }
+
+ TCollection_AsciiString aH (theArgVec[++anArgIter]);
+ if (!aH.IsIntegerValue())
+ {
+ std::cout << "Error: a width should be an integer value!\n";
+ return 1;
+ }
+
+ aHeight = aH.IntegerValue();
}
else if (aFlag == "-color")
{
else if (aFlag == "-demoversion"
|| aFlag == "-demo")
{
- aPos.SetCoord (0.0, 0.0);
+ aPosX = 0;
+ aPosY = 0;
aTextHeight = 16;
aMinRange = 0.0;
aMaxRange = 100;
aNbIntervals = 10;
+ aWidth = 0;
+ aHeight = 0;
aLabPosition = Aspect_TOCSP_RIGHT;
aCS->SetColorType (Aspect_TOCSD_AUTO);
aCS->SetLabelType (Aspect_TOCSD_AUTO);
return 1;
}
}
-
- aCS->SetPosition (aPos.X(), aPos.Y());
- aCS->SetHeight (0.95);
+ if (!aWidth || !aHeight)
+ {
+ Standard_Integer aWinWidth, aWinHeight;
+ aView->Window()->Size (aWinWidth, aWinHeight);
+ if (!aWidth)
+ {
+ aWidth = aWinWidth;
+ }
+ if (!aHeight)
+ {
+ aHeight = aWinHeight;
+ }
+ }
+ aCS->SetSize (aWidth, aHeight);
+ aCS->SetPosition (aPosX, aPosY);
aCS->SetTextHeight (aTextHeight);
aCS->SetRange (aMinRange, aMaxRange);
aCS->SetNumberOfIntervals (aNbIntervals);
aCS->SetLabelPosition (aLabPosition);
+ aCS->SetBGColor (aView->BackgroundColor());
aCS->SetToUpdate();
aContext->Display (aCS);
--- /dev/null
+puts "============"
+puts "OCC26312"
+puts "ColorScale doesn't work as expected."
+puts "============"
+puts ""
+
+vinit View1
+vclear
+vaxo
+
+# Disable ffp
+vcaps -ffp 0
+# draw color scale
+vcolorscale cs -demo
+vdump ${imagedir}/${casename}_View1.png
+
+#add more views
+vinit View2 w=300 h=500
+vinit View3 w=500 h=300
+
+# dump all views
+vactivate View2
+vcolorscale cs -height 500
+vdump ${imagedir}/${casename}_View2.png
+vactivate View3
+vcolorscale cs -height 300
+vdump ${imagedir}/${casename}_View3.png