From e5b8456d5bb9912b554fb0b218439f0a7f6c8211 Mon Sep 17 00:00:00 2001 From: kgv Date: Tue, 23 Aug 2016 15:18:48 +0300 Subject: [PATCH] 0027783: Visualization, XCAFPrs_AISObject - override method SetMaterial() XCAFPrs_AISObject::SetMaterial() now changes the default material of the object but preserves custom XDE styles. XCAFPrs_AISObject::Compute() now does not reset map of custom aspects each call, so that to keep in sync aspects across multiple presentations. AIS_InteractiveContext - private methods and class fields are now protected to allow inheritance. --- src/AIS/AIS_ColoredShape.hxx | 4 +- src/AIS/AIS_InteractiveContext.hxx | 22 +++---- src/XCAFPrs/XCAFPrs_AISObject.cxx | 99 ++++++++++++++++++++++++------ src/XCAFPrs/XCAFPrs_AISObject.hxx | 15 ++++- 4 files changed, 105 insertions(+), 35 deletions(-) diff --git a/src/AIS/AIS_ColoredShape.hxx b/src/AIS/AIS_ColoredShape.hxx index 8ebbc565b6..4132fc8ba4 100644 --- a/src/AIS/AIS_ColoredShape.hxx +++ b/src/AIS/AIS_ColoredShape.hxx @@ -38,10 +38,10 @@ public: //! @name sub-shape aspects //! Customize properties of specified sub-shape. //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape! //! This method can be used to mark sub-shapes with customizable properties. - Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape); + Standard_EXPORT virtual Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape); //! Reset the map of custom sub-shape aspects. - Standard_EXPORT void ClearCustomAspects(); + Standard_EXPORT virtual void ClearCustomAspects(); //! Reset custom properties of specified sub-shape. //! @param theToUnregister unregister or not sub-shape from the map diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index 1aa68e1ccd..4643ec9648 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -1556,12 +1556,6 @@ friend class AIS_LocalContext; protected: - - - -private: - - Standard_EXPORT void GetDefModes (const Handle(AIS_InteractiveObject)& anIobj, Standard_Integer& Dmode, Standard_Integer& HiMod, Standard_Integer& SelMode) const; Standard_EXPORT void EraseGlobal (const Handle(AIS_InteractiveObject)& anObj, const Standard_Boolean updateviewer = Standard_True); @@ -1581,28 +1575,30 @@ private: Standard_EXPORT void redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj, const Standard_Boolean theToUpdateViewer = Standard_True); //! Helper function to unhighlight all entity owners currently highlighted with seleciton color. - void unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject); + Standard_EXPORT void unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject); //! Helper function that highlights the owner given with without //! performing AutoHighlight checks, e.g. is used for dynamic highlight. //! If the parameter is set and is true, highlight will be synchronized //! automatically in all views of the viewer. - void highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner, - const Quantity_NameOfColor theColor, - const Handle(V3d_Viewer)& theViewer = NULL); + Standard_EXPORT void highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner, + const Quantity_NameOfColor theColor, + const Handle(V3d_Viewer)& theViewer = NULL); //! Helper function that highlights the owner given with with check //! for AutoHighlight, e.g. is used for selection. //! If the parameter is set and is true, selection color will be synchronized //! automatically in all views of the viewer. - void highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner, - const Quantity_NameOfColor theSelColor); + Standard_EXPORT void highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner, + const Quantity_NameOfColor theSelColor); //! Helper function that unhighlights all owners that are stored in current AIS_Selection. //! The function updates global status and selection state of owner and interactive object. //! If the parameter is set to true, interactive objects with sub-intensity //! switched on in AIS_GlobalStatus will be highlighted with context's sub-intensity color. - void unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity = Standard_False); + Standard_EXPORT void unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity = Standard_False); + +protected: AIS_DataMapOfIOStatus myObjects; Handle(SelectMgr_SelectionManager) mgrSelector; diff --git a/src/XCAFPrs/XCAFPrs_AISObject.cxx b/src/XCAFPrs/XCAFPrs_AISObject.cxx index 4b9607a13c..27b4a0377e 100644 --- a/src/XCAFPrs/XCAFPrs_AISObject.cxx +++ b/src/XCAFPrs/XCAFPrs_AISObject.cxx @@ -46,10 +46,13 @@ IMPLEMENT_STANDARD_RTTIEXT(XCAFPrs_AISObject,AIS_ColoredShape) //======================================================================= XCAFPrs_AISObject::XCAFPrs_AISObject (const TDF_Label& theLabel) -: AIS_ColoredShape(TopoDS_Shape()) +: AIS_ColoredShape(TopoDS_Shape()), + myToSyncStyles (Standard_True) { // define plastic material by default for proper color reproduction - SetMaterial (Graphic3d_NOM_PLASTIC); + setMaterial (myDrawer, Graphic3d_NOM_PLASTIC, Standard_False, Standard_False); + hasOwnMaterial = Standard_True; + myLabel = theLabel; } @@ -112,33 +115,26 @@ static void DisplayText (const TDF_Label& aLabel, } //======================================================================= -//function : Compute -//purpose : +//function : DispatchStyles +//purpose : //======================================================================= -void XCAFPrs_AISObject::Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePrs, - const Standard_Integer theMode) +void XCAFPrs_AISObject::DispatchStyles (const Standard_Boolean theToSyncStyles) { + myToSyncStyles = theToSyncStyles; + myShapeColors.Clear(); + TopoDS_Shape aShape; - if (!XCAFDoc_ShapeTool::GetShape (myLabel, aShape) || aShape.IsNull()) return; - - // Shape vide -> Assemblage vide. - if (aShape.ShapeType() == TopAbs_COMPOUND) + if (!XCAFDoc_ShapeTool::GetShape (myLabel, aShape) || aShape.IsNull()) { - TopoDS_Iterator anExplor (aShape); - if (!anExplor.More()) - { - return; - } + Set (TopoDS_Shape()); + return; } - Set (aShape); - ClearCustomAspects(); // Collecting information on colored subshapes TopLoc_Location aLoc; XCAFPrs_DataMapOfShapeStyle aSettings; - XCAFPrs::CollectStyleSettings ( myLabel, aLoc, aSettings ); + XCAFPrs::CollectStyleSettings (myLabel, aLoc, aSettings); // Getting default colors XCAFPrs_Style aDefStyle; @@ -190,6 +186,47 @@ void XCAFPrs_AISObject::Compute (const Handle(PrsMgr_PresentationManager3d)& the SetColors (aDrawer, aColorCurv, aColorSurf); } aStyleGroups.Clear(); +} + +//======================================================================= +//function : Compute +//purpose : +//======================================================================= +void XCAFPrs_AISObject::Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePrs, + const Standard_Integer theMode) +{ + // update shape and sub-shapes styles only on first compute, or on first recompute + if (myToSyncStyles) + { + Standard_Boolean toMapStyles = myToSyncStyles; + for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) + { + if (aPrsIter.Value().Presentation()->Presentation() != thePrs + && !aPrsIter.Value().Presentation()->MustBeUpdated()) + { + toMapStyles = Standard_False; + break; + } + } + if (toMapStyles) + { + DispatchStyles (Standard_True); + } + } + if (myshape.IsNull()) + { + return; + } + + if (myshape.ShapeType() == TopAbs_COMPOUND) + { + TopoDS_Iterator anExplor (myshape); + if (!anExplor.More()) + { + return; + } + } AIS_ColoredShape::Compute (thePresentationManager, thePrs, theMode); @@ -289,3 +326,27 @@ void XCAFPrs_AISObject::DefaultStyle (XCAFPrs_Style& theStyle) const theStyle.SetColorSurf (Quantity_NOC_WHITE); theStyle.SetColorCurv (Quantity_NOC_WHITE); } + +// ======================================================================= +// function : SetMaterial +// purpose : +// ======================================================================= +void XCAFPrs_AISObject::SetMaterial (const Graphic3d_MaterialAspect& theMaterial) +{ + XCAFPrs_Style aDefStyle; + DefaultStyle (aDefStyle); + setMaterial (myDrawer, theMaterial, HasColor(), IsTransparent()); + SetColors (myDrawer, aDefStyle.GetColorCurv(), aDefStyle.GetColorSurf()); + for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) + { + const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value(); + + // take current color + const Quantity_Color aColorCurv = aDrawer->WireAspect()->Aspect()->Color(); + const Quantity_Color aSurfColor = aDrawer->ShadingAspect()->Aspect()->InteriorColor(); + + // SetColors() will take the material from myDrawer + SetColors (aDrawer, aColorCurv, aSurfColor); + } + SynchronizeAspects(); +} diff --git a/src/XCAFPrs/XCAFPrs_AISObject.hxx b/src/XCAFPrs/XCAFPrs_AISObject.hxx index c59c84da7f..6038dce850 100644 --- a/src/XCAFPrs/XCAFPrs_AISObject.hxx +++ b/src/XCAFPrs/XCAFPrs_AISObject.hxx @@ -38,6 +38,18 @@ public: myLabel = theLabel; } + //! Fetch the Shape from associated Label and fill the map of sub-shapes styles. + //! By default, this method is called implicitly within first ::Compute(). + //! Application might call this method explicitly to manipulate styles afterwards. + //! @param theToSyncStyles flag indicating if method ::Compute() should call this method again + //! on first compute or re-compute + Standard_EXPORT virtual void DispatchStyles (const Standard_Boolean theToSyncStyles = Standard_False); + + //! Sets the material aspect. + //! This method assigns the new default material without overriding XDE styles. + //! Re-computation of existing presentation is not required after calling this method. + Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theMaterial) Standard_OVERRIDE; + protected: //! Redefined method to compute presentation. @@ -57,7 +69,8 @@ protected: protected: - TDF_Label myLabel; + TDF_Label myLabel; //!< label pointing onto the shape + Standard_Boolean myToSyncStyles; //!< flag indicating that shape and sub-shapes should be updates within Compute() public: