From 48cc825e838f53f5a457abe23d71fe7a422f41c6 Mon Sep 17 00:00:00 2001 From: aba Date: Thu, 22 May 2014 17:33:02 +0400 Subject: [PATCH] 0002883: It is impossible to set material, color and transparency to compound Fast shading presentation update on setting color, material and transparency for AIS_Shape: - Iterate through all groups not only last one. - Iterate through all presentation (to change presentations in all viewers). Added test cases bugs/vis/bug2883_1 and bugs/vis/bug2883_2 --- src/AIS/AIS_Shape.cxx | 187 ++++++++++++++++++++++++--------------- tests/bugs/vis/bug2883_1 | 26 ++++++ tests/bugs/vis/bug2883_2 | 31 +++++++ 3 files changed, 173 insertions(+), 71 deletions(-) create mode 100644 tests/bugs/vis/bug2883_1 create mode 100644 tests/bugs/vis/bug2883_2 diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index 1114378bf9..bc913c38ff 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -539,35 +540,45 @@ void AIS_Shape::SetColor (const Quantity_Color& theColor) myOwnColor = theColor; hasOwnColor = Standard_True; - // fast shading modification... - if (!GetContext().IsNull()) + // modify shading presentation without re-computation + const PrsMgr_Presentations& aPrsList = Presentations(); + Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect(); + Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect(); + Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect(); + for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) { - if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); + if (aPrsModed.Mode() != AIS_Shaded) { - Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); - Handle(Graphic3d_Group) aCurGroup = Prs3d_Root::CurrentGroup (aPrs); - Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect(); - Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect(); - Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect(); - - // Set aspects for presentation and for group - aPrs->SetPrimitivesAspect (anAreaAspect); - aPrs->SetPrimitivesAspect (aLineAspect); - aPrs->SetPrimitivesAspect (aPointAspect); + continue; + } + + const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); + + // Set aspects for presentation + aPrs->SetPrimitivesAspect (anAreaAspect); + aPrs->SetPrimitivesAspect (aLineAspect); + aPrs->SetPrimitivesAspect (aPointAspect); + + // Go through all groups to change color for all primitives + for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) + { + const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); + // 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 (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) { - aCurGroup->SetGroupPrimitivesAspect (anAreaAspect); + aGroup->SetGroupPrimitivesAspect (anAreaAspect); } - if (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE)) + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE)) { - aCurGroup->SetGroupPrimitivesAspect (aLineAspect); + aGroup->SetGroupPrimitivesAspect (aLineAspect); } - if (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER)) + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER)) { - aCurGroup->SetGroupPrimitivesAspect (aPointAspect); + aGroup->SetGroupPrimitivesAspect (aPointAspect); } } } @@ -636,21 +647,28 @@ void AIS_Shape::UnsetColor() } myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)()); - if (!GetContext().IsNull()) + // modify shading presentation without re-computation + const PrsMgr_Presentations& aPrsList = Presentations(); + Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect(); + Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect(); + for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) { - if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); + if (aPrsModed.Mode() != AIS_Shaded) { - Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->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, + continue; + } + + const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); + + aPrs->SetPrimitivesAspect (anAreaAsp); + aPrs->SetPrimitivesAspect (aLineAsp); + + for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) + { + const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); + + // 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)) @@ -663,6 +681,7 @@ void AIS_Shape::UnsetColor() } } } + LoadRecomputable (AIS_WireFrame); LoadRecomputable (2); } @@ -775,15 +794,23 @@ void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat) } myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel); - if (!GetContext().IsNull()) + // modify shading presentation without re-computation + const PrsMgr_Presentations& aPrsList = Presentations(); + Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); + for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) { - if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); + if (aPrsModed.Mode() != AIS_Shaded) { - Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); - - Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - aPrs->SetPrimitivesAspect (anAreaAsp); + continue; + } + + const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); + aPrs->SetPrimitivesAspect (anAreaAsp); + for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) + { + const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); + // 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 @@ -792,9 +819,10 @@ void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat) aGroup->SetGroupPrimitivesAspect (anAreaAsp); } } - myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update - myToRecomputeModes.Clear(); } + + myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update + myToRecomputeModes.Clear(); } //======================================================================= @@ -826,23 +854,29 @@ void AIS_Shape::UnsetMaterial() } hasOwnMaterial = Standard_False; - if (!GetContext().IsNull()) + // modify shading presentation without re-computation + const PrsMgr_Presentations& aPrsList = Presentations(); + Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); + for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) { - if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); + if (aPrsModed.Mode() != AIS_Shaded) { - Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); - Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - aPrs->SetPrimitivesAspect (anAreaAsp); - // 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 + continue; + } + + const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); + aPrs->SetPrimitivesAspect (anAreaAsp); + for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) + { + const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) { aGroup->SetGroupPrimitivesAspect (anAreaAsp); } } } + myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update myToRecomputeModes.Clear(); } @@ -875,25 +909,30 @@ void AIS_Shape::SetTransparency (const Standard_Real theValue) setTransparency (myDrawer, theValue); myTransparency = theValue; - if (!GetContext().IsNull()) + // modify shading presentation without re-computation + const PrsMgr_Presentations& aPrsList = Presentations(); + Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); + for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) { - if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); + if (aPrsModed.Mode() != AIS_Shaded) { - Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); - Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - aPrs->SetPrimitivesAspect (anAreaAsp); - // force highest priority for transparent objects - aPrs->SetDisplayPriority (10); - // 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 + continue; + } + + const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); + aPrs->SetPrimitivesAspect (anAreaAsp); + aPrs->SetDisplayPriority (10); // force highest priority for translucent objects + for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) + { + const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) { aGroup->SetGroupPrimitivesAspect (anAreaAsp); } } } + myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update myToRecomputeModes.Clear(); } @@ -919,24 +958,30 @@ void AIS_Shape::UnsetTransparency() myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); } - if (!GetContext().IsNull()) + // modify shading presentation without re-computation + const PrsMgr_Presentations& aPrsList = Presentations(); + Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); + for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) { - if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); + if (aPrsModed.Mode() != AIS_Shaded) { - Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); - Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - aPrs->SetPrimitivesAspect (anAreaAsp); - // 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 + continue; + } + + const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); + aPrs->SetPrimitivesAspect (anAreaAsp); + for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next()) + { + const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value(); if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) { aGroup->SetGroupPrimitivesAspect (anAreaAsp); } - aPrs->ResetDisplayPriority(); } + aPrs->ResetDisplayPriority(); } + myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update myToRecomputeModes.Clear(); } diff --git a/tests/bugs/vis/bug2883_1 b/tests/bugs/vis/bug2883_1 new file mode 100644 index 0000000000..23989a749d --- /dev/null +++ b/tests/bugs/vis/bug2883_1 @@ -0,0 +1,26 @@ +puts "==========" +puts "OCC2883" +puts "==========" +puts "" +######################################################################## +# It is impossible to set material, color and transparency to compound +######################################################################## + +vertex v -20 10 -30 +vertex ve1 -10 10 10 +vertex ve2 0 10 10 +edge e ve1 ve2 +sphere s -80 0 0 150 +mkface f s 0.1 0.7 0.2 0.9 +box s -60 0 0 30 60 40 +compound v e f s c + +vinit View1 +vclear +vaxo +vsetdispmode 1 +vdisplay c +vfit +vsetmaterial c JADE +set only_screen 1 + diff --git a/tests/bugs/vis/bug2883_2 b/tests/bugs/vis/bug2883_2 new file mode 100644 index 0000000000..202ae50404 --- /dev/null +++ b/tests/bugs/vis/bug2883_2 @@ -0,0 +1,31 @@ +puts "==========" +puts "OCC2883" +puts "==========" +puts "" +######################################################################## +# It is impossible to set material, color and transparency to compound +######################################################################## + +box b1 0 0 0 1 2 3 +box b2 4 0 0 3 1 2 +vinit drv1/v1/v1 +vsetdispmode 1 +vdisplay b1 b2 +vfit +vinit drv1/v2/v1 +vsetdispmode 1 +vdisplay b1 b2 +vfit +vsetcolor b1 RED +vactivate drv1/v1/v1 +vdump v1.png +vactivate drv1/v2/v1 +vdump v2.png +set info [diffimage v1.png v2.png 0 0 0] +if { $info != 0 } { + puts "Error: images v1 and v2 are different" +} else { + puts "OK: images v1 and v2 are similar" +} + +set only_screen 1 -- 2.20.1