0032056: Coding Rules - remove package MMgt and other types deprecated since OCCT...
[occt.git] / src / PrsMgr / PrsMgr_PresentableObject.cxx
1 // Created on: 1997-12-16
2 // Created by: Jean Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <PrsMgr_PresentableObject.hxx>
18
19 #include <Graphic3d_AspectFillArea3d.hxx>
20 #include <Prs3d_Drawer.hxx>
21 #include <Prs3d_LineAspect.hxx>
22 #include <Prs3d_PointAspect.hxx>
23 #include <Prs3d_Presentation.hxx>
24 #include <Prs3d_ShadingAspect.hxx>
25 #include <PrsMgr_Presentation.hxx>
26 #include <PrsMgr_PresentationManager.hxx>
27 #include <Standard_NotImplemented.hxx>
28 #include <TColStd_MapOfInteger.hxx>
29
30 IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentableObject, Standard_Transient)
31
32 //=======================================================================
33 //function : getIdentityTrsf
34 //purpose  :
35 //=======================================================================
36 const gp_Trsf& PrsMgr_PresentableObject::getIdentityTrsf()
37 {
38   static const gp_Trsf THE_IDENTITY_TRSF;
39   return THE_IDENTITY_TRSF;
40 }
41
42 //=======================================================================
43 //function : PrsMgr_PresentableObject
44 //purpose  :
45 //=======================================================================
46 PrsMgr_PresentableObject::PrsMgr_PresentableObject (const PrsMgr_TypeOfPresentation3d theType)
47 : myParent (NULL),
48   myDrawer (new Prs3d_Drawer()),
49   myTypeOfPresentation3d (theType),
50   //
51   myCurrentFacingModel (Aspect_TOFM_BOTH_SIDE),
52   myOwnWidth (0.0f),
53   hasOwnColor (Standard_False),
54   hasOwnMaterial (Standard_False),
55   //
56   myInfiniteState (Standard_False),
57   myIsMutable (Standard_False),
58   myHasOwnPresentations (Standard_True),
59   myToPropagateVisualState (Standard_True)
60 {
61   myDrawer->SetDisplayMode (-1);
62 }
63
64 //=======================================================================
65 //function : ~PrsMgr_PresentableObject
66 //purpose  : destructor
67 //=======================================================================
68 PrsMgr_PresentableObject::~PrsMgr_PresentableObject()
69 {
70   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
71   {
72     // should never happen - assertion can be used
73     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value();
74     aPrs3d->Erase();
75     aPrs3d->myPresentableObject = NULL;
76   }
77
78   for (PrsMgr_ListOfPresentableObjectsIter anIter (myChildren); anIter.More(); anIter.Next())
79   {
80     anIter.Value()->SetCombinedParentTransform (Handle(TopLoc_Datum3D)());
81     anIter.Value()->myParent = NULL;
82   }
83 }
84
85 //=======================================================================
86 //function : Fill
87 //purpose  : 
88 //=======================================================================
89 void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
90                                      const Handle(PrsMgr_Presentation)&        thePrs,
91                                      const Standard_Integer                    theMode)
92 {
93   const Handle(Prs3d_Presentation)& aStruct3d = thePrs;
94   Compute (thePrsMgr, aStruct3d, theMode);
95   aStruct3d->SetTransformation (myTransformation);
96   aStruct3d->SetClipPlanes (myClipPlanes);
97   aStruct3d->SetTransformPersistence (TransformPersistence());
98 }
99
100 //=======================================================================
101 //function : computeHLR
102 //purpose  :
103 //=======================================================================
104 void PrsMgr_PresentableObject::computeHLR (const Handle(Graphic3d_Camera)& ,
105                                            const Handle(TopLoc_Datum3D)& ,
106                                            const Handle(Prs3d_Presentation)& )
107 {
108   throw Standard_NotImplemented("cannot compute under a specific projector");
109 }
110
111 //=======================================================================
112 //function : ToBeUpdated
113 //purpose  :
114 //=======================================================================
115 Standard_Boolean PrsMgr_PresentableObject::ToBeUpdated (Standard_Boolean theToIncludeHidden) const
116 {
117   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
118   {
119     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
120     if (aModedPrs->MustBeUpdated())
121     {
122       if (theToIncludeHidden)
123       {
124         return Standard_True;
125       }
126
127       Handle(PrsMgr_PresentationManager) aPrsMgr = aModedPrs->PresentationManager();
128       if (aPrsMgr->IsDisplayed  (this, aModedPrs->Mode())
129        || aPrsMgr->IsHighlighted(this, aModedPrs->Mode()))
130       {
131         return Standard_True;
132       }
133     }
134   }
135   return Standard_False;
136 }
137
138 //=======================================================================
139 //function : UpdatePresentations
140 //purpose  :
141 //=======================================================================
142 Standard_Boolean PrsMgr_PresentableObject::UpdatePresentations (Standard_Boolean theToIncludeHidden)
143 {
144   Standard_Boolean hasUpdates = Standard_False;
145   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
146   {
147     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
148     if (aModedPrs->MustBeUpdated())
149     {
150       Handle(PrsMgr_PresentationManager) aPrsMgr = aModedPrs->PresentationManager();
151       if (theToIncludeHidden
152        || aPrsMgr->IsDisplayed  (this, aModedPrs->Mode())
153        || aPrsMgr->IsHighlighted(this, aModedPrs->Mode()))
154       {
155         hasUpdates = Standard_True;
156         aPrsMgr->Update (this, aModedPrs->Mode());
157       }
158     }
159   }
160   return hasUpdates;
161 }
162
163 //=======================================================================
164 //function : Update
165 //purpose  :
166 //=======================================================================
167 void PrsMgr_PresentableObject::Update (Standard_Integer theMode, Standard_Boolean theToClearOther)
168 {
169   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More();)
170   {
171     if (aPrsIter.Value()->Mode() == theMode)
172     {
173       Handle(PrsMgr_PresentationManager) aPrsMgr = aPrsIter.Value()->PresentationManager();
174       if (aPrsMgr->IsDisplayed  (this, theMode)
175        || aPrsMgr->IsHighlighted(this, theMode))
176       {
177         aPrsMgr->Update (this, theMode);
178         aPrsIter.Value()->SetUpdateStatus (Standard_False);
179       }
180       else
181       {
182         SetToUpdate (aPrsIter.Value()->Mode());
183       }
184     }
185     else if (theToClearOther)
186     {
187       myPresentations.Remove (aPrsIter);
188       continue;
189     }
190     aPrsIter.Next();
191   }
192 }
193
194 //=======================================================================
195 //function : SetToUpdate
196 //purpose  : 
197 //=======================================================================
198 void PrsMgr_PresentableObject::SetToUpdate (Standard_Integer theMode)
199 {
200   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
201   {
202     if (theMode == -1
203      || aPrsIter.Value()->Mode() == theMode)
204     {
205       aPrsIter.ChangeValue()->SetUpdateStatus (Standard_True);
206     }
207   }
208 }
209
210 //=======================================================================
211 //function : ToBeUpdated
212 //purpose  : gets the list of modes to be updated
213 //=======================================================================
214 void PrsMgr_PresentableObject::ToBeUpdated (TColStd_ListOfInteger& theOutList) const
215 {
216   theOutList.Clear();
217   TColStd_MapOfInteger MI(myPresentations.Length()); 
218   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
219   {
220     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
221     if (aModedPrs->MustBeUpdated()
222      && MI.Add (aModedPrs->Mode()))
223     {
224       theOutList.Append (aModedPrs->Mode());
225     }
226   }
227 }
228
229 //=======================================================================
230 //function : SetTypeOfPresentation
231 //purpose  :
232 //=======================================================================
233 void PrsMgr_PresentableObject::SetTypeOfPresentation (const PrsMgr_TypeOfPresentation3d theType)
234 {
235   myTypeOfPresentation3d = theType;
236   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
237   {
238     const Handle(PrsMgr_Presentation)& aPrs  = aPrsIter.Value();
239     aPrs->SetVisual (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant
240                    ? Graphic3d_TOS_COMPUTED
241                    : Graphic3d_TOS_ALL);
242   }
243 }
244
245 //=======================================================================
246 //function : setLocalTransformation
247 //purpose  :
248 //=======================================================================
249 void PrsMgr_PresentableObject::setLocalTransformation (const Handle(TopLoc_Datum3D)& theTransformation)
250 {
251   myLocalTransformation = theTransformation;
252   UpdateTransformation();
253 }
254
255 //=======================================================================
256 //function : ResetTransformation
257 //purpose  : 
258 //=======================================================================
259 void PrsMgr_PresentableObject::ResetTransformation() 
260 {
261   setLocalTransformation (Handle(TopLoc_Datum3D)());
262 }
263
264 //=======================================================================
265 //function : SetCombinedParentTransform
266 //purpose  : 
267 //=======================================================================
268 void PrsMgr_PresentableObject::SetCombinedParentTransform (const Handle(TopLoc_Datum3D)& theTrsf)
269 {
270   myCombinedParentTransform = theTrsf;
271   UpdateTransformation();
272 }
273
274 //=======================================================================
275 //function : UpdateTransformation
276 //purpose  :
277 //=======================================================================
278 void PrsMgr_PresentableObject::UpdateTransformation()
279 {
280   myTransformation.Nullify();
281   myInvTransformation = gp_Trsf();
282   if (!myCombinedParentTransform.IsNull() && myCombinedParentTransform->Form() != gp_Identity)
283   {
284     if (!myLocalTransformation.IsNull() && myLocalTransformation->Form() != gp_Identity)
285     {
286       const gp_Trsf aTrsf = myCombinedParentTransform->Trsf() * myLocalTransformation->Trsf();
287       myTransformation    = new TopLoc_Datum3D (aTrsf);
288       myInvTransformation = aTrsf.Inverted();
289     }
290     else
291     {
292       myTransformation    = myCombinedParentTransform;
293       myInvTransformation = myCombinedParentTransform->Trsf().Inverted();
294     }
295   }
296   else if (!myLocalTransformation.IsNull() && myLocalTransformation->Form() != gp_Identity)
297   {
298     myTransformation    = myLocalTransformation;
299     myInvTransformation = myLocalTransformation->Trsf().Inverted();
300   }
301
302   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
303   {
304     aPrsIter.ChangeValue()->SetTransformation (myTransformation);
305   }
306
307   for (PrsMgr_ListOfPresentableObjectsIter aChildIter (myChildren); aChildIter.More(); aChildIter.Next())
308   {
309     aChildIter.Value()->SetCombinedParentTransform (myTransformation);
310   }
311 }
312
313 //=======================================================================
314 //function : recomputeComputed
315 //purpose  :
316 //=======================================================================
317 void PrsMgr_PresentableObject::recomputeComputed() const
318 {
319   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
320   {
321     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value();
322     aPrs3d->ReCompute();
323   }
324 }
325
326 //=======================================================================
327 //function : SetTransformPersistence
328 //purpose  :
329 //=======================================================================
330 void PrsMgr_PresentableObject::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
331 {
332   myTransformPersistence = theTrsfPers;
333   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
334   {
335     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value();
336     aPrs3d->SetTransformPersistence (myTransformPersistence);
337     aPrs3d->ReCompute();
338   }
339 }
340
341 //=======================================================================
342 //function : AddChild
343 //purpose  : 
344 //=======================================================================
345 void PrsMgr_PresentableObject::AddChild (const Handle(PrsMgr_PresentableObject)& theObject)
346 {
347   Handle(PrsMgr_PresentableObject) aHandleGuard = theObject;
348   if (theObject->myParent != NULL)
349   {
350     theObject->myParent->RemoveChild (aHandleGuard);
351   }
352
353   myChildren.Append (theObject);  
354   theObject->myParent = this;
355   theObject->SetCombinedParentTransform (myTransformation);
356 }
357
358 //=======================================================================
359 //function : AddChildWithCurrentTransformation
360 //purpose  : 
361 //=======================================================================
362 void PrsMgr_PresentableObject::AddChildWithCurrentTransformation(const Handle(PrsMgr_PresentableObject)& theObject)
363 {
364   gp_Trsf aTrsf = Transformation().Inverted() * theObject->Transformation();
365   theObject->SetLocalTransformation(aTrsf);
366   AddChild(theObject);
367 }
368
369 //=======================================================================
370 //function : RemoveChild
371 //purpose  : 
372 //=======================================================================
373 void PrsMgr_PresentableObject::RemoveChild (const Handle(PrsMgr_PresentableObject)& theObject)
374 {
375   PrsMgr_ListOfPresentableObjectsIter anIter (myChildren);
376   for (; anIter.More(); anIter.Next())
377   {
378     if (anIter.Value() == theObject)
379     {
380       theObject->myParent = NULL;
381       theObject->SetCombinedParentTransform (Handle(TopLoc_Datum3D)());
382       myChildren.Remove (anIter);
383       break;
384     }
385   }
386 }
387
388 //=======================================================================
389 //function : RemoveChildWithRestoreTransformation
390 //purpose  : 
391 //=======================================================================
392 void PrsMgr_PresentableObject::RemoveChildWithRestoreTransformation(const Handle(PrsMgr_PresentableObject)& theObject)
393 {
394   gp_Trsf aTrsf = theObject->Transformation();
395   RemoveChild(theObject);
396   theObject->SetLocalTransformation(aTrsf);
397 }
398
399 //=======================================================================
400 //function : SetZLayer
401 //purpose  :
402 //=======================================================================
403 void PrsMgr_PresentableObject::SetZLayer (const Graphic3d_ZLayerId theLayerId)
404 {
405   if (myDrawer->ZLayer() == theLayerId)
406   {
407     return;
408   }
409
410   myDrawer->SetZLayer (theLayerId);
411   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
412   {
413     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
414     aModedPrs->SetZLayer (theLayerId);
415   }
416 }
417
418 // =======================================================================
419 // function : AddClipPlane
420 // purpose  :
421 // =======================================================================
422 void PrsMgr_PresentableObject::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
423 {
424   // add to collection and process changes
425   if (myClipPlanes.IsNull())
426   {
427     myClipPlanes = new Graphic3d_SequenceOfHClipPlane();
428   }
429
430   myClipPlanes->Append (thePlane);
431   UpdateClipping();
432 }
433
434 // =======================================================================
435 // function : RemoveClipPlane
436 // purpose  :
437 // =======================================================================
438 void PrsMgr_PresentableObject::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
439 {
440   if (myClipPlanes.IsNull())
441   {
442     return;
443   }
444
445   // remove from collection and process changes
446   for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*myClipPlanes); aPlaneIt.More(); aPlaneIt.Next())
447   {
448     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
449     if (aPlane != thePlane)
450       continue;
451
452     myClipPlanes->Remove (aPlaneIt);
453     UpdateClipping();
454     return;
455   }
456 }
457
458 // =======================================================================
459 // function : SetClipPlanes
460 // purpose  :
461 // =======================================================================
462 void PrsMgr_PresentableObject::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
463 {
464   // change collection and process changes
465   myClipPlanes = thePlanes;
466   UpdateClipping();
467 }
468
469 // =======================================================================
470 // function : UpdateClipping
471 // purpose  :
472 // =======================================================================
473 void PrsMgr_PresentableObject::UpdateClipping()
474 {
475   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
476   {
477     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
478     aModedPrs->SetClipPlanes (myClipPlanes);
479   }
480 }
481
482 //=======================================================================
483 //function : SetInfiniteState
484 //purpose  :
485 //=======================================================================
486 void PrsMgr_PresentableObject::SetInfiniteState (const Standard_Boolean theFlag)
487 {
488   if (myInfiniteState == theFlag)
489   {
490     return;
491   }
492
493   myInfiniteState = theFlag;
494   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
495   {
496     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
497     aModedPrs->SetInfiniteState (theFlag);
498   }
499 }
500
501 // =======================================================================
502 // function : SetMutable
503 // purpose  :
504 // =======================================================================
505 void PrsMgr_PresentableObject::SetMutable (const Standard_Boolean theIsMutable)
506 {
507   if (myIsMutable == theIsMutable)
508   {
509     return;
510   }
511
512   myIsMutable = theIsMutable;
513   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
514   {
515     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
516     aModedPrs->SetMutable (theIsMutable);
517   }
518 }
519
520 // =======================================================================
521 // function : UnsetAttributes
522 // purpose  :
523 // =======================================================================
524 void PrsMgr_PresentableObject::UnsetAttributes()
525 {
526   Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer();
527   if (myDrawer->HasLink())
528   {
529     aDrawer->Link(myDrawer->Link());
530   }
531   myDrawer = aDrawer;
532
533   hasOwnColor    = Standard_False;
534   hasOwnMaterial = Standard_False;
535   myOwnWidth     = 0.0f;
536   myDrawer->SetTransparency (0.0f);
537 }
538
539 //=======================================================================
540 //function : SetHilightMode
541 //purpose  :
542 //=======================================================================
543 void PrsMgr_PresentableObject::SetHilightMode (const Standard_Integer theMode)
544 {
545   if (myHilightDrawer.IsNull())
546   {
547     myHilightDrawer = new Prs3d_Drawer();
548     myHilightDrawer->Link (myDrawer);
549     myHilightDrawer->SetAutoTriangulation (Standard_False);
550     myHilightDrawer->SetColor (Quantity_NOC_GRAY80);
551     myHilightDrawer->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
552   }
553   if (myDynHilightDrawer.IsNull())
554   {
555     myDynHilightDrawer = new Prs3d_Drawer();
556     myDynHilightDrawer->Link (myDrawer);
557     myDynHilightDrawer->SetColor (Quantity_NOC_CYAN1);
558     myDynHilightDrawer->SetAutoTriangulation (Standard_False);
559     myDynHilightDrawer->SetZLayer(Graphic3d_ZLayerId_Top);
560   }
561   myHilightDrawer   ->SetDisplayMode (theMode);
562   myDynHilightDrawer->SetDisplayMode (theMode);
563 }
564
565 //=======================================================================
566 //function : SynchronizeAspects
567 //purpose  :
568 //=======================================================================
569 void PrsMgr_PresentableObject::SynchronizeAspects()
570 {
571   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
572   {
573     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
574     for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Groups()); aGroupIter.More(); aGroupIter.Next())
575     {
576       if (!aGroupIter.Value().IsNull())
577       {
578         aGroupIter.ChangeValue()->SynchronizeAspects();
579       }
580     }
581   }
582 }
583
584 //=======================================================================
585 //function : replaceAspects
586 //purpose  :
587 //=======================================================================
588 void PrsMgr_PresentableObject::replaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap)
589 {
590   if (theMap.IsEmpty())
591   {
592     return;
593   }
594
595   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
596   {
597     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
598     for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Groups()); aGroupIter.More(); aGroupIter.Next())
599     {
600       if (!aGroupIter.Value().IsNull())
601       {
602         aGroupIter.ChangeValue()->ReplaceAspects (theMap);
603       }
604     }
605   }
606 }
607
608 //=======================================================================
609 //function : BoundingBox
610 //purpose  :
611 //=======================================================================
612 void PrsMgr_PresentableObject::BoundingBox (Bnd_Box& theBndBox)
613 {
614   if (myDrawer->DisplayMode() == -1)
615   {
616     if (!myPresentations.IsEmpty())
617     {
618       const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations.First();
619       const Graphic3d_BndBox3d& aBndBox = aPrs3d->CStructure()->BoundingBox();
620       if (aBndBox.IsValid())
621       {
622         theBndBox.Update (aBndBox.CornerMin().x(), aBndBox.CornerMin().y(), aBndBox.CornerMin().z(),
623                           aBndBox.CornerMax().x(), aBndBox.CornerMax().y(), aBndBox.CornerMax().z());
624       }
625       else
626       {
627         theBndBox.SetVoid();
628       }
629       return;
630     }
631
632     for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (myChildren); aPrsIter.More(); aPrsIter.Next())
633     {
634       if (const Handle(PrsMgr_PresentableObject)& aChild = aPrsIter.Value())
635       {
636         Bnd_Box aBox;
637         aChild->BoundingBox (aBox);
638         theBndBox.Add (aBox);
639       }
640     }
641     return;
642   }
643
644   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
645   {
646     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
647     if (aPrs3d->Mode() == myDrawer->DisplayMode())
648     {
649       const Graphic3d_BndBox3d& aBndBox = aPrs3d->CStructure()->BoundingBox();
650       if (aBndBox.IsValid())
651       {
652         theBndBox.Update (aBndBox.CornerMin().x(), aBndBox.CornerMin().y(), aBndBox.CornerMin().z(),
653                           aBndBox.CornerMax().x(), aBndBox.CornerMax().y(), aBndBox.CornerMax().z());
654       }
655       else
656       {
657         theBndBox.SetVoid();
658       }
659       return;
660     }
661   }
662 }
663
664 //=======================================================================
665 //function : Material
666 //purpose  :
667 //=======================================================================
668 Graphic3d_NameOfMaterial PrsMgr_PresentableObject::Material() const
669 {
670   return myDrawer->ShadingAspect()->Material().Name();
671 }
672
673 //=======================================================================
674 //function : SetMaterial
675 //purpose  :
676 //=======================================================================
677 void PrsMgr_PresentableObject::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
678 {
679   myDrawer->SetupOwnShadingAspect();
680   myDrawer->ShadingAspect()->SetMaterial (theMaterial);
681   hasOwnMaterial = Standard_True;
682 }
683
684 //=======================================================================
685 //function : UnsetMaterial
686 //purpose  :
687 //=======================================================================
688 void PrsMgr_PresentableObject::UnsetMaterial()
689 {
690   if (!HasMaterial())
691   {
692     return;
693   }
694
695   if (HasColor() || IsTransparent())
696   {
697     if (myDrawer->HasLink())
698     {
699       myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Aspect()->BackMaterial());
700     }
701
702     if (HasColor())
703     {
704       SetColor (myDrawer->Color());
705     }
706
707     if (IsTransparent())
708     {
709       SetTransparency (myDrawer->Transparency());
710     }
711   }
712   else
713   {
714     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
715   }
716
717   hasOwnMaterial = Standard_False;
718 }
719
720 //=======================================================================
721 //function : SetTransparency
722 //purpose  :
723 //=======================================================================
724 void PrsMgr_PresentableObject::SetTransparency (const Standard_Real theValue)
725 {
726   myDrawer->SetupOwnShadingAspect();
727   myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (Standard_ShortReal(theValue));
728   myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (Standard_ShortReal(theValue));
729   myDrawer->SetTransparency (Standard_ShortReal(theValue));
730 }
731
732 //=======================================================================
733 //function : UnsetTransparency
734 //purpose  :
735 //=======================================================================
736 void PrsMgr_PresentableObject::UnsetTransparency()
737 {
738   if (HasColor() || HasMaterial())
739   {
740     myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (0.0f);
741     myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (0.0f);
742   }
743   else
744   {
745     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
746   }
747   myDrawer->SetTransparency (0.0f);
748 }
749
750 //=======================================================================
751 //function : SetPolygonOffsets
752 //purpose  :
753 //=======================================================================
754 void PrsMgr_PresentableObject::SetPolygonOffsets (const Standard_Integer   theMode,
755                                                   const Standard_ShortReal theFactor,
756                                                   const Standard_ShortReal theUnits)
757 {
758   myDrawer->SetupOwnShadingAspect();
759   myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets (theMode, theFactor, theUnits);
760   SynchronizeAspects();
761 }
762
763 //=======================================================================
764 //function : HasPolygonOffsets
765 //purpose  :
766 //=======================================================================
767 Standard_Boolean PrsMgr_PresentableObject::HasPolygonOffsets() const
768 {
769   return !(myDrawer->HasOwnShadingAspect()
770         || (myDrawer->HasLink()
771          && myDrawer->ShadingAspect() == myDrawer->Link()->ShadingAspect()));
772 }
773
774 //=======================================================================
775 //function : PolygonOffsets
776 //purpose  :
777 //=======================================================================
778 void PrsMgr_PresentableObject::PolygonOffsets (Standard_Integer&   theMode,
779                                                Standard_ShortReal& theFactor,
780                                                Standard_ShortReal& theUnits) const
781 {
782   if (HasPolygonOffsets())
783   {
784     myDrawer->ShadingAspect()->Aspect()->PolygonOffsets (theMode, theFactor, theUnits);
785   }
786 }
787
788 // =======================================================================
789 // function : DumpJson
790 // purpose  :
791 // =======================================================================
792 void PrsMgr_PresentableObject::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
793 {
794   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
795
796   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myParent)
797
798   for (PrsMgr_Presentations::Iterator anIterator (myPresentations); anIterator.More(); anIterator.Next())
799   {
800     const Handle(PrsMgr_Presentation)& aPresentation = anIterator.Value();
801     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aPresentation.get())
802   }
803
804   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myClipPlanes.get())
805
806   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDrawer.get())
807   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myHilightDrawer.get())
808   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDynHilightDrawer.get())
809
810   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myTransformPersistence.get())
811
812   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myLocalTransformation.get())
813   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myTransformation.get())
814   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myCombinedParentTransform.get())
815
816   for (PrsMgr_ListOfPresentableObjects::Iterator anIterator (myChildren); anIterator.More(); anIterator.Next())
817   {
818     const Handle(PrsMgr_PresentableObject)& aChildObject = anIterator.Value();
819     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aChildObject.get())
820   }
821
822   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myInvTransformation)
823
824   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTypeOfPresentation3d)
825   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurrentFacingModel)
826
827   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOwnWidth)
828   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, hasOwnColor)
829   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, hasOwnMaterial)
830
831   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myInfiniteState)
832   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsMutable)
833   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnPresentations)
834
835   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToPropagateVisualState)
836 }