return isOverriden || isSubOverride;
}
+//! Function to check if specified compound is sub-shape of another one
+inline Standard_Boolean isContainCompound (const TopoDS_Shape& theShape,
+ const TopoDS_Compound& theCompound)
+{
+ if (theShape.ShapeType() != TopAbs_COMPOUND)
+ {
+ return Standard_False;
+ }
+
+ for (TopoDS_Iterator aSubShapeIter (theShape); aSubShapeIter.More(); aSubShapeIter.Next())
+ {
+ if (aSubShapeIter.Value().ShapeType() != TopAbs_COMPOUND)
+ {
+ continue;
+ }
+ else if (aSubShapeIter.Value() == theCompound
+ || isContainCompound (aSubShapeIter.Value(), theCompound))
+ {
+ return Standard_True;
+ }
+ }
+ return Standard_False;
+}
+
//=======================================================================
//function : dispatchColors
//purpose :
// This needed when colored shape is not part of <theBaseShape>
// (but subshapes are) and actually container for subshapes.
DataMapOfShapeShape aSubshapeKeyshapeMap;
- for (DataMapOfShapeColor::Iterator anIt (theKeyshapeColorMap);
- anIt.More(); anIt.Next())
+ for (DataMapOfShapeColor::Iterator aKeyShapeIter (theKeyshapeColorMap);
+ aKeyShapeIter.More(); aKeyShapeIter.Next())
{
- const TopoDS_Shape& aSh = anIt.Key();
- TopAbs_ShapeEnum aType = aSh.ShapeType();
+ const TopoDS_Shape& aKeySh = aKeyShapeIter.Key();
+ const TopAbs_ShapeEnum aType = aKeySh.ShapeType();
TopAbs_ShapeEnum aSubType = (aType == TopAbs_SOLID || aType == TopAbs_SHELL)
? TopAbs_FACE
: (aType == TopAbs_WIRE ? TopAbs_EDGE : TopAbs_SHAPE);
{
case TopAbs_SHAPE:
{
- aSubshapeKeyshapeMap.Bind (aSh, aSh);
+ if (aType == TopAbs_COMPOUND
+ && !isContainCompound (theBaseShape, TopoDS::Compound (aKeySh)))
+ {
+ for (TopoDS_Iterator aSubShapeIter (aKeySh); aSubShapeIter.More(); aSubShapeIter.Next())
+ {
+ if (!aSubshapeKeyshapeMap.IsBound (aSubShapeIter.Value()))
+ {
+ aSubshapeKeyshapeMap.Bind (aSubShapeIter.Value(), aKeySh);
+ }
+ }
+ }
+ else
+ {
+ aSubshapeKeyshapeMap.Bind (aKeySh, aKeySh);
+ }
break;
}
default:
{
- for (TopExp_Explorer anExp (aSh, aSubType); anExp.More(); anExp.Next())
+ for (TopExp_Explorer anExp (aKeySh, aSubType); anExp.More(); anExp.Next())
{
if (!aSubshapeKeyshapeMap.IsBound (anExp.Current()))
{
- aSubshapeKeyshapeMap.Bind (anExp.Current(), aSh);
+ aSubshapeKeyshapeMap.Bind (anExp.Current(), aKeySh);
}
}
}
-- shape - style correspondence
-- The location <loc> is for internal use, it
-- should be Null location for external call
-
- DispatchStyles (shape: Shape from TopoDS;
- settings: DataMapOfShapeStyle from XCAFPrs;
- items: in out DataMapOfStyleShape from XCAFPrs;
- DefStyle: Style from XCAFPrs;
- force: Boolean = Standard_True;
- context: ShapeEnum from TopAbs = TopAbs_SHAPE)
- returns Boolean;
- ---Purpose: Iterates on shape (recursively) and splits it
- -- on parts each of which has its own style
- -- (basing on settings collected by CollectStyleSettings())
- -- The DefStyle is default style applied to a shape if
- -- no specific style assignment is applied to it
- -- If force is True, the <shape> is added to a map
- -- even if no styles are redefined for it or its
- -- subshapes
- -- The context is for internal use, it indicates
- -- the type of the shape to which <shape> belongs
SetViewNameMode ( viewNameMode: Boolean from Standard);
#include <TopLoc_IndexedMapOfLocation.hxx>
#include <TDF_AttributeSequence.hxx>
#include <XCAFDoc_GraphNode.hxx>
+#include <XCAFPrs_Style.hxx>
static Standard_Boolean viewnameMode = Standard_False;
}
}
-//=======================================================================
-//function : DispatchStyles
-//purpose : fill items map (style - shape)
-//=======================================================================
-
-// merge style with father (to reflect inheritance)
-static Standard_Boolean MergeStyles (XCAFPrs_Style &style, const XCAFPrs_Style &father)
-{
- if ( ! style.IsSetColorCurv() && father.IsSetColorCurv() )
- style.SetColorCurv ( father.GetColorCurv() );
- if ( ! style.IsSetColorSurf() && father.IsSetColorSurf() )
- style.SetColorSurf ( father.GetColorSurf() );
- return style == father;
-}
-
-Standard_Boolean XCAFPrs::DispatchStyles (const TopoDS_Shape &shape,
- const XCAFPrs_DataMapOfShapeStyle &settings,
- XCAFPrs_DataMapOfStyleShape &items,
- const XCAFPrs_Style &DefStyle,
- const Standard_Boolean force,
- const TopAbs_ShapeEnum context)
-{
- const XCAFPrs_Style *style = &DefStyle;
- XCAFPrs_Style ownstyle;
-
- // check own setting of current shape
- Standard_Boolean overriden = Standard_False;
- if ( settings.IsBound ( shape ) ) {
- ownstyle = settings.Find ( shape );
- if ( ! MergeStyles ( ownstyle, DefStyle ) ) {
- overriden = Standard_True;
- style = &ownstyle;
- }
- }
-
- // iterate on subshapes
- BRep_Builder B;
- TopoDS_Shape copy = shape.EmptyCopied();
- copy.Closed (shape.Closed());
- Standard_Boolean suboverride = Standard_False;
- Standard_Integer nbDef = 0;
- for ( TopoDS_Iterator it(shape); it.More(); it.Next() ) {
- if ( DispatchStyles ( it.Value(), settings, items, *style, Standard_False, shape.ShapeType() ) ) {
- suboverride = Standard_True;
- }
- else {
- B.Add ( copy, it.Value() );
- nbDef++;
- }
- }
- if ( shape.ShapeType() == TopAbs_FACE || ! suboverride )
- copy = shape;
- else if ( ! nbDef ) return overriden || suboverride; // avoid empty compounds
-
- // if any of styles is overriden regarding to default one, add rest to map
- if ( overriden || force ||
- ( suboverride && context != TopAbs_FACE ) ) { // avoid drawing edges of the same color as face
- TopoDS_Compound C;
- if ( items.IsBound ( *style ) )
- C = TopoDS::Compound ( items.Find ( *style ) );
- else {
- B.MakeCompound ( C );
- items.Bind ( *style, C );
- }
- B.Add ( C, copy );
- }
- return overriden || suboverride;
-}
-
//=======================================================================
//function : SetViewNameMode
//purpose :
#include <XCAFPrs_AISObject.hxx>
#include <AIS_DisplayMode.hxx>
+#include <BRep_Builder.hxx>
#include <BRepBndLib.hxx>
#include <gp_Pnt.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
SetColors (myDrawer, aColorCurv, aColorSurf);
- // Set colors etc. for current shape according to style
- for (XCAFPrs_DataMapIteratorOfDataMapOfShapeStyle anIter( aSettings ); anIter.More(); anIter.Next())
+ // collect sub-shapes with the same style into compounds
+ BRep_Builder aBuilder;
+ NCollection_DataMap<XCAFPrs_Style, TopoDS_Compound, XCAFPrs_Style> aStyleGroups;
+ for (XCAFPrs_DataMapIteratorOfDataMapOfShapeStyle aStyledShapeIter (aSettings);
+ aStyledShapeIter.More(); aStyledShapeIter.Next())
{
- Handle(AIS_ColoredDrawer) aDrawer = CustomAspects (anIter.Key());
- const XCAFPrs_Style& aStyle = anIter.Value();
+ TopoDS_Compound aComp;
+ if (aStyleGroups.Find (aStyledShapeIter.Value(), aComp))
+ {
+ aBuilder.Add (aComp, aStyledShapeIter.Key());
+ continue;
+ }
+
+ aBuilder.MakeCompound (aComp);
+ aBuilder.Add (aComp, aStyledShapeIter.Key());
+ aStyleGroups.Bind (aStyledShapeIter.Value(), aComp);
+ }
+ aSettings.Clear();
+
+ // assign custom aspects
+ for (NCollection_DataMap<XCAFPrs_Style, TopoDS_Compound, XCAFPrs_Style>::Iterator aStyleGroupIter (aStyleGroups);
+ aStyleGroupIter.More(); aStyleGroupIter.Next())
+ {
+ const TopoDS_Compound& aComp = aStyleGroupIter.Value();
+ TopoDS_Iterator aShapeIter (aComp);
+ TopoDS_Shape aShape = aShapeIter.Value();
+ aShapeIter.Next();
+ if (aShapeIter.More())
+ {
+ aShape = aComp;
+ }
+
+ Handle(AIS_ColoredDrawer) aDrawer = CustomAspects (aShape);
+ const XCAFPrs_Style& aStyle = aStyleGroupIter.Key();
aDrawer->SetHidden (!aStyle.IsVisible());
aColorCurv = aStyle.IsSetColorCurv() ? aStyle.GetColorCurv() : aDefStyle.GetColorCurv();
SetColors (aDrawer, aColorCurv, aColorSurf);
}
+ aStyleGroups.Clear();
AIS_ColoredShape::Compute (thePresentationManager, thePrs, theMode);