diff --git a/src/AIS/AIS_ColorScale.cxx b/src/AIS/AIS_ColorScale.cxx index 93a1f682dc..9b53f63211 100644 --- a/src/AIS/AIS_ColorScale.cxx +++ b/src/AIS/AIS_ColorScale.cxx @@ -57,9 +57,10 @@ myLabelPos (Aspect_TOCSP_RIGHT), 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) { } @@ -351,7 +352,7 @@ void AIS_ColorScale::GetPosition (Standard_Real& theX, Standard_Real& theY) cons //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; @@ -364,7 +365,7 @@ void AIS_ColorScale::SetPosition (const Standard_Real theX, const Standard_Real //function : SetXPosition //purpose : //======================================================================= -void AIS_ColorScale::SetXPosition (const Standard_Real theX) +void AIS_ColorScale::SetXPosition (const Standard_Integer theX) { SetPosition (theX, GetYPosition()); } @@ -373,7 +374,7 @@ void AIS_ColorScale::SetXPosition (const Standard_Real theX) //function : SetYPosition //purpose : //======================================================================= -void AIS_ColorScale::SetYPosition (const Standard_Real theY) +void AIS_ColorScale::SetYPosition (const Standard_Integer theY) { SetPosition (GetXPosition(), theY); } @@ -382,7 +383,7 @@ void AIS_ColorScale::SetYPosition (const Standard_Real 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; @@ -392,7 +393,7 @@ void AIS_ColorScale::GetSize (Standard_Real& theWidth, Standard_Real& theHeight) //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; @@ -405,7 +406,7 @@ void AIS_ColorScale::SetSize (const Standard_Real theWidth, const Standard_Real //function : SetWidth //purpose : //======================================================================= -void AIS_ColorScale::SetWidth (const Standard_Real theWidth) +void AIS_ColorScale::SetWidth (const Standard_Integer theWidth) { SetSize (theWidth, GetHeight()); } @@ -414,7 +415,7 @@ void AIS_ColorScale::SetWidth (const Standard_Real theWidth) //function : SetHeight //purpose : //======================================================================= -void AIS_ColorScale::SetHeight (const Standard_Real theHeight) +void AIS_ColorScale::SetHeight (const Standard_Integer theHeight) { SetSize (GetWidth(), theHeight); } @@ -546,11 +547,9 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr 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(); @@ -567,7 +566,7 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr 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(); @@ -602,18 +601,18 @@ void AIS_ColorScale::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePr 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; diff --git a/src/AIS/AIS_ColorScale.hxx b/src/AIS/AIS_ColorScale.hxx index 1d67bead16..86fa980627 100644 --- a/src/AIS/AIS_ColorScale.hxx +++ b/src/AIS/AIS_ColorScale.hxx @@ -147,40 +147,46 @@ public: 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; } @@ -265,10 +271,11 @@ private: 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 diff --git a/src/QABugs/QABugs_11.cxx b/src/QABugs/QABugs_11.cxx index 1ada39b5e6..b619e3f63f 100644 --- a/src/QABugs/QABugs_11.cxx +++ b/src/QABugs/QABugs_11.cxx @@ -4550,6 +4550,9 @@ static Standard_Integer OCC12584 (Draw_Interpretor& di, Standard_Integer argc, c { 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); diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index a16b936087..f73417ee75 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -3478,10 +3478,13 @@ static int VColorScale (Draw_Interpretor& theDI, 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); @@ -3497,7 +3500,7 @@ static int VColorScale (Draw_Interpretor& theDI, << "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) @@ -3616,14 +3619,51 @@ static int VColorScale (Draw_Interpretor& theDI, 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") { @@ -3828,11 +3868,14 @@ static int VColorScale (Draw_Interpretor& theDI, 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); @@ -3843,13 +3886,26 @@ static int VColorScale (Draw_Interpretor& theDI, 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); diff --git a/tests/bugs/vis/bug26312 b/tests/bugs/vis/bug26312 new file mode 100644 index 0000000000..c94faaacff --- /dev/null +++ b/tests/bugs/vis/bug26312 @@ -0,0 +1,27 @@ +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