0030464: Visualization - unable to set sub-shape transparency using vaspects command IR-2019-02-01 IR-2019-02-02
authorkgv <kgv@opencascade.com>
Thu, 31 Jan 2019 11:52:19 +0000 (14:52 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 1 Feb 2019 10:26:24 +0000 (13:26 +0300)
Added AIS_ColoredShape::SetCustomTransparency() for simple way for assigning sub-shape transparency.

src/AIS/AIS_ColoredDrawer.hxx
src/AIS/AIS_ColoredShape.cxx
src/AIS/AIS_ColoredShape.hxx
src/ViewerTest/ViewerTest.cxx
tests/bugs/xde/bug28641

index b80be3f..84b555a 100644 (file)
@@ -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;
 
 };
index 0fc54c8..ef8b54a 100644 (file)
@@ -188,6 +188,25 @@ void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape&   theShape,
 }
 
 //=======================================================================
+//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;
+          }
+        }
       }
     }
 
index c713ce1..696be6e 100644 (file)
@@ -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);
index 9e03442..96bbcae 100644 (file)
@@ -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<ViewerTest_AspectsChangeSet>::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);
index a0ed6a8..73305b8 100644 (file)
@@ -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