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