0029056: Configuration - It is not possible to install VTK products
[occt.git] / src / AIS / AIS_ColoredShape.cxx
... / ...
CommitLineData
1// Created on: 2014-04-24
2// Created by: Kirill Gavrilov
3// Copyright (c) 2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <AIS_ColoredShape.hxx>
17
18#include <AIS_InteractiveContext.hxx>
19#include <BRep_Builder.hxx>
20#include <BRepTools.hxx>
21#include <gp_Pnt2d.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 <Graphic3d_Texture2Dmanual.hxx>
29#include <Precision.hxx>
30#include <Prs3d.hxx>
31#include <Prs3d_LineAspect.hxx>
32#include <Prs3d_IsoAspect.hxx>
33#include <Prs3d_Presentation.hxx>
34#include <Prs3d_ShadingAspect.hxx>
35#include <Prs3d_Root.hxx>
36#include <PrsMgr_PresentationManager3d.hxx>
37#include <Standard_ErrorHandler.hxx>
38#include <StdPrs_ShadedShape.hxx>
39#include <StdPrs_ToolTriangulatedShape.hxx>
40#include <StdPrs_WFShape.hxx>
41#include <TopExp_Explorer.hxx>
42#include <TopoDS.hxx>
43#include <TopoDS_Compound.hxx>
44#include <TopoDS_Iterator.hxx>
45
46IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
47IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredDrawer,Prs3d_Drawer)
48
49namespace
50{
51 //! Collect all sub-compounds into map.
52 static void collectSubCompounds (TopTools_MapOfShape& theMap,
53 const TopoDS_Shape& theShape)
54 {
55 for (TopoDS_Iterator aChildIter (theShape); aChildIter.More(); aChildIter.Next())
56 {
57 const TopoDS_Shape& aShape = aChildIter.Value();
58 if (aShape.ShapeType() == TopAbs_COMPOUND
59 && theMap.Add (aShape))
60 {
61 collectSubCompounds (theMap, aShape);
62 }
63 }
64 }
65}
66
67//=======================================================================
68//function : AIS_ColoredShape
69//purpose :
70//=======================================================================
71AIS_ColoredShape::AIS_ColoredShape (const TopoDS_Shape& theShape)
72: AIS_Shape (theShape)
73{
74 // disable dedicated line aspects
75 myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
76 myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
77 myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
78}
79
80//=======================================================================
81//function : AIS_ColoredShape
82//purpose :
83//=======================================================================
84AIS_ColoredShape::AIS_ColoredShape (const Handle(AIS_Shape)& theShape)
85: AIS_Shape (theShape->Shape())
86{
87 // disable dedicated line aspects
88 myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
89 myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
90 myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
91 if (theShape->HasMaterial())
92 {
93 SetMaterial (theShape->Material());
94 }
95 if (theShape->HasColor())
96 {
97 Quantity_Color aColor;
98 theShape->Color (aColor);
99 SetColor (aColor);
100 }
101 if (theShape->HasWidth())
102 {
103 SetWidth (theShape->Width());
104 }
105 if (theShape->IsTransparent())
106 {
107 SetTransparency (theShape->Transparency());
108 }
109}
110
111//=======================================================================
112//function : CustomAspects
113//purpose :
114//=======================================================================
115Handle(AIS_ColoredDrawer) AIS_ColoredShape::CustomAspects (const TopoDS_Shape& theShape)
116{
117 Handle(AIS_ColoredDrawer) aDrawer;
118 myShapeColors.Find (theShape, aDrawer);
119 if (aDrawer.IsNull())
120 {
121 aDrawer = new AIS_ColoredDrawer (myDrawer);
122 myShapeColors.Bind (theShape, aDrawer);
123 LoadRecomputable (AIS_WireFrame);
124 LoadRecomputable (AIS_Shaded);
125 }
126 return aDrawer;
127}
128
129//=======================================================================
130//function : ClearCustomAspects
131//purpose :
132//=======================================================================
133void AIS_ColoredShape::ClearCustomAspects()
134{
135 if (myShapeColors.IsEmpty())
136 {
137 return;
138 }
139 myShapeColors.Clear();
140 LoadRecomputable (AIS_WireFrame);
141 LoadRecomputable (AIS_Shaded);
142}
143
144//=======================================================================
145//function : UnsetCustomAspects
146//purpose :
147//=======================================================================
148void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape& theShape,
149 const Standard_Boolean theToUnregister)
150{
151 if (!myShapeColors.IsBound (theShape))
152 {
153 return;
154 }
155
156 LoadRecomputable (AIS_WireFrame);
157 LoadRecomputable (AIS_Shaded);
158 if (theToUnregister)
159 {
160 myShapeColors.UnBind (theShape);
161 return;
162 }
163
164 myShapeColors.ChangeFind (theShape) = new AIS_ColoredDrawer (myDrawer);
165}
166
167//=======================================================================
168//function : SetCustomColor
169//purpose :
170//=======================================================================
171void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape,
172 const Quantity_Color& theColor)
173{
174 if (theShape.IsNull())
175 {
176 return;
177 }
178
179 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
180 setColor (aDrawer, theColor);
181 aDrawer->SetOwnColor (theColor);
182 LoadRecomputable (AIS_WireFrame);
183 LoadRecomputable (AIS_Shaded);
184}
185
186//=======================================================================
187//function : SetCustomWidth
188//purpose :
189//=======================================================================
190void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape,
191 const Standard_Real theLineWidth)
192{
193 if (theShape.IsNull())
194 {
195 return;
196 }
197
198 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
199 setWidth (CustomAspects (theShape), theLineWidth);
200 aDrawer->SetOwnWidth (theLineWidth);
201 LoadRecomputable (AIS_WireFrame);
202 LoadRecomputable (AIS_Shaded);
203}
204
205//=======================================================================
206//function : SetColor
207//purpose :
208//=======================================================================
209
210void AIS_ColoredShape::SetColor (const Quantity_Color& theColor)
211{
212 setColor (myDrawer, theColor);
213 myDrawer->SetColor (theColor);
214 hasOwnColor = Standard_True;
215 LoadRecomputable (AIS_WireFrame);
216 LoadRecomputable (AIS_Shaded);
217 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
218 {
219 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
220 if (aDrawer->HasOwnColor())
221 {
222 continue;
223 }
224
225 if (aDrawer->HasOwnShadingAspect())
226 {
227 aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
228 }
229 if (aDrawer->HasOwnLineAspect())
230 {
231 aDrawer->LineAspect()->SetColor (theColor);
232 }
233 if (aDrawer->HasOwnWireAspect())
234 {
235 aDrawer->WireAspect()->SetColor (theColor);
236 }
237 }
238}
239
240//=======================================================================
241//function : SetWidth
242//purpose :
243//=======================================================================
244
245void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth)
246{
247 setWidth (myDrawer, theLineWidth);
248 myOwnWidth = theLineWidth;
249 LoadRecomputable (AIS_WireFrame);
250 LoadRecomputable (AIS_Shaded);
251 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
252 {
253 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
254 if (aDrawer->HasOwnWidth())
255 {
256 continue;
257 }
258
259 if (aDrawer->HasOwnLineAspect())
260 {
261 aDrawer->LineAspect()->SetWidth (theLineWidth);
262 }
263 if (aDrawer->HasOwnWireAspect())
264 {
265 aDrawer->WireAspect()->SetWidth (theLineWidth);
266 }
267 }
268}
269
270//=======================================================================
271//function : SetTransparency
272//purpose :
273//=======================================================================
274
275void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
276{
277 setTransparency (myDrawer, theValue);
278 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
279 LoadRecomputable (AIS_WireFrame);
280 LoadRecomputable (AIS_Shaded);
281 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
282 {
283 const Handle(Prs3d_Drawer)& aDrawer = anIter.Value();
284 if (aDrawer->HasOwnShadingAspect())
285 {
286 aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
287 }
288 }
289}
290
291//=======================================================================
292//function : UnsetTransparency
293//purpose :
294//=======================================================================
295void AIS_ColoredShape::UnsetTransparency()
296{
297 myDrawer->SetTransparency (0.0f);
298 if (myDrawer->HasOwnShadingAspect())
299 {
300 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
301 if (!HasColor()
302 && !HasMaterial()
303 && !myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
304 {
305 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
306 }
307 }
308
309 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
310 {
311 const Handle(Prs3d_Drawer)& aDrawer = anIter.Value();
312 if (aDrawer->HasOwnShadingAspect())
313 {
314 aDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
315 }
316 }
317 SynchronizeAspects();
318}
319
320//=======================================================================
321//function : SetMaterial
322//purpose :
323//=======================================================================
324
325void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
326{
327 setMaterial (myDrawer, theMaterial, HasColor(), IsTransparent());
328 //myOwnMaterial = theMaterial;
329 hasOwnMaterial = Standard_True;
330 LoadRecomputable (AIS_Shaded);
331 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
332 {
333 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
334 //if (aDrawer->HasOwnMaterial()) continue;
335 if (aDrawer->HasOwnShadingAspect())
336 {
337 setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), Standard_False); // aDrawer->IsTransparent()
338 }
339 }
340}
341
342//=======================================================================
343//function : Compute
344//purpose :
345//=======================================================================
346void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
347 const Handle(Prs3d_Presentation)& thePrs,
348 const Standard_Integer theMode)
349{
350 if (myshape.IsNull())
351 {
352 return;
353 }
354
355 if (IsInfinite())
356 {
357 thePrs->SetInfiniteState (Standard_True);
358 }
359
360 if (theMode == AIS_Shaded)
361 {
362 if (myDrawer->IsAutoTriangulation())
363 {
364 // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
365 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
366
367 // After this call if type of deflection is relative
368 // computed deflection coefficient is stored as absolute.
369 Standard_Boolean wasRecomputed = StdPrs_ToolTriangulatedShape::Tessellate (myshape, myDrawer);
370
371 // Set to update wireframe presentation on triangulation.
372 if (myDrawer->IsoOnTriangulation() && wasRecomputed)
373 {
374 SetToUpdate (AIS_WireFrame);
375 }
376 }
377 }
378 else // WireFrame mode
379 {
380 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
381
382 // After this call if type of deflection is relative
383 // computed deflection coefficient is stored as absolute.
384 Prs3d::GetDeflection (myshape, myDrawer);
385 }
386
387 // Extract myShapeColors map (KeyshapeColored -> Color)
388 // to subshapes map (Subshape -> Color).
389 // This needed when colored shape is not part of BaseShape
390 // (but subshapes are) and actually container for subshapes.
391 AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
392 {
393 // unroll compounds specified for grouping sub-shapes with the same style
394 // (e.g. the compounds that are not a part of the main shape)
395 TopTools_MapOfShape aMapOfOwnCompounds;
396 if (myshape.ShapeType() == TopAbs_COMPOUND)
397 {
398 aMapOfOwnCompounds.Add (myshape);
399 collectSubCompounds (aMapOfOwnCompounds, myshape);
400 }
401 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
402 aKeyShapeIter.More(); aKeyShapeIter.Next())
403 {
404 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
405 if (aKeyShape.ShapeType() != TopAbs_COMPOUND
406 || aMapOfOwnCompounds.Contains (aKeyShape))
407 {
408 continue;
409 }
410
411 for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next())
412 {
413 const TopoDS_Shape& aShape = aChildIter.Value();
414 if (!myShapeColors.IsBound (aShape))
415 {
416 bindSubShapes (aSubshapeDrawerMap, aShape, aKeyShapeIter.Value());
417 }
418 }
419 }
420
421 // assign other sub-shapes with styles
422 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
423 aKeyShapeIter.More(); aKeyShapeIter.Next())
424 {
425 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
426 if (myshape == aKeyShape
427 || (aKeyShape.ShapeType() == TopAbs_COMPOUND
428 && !aMapOfOwnCompounds.Contains (aKeyShape)))
429 {
430 continue;
431 }
432
433 bindSubShapes (aSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value());
434 }
435 }
436
437 Handle(AIS_ColoredDrawer) aBaseDrawer;
438 myShapeColors.Find (myshape, aBaseDrawer);
439
440 // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound
441 DataMapOfDrawerCompd aDispatchedOpened[(size_t)TopAbs_SHAPE];
442 DataMapOfDrawerCompd aDispatchedClosed;
443 dispatchColors (aBaseDrawer, myshape,
444 aSubshapeDrawerMap, TopAbs_COMPOUND, Standard_False,
445 aDispatchedOpened, theMode == AIS_Shaded ? aDispatchedClosed : aDispatchedOpened[TopAbs_FACE]);
446 addShapesWithCustomProps (thePrs, aDispatchedOpened, aDispatchedClosed, theMode);
447}
448
449//=======================================================================
450//function : addShapesWithCustomProps
451//purpose :
452//=======================================================================
453void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
454 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
455 const DataMapOfDrawerCompd& theDrawerClosedFaces,
456 const Standard_Integer theMode)
457{
458 Handle(Graphic3d_Group) anOpenGroup, aClosedGroup;
459 for (size_t aShType = 0; aShType <= (size_t )TopAbs_SHAPE; ++aShType)
460 {
461 const Standard_Boolean isClosed = aShType == TopAbs_SHAPE;
462 Handle(Graphic3d_Group)& aShadedGroup = isClosed ? aClosedGroup : anOpenGroup;
463 const DataMapOfDrawerCompd& aDrawerShapeMap = isClosed
464 ? theDrawerClosedFaces
465 : theDrawerOpenedShapePerType[aShType];
466 for (DataMapOfDrawerCompd::Iterator aMapIter (aDrawerShapeMap);
467 aMapIter.More(); aMapIter.Next())
468 {
469 const Handle(AIS_ColoredDrawer)& aCustomDrawer = aMapIter.Key();
470 const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type
471 Handle(Prs3d_Drawer) aDrawer;
472 if (!aCustomDrawer.IsNull())
473 {
474 aDrawer = aCustomDrawer;
475 if (aCustomDrawer->IsHidden())
476 {
477 continue;
478 }
479 }
480 else
481 {
482 aDrawer = myDrawer;
483 }
484
485 // It is supposed that absolute deflection contains previously computed relative deflection
486 // (if deflection type is relative).
487 // In case of CustomDrawer it is taken from Link().
488 Aspect_TypeOfDeflection aPrevType = aDrawer->TypeOfDeflection();
489 aDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
490
491 // Draw each kind of subshapes and personal-colored shapes in a separate group
492 // since it's necessary to set transparency/material for all subshapes
493 // without affecting their unique colors
494 if (theMode == AIS_Shaded
495 && aShapeDraw.ShapeType() <= TopAbs_FACE
496 && !IsInfinite())
497 {
498 // add wireframe presentation for isolated edges and vertices
499 StdPrs_ShadedShape::AddWireframeForFreeElements (thePrs, aShapeDraw, aDrawer);
500
501 // add special wireframe presentation for faces without triangulation
502 StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (thePrs, aShapeDraw, aDrawer);
503
504 Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw,
505 aDrawer->ShadingAspect()->Aspect()->ToMapTexture()
506 && !aDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
507 myUVOrigin, myUVRepeat, myUVScale);
508 if (!aTriangles.IsNull())
509 {
510 if (aShadedGroup.IsNull())
511 {
512 aShadedGroup = Prs3d_Root::NewGroup (thePrs);
513 aShadedGroup->SetClosed (isClosed);
514 }
515 aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect());
516 aShadedGroup->AddPrimitiveArray (aTriangles);
517 }
518
519 if (aDrawer->FaceBoundaryDraw())
520 {
521 Handle(Graphic3d_ArrayOfSegments) aBndSegments = StdPrs_ShadedShape::FillFaceBoundaries (aShapeDraw);
522 if (!aBndSegments.IsNull())
523 {
524 if (aShadedGroup.IsNull())
525 {
526 aShadedGroup = Prs3d_Root::NewGroup (thePrs);
527 aShadedGroup->SetClosed (isClosed);
528 }
529
530 Handle(Graphic3d_AspectLine3d) aBoundaryAspect = aDrawer->FaceBoundaryAspect()->Aspect();
531 aShadedGroup->SetPrimitivesAspect (aBoundaryAspect);
532 aShadedGroup->AddPrimitiveArray (aBndSegments);
533 }
534 }
535 }
536 else
537 {
538 StdPrs_WFShape::Add (thePrs, aShapeDraw, aDrawer);
539 }
540 aDrawer->SetTypeOfDeflection (aPrevType);
541 }
542 }
543}
544
545//=======================================================================
546//function : dispatchColors
547//purpose :
548//=======================================================================
549Standard_Boolean AIS_ColoredShape::dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
550 const TopoDS_Shape& theShapeToParse,
551 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
552 const TopAbs_ShapeEnum theParentType,
553 const Standard_Boolean theIsParentClosed,
554 DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
555 DataMapOfDrawerCompd& theDrawerClosedFaces)
556{
557 const TopAbs_ShapeEnum aShapeType = theShapeToParse.ShapeType();
558 if (aShapeType == TopAbs_SHAPE)
559 {
560 return Standard_False;
561 }
562
563 // check own setting of current shape
564 Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
565 const Standard_Boolean isOverriden = theShapeDrawerMap.Find (theShapeToParse, aDrawer);
566 if (isOverriden
567 && aDrawer->IsHidden())
568 {
569 return Standard_True;
570 }
571
572 // handle compounds, solids and shells
573 Standard_Boolean isSubOverride = Standard_False;
574 if (aShapeType <= TopAbs_SHELL)
575 {
576 // detect parts of closed solids
577 Standard_Boolean isClosedShell = theParentType == TopAbs_SOLID
578 && aShapeType == TopAbs_SHELL
579 && BRep_Tool::IsClosed (theShapeToParse)
580 && StdPrs_ToolTriangulatedShape::IsTriangulated (theShapeToParse);
581 if (isClosedShell)
582 {
583 for (TopoDS_Iterator aFaceIter (theShapeToParse); aFaceIter.More(); aFaceIter.Next())
584 {
585 const TopoDS_Shape& aFace = aFaceIter.Value();
586 Handle(AIS_ColoredDrawer) aFaceDrawer;
587 if (aFace.ShapeType() == TopAbs_FACE
588 && theShapeDrawerMap.Find (aFace, aFaceDrawer)
589 && aFaceDrawer->IsHidden())
590 {
591 isClosedShell = Standard_False;
592 break;
593 }
594 }
595 }
596
597 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
598 {
599 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
600 if (dispatchColors (aDrawer, aSubShape,
601 theShapeDrawerMap, aShapeType,
602 isClosedShell,
603 theDrawerOpenedShapePerType,
604 theDrawerClosedFaces))
605 {
606 isSubOverride = Standard_True;
607 }
608 }
609 return isOverriden || isSubOverride;
610 }
611
612 // iterate on sub-shapes
613 BRep_Builder aBBuilder;
614 TopoDS_Shape aShapeCopy = theShapeToParse.EmptyCopied();
615 aShapeCopy.Closed (theShapeToParse.Closed());
616 Standard_Integer nbDef = 0;
617 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
618 {
619 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
620 if (dispatchColors (aDrawer, aSubShape,
621 theShapeDrawerMap, aShapeType,
622 theIsParentClosed,
623 theDrawerOpenedShapePerType,
624 theDrawerClosedFaces))
625 {
626 isSubOverride = Standard_True;
627 }
628 else
629 {
630 aBBuilder.Add (aShapeCopy, aSubShape);
631 ++nbDef;
632 }
633 }
634 if (aShapeType == TopAbs_FACE || !isSubOverride)
635 {
636 aShapeCopy = theShapeToParse;
637 }
638 else if (nbDef == 0)
639 {
640 return isOverriden || isSubOverride; // empty compound
641 }
642
643 // if any of styles is overridden regarding to default one, add rest to map
644 if (isOverriden
645 || (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden
646 && theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face
647 || (theParentType <= TopAbs_SHELL && !(isOverriden || isSubOverride))) // bind original shape to default color
648 {
649 TopoDS_Compound aCompound;
650 DataMapOfDrawerCompd& aDrawerShapeMap = theIsParentClosed
651 && aShapeType == TopAbs_FACE
652 ? theDrawerClosedFaces
653 : theDrawerOpenedShapePerType[(size_t)aShapeType];
654 if (!aDrawerShapeMap.FindFromKey (aDrawer, aCompound))
655 {
656 aBBuilder.MakeCompound (aCompound);
657 aDrawerShapeMap.Add (aDrawer, aCompound);
658 }
659 aBBuilder.Add (aCompound, aShapeCopy);
660 }
661 return isOverriden || isSubOverride;
662}
663
664//=======================================================================
665//function : isShapeEntirelyVisible
666//purpose :
667//=======================================================================
668Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const
669{
670 for (AIS_DataMapOfShapeDrawer::Iterator aMapIter (myShapeColors); aMapIter.More(); aMapIter.Next())
671 {
672 if (aMapIter.Value()->IsHidden())
673 {
674 return Standard_False;
675 }
676 }
677 return Standard_True;
678}
679
680//=======================================================================
681//function : bindSubShapes
682//purpose :
683//=======================================================================
684void AIS_ColoredShape::bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
685 const TopoDS_Shape& theKeyShape,
686 const Handle(AIS_ColoredDrawer)& theDrawer)
687{
688 TopAbs_ShapeEnum aShapeWithColorType = theKeyShape.ShapeType();
689 if (aShapeWithColorType == TopAbs_COMPOUND)
690 {
691 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
692 }
693 else if (aShapeWithColorType == TopAbs_SOLID || aShapeWithColorType == TopAbs_SHELL)
694 {
695 for (TopExp_Explorer anExp (theKeyShape, TopAbs_FACE); anExp.More(); anExp.Next())
696 {
697 if (!theShapeDrawerMap.IsBound (anExp.Current()))
698 {
699 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
700 }
701 }
702 }
703 else if (aShapeWithColorType == TopAbs_WIRE)
704 {
705 for (TopExp_Explorer anExp (theKeyShape, TopAbs_EDGE); anExp.More(); anExp.Next())
706 {
707 if (!theShapeDrawerMap.IsBound (anExp.Current()))
708 {
709 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
710 }
711 }
712 }
713 else
714 {
715 // bind single face, edge and vertex
716 // force rebind if required due to the color of single shape has
717 // higher priority than the color of "compound" shape (wire is a
718 // compound of edges, shell is a compound of faces) that contains
719 // this single shape.
720 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
721 }
722}