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);
132 //=======================================================================
133 //function : ClearCustomAspects
135 //=======================================================================
136 void AIS_ColoredShape::ClearCustomAspects()
138 if (myShapeColors.IsEmpty())
142 myShapeColors.Clear();
146 //=======================================================================
147 //function : UnsetCustomAspects
149 //=======================================================================
150 void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape& theShape,
151 const Standard_Boolean theToUnregister)
153 if (!myShapeColors.IsBound (theShape))
161 myShapeColors.UnBind (theShape);
165 myShapeColors.ChangeFind (theShape) = new AIS_ColoredDrawer (myDrawer);
168 //=======================================================================
169 //function : SetCustomColor
171 //=======================================================================
172 void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape,
173 const Quantity_Color& theColor)
175 if (theShape.IsNull())
180 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
181 setColor (aDrawer, theColor);
182 aDrawer->SetOwnColor (theColor);
185 //=======================================================================
186 //function : SetCustomTransparency
188 //=======================================================================
189 void AIS_ColoredShape::SetCustomTransparency (const TopoDS_Shape& theShape,
190 Standard_Real theTransparency)
192 if (theShape.IsNull())
197 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
198 setTransparency (aDrawer, theTransparency);
199 aDrawer->SetOwnTransparency (theTransparency);
202 //=======================================================================
203 //function : SetCustomWidth
205 //=======================================================================
206 void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape,
207 const Standard_Real theLineWidth)
209 if (theShape.IsNull())
214 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
215 setWidth (aDrawer, theLineWidth);
216 aDrawer->SetOwnWidth (theLineWidth);
219 //=======================================================================
220 //function : SetColor
222 //=======================================================================
224 void AIS_ColoredShape::SetColor (const Quantity_Color& theColor)
226 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
228 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
229 if (aDrawer->HasOwnColor())
234 if (aDrawer->HasOwnShadingAspect())
236 aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
238 if (aDrawer->HasOwnLineAspect())
240 aDrawer->LineAspect()->SetColor (theColor);
242 if (aDrawer->HasOwnWireAspect())
244 aDrawer->WireAspect()->SetColor (theColor);
246 if (aDrawer->HasOwnFaceBoundaryAspect())
248 aDrawer->FaceBoundaryAspect()->SetColor (theColor);
251 AIS_Shape::SetColor (theColor);
254 //=======================================================================
255 //function : SetWidth
257 //=======================================================================
259 void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth)
261 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
263 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
264 if (aDrawer->HasOwnWidth())
269 if (aDrawer->HasOwnLineAspect())
271 aDrawer->LineAspect()->SetWidth (theLineWidth);
273 if (aDrawer->HasOwnWireAspect())
275 aDrawer->WireAspect()->SetWidth (theLineWidth);
277 if (aDrawer->HasOwnFaceBoundaryAspect())
279 aDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
282 AIS_Shape::SetWidth (theLineWidth);
285 //=======================================================================
286 //function : UnsetWidth
288 //=======================================================================
289 void AIS_ColoredShape::UnsetWidth()
294 //=======================================================================
295 //function : SetTransparency
297 //=======================================================================
299 void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
301 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
303 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
304 if (aDrawer->HasOwnTransparency())
309 if (aDrawer->HasOwnShadingAspect())
311 aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
314 AIS_Shape::SetTransparency (theValue);
317 //=======================================================================
318 //function : UnsetTransparency
320 //=======================================================================
321 void AIS_ColoredShape::UnsetTransparency()
323 SetTransparency (0.0f);
326 //=======================================================================
327 //function : SetMaterial
329 //=======================================================================
331 void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
333 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
335 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
336 //if (aDrawer->HasOwnMaterial()) continue;
337 if (aDrawer->HasOwnShadingAspect())
339 setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), aDrawer->HasOwnTransparency());
342 AIS_Shape::SetMaterial (theMaterial);
345 //=======================================================================
348 //=======================================================================
349 void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
350 const Handle(Prs3d_Presentation)& thePrs,
351 const Standard_Integer theMode)
353 if (myshape.IsNull())
360 thePrs->SetInfiniteState (Standard_True);
367 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
369 // After this call if type of deflection is relative
370 // computed deflection coefficient is stored as absolute.
371 Prs3d::GetDeflection (myshape, myDrawer);
376 if (myDrawer->IsAutoTriangulation())
378 // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
379 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
381 // After this call if type of deflection is relative
382 // computed deflection coefficient is stored as absolute.
383 Standard_Boolean wasRecomputed = StdPrs_ToolTriangulatedShape::Tessellate (myshape, myDrawer);
385 // Set to update wireframe presentation on triangulation.
386 if (myDrawer->IsoOnTriangulation() && wasRecomputed)
388 SetToUpdate (AIS_WireFrame);
395 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
404 // Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
405 // This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes.
406 AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
407 fillSubshapeDrawerMap (aSubshapeDrawerMap);
409 Handle(AIS_ColoredDrawer) aBaseDrawer;
410 myShapeColors.Find (myshape, aBaseDrawer);
412 // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound
413 DataMapOfDrawerCompd aDispatchedOpened[(size_t)TopAbs_SHAPE];
414 DataMapOfDrawerCompd aDispatchedClosed;
415 dispatchColors (aBaseDrawer, myshape,
416 aSubshapeDrawerMap, TopAbs_COMPOUND, Standard_False,
417 aDispatchedOpened, theMode == AIS_Shaded ? aDispatchedClosed : aDispatchedOpened[TopAbs_FACE]);
418 addShapesWithCustomProps (thePrs, aDispatchedOpened, aDispatchedClosed, theMode);
421 //=======================================================================
422 //function : fillSubshapeDrawerMap
424 //=======================================================================
425 void AIS_ColoredShape::fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const
427 // unroll compounds specified for grouping sub-shapes with the same style
428 // (e.g. the compounds that are not a part of the main shape)
429 TopTools_MapOfShape aMapOfOwnCompounds;
430 if (myshape.ShapeType() == TopAbs_COMPOUND)
432 aMapOfOwnCompounds.Add (myshape);
433 collectSubCompounds (aMapOfOwnCompounds, myshape);
435 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
436 aKeyShapeIter.More(); aKeyShapeIter.Next())
438 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
439 if (aKeyShape.ShapeType() != TopAbs_COMPOUND
440 || aMapOfOwnCompounds.Contains (aKeyShape))
445 for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next())
447 const TopoDS_Shape& aShape = aChildIter.Value();
448 if (!myShapeColors.IsBound (aShape))
450 bindSubShapes (theSubshapeDrawerMap, aShape, aKeyShapeIter.Value());
455 // assign other sub-shapes with styles
456 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
457 aKeyShapeIter.More(); aKeyShapeIter.Next())
459 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
460 if (myshape == aKeyShape
461 || (aKeyShape.ShapeType() == TopAbs_COMPOUND
462 && !aMapOfOwnCompounds.Contains (aKeyShape)))
467 bindSubShapes (theSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value());
471 //=======================================================================
472 //function : ComputeSelection
474 //=======================================================================
475 void AIS_ColoredShape::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
476 const Standard_Integer theMode)
478 if (myshape.IsNull())
482 else if (isShapeEntirelyVisible())
484 base_type::ComputeSelection (theSelection, theMode);
488 const TopAbs_ShapeEnum aTypOfSel = AIS_Shape::SelectionType (theMode);
489 const Standard_Real aDeflection = Prs3d::GetDeflection (myshape, myDrawer);
490 const Standard_Real aDeviationAngle = myDrawer->HLRAngle();
491 const Standard_Integer aPriority = StdSelect_BRepSelectionTool::GetStandardPriority (myshape, aTypOfSel);
492 if (myDrawer->IsAutoTriangulation()
493 && !BRepTools::Triangulation (myshape, Precision::Infinite()))
495 BRepMesh_IncrementalMesh aMesher (myshape, aDeflection, Standard_False, aDeviationAngle);
498 AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
499 fillSubshapeDrawerMap (aSubshapeDrawerMap);
501 Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority);
502 if (aTypOfSel == TopAbs_SHAPE)
504 aBrepOwner = new StdSelect_BRepOwner (myshape, aPriority);
507 Handle(AIS_ColoredDrawer) aBaseDrawer;
508 myShapeColors.Find (myshape, aBaseDrawer);
509 computeSubshapeSelection (aBaseDrawer, aSubshapeDrawerMap, myshape, aBrepOwner, theSelection,
510 aTypOfSel, aPriority, aDeflection, aDeviationAngle);
512 Handle(SelectMgr_SelectableObject) aThis (this);
513 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (theSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
515 const Handle(SelectMgr_EntityOwner)& anOwner = aSelEntIter.Value()->BaseSensitive()->OwnerId();
516 anOwner->SetSelectable (aThis);
519 StdSelect_BRepSelectionTool::PreBuildBVH (theSelection);
522 //=======================================================================
523 //function : computeSubshapeSelection
525 //=======================================================================
526 void AIS_ColoredShape::computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer,
527 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
528 const TopoDS_Shape& theShape,
529 const Handle(StdSelect_BRepOwner)& theOwner,
530 const Handle(SelectMgr_Selection)& theSelection,
531 const TopAbs_ShapeEnum theTypOfSel,
532 const Standard_Integer thePriority,
533 const Standard_Real theDeflection,
534 const Standard_Real theDeflAngle)
536 Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
537 theShapeDrawerMap.Find (theShape, aDrawer);
538 if (!aDrawer.IsNull()
539 && aDrawer->IsHidden())
544 const Standard_Integer aNbPOnEdge = 9;
545 const Standard_Real aMaximalParameter = 500.0;
546 if (theTypOfSel == TopAbs_SHAPE
547 && theShape.ShapeType() >= TopAbs_FACE)
549 StdSelect_BRepSelectionTool::ComputeSensitive (theShape, theOwner, theSelection,
550 theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation());
553 else if (theShape.ShapeType() == theTypOfSel)
555 const Standard_Boolean isComesFromDecomposition = !theShape.IsEqual (myshape);
556 Handle(StdSelect_BRepOwner) aBrepOwner = new StdSelect_BRepOwner (theShape, thePriority, isComesFromDecomposition);
557 StdSelect_BRepSelectionTool::ComputeSensitive (theShape, aBrepOwner, theSelection,
558 theDeflection, theDeflAngle, aNbPOnEdge, aMaximalParameter, myDrawer->IsAutoTriangulation());
562 for (TopoDS_Iterator aSubShapeIter (theShape); aSubShapeIter.More(); aSubShapeIter.Next())
564 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
565 computeSubshapeSelection (aDrawer, theShapeDrawerMap, aSubShape,
566 theOwner, theSelection, theTypOfSel, thePriority,
567 theDeflection, theDeflAngle);
571 //=======================================================================
572 //function : addShapesWithCustomProps
574 //=======================================================================
575 void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
576 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
577 const DataMapOfDrawerCompd& theDrawerClosedFaces,
578 const Standard_Integer theMode)
580 Handle(Graphic3d_Group) anOpenGroup, aClosedGroup, anEdgesGroup;
581 for (size_t aShType = 0; aShType <= (size_t )TopAbs_SHAPE; ++aShType)
583 const Standard_Boolean isClosed = aShType == TopAbs_SHAPE;
584 Handle(Graphic3d_Group)& aShadedGroup = isClosed ? aClosedGroup : anOpenGroup;
585 const DataMapOfDrawerCompd& aDrawerShapeMap = isClosed
586 ? theDrawerClosedFaces
587 : theDrawerOpenedShapePerType[aShType];
588 for (DataMapOfDrawerCompd::Iterator aMapIter (aDrawerShapeMap);
589 aMapIter.More(); aMapIter.Next())
591 const Handle(AIS_ColoredDrawer)& aCustomDrawer = aMapIter.Key();
592 const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type
593 Handle(Prs3d_Drawer) aDrawer;
594 if (!aCustomDrawer.IsNull())
596 aDrawer = aCustomDrawer;
597 if (aCustomDrawer->IsHidden())
607 // It is supposed that absolute deflection contains previously computed relative deflection
608 // (if deflection type is relative).
609 // In case of CustomDrawer it is taken from Link().
610 Aspect_TypeOfDeflection aPrevType = aDrawer->TypeOfDeflection();
611 aDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
613 // Draw each kind of subshapes and personal-colored shapes in a separate group
614 // since it's necessary to set transparency/material for all subshapes
615 // without affecting their unique colors
616 if (theMode == AIS_Shaded
617 && aShapeDraw.ShapeType() <= TopAbs_FACE
620 // add wireframe presentation for isolated edges and vertices
621 StdPrs_ShadedShape::AddWireframeForFreeElements (thePrs, aShapeDraw, aDrawer);
623 // add special wireframe presentation for faces without triangulation
624 StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (thePrs, aShapeDraw, aDrawer);
626 Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw,
627 aDrawer->ShadingAspect()->Aspect()->ToMapTexture()
628 && !aDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
629 myUVOrigin, myUVRepeat, myUVScale);
630 if (!aTriangles.IsNull())
632 if (aShadedGroup.IsNull())
634 aShadedGroup = thePrs->NewGroup();
635 aShadedGroup->SetClosed (isClosed);
637 aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect());
638 aShadedGroup->AddPrimitiveArray (aTriangles);
641 if (aDrawer->FaceBoundaryDraw())
643 if (Handle(Graphic3d_ArrayOfSegments) aBndSegments = StdPrs_ShadedShape::FillFaceBoundaries (aShapeDraw, aDrawer->FaceBoundaryUpperContinuity()))
645 if (anEdgesGroup.IsNull())
647 anEdgesGroup = thePrs->NewGroup();
650 anEdgesGroup->SetPrimitivesAspect (aDrawer->FaceBoundaryAspect()->Aspect());
651 anEdgesGroup->AddPrimitiveArray (aBndSegments);
657 StdPrs_WFShape::Add (thePrs, aShapeDraw, aDrawer);
659 aDrawer->SetTypeOfDeflection (aPrevType);
664 //=======================================================================
665 //function : dispatchColors
667 //=======================================================================
668 Standard_Boolean AIS_ColoredShape::dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
669 const TopoDS_Shape& theShapeToParse,
670 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
671 const TopAbs_ShapeEnum theParentType,
672 const Standard_Boolean theIsParentClosed,
673 DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
674 DataMapOfDrawerCompd& theDrawerClosedFaces)
676 const TopAbs_ShapeEnum aShapeType = theShapeToParse.ShapeType();
677 if (aShapeType == TopAbs_SHAPE)
679 return Standard_False;
682 // check own setting of current shape
683 Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
684 const Standard_Boolean isOverriden = theShapeDrawerMap.Find (theShapeToParse, aDrawer);
686 && aDrawer->IsHidden())
688 return Standard_True;
691 // handle compounds, solids and shells
692 Standard_Boolean isSubOverride = Standard_False;
693 if (aShapeType <= TopAbs_SHELL)
695 // detect parts of closed solids
696 Standard_Boolean isClosedShell = theParentType == TopAbs_SOLID
697 && aShapeType == TopAbs_SHELL
698 && BRep_Tool::IsClosed (theShapeToParse)
699 && StdPrs_ToolTriangulatedShape::IsTriangulated (theShapeToParse);
702 for (TopoDS_Iterator aFaceIter (theShapeToParse); aFaceIter.More(); aFaceIter.Next())
704 const TopoDS_Shape& aFace = aFaceIter.Value();
705 Handle(AIS_ColoredDrawer) aFaceDrawer;
706 if (aFace.ShapeType() != TopAbs_FACE
707 || !theShapeDrawerMap.Find (aFace, aFaceDrawer))
712 if (aFaceDrawer->IsHidden())
714 isClosedShell = Standard_False;
717 else if (aFaceDrawer->HasOwnShadingAspect()
718 && aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_Opaque)
720 if (aFaceDrawer->ShadingAspect()->Aspect()->AlphaMode() != Graphic3d_AlphaMode_BlendAuto
721 || aFaceDrawer->ShadingAspect()->Aspect()->FrontMaterial().Alpha() < 1.0f
722 || (aFaceDrawer->ShadingAspect()->Aspect()->Distinguish()
723 && aFaceDrawer->ShadingAspect()->Aspect()->BackMaterial().Alpha() < 1.0f))
725 isClosedShell = Standard_False;
732 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
734 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
735 if (dispatchColors (aDrawer, aSubShape,
736 theShapeDrawerMap, aShapeType,
738 theDrawerOpenedShapePerType,
739 theDrawerClosedFaces))
741 isSubOverride = Standard_True;
744 return isOverriden || isSubOverride;
747 // iterate on sub-shapes
748 BRep_Builder aBBuilder;
749 TopoDS_Shape aShapeCopy = theShapeToParse.EmptyCopied();
750 aShapeCopy.Closed (theShapeToParse.Closed());
751 Standard_Integer nbDef = 0;
752 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
754 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
755 if (dispatchColors (aDrawer, aSubShape,
756 theShapeDrawerMap, aShapeType,
758 theDrawerOpenedShapePerType,
759 theDrawerClosedFaces))
761 isSubOverride = Standard_True;
765 aBBuilder.Add (aShapeCopy, aSubShape);
769 if (aShapeType == TopAbs_FACE || !isSubOverride)
771 aShapeCopy = theShapeToParse;
775 return isOverriden || isSubOverride; // empty compound
778 // if any of styles is overridden regarding to default one, add rest to map
780 || (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden
781 && theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face
782 || (theParentType <= TopAbs_SHELL && !(isOverriden || isSubOverride))) // bind original shape to default color
784 TopoDS_Compound aCompound;
785 DataMapOfDrawerCompd& aDrawerShapeMap = theIsParentClosed
786 && aShapeType == TopAbs_FACE
787 ? theDrawerClosedFaces
788 : theDrawerOpenedShapePerType[(size_t)aShapeType];
789 if (!aDrawerShapeMap.FindFromKey (aDrawer, aCompound))
791 aBBuilder.MakeCompound (aCompound);
792 aDrawerShapeMap.Add (aDrawer, aCompound);
794 aBBuilder.Add (aCompound, aShapeCopy);
796 return isOverriden || isSubOverride;
799 //=======================================================================
800 //function : isShapeEntirelyVisible
802 //=======================================================================
803 Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const
805 for (AIS_DataMapOfShapeDrawer::Iterator aMapIter (myShapeColors); aMapIter.More(); aMapIter.Next())
807 if (aMapIter.Value()->IsHidden())
809 return Standard_False;
812 return Standard_True;
815 //=======================================================================
816 //function : bindSubShapes
818 //=======================================================================
819 void AIS_ColoredShape::bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
820 const TopoDS_Shape& theKeyShape,
821 const Handle(AIS_ColoredDrawer)& theDrawer) const
823 TopAbs_ShapeEnum aShapeWithColorType = theKeyShape.ShapeType();
824 if (aShapeWithColorType == TopAbs_COMPOUND)
826 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
828 else if (aShapeWithColorType == TopAbs_SOLID || aShapeWithColorType == TopAbs_SHELL)
830 for (TopExp_Explorer anExp (theKeyShape, TopAbs_FACE); anExp.More(); anExp.Next())
832 if (!theShapeDrawerMap.IsBound (anExp.Current()))
834 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
838 else if (aShapeWithColorType == TopAbs_WIRE)
840 for (TopExp_Explorer anExp (theKeyShape, TopAbs_EDGE); anExp.More(); anExp.Next())
842 if (!theShapeDrawerMap.IsBound (anExp.Current()))
844 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
850 // bind single face, edge and vertex
851 // force rebind if required due to the color of single shape has
852 // higher priority than the color of "compound" shape (wire is a
853 // compound of edges, shell is a compound of faces) that contains
854 // this single shape.
855 theShapeDrawerMap.Bind (theKeyShape, theDrawer);