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