0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[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 : GetTransformPersistence
343 //purpose  :
344 //=======================================================================
345 gp_Pnt PrsMgr_PresentableObject::GetTransformPersistencePoint() const
346 {
347   if (myTransformPersistence.IsNull())
348   {
349     return gp_Pnt();
350   }
351   else if (myTransformPersistence->IsZoomOrRotate())
352   {
353     return myTransformPersistence->AnchorPoint();
354   }
355   else if (!myTransformPersistence->IsTrihedronOr2d())
356   {
357     return gp_Pnt();
358   }
359
360   Standard_Real anX = 0.0;
361   if ((myTransformPersistence->Corner2d() & Aspect_TOTP_RIGHT) != 0)
362   {
363     anX = 1.0;
364   }
365   else if ((myTransformPersistence->Corner2d() & Aspect_TOTP_LEFT) != 0)
366   {
367     anX = -1.0;
368   }
369
370   Standard_Real anY = 0.0;
371   if ((myTransformPersistence->Corner2d() & Aspect_TOTP_TOP) != 0)
372   {
373     anY = 1.0;
374   }
375   else if ((myTransformPersistence->Corner2d() & Aspect_TOTP_BOTTOM) != 0)
376   {
377     anY = -1.0;
378   }
379
380   return gp_Pnt (anX, anY, myTransformPersistence->Offset2d().x());
381 }
382
383 //=======================================================================
384 //function : AddChild
385 //purpose  : 
386 //=======================================================================
387 void PrsMgr_PresentableObject::AddChild (const Handle(PrsMgr_PresentableObject)& theObject)
388 {
389   Handle(PrsMgr_PresentableObject) aHandleGuard = theObject;
390   if (theObject->myParent != NULL)
391   {
392     theObject->myParent->RemoveChild (aHandleGuard);
393   }
394
395   myChildren.Append (theObject);  
396   theObject->myParent = this;
397   theObject->SetCombinedParentTransform (myTransformation);
398 }
399
400 //=======================================================================
401 //function : AddChildWithCurrentTransformation
402 //purpose  : 
403 //=======================================================================
404 void PrsMgr_PresentableObject::AddChildWithCurrentTransformation(const Handle(PrsMgr_PresentableObject)& theObject)
405 {
406   gp_Trsf aTrsf = Transformation().Inverted() * theObject->Transformation();
407   theObject->SetLocalTransformation(aTrsf);
408   AddChild(theObject);
409 }
410
411 //=======================================================================
412 //function : RemoveChild
413 //purpose  : 
414 //=======================================================================
415 void PrsMgr_PresentableObject::RemoveChild (const Handle(PrsMgr_PresentableObject)& theObject)
416 {
417   PrsMgr_ListOfPresentableObjectsIter anIter (myChildren);
418   for (; anIter.More(); anIter.Next())
419   {
420     if (anIter.Value() == theObject)
421     {
422       theObject->myParent = NULL;
423       theObject->SetCombinedParentTransform (Handle(TopLoc_Datum3D)());
424       myChildren.Remove (anIter);
425       break;
426     }
427   }
428 }
429
430 //=======================================================================
431 //function : RemoveChildWithRestoreTransformation
432 //purpose  : 
433 //=======================================================================
434 void PrsMgr_PresentableObject::RemoveChildWithRestoreTransformation(const Handle(PrsMgr_PresentableObject)& theObject)
435 {
436   gp_Trsf aTrsf = theObject->Transformation();
437   RemoveChild(theObject);
438   theObject->SetLocalTransformation(aTrsf);
439 }
440
441 //=======================================================================
442 //function : SetZLayer
443 //purpose  :
444 //=======================================================================
445 void PrsMgr_PresentableObject::SetZLayer (const Graphic3d_ZLayerId theLayerId)
446 {
447   if (myDrawer->ZLayer() == theLayerId)
448   {
449     return;
450   }
451
452   myDrawer->SetZLayer (theLayerId);
453   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
454   {
455     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
456     aModedPrs->SetZLayer (theLayerId);
457   }
458 }
459
460 // =======================================================================
461 // function : AddClipPlane
462 // purpose  :
463 // =======================================================================
464 void PrsMgr_PresentableObject::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
465 {
466   // add to collection and process changes
467   if (myClipPlanes.IsNull())
468   {
469     myClipPlanes = new Graphic3d_SequenceOfHClipPlane();
470   }
471
472   myClipPlanes->Append (thePlane);
473   UpdateClipping();
474 }
475
476 // =======================================================================
477 // function : RemoveClipPlane
478 // purpose  :
479 // =======================================================================
480 void PrsMgr_PresentableObject::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
481 {
482   if (myClipPlanes.IsNull())
483   {
484     return;
485   }
486
487   // remove from collection and process changes
488   for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*myClipPlanes); aPlaneIt.More(); aPlaneIt.Next())
489   {
490     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
491     if (aPlane != thePlane)
492       continue;
493
494     myClipPlanes->Remove (aPlaneIt);
495     UpdateClipping();
496     return;
497   }
498 }
499
500 // =======================================================================
501 // function : SetClipPlanes
502 // purpose  :
503 // =======================================================================
504 void PrsMgr_PresentableObject::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
505 {
506   // change collection and process changes
507   myClipPlanes = thePlanes;
508   UpdateClipping();
509 }
510
511 // =======================================================================
512 // function : UpdateClipping
513 // purpose  :
514 // =======================================================================
515 void PrsMgr_PresentableObject::UpdateClipping()
516 {
517   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
518   {
519     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
520     aModedPrs->SetClipPlanes (myClipPlanes);
521   }
522 }
523
524 //=======================================================================
525 //function : SetInfiniteState
526 //purpose  :
527 //=======================================================================
528 void PrsMgr_PresentableObject::SetInfiniteState (const Standard_Boolean theFlag)
529 {
530   if (myInfiniteState == theFlag)
531   {
532     return;
533   }
534
535   myInfiniteState = theFlag;
536   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
537   {
538     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
539     aModedPrs->SetInfiniteState (theFlag);
540   }
541 }
542
543 // =======================================================================
544 // function : SetMutable
545 // purpose  :
546 // =======================================================================
547 void PrsMgr_PresentableObject::SetMutable (const Standard_Boolean theIsMutable)
548 {
549   if (myIsMutable == theIsMutable)
550   {
551     return;
552   }
553
554   myIsMutable = theIsMutable;
555   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
556   {
557     const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
558     aModedPrs->SetMutable (theIsMutable);
559   }
560 }
561
562 // =======================================================================
563 // function : UnsetAttributes
564 // purpose  :
565 // =======================================================================
566 void PrsMgr_PresentableObject::UnsetAttributes()
567 {
568   Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer();
569   if (myDrawer->HasLink())
570   {
571     aDrawer->Link(myDrawer->Link());
572   }
573   myDrawer = aDrawer;
574
575   hasOwnColor    = Standard_False;
576   hasOwnMaterial = Standard_False;
577   myOwnWidth     = 0.0f;
578   myDrawer->SetTransparency (0.0f);
579 }
580
581 //=======================================================================
582 //function : SetHilightMode
583 //purpose  :
584 //=======================================================================
585 void PrsMgr_PresentableObject::SetHilightMode (const Standard_Integer theMode)
586 {
587   if (myHilightDrawer.IsNull())
588   {
589     myHilightDrawer = new Prs3d_Drawer();
590     myHilightDrawer->Link (myDrawer);
591     myHilightDrawer->SetAutoTriangulation (Standard_False);
592     myHilightDrawer->SetColor (Quantity_NOC_GRAY80);
593     myHilightDrawer->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
594   }
595   if (myDynHilightDrawer.IsNull())
596   {
597     myDynHilightDrawer = new Prs3d_Drawer();
598     myDynHilightDrawer->Link (myDrawer);
599     myDynHilightDrawer->SetColor (Quantity_NOC_CYAN1);
600     myDynHilightDrawer->SetAutoTriangulation (Standard_False);
601     myDynHilightDrawer->SetZLayer(Graphic3d_ZLayerId_Top);
602   }
603   myHilightDrawer   ->SetDisplayMode (theMode);
604   myDynHilightDrawer->SetDisplayMode (theMode);
605 }
606
607 //=======================================================================
608 //function : SynchronizeAspects
609 //purpose  :
610 //=======================================================================
611 void PrsMgr_PresentableObject::SynchronizeAspects()
612 {
613   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
614   {
615     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
616     for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Groups()); aGroupIter.More(); aGroupIter.Next())
617     {
618       if (!aGroupIter.Value().IsNull())
619       {
620         aGroupIter.ChangeValue()->SynchronizeAspects();
621       }
622     }
623   }
624 }
625
626 //=======================================================================
627 //function : replaceAspects
628 //purpose  :
629 //=======================================================================
630 void PrsMgr_PresentableObject::replaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap)
631 {
632   if (theMap.IsEmpty())
633   {
634     return;
635   }
636
637   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
638   {
639     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
640     for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Groups()); aGroupIter.More(); aGroupIter.Next())
641     {
642       if (!aGroupIter.Value().IsNull())
643       {
644         aGroupIter.ChangeValue()->ReplaceAspects (theMap);
645       }
646     }
647   }
648 }
649
650 //=======================================================================
651 //function : BoundingBox
652 //purpose  :
653 //=======================================================================
654 void PrsMgr_PresentableObject::BoundingBox (Bnd_Box& theBndBox)
655 {
656   if (myDrawer->DisplayMode() == -1)
657   {
658     if (!myPresentations.IsEmpty())
659     {
660       const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations.First();
661       const Graphic3d_BndBox3d& aBndBox = aPrs3d->CStructure()->BoundingBox();
662       if (aBndBox.IsValid())
663       {
664         theBndBox.Update (aBndBox.CornerMin().x(), aBndBox.CornerMin().y(), aBndBox.CornerMin().z(),
665                           aBndBox.CornerMax().x(), aBndBox.CornerMax().y(), aBndBox.CornerMax().z());
666       }
667       else
668       {
669         theBndBox.SetVoid();
670       }
671       return;
672     }
673
674     for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (myChildren); aPrsIter.More(); aPrsIter.Next())
675     {
676       if (const Handle(PrsMgr_PresentableObject)& aChild = aPrsIter.Value())
677       {
678         Bnd_Box aBox;
679         aChild->BoundingBox (aBox);
680         theBndBox.Add (aBox);
681       }
682     }
683     return;
684   }
685
686   for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
687   {
688     const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
689     if (aPrs3d->Mode() == myDrawer->DisplayMode())
690     {
691       const Graphic3d_BndBox3d& aBndBox = aPrs3d->CStructure()->BoundingBox();
692       if (aBndBox.IsValid())
693       {
694         theBndBox.Update (aBndBox.CornerMin().x(), aBndBox.CornerMin().y(), aBndBox.CornerMin().z(),
695                           aBndBox.CornerMax().x(), aBndBox.CornerMax().y(), aBndBox.CornerMax().z());
696       }
697       else
698       {
699         theBndBox.SetVoid();
700       }
701       return;
702     }
703   }
704 }
705
706 //=======================================================================
707 //function : Material
708 //purpose  :
709 //=======================================================================
710 Graphic3d_NameOfMaterial PrsMgr_PresentableObject::Material() const
711 {
712   return myDrawer->ShadingAspect()->Material().Name();
713 }
714
715 //=======================================================================
716 //function : SetMaterial
717 //purpose  :
718 //=======================================================================
719 void PrsMgr_PresentableObject::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
720 {
721   myDrawer->SetupOwnShadingAspect();
722   myDrawer->ShadingAspect()->SetMaterial (theMaterial);
723   hasOwnMaterial = Standard_True;
724 }
725
726 //=======================================================================
727 //function : UnsetMaterial
728 //purpose  :
729 //=======================================================================
730 void PrsMgr_PresentableObject::UnsetMaterial()
731 {
732   if (!HasMaterial())
733   {
734     return;
735   }
736
737   if (HasColor() || IsTransparent())
738   {
739     if (myDrawer->HasLink())
740     {
741       myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Aspect()->BackMaterial());
742     }
743
744     if (HasColor())
745     {
746       SetColor (myDrawer->Color());
747     }
748
749     if (IsTransparent())
750     {
751       SetTransparency (myDrawer->Transparency());
752     }
753   }
754   else
755   {
756     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
757   }
758
759   hasOwnMaterial = Standard_False;
760 }
761
762 //=======================================================================
763 //function : SetTransparency
764 //purpose  :
765 //=======================================================================
766 void PrsMgr_PresentableObject::SetTransparency (const Standard_Real theValue)
767 {
768   myDrawer->SetupOwnShadingAspect();
769   myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (Standard_ShortReal(theValue));
770   myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (Standard_ShortReal(theValue));
771   myDrawer->SetTransparency (Standard_ShortReal(theValue));
772 }
773
774 //=======================================================================
775 //function : UnsetTransparency
776 //purpose  :
777 //=======================================================================
778 void PrsMgr_PresentableObject::UnsetTransparency()
779 {
780   if (HasColor() || HasMaterial())
781   {
782     myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (0.0f);
783     myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (0.0f);
784   }
785   else
786   {
787     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
788   }
789   myDrawer->SetTransparency (0.0f);
790 }
791
792 //=======================================================================
793 //function : SetPolygonOffsets
794 //purpose  :
795 //=======================================================================
796 void PrsMgr_PresentableObject::SetPolygonOffsets (const Standard_Integer   theMode,
797                                                   const Standard_ShortReal theFactor,
798                                                   const Standard_ShortReal theUnits)
799 {
800   myDrawer->SetupOwnShadingAspect();
801   myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets (theMode, theFactor, theUnits);
802   SynchronizeAspects();
803 }
804
805 //=======================================================================
806 //function : HasPolygonOffsets
807 //purpose  :
808 //=======================================================================
809 Standard_Boolean PrsMgr_PresentableObject::HasPolygonOffsets() const
810 {
811   return !(myDrawer->HasOwnShadingAspect()
812         || (myDrawer->HasLink()
813          && myDrawer->ShadingAspect() == myDrawer->Link()->ShadingAspect()));
814 }
815
816 //=======================================================================
817 //function : PolygonOffsets
818 //purpose  :
819 //=======================================================================
820 void PrsMgr_PresentableObject::PolygonOffsets (Standard_Integer&   theMode,
821                                                Standard_ShortReal& theFactor,
822                                                Standard_ShortReal& theUnits) const
823 {
824   if (HasPolygonOffsets())
825   {
826     myDrawer->ShadingAspect()->Aspect()->PolygonOffsets (theMode, theFactor, theUnits);
827   }
828 }
829
830 // =======================================================================
831 // function : DumpJson
832 // purpose  :
833 // =======================================================================
834 void PrsMgr_PresentableObject::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
835 {
836   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
837
838   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myParent)
839
840   for (PrsMgr_Presentations::Iterator anIterator (myPresentations); anIterator.More(); anIterator.Next())
841   {
842     const Handle(PrsMgr_Presentation)& aPresentation = anIterator.Value();
843     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aPresentation.get())
844   }
845
846   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myClipPlanes.get())
847
848   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDrawer.get())
849   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myHilightDrawer.get())
850   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDynHilightDrawer.get())
851
852   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myTransformPersistence.get())
853
854   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myLocalTransformation.get())
855   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myTransformation.get())
856   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myCombinedParentTransform.get())
857
858   for (PrsMgr_ListOfPresentableObjects::Iterator anIterator (myChildren); anIterator.More(); anIterator.Next())
859   {
860     const Handle(PrsMgr_PresentableObject)& aChildObject = anIterator.Value();
861     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aChildObject.get())
862   }
863
864   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myInvTransformation)
865
866   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTypeOfPresentation3d)
867   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurrentFacingModel)
868
869   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOwnWidth)
870   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, hasOwnColor)
871   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, hasOwnMaterial)
872
873   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myInfiniteState)
874   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsMutable)
875   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnPresentations)
876
877   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToPropagateVisualState)
878 }