0026411: Necessary to improve XCAF to store and querying GD&T data.
[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>
24#include <Graphic3d_Group.hxx>
25#include <Graphic3d_StructureManager.hxx>
26#include <Graphic3d_Texture2Dmanual.hxx>
27#include <Precision.hxx>
6262338c 28#include <Prs3d.hxx>
ad3217cd 29#include <Prs3d_LineAspect.hxx>
30#include <Prs3d_IsoAspect.hxx>
31#include <Prs3d_Presentation.hxx>
32#include <Prs3d_ShadingAspect.hxx>
33#include <Prs3d_Root.hxx>
34#include <PrsMgr_PresentationManager3d.hxx>
35#include <Standard_ErrorHandler.hxx>
36#include <StdPrs_ShadedShape.hxx>
37#include <StdPrs_ToolShadedShape.hxx>
38#include <StdPrs_WFDeflectionShape.hxx>
ad3217cd 39#include <TopExp_Explorer.hxx>
40#include <TopoDS.hxx>
41#include <TopoDS_Compound.hxx>
42#include <TopoDS_Iterator.hxx>
43
ad3217cd 44
ec357c5c 45
ad3217cd 46
47//=======================================================================
48//function : AIS_ColoredShape
49//purpose :
50//=======================================================================
51AIS_ColoredShape::AIS_ColoredShape (const TopoDS_Shape& theShape)
52: AIS_Shape (theShape)
53{
54 // disable dedicated line aspects
55 myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
56 myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
57 myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
58}
59
60//=======================================================================
61//function : AIS_ColoredShape
62//purpose :
63//=======================================================================
64AIS_ColoredShape::AIS_ColoredShape (const Handle(AIS_Shape)& theShape)
65: AIS_Shape (theShape->Shape())
66{
67 // disable dedicated line aspects
68 myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
69 myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
70 myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
71 if (theShape->HasMaterial())
72 {
73 SetMaterial (theShape->Material());
74 }
75 if (theShape->HasColor())
76 {
77 SetColor (theShape->Color());
78 }
79 if (theShape->HasWidth())
80 {
81 SetWidth (theShape->Width());
82 }
83 if (theShape->IsTransparent())
84 {
85 SetTransparency (theShape->Transparency());
86 }
87}
88
89//=======================================================================
90//function : CustomAspects
91//purpose :
92//=======================================================================
93Handle(AIS_ColoredDrawer) AIS_ColoredShape::CustomAspects (const TopoDS_Shape& theShape)
94{
95 Handle(AIS_ColoredDrawer) aDrawer;
96 myShapeColors.Find (theShape, aDrawer);
97 if (aDrawer.IsNull())
98 {
99 aDrawer = new AIS_ColoredDrawer (myDrawer);
100 myShapeColors.Bind (theShape, aDrawer);
101 LoadRecomputable (AIS_WireFrame);
102 LoadRecomputable (AIS_Shaded);
103 }
104 return aDrawer;
105}
106
107//=======================================================================
108//function : ClearCustomAspects
109//purpose :
110//=======================================================================
111void AIS_ColoredShape::ClearCustomAspects()
112{
113 if (myShapeColors.IsEmpty())
114 {
115 return;
116 }
117 myShapeColors.Clear();
118 LoadRecomputable (AIS_WireFrame);
119 LoadRecomputable (AIS_Shaded);
120}
121
122//=======================================================================
123//function : UnsetCustomAspects
124//purpose :
125//=======================================================================
126void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape& theShape,
127 const Standard_Boolean theToUnregister)
128{
129 if (!myShapeColors.IsBound (theShape))
130 {
131 return;
132 }
133
134 LoadRecomputable (AIS_WireFrame);
135 LoadRecomputable (AIS_Shaded);
136 if (theToUnregister)
137 {
138 myShapeColors.UnBind (theShape);
139 return;
140 }
141
142 myShapeColors.ChangeFind (theShape) = new AIS_ColoredDrawer (myDrawer);
143}
144
145//=======================================================================
146//function : SetCustomColor
147//purpose :
148//=======================================================================
149void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape,
150 const Quantity_Color& theColor)
151{
152 if (theShape.IsNull())
153 {
154 return;
155 }
156
157 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
158 setColor (aDrawer, theColor);
159 aDrawer->SetOwnColor (theColor);
160 LoadRecomputable (AIS_WireFrame);
161 LoadRecomputable (AIS_Shaded);
162}
163
164//=======================================================================
165//function : SetCustomWidth
166//purpose :
167//=======================================================================
168void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape,
169 const Standard_Real theLineWidth)
170{
171 if (theShape.IsNull())
172 {
173 return;
174 }
175
176 const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
177 setWidth (CustomAspects (theShape), theLineWidth);
178 aDrawer->SetOwnWidth (theLineWidth);
179 LoadRecomputable (AIS_WireFrame);
180 LoadRecomputable (AIS_Shaded);
181}
182
183//=======================================================================
184//function : SetColor
185//purpose :
186//=======================================================================
187
188void AIS_ColoredShape::SetColor (const Quantity_Color& theColor)
189{
190 setColor (myDrawer, theColor);
191 myOwnColor = theColor;
192 hasOwnColor = Standard_True;
193 LoadRecomputable (AIS_WireFrame);
194 LoadRecomputable (AIS_Shaded);
195 for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
196 {
197 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
198 if (aDrawer->HasOwnColor())
199 {
200 continue;
201 }
202
6262338c 203 if (aDrawer->HasOwnShadingAspect())
ad3217cd 204 {
205 aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
206 }
6262338c 207 if (aDrawer->HasOwnLineAspect())
ad3217cd 208 {
209 aDrawer->LineAspect()->SetColor (theColor);
210 }
6262338c 211 if (aDrawer->HasOwnWireAspect())
ad3217cd 212 {
213 aDrawer->WireAspect()->SetColor (theColor);
214 }
215 }
216}
217
218//=======================================================================
219//function : SetWidth
220//purpose :
221//=======================================================================
222
223void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth)
224{
225 setWidth (myDrawer, theLineWidth);
226 myOwnWidth = theLineWidth;
227 LoadRecomputable (AIS_WireFrame);
228 LoadRecomputable (AIS_Shaded);
229 for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
230 {
231 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
232 if (aDrawer->HasOwnWidth())
233 {
234 continue;
235 }
236
6262338c 237 if (aDrawer->HasOwnLineAspect())
ad3217cd 238 {
239 aDrawer->LineAspect()->SetWidth (theLineWidth);
240 }
6262338c 241 if (aDrawer->HasOwnWireAspect())
ad3217cd 242 {
243 aDrawer->WireAspect()->SetWidth (theLineWidth);
244 }
245 }
246}
247
248//=======================================================================
249//function : SetTransparency
250//purpose :
251//=======================================================================
252
253void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
254{
255 setTransparency (myDrawer, theValue);
256 myTransparency = theValue;
257 LoadRecomputable (AIS_WireFrame);
258 LoadRecomputable (AIS_Shaded);
259 for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
260 {
6262338c 261 const Handle(Prs3d_Drawer)& aDrawer = anIter.Value();
262 if (aDrawer->HasOwnShadingAspect())
ad3217cd 263 {
264 aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
265 }
266 }
267}
268
269//=======================================================================
e0608a8d 270//function : SetMaterial
271//purpose :
272//=======================================================================
273
274void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
275{
276 setMaterial (myDrawer, theMaterial, HasColor(), IsTransparent());
277 //myOwnMaterial = theMaterial;
278 hasOwnMaterial = Standard_True;
279 LoadRecomputable (AIS_Shaded);
280 for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
281 {
282 const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
283 //if (aDrawer->HasOwnMaterial()) continue;
6262338c 284 if (aDrawer->HasOwnShadingAspect())
e0608a8d 285 {
286 setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), Standard_False); // aDrawer->IsTransparent()
287 }
288 }
289}
290
291//=======================================================================
ad3217cd 292//function : Compute
293//purpose :
294//=======================================================================
295void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
296 const Handle(Prs3d_Presentation)& thePrs,
297 const Standard_Integer theMode)
298{
299 thePrs->Clear();
300 if (IsInfinite())
301 {
302 thePrs->SetInfiniteState (Standard_True);
303 }
304
ad3217cd 305 if (theMode == AIS_Shaded)
306 {
4c513386 307 if (myDrawer->IsAutoTriangulation())
ad3217cd 308 {
4c513386 309 // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
310 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
311 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
312 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
313 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
314 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
315 {
316 BRepTools::Clean (myshape);
317 }
306f5893 318 // After this call if type of deflection is relative
319 // computed deflection coefficient is stored as absolute.
4c513386 320 StdPrs_ShadedShape::Tessellate (myshape, myDrawer);
ad3217cd 321 }
7f917335 322 }
323 else // WireFrame mode
324 {
325 // After this call if type of deflection is relative
326 // computed deflection coefficient is stored as absolute.
327 Prs3d::GetDeflection (myshape, myDrawer);
ad3217cd 328 }
329
5bffb882 330 TopoDS_Compound anOpened, aClosed;
331 BRep_Builder aBuilder;
332 aBuilder.MakeCompound (aClosed);
333 aBuilder.MakeCompound (anOpened);
334 if (theMode == AIS_Shaded && myshape.ShapeType() <= TopAbs_SOLID)
335 {
336 StdPrs_ShadedShape::ExploreSolids (myshape, aBuilder, aClosed, anOpened, Standard_False);
337 }
338 else
339 {
340 aBuilder.Add (anOpened, myshape);
341 }
342
343 // myShapeColors + anOpened --> array[TopAbs_ShapeEnum] of map of color-to-compound
344 DataMapOfShapeCompd aDispatchedOpened [(size_t)TopAbs_SHAPE];
345 dispatchColors (anOpened, myShapeColors, aDispatchedOpened);
346 addShapesWithCustomProps (thePrs, aDispatchedOpened, theMode, StdPrs_Volume_Opened);
347
348 if (theMode == AIS_Shaded)
349 {
350 if (isShapeEntirelyVisible())
351 {
352 // myShapeColors + aClosed --> array[TopAbs_ShapeEnum] of map of color-to-compound
353 DataMapOfShapeCompd aDispatchedClosed [(size_t)TopAbs_SHAPE];
354 dispatchColors (aClosed, myShapeColors, aDispatchedClosed);
355 addShapesWithCustomProps (thePrs, aDispatchedClosed, theMode, StdPrs_Volume_Closed);
356 }
357 else
358 {
359 for (TopoDS_Iterator aSolidIter (aClosed); aSolidIter.More(); aSolidIter.Next())
360 {
361 DataMapOfShapeCompd aDispatchedClosed [(size_t)TopAbs_SHAPE];
362 dispatchColors (aSolidIter.Value(), myShapeColors, aDispatchedClosed);
363 addShapesWithCustomProps (thePrs, aDispatchedClosed, theMode,
364 isShapeEntirelyVisible (aDispatchedClosed) ? StdPrs_Volume_Closed : StdPrs_Volume_Opened);
365 }
366 }
367 }
368}
ad3217cd 369
5bffb882 370//=======================================================================
371//function : addShapesWithCustomProps
372//purpose :
373//=======================================================================
374void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
375 DataMapOfShapeCompd* theDispatched,
376 const Standard_Integer theMode,
377 const StdPrs_Volume theVolume)
378{
ad3217cd 379 Handle(AIS_ColoredDrawer) aCustomDrawer;
380 for (size_t aShType = 0; aShType < (size_t )TopAbs_SHAPE; ++aShType)
381 {
5bffb882 382 DataMapOfShapeCompd& aKeyshapeDrawshapeMap = theDispatched[aShType];
ad3217cd 383 for (DataMapOfShapeCompd::Iterator aMapIter (aKeyshapeDrawshapeMap);
384 aMapIter.More(); aMapIter.Next())
385 {
386 const TopoDS_Shape& aShapeKey = aMapIter.Key(); // key shape with detailed color or a base shape
387 const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type
6262338c 388 Handle(Prs3d_Drawer) aDrawer;
86766b0e 389 if (myShapeColors.Find (aShapeKey, aCustomDrawer))
390 {
391 aDrawer = aCustomDrawer;
392 if (aCustomDrawer->IsHidden())
393 {
394 continue;
395 }
396 }
397 else
398 {
399 aDrawer = myDrawer;
400 }
ad3217cd 401
7f917335 402 // It is supposed that absolute deflection contains previously computed relative deflection
403 // (if deflection type is relative).
404 // In case of CustomDrawer it is taken from Link().
405 Aspect_TypeOfDeflection aPrevType = aDrawer->TypeOfDeflection();
406 aDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
407
ad3217cd 408 // Draw each kind of subshapes and personal-colored shapes in a separate group
409 // since it's necessary to set transparency/material for all subshapes
410 // without affecting their unique colors
5bffb882 411 if (theMode == AIS_Shaded
412 && aShapeDraw.ShapeType() <= TopAbs_FACE
413 && !IsInfinite())
ad3217cd 414 {
5bffb882 415 StdPrs_ShadedShape::Add (thePrs, aShapeDraw, aDrawer, theVolume);
416 }
417 else
418 {
419 StdPrs_WFDeflectionShape::Add (thePrs, aShapeDraw, aDrawer);
ad3217cd 420 }
7f917335 421 aDrawer->SetTypeOfDeflection (aPrevType);
ad3217cd 422 }
423 }
424}
425
426//=======================================================================
427//function : dispatchColors
428//purpose :
429//=======================================================================
430Standard_Boolean AIS_ColoredShape::dispatchColors (const TopoDS_Shape& theBaseKey,
431 const TopoDS_Shape& theSubshapeToParse,
432 const DataMapOfShapeShape& theSubshapeKeyshapeMap,
433 const TopAbs_ShapeEnum theParentType,
434 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray)
435{
436 TopAbs_ShapeEnum aShType = theSubshapeToParse.ShapeType();
437 if (aShType == TopAbs_SHAPE)
438 {
439 return Standard_False;
440 }
441
442 // check own setting of current shape
443 TopoDS_Shape aKeyShape = theBaseKey;
444 Standard_Boolean isOverriden = theSubshapeKeyshapeMap.Find (theSubshapeToParse, aKeyShape);
445
446 // iterate on sub-shapes
447 BRep_Builder aBBuilder;
448 TopoDS_Shape aShapeCopy = theSubshapeToParse.EmptyCopied();
ab860031 449 aShapeCopy.Closed (theSubshapeToParse.Closed());
ad3217cd 450 Standard_Boolean isSubOverride = Standard_False;
451 Standard_Integer nbDef = 0;
452 for (TopoDS_Iterator it (theSubshapeToParse); it.More(); it.Next())
453 {
454 if (dispatchColors (theBaseKey, it.Value(),
455 theSubshapeKeyshapeMap, aShType,
456 theTypeKeyshapeDrawshapeArray))
457 {
458 isSubOverride = Standard_True;
459 }
460 else
461 {
462 aBBuilder.Add (aShapeCopy, it.Value());
463 ++nbDef;
464 }
465 }
466 if (aShType == TopAbs_FACE || !isSubOverride)
467 {
468 aShapeCopy = theSubshapeToParse;
469 }
470 else if (nbDef == 0)
471 {
472 return isOverriden || isSubOverride; // empty compound
473 }
474
475 // if any of styles is overridden regarding to default one, add rest to map
476 if (isOverriden
477 || (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden
478 && theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face
479 || (theParentType == TopAbs_SHAPE && !(isOverriden || isSubOverride))) // bind original shape to default color
480 {
481 TopoDS_Compound aCompound;
482 DataMapOfShapeCompd& aKeyshapeDrawshapeMap = theTypeKeyshapeDrawshapeArray[(size_t )aShType];
483 if (!aKeyshapeDrawshapeMap.FindFromKey (aKeyShape, aCompound))
484 {
485 aBBuilder.MakeCompound (aCompound);
486 aKeyshapeDrawshapeMap.Add (aKeyShape, aCompound);
487 }
488 aBBuilder.Add (aCompound, aShapeCopy);
489 }
490 return isOverriden || isSubOverride;
491}
492
3ea0a91b 493//! Function to check if specified compound is sub-shape of another one
5bffb882 494inline Standard_Boolean isFirstCmpContainSecondOne (const TopoDS_Shape& theFirstCmp,
495 const TopoDS_Shape& theSecondCmp)
3ea0a91b 496{
5bffb882 497 if (theFirstCmp.ShapeType() != TopAbs_COMPOUND
498 || theSecondCmp.ShapeType() != TopAbs_COMPOUND)
3ea0a91b 499 {
500 return Standard_False;
501 }
502
5bffb882 503 for (TopoDS_Iterator aFirstCmpIter (theFirstCmp); aFirstCmpIter.More(); aFirstCmpIter.Next())
3ea0a91b 504 {
5bffb882 505 if (aFirstCmpIter.Value().ShapeType() != TopAbs_COMPOUND)
3ea0a91b 506 {
507 continue;
508 }
5bffb882 509 else if (aFirstCmpIter.Value() == theSecondCmp
510 || isFirstCmpContainSecondOne (aFirstCmpIter.Value(), theSecondCmp))
3ea0a91b 511 {
512 return Standard_True;
513 }
514 }
515 return Standard_False;
516}
517
ad3217cd 518//=======================================================================
519//function : dispatchColors
520//purpose :
521//=======================================================================
522void AIS_ColoredShape::dispatchColors (const TopoDS_Shape& theBaseShape,
523 const DataMapOfShapeColor& theKeyshapeColorMap,
524 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray)
525{
526 // Extract <theShapeColors> map (KeyshapeColored -> Color)
527 // to subshapes map (Subshape -> KeyshapeColored).
528 // This needed when colored shape is not part of <theBaseShape>
529 // (but subshapes are) and actually container for subshapes.
530 DataMapOfShapeShape aSubshapeKeyshapeMap;
3ea0a91b 531 for (DataMapOfShapeColor::Iterator aKeyShapeIter (theKeyshapeColorMap);
532 aKeyShapeIter.More(); aKeyShapeIter.Next())
ad3217cd 533 {
5bffb882 534 const TopoDS_Shape& aKeyShape = aKeyShapeIter.Key();
535 bindSubShapes (aSubshapeKeyshapeMap, theBaseShape, aKeyShape, aKeyShape);
536 }
537
538 // Fill the array of maps per shape type
539 dispatchColors (theBaseShape, theBaseShape,
540 aSubshapeKeyshapeMap, TopAbs_SHAPE,
541 theTypeKeyshapeDrawshapeArray);
542}
543
544//=======================================================================
545//function : isShapeEntirelyVisible
546//purpose :
547//=======================================================================
548Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible (DataMapOfShapeCompd* theDispatched) const
549{
550 Handle(AIS_ColoredDrawer) aCustomDrawer;
551 for (size_t aShType = (size_t )TopAbs_COMPOUND; aShType <= (size_t )TopAbs_FACE; ++aShType)
552 {
553 const DataMapOfShapeCompd& aKeyshapeDrawshapeMap = theDispatched[aShType];
554 for (DataMapOfShapeCompd::Iterator aMapIter (aKeyshapeDrawshapeMap); aMapIter.More(); aMapIter.Next())
ad3217cd 555 {
5bffb882 556 if (myShapeColors.Find (aMapIter.Key(), aCustomDrawer)
557 && !aCustomDrawer.IsNull()
558 && aCustomDrawer->IsHidden())
ad3217cd 559 {
5bffb882 560 return Standard_False;
ad3217cd 561 }
5bffb882 562 }
563 }
564 return Standard_True;
565}
566
567//=======================================================================
568//function : isShapeEntirelyVisible
569//purpose :
570//=======================================================================
571Standard_Boolean AIS_ColoredShape::isShapeEntirelyVisible() const
572{
573 for (DataMapOfShapeColor::Iterator aMapIter (myShapeColors); aMapIter.More(); aMapIter.Next())
574 {
575 if (aMapIter.Value()->IsHidden())
576 {
577 return Standard_False;
578 }
579 }
580 return Standard_True;
581}
582
583//=======================================================================
584//function : bindSubShapes
585//purpose :
586//=======================================================================
587void AIS_ColoredShape::bindSubShapes (DataMapOfShapeShape& theSubshapeKeyshapeMap,
588 const TopoDS_Shape& theBaseShape,
589 const TopoDS_Shape& theShapeWithColor,
590 const TopoDS_Shape& theColorKeyShape)
591{
592 TopAbs_ShapeEnum aShapeWithColorType = theShapeWithColor.ShapeType();
593 if (aShapeWithColorType == TopAbs_COMPOUND)
594 {
595 if (isFirstCmpContainSecondOne (theBaseShape, theShapeWithColor))
596 {
597 if (!theSubshapeKeyshapeMap.IsBound (theShapeWithColor))
ad3217cd 598 {
5bffb882 599 theSubshapeKeyshapeMap.Bind (theShapeWithColor, theColorKeyShape);
600 }
601 }
602 else
603 {
604 for (TopoDS_Iterator aSubShapeIter (theShapeWithColor); aSubShapeIter.More(); aSubShapeIter.Next())
605 {
606 bindSubShapes (theSubshapeKeyshapeMap, theBaseShape, aSubShapeIter.Value(), theColorKeyShape);
ad3217cd 607 }
608 }
609 }
5bffb882 610 else if (aShapeWithColorType == TopAbs_SOLID || aShapeWithColorType == TopAbs_SHELL)
611 {
612 for (TopExp_Explorer anExp (theShapeWithColor, TopAbs_FACE); anExp.More(); anExp.Next())
613 {
614 if (!theSubshapeKeyshapeMap.IsBound (anExp.Current()))
615 {
616 theSubshapeKeyshapeMap.Bind (anExp.Current(), theColorKeyShape);
617 }
618 }
619 }
620 else if (aShapeWithColorType == TopAbs_WIRE)
621 {
622 for (TopExp_Explorer anExp (theShapeWithColor, TopAbs_EDGE); anExp.More(); anExp.Next())
623 {
624 if (!theSubshapeKeyshapeMap.IsBound (anExp.Current()))
625 {
626 theSubshapeKeyshapeMap.Bind (anExp.Current(), theColorKeyShape);
627 }
628 }
629 }
630 else
631 {
632 // bind single face, edge and vertex
633 // force rebind if required due to the color of single shape has
634 // higher priority than the color of "compound" shape (wire is a
635 // compound of edges, shell is a compound of faces) that contains
636 // this single shape.
637 theSubshapeKeyshapeMap.Bind (theShapeWithColor, theColorKeyShape);
638 }
ad3217cd 639}
5bffb882 640