1 // Created on: 2014-04-24
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <AIS_ColoredShape.hxx>
18 #include <AIS_InteractiveContext.hxx>
19 #include <BRep_Builder.hxx>
20 #include <BRepTools.hxx>
21 #include <BRepMesh_IncrementalMesh.hxx>
22 #include <Graphic3d_AspectFillArea3d.hxx>
23 #include <Graphic3d_AspectLine3d.hxx>
24 #include <Graphic3d_ArrayOfTriangles.hxx>
25 #include <Graphic3d_ArrayOfSegments.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_StructureManager.hxx>
28 #include <Precision.hxx>
29 #include <Prs3d_Presentation.hxx>
30 #include <Prs3d_ShadingAspect.hxx>
31 #include <PrsMgr_PresentationManager.hxx>
32 #include <StdSelect_BRepSelectionTool.hxx>
33 #include <StdPrs_ShadedShape.hxx>
34 #include <StdPrs_ToolTriangulatedShape.hxx>
35 #include <StdPrs_WFShape.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopoDS_Compound.hxx>
38 #include <TopoDS_Iterator.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
41 IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredDrawer,Prs3d_Drawer)
45 //! Collect all sub-compounds into map.
46 static void collectSubCompounds (TopTools_MapOfShape& theMap,
47 const TopoDS_Shape& theShape)
49 for (TopoDS_Iterator aChildIter (theShape); aChildIter.More(); aChildIter.Next())
51 const TopoDS_Shape& aShape = aChildIter.Value();
52 if (aShape.ShapeType() == TopAbs_COMPOUND
53 && theMap.Add (aShape))
55 collectSubCompounds (theMap, aShape);
61 //=======================================================================
62 //function : AIS_ColoredShape
64 //=======================================================================
65 AIS_ColoredShape::AIS_ColoredShape (const TopoDS_Shape& theShape)
66 : AIS_Shape (theShape)
68 // disable dedicated line aspects
69 myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
70 myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
71 myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
72 myDrawer->SetFaceBoundaryAspect (myDrawer->LineAspect());
75 //=======================================================================
76 //function : AIS_ColoredShape
78 //=======================================================================
79 AIS_ColoredShape::AIS_ColoredShape (const Handle(AIS_Shape)& theShape)
80 : AIS_Shape (theShape->Shape())
82 // disable dedicated line aspects
83 myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
84 myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
85 myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
86 myDrawer->SetFaceBoundaryAspect (myDrawer->LineAspect());
87 if (theShape->HasMaterial())
89 SetMaterial (theShape->Material());
91 if (theShape->HasColor())
93 Quantity_Color aColor;
94 theShape->Color (aColor);
97 if (theShape->HasWidth())
99 SetWidth (theShape->Width());
101 if (theShape->IsTransparent())
103 SetTransparency (theShape->Transparency());
107 //=======================================================================
108 //function : CustomAspects
110 //=======================================================================
111 Handle(AIS_ColoredDrawer) AIS_ColoredShape::CustomAspects (const TopoDS_Shape& theShape)
113 Handle(AIS_ColoredDrawer) aDrawer;
114 myShapeColors.Find (theShape, aDrawer);
115 if (aDrawer.IsNull())
117 aDrawer = new AIS_ColoredDrawer (myDrawer);
118 myShapeColors.Bind (theShape, aDrawer);
124 //=======================================================================
125 //function : ClearCustomAspects
127 //=======================================================================
128 void AIS_ColoredShape::ClearCustomAspects()
130 if (myShapeColors.IsEmpty())
134 myShapeColors.Clear();
138 //=======================================================================
139 //function : UnsetCustomAspects
141 //=======================================================================
142 void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape& theShape,
143 const Standard_Boolean theToUnregister)
145 if (!myShapeColors.IsBound (theShape))
153 myShapeColors.UnBind (theShape);
157 myShapeColors.ChangeFind (theShape) = new AIS_ColoredDrawer (myDrawer);
160 //=======================================================================
161 //function : SetCustomColor
163 //=======================================================================
164 void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape,
165 const Quantity_Color& theColor)
167 if (theShape.IsNull())
172 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
173 setColor (aDrawer, theColor);
174 aDrawer->SetOwnColor (theColor);
177 //=======================================================================
178 //function : SetCustomTransparency
180 //=======================================================================
181 void AIS_ColoredShape::SetCustomTransparency (const TopoDS_Shape& theShape,
182 Standard_Real theTransparency)
184 if (theShape.IsNull())
189 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
190 setTransparency (aDrawer, theTransparency);
191 aDrawer->SetOwnTransparency (theTransparency);
194 //=======================================================================
195 //function : SetCustomWidth
197 //=======================================================================
198 void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape,
199 const Standard_Real theLineWidth)
201 if (theShape.IsNull())
206 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
207 setWidth (aDrawer, theLineWidth);
208 aDrawer->SetOwnWidth (theLineWidth);
211 //=======================================================================
212 //function : SetColor
214 //=======================================================================
216 void AIS_ColoredShape::SetColor (const Quantity_Color& theColor)
218 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
220 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
221 if (aDrawer->HasOwnColor())
226 if (aDrawer->HasOwnShadingAspect())
228 aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
230 if (aDrawer->HasOwnLineAspect())
232 aDrawer->LineAspect()->SetColor (theColor);
234 if (aDrawer->HasOwnWireAspect())
236 aDrawer->WireAspect()->SetColor (theColor);
238 if (aDrawer->HasOwnFaceBoundaryAspect())
240 aDrawer->FaceBoundaryAspect()->SetColor (theColor);
243 AIS_Shape::SetColor (theColor);
246 //=======================================================================
247 //function : SetWidth
249 //=======================================================================
251 void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth)
253 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
255 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
256 if (aDrawer->HasOwnWidth())
261 if (aDrawer->HasOwnLineAspect())
263 aDrawer->LineAspect()->SetWidth (theLineWidth);
265 if (aDrawer->HasOwnWireAspect())
267 aDrawer->WireAspect()->SetWidth (theLineWidth);
269 if (aDrawer->HasOwnFaceBoundaryAspect())
271 aDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
274 AIS_Shape::SetWidth (theLineWidth);
277 //=======================================================================
278 //function : UnsetWidth
280 //=======================================================================
281 void AIS_ColoredShape::UnsetWidth()
286 //=======================================================================
287 //function : SetTransparency
289 //=======================================================================
291 void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
293 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
295 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
296 if (aDrawer->HasOwnTransparency())
301 if (aDrawer->HasOwnShadingAspect())
303 aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
306 AIS_Shape::SetTransparency (theValue);
309 //=======================================================================
310 //function : UnsetTransparency
312 //=======================================================================
313 void AIS_ColoredShape::UnsetTransparency()
315 SetTransparency (0.0f);
318 //=======================================================================
319 //function : SetMaterial
321 //=======================================================================
323 void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
325 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
327 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
328 if (aDrawer->HasOwnMaterial())
333 if (aDrawer->HasOwnShadingAspect())
335 setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), aDrawer->HasOwnTransparency());
338 AIS_Shape::SetMaterial (theMaterial);
341 //=======================================================================
344 //=======================================================================
345 void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
346 const Handle(Prs3d_Presentation)& thePrs,
347 const Standard_Integer theMode)
349 if (myshape.IsNull())
356 thePrs->SetInfiniteState (Standard_True);
363 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
365 // After this call if type of deflection is relative
366 // computed deflection coefficient is stored as absolute.
367 StdPrs_ToolTriangulatedShape::GetDeflection (myshape, myDrawer);
372 if (myDrawer->IsAutoTriangulation())
374 // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
375 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
377 // After this call if type of deflection is relative
378 // computed deflection coefficient is stored as absolute.
379 Standard_Boolean wasRecomputed = StdPrs_ToolTriangulatedShape::Tessellate (myshape, myDrawer);
381 // Set to update wireframe presentation on triangulation.
382 if (myDrawer->IsoOnTriangulation() && wasRecomputed)
384 SetToUpdate (AIS_WireFrame);
391 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
400 // Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
401 // This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes.
402 AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
403 fillSubshapeDrawerMap (aSubshapeDrawerMap);
405 Handle(AIS_ColoredDrawer) aBaseDrawer;
406 myShapeColors.Find (myshape, aBaseDrawer);
408 // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound
409 DataMapOfDrawerCompd aDispatchedOpened[(size_t)TopAbs_SHAPE];
410 DataMapOfDrawerCompd aDispatchedClosed;
411 dispatchColors (aBaseDrawer, myshape,
412 aSubshapeDrawerMap, TopAbs_COMPOUND, Standard_False,
413 aDispatchedOpened, theMode == AIS_Shaded ? aDispatchedClosed : aDispatchedOpened[TopAbs_FACE]);
414 addShapesWithCustomProps (thePrs, aDispatchedOpened, aDispatchedClosed, theMode);
417 //=======================================================================
418 //function : fillSubshapeDrawerMap
420 //=======================================================================
421 void AIS_ColoredShape::fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const
423 // unroll compounds specified for grouping sub-shapes with the same style
424 // (e.g. the compounds that are not a part of the main shape)
425 TopTools_MapOfShape aMapOfOwnCompounds;
426 if (myshape.ShapeType() == TopAbs_COMPOUND)
428 aMapOfOwnCompounds.Add (myshape);
429 collectSubCompounds (aMapOfOwnCompounds, myshape);
431 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
432 aKeyShapeIter.More(); aKeyShapeIter.Next())
434 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
435 if (aKeyShape.ShapeType() != TopAbs_COMPOUND
436 || aMapOfOwnCompounds.Contains (aKeyShape))
441 for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next())
443 const TopoDS_Shape& aShape = aChildIter.Value();
444 if (!myShapeColors.IsBound (aShape))
446 bindSubShapes (theSubshapeDrawerMap, aShape, aKeyShapeIter.Value());
451 // assign other sub-shapes with styles
452 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
453 aKeyShapeIter.More(); aKeyShapeIter.Next())
455 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
456 if (myshape == aKeyShape
457 || (aKeyShape.ShapeType() == TopAbs_COMPOUND
458 && !aMapOfOwnCompounds.Contains (aKeyShape)))
463 bindSubShapes (theSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value());
467 //=======================================================================
468 //function : ComputeSelection
470 //=======================================================================
471 void AIS_ColoredShape::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
472 const Standard_Integer theMode)
474 if (myshape.IsNull())
478 else if (isShapeEntirelyVisible())
480 base_type::ComputeSelection (theSelection, theMode);
484 const TopAbs_ShapeEnum aTypOfSel = AIS_Shape::SelectionType (theMode);
485 const Standard_Real aDeflection = StdPrs_ToolTriangulatedShape::GetDeflection (myshape, myDrawer);
486 const Standard_Real aDeviationAngle = myDrawer->DeviationAngle();
487 const Standard_Integer aPriority = StdSelect_BRepSelectionTool::GetStandardPriority (myshape, aTypOfSel);
488 if (myDrawer->IsAutoTriangulation()
489 && !BRepTools::Triangulation (myshape, Precision::Infinite()))
491 BRepMesh_IncrementalMesh aMesher (myshape, aDeflection, Standard_False, aDeviationAngle);
494 AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
495 fillSubshapeDrawerMap (aSubshapeDrawerMap);
497 Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority);
498 if (aTypOfSel == TopAbs_SHAPE)
500 aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority);
503 Handle(AIS_ColoredDrawer) aBaseDrawer;
504 myShapeColors.Find (myshape, aBaseDrawer);
505 computeSubshapeSelection (aBaseDrawer, aSubshapeDrawerMap, myshape, aBrepOwner, theSelection,
506 aTypOfSel, aPriority, aDeflection, aDeviationAngle);
508 Handle(SelectMgr_SelectableObject) aThis (this);
509 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (theSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
511 const Handle(SelectMgr_EntityOwner)& anOwner = aSelEntIter.Value()->BaseSensitive()->OwnerId();
512 anOwner->SetSelectable (aThis);
516 //=======================================================================
517 //function : computeSubshapeSelection
519 //=======================================================================
520 void AIS_ColoredShape::computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer,
521 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
522 const TopoDS_Shape& theShape,
523 const Handle(StdSelect_BRepOwner)& theOwner,
524 const Handle(SelectMgr_Selection)& theSelection,
525 const TopAbs_ShapeEnum theTypOfSel,
526 const Standard_Integer thePriority,
527 const Standard_Real theDeflection,
528 const Standard_Real theDeflAngle)
530 Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
531 theShapeDrawerMap.Find (theShape, aDrawer);
532 if (!aDrawer.IsNull()
533 && aDrawer->IsHidden())
538 const Standard_Integer aNbPOnEdge = 9;
539 const Standard_Real aMaximalParameter = 500.0;
540 if (theTypOfSel == TopAbs_SHAPE
541 && theShape.ShapeType() >= TopAbs_FACE)
543 StdSelect_BRepSelectionTool::ComputeSensitive (theShape, theOwner, theSelection,
544 theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation());
547 else if (theShape.ShapeType() == theTypOfSel)
549 const Standard_Boolean isComesFromDecomposition = !theShape.IsEqual (myshape);
550 Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (theShape, thePriority, isComesFromDecomposition);
551 StdSelect_BRepSelectionTool::ComputeSensitive (theShape, aBrepOwner, theSelection,
552 theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation());
556 for (TopoDS_Iterator aSubShapeIter (theShape); aSubShapeIter.More(); aSubShapeIter.Next())
558 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
559 computeSubshapeSelection (aDrawer, theShapeDrawerMap, aSubShape,
560 theOwner, theSelection, theTypOfSel, thePriority,
561 theDeflection, theDeflAngle);
565 //=======================================================================
566 //function : addShapesWithCustomProps
568 //=======================================================================
569 void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
570 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
571 const DataMapOfDrawerCompd& theDrawerClosedFaces,
572 const Standard_Integer theMode)
574 Handle(Graphic3d_Group) anOpenGroup, aClosedGroup, anEdgesGroup;
575 for (size_t aShType = 0; aShType <= (size_t )TopAbs_SHAPE; ++aShType)
577 const Standard_Boolean isClosed = aShType == TopAbs_SHAPE;
578 Handle(Graphic3d_Group)& aShadedGroup = isClosed ? aClosedGroup : anOpenGroup;
579 const DataMapOfDrawerCompd& aDrawerShapeMap = isClosed
580 ? theDrawerClosedFaces
581 : theDrawerOpenedShapePerType[aShType];
582 for (DataMapOfDrawerCompd::Iterator aMapIter (aDrawerShapeMap);
583 aMapIter.More(); aMapIter.Next())
585 const Handle(AIS_ColoredDrawer)& aCustomDrawer = aMapIter.Key();
586 const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type
587 Handle(Prs3d_Drawer) aDrawer;
588 if (!aCustomDrawer.IsNull())
590 aDrawer = aCustomDrawer;
591 if (aCustomDrawer->IsHidden())
601 // It is supposed that absolute deflection contains previously computed relative deflection
602 // (if deflection type is relative).
603 // In case of CustomDrawer it is taken from Link().
604 Aspect_TypeOfDeflection aPrevType = aDrawer->TypeOfDeflection();
605 aDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
607 // Draw each kind of subshapes and personal-colored shapes in a separate group
608 // since it's necessary to set transparency/material for all subshapes
609 // without affecting their unique colors
610 if (theMode == AIS_Shaded
611 && aShapeDraw.ShapeType() <= TopAbs_FACE
614 // add wireframe presentation for isolated edges and vertices
615 StdPrs_ShadedShape::AddWireframeForFreeElements (thePrs, aShapeDraw, aDrawer);
617 // add special wireframe presentation for faces without triangulation
618 StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (thePrs, aShapeDraw, aDrawer);
620 Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw,
621 aDrawer->ShadingAspect()->Aspect()->ToMapTexture()
622 && !aDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
623 myUVOrigin, myUVRepeat, myUVScale);
624 if (!aTriangles.IsNull())
626 if (aShadedGroup.IsNull())
628 aShadedGroup = thePrs->NewGroup();
629 aShadedGroup->SetClosed (isClosed);
631 aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect());
632 aShadedGroup->AddPrimitiveArray (aTriangles);
635 if (aDrawer->FaceBoundaryDraw())
637 if (Handle(Graphic3d_ArrayOfSegments) aBndSegments = StdPrs_ShadedShape::FillFaceBoundaries (aShapeDraw, aDrawer->FaceBoundaryUpperContinuity()))
639 if (anEdgesGroup.IsNull())
641 anEdgesGroup = thePrs->NewGroup();
644 anEdgesGroup->SetPrimitivesAspect (aDrawer->FaceBoundaryAspect()->Aspect());
645 anEdgesGroup->AddPrimitiveArray (aBndSegments);
651 StdPrs_WFShape::Add (thePrs, aShapeDraw, aDrawer);
653 aDrawer->SetTypeOfDeflection (aPrevType);
658 //=======================================================================
659 //function : dispatchColors
661 //=======================================================================
662 Standard_Boolean AIS_ColoredShape::dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
663 const TopoDS_Shape& theShapeToParse,
664 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
665 const TopAbs_ShapeEnum theParentType,
666 const Standard_Boolean theIsParentClosed,
667 DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
668 DataMapOfDrawerCompd& theDrawerClosedFaces)
670 const TopAbs_ShapeEnum aShapeType = theShapeToParse.ShapeType();
671 if (aShapeType == TopAbs_SHAPE)
673 return Standard_False;
676 // check own setting of current shape
677 Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
678 const Standard_Boolean isOverriden = theShapeDrawerMap.Find (theShapeToParse, aDrawer);
680 && aDrawer->IsHidden())
682 return Standard_True;
685 // handle compounds, solids and shells
686 Standard_Boolean isSubOverride = Standard_False;
687 if (aShapeType <= TopAbs_SHELL)
689 // detect parts of closed solids
690 Standard_Boolean isClosedShell = theParentType == TopAbs_SOLID
691 && aShapeType == TopAbs_SHELL
692 && BRep_Tool::IsClosed (theShapeToParse)
693 && StdPrs_ToolTriangulatedShape::IsTriangulated (theShapeToParse);
696 for (TopoDS_Iterator aFaceIter (theShapeToParse); aFaceIter.More(); aFaceIter.Next())
698 const TopoDS_Shape& aFace = aFaceIter.Value();
699 Handle(AIS_ColoredDrawer) aFaceDrawer;
700 if (aFace.ShapeType() != TopAbs_FACE
701 || !theShapeDrawerMap.Find (aFace, aFaceDrawer))
706 if (aFaceDrawer->IsHidden())
708 isClosedShell = Standard_False;
711 else if (aFaceDrawer->HasOwnShadingAspect()
712 && aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_Opaque)
714 if (aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_BlendAuto
715 || aFaceDrawer->ShadingAspect()->Aspect()->FrontMaterial().Alpha() < 1.0f
716 || (aFaceDrawer->ShadingAspect()->Aspect()->Distinguish()
717 && aFaceDrawer->ShadingAspect()->Aspect()->BackMaterial().Alpha() < 1.0f))
719 isClosedShell = Standard_False;
726 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
728 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
729 if (dispatchColors (aDrawer, aSubShape,
730 theShapeDrawerMap, aShapeType,
732 theDrawerOpenedShapePerType,
733 theDrawerClosedFaces))
735 isSubOverride = Standard_True;
738 return isOverriden || isSubOverride;
741 // iterate on sub-shapes
742 BRep_Builder aBBuilder;
743 TopoDS_Shape aShapeCopy = theShapeToParse.EmptyCopied();
744 aShapeCopy.Closed (theShapeToParse.Closed());
745 Standard_Integer nbDef = 0;
746 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
748 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
749 if (dispatchColors (aDrawer, aSubShape,
750 theShapeDrawerMap, aShapeType,
752 theDrawerOpenedShapePerType,
753 theDrawerClosedFaces))
755 isSubOverride = Standard_True;
759 aBBuilder.Add (aShapeCopy, aSubShape);
763 if (aShapeType == TopAbs_FACE || !isSubOverride)
765 aShapeCopy = theShapeToParse;
769 return isOverriden || isSubOverride; // empty compound
772 // if any of styles is overridden regarding to default one, add rest to map
774 || (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden
775 && theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face
776 || (theParentType <= TopAbs_SHELL && !(isOverriden || isSubOverride))) // bind original shape to default color
778 TopoDS_Compound aCompound;
779 DataMapOfDrawerCompd& aDrawerShapeMap = theIsParentClosed
780 && aShapeType == TopAbs_FACE
781 ? theDrawerClosedFaces
782 : theDrawerOpenedShapePerType[(size_t)aShapeType];
783 if (!aDrawerShapeMap.FindFromKey (aDrawer, aCompound))
785 aBBuilder.MakeCompound (aCompound);
786 aDrawerShapeMap.Add (aDrawer, aCompound);
788 aBBuilder.Add (aCompound, aShapeCopy);
790 return isOverriden || isSubOverride;
793 //=======================================================================
794 //function : isShapeEntirelyVisible
796 //=======================================================================
797 Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const
799 for (AIS_DataMapOfShapeDrawer::Iterator aMapIter (myShapeColors); aMapIter.More(); aMapIter.Next())
801 if (aMapIter.Value()->IsHidden())
803 return Standard_False;
806 return Standard_True;
809 //=======================================================================
810 //function : bindSubShapes
812 //=======================================================================
813 void AIS_ColoredShape::bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
814 const TopoDS_Shape& theKeyShape,
815 const Handle(AIS_ColoredDrawer)& theDrawer) const
817 TopAbs_ShapeEnum aShapeWithColorType = theKeyShape.ShapeType();
818 if (aShapeWithColorType == TopAbs_COMPOUND)
820 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
822 else if (aShapeWithColorType == TopAbs_SOLID || aShapeWithColorType == TopAbs_SHELL)
824 for (TopExp_Explorer anExp (theKeyShape, TopAbs_FACE); anExp.More(); anExp.Next())
826 if (!theShapeDrawerMap.IsBound (anExp.Current()))
828 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
832 else if (aShapeWithColorType == TopAbs_WIRE)
834 for (TopExp_Explorer anExp (theKeyShape, TopAbs_EDGE); anExp.More(); anExp.Next())
836 if (!theShapeDrawerMap.IsBound (anExp.Current()))
838 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
844 // bind single face, edge and vertex
845 // force rebind if required due to the color of single shape has
846 // higher priority than the color of "compound" shape (wire is a
847 // compound of edges, shell is a compound of faces) that contains
848 // this single shape.
849 theShapeDrawerMap.Bind (theKeyShape, theDrawer);