From 7604a1536514c09cb35998a23ff553493da00b17 Mon Sep 17 00:00:00 2001 From: kgv Date: Mon, 10 Sep 2018 18:44:17 +0300 Subject: [PATCH] 0029988: AIS_Shape - SetWidth() and SetColor() has no effect for FaceBoundary AIS_Shape SetWidth and SetColor methods now propagate modifications to FaceBoundary aspect. --- src/AIS/AIS_ColoredShape.cxx | 10 +++ src/AIS/AIS_GraphicTool.cxx | 17 ++--- src/AIS/AIS_Shape.cxx | 119 ++++++++++++++++++++------------ src/AIS/AIS_Shape.hxx | 11 +-- src/AIS/AIS_TypeOfAttribute.hxx | 1 + tests/bugs/vis/bug23407_2 | 12 ++-- 6 files changed, 102 insertions(+), 68 deletions(-) diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx index 662f7b5ca2..0fc54c84c9 100644 --- a/src/AIS/AIS_ColoredShape.cxx +++ b/src/AIS/AIS_ColoredShape.cxx @@ -77,6 +77,7 @@ AIS_ColoredShape::AIS_ColoredShape (const TopoDS_Shape& theShape) myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect()); myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect()); myDrawer->SetSeenLineAspect (myDrawer->LineAspect()); + myDrawer->SetFaceBoundaryAspect (myDrawer->LineAspect()); } //======================================================================= @@ -90,6 +91,7 @@ AIS_ColoredShape::AIS_ColoredShape (const Handle(AIS_Shape)& theShape) myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect()); myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect()); myDrawer->SetSeenLineAspect (myDrawer->LineAspect()); + myDrawer->SetFaceBoundaryAspect (myDrawer->LineAspect()); if (theShape->HasMaterial()) { SetMaterial (theShape->Material()); @@ -236,6 +238,10 @@ void AIS_ColoredShape::SetColor (const Quantity_Color& theColor) { aDrawer->WireAspect()->SetColor (theColor); } + if (aDrawer->HasOwnFaceBoundaryAspect()) + { + aDrawer->FaceBoundaryAspect()->SetColor (theColor); + } } } @@ -266,6 +272,10 @@ void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth) { aDrawer->WireAspect()->SetWidth (theLineWidth); } + if (aDrawer->HasOwnFaceBoundaryAspect()) + { + aDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth); + } } } diff --git a/src/AIS/AIS_GraphicTool.cxx b/src/AIS/AIS_GraphicTool.cxx index bba590f76e..c42c482952 100644 --- a/src/AIS/AIS_GraphicTool.cxx +++ b/src/AIS/AIS_GraphicTool.cxx @@ -31,43 +31,34 @@ static Handle(Prs3d_LineAspect) GetLineAspect(const Handle(Prs3d_Drawer)& Dr, const AIS_TypeOfAttribute Att) { - switch(Att){ + switch(Att) + { case AIS_TOA_Line: return Dr->LineAspect(); - break; case AIS_TOA_Dimension: return Dr->DimensionAspect()->LineAspect(); - break; case AIS_TOA_Wire: return Dr->WireAspect(); - break; case AIS_TOA_Plane: return Dr->PlaneAspect()->EdgesAspect(); - break; case AIS_TOA_Vector: return Dr->VectorAspect(); - break; case AIS_TOA_UIso: return Handle(Prs3d_LineAspect) (Dr->UIsoAspect()); - break; case AIS_TOA_VIso: return Handle(Prs3d_LineAspect) (Dr->VIsoAspect()); - break; case AIS_TOA_Free: return Dr->FreeBoundaryAspect(); - break; case AIS_TOA_UnFree: return Dr->UnFreeBoundaryAspect(); - break; case AIS_TOA_Section: return Dr->SectionAspect(); - break; case AIS_TOA_Hidden: return Dr->HiddenLineAspect(); - break; case AIS_TOA_Seen: return Dr->SeenLineAspect(); - break; + case AIS_TOA_FaceBoundary: + return Dr->FaceBoundaryAspect(); case AIS_TOA_FirstAxis: return Dr->DatumAspect()->LineAspect(Prs3d_DP_XAxis); case AIS_TOA_SecondAxis: diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index de7ca1b082..b22bc6eea3 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -346,11 +346,13 @@ Standard_Real AIS_Shape::Transparency() const { //purpose : //======================================================================= -void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, +bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, const Quantity_Color& theColor) const { + bool toRecompute = false; if (!theDrawer->HasOwnShadingAspect()) { + toRecompute = true; theDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); if (theDrawer->HasLink()) { @@ -359,6 +361,7 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnLineAspect()) { + toRecompute = true; theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { @@ -367,6 +370,7 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnWireAspect()) { + toRecompute = true; theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { @@ -375,6 +379,7 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnPointAspect()) { + toRecompute = true; theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0)); if (theDrawer->HasLink()) { @@ -383,6 +388,7 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnFreeBoundaryAspect()) { + toRecompute = true; theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { @@ -391,6 +397,7 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnUnFreeBoundaryAspect()) { + toRecompute = true; theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { @@ -399,12 +406,22 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnSeenLineAspect()) { + toRecompute = true; theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect(); } } + if (!theDrawer->HasOwnFaceBoundaryAspect()) + { + toRecompute = true; + theDrawer->SetFaceBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); + if (theDrawer->HasLink()) + { + *theDrawer->FaceBoundaryAspect()->Aspect() = *theDrawer->Link()->FaceBoundaryAspect()->Aspect(); + } + } // override color theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel); @@ -414,6 +431,8 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, theDrawer->FreeBoundaryAspect()->SetColor (theColor); theDrawer->UnFreeBoundaryAspect()->SetColor (theColor); theDrawer->SeenLineAspect()->SetColor (theColor); + theDrawer->FaceBoundaryAspect()->SetColor (theColor); + return toRecompute; } //======================================================================= @@ -423,9 +442,16 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer, void AIS_Shape::SetColor (const Quantity_Color& theColor) { - setColor (myDrawer, theColor); + const bool toRecompute = setColor (myDrawer, theColor); myDrawer->SetColor (theColor); hasOwnColor = Standard_True; + if (!toRecompute) + { + myToRecomputeModes.Clear(); + myRecomputeEveryPrs = false; + SynchronizeAspects(); + return; + } // modify shading presentation without re-computation const PrsMgr_Presentations& aPrsList = Presentations(); @@ -477,8 +503,10 @@ void AIS_Shape::UnsetColor() if (!HasColor()) { myToRecomputeModes.Clear(); + myRecomputeEveryPrs = false; return; } + hasOwnColor = Standard_False; myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE)); @@ -490,6 +518,7 @@ void AIS_Shape::UnsetColor() myDrawer->SetFreeBoundaryAspect (anEmptyAsp); myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp); myDrawer->SetSeenLineAspect (anEmptyAsp); + myDrawer->SetFaceBoundaryAspect (anEmptyAsp); } else { @@ -522,6 +551,12 @@ void AIS_Shape::UnsetColor() AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor); } myDrawer->SeenLineAspect()->SetColor (aColor); + aColor = Quantity_NOC_BLACK; + if (myDrawer->HasLink()) + { + AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_FaceBoundary, aColor); + } + myDrawer->FaceBoundaryAspect()->SetColor (aColor); } if (!myDrawer->HasOwnShadingAspect()) @@ -568,40 +603,7 @@ void AIS_Shape::UnsetColor() myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); } myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)()); - - // modify shading presentation without re-computation - const PrsMgr_Presentations& aPrsList = Presentations(); - Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->LineAspect()->Aspect(); - for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) - { - const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); - if (aPrsModed.Mode() != AIS_Shaded) - { - continue; - } - - const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation(); - 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)) - { - aGroup->SetGroupPrimitivesAspect (anAreaAsp); - } - if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE)) - { - aGroup->SetGroupPrimitivesAspect (aLineAsp); - } - } - } - - LoadRecomputable (AIS_WireFrame); - LoadRecomputable (2); + myRecomputeEveryPrs = true; } //======================================================================= @@ -609,11 +611,13 @@ void AIS_Shape::UnsetColor() //purpose : //======================================================================= -void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, +bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theLineWidth) const { + bool toRecompute = false; if (!theDrawer->HasOwnLineAspect()) { + toRecompute = true; theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { @@ -622,6 +626,7 @@ void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnWireAspect()) { + toRecompute = true; theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { @@ -630,6 +635,7 @@ void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnFreeBoundaryAspect()) { + toRecompute = true; theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { @@ -638,6 +644,7 @@ void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnUnFreeBoundaryAspect()) { + toRecompute = true; theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { @@ -646,12 +653,22 @@ void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, } if (!theDrawer->HasOwnSeenLineAspect()) { + toRecompute = true; theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); if (theDrawer->HasLink()) { *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect(); } } + if (!theDrawer->HasOwnFaceBoundaryAspect()) + { + toRecompute = true; + theDrawer->SetFaceBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); + if (theDrawer->HasLink()) + { + *theDrawer->FaceBoundaryAspect()->Aspect() = *theDrawer->Link()->FaceBoundaryAspect()->Aspect(); + } + } // override width theDrawer->LineAspect()->SetWidth (theLineWidth); @@ -659,6 +676,8 @@ void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth); theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth); theDrawer->SeenLineAspect()->SetWidth (theLineWidth); + theDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth); + return toRecompute; } //======================================================================= @@ -668,10 +687,17 @@ void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer, void AIS_Shape::SetWidth (const Standard_Real theLineWidth) { - setWidth (myDrawer, theLineWidth); myOwnWidth = theLineWidth; - LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe.... - LoadRecomputable (2); // and the bounding box... + if (setWidth (myDrawer, theLineWidth)) + { + myRecomputeEveryPrs = true; + } + else + { + myRecomputeEveryPrs = false; + myToRecomputeModes.Clear(); + SynchronizeAspects(); + } } //======================================================================= @@ -684,20 +710,21 @@ void AIS_Shape::UnsetWidth() if (myOwnWidth == 0.0) { myToRecomputeModes.Clear(); + myRecomputeEveryPrs = false; return; } myOwnWidth = 0.0; - - Handle(Prs3d_LineAspect) anEmptyAsp; - if (!HasColor()) { + const Handle(Prs3d_LineAspect) anEmptyAsp; myDrawer->SetLineAspect (anEmptyAsp); myDrawer->SetWireAspect (anEmptyAsp); myDrawer->SetFreeBoundaryAspect (anEmptyAsp); myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp); myDrawer->SetSeenLineAspect (anEmptyAsp); + myDrawer->SetFaceBoundaryAspect (anEmptyAsp); + myRecomputeEveryPrs = true; } else { @@ -711,8 +738,12 @@ void AIS_Shape::UnsetWidth() AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.); myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ? AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.); + myDrawer->FaceBoundaryAspect() ->SetWidth (myDrawer->HasLink() ? + AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_FaceBoundary) : 1.); + SynchronizeAspects(); + myToRecomputeModes.Clear(); + myRecomputeEveryPrs = false; } - LoadRecomputable (AIS_WireFrame); } //======================================================================= diff --git a/src/AIS/AIS_Shape.hxx b/src/AIS/AIS_Shape.hxx index c6f566f2f5..fccbd6e88f 100644 --- a/src/AIS/AIS_Shape.hxx +++ b/src/AIS/AIS_Shape.hxx @@ -174,8 +174,7 @@ public: Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE; //! Sets the value aValue for line width in the reconstructed compound shape. - //! Changes line aspects for lines-only presentation modes like Wireframe and Bounding Box. - //! Doesn't change face boundary line aspect. + //! Changes line aspects for lines presentation. Standard_EXPORT virtual void SetWidth (const Standard_Real aValue) Standard_OVERRIDE; //! Removes the setting for line width in the reconstructed compound shape. @@ -305,9 +304,13 @@ protected: Standard_EXPORT void LoadRecomputable (const Standard_Integer TheMode); - Standard_EXPORT void setColor (const Handle(Prs3d_Drawer)& theDrawer, const Quantity_Color& theColor) const; + //! Create own aspects (if they do not exist) and set color to them. + //! @return TRUE if new aspects have been created + Standard_EXPORT bool setColor (const Handle(Prs3d_Drawer)& theDrawer, const Quantity_Color& theColor) const; - Standard_EXPORT void setWidth (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theWidth) const; + //! Create own aspects (if they do not exist) and set width to them. + //! @return TRUE if new aspects have been created + Standard_EXPORT bool setWidth (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theWidth) const; Standard_EXPORT void setTransparency (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theValue) const; diff --git a/src/AIS/AIS_TypeOfAttribute.hxx b/src/AIS/AIS_TypeOfAttribute.hxx index c31efd19e2..10ad56db2a 100644 --- a/src/AIS/AIS_TypeOfAttribute.hxx +++ b/src/AIS/AIS_TypeOfAttribute.hxx @@ -32,6 +32,7 @@ AIS_TOA_UnFree, AIS_TOA_Section, AIS_TOA_Hidden, AIS_TOA_Seen, +AIS_TOA_FaceBoundary, AIS_TOA_FirstAxis, AIS_TOA_SecondAxis, AIS_TOA_ThirdAxis diff --git a/tests/bugs/vis/bug23407_2 b/tests/bugs/vis/bug23407_2 index 55e373e21f..bf438d515f 100755 --- a/tests/bugs/vis/bug23407_2 +++ b/tests/bugs/vis/bug23407_2 @@ -1,18 +1,16 @@ puts "============" -puts "CR23407" +puts "CR23407: Draw face outlines for XDE objects" puts "============" puts "" -####################################################################### -# Draw face outlines for XDE objects -####################################################################### box b 10 10 10 -vinit +vclear +vinit View1 vdisplay b vsetdispmode 1 -vshowfaceboundary b 1 255 0 0 10 1 +vshowfaceboundary b 1 255 0 0 5 1 vfit -vaspects -setwidth 5 +vaspects -setwidth 10 if { "[vreadpixel 314 344 rgb name]" != "RED" || "[vreadpixel 26 267 rgb name]" != "RED" } {