0027700: Visualization - glPolygonMode() used for frame drawing affects label text...
[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 (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
93   {
94     const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
95     const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
96     if (theMode == aPrsList (aPrsIter).Mode()
97      && this    == aPrsMgr)
98     {
99       if (!aModedPrs.Presentation().IsNull())
100       {
101         aModedPrs.Presentation()->Erase();
102       }
103       aPrsList.Remove (aPrsIter);
104       return;
105     }
106   }
107 }
108
109 // =======================================================================
110 // function : Clear
111 // purpose  :
112 // =======================================================================
113 void PrsMgr_PresentationManager::Clear (const Handle(PrsMgr_PresentableObject)& thePrsObj,
114                                         const Standard_Integer                  theMode)
115 {
116   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
117   {
118     Clear (anIter.Value(), theMode);
119   }
120
121   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
122   if (!aPrs.IsNull())
123   {
124     aPrs->Clear();
125   }
126 }
127
128 // =======================================================================
129 // function : SetVisibility
130 // purpose  :
131 // =======================================================================
132 void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableObject)& thePrsObj,
133                                                 const Standard_Integer theMode,
134                                                 const Standard_Boolean theValue)
135 {
136   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
137   {
138     SetVisibility (anIter.Value(), theMode, theValue);
139   }
140   if (!thePrsObj->HasOwnPresentations())
141   {
142     return;
143   }
144
145   Presentation (thePrsObj, theMode)->SetVisible (theValue);
146 }
147
148 // =======================================================================
149 // function : Highlight
150 // purpose  :
151 // =======================================================================
152 void PrsMgr_PresentationManager::Highlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
153                                             const Standard_Integer                  theMode)
154 {
155   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
156   {
157     Highlight (anIter.Value(), theMode);
158   }
159   if (!thePrsObj->HasOwnPresentations())
160   {
161     return;
162   }
163
164   Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
165   if (aPrs->MustBeUpdated())
166   {
167     Update (thePrsObj, theMode);
168   }
169
170   if (myImmediateModeOn > 0)
171   {
172     Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
173     aShadow->Highlight (Aspect_TOHM_COLOR, mySelectionColor);
174     AddToImmediateList (aShadow);
175   }
176   else
177   {
178     aPrs->Highlight (Aspect_TOHM_COLOR, mySelectionColor);
179   }
180 }
181
182 // =======================================================================
183 // function : Unhighlight
184 // purpose  :
185 // =======================================================================
186 void PrsMgr_PresentationManager::Unhighlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
187                                               const Standard_Integer                  theMode)
188 {
189   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
190   {
191     Unhighlight (anIter.Value(), theMode);
192   }
193
194   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
195   if (!aPrs.IsNull())
196   {
197     aPrs->Unhighlight();
198   }
199 }
200
201 // =======================================================================
202 // function : SetDisplayPriority
203 // purpose  :
204 // =======================================================================
205 void PrsMgr_PresentationManager::SetDisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
206                                                      const Standard_Integer                  theMode,
207                                                      const Standard_Integer                  theNewPrior) const
208 {
209   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
210   {
211     SetDisplayPriority (anIter.Value(), theMode, theNewPrior);
212   }
213
214   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
215   if (!aPrs.IsNull())
216   {
217     aPrs->SetDisplayPriority (theNewPrior);
218   }
219 }
220
221 // =======================================================================
222 // function : DisplayPriority
223 // purpose  :
224 // =======================================================================
225 Standard_Integer PrsMgr_PresentationManager::DisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
226                                                               const Standard_Integer                  theMode) const
227 {
228   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
229   {
230     Standard_Integer aPriority = DisplayPriority (anIter.Value(), theMode);
231     if (aPriority != 0)
232     {
233       return aPriority;
234     }
235   }
236
237   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
238   return !aPrs.IsNull()
239         ? aPrs->DisplayPriority()
240         : 0;
241 }
242
243 // =======================================================================
244 // function : IsDisplayed
245 // purpose  :
246 // =======================================================================
247 Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (const Handle(PrsMgr_PresentableObject)& thePrsObj,
248                                                           const Standard_Integer                  theMode) const
249 {
250   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
251   {
252     if (IsDisplayed (anIter.Value(), theMode))
253     {
254       return Standard_True;
255     }
256   }
257
258   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
259   return !aPrs.IsNull()
260        && aPrs->IsDisplayed();
261 }
262
263 // =======================================================================
264 // function : IsHighlighted
265 // purpose  :
266 // =======================================================================
267 Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (const Handle(PrsMgr_PresentableObject)& thePrsObj,
268                                                             const Standard_Integer                  theMode) const
269 {
270   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
271   {
272     if (IsHighlighted (anIter.Value(), theMode))
273     {
274       return Standard_True;
275     }
276   }
277
278   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
279   return !aPrs.IsNull()
280        && aPrs->IsHighlighted();
281 }
282
283 // =======================================================================
284 // function : Update
285 // purpose  :
286 // =======================================================================
287 void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& thePrsObj,
288                                          const Standard_Integer                  theMode) const
289 {
290   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
291   {
292     Update (anIter.Value(), theMode);
293   }
294
295   Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
296   if (!aPrs.IsNull())
297   {
298     aPrs->Clear();
299     thePrsObj->Fill (this, aPrs, theMode);
300     aPrs->SetUpdateStatus (Standard_False);
301   }
302 }
303
304 // =======================================================================
305 // function : BeginImmediateDraw
306 // purpose  :
307 // =======================================================================
308 void PrsMgr_PresentationManager::BeginImmediateDraw()
309 {
310   if (++myImmediateModeOn > 1)
311   {
312     return;
313   }
314
315   ClearImmediateDraw();
316 }
317
318 // =======================================================================
319 // function : ClearImmediateDraw
320 // purpose  :
321 // =======================================================================
322 void PrsMgr_PresentationManager::ClearImmediateDraw()
323 {
324   for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
325   {
326     anIter.Value()->Erase();
327   }
328
329   for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next())
330   {
331     anIter.Value()->Erase();
332   }
333
334   myImmediateList.Clear();
335   myViewDependentImmediateList.Clear();
336 }
337
338 // =======================================================================
339 // function : displayImmediate
340 // purpose  : Handles the structures from myImmediateList and its visibility
341 //            in all views of the viewer given by setting proper affinity
342 // =======================================================================
343 void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& theViewer)
344 {
345   for (theViewer->InitActiveViews(); theViewer->MoreActiveViews(); theViewer->NextActiveViews())
346   {
347     const Handle(Graphic3d_CView)& aView = theViewer->ActiveView()->View();
348     for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
349     {
350       const Handle(Prs3d_Presentation)& aPrs = anIter.Value();
351       if (aPrs.IsNull())
352         continue;
353
354       Handle(Graphic3d_Structure) aViewDepPrs;
355       Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs);
356       if (!aShadowPrs.IsNull() && aView->IsComputed (aShadowPrs->ParentId(), aViewDepPrs))
357       {
358         aShadowPrs.Nullify();
359         aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, 
360                                                    Handle(Prs3d_Presentation)::DownCast (aViewDepPrs));
361         aShadowPrs->SetZLayer (aViewDepPrs->CStructure()->ZLayer());
362         aShadowPrs->SetClipPlanes (aViewDepPrs->GetClipPlanes());
363         aShadowPrs->CStructure()->IsForHighlight = 1;
364         aShadowPrs->Highlight (Aspect_TOHM_COLOR, aPrs->HighlightColor());
365         myViewDependentImmediateList.Append (aShadowPrs);
366       }
367       // handles custom highlight presentations which were defined in overridden
368       // HilightOwnerWithColor method of a custom AIS objects and maintain its
369       // visibility in different views on their own
370       else if (aShadowPrs.IsNull())
371       {
372         aPrs->Display();
373         continue;
374       }
375
376       if (!aShadowPrs->IsDisplayed())
377       {
378         aShadowPrs->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
379         aShadowPrs->CStructure()->ViewAffinity->SetVisible (Standard_False);
380         aShadowPrs->Display();
381       }
382
383       Standard_Integer aViewId = aView->Identification();
384       bool isParentVisible = aShadowPrs->ParentAffinity().IsNull() ?
385         Standard_True : aShadowPrs->ParentAffinity()->IsVisible (aViewId);
386       aShadowPrs->CStructure()->ViewAffinity->SetVisible (aViewId, isParentVisible);
387     }
388   }
389 }
390
391 // =======================================================================
392 // function : EndImmediateDraw
393 // purpose  :
394 // =======================================================================
395 void PrsMgr_PresentationManager::EndImmediateDraw (const Handle(V3d_Viewer)& theViewer)
396 {
397   if (--myImmediateModeOn > 0)
398   {
399     return;
400   }
401
402   displayImmediate (theViewer);
403 }
404
405 // =======================================================================
406 // function : RedrawImmediate
407 // purpose  : Clears all immediate structures and redisplays with proper
408 //            affinity
409 //=======================================================================
410 void PrsMgr_PresentationManager::RedrawImmediate (const Handle(V3d_Viewer)& theViewer)
411 {
412   if (myImmediateList.IsEmpty())
413     return;
414
415   // Clear previously displayed structures
416   for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
417   {
418     anIter.Value()->Erase();
419   }
420   for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next())
421   {
422     anIter.Value()->Erase();
423   }
424   myViewDependentImmediateList.Clear();
425
426   displayImmediate (theViewer);
427 }
428
429 // =======================================================================
430 // function : AddToImmediateList
431 // purpose  :
432 //=======================================================================
433 void PrsMgr_PresentationManager::AddToImmediateList (const Handle(Prs3d_Presentation)& thePrs)
434 {
435   if (myImmediateModeOn < 1)
436   {
437     return;
438   }
439
440   for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
441   {
442     if (anIter.Value() == thePrs)
443     {
444       return;
445     }
446   }
447
448   myImmediateList.Append (thePrs);
449 }
450
451 // =======================================================================
452 // function : HasPresentation
453 // purpose  :
454 // =======================================================================
455 Standard_Boolean PrsMgr_PresentationManager::HasPresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
456                                                               const Standard_Integer                  theMode) const
457 {
458   if (!thePrsObj->HasOwnPresentations())
459     return Standard_False;
460
461   const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
462   for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
463   {
464     const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
465     const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
466     if (theMode == aModedPrs.Mode()
467      && this    == aPrsMgr)
468     {
469       return Standard_True;
470     }
471   }
472   return Standard_False;
473 }
474
475 // =======================================================================
476 // function : Presentation
477 // purpose  :
478 // =======================================================================
479 Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
480                                                                       const Standard_Integer                  theMode,
481                                                                       const Standard_Boolean                  theToCreate,
482                                                                       const Handle(PrsMgr_PresentableObject)& theSelObj) const
483 {
484   const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
485   for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
486   {
487     const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
488     const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
489     if (theMode == aModedPrs.Mode()
490      && this    == aPrsMgr)
491     {
492       return aModedPrs.Presentation();
493     }
494   }
495
496   if (!theToCreate)
497   {
498     return Handle(PrsMgr_Presentation)();
499   }
500
501   Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj);
502   aPrs->SetZLayer (thePrsObj->ZLayer());
503   aPrs->Presentation()->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj);
504   thePrsObj->Presentations().Append (PrsMgr_ModedPresentation (aPrs, theMode));
505   thePrsObj->Fill (this, aPrs, theMode);
506
507   // set layer index accordingly to object's presentations
508   aPrs->SetUpdateStatus (Standard_False);
509   return aPrs;
510 }
511
512 // =======================================================================
513 // function : RemovePresentation
514 // purpose  :
515 // =======================================================================
516 Standard_Boolean PrsMgr_PresentationManager::RemovePresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
517                                                                  const Standard_Integer                  theMode)
518 {
519   PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
520   for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
521   {
522     const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
523     const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
524     if (theMode == aPrsList (aPrsIter).Mode()
525      && this    == aPrsMgr)
526     {
527       aPrsList.Remove (aPrsIter);
528       return Standard_True;
529     }
530   }
531   return Standard_False;
532 }
533
534 // =======================================================================
535 // function : SetZLayer
536 // purpose  :
537 // =======================================================================
538 void PrsMgr_PresentationManager::SetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj,
539                                             const Standard_Integer                  theLayerId)
540 {
541   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
542   {
543     SetZLayer (anIter.Value(), theLayerId);
544   }
545   if (!thePrsObj->HasOwnPresentations())
546   {
547     return;
548   }
549
550   thePrsObj->SetZLayer (theLayerId);
551 }
552
553 // =======================================================================
554 // function : GetZLayer
555 // purpose  :
556 // =======================================================================
557 Standard_Integer PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const
558 {
559   return thePrsObj->ZLayer();
560 }
561
562 // =======================================================================
563 // function : Connect
564 // purpose  :
565 // =======================================================================
566 void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)& thePrsObject,
567                                           const Handle(PrsMgr_PresentableObject)& theOtherObject,
568                                           const Standard_Integer                  theMode,
569                                           const Standard_Integer                  theOtherMode)
570 {
571   Handle(PrsMgr_Presentation) aPrs      = Presentation (thePrsObject,   theMode,      Standard_True);
572   Handle(PrsMgr_Presentation) aPrsOther = Presentation (theOtherObject, theOtherMode, Standard_True);
573   aPrs->Connect (aPrsOther);
574 }
575
576 // =======================================================================
577 // function : Transform
578 // purpose  :
579 // =======================================================================
580 void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObject)& thePrsObj,
581                                             const Handle(Geom_Transformation)&      theTransformation,
582                                             const Standard_Integer                  theMode)
583 {
584   Presentation (thePrsObj, theMode)->Transform (theTransformation);
585 }
586
587
588 // =======================================================================
589 // function : Color
590 // purpose  :
591 // =======================================================================
592 void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)& thePrsObj,
593                                         const Quantity_NameOfColor              theColor,
594                                         const Standard_Integer                  theMode,
595                                         const Handle(PrsMgr_PresentableObject)& theSelObj,
596                                         const Standard_Integer theImmediateStructLayerId)
597 {
598   for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
599   {
600     Color (anIter.Value(), theColor, theMode, NULL, theImmediateStructLayerId);
601   }
602   if (!thePrsObj->HasOwnPresentations())
603   {
604     return;
605   }
606
607   Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True, theSelObj);
608   if (aPrs->MustBeUpdated())
609   {
610     Update (thePrsObj, theMode);
611   }
612
613   if (myImmediateModeOn > 0)
614   {
615     Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
616     aShadow->SetZLayer (theImmediateStructLayerId);
617     aShadow->SetClipPlanes (aPrs->Presentation()->GetClipPlanes());
618     aShadow->CStructure()->IsForHighlight = 1;
619     aShadow->Highlight (Aspect_TOHM_COLOR, theColor);
620     AddToImmediateList (aShadow);
621   }
622   else
623   {
624     aPrs->Highlight (Aspect_TOHM_COLOR, theColor);
625   }
626 }
627
628 // =======================================================================
629 // function : BoundBox
630 // purpose  :
631 // =======================================================================
632 void PrsMgr_PresentationManager::BoundBox (const Handle(PrsMgr_PresentableObject)& thePrsObj,
633                                            const Standard_Integer                  theMode)
634 {
635   Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
636   if (aPrs->MustBeUpdated())
637   {
638     Update (thePrsObj, theMode);
639   }
640   aPrs->Highlight (Aspect_TOHM_BOUNDBOX, mySelectionColor);
641 }
642
643 namespace
644 {
645   // =======================================================================
646   // function : updatePrsTransformation
647   // purpose  : Internal funtion that scans thePrsList for shadow presentations
648   //            and applies transformation theTrsf to them in case if parent ID
649   //            of shadow presentation is equal to theRefId
650   // =======================================================================
651   void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList,
652                                 const Standard_Integer theRefId,
653                                 const Graphic3d_Mat4& theTrsf)
654   {
655     for (PrsMgr_ListOfPresentations::Iterator anIter (thePrsList); anIter.More(); anIter.Next())
656     {
657       const Handle(Prs3d_Presentation)& aPrs = anIter.Value();
658       if (aPrs.IsNull())
659         continue;
660
661       Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs);
662       if (aShadowPrs.IsNull() || aShadowPrs->ParentId() != theRefId)
663         continue;
664
665       aShadowPrs->CStructure()->Transformation = theTrsf;
666     }
667   }
668 }
669
670 // =======================================================================
671 // function : UpdateHighlightTrsf
672 // purpose  :
673 // =======================================================================
674 void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
675                                                       const Handle(PrsMgr_PresentableObject)& theObj,
676                                                       const Standard_Integer theMode,
677                                                       const Handle(PrsMgr_PresentableObject)& theSelObj)
678 {
679   if (theObj.IsNull())
680     return;
681
682   const Handle(Prs3d_Presentation)& aBasePrs = Presentation (theObj, theMode, Standard_False)->Presentation();
683   const Handle(Prs3d_Presentation)& aParentPrs = theSelObj.IsNull() ?
684     aBasePrs : Presentation (theSelObj, theMode, Standard_False)->Presentation();
685   const Standard_Integer aParentId = aParentPrs->CStructure()->Id;
686
687   updatePrsTransformation (myImmediateList, aParentId, aBasePrs->CStructure()->Transformation);
688
689   if (!myViewDependentImmediateList.IsEmpty())
690   {
691     for (theViewer->InitActiveViews(); theViewer->MoreActiveViews(); theViewer->NextActiveViews())
692     {
693       const Handle(Graphic3d_CView)& aView = theViewer->ActiveView()->View();
694       Handle(Graphic3d_Structure) aViewDepParentPrs;
695       if (aView->IsComputed (aParentId, aViewDepParentPrs))
696       {
697         updatePrsTransformation (myViewDependentImmediateList,
698                                  aViewDepParentPrs->CStructure()->Id,
699                                  aBasePrs->CStructure()->Transformation);
700       }
701     }
702   }
703 }