From 735dc1d26e45b47002396beacc71066468826d75 Mon Sep 17 00:00:00 2001 From: dbp Date: Thu, 2 Oct 2014 14:05:21 +0400 Subject: [PATCH] 0024930: Visualization - SetMaterial/UnsetMaterial/UnsetColor are not implemented for AIS_TexturedShape Correction of test case for issue CR24930 --- src/AIS/AIS_TexturedShape.cxx | 102 ++++++++++++++++++++++++++++++++-- src/AIS/AIS_TexturedShape.hxx | 11 +++- tests/bugs/vis/bug24930 | 64 +++++++++++++++++++++ 3 files changed, 171 insertions(+), 6 deletions(-) create mode 100755 tests/bugs/vis/bug24930 diff --git a/src/AIS/AIS_TexturedShape.cxx b/src/AIS/AIS_TexturedShape.cxx index b755174944..d8659bc6c1 100644 --- a/src/AIS/AIS_TexturedShape.cxx +++ b/src/AIS/AIS_TexturedShape.cxx @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -25,7 +26,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -197,12 +200,95 @@ void AIS_TexturedShape::SetColor (const Quantity_Color& theColor) { AIS_Shape::SetColor (theColor); - if (!GetContext().IsNull()) + for (Standard_Integer aPrsIt = 1; aPrsIt <= Presentations().Length(); ++aPrsIt) { - if (GetContext()->MainPrsMgr()->HasPresentation (this, 3)) + const PrsMgr_ModedPresentation& aPrsModed = Presentations().Value (aPrsIt); + + if (aPrsModed.Mode() != 3) + continue; + + updateAttributes (aPrsModed.Presentation()->Presentation()); + } +} + +//======================================================================= +//function : UnsetColor +//purpose : +//======================================================================= + +void AIS_TexturedShape::UnsetColor() +{ + AIS_Shape::UnsetColor(); + + for (Standard_Integer aPrsIt = 1; aPrsIt <= Presentations().Length(); ++aPrsIt) + { + const PrsMgr_ModedPresentation& aPrsModed = Presentations().Value (aPrsIt); + + if (aPrsModed.Mode() != 3) + continue; + + Handle(Prs3d_Presentation) aPrs = aPrsModed.Presentation()->Presentation(); + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); + + Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect(); + Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect(); + Quantity_Color aColor; + AIS_GraphicTool::GetInteriorColor (myDrawer->Link(), aColor); + anAreaAsp->SetInteriorColor (aColor); + aPrs->SetPrimitivesAspect (anAreaAsp); + aPrs->SetPrimitivesAspect (aLineAsp); + // Check if aspect of given type is set for the group, + // because setting aspect for group with no already set aspect + // can lead to loss of presentation data + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) { - updateAttributes (GetContext()->MainPrsMgr()->Presentation (this, 3)->Presentation()); + aGroup->SetGroupPrimitivesAspect (anAreaAsp); } + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE)) + { + aGroup->SetGroupPrimitivesAspect (aLineAsp); + } + + updateAttributes (aPrs); + } +} + +//======================================================================= +//function : SetMaterial +//purpose : +//======================================================================= + +void AIS_TexturedShape::SetMaterial (const Graphic3d_MaterialAspect& theMat) +{ + AIS_Shape::SetMaterial (theMat); + + for (Standard_Integer aPrsIt = 1; aPrsIt <= Presentations().Length(); ++aPrsIt) + { + const PrsMgr_ModedPresentation& aPrsModed = Presentations().Value (aPrsIt); + + if (aPrsModed.Mode() != 3) + continue; + + updateAttributes (aPrsModed.Presentation()->Presentation()); + } +} + +//======================================================================= +//function : UnsetMaterial +//purpose : +//======================================================================= +void AIS_TexturedShape::UnsetMaterial() +{ + AIS_Shape::UnsetMaterial(); + + for (Standard_Integer aPrsIt = 1; aPrsIt <= Presentations().Length(); ++aPrsIt) + { + const PrsMgr_ModedPresentation& aPrsModed = Presentations().Value (aPrsIt); + + if (aPrsModed.Mode() != 3) + continue; + + updateAttributes (aPrsModed.Presentation()->Presentation()); } } @@ -281,9 +367,15 @@ void AIS_TexturedShape::updateAttributes (const Handle(Prs3d_Presentation)& theP myAspect->AllowBackFace(); } - if (!thePrs.IsNull()) + // Go through all groups to change fill aspect for all primitives + for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (thePrs->Groups()); aGroupIt.More(); aGroupIt.Next()) { - Prs3d_Root::CurrentGroup (thePrs)->SetGroupPrimitivesAspect (myAspect); + const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); + + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) + { + aGroup->SetGroupPrimitivesAspect (myAspect); + } } } diff --git a/src/AIS/AIS_TexturedShape.hxx b/src/AIS/AIS_TexturedShape.hxx index e87063fa44..e0da81b4af 100644 --- a/src/AIS/AIS_TexturedShape.hxx +++ b/src/AIS/AIS_TexturedShape.hxx @@ -98,9 +98,18 @@ public: //! @name methods to alter texture mapping properties //! @endcode Standard_EXPORT void UpdateAttributes(); - //! Sets the color + //! Sets the color. Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor); + //! Removes settings for the color. + Standard_EXPORT virtual void UnsetColor(); + + //! Sets the material aspect. + Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect); + + //! Removes settings for material aspect. + Standard_EXPORT virtual void UnsetMaterial(); + //! Enables texture modulation Standard_EXPORT void EnableTextureModulate(); diff --git a/tests/bugs/vis/bug24930 b/tests/bugs/vis/bug24930 new file mode 100755 index 0000000000..2886083fdb --- /dev/null +++ b/tests/bugs/vis/bug24930 @@ -0,0 +1,64 @@ +puts "============" +puts "OCC24930" +puts "============" +puts "" + +pload QAcommands + +box b 10 10 10 +vinit +vdisplay b +vsetdispmode b 1 +vfit + +# +set anImage_1 ${imagedir}/${casename}_1.png +vdump ${anImage_1} +# + +# Enable texture +vtexture b 0 + +# +set anImage_2 ${imagedir}/${casename}_2.png +vdump ${anImage_2} +# + +# Set new color +vsetcolor b GREEN +# Check pixel color +checkcolor 205 180 0 0.64705884456634521 0 + +# +set anImage_3 ${imagedir}/${casename}_3.png +vdump ${anImage_3} +# +# Reset color +vunsetcolor b +# Check pixel color +checkcolor 205 180 0.608 0.431 0.071 + +# +set anImage_4 ${imagedir}/${casename}_4.png +vdump ${anImage_4} +# + +# Set new material +vsetmaterial b silver +# Check pixel color +checkcolor 205 180 0.380 0.380 0.380 + +# +set anImage_5 ${imagedir}/${casename}_5.png +vdump ${anImage_5} +# + +# Unset material +vunsetmaterial b +# Check pixel color +checkcolor 205 180 0.608 0.431 0.706 + +# +set anImage_6 ${imagedir}/${casename}_6.png +vdump ${anImage_6} +#