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