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 <gp_Pnt2d.hxx>
23 #include <Graphic3d_AspectFillArea3d.hxx>
24 #include <Graphic3d_AspectLine3d.hxx>
25 #include <Graphic3d_ArrayOfTriangles.hxx>
26 #include <Graphic3d_ArrayOfSegments.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <Graphic3d_StructureManager.hxx>
29 #include <Graphic3d_Texture2Dmanual.hxx>
30 #include <Precision.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Prs3d_IsoAspect.hxx>
34 #include <Prs3d_Presentation.hxx>
35 #include <Prs3d_ShadingAspect.hxx>
36 #include <Prs3d_Root.hxx>
37 #include <PrsMgr_PresentationManager3d.hxx>
38 #include <Standard_ErrorHandler.hxx>
39 #include <StdSelect_BRepSelectionTool.hxx>
40 #include <StdPrs_ShadedShape.hxx>
41 #include <StdPrs_ToolTriangulatedShape.hxx>
42 #include <StdPrs_WFShape.hxx>
43 #include <TopExp_Explorer.hxx>
45 #include <TopoDS_Compound.hxx>
46 #include <TopoDS_Iterator.hxx>
48 IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
49 IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredDrawer,Prs3d_Drawer)
53 //! Collect all sub-compounds into map.
54 static void collectSubCompounds (TopTools_MapOfShape& theMap,
55 const TopoDS_Shape& theShape)
57 for (TopoDS_Iterator aChildIter (theShape); aChildIter.More(); aChildIter.Next())
59 const TopoDS_Shape& aShape = aChildIter.Value();
60 if (aShape.ShapeType() == TopAbs_COMPOUND
61 && theMap.Add (aShape))
63 collectSubCompounds (theMap, aShape);
69 //=======================================================================
70 //function : AIS_ColoredShape
72 //=======================================================================
73 AIS_ColoredShape::AIS_ColoredShape (const TopoDS_Shape& theShape)
74 : AIS_Shape (theShape)
76 // disable dedicated line aspects
77 myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
78 myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
79 myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
80 myDrawer->SetFaceBoundaryAspect (myDrawer->LineAspect());
83 //=======================================================================
84 //function : AIS_ColoredShape
86 //=======================================================================
87 AIS_ColoredShape::AIS_ColoredShape (const Handle(AIS_Shape)& theShape)
88 : AIS_Shape (theShape->Shape())
90 // disable dedicated line aspects
91 myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
92 myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
93 myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
94 myDrawer->SetFaceBoundaryAspect (myDrawer->LineAspect());
95 if (theShape->HasMaterial())
97 SetMaterial (theShape->Material());
99 if (theShape->HasColor())
101 Quantity_Color aColor;
102 theShape->Color (aColor);
105 if (theShape->HasWidth())
107 SetWidth (theShape->Width());
109 if (theShape->IsTransparent())
111 SetTransparency (theShape->Transparency());
115 //=======================================================================
116 //function : CustomAspects
118 //=======================================================================
119 Handle(AIS_ColoredDrawer) AIS_ColoredShape::CustomAspects (const TopoDS_Shape& theShape)
121 Handle(AIS_ColoredDrawer) aDrawer;
122 myShapeColors.Find (theShape, aDrawer);
123 if (aDrawer.IsNull())
125 aDrawer = new AIS_ColoredDrawer (myDrawer);
126 myShapeColors.Bind (theShape, aDrawer);
127 LoadRecomputable (AIS_WireFrame);
128 LoadRecomputable (AIS_Shaded);
133 //=======================================================================
134 //function : ClearCustomAspects
136 //=======================================================================
137 void AIS_ColoredShape::ClearCustomAspects()
139 if (myShapeColors.IsEmpty())
143 myShapeColors.Clear();
144 LoadRecomputable (AIS_WireFrame);
145 LoadRecomputable (AIS_Shaded);
148 //=======================================================================
149 //function : UnsetCustomAspects
151 //=======================================================================
152 void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape& theShape,
153 const Standard_Boolean theToUnregister)
155 if (!myShapeColors.IsBound (theShape))
160 LoadRecomputable (AIS_WireFrame);
161 LoadRecomputable (AIS_Shaded);
164 myShapeColors.UnBind (theShape);
168 myShapeColors.ChangeFind (theShape) = new AIS_ColoredDrawer (myDrawer);
171 //=======================================================================
172 //function : SetCustomColor
174 //=======================================================================
175 void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape,
176 const Quantity_Color& theColor)
178 if (theShape.IsNull())
183 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
184 setColor (aDrawer, theColor);
185 aDrawer->SetOwnColor (theColor);
186 LoadRecomputable (AIS_WireFrame);
187 LoadRecomputable (AIS_Shaded);
190 //=======================================================================
191 //function : SetCustomTransparency
193 //=======================================================================
194 void AIS_ColoredShape::SetCustomTransparency (const TopoDS_Shape& theShape,
195 Standard_Real theTransparency)
197 if (theShape.IsNull())
202 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
203 setTransparency (aDrawer, theTransparency);
204 aDrawer->SetOwnTransparency (theTransparency);
205 LoadRecomputable (AIS_WireFrame);
206 LoadRecomputable (AIS_Shaded);
209 //=======================================================================
210 //function : SetCustomWidth
212 //=======================================================================
213 void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape,
214 const Standard_Real theLineWidth)
216 if (theShape.IsNull())
221 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
222 setWidth (aDrawer, theLineWidth);
223 aDrawer->SetOwnWidth (theLineWidth);
224 LoadRecomputable (AIS_WireFrame);
225 LoadRecomputable (AIS_Shaded);
228 //=======================================================================
229 //function : SetColor
231 //=======================================================================
233 void AIS_ColoredShape::SetColor (const Quantity_Color& theColor)
235 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
237 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
238 if (aDrawer->HasOwnColor())
243 if (aDrawer->HasOwnShadingAspect())
245 aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
247 if (aDrawer->HasOwnLineAspect())
249 aDrawer->LineAspect()->SetColor (theColor);
251 if (aDrawer->HasOwnWireAspect())
253 aDrawer->WireAspect()->SetColor (theColor);
255 if (aDrawer->HasOwnFaceBoundaryAspect())
257 aDrawer->FaceBoundaryAspect()->SetColor (theColor);
260 AIS_Shape::SetColor (theColor);
263 //=======================================================================
264 //function : SetWidth
266 //=======================================================================
268 void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth)
270 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
272 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
273 if (aDrawer->HasOwnWidth())
278 if (aDrawer->HasOwnLineAspect())
280 aDrawer->LineAspect()->SetWidth (theLineWidth);
282 if (aDrawer->HasOwnWireAspect())
284 aDrawer->WireAspect()->SetWidth (theLineWidth);
286 if (aDrawer->HasOwnFaceBoundaryAspect())
288 aDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
291 AIS_Shape::SetWidth (theLineWidth);
294 //=======================================================================
295 //function : UnsetWidth
297 //=======================================================================
298 void AIS_ColoredShape::UnsetWidth()
303 //=======================================================================
304 //function : SetTransparency
306 //=======================================================================
308 void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
310 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
312 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
313 if (aDrawer->HasOwnTransparency())
318 if (aDrawer->HasOwnShadingAspect())
320 aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
323 AIS_Shape::SetTransparency (theValue);
326 //=======================================================================
327 //function : UnsetTransparency
329 //=======================================================================
330 void AIS_ColoredShape::UnsetTransparency()
332 SetTransparency (0.0f);
335 //=======================================================================
336 //function : SetMaterial
338 //=======================================================================
340 void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
342 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
344 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
345 //if (aDrawer->HasOwnMaterial()) continue;
346 if (aDrawer->HasOwnShadingAspect())
348 setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), aDrawer->HasOwnTransparency());
351 AIS_Shape::SetMaterial (theMaterial);
354 //=======================================================================
357 //=======================================================================
358 void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
359 const Handle(Prs3d_Presentation)& thePrs,
360 const Standard_Integer theMode)
362 if (myshape.IsNull())
369 thePrs->SetInfiniteState (Standard_True);
376 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
378 // After this call if type of deflection is relative
379 // computed deflection coefficient is stored as absolute.
380 Prs3d::GetDeflection (myshape, myDrawer);
385 if (myDrawer->IsAutoTriangulation())
387 // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
388 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
390 // After this call if type of deflection is relative
391 // computed deflection coefficient is stored as absolute.
392 Standard_Boolean wasRecomputed = StdPrs_ToolTriangulatedShape::Tessellate (myshape, myDrawer);
394 // Set to update wireframe presentation on triangulation.
395 if (myDrawer->IsoOnTriangulation() && wasRecomputed)
397 SetToUpdate (AIS_WireFrame);
404 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
413 // Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
414 // This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes.
415 AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
416 fillSubshapeDrawerMap (aSubshapeDrawerMap);
418 Handle(AIS_ColoredDrawer) aBaseDrawer;
419 myShapeColors.Find (myshape, aBaseDrawer);
421 // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound
422 DataMapOfDrawerCompd aDispatchedOpened[(size_t)TopAbs_SHAPE];
423 DataMapOfDrawerCompd aDispatchedClosed;
424 dispatchColors (aBaseDrawer, myshape,
425 aSubshapeDrawerMap, TopAbs_COMPOUND, Standard_False,
426 aDispatchedOpened, theMode == AIS_Shaded ? aDispatchedClosed : aDispatchedOpened[TopAbs_FACE]);
427 addShapesWithCustomProps (thePrs, aDispatchedOpened, aDispatchedClosed, theMode);
430 //=======================================================================
431 //function : fillSubshapeDrawerMap
433 //=======================================================================
434 void AIS_ColoredShape::fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const
436 // unroll compounds specified for grouping sub-shapes with the same style
437 // (e.g. the compounds that are not a part of the main shape)
438 TopTools_MapOfShape aMapOfOwnCompounds;
439 if (myshape.ShapeType() == TopAbs_COMPOUND)
441 aMapOfOwnCompounds.Add (myshape);
442 collectSubCompounds (aMapOfOwnCompounds, myshape);
444 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
445 aKeyShapeIter.More(); aKeyShapeIter.Next())
447 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
448 if (aKeyShape.ShapeType() != TopAbs_COMPOUND
449 || aMapOfOwnCompounds.Contains (aKeyShape))
454 for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next())
456 const TopoDS_Shape& aShape = aChildIter.Value();
457 if (!myShapeColors.IsBound (aShape))
459 bindSubShapes (theSubshapeDrawerMap, aShape, aKeyShapeIter.Value());
464 // assign other sub-shapes with styles
465 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
466 aKeyShapeIter.More(); aKeyShapeIter.Next())
468 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
469 if (myshape == aKeyShape
470 || (aKeyShape.ShapeType() == TopAbs_COMPOUND
471 && !aMapOfOwnCompounds.Contains (aKeyShape)))
476 bindSubShapes (theSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value());
480 //=======================================================================
481 //function : ComputeSelection
483 //=======================================================================
484 void AIS_ColoredShape::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
485 const Standard_Integer theMode)
487 if (myshape.IsNull())
491 else if (isShapeEntirelyVisible())
493 base_type::ComputeSelection (theSelection, theMode);
497 const TopAbs_ShapeEnum aTypOfSel = AIS_Shape::SelectionType (theMode);
498 const Standard_Real aDeflection = Prs3d::GetDeflection (myshape, myDrawer);
499 const Standard_Real aDeviationAngle = myDrawer->HLRAngle();
500 const Standard_Integer aPriority = StdSelect_BRepSelectionTool::GetStandardPriority (myshape, aTypOfSel);
501 if (myDrawer->IsAutoTriangulation()
502 && !BRepTools::Triangulation (myshape, Precision::Infinite()))
504 BRepMesh_IncrementalMesh aMesher (myshape, aDeflection, Standard_False, aDeviationAngle);
507 AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
508 fillSubshapeDrawerMap (aSubshapeDrawerMap);
510 Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority);
511 if (aTypOfSel == TopAbs_SHAPE)
513 aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority);
516 Handle(AIS_ColoredDrawer) aBaseDrawer;
517 myShapeColors.Find (myshape, aBaseDrawer);
518 computeSubshapeSelection (aBaseDrawer, aSubshapeDrawerMap, myshape, aBrepOwner, theSelection,
519 aTypOfSel, aPriority, aDeflection, aDeviationAngle);
521 Handle(SelectMgr_SelectableObject) aThis (this);
522 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (theSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
524 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aSelEntIter.Value()->BaseSensitive()->OwnerId());
525 anOwner->Set (aThis);
528 StdSelect_BRepSelectionTool::PreBuildBVH (theSelection);
531 //=======================================================================
532 //function : computeSubshapeSelection
534 //=======================================================================
535 void AIS_ColoredShape::computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer,
536 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
537 const TopoDS_Shape& theShape,
538 const Handle(StdSelect_BRepOwner)& theOwner,
539 const Handle(SelectMgr_Selection)& theSelection,
540 const TopAbs_ShapeEnum theTypOfSel,
541 const Standard_Integer thePriority,
542 const Standard_Real theDeflection,
543 const Standard_Real theDeflAngle)
545 Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
546 theShapeDrawerMap.Find (theShape, aDrawer);
547 if (!aDrawer.IsNull()
548 && aDrawer->IsHidden())
553 const Standard_Integer aNbPOnEdge = 9;
554 const Standard_Real aMaximalParameter = 500.0;
555 if (theTypOfSel == TopAbs_SHAPE
556 && theShape.ShapeType() >= TopAbs_FACE)
558 StdSelect_BRepSelectionTool::ComputeSensitive (theShape, theOwner, theSelection,
559 theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation());
562 else if (theShape.ShapeType() == theTypOfSel)
564 const Standard_Boolean isComesFromDecomposition = !theShape.IsEqual (myshape);
565 Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (theShape, thePriority, isComesFromDecomposition);
566 StdSelect_BRepSelectionTool::ComputeSensitive (theShape, aBrepOwner, theSelection,
567 theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation());
571 for (TopoDS_Iterator aSubShapeIter (theShape); aSubShapeIter.More(); aSubShapeIter.Next())
573 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
574 computeSubshapeSelection (aDrawer, theShapeDrawerMap, aSubShape,
575 theOwner, theSelection, theTypOfSel, thePriority,
576 theDeflection, theDeflAngle);
580 //=======================================================================
581 //function : addShapesWithCustomProps
583 //=======================================================================
584 void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
585 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
586 const DataMapOfDrawerCompd& theDrawerClosedFaces,
587 const Standard_Integer theMode)
589 Handle(Graphic3d_Group) anOpenGroup, aClosedGroup, anEdgesGroup;
590 for (size_t aShType = 0; aShType <= (size_t )TopAbs_SHAPE; ++aShType)
592 const Standard_Boolean isClosed = aShType == TopAbs_SHAPE;
593 Handle(Graphic3d_Group)& aShadedGroup = isClosed ? aClosedGroup : anOpenGroup;
594 const DataMapOfDrawerCompd& aDrawerShapeMap = isClosed
595 ? theDrawerClosedFaces
596 : theDrawerOpenedShapePerType[aShType];
597 for (DataMapOfDrawerCompd::Iterator aMapIter (aDrawerShapeMap);
598 aMapIter.More(); aMapIter.Next())
600 const Handle(AIS_ColoredDrawer)& aCustomDrawer = aMapIter.Key();
601 const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type
602 Handle(Prs3d_Drawer) aDrawer;
603 if (!aCustomDrawer.IsNull())
605 aDrawer = aCustomDrawer;
606 if (aCustomDrawer->IsHidden())
616 // It is supposed that absolute deflection contains previously computed relative deflection
617 // (if deflection type is relative).
618 // In case of CustomDrawer it is taken from Link().
619 Aspect_TypeOfDeflection aPrevType = aDrawer->TypeOfDeflection();
620 aDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
622 // Draw each kind of subshapes and personal-colored shapes in a separate group
623 // since it's necessary to set transparency/material for all subshapes
624 // without affecting their unique colors
625 if (theMode == AIS_Shaded
626 && aShapeDraw.ShapeType() <= TopAbs_FACE
629 // add wireframe presentation for isolated edges and vertices
630 StdPrs_ShadedShape::AddWireframeForFreeElements (thePrs, aShapeDraw, aDrawer);
632 // add special wireframe presentation for faces without triangulation
633 StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (thePrs, aShapeDraw, aDrawer);
635 Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw,
636 aDrawer->ShadingAspect()->Aspect()->ToMapTexture()
637 && !aDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
638 myUVOrigin, myUVRepeat, myUVScale);
639 if (!aTriangles.IsNull())
641 if (aShadedGroup.IsNull())
643 aShadedGroup = thePrs->NewGroup();
644 aShadedGroup->SetClosed (isClosed);
646 aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect());
647 aShadedGroup->AddPrimitiveArray (aTriangles);
650 if (aDrawer->FaceBoundaryDraw())
652 if (Handle(Graphic3d_ArrayOfSegments) aBndSegments = StdPrs_ShadedShape::FillFaceBoundaries (aShapeDraw, aDrawer->FaceBoundaryUpperContinuity()))
654 if (anEdgesGroup.IsNull())
656 anEdgesGroup = thePrs->NewGroup();
659 anEdgesGroup->SetPrimitivesAspect (aDrawer->FaceBoundaryAspect()->Aspect());
660 anEdgesGroup->AddPrimitiveArray (aBndSegments);
666 StdPrs_WFShape::Add (thePrs, aShapeDraw, aDrawer);
668 aDrawer->SetTypeOfDeflection (aPrevType);
673 //=======================================================================
674 //function : dispatchColors
676 //=======================================================================
677 Standard_Boolean AIS_ColoredShape::dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
678 const TopoDS_Shape& theShapeToParse,
679 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
680 const TopAbs_ShapeEnum theParentType,
681 const Standard_Boolean theIsParentClosed,
682 DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
683 DataMapOfDrawerCompd& theDrawerClosedFaces)
685 const TopAbs_ShapeEnum aShapeType = theShapeToParse.ShapeType();
686 if (aShapeType == TopAbs_SHAPE)
688 return Standard_False;
691 // check own setting of current shape
692 Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
693 const Standard_Boolean isOverriden = theShapeDrawerMap.Find (theShapeToParse, aDrawer);
695 && aDrawer->IsHidden())
697 return Standard_True;
700 // handle compounds, solids and shells
701 Standard_Boolean isSubOverride = Standard_False;
702 if (aShapeType <= TopAbs_SHELL)
704 // detect parts of closed solids
705 Standard_Boolean isClosedShell = theParentType == TopAbs_SOLID
706 && aShapeType == TopAbs_SHELL
707 && BRep_Tool::IsClosed (theShapeToParse)
708 && StdPrs_ToolTriangulatedShape::IsTriangulated (theShapeToParse);
711 for (TopoDS_Iterator aFaceIter (theShapeToParse); aFaceIter.More(); aFaceIter.Next())
713 const TopoDS_Shape& aFace = aFaceIter.Value();
714 Handle(AIS_ColoredDrawer) aFaceDrawer;
715 if (aFace.ShapeType() != TopAbs_FACE
716 || !theShapeDrawerMap.Find (aFace, aFaceDrawer))
721 if (aFaceDrawer->IsHidden())
723 isClosedShell = Standard_False;
726 else if (aFaceDrawer->HasOwnShadingAspect()
727 && aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_Opaque)
729 if (aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_BlendAuto
730 || aFaceDrawer->ShadingAspect()->Aspect()->FrontMaterial().Alpha() < 1.0f
731 || (aFaceDrawer->ShadingAspect()->Aspect()->Distinguish()
732 && aFaceDrawer->ShadingAspect()->Aspect()->BackMaterial().Alpha() < 1.0f))
734 isClosedShell = Standard_False;
741 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
743 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
744 if (dispatchColors (aDrawer, aSubShape,
745 theShapeDrawerMap, aShapeType,
747 theDrawerOpenedShapePerType,
748 theDrawerClosedFaces))
750 isSubOverride = Standard_True;
753 return isOverriden || isSubOverride;
756 // iterate on sub-shapes
757 BRep_Builder aBBuilder;
758 TopoDS_Shape aShapeCopy = theShapeToParse.EmptyCopied();
759 aShapeCopy.Closed (theShapeToParse.Closed());
760 Standard_Integer nbDef = 0;
761 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
763 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
764 if (dispatchColors (aDrawer, aSubShape,
765 theShapeDrawerMap, aShapeType,
767 theDrawerOpenedShapePerType,
768 theDrawerClosedFaces))
770 isSubOverride = Standard_True;
774 aBBuilder.Add (aShapeCopy, aSubShape);
778 if (aShapeType == TopAbs_FACE || !isSubOverride)
780 aShapeCopy = theShapeToParse;
784 return isOverriden || isSubOverride; // empty compound
787 // if any of styles is overridden regarding to default one, add rest to map
789 || (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden
790 && theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face
791 || (theParentType <= TopAbs_SHELL && !(isOverriden || isSubOverride))) // bind original shape to default color
793 TopoDS_Compound aCompound;
794 DataMapOfDrawerCompd& aDrawerShapeMap = theIsParentClosed
795 && aShapeType == TopAbs_FACE
796 ? theDrawerClosedFaces
797 : theDrawerOpenedShapePerType[(size_t)aShapeType];
798 if (!aDrawerShapeMap.FindFromKey (aDrawer, aCompound))
800 aBBuilder.MakeCompound (aCompound);
801 aDrawerShapeMap.Add (aDrawer, aCompound);
803 aBBuilder.Add (aCompound, aShapeCopy);
805 return isOverriden || isSubOverride;
808 //=======================================================================
809 //function : isShapeEntirelyVisible
811 //=======================================================================
812 Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const
814 for (AIS_DataMapOfShapeDrawer::Iterator aMapIter (myShapeColors); aMapIter.More(); aMapIter.Next())
816 if (aMapIter.Value()->IsHidden())
818 return Standard_False;
821 return Standard_True;
824 //=======================================================================
825 //function : bindSubShapes
827 //=======================================================================
828 void AIS_ColoredShape::bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
829 const TopoDS_Shape& theKeyShape,
830 const Handle(AIS_ColoredDrawer)& theDrawer) const
832 TopAbs_ShapeEnum aShapeWithColorType = theKeyShape.ShapeType();
833 if (aShapeWithColorType == TopAbs_COMPOUND)
835 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
837 else if (aShapeWithColorType == TopAbs_SOLID || aShapeWithColorType == TopAbs_SHELL)
839 for (TopExp_Explorer anExp (theKeyShape, TopAbs_FACE); anExp.More(); anExp.Next())
841 if (!theShapeDrawerMap.IsBound (anExp.Current()))
843 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
847 else if (aShapeWithColorType == TopAbs_WIRE)
849 for (TopExp_Explorer anExp (theKeyShape, TopAbs_EDGE); anExp.More(); anExp.Next())
851 if (!theShapeDrawerMap.IsBound (anExp.Current()))
853 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
859 // bind single face, edge and vertex
860 // force rebind if required due to the color of single shape has
861 // higher priority than the color of "compound" shape (wire is a
862 // compound of edges, shell is a compound of faces) that contains
863 // this single shape.
864 theShapeDrawerMap.Bind (theKeyShape, theDrawer);