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