0028811: Visualization - merge texturing support into AIS_Shape class and get rid...
[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);
a6dee93d 301 if (!HasColor()
302 && !HasMaterial()
303 && !myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
304 {
305 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
306 }
f6d4c5cf 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//=======================================================================
e0608a8d 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);
fb66bb28 331 for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
e0608a8d 332 {
333 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
334 //if (aDrawer->HasOwnMaterial()) continue;
6262338c 335 if (aDrawer->HasOwnShadingAspect())
e0608a8d 336 {
337 setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), Standard_False); // aDrawer->IsTransparent()
338 }
339 }
340}
341
342//=======================================================================
ad3217cd 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{
ede89abc 350 if (myshape.IsNull())
351 {
352 return;
353 }
354
ad3217cd 355 if (IsInfinite())
356 {
357 thePrs->SetInfiniteState (Standard_True);
358 }
359
ad3217cd 360 if (theMode == AIS_Shaded)
361 {
4c513386 362 if (myDrawer->IsAutoTriangulation())
ad3217cd 363 {
4c513386 364 // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
83b0f13a 365 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
366
306f5893 367 // After this call if type of deflection is relative
368 // computed deflection coefficient is stored as absolute.
5ad8c033 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 }
ad3217cd 376 }
7f917335 377 }
378 else // WireFrame mode
379 {
83b0f13a 380 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
381
7f917335 382 // After this call if type of deflection is relative
383 // computed deflection coefficient is stored as absolute.
384 Prs3d::GetDeflection (myshape, myDrawer);
ad3217cd 385 }
386
9c86076b 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;
5bffb882 392 {
9c86076b 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)
5bffb882 397 {
9c86076b 398 aMapOfOwnCompounds.Add (myshape);
399 collectSubCompounds (aMapOfOwnCompounds, myshape);
5bffb882 400 }
9c86076b 401 for (AIS_DataMapOfShapeDrawer::Iterator aKeyShapeIter (myShapeColors);
402 aKeyShapeIter.More(); aKeyShapeIter.Next())
5bffb882 403 {
9c86076b 404 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
405 if (aKeyShape.ShapeType() != TopAbs_COMPOUND
406 || aMapOfOwnCompounds.Contains (aKeyShape))
5bffb882 407 {
9c86076b 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 }
5bffb882 418 }
419 }
9c86076b 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 }
5bffb882 435 }
9c86076b 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);
5bffb882 447}
ad3217cd 448
5bffb882 449//=======================================================================
450//function : addShapesWithCustomProps
451//purpose :
452//=======================================================================
453void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
9c86076b 454 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
455 const DataMapOfDrawerCompd& theDrawerClosedFaces,
456 const Standard_Integer theMode)
5bffb882 457{
9c86076b 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);
ad3217cd 467 aMapIter.More(); aMapIter.Next())
468 {
9c86076b 469 const Handle(AIS_ColoredDrawer)& aCustomDrawer = aMapIter.Key();
ad3217cd 470 const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type
6262338c 471 Handle(Prs3d_Drawer) aDrawer;
9c86076b 472 if (!aCustomDrawer.IsNull())
86766b0e 473 {
474 aDrawer = aCustomDrawer;
475 if (aCustomDrawer->IsHidden())
476 {
477 continue;
478 }
479 }
480 else
481 {
482 aDrawer = myDrawer;
483 }
ad3217cd 484
7f917335 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
ad3217cd 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
5bffb882 494 if (theMode == AIS_Shaded
495 && aShapeDraw.ShapeType() <= TopAbs_FACE
496 && !IsInfinite())
ad3217cd 497 {
9c86076b 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
a6dee93d 504 Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw,
505 aDrawer->ShadingAspect()->Aspect()->ToMapTexture()
506 && !aDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
507 myUVOrigin, myUVRepeat, myUVScale);
9c86076b 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 }
5bffb882 535 }
536 else
537 {
5ad8c033 538 StdPrs_WFShape::Add (thePrs, aShapeDraw, aDrawer);
ad3217cd 539 }
7f917335 540 aDrawer->SetTypeOfDeflection (aPrevType);
ad3217cd 541 }
542 }
543}
544
545//=======================================================================
546//function : dispatchColors
547//purpose :
548//=======================================================================
9c86076b 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)
ad3217cd 556{
9c86076b 557 const TopAbs_ShapeEnum aShapeType = theShapeToParse.ShapeType();
558 if (aShapeType == TopAbs_SHAPE)
ad3217cd 559 {
560 return Standard_False;
561 }
562
563 // check own setting of current shape
9c86076b 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 }
ad3217cd 611
612 // iterate on sub-shapes
613 BRep_Builder aBBuilder;
9c86076b 614 TopoDS_Shape aShapeCopy = theShapeToParse.EmptyCopied();
615 aShapeCopy.Closed (theShapeToParse.Closed());
ad3217cd 616 Standard_Integer nbDef = 0;
9c86076b 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))
ad3217cd 625 {
626 isSubOverride = Standard_True;
627 }
628 else
629 {
9c86076b 630 aBBuilder.Add (aShapeCopy, aSubShape);
ad3217cd 631 ++nbDef;
632 }
633 }
9c86076b 634 if (aShapeType == TopAbs_FACE || !isSubOverride)
ad3217cd 635 {
9c86076b 636 aShapeCopy = theShapeToParse;
ad3217cd 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
9c86076b 647 || (theParentType <= TopAbs_SHELL && !(isOverriden || isSubOverride))) // bind original shape to default color
ad3217cd 648 {
649 TopoDS_Compound aCompound;
9c86076b 650 DataMapOfDrawerCompd& aDrawerShapeMap = theIsParentClosed
651 && aShapeType == TopAbs_FACE
652 ? theDrawerClosedFaces
653 : theDrawerOpenedShapePerType[(size_t)aShapeType];
654 if (!aDrawerShapeMap.FindFromKey (aDrawer, aCompound))
ad3217cd 655 {
656 aBBuilder.MakeCompound (aCompound);
9c86076b 657 aDrawerShapeMap.Add (aDrawer, aCompound);
ad3217cd 658 }
659 aBBuilder.Add (aCompound, aShapeCopy);
660 }
661 return isOverriden || isSubOverride;
662}
663
5bffb882 664//=======================================================================
665//function : isShapeEntirelyVisible
666//purpose :
667//=======================================================================
668Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const
669{
fb66bb28 670 for (AIS_DataMapOfShapeDrawer::Iterator aMapIter (myShapeColors); aMapIter.More(); aMapIter.Next())
5bffb882 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//=======================================================================
9c86076b 684void AIS_ColoredShape::bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
685 const TopoDS_Shape& theKeyShape,
686 const Handle(AIS_ColoredDrawer)& theDrawer)
5bffb882 687{
9c86076b 688 TopAbs_ShapeEnum aShapeWithColorType = theKeyShape.ShapeType();
5bffb882 689 if (aShapeWithColorType == TopAbs_COMPOUND)
690 {
9c86076b 691 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
ad3217cd 692 }
5bffb882 693 else if (aShapeWithColorType == TopAbs_SOLID || aShapeWithColorType == TopAbs_SHELL)
694 {
9c86076b 695 for (TopExp_Explorer anExp (theKeyShape, TopAbs_FACE); anExp.More(); anExp.Next())
5bffb882 696 {
9c86076b 697 if (!theShapeDrawerMap.IsBound (anExp.Current()))
5bffb882 698 {
9c86076b 699 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
5bffb882 700 }
701 }
702 }
703 else if (aShapeWithColorType == TopAbs_WIRE)
704 {
9c86076b 705 for (TopExp_Explorer anExp (theKeyShape, TopAbs_EDGE); anExp.More(); anExp.Next())
5bffb882 706 {
9c86076b 707 if (!theShapeDrawerMap.IsBound (anExp.Current()))
5bffb882 708 {
9c86076b 709 theShapeDrawerMap.Bind (anExp.Current(), theDrawer);
5bffb882 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.
9c86076b 720 theShapeDrawerMap.Bind (theKeyShape, theDrawer);
5bffb882 721 }
ad3217cd 722}