From: kgv Date: Sat, 22 Nov 2014 12:19:49 +0000 (+0300) Subject: 0025484: Visualization - group sub-shapes with the same style in XCAFPrs_AISObject... X-Git-Tag: V6_9_0_beta~262 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=3ea0a91b703ef959c0c772d83e5e8c5f90c5137e 0025484: Visualization - group sub-shapes with the same style in XCAFPrs_AISObject::Compute() --- diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx index d6ea64117c..fe327eca34 100644 --- a/src/AIS/AIS_ColoredShape.cxx +++ b/src/AIS/AIS_ColoredShape.cxx @@ -447,6 +447,30 @@ Standard_Boolean AIS_ColoredShape::dispatchColors (const TopoDS_Shape& th 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 : @@ -460,11 +484,11 @@ void AIS_ColoredShape::dispatchColors (const TopoDS_Shape& theBaseShape, // This needed when colored shape is not part of // (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); @@ -472,16 +496,30 @@ void AIS_ColoredShape::dispatchColors (const TopoDS_Shape& theBaseShape, { 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); } } } diff --git a/src/XCAFPrs/XCAFPrs.cdl b/src/XCAFPrs/XCAFPrs.cdl index f5c2c8802e..ab6ac66ab8 100644 --- a/src/XCAFPrs/XCAFPrs.cdl +++ b/src/XCAFPrs/XCAFPrs.cdl @@ -66,24 +66,6 @@ is -- shape - style correspondence -- The location 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 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 belongs SetViewNameMode ( viewNameMode: Boolean from Standard); diff --git a/src/XCAFPrs/XCAFPrs.cxx b/src/XCAFPrs/XCAFPrs.cxx index 00fb4682eb..d3e0a7eb33 100644 --- a/src/XCAFPrs/XCAFPrs.cxx +++ b/src/XCAFPrs/XCAFPrs.cxx @@ -28,6 +28,7 @@ #include #include #include +#include static Standard_Boolean viewnameMode = Standard_False; @@ -212,75 +213,6 @@ void XCAFPrs::CollectStyleSettings (const TDF_Label &L, } } -//======================================================================= -//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 : diff --git a/src/XCAFPrs/XCAFPrs_AISObject.cxx b/src/XCAFPrs/XCAFPrs_AISObject.cxx index 3330162bf6..0f94f57bec 100644 --- a/src/XCAFPrs/XCAFPrs_AISObject.cxx +++ b/src/XCAFPrs/XCAFPrs_AISObject.cxx @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -151,11 +152,40 @@ void XCAFPrs_AISObject::Compute (const Handle(PrsMgr_PresentationManager3d)& the 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 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::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(); @@ -163,6 +193,7 @@ void XCAFPrs_AISObject::Compute (const Handle(PrsMgr_PresentationManager3d)& the SetColors (aDrawer, aColorCurv, aColorSurf); } + aStyleGroups.Clear(); AIS_ColoredShape::Compute (thePresentationManager, thePrs, theMode);