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