0025180: Visualization - Homogeneous transformation API in TKV3d
[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();
e2d7642f 92 for (PrsMgr_Presentations::Iterator anIt (aPrsList); anIt.More();)
eef7fc64 93 {
e2d7642f 94 const PrsMgr_ModedPresentation& aModedPrs = anIt.Value();
95 if (aModedPrs.Presentation().IsNull())
a1954302 96 {
e2d7642f 97 anIt.Next();
98 continue;
99 }
100
101 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager();
102 if ((theMode == aModedPrs.Mode() || theMode == -1)
103 && (this == aPrsMgr))
104 {
105 aModedPrs.Presentation()->Erase();
106
107 aPrsList.Remove (anIt);
108
109 if (theMode != -1)
a1954302 110 {
e2d7642f 111 return;
a1954302 112 }
e2d7642f 113 }
114 else
115 {
116 anIt.Next();
a1954302 117 }
eef7fc64 118 }
7fd59977 119}
120
679ecdee 121// =======================================================================
122// function : Clear
123// purpose :
124// =======================================================================
125void PrsMgr_PresentationManager::Clear (const Handle(PrsMgr_PresentableObject)& thePrsObj,
126 const Standard_Integer theMode)
7fd59977 127{
0717ddc1 128 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
129 {
130 Clear (anIter.Value(), theMode);
131 }
132
a1954302 133 const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
134 if (!aPrs.IsNull())
679ecdee 135 {
a1954302 136 aPrs->Clear();
679ecdee 137 }
7fd59977 138}
139
679ecdee 140// =======================================================================
141// function : SetVisibility
142// purpose :
143// =======================================================================
0717ddc1 144void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableObject)& thePrsObj,
eb4320f2 145 const Standard_Integer theMode,
146 const Standard_Boolean theValue)
147{
0717ddc1 148 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
149 {
150 SetVisibility (anIter.Value(), theMode, theValue);
151 }
152 if (!thePrsObj->HasOwnPresentations())
153 {
154 return;
155 }
156
157 Presentation (thePrsObj, theMode)->SetVisible (theValue);
eb4320f2 158}
7fd59977 159
679ecdee 160// =======================================================================
161// function : Highlight
162// purpose :
163// =======================================================================
164void PrsMgr_PresentationManager::Highlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
165 const Standard_Integer theMode)
7fd59977 166{
0717ddc1 167 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
168 {
169 Highlight (anIter.Value(), theMode);
170 }
171 if (!thePrsObj->HasOwnPresentations())
172 {
173 return;
174 }
175
a1954302 176 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
679ecdee 177 if (aPrs->MustBeUpdated())
178 {
179 Update (thePrsObj, theMode);
7fd59977 180 }
7fd59977 181
679ecdee 182 if (myImmediateModeOn > 0)
183 {
184 Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
a1954302 185 aShadow->Highlight (Aspect_TOHM_COLOR, mySelectionColor);
679ecdee 186 AddToImmediateList (aShadow);
187 }
188 else
189 {
a1954302 190 aPrs->Highlight (Aspect_TOHM_COLOR, mySelectionColor);
679ecdee 191 }
7fd59977 192}
193
679ecdee 194// =======================================================================
195// function : Unhighlight
196// purpose :
197// =======================================================================
198void PrsMgr_PresentationManager::Unhighlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
199 const Standard_Integer theMode)
7fd59977 200{
0717ddc1 201 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
202 {
203 Unhighlight (anIter.Value(), theMode);
204 }
205
a1954302 206 const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
207 if (!aPrs.IsNull())
679ecdee 208 {
a1954302 209 aPrs->Unhighlight();
7fd59977 210 }
211}
212
679ecdee 213// =======================================================================
214// function : SetDisplayPriority
215// purpose :
216// =======================================================================
217void PrsMgr_PresentationManager::SetDisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
218 const Standard_Integer theMode,
219 const Standard_Integer theNewPrior) const
220{
0717ddc1 221 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
222 {
223 SetDisplayPriority (anIter.Value(), theMode, theNewPrior);
224 }
225
a1954302 226 const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
227 if (!aPrs.IsNull())
679ecdee 228 {
a1954302 229 aPrs->SetDisplayPriority (theNewPrior);
679ecdee 230 }
231}
7fd59977 232
679ecdee 233// =======================================================================
234// function : DisplayPriority
235// purpose :
236// =======================================================================
237Standard_Integer PrsMgr_PresentationManager::DisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
238 const Standard_Integer theMode) const
7fd59977 239{
0717ddc1 240 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
241 {
242 Standard_Integer aPriority = DisplayPriority (anIter.Value(), theMode);
243 if (aPriority != 0)
244 {
245 return aPriority;
246 }
247 }
248
a1954302 249 const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
250 return !aPrs.IsNull()
251 ? aPrs->DisplayPriority()
252 : 0;
7fd59977 253}
254
679ecdee 255// =======================================================================
256// function : IsDisplayed
257// purpose :
258// =======================================================================
259Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (const Handle(PrsMgr_PresentableObject)& thePrsObj,
260 const Standard_Integer theMode) const
7fd59977 261{
0717ddc1 262 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
263 {
264 if (IsDisplayed (anIter.Value(), theMode))
265 {
266 return Standard_True;
267 }
268 }
269
a1954302 270 const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
271 return !aPrs.IsNull()
272 && aPrs->IsDisplayed();
7fd59977 273}
274
679ecdee 275// =======================================================================
276// function : IsHighlighted
277// purpose :
278// =======================================================================
279Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (const Handle(PrsMgr_PresentableObject)& thePrsObj,
280 const Standard_Integer theMode) const
281{
0717ddc1 282 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
283 {
284 if (IsHighlighted (anIter.Value(), theMode))
285 {
286 return Standard_True;
287 }
288 }
289
a1954302 290 const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
291 return !aPrs.IsNull()
292 && aPrs->IsHighlighted();
679ecdee 293}
7fd59977 294
679ecdee 295// =======================================================================
296// function : Update
297// purpose :
298// =======================================================================
299void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& thePrsObj,
300 const Standard_Integer theMode) const
301{
0717ddc1 302 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
303 {
304 Update (anIter.Value(), theMode);
305 }
7fd59977 306
679ecdee 307 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
308 if (!aPrs.IsNull())
309 {
310 aPrs->Clear();
311 thePrsObj->Fill (this, aPrs, theMode);
312 aPrs->SetUpdateStatus (Standard_False);
313 }
314}
7fd59977 315
679ecdee 316// =======================================================================
317// function : BeginImmediateDraw
318// purpose :
319// =======================================================================
320void PrsMgr_PresentationManager::BeginImmediateDraw()
321{
322 if (++myImmediateModeOn > 1)
323 {
324 return;
7fd59977 325 }
679ecdee 326
327 ClearImmediateDraw();
7fd59977 328}
679ecdee 329
330// =======================================================================
331// function : ClearImmediateDraw
332// purpose :
333// =======================================================================
334void PrsMgr_PresentationManager::ClearImmediateDraw()
335{
c3282ec1 336 for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
679ecdee 337 {
c3282ec1 338 anIter.Value()->Erase();
679ecdee 339 }
340
c3282ec1 341 for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next())
679ecdee 342 {
c3282ec1 343 anIter.Value()->Erase();
679ecdee 344 }
345
7fd59977 346 myImmediateList.Clear();
c3282ec1 347 myViewDependentImmediateList.Clear();
348}
349
350// =======================================================================
351// function : displayImmediate
352// purpose : Handles the structures from myImmediateList and its visibility
353// in all views of the viewer given by setting proper affinity
354// =======================================================================
355void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& theViewer)
356{
357 for (theViewer->InitActiveViews(); theViewer->MoreActiveViews(); theViewer->NextActiveViews())
358 {
c357e426 359 const Handle(Graphic3d_CView)& aView = theViewer->ActiveView()->View();
c3282ec1 360 for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
361 {
362 const Handle(Prs3d_Presentation)& aPrs = anIter.Value();
363 if (aPrs.IsNull())
364 continue;
365
aa00364d 366 Handle(Graphic3d_Structure) aViewDepPrs;
c3282ec1 367 Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs);
368 if (!aShadowPrs.IsNull() && aView->IsComputed (aShadowPrs->ParentId(), aViewDepPrs))
369 {
370 aShadowPrs.Nullify();
aa00364d 371 aShadowPrs = new Prs3d_PresentationShadow (myStructureManager,
372 Handle(Prs3d_Presentation)::DownCast (aViewDepPrs));
c3282ec1 373 aShadowPrs->SetZLayer (aViewDepPrs->CStructure()->ZLayer());
3202bf1e 374 aShadowPrs->SetClipPlanes (aViewDepPrs->ClipPlanes());
c3282ec1 375 aShadowPrs->CStructure()->IsForHighlight = 1;
376 aShadowPrs->Highlight (Aspect_TOHM_COLOR, aPrs->HighlightColor());
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();
474 for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
475 {
476 const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter);
477 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager();
478 if (theMode == aModedPrs.Mode()
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();
679ecdee 497 for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
498 {
499 const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter);
500 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager();
501 if (theMode == aModedPrs.Mode()
502 && this == aPrsMgr)
503 {
504 return aModedPrs.Presentation();
505 }
506 }
7fd59977 507
a1954302 508 if (!theToCreate)
509 {
510 return Handle(PrsMgr_Presentation)();
511 }
7fd59977 512
af324faa 513 Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj);
a1954302 514 aPrs->SetZLayer (thePrsObj->ZLayer());
a272ed94 515 aPrs->Presentation()->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj);
679ecdee 516 thePrsObj->Presentations().Append (PrsMgr_ModedPresentation (aPrs, theMode));
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();
532 for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
533 {
a1954302 534 const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter);
535 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager();
536 if (theMode == aPrsList (aPrsIter).Mode()
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,
551 const Standard_Integer theLayerId)
552{
0717ddc1 553 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
554 {
555 SetZLayer (anIter.Value(), theLayerId);
556 }
557 if (!thePrsObj->HasOwnPresentations())
558 {
559 return;
560 }
a1954302 561
562 thePrsObj->SetZLayer (theLayerId);
679ecdee 563}
7fd59977 564
679ecdee 565// =======================================================================
566// function : GetZLayer
567// purpose :
568// =======================================================================
569Standard_Integer PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const
570{
a1954302 571 return thePrsObj->ZLayer();
679ecdee 572}
7fd59977 573
679ecdee 574// =======================================================================
575// function : Connect
576// purpose :
577// =======================================================================
578void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)& thePrsObject,
579 const Handle(PrsMgr_PresentableObject)& theOtherObject,
580 const Standard_Integer theMode,
581 const Standard_Integer theOtherMode)
582{
a1954302 583 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObject, theMode, Standard_True);
584 Handle(PrsMgr_Presentation) aPrsOther = Presentation (theOtherObject, theOtherMode, Standard_True);
585 aPrs->Connect (aPrsOther);
7fd59977 586}
587
679ecdee 588// =======================================================================
589// function : Transform
590// purpose :
591// =======================================================================
592void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObject)& thePrsObj,
593 const Handle(Geom_Transformation)& theTransformation,
594 const Standard_Integer theMode)
595{
1f7f5a90 596 Presentation (thePrsObj, theMode)->SetTransformation (theTransformation);
679ecdee 597}
7fd59977 598
7fd59977 599
679ecdee 600// =======================================================================
601// function : Color
602// purpose :
603// =======================================================================
604void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)& thePrsObj,
605 const Quantity_NameOfColor theColor,
a272ed94 606 const Standard_Integer theMode,
c3282ec1 607 const Handle(PrsMgr_PresentableObject)& theSelObj,
608 const Standard_Integer theImmediateStructLayerId)
7fd59977 609{
0717ddc1 610 for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
611 {
c3282ec1 612 Color (anIter.Value(), theColor, theMode, NULL, theImmediateStructLayerId);
0717ddc1 613 }
614 if (!thePrsObj->HasOwnPresentations())
615 {
616 return;
617 }
618
a272ed94 619 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True, theSelObj);
679ecdee 620 if (aPrs->MustBeUpdated())
621 {
622 Update (thePrsObj, theMode);
623 }
59f45b7c 624
679ecdee 625 if (myImmediateModeOn > 0)
626 {
627 Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
c3282ec1 628 aShadow->SetZLayer (theImmediateStructLayerId);
3202bf1e 629 aShadow->SetClipPlanes (aPrs->Presentation()->ClipPlanes());
c3282ec1 630 aShadow->CStructure()->IsForHighlight = 1;
a1954302 631 aShadow->Highlight (Aspect_TOHM_COLOR, theColor);
679ecdee 632 AddToImmediateList (aShadow);
633 }
634 else
635 {
a1954302 636 aPrs->Highlight (Aspect_TOHM_COLOR, theColor);
679ecdee 637 }
638}
639
640// =======================================================================
641// function : BoundBox
642// purpose :
643// =======================================================================
a1954302 644void PrsMgr_PresentationManager::BoundBox (const Handle(PrsMgr_PresentableObject)& thePrsObj,
679ecdee 645 const Standard_Integer theMode)
59f45b7c 646{
a1954302 647 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
648 if (aPrs->MustBeUpdated())
679ecdee 649 {
a1954302 650 Update (thePrsObj, theMode);
59f45b7c 651 }
a1954302 652 aPrs->Highlight (Aspect_TOHM_BOUNDBOX, mySelectionColor);
59f45b7c 653}
654
5396886c 655namespace
656{
657 // =======================================================================
658 // function : updatePrsTransformation
1f7f5a90 659 // purpose : Internal function that scans thePrsList for shadow presentations
5396886c 660 // and applies transformation theTrsf to them in case if parent ID
661 // of shadow presentation is equal to theRefId
662 // =======================================================================
663 void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList,
664 const Standard_Integer theRefId,
1f7f5a90 665 const Handle(Geom_Transformation)& theTrsf)
5396886c 666 {
667 for (PrsMgr_ListOfPresentations::Iterator anIter (thePrsList); anIter.More(); anIter.Next())
668 {
669 const Handle(Prs3d_Presentation)& aPrs = anIter.Value();
670 if (aPrs.IsNull())
671 continue;
672
673 Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs);
674 if (aShadowPrs.IsNull() || aShadowPrs->ParentId() != theRefId)
675 continue;
676
1f7f5a90 677 aShadowPrs->CStructure()->SetTransformation (theTrsf);
5396886c 678 }
679 }
680}
681
682// =======================================================================
683// function : UpdateHighlightTrsf
684// purpose :
685// =======================================================================
686void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
687 const Handle(PrsMgr_PresentableObject)& theObj,
688 const Standard_Integer theMode,
689 const Handle(PrsMgr_PresentableObject)& theSelObj)
690{
691 if (theObj.IsNull())
692 return;
693
694 const Handle(Prs3d_Presentation)& aBasePrs = Presentation (theObj, theMode, Standard_False)->Presentation();
695 const Handle(Prs3d_Presentation)& aParentPrs = theSelObj.IsNull() ?
696 aBasePrs : Presentation (theSelObj, theMode, Standard_False)->Presentation();
697 const Standard_Integer aParentId = aParentPrs->CStructure()->Id;
698
1f7f5a90 699 updatePrsTransformation (myImmediateList, aParentId, aBasePrs->CStructure()->Transformation());
5396886c 700
701 if (!myViewDependentImmediateList.IsEmpty())
702 {
703 for (theViewer->InitActiveViews(); theViewer->MoreActiveViews(); theViewer->NextActiveViews())
704 {
705 const Handle(Graphic3d_CView)& aView = theViewer->ActiveView()->View();
706 Handle(Graphic3d_Structure) aViewDepParentPrs;
707 if (aView->IsComputed (aParentId, aViewDepParentPrs))
708 {
709 updatePrsTransformation (myViewDependentImmediateList,
710 aViewDepParentPrs->CStructure()->Id,
1f7f5a90 711 aBasePrs->CStructure()->Transformation());
5396886c 712 }
713 }
714 }
715}