From: kgv Date: Thu, 31 Jan 2019 11:52:19 +0000 (+0300) Subject: 0030464: Visualization - unable to set sub-shape transparency using vaspects command X-Git-Tag: V7_4_0_beta~261 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=c1197a157530359ec94443c53bcd32a48b3e0b18 0030464: Visualization - unable to set sub-shape transparency using vaspects command Added AIS_ColoredShape::SetCustomTransparency() for simple way for assigning sub-shape transparency. --- diff --git a/src/AIS/AIS_ColoredDrawer.hxx b/src/AIS/AIS_ColoredDrawer.hxx index b80be3f0c2..84b555a018 100644 --- a/src/AIS/AIS_ColoredDrawer.hxx +++ b/src/AIS/AIS_ColoredDrawer.hxx @@ -27,6 +27,7 @@ public: AIS_ColoredDrawer (const Handle(Prs3d_Drawer)& theLink) : myIsHidden (false), myHasOwnColor (false), + myHasOwnTransp(false), myHasOwnWidth (false) { Link (theLink); @@ -34,9 +35,15 @@ public: bool IsHidden() const { return myIsHidden; } void SetHidden (const bool theToHide) { myIsHidden = theToHide;} + bool HasOwnColor() const { return myHasOwnColor; } void UnsetOwnColor() { myHasOwnColor = false; } void SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = true; } + + bool HasOwnTransparency() const { return myHasOwnTransp; } + void UnsetOwnTransparency() { myHasOwnTransp = false; } + void SetOwnTransparency (Standard_Real /*theTransp*/) { myHasOwnTransp = true; } + bool HasOwnWidth() const { return myHasOwnWidth; } void UnsetOwnWidth() { myHasOwnWidth = false; } void SetOwnWidth (const Standard_Real /*theWidth*/) { myHasOwnWidth = true; } @@ -45,6 +52,7 @@ public: //! @name list of overridden properties bool myIsHidden; bool myHasOwnColor; + bool myHasOwnTransp; bool myHasOwnWidth; }; diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx index 0fc54c84c9..ef8b54a09c 100644 --- a/src/AIS/AIS_ColoredShape.cxx +++ b/src/AIS/AIS_ColoredShape.cxx @@ -187,6 +187,25 @@ void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape, LoadRecomputable (AIS_Shaded); } +//======================================================================= +//function : SetCustomTransparency +//purpose : +//======================================================================= +void AIS_ColoredShape::SetCustomTransparency (const TopoDS_Shape& theShape, + Standard_Real theTransparency) +{ + if (theShape.IsNull()) + { + return; + } + + const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape); + setTransparency (aDrawer, theTransparency); + aDrawer->SetOwnTransparency (theTransparency); + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); +} + //======================================================================= //function : SetCustomWidth //purpose : @@ -200,7 +219,7 @@ void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape, } const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape); - setWidth (CustomAspects (theShape), theLineWidth); + setWidth (aDrawer, theLineWidth); aDrawer->SetOwnWidth (theLineWidth); LoadRecomputable (AIS_WireFrame); LoadRecomputable (AIS_Shaded); @@ -292,7 +311,12 @@ void AIS_ColoredShape::SetTransparency (const Standard_Real theValue) LoadRecomputable (AIS_Shaded); for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) { - const Handle(Prs3d_Drawer)& aDrawer = anIter.Value(); + const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value(); + if (aDrawer->HasOwnTransparency()) + { + continue; + } + if (aDrawer->HasOwnShadingAspect()) { aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel); @@ -346,7 +370,7 @@ void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial) //if (aDrawer->HasOwnMaterial()) continue; if (aDrawer->HasOwnShadingAspect()) { - setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), Standard_False); // aDrawer->IsTransparent() + setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), aDrawer->HasOwnTransparency()); } } } @@ -715,13 +739,29 @@ Standard_Boolean AIS_ColoredShape::dispatchColors (const Handle(AIS_ColoredDrawe { const TopoDS_Shape& aFace = aFaceIter.Value(); Handle(AIS_ColoredDrawer) aFaceDrawer; - if (aFace.ShapeType() == TopAbs_FACE - && theShapeDrawerMap.Find (aFace, aFaceDrawer) - && aFaceDrawer->IsHidden()) + if (aFace.ShapeType() != TopAbs_FACE + || !theShapeDrawerMap.Find (aFace, aFaceDrawer)) + { + continue; + } + + if (aFaceDrawer->IsHidden()) { isClosedShell = Standard_False; break; } + else if (aFaceDrawer->HasOwnShadingAspect() + && aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_Opaque) + { + if (aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_BlendAuto + || aFaceDrawer->ShadingAspect()->Aspect()->FrontMaterial().Alpha() < 1.0f + || (aFaceDrawer->ShadingAspect()->Aspect()->Distinguish() + && aFaceDrawer->ShadingAspect()->Aspect()->BackMaterial().Alpha() < 1.0f)) + { + isClosedShell = Standard_False; + break; + } + } } } diff --git a/src/AIS/AIS_ColoredShape.hxx b/src/AIS/AIS_ColoredShape.hxx index c713ce1d12..696be6edc4 100644 --- a/src/AIS/AIS_ColoredShape.hxx +++ b/src/AIS/AIS_ColoredShape.hxx @@ -56,6 +56,10 @@ public: //! @name sub-shape aspects Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape, const Quantity_Color& theColor); + //! Customize transparency of specified sub-shape + Standard_EXPORT void SetCustomTransparency (const TopoDS_Shape& theShape, + Standard_Real theTransparency); + //! Customize line width of specified sub-shape Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape, const Standard_Real theLineWidth); diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 9e03442a2d..96bbcaec02 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -1709,7 +1709,7 @@ struct ViewerTest_AspectsChangeSet } //! @return true if properties are valid - Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const + Standard_Boolean Validate() const { Standard_Boolean isOk = Standard_True; if (Visibility != 0 && Visibility != 1) @@ -1729,12 +1729,6 @@ struct ViewerTest_AspectsChangeSet std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n"; isOk = Standard_False; } - if (theIsSubPart - && ToSetTransparency != 0) - { - std::cout << "Error: the transparency can not be defined for sub-part of object!\n"; - isOk = Standard_False; - } if (ToSetAlphaMode == 1 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f)) { @@ -2498,15 +2492,13 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, } } - Standard_Boolean isFirst = Standard_True; for (NCollection_Sequence::Iterator aChangesIter (aChanges); aChangesIter.More(); aChangesIter.Next()) { - if (!aChangesIter.Value().Validate (!isFirst)) + if (!aChangesIter.Value().Validate()) { return 1; } - isFirst = Standard_False; } // special case for -defaults parameter. @@ -2823,6 +2815,10 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, { aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color); } + if (aChangeSet->ToSetTransparency == 1) + { + aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency); + } if (aChangeSet->ToSetLineWidth == 1) { aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth); diff --git a/tests/bugs/xde/bug28641 b/tests/bugs/xde/bug28641 index a0ed6a86c3..73305b8059 100644 --- a/tests/bugs/xde/bug28641 +++ b/tests/bugs/xde/bug28641 @@ -24,7 +24,7 @@ XShow D_First vfit vsetdispmode 1 vdump $::imagedir/${::casename}_first.png -if { [vreadpixel 300 200 rgb name] != "GRAY14" } { puts "Error: wrong color in 3D Viewer" } +if { [vreadpixel 300 200 rgb name] != "DARKKHAKI" } { puts "Error: wrong color in 3D Viewer" } # Write file SaveAs D_First ${imagedir}/bug28521.xbf @@ -83,6 +83,6 @@ XShow D_Second vfit vsetdispmode 1 vdump $::imagedir/${::casename}.png -if { [vreadpixel 300 200 rgb name] != "GRAY14" } { puts "Error: wrong color in 3D Viewer" } +if { [vreadpixel 300 200 rgb name] != "DARKKHAKI" } { puts "Error: wrong color in 3D Viewer" } Close D_Second