0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[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
42cf5bc1 17#include <Geom_Transformation.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 {
371 aShadowPrs.Nullify();
7dd7c146 372 aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, aViewDepPrs);
c3282ec1 373 aShadowPrs->SetZLayer (aViewDepPrs->CStructure()->ZLayer());
3202bf1e 374 aShadowPrs->SetClipPlanes (aViewDepPrs->ClipPlanes());
c3282ec1 375 aShadowPrs->CStructure()->IsForHighlight = 1;
8e5fb5ea 376 aShadowPrs->Highlight (aPrs->HighlightStyle());
c3282ec1 377 myViewDependentImmediateList.Append (aShadowPrs);
378 }
c357e426 379 // handles custom highlight presentations which were defined in overridden
c3282ec1 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 }
7fd59977 401}
402
679ecdee 403// =======================================================================
404// function : EndImmediateDraw
405// purpose :
406// =======================================================================
c3282ec1 407void PrsMgr_PresentationManager::EndImmediateDraw (const Handle(V3d_Viewer)& theViewer)
679ecdee 408{
409 if (--myImmediateModeOn > 0)
410 {
411 return;
412 }
413
c3282ec1 414 displayImmediate (theViewer);
415}
416
417// =======================================================================
418// function : RedrawImmediate
419// purpose : Clears all immediate structures and redisplays with proper
420// affinity
421//=======================================================================
422void PrsMgr_PresentationManager::RedrawImmediate (const Handle(V3d_Viewer)& theViewer)
423{
424 if (myImmediateList.IsEmpty())
425 return;
426
427 // Clear previously displayed structures
679ecdee 428 for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
429 {
c3282ec1 430 anIter.Value()->Erase();
679ecdee 431 }
c3282ec1 432 for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next())
679ecdee 433 {
c3282ec1 434 anIter.Value()->Erase();
679ecdee 435 }
c3282ec1 436 myViewDependentImmediateList.Clear();
437
438 displayImmediate (theViewer);
679ecdee 439}
7fd59977 440
679ecdee 441// =======================================================================
442// function : AddToImmediateList
443// purpose :
444//=======================================================================
445void 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;
7fd59977 457 }
679ecdee 458 }
459
460 myImmediateList.Append (thePrs);
461}
462
463// =======================================================================
464// function : HasPresentation
465// purpose :
466// =======================================================================
467Standard_Boolean PrsMgr_PresentationManager::HasPresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
468 const Standard_Integer theMode) const
469{
0717ddc1 470 if (!thePrsObj->HasOwnPresentations())
471 return Standard_False;
472
679ecdee 473 const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
7dd7c146 474 for (PrsMgr_Presentations::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
679ecdee 475 {
7dd7c146 476 const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
477 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aPrs->PresentationManager();
478 if (theMode == aPrs->Mode()
679ecdee 479 && this == aPrsMgr)
480 {
481 return Standard_True;
7fd59977 482 }
483 }
679ecdee 484 return Standard_False;
7fd59977 485}
486
679ecdee 487// =======================================================================
488// function : Presentation
489// purpose :
490// =======================================================================
491Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
a1954302 492 const Standard_Integer theMode,
a272ed94 493 const Standard_Boolean theToCreate,
494 const Handle(PrsMgr_PresentableObject)& theSelObj) const
679ecdee 495{
496 const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
7dd7c146 497 for (PrsMgr_Presentations::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
679ecdee 498 {
7dd7c146 499 const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
500 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aPrs->PresentationManager();
501 if (theMode == aPrs->Mode()
679ecdee 502 && this == aPrsMgr)
503 {
7dd7c146 504 return aPrs;
679ecdee 505 }
506 }
7fd59977 507
a1954302 508 if (!theToCreate)
509 {
510 return Handle(PrsMgr_Presentation)();
511 }
7fd59977 512
7dd7c146 513 Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj, theMode);
a1954302 514 aPrs->SetZLayer (thePrsObj->ZLayer());
7dd7c146 515 aPrs->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj);
516 thePrsObj->Presentations().Append (aPrs);
679ecdee 517 thePrsObj->Fill (this, aPrs, theMode);
7fd59977 518
679ecdee 519 // set layer index accordingly to object's presentations
679ecdee 520 aPrs->SetUpdateStatus (Standard_False);
a1954302 521 return aPrs;
679ecdee 522}
7fd59977 523
679ecdee 524// =======================================================================
525// function : RemovePresentation
526// purpose :
527// =======================================================================
a1954302 528Standard_Boolean PrsMgr_PresentationManager::RemovePresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
529 const Standard_Integer theMode)
7fd59977 530{
679ecdee 531 PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
7dd7c146 532 for (PrsMgr_Presentations::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
679ecdee 533 {
7dd7c146 534 const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
535 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aPrs->PresentationManager();
536 if (theMode == aPrs->Mode()
a1954302 537 && this == aPrsMgr)
679ecdee 538 {
539 aPrsList.Remove (aPrsIter);
a1954302 540 return Standard_True;
679ecdee 541 }
542 }
a1954302 543 return Standard_False;
679ecdee 544}
7fd59977 545
679ecdee 546// =======================================================================
547// function : SetZLayer
548// purpose :
549// =======================================================================
550void PrsMgr_PresentationManager::SetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj,
8f138407 551 const Graphic3d_ZLayerId theLayerId)
679ecdee 552{
0d56f743 553 if (thePrsObj->ToPropagateVisualState())
0717ddc1 554 {
0d56f743 555 for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
556 {
557 SetZLayer(anIter.Value(), theLayerId);
558 }
0717ddc1 559 }
0d56f743 560
0717ddc1 561 if (!thePrsObj->HasOwnPresentations())
562 {
563 return;
564 }
a1954302 565
566 thePrsObj->SetZLayer (theLayerId);
679ecdee 567}
7fd59977 568
679ecdee 569// =======================================================================
570// function : GetZLayer
571// purpose :
572// =======================================================================
8f138407 573Graphic3d_ZLayerId PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const
679ecdee 574{
a1954302 575 return thePrsObj->ZLayer();
679ecdee 576}
7fd59977 577
679ecdee 578// =======================================================================
579// function : Connect
580// purpose :
581// =======================================================================
582void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)& thePrsObject,
583 const Handle(PrsMgr_PresentableObject)& theOtherObject,
584 const Standard_Integer theMode,
585 const Standard_Integer theOtherMode)
586{
a1954302 587 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObject, theMode, Standard_True);
588 Handle(PrsMgr_Presentation) aPrsOther = Presentation (theOtherObject, theOtherMode, Standard_True);
7dd7c146 589 aPrs->Connect (aPrsOther.get(), Graphic3d_TOC_DESCENDANT);
7fd59977 590}
591
679ecdee 592// =======================================================================
593// function : Transform
594// purpose :
595// =======================================================================
596void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObject)& thePrsObj,
597 const Handle(Geom_Transformation)& theTransformation,
598 const Standard_Integer theMode)
599{
1f7f5a90 600 Presentation (thePrsObj, theMode)->SetTransformation (theTransformation);
679ecdee 601}
7fd59977 602
679ecdee 603// =======================================================================
604// function : Color
605// purpose :
606// =======================================================================
607void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)& thePrsObj,
f838dac4 608 const Handle(Prs3d_Drawer)& theStyle,
a272ed94 609 const Standard_Integer theMode,
c3282ec1 610 const Handle(PrsMgr_PresentableObject)& theSelObj,
611 const Standard_Integer theImmediateStructLayerId)
7fd59977 612{
0d56f743 613 if (thePrsObj->ToPropagateVisualState())
0717ddc1 614 {
0d56f743 615 for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
616 {
617 Color(anIter.Value(), theStyle, theMode, NULL, theImmediateStructLayerId);
618 }
0717ddc1 619 }
620 if (!thePrsObj->HasOwnPresentations())
621 {
622 return;
623 }
624
a272ed94 625 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True, theSelObj);
679ecdee 626 if (aPrs->MustBeUpdated())
627 {
628 Update (thePrsObj, theMode);
629 }
59f45b7c 630
679ecdee 631 if (myImmediateModeOn > 0)
632 {
7dd7c146 633 Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs);
c3282ec1 634 aShadow->SetZLayer (theImmediateStructLayerId);
7dd7c146 635 aShadow->SetClipPlanes (aPrs->ClipPlanes());
c3282ec1 636 aShadow->CStructure()->IsForHighlight = 1;
8e5fb5ea 637 aShadow->Highlight (theStyle);
679ecdee 638 AddToImmediateList (aShadow);
639 }
640 else
641 {
8e5fb5ea 642 aPrs->Highlight (theStyle);
59f45b7c 643 }
644}
645
5396886c 646namespace
647{
648 // =======================================================================
649 // function : updatePrsTransformation
1f7f5a90 650 // purpose : Internal function that scans thePrsList for shadow presentations
5396886c 651 // and applies transformation theTrsf to them in case if parent ID
652 // of shadow presentation is equal to theRefId
653 // =======================================================================
654 void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList,
655 const Standard_Integer theRefId,
1f7f5a90 656 const Handle(Geom_Transformation)& theTrsf)
5396886c 657 {
658 for (PrsMgr_ListOfPresentations::Iterator anIter (thePrsList); anIter.More(); anIter.Next())
659 {
660 const Handle(Prs3d_Presentation)& aPrs = anIter.Value();
661 if (aPrs.IsNull())
662 continue;
663
664 Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs);
665 if (aShadowPrs.IsNull() || aShadowPrs->ParentId() != theRefId)
666 continue;
667
1f7f5a90 668 aShadowPrs->CStructure()->SetTransformation (theTrsf);
5396886c 669 }
670 }
671}
672
673// =======================================================================
674// function : UpdateHighlightTrsf
675// purpose :
676// =======================================================================
677void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
678 const Handle(PrsMgr_PresentableObject)& theObj,
679 const Standard_Integer theMode,
680 const Handle(PrsMgr_PresentableObject)& theSelObj)
681{
682 if (theObj.IsNull())
683 return;
684
7bbccb5f 685 Handle(PrsMgr_Presentation) aPrs = Presentation (!theSelObj.IsNull() ? theSelObj : theObj, theMode, Standard_False);
686 if (aPrs.IsNull())
687 {
688 return;
689 }
5396886c 690
7bbccb5f 691 Handle(Geom_Transformation) aTrsf = theObj->LocalTransformationGeom();
7dd7c146 692 const Standard_Integer aParentId = aPrs->CStructure()->Id;
7bbccb5f 693 updatePrsTransformation (myImmediateList, aParentId, aTrsf);
5396886c 694
695 if (!myViewDependentImmediateList.IsEmpty())
696 {
6a24c6de 697 for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
5396886c 698 {
6a24c6de 699 const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View();
5396886c 700 Handle(Graphic3d_Structure) aViewDepParentPrs;
701 if (aView->IsComputed (aParentId, aViewDepParentPrs))
702 {
703 updatePrsTransformation (myViewDependentImmediateList,
704 aViewDepParentPrs->CStructure()->Id,
7bbccb5f 705 aTrsf);
5396886c 706 }
707 }
708 }
709}