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