0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / AIS / AIS_ColoredShape.cxx
CommitLineData
ad3217cd 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>
9c86076b 24#include <Graphic3d_ArrayOfTriangles.hxx>
25#include <Graphic3d_ArrayOfSegments.hxx>
ad3217cd 26#include <Graphic3d_Group.hxx>
27#include <Graphic3d_StructureManager.hxx>
28#include <Graphic3d_Texture2Dmanual.hxx>
29#include <Precision.hxx>
6262338c 30#include <Prs3d.hxx>
ad3217cd 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>
5ad8c033 39#include <StdPrs_ToolTriangulatedShape.hxx>
40#include <StdPrs_WFShape.hxx>
ad3217cd 41#include <TopExp_Explorer.hxx>
42#include <TopoDS.hxx>
43#include <TopoDS_Compound.hxx>
44#include <TopoDS_Iterator.hxx>
45
92efcf78 46IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
47IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredDrawer,Prs3d_Drawer)
48
9c86076b 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 {
478ad1d1 61 collectSubCompounds (theMap, aShape);
9c86076b 62 }
63 }
64 }
65}
66
ad3217cd 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 {
87432b82 97 Quantity_Color aColor;
98 theShape->Color (aColor);
99 SetColor (aColor);
ad3217cd 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);
f838dac4 213 myDrawer->SetColor (theColor);
ad3217cd 214 hasOwnColor = Standard_True;
215 LoadRecomputable (AIS_WireFrame);
216 LoadRecomputable (AIS_Shaded);
fb66bb28 217 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
ad3217cd 218 {
219 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
220 if (aDrawer->HasOwnColor())
221 {
222 continue;
223 }
224
6262338c 225 if (aDrawer->HasOwnShadingAspect())
ad3217cd 226 {
227 aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
228 }
6262338c 229 if (aDrawer->HasOwnLineAspect())
ad3217cd 230 {
231 aDrawer->LineAspect()->SetColor (theColor);
232 }
6262338c 233 if (aDrawer->HasOwnWireAspect())
ad3217cd 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);
fb66bb28 251 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
ad3217cd 252 {
253 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
254 if (aDrawer->HasOwnWidth())
255 {
256 continue;
257 }
258
6262338c 259 if (aDrawer->HasOwnLineAspect())
ad3217cd 260 {
261 aDrawer->LineAspect()->SetWidth (theLineWidth);
262 }
6262338c 263 if (aDrawer->HasOwnWireAspect())
ad3217cd 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);
f838dac4 278 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
ad3217cd 279 LoadRecomputable (AIS_WireFrame);
280 LoadRecomputable (AIS_Shaded);
fb66bb28 281 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
ad3217cd 282 {
6262338c 283 const Handle(Prs3d_Drawer)& aDrawer = anIter.Value();
284 if (aDrawer->HasOwnShadingAspect())
ad3217cd 285 {
286 aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
287 }
288 }
289}
290
291//=======================================================================
f6d4c5cf 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 }
302 if (!HasColor() && !HasMaterial())
303 {
304 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
305 }
306
307 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
308 {
309 const Handle(Prs3d_Drawer)& aDrawer = anIter.Value();
310 if (aDrawer->HasOwnShadingAspect())
311 {
312 aDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
313 }
314 }
315 SynchronizeAspects();
316}
317
318//=======================================================================
e0608a8d 319//function : SetMaterial
320//purpose :
321//=======================================================================
322
323void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
324{
325 setMaterial (myDrawer, theMaterial, HasColor(), IsTransparent());
326 //myOwnMaterial = theMaterial;
327 hasOwnMaterial = Standard_True;
328 LoadRecomputable (AIS_Shaded);
fb66bb28 329 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
e0608a8d 330 {
331 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
332 //if (aDrawer->HasOwnMaterial()) continue;
6262338c 333 if (aDrawer->HasOwnShadingAspect())
e0608a8d 334 {
335 setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), Standard_False); // aDrawer->IsTransparent()
336 }
337 }
338}
339
340//=======================================================================
ad3217cd 341//function : Compute
342//purpose :
343//=======================================================================
344void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
345 const Handle(Prs3d_Presentation)& thePrs,
346 const Standard_Integer theMode)
347{
ede89abc 348 if (myshape.IsNull())
349 {
350 return;
351 }
352
ad3217cd 353 if (IsInfinite())
354 {
355 thePrs->SetInfiniteState (Standard_True);
356 }
357
ad3217cd 358 if (theMode == AIS_Shaded)
359 {
4c513386 360 if (myDrawer->IsAutoTriangulation())
ad3217cd 361 {
4c513386 362 // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
83b0f13a 363 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
364
306f5893 365 // After this call if type of deflection is relative
366 // computed deflection coefficient is stored as absolute.
5ad8c033 367 Standard_Boolean wasRecomputed = StdPrs_ToolTriangulatedShape::Tessellate (myshape, myDrawer);
368
369 // Set to update wireframe presentation on triangulation.
370 if (myDrawer->IsoOnTriangulation() && wasRecomputed)
371 {
372 SetToUpdate (AIS_WireFrame);
373 }
ad3217cd 374 }
7f917335 375 }
376 else // WireFrame mode
377 {
83b0f13a 378 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
379
7f917335 380 // After this call if type of deflection is relative
381 // computed deflection coefficient is stored as absolute.
382 Prs3d::GetDeflection (myshape, myDrawer);
ad3217cd 383 }
384
9c86076b 385 // Extract myShapeColors map (KeyshapeColored -> Color)
386 // to subshapes map (Subshape -> Color).
387 // This needed when colored shape is not part of BaseShape
388 // (but subshapes are) and actually container for subshapes.
389 AIS_DataMapOfShapeDrawer aSubshapeDrawerMap;
5bffb882 390 {
9c86076b 391 // unroll compounds specified for grouping sub-shapes with the same style
392 // (e.g. the compounds that are not a part of the main shape)
393 TopTools_MapOfShape aMapOfOwnCompounds;
394 if (myshape.ShapeType() == TopAbs_COMPOUND)
5bffb882 395 {
9c86076b 396 aMapOfOwnCompounds.Add (myshape);
397 collectSubCompounds (aMapOfOwnCompounds, myshape);
5bffb882 398 }
9c86076b 399 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
400 aKeyShapeIter.More(); aKeyShapeIter.Next())
5bffb882 401 {
9c86076b 402 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
403 if (aKeyShape.ShapeType() != TopAbs_COMPOUND
404 || aMapOfOwnCompounds.Contains (aKeyShape))
5bffb882 405 {
9c86076b 406 continue;
407 }
408
409 for (TopoDS_Iterator aChildIter (aKeyShape); aChildIter.More(); aChildIter.Next())
410 {
411 const TopoDS_Shape& aShape = aChildIter.Value();
412 if (!myShapeColors.IsBound (aShape))
413 {
414 bindSubShapes (aSubshapeDrawerMap, aShape, aKeyShapeIter.Value());
415 }
5bffb882 416 }
417 }
9c86076b 418
419 // assign other sub-shapes with styles
420 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
421 aKeyShapeIter.More(); aKeyShapeIter.Next())
422 {
423 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
424 if (myshape == aKeyShape
425 || (aKeyShape.ShapeType() == TopAbs_COMPOUND
426 && !aMapOfOwnCompounds.Contains (aKeyShape)))
427 {
428 continue;
429 }
430
431 bindSubShapes (aSubshapeDrawerMap, aKeyShape, aKeyShapeIter.Value());
432 }
5bffb882 433 }
9c86076b 434
435 Handle(AIS_ColoredDrawer) aBaseDrawer;
436 myShapeColors.Find (myshape, aBaseDrawer);
437
438 // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound
439 DataMapOfDrawerCompd aDispatchedOpened[(size_t)TopAbs_SHAPE];
440 DataMapOfDrawerCompd aDispatchedClosed;
441 dispatchColors (aBaseDrawer, myshape,
442 aSubshapeDrawerMap, TopAbs_COMPOUND, Standard_False,
443 aDispatchedOpened, theMode == AIS_Shaded ? aDispatchedClosed : aDispatchedOpened[TopAbs_FACE]);
444 addShapesWithCustomProps (thePrs, aDispatchedOpened, aDispatchedClosed, theMode);
5bffb882 445}
ad3217cd 446
5bffb882 447//=======================================================================
448//function : addShapesWithCustomProps
449//purpose :
450//=======================================================================
451void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
9c86076b 452 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
453 const DataMapOfDrawerCompd& theDrawerClosedFaces,
454 const Standard_Integer theMode)
5bffb882 455{
9c86076b 456 Handle(Graphic3d_Group) anOpenGroup, aClosedGroup;
457 for (size_t aShType = 0; aShType <= (size_t )TopAbs_SHAPE; ++aShType)
458 {
459 const Standard_Boolean isClosed = aShType == TopAbs_SHAPE;
460 Handle(Graphic3d_Group)& aShadedGroup = isClosed ? aClosedGroup : anOpenGroup;
461 const DataMapOfDrawerCompd& aDrawerShapeMap = isClosed
462 ? theDrawerClosedFaces
463 : theDrawerOpenedShapePerType[aShType];
464 for (DataMapOfDrawerCompd::Iterator aMapIter (aDrawerShapeMap);
ad3217cd 465 aMapIter.More(); aMapIter.Next())
466 {
9c86076b 467 const Handle(AIS_ColoredDrawer)& aCustomDrawer = aMapIter.Key();
ad3217cd 468 const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type
6262338c 469 Handle(Prs3d_Drawer) aDrawer;
9c86076b 470 if (!aCustomDrawer.IsNull())
86766b0e 471 {
472 aDrawer = aCustomDrawer;
473 if (aCustomDrawer->IsHidden())
474 {
475 continue;
476 }
477 }
478 else
479 {
480 aDrawer = myDrawer;
481 }
ad3217cd 482
7f917335 483 // It is supposed that absolute deflection contains previously computed relative deflection
484 // (if deflection type is relative).
485 // In case of CustomDrawer it is taken from Link().
486 Aspect_TypeOfDeflection aPrevType = aDrawer->TypeOfDeflection();
487 aDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
488
ad3217cd 489 // Draw each kind of subshapes and personal-colored shapes in a separate group
490 // since it's necessary to set transparency/material for all subshapes
491 // without affecting their unique colors
5bffb882 492 if (theMode == AIS_Shaded
493 && aShapeDraw.ShapeType() <= TopAbs_FACE
494 && !IsInfinite())
ad3217cd 495 {
9c86076b 496 // add wireframe presentation for isolated edges and vertices
497 StdPrs_ShadedShape::AddWireframeForFreeElements (thePrs, aShapeDraw, aDrawer);
498
499 // add special wireframe presentation for faces without triangulation
500 StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (thePrs, aShapeDraw, aDrawer);
501
502 Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw);
503 if (!aTriangles.IsNull())
504 {
505 if (aShadedGroup.IsNull())
506 {
507 aShadedGroup = Prs3d_Root::NewGroup (thePrs);
508 aShadedGroup->SetClosed (isClosed);
509 }
510 aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect());
511 aShadedGroup->AddPrimitiveArray (aTriangles);
512 }
513
514 if (aDrawer->FaceBoundaryDraw())
515 {
516 Handle(Graphic3d_ArrayOfSegments) aBndSegments = StdPrs_ShadedShape::FillFaceBoundaries (aShapeDraw);
517 if (!aBndSegments.IsNull())
518 {
519 if (aShadedGroup.IsNull())
520 {
521 aShadedGroup = Prs3d_Root::NewGroup (thePrs);
522 aShadedGroup->SetClosed (isClosed);
523 }
524
525 Handle(Graphic3d_AspectLine3d) aBoundaryAspect = aDrawer->FaceBoundaryAspect()->Aspect();
526 aShadedGroup->SetPrimitivesAspect (aBoundaryAspect);
527 aShadedGroup->AddPrimitiveArray (aBndSegments);
528 }
529 }
5bffb882 530 }
531 else
532 {
5ad8c033 533 StdPrs_WFShape::Add (thePrs, aShapeDraw, aDrawer);
ad3217cd 534 }
7f917335 535 aDrawer->SetTypeOfDeflection (aPrevType);
ad3217cd 536 }
537 }
538}
539
540//=======================================================================
541//function : dispatchColors
542//purpose :
543//=======================================================================
9c86076b 544Standard_Boolean AIS_ColoredShape::dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
545 const TopoDS_Shape& theShapeToParse,
546 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
547 const TopAbs_ShapeEnum theParentType,
548 const Standard_Boolean theIsParentClosed,
549 DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
550 DataMapOfDrawerCompd& theDrawerClosedFaces)
ad3217cd 551{
9c86076b 552 const TopAbs_ShapeEnum aShapeType = theShapeToParse.ShapeType();
553 if (aShapeType == TopAbs_SHAPE)
ad3217cd 554 {
555 return Standard_False;
556 }
557
558 // check own setting of current shape
9c86076b 559 Handle(AIS_ColoredDrawer) aDrawer = theParentDrawer;
560 const Standard_Boolean isOverriden = theShapeDrawerMap.Find (theShapeToParse, aDrawer);
561 if (isOverriden
562 && aDrawer->IsHidden())
563 {
564 return Standard_True;
565 }
566
567 // handle compounds, solids and shells
568 Standard_Boolean isSubOverride = Standard_False;
569 if (aShapeType <= TopAbs_SHELL)
570 {
571 // detect parts of closed solids
572 Standard_Boolean isClosedShell = theParentType == TopAbs_SOLID
573 && aShapeType == TopAbs_SHELL
574 && BRep_Tool::IsClosed (theShapeToParse)
575 && StdPrs_ToolTriangulatedShape::IsTriangulated (theShapeToParse);
576 if (isClosedShell)
577 {
578 for (TopoDS_Iterator aFaceIter (theShapeToParse); aFaceIter.More(); aFaceIter.Next())
579 {
580 const TopoDS_Shape& aFace = aFaceIter.Value();
581 Handle(AIS_ColoredDrawer) aFaceDrawer;
582 if (aFace.ShapeType() == TopAbs_FACE
583 && theShapeDrawerMap.Find (aFace, aFaceDrawer)
584 && aFaceDrawer->IsHidden())
585 {
586 isClosedShell = Standard_False;
587 break;
588 }
589 }
590 }
591
592 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
593 {
594 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
595 if (dispatchColors (aDrawer, aSubShape,
596 theShapeDrawerMap, aShapeType,
597 isClosedShell,
598 theDrawerOpenedShapePerType,
599 theDrawerClosedFaces))
600 {
601 isSubOverride = Standard_True;
602 }
603 }
604 return isOverriden || isSubOverride;
605 }
ad3217cd 606
607 // iterate on sub-shapes
608 BRep_Builder aBBuilder;
9c86076b 609 TopoDS_Shape aShapeCopy = theShapeToParse.EmptyCopied();
610 aShapeCopy.Closed (theShapeToParse.Closed());
ad3217cd 611 Standard_Integer nbDef = 0;
9c86076b 612 for (TopoDS_Iterator aSubShapeIter (theShapeToParse); aSubShapeIter.More(); aSubShapeIter.Next())
613 {
614 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
615 if (dispatchColors (aDrawer, aSubShape,
616 theShapeDrawerMap, aShapeType,
617 theIsParentClosed,
618 theDrawerOpenedShapePerType,
619 theDrawerClosedFaces))
ad3217cd 620 {
621 isSubOverride = Standard_True;
622 }
623 else
624 {
9c86076b 625 aBBuilder.Add (aShapeCopy, aSubShape);
ad3217cd 626 ++nbDef;
627 }
628 }
9c86076b 629 if (aShapeType == TopAbs_FACE || !isSubOverride)
ad3217cd 630 {
9c86076b 631 aShapeCopy = theShapeToParse;
ad3217cd 632 }
633 else if (nbDef == 0)
634 {
635 return isOverriden || isSubOverride; // empty compound
636 }
637
638 // if any of styles is overridden regarding to default one, add rest to map
639 if (isOverriden
640 || (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden
641 && theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face
9c86076b 642 || (theParentType <= TopAbs_SHELL && !(isOverriden || isSubOverride))) // bind original shape to default color
ad3217cd 643 {
644 TopoDS_Compound aCompound;
9c86076b 645 DataMapOfDrawerCompd& aDrawerShapeMap = theIsParentClosed
646 && aShapeType == TopAbs_FACE
647 ? theDrawerClosedFaces
648 : theDrawerOpenedShapePerType[(size_t)aShapeType];
649 if (!aDrawerShapeMap.FindFromKey (aDrawer, aCompound))
ad3217cd 650 {
651 aBBuilder.MakeCompound (aCompound);
9c86076b 652 aDrawerShapeMap.Add (aDrawer, aCompound);
ad3217cd 653 }
654 aBBuilder.Add (aCompound, aShapeCopy);
655 }
656 return isOverriden || isSubOverride;
657}
658
5bffb882 659//=======================================================================
660//function : isShapeEntirelyVisible
661//purpose :
662//=======================================================================
663Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const
664{
fb66bb28 665 for (AIS_DataMapOfShapeDrawer::Iterator aMapIter (myShapeColors); aMapIter.More(); aMapIter.Next())
5bffb882 666 {
667 if (aMapIter.Value()->IsHidden())
668 {
669 return Standard_False;
670 }
671 }
672 return Standard_True;
673}
674
675//=======================================================================
676//function : bindSubShapes
677//purpose :
678//=======================================================================
9c86076b 679void AIS_ColoredShape::bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
680 const TopoDS_Shape& theKeyShape,
681 const Handle(AIS_ColoredDrawer)& theDrawer)
5bffb882 682{
9c86076b 683 TopAbs_ShapeEnum aShapeWithColorType = theKeyShape.ShapeType();
5bffb882 684 if (aShapeWithColorType == TopAbs_COMPOUND)
685 {
9c86076b 686 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
ad3217cd 687 }
5bffb882 688 else if (aShapeWithColorType == TopAbs_SOLID || aShapeWithColorType == TopAbs_SHELL)
689 {
9c86076b 690 for (TopExp_Explorer anExp (theKeyShape, TopAbs_FACE); anExp.More(); anExp.Next())
5bffb882 691 {
9c86076b 692 if (!theShapeDrawerMap.IsBound (anExp.Current()))
5bffb882 693 {
9c86076b 694 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
5bffb882 695 }
696 }
697 }
698 else if (aShapeWithColorType == TopAbs_WIRE)
699 {
9c86076b 700 for (TopExp_Explorer anExp (theKeyShape, TopAbs_EDGE); anExp.More(); anExp.Next())
5bffb882 701 {
9c86076b 702 if (!theShapeDrawerMap.IsBound (anExp.Current()))
5bffb882 703 {
9c86076b 704 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
5bffb882 705 }
706 }
707 }
708 else
709 {
710 // bind single face, edge and vertex
711 // force rebind if required due to the color of single shape has
712 // higher priority than the color of "compound" shape (wire is a
713 // compound of edges, shell is a compound of faces) that contains
714 // this single shape.
9c86076b 715 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
5bffb882 716 }
ad3217cd 717}