1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

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.
This commit is contained in:
kgv
2016-08-23 15:18:48 +03:00
committed by bugmaster
parent 0deb6f045f
commit e5b8456d5b
4 changed files with 105 additions and 35 deletions

View File

@@ -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();
}

View File

@@ -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: