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