0027900: Coding rules - drop redundant Name parameter from V3d_Viewer constructor
[occt.git] / src / PrsMgr / PrsMgr_PresentationManager.cxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <Geom_Transformation.hxx>
17 #include <Graphic3d_GraphicDriver.hxx>
18 #include <Prs3d_Presentation.hxx>
19 #include <Prs3d_PresentationShadow.hxx>
20 #include <PrsMgr_ModedPresentation.hxx>
21 #include <PrsMgr_PresentableObject.hxx>
22 #include <PrsMgr_Presentation.hxx>
23 #include <PrsMgr_PresentationManager.hxx>
24 #include <PrsMgr_Presentations.hxx>
25 #include <Standard_NoSuchObject.hxx>
26 #include <Standard_Type.hxx>
27 #include <TColStd_ListIteratorOfListOfTransient.hxx>
28 #include <V3d_View.hxx>
29
30 IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentationManager,MMgt_TShared)
31
32 // =======================================================================
33 // function : PrsMgr_PresentationManager
34 // purpose  :
35 // =======================================================================
36 PrsMgr_PresentationManager::PrsMgr_PresentationManager (const Handle(Graphic3d_StructureManager)& theStructureManager)
37 : myStructureManager (theStructureManager),
38   myImmediateModeOn  (0),
39   mySelectionColor   (Quantity_NOC_GRAY99)
40 {
41   //
42 }
43
44 // =======================================================================
45 // function : Display
46 // purpose  :
47 // =======================================================================
48 void PrsMgr_PresentationManager::Display (const Handle(PrsMgr_PresentableObject)& thePrsObj,
49                                           const Standard_Integer                  theMode)
50 {
51   if (thePrsObj->HasOwnPresentations())
52   {
53     Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
54     if (aPrs->MustBeUpdated())
55     {
56       Update (thePrsObj, theMode);
57     }
58
59     if (myImmediateModeOn > 0)
60     {
61       AddToImmediateList (aPrs->Presentation());
62     }
63     else
64     {
65       aPrs->Display();
66     }
67   }
68   else
69   {
70     thePrsObj->Compute (this, Handle(Prs3d_Presentation)(), theMode);
71   }
72
73   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
74   {
75     Display (anIter.Value(), theMode);
76   }
77 }
78
79 // =======================================================================
80 // function : Erase
81 // purpose  :
82 // =======================================================================
83 void PrsMgr_PresentationManager::Erase (const Handle(PrsMgr_PresentableObject)& thePrsObj,
84                                         const Standard_Integer                  theMode)
85 {
86   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
87   {
88     Erase (anIter.Value(), theMode);
89   }
90
91   PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
92   for (PrsMgr_Presentations::Iterator anIt (aPrsList); anIt.More();)
93   {
94     const PrsMgr_ModedPresentation& aModedPrs = anIt.Value();
95     if (aModedPrs.Presentation().IsNull())
96     {
97       anIt.Next();
98       continue;
99     }
100
101     const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager();
102     if ((theMode == aModedPrs.Mode() || theMode == -1)
103      && (this == aPrsMgr))
104     {
105       aModedPrs.Presentation()->Erase();
106
107       aPrsList.Remove (anIt);
108
109       if (theMode != -1)
110       {
111         return;
112       }
113     }
114     else
115     {
116       anIt.Next();
117     }
118   }
119 }
120
121 // =======================================================================
122 // function : Clear
123 // purpose  :
124 // =======================================================================
125 void PrsMgr_PresentationManager::Clear (const Handle(PrsMgr_PresentableObject)& thePrsObj,
126                                         const Standard_Integer                  theMode)
127 {
128   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
129   {
130     Clear (anIter.Value(), theMode);
131   }
132
133   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
134   if (!aPrs.IsNull())
135   {
136     aPrs->Clear();
137   }
138 }
139
140 // =======================================================================
141 // function : SetVisibility
142 // purpose  :
143 // =======================================================================
144 void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableObject)& thePrsObj,
145                                                 const Standard_Integer theMode,
146                                                 const Standard_Boolean theValue)
147 {
148   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
149   {
150     SetVisibility (anIter.Value(), theMode, theValue);
151   }
152   if (!thePrsObj->HasOwnPresentations())
153   {
154     return;
155   }
156
157   Presentation (thePrsObj, theMode)->SetVisible (theValue);
158 }
159
160 // =======================================================================
161 // function : Highlight
162 // purpose  :
163 // =======================================================================
164 void PrsMgr_PresentationManager::Highlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
165                                             const Standard_Integer                  theMode)
166 {
167   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
168   {
169     Highlight (anIter.Value(), theMode);
170   }
171   if (!thePrsObj->HasOwnPresentations())
172   {
173     return;
174   }
175
176   Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
177   if (aPrs->MustBeUpdated())
178   {
179     Update (thePrsObj, theMode);
180   }
181
182   if (myImmediateModeOn > 0)
183   {
184     Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
185     aShadow->Highlight (Aspect_TOHM_COLOR, mySelectionColor);
186     AddToImmediateList (aShadow);
187   }
188   else
189   {
190     aPrs->Highlight (Aspect_TOHM_COLOR, mySelectionColor);
191   }
192 }
193
194 // =======================================================================
195 // function : Unhighlight
196 // purpose  :
197 // =======================================================================
198 void PrsMgr_PresentationManager::Unhighlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
199                                               const Standard_Integer                  theMode)
200 {
201   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
202   {
203     Unhighlight (anIter.Value(), theMode);
204   }
205
206   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
207   if (!aPrs.IsNull())
208   {
209     aPrs->Unhighlight();
210   }
211 }
212
213 // =======================================================================
214 // function : SetDisplayPriority
215 // purpose  :
216 // =======================================================================
217 void PrsMgr_PresentationManager::SetDisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
218                                                      const Standard_Integer                  theMode,
219                                                      const Standard_Integer                  theNewPrior) const
220 {
221   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
222   {
223     SetDisplayPriority (anIter.Value(), theMode, theNewPrior);
224   }
225
226   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
227   if (!aPrs.IsNull())
228   {
229     aPrs->SetDisplayPriority (theNewPrior);
230   }
231 }
232
233 // =======================================================================
234 // function : DisplayPriority
235 // purpose  :
236 // =======================================================================
237 Standard_Integer PrsMgr_PresentationManager::DisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
238                                                               const Standard_Integer                  theMode) const
239 {
240   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
241   {
242     Standard_Integer aPriority = DisplayPriority (anIter.Value(), theMode);
243     if (aPriority != 0)
244     {
245       return aPriority;
246     }
247   }
248
249   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
250   return !aPrs.IsNull()
251         ? aPrs->DisplayPriority()
252         : 0;
253 }
254
255 // =======================================================================
256 // function : IsDisplayed
257 // purpose  :
258 // =======================================================================
259 Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (const Handle(PrsMgr_PresentableObject)& thePrsObj,
260                                                           const Standard_Integer                  theMode) const
261 {
262   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
263   {
264     if (IsDisplayed (anIter.Value(), theMode))
265     {
266       return Standard_True;
267     }
268   }
269
270   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
271   return !aPrs.IsNull()
272        && aPrs->IsDisplayed();
273 }
274
275 // =======================================================================
276 // function : IsHighlighted
277 // purpose  :
278 // =======================================================================
279 Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (const Handle(PrsMgr_PresentableObject)& thePrsObj,
280                                                             const Standard_Integer                  theMode) const
281 {
282   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
283   {
284     if (IsHighlighted (anIter.Value(), theMode))
285     {
286       return Standard_True;
287     }
288   }
289
290   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
291   return !aPrs.IsNull()
292        && aPrs->IsHighlighted();
293 }
294
295 // =======================================================================
296 // function : Update
297 // purpose  :
298 // =======================================================================
299 void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& thePrsObj,
300                                          const Standard_Integer                  theMode) const
301 {
302   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
303   {
304     Update (anIter.Value(), theMode);
305   }
306
307   Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
308   if (!aPrs.IsNull())
309   {
310     aPrs->Clear();
311     thePrsObj->Fill (this, aPrs, theMode);
312     aPrs->SetUpdateStatus (Standard_False);
313   }
314 }
315
316 // =======================================================================
317 // function : BeginImmediateDraw
318 // purpose  :
319 // =======================================================================
320 void PrsMgr_PresentationManager::BeginImmediateDraw()
321 {
322   if (++myImmediateModeOn > 1)
323   {
324     return;
325   }
326
327   ClearImmediateDraw();
328 }
329
330 // =======================================================================
331 // function : ClearImmediateDraw
332 // purpose  :
333 // =======================================================================
334 void PrsMgr_PresentationManager::ClearImmediateDraw()
335 {
336   for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
337   {
338     anIter.Value()->Erase();
339   }
340
341   for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next())
342   {
343     anIter.Value()->Erase();
344   }
345
346   myImmediateList.Clear();
347   myViewDependentImmediateList.Clear();
348 }
349
350 // =======================================================================
351 // function : displayImmediate
352 // purpose  : Handles the structures from myImmediateList and its visibility
353 //            in all views of the viewer given by setting proper affinity
354 // =======================================================================
355 void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& theViewer)
356 {
357   for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
358   {
359     const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View();
360     for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
361     {
362       const Handle(Prs3d_Presentation)& aPrs = anIter.Value();
363       if (aPrs.IsNull())
364         continue;
365
366       Handle(Graphic3d_Structure) aViewDepPrs;
367       Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs);
368       if (!aShadowPrs.IsNull() && aView->IsComputed (aShadowPrs->ParentId(), aViewDepPrs))
369       {
370         aShadowPrs.Nullify();
371         aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, 
372                                                    Handle(Prs3d_Presentation)::DownCast (aViewDepPrs));
373         aShadowPrs->SetZLayer (aViewDepPrs->CStructure()->ZLayer());
374         aShadowPrs->SetClipPlanes (aViewDepPrs->ClipPlanes());
375         aShadowPrs->CStructure()->IsForHighlight = 1;
376         aShadowPrs->Highlight (Aspect_TOHM_COLOR, aPrs->HighlightColor());
377         myViewDependentImmediateList.Append (aShadowPrs);
378       }
379       // handles custom highlight presentations which were defined in overridden
380       // HilightOwnerWithColor method of a custom AIS objects and maintain its
381       // visibility in different views on their own
382       else if (aShadowPrs.IsNull())
383       {
384         aPrs->Display();
385         continue;
386       }
387
388       if (!aShadowPrs->IsDisplayed())
389       {
390         aShadowPrs->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
391         aShadowPrs->CStructure()->ViewAffinity->SetVisible (Standard_False);
392         aShadowPrs->Display();
393       }
394
395       Standard_Integer aViewId = aView->Identification();
396       bool isParentVisible = aShadowPrs->ParentAffinity().IsNull() ?
397         Standard_True : aShadowPrs->ParentAffinity()->IsVisible (aViewId);
398       aShadowPrs->CStructure()->ViewAffinity->SetVisible (aViewId, isParentVisible);
399     }
400   }
401 }
402
403 // =======================================================================
404 // function : EndImmediateDraw
405 // purpose  :
406 // =======================================================================
407 void PrsMgr_PresentationManager::EndImmediateDraw (const Handle(V3d_Viewer)& theViewer)
408 {
409   if (--myImmediateModeOn > 0)
410   {
411     return;
412   }
413
414   displayImmediate (theViewer);
415 }
416
417 // =======================================================================
418 // function : RedrawImmediate
419 // purpose  : Clears all immediate structures and redisplays with proper
420 //            affinity
421 //=======================================================================
422 void PrsMgr_PresentationManager::RedrawImmediate (const Handle(V3d_Viewer)& theViewer)
423 {
424   if (myImmediateList.IsEmpty())
425     return;
426
427   // Clear previously displayed structures
428   for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
429   {
430     anIter.Value()->Erase();
431   }
432   for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next())
433   {
434     anIter.Value()->Erase();
435   }
436   myViewDependentImmediateList.Clear();
437
438   displayImmediate (theViewer);
439 }
440
441 // =======================================================================
442 // function : AddToImmediateList
443 // purpose  :
444 //=======================================================================
445 void PrsMgr_PresentationManager::AddToImmediateList (const Handle(Prs3d_Presentation)& thePrs)
446 {
447   if (myImmediateModeOn < 1)
448   {
449     return;
450   }
451
452   for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
453   {
454     if (anIter.Value() == thePrs)
455     {
456       return;
457     }
458   }
459
460   myImmediateList.Append (thePrs);
461 }
462
463 // =======================================================================
464 // function : HasPresentation
465 // purpose  :
466 // =======================================================================
467 Standard_Boolean PrsMgr_PresentationManager::HasPresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
468                                                               const Standard_Integer                  theMode) const
469 {
470   if (!thePrsObj->HasOwnPresentations())
471     return Standard_False;
472
473   const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
474   for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
475   {
476     const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
477     const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
478     if (theMode == aModedPrs.Mode()
479      && this    == aPrsMgr)
480     {
481       return Standard_True;
482     }
483   }
484   return Standard_False;
485 }
486
487 // =======================================================================
488 // function : Presentation
489 // purpose  :
490 // =======================================================================
491 Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
492                                                                       const Standard_Integer                  theMode,
493                                                                       const Standard_Boolean                  theToCreate,
494                                                                       const Handle(PrsMgr_PresentableObject)& theSelObj) const
495 {
496   const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
497   for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
498   {
499     const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
500     const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
501     if (theMode == aModedPrs.Mode()
502      && this    == aPrsMgr)
503     {
504       return aModedPrs.Presentation();
505     }
506   }
507
508   if (!theToCreate)
509   {
510     return Handle(PrsMgr_Presentation)();
511   }
512
513   Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj);
514   aPrs->SetZLayer (thePrsObj->ZLayer());
515   aPrs->Presentation()->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj);
516   thePrsObj->Presentations().Append (PrsMgr_ModedPresentation (aPrs, theMode));
517   thePrsObj->Fill (this, aPrs, theMode);
518
519   // set layer index accordingly to object's presentations
520   aPrs->SetUpdateStatus (Standard_False);
521   return aPrs;
522 }
523
524 // =======================================================================
525 // function : RemovePresentation
526 // purpose  :
527 // =======================================================================
528 Standard_Boolean PrsMgr_PresentationManager::RemovePresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
529                                                                  const Standard_Integer                  theMode)
530 {
531   PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
532   for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
533   {
534     const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
535     const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
536     if (theMode == aPrsList (aPrsIter).Mode()
537      && this    == aPrsMgr)
538     {
539       aPrsList.Remove (aPrsIter);
540       return Standard_True;
541     }
542   }
543   return Standard_False;
544 }
545
546 // =======================================================================
547 // function : SetZLayer
548 // purpose  :
549 // =======================================================================
550 void PrsMgr_PresentationManager::SetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj,
551                                             const Standard_Integer                  theLayerId)
552 {
553   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
554   {
555     SetZLayer (anIter.Value(), theLayerId);
556   }
557   if (!thePrsObj->HasOwnPresentations())
558   {
559     return;
560   }
561
562   thePrsObj->SetZLayer (theLayerId);
563 }
564
565 // =======================================================================
566 // function : GetZLayer
567 // purpose  :
568 // =======================================================================
569 Standard_Integer PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const
570 {
571   return thePrsObj->ZLayer();
572 }
573
574 // =======================================================================
575 // function : Connect
576 // purpose  :
577 // =======================================================================
578 void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)& thePrsObject,
579                                           const Handle(PrsMgr_PresentableObject)& theOtherObject,
580                                           const Standard_Integer                  theMode,
581                                           const Standard_Integer                  theOtherMode)
582 {
583   Handle(PrsMgr_Presentation) aPrs      = Presentation (thePrsObject,   theMode,      Standard_True);
584   Handle(PrsMgr_Presentation) aPrsOther = Presentation (theOtherObject, theOtherMode, Standard_True);
585   aPrs->Connect (aPrsOther);
586 }
587
588 // =======================================================================
589 // function : Transform
590 // purpose  :
591 // =======================================================================
592 void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObject)& thePrsObj,
593                                             const Handle(Geom_Transformation)&      theTransformation,
594                                             const Standard_Integer                  theMode)
595 {
596   Presentation (thePrsObj, theMode)->SetTransformation (theTransformation);
597 }
598
599
600 // =======================================================================
601 // function : Color
602 // purpose  :
603 // =======================================================================
604 void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)& thePrsObj,
605                                         const Quantity_NameOfColor              theColor,
606                                         const Standard_Integer                  theMode,
607                                         const Handle(PrsMgr_PresentableObject)& theSelObj,
608                                         const Standard_Integer theImmediateStructLayerId)
609 {
610   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
611   {
612     Color (anIter.Value(), theColor, theMode, NULL, theImmediateStructLayerId);
613   }
614   if (!thePrsObj->HasOwnPresentations())
615   {
616     return;
617   }
618
619   Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True, theSelObj);
620   if (aPrs->MustBeUpdated())
621   {
622     Update (thePrsObj, theMode);
623   }
624
625   if (myImmediateModeOn > 0)
626   {
627     Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
628     aShadow->SetZLayer (theImmediateStructLayerId);
629     aShadow->SetClipPlanes (aPrs->Presentation()->ClipPlanes());
630     aShadow->CStructure()->IsForHighlight = 1;
631     aShadow->Highlight (Aspect_TOHM_COLOR, theColor);
632     AddToImmediateList (aShadow);
633   }
634   else
635   {
636     aPrs->Highlight (Aspect_TOHM_COLOR, theColor);
637   }
638 }
639
640 // =======================================================================
641 // function : BoundBox
642 // purpose  :
643 // =======================================================================
644 void PrsMgr_PresentationManager::BoundBox (const Handle(PrsMgr_PresentableObject)& thePrsObj,
645                                            const Standard_Integer                  theMode)
646 {
647   Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
648   if (aPrs->MustBeUpdated())
649   {
650     Update (thePrsObj, theMode);
651   }
652   aPrs->Highlight (Aspect_TOHM_BOUNDBOX, mySelectionColor);
653 }
654
655 namespace
656 {
657   // =======================================================================
658   // function : updatePrsTransformation
659   // purpose  : Internal function that scans thePrsList for shadow presentations
660   //            and applies transformation theTrsf to them in case if parent ID
661   //            of shadow presentation is equal to theRefId
662   // =======================================================================
663   void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList,
664                                 const Standard_Integer theRefId,
665                                 const Handle(Geom_Transformation)& theTrsf)
666   {
667     for (PrsMgr_ListOfPresentations::Iterator anIter (thePrsList); anIter.More(); anIter.Next())
668     {
669       const Handle(Prs3d_Presentation)& aPrs = anIter.Value();
670       if (aPrs.IsNull())
671         continue;
672
673       Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs);
674       if (aShadowPrs.IsNull() || aShadowPrs->ParentId() != theRefId)
675         continue;
676
677       aShadowPrs->CStructure()->SetTransformation (theTrsf);
678     }
679   }
680 }
681
682 // =======================================================================
683 // function : UpdateHighlightTrsf
684 // purpose  :
685 // =======================================================================
686 void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
687                                                       const Handle(PrsMgr_PresentableObject)& theObj,
688                                                       const Standard_Integer theMode,
689                                                       const Handle(PrsMgr_PresentableObject)& theSelObj)
690 {
691   if (theObj.IsNull())
692     return;
693
694   const Handle(Prs3d_Presentation)& aBasePrs = Presentation (theObj, theMode, Standard_False)->Presentation();
695   const Handle(Prs3d_Presentation)& aParentPrs = theSelObj.IsNull() ?
696     aBasePrs : Presentation (theSelObj, theMode, Standard_False)->Presentation();
697   const Standard_Integer aParentId = aParentPrs->CStructure()->Id;
698
699   updatePrsTransformation (myImmediateList, aParentId, aBasePrs->CStructure()->Transformation());
700
701   if (!myViewDependentImmediateList.IsEmpty())
702   {
703     for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
704     {
705       const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View();
706       Handle(Graphic3d_Structure) aViewDepParentPrs;
707       if (aView->IsComputed (aParentId, aViewDepParentPrs))
708       {
709         updatePrsTransformation (myViewDependentImmediateList,
710                                  aViewDepParentPrs->CStructure()->Id,
711                                  aBasePrs->CStructure()->Transformation());
712       }
713     }
714   }
715 }