0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / PrsMgr / PrsMgr_PresentableObject.cxx
CommitLineData
b311480e 1// Created on: 1997-12-16
2// Created by: Jean Louis Frenkel
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
778cd667 17#include <PrsMgr_PresentableObject.hxx>
42cf5bc1 18
2b886265 19#include <Graphic3d_AspectFillArea3d.hxx>
f838dac4 20#include <Prs3d_Drawer.hxx>
2b886265 21#include <Prs3d_LineAspect.hxx>
22#include <Prs3d_PointAspect.hxx>
42cf5bc1 23#include <Prs3d_Presentation.hxx>
2b886265 24#include <Prs3d_ShadingAspect.hxx>
7dd7c146 25#include <PrsMgr_Presentation.hxx>
26#include <PrsMgr_PresentationManager.hxx>
42cf5bc1 27#include <Standard_NotImplemented.hxx>
7fd59977 28#include <TColStd_MapOfInteger.hxx>
7fd59977 29
f838dac4 30IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentableObject, Standard_Transient)
92efcf78 31
1f7f5a90 32//=======================================================================
33//function : getIdentityTrsf
34//purpose :
35//=======================================================================
36const gp_Trsf& PrsMgr_PresentableObject::getIdentityTrsf()
37{
2b886265 38 static const gp_Trsf THE_IDENTITY_TRSF;
1f7f5a90 39 return THE_IDENTITY_TRSF;
40}
41
7fd59977 42//=======================================================================
43//function : PrsMgr_PresentableObject
b7cd4ba7 44//purpose :
7fd59977 45//=======================================================================
b7cd4ba7 46PrsMgr_PresentableObject::PrsMgr_PresentableObject (const PrsMgr_TypeOfPresentation3d theType)
2b886265 47: myParent (NULL),
48 myDrawer (new Prs3d_Drawer()),
f838dac4 49 myTypeOfPresentation3d (theType),
2b886265 50 //
51 myCurrentFacingModel (Aspect_TOFM_BOTH_SIDE),
52 myOwnWidth (0.0f),
53 hasOwnColor (Standard_False),
54 hasOwnMaterial (Standard_False),
55 //
56 myInfiniteState (Standard_False),
0717ddc1 57 myIsMutable (Standard_False),
0d56f743 58 myHasOwnPresentations (Standard_True),
59 myToPropagateVisualState (Standard_True)
7fd59977 60{
f838dac4 61 myDrawer->SetDisplayMode (-1);
7fd59977 62}
63
7fd59977 64//=======================================================================
0717ddc1 65//function : ~PrsMgr_PresentableObject
66//purpose : destructor
67//=======================================================================
68PrsMgr_PresentableObject::~PrsMgr_PresentableObject()
69{
7dd7c146 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
0717ddc1 78 for (PrsMgr_ListOfPresentableObjectsIter anIter (myChildren); anIter.More(); anIter.Next())
79 {
7f24b768 80 anIter.Value()->SetCombinedParentTransform (Handle(TopLoc_Datum3D)());
0717ddc1 81 anIter.Value()->myParent = NULL;
82 }
83}
84
85//=======================================================================
7fd59977 86//function : Fill
87//purpose :
88//=======================================================================
af324faa 89void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
90 const Handle(PrsMgr_Presentation)& thePrs,
91 const Standard_Integer theMode)
4269bd1b 92{
7dd7c146 93 const Handle(Prs3d_Presentation)& aStruct3d = thePrs;
af324faa 94 Compute (thePrsMgr, aStruct3d, theMode);
1b63268e 95 aStruct3d->SetTransformation (myTransformation);
af324faa 96 aStruct3d->SetClipPlanes (myClipPlanes);
778cd667 97 aStruct3d->SetTransformPersistence (TransformPersistence());
7fd59977 98}
99
7fd59977 100//=======================================================================
b5163d2f 101//function : computeHLR
102//purpose :
7fd59977 103//=======================================================================
b5163d2f 104void PrsMgr_PresentableObject::computeHLR (const Handle(Graphic3d_Camera)& ,
7f24b768 105 const Handle(TopLoc_Datum3D)& ,
b5163d2f 106 const Handle(Prs3d_Presentation)& )
7fd59977 107{
9775fa61 108 throw Standard_NotImplemented("cannot compute under a specific projector");
7fd59977 109}
110
111//=======================================================================
226fce20 112//function : ToBeUpdated
113//purpose :
7fd59977 114//=======================================================================
226fce20 115Standard_Boolean PrsMgr_PresentableObject::ToBeUpdated (Standard_Boolean theToIncludeHidden) const
116{
117 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
118 {
7dd7c146 119 const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
120 if (aModedPrs->MustBeUpdated())
226fce20 121 {
122 if (theToIncludeHidden)
123 {
124 return Standard_True;
125 }
126
7dd7c146 127 Handle(PrsMgr_PresentationManager) aPrsMgr = aModedPrs->PresentationManager();
128 if (aPrsMgr->IsDisplayed (this, aModedPrs->Mode())
129 || aPrsMgr->IsHighlighted(this, aModedPrs->Mode()))
226fce20 130 {
131 return Standard_True;
7fd59977 132 }
7fd59977 133 }
134 }
226fce20 135 return Standard_False;
7fd59977 136}
4269bd1b 137
7fd59977 138//=======================================================================
226fce20 139//function : UpdatePresentations
140//purpose :
7fd59977 141//=======================================================================
226fce20 142Standard_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 {
7dd7c146 147 const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
148 if (aModedPrs->MustBeUpdated())
226fce20 149 {
7dd7c146 150 Handle(PrsMgr_PresentationManager) aPrsMgr = aModedPrs->PresentationManager();
226fce20 151 if (theToIncludeHidden
7dd7c146 152 || aPrsMgr->IsDisplayed (this, aModedPrs->Mode())
153 || aPrsMgr->IsHighlighted(this, aModedPrs->Mode()))
226fce20 154 {
155 hasUpdates = Standard_True;
7dd7c146 156 aPrsMgr->Update (this, aModedPrs->Mode());
226fce20 157 }
7fd59977 158 }
159 }
226fce20 160 return hasUpdates;
7fd59977 161}
4269bd1b 162
7fd59977 163//=======================================================================
226fce20 164//function : Update
165//purpose :
7fd59977 166//=======================================================================
226fce20 167void PrsMgr_PresentableObject::Update (Standard_Integer theMode, Standard_Boolean theToClearOther)
7fd59977 168{
226fce20 169 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More();)
170 {
7dd7c146 171 if (aPrsIter.Value()->Mode() == theMode)
226fce20 172 {
7dd7c146 173 Handle(PrsMgr_PresentationManager) aPrsMgr = aPrsIter.Value()->PresentationManager();
226fce20 174 if (aPrsMgr->IsDisplayed (this, theMode)
175 || aPrsMgr->IsHighlighted(this, theMode))
176 {
177 aPrsMgr->Update (this, theMode);
7dd7c146 178 aPrsIter.Value()->SetUpdateStatus (Standard_False);
226fce20 179 }
180 else
181 {
7dd7c146 182 SetToUpdate (aPrsIter.Value()->Mode());
226fce20 183 }
184 }
185 else if (theToClearOther)
186 {
187 myPresentations.Remove (aPrsIter);
188 continue;
189 }
190 aPrsIter.Next();
7fd59977 191 }
192}
4269bd1b 193
194//=======================================================================
195//function : SetToUpdate
226fce20 196//purpose :
4269bd1b 197//=======================================================================
226fce20 198void PrsMgr_PresentableObject::SetToUpdate (Standard_Integer theMode)
7fd59977 199{
226fce20 200 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
201 {
202 if (theMode == -1
7dd7c146 203 || aPrsIter.Value()->Mode() == theMode)
226fce20 204 {
7dd7c146 205 aPrsIter.ChangeValue()->SetUpdateStatus (Standard_True);
226fce20 206 }
7fd59977 207 }
208}
209
210//=======================================================================
211//function : ToBeUpdated
212//purpose : gets the list of modes to be updated
213//=======================================================================
226fce20 214void PrsMgr_PresentableObject::ToBeUpdated (TColStd_ListOfInteger& theOutList) const
7fd59977 215{
226fce20 216 theOutList.Clear();
016e5959 217 TColStd_MapOfInteger MI(myPresentations.Length());
226fce20 218 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
219 {
7dd7c146 220 const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
221 if (aModedPrs->MustBeUpdated()
222 && MI.Add (aModedPrs->Mode()))
226fce20 223 {
7dd7c146 224 theOutList.Append (aModedPrs->Mode());
226fce20 225 }
7fd59977 226 }
7fd59977 227}
228
229//=======================================================================
230//function : SetTypeOfPresentation
af324faa 231//purpose :
7fd59977 232//=======================================================================
af324faa 233void PrsMgr_PresentableObject::SetTypeOfPresentation (const PrsMgr_TypeOfPresentation3d theType)
7fd59977 234{
af324faa 235 myTypeOfPresentation3d = theType;
226fce20 236 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
af324faa 237 {
7dd7c146 238 const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
239 aPrs->SetVisual (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant
240 ? Graphic3d_TOS_COMPUTED
241 : Graphic3d_TOS_ALL);
7fd59977 242 }
243}
244
245//=======================================================================
1f7f5a90 246//function : setLocalTransformation
247//purpose :
7fd59977 248//=======================================================================
7f24b768 249void PrsMgr_PresentableObject::setLocalTransformation (const Handle(TopLoc_Datum3D)& theTransformation)
7fd59977 250{
0717ddc1 251 myLocalTransformation = theTransformation;
252 UpdateTransformation();
7fd59977 253}
254
255//=======================================================================
0717ddc1 256//function : ResetTransformation
7fd59977 257//purpose :
258//=======================================================================
0717ddc1 259void PrsMgr_PresentableObject::ResetTransformation()
7fd59977 260{
7f24b768 261 setLocalTransformation (Handle(TopLoc_Datum3D)());
7fd59977 262}
263
4269bd1b 264//=======================================================================
0717ddc1 265//function : SetCombinedParentTransform
266//purpose :
267//=======================================================================
7f24b768 268void PrsMgr_PresentableObject::SetCombinedParentTransform (const Handle(TopLoc_Datum3D)& theTrsf)
0717ddc1 269{
1f7f5a90 270 myCombinedParentTransform = theTrsf;
0717ddc1 271 UpdateTransformation();
272}
273
274//=======================================================================
275//function : UpdateTransformation
4269bd1b 276//purpose :
277//=======================================================================
0717ddc1 278void PrsMgr_PresentableObject::UpdateTransformation()
7fd59977 279{
1f7f5a90 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();
7f24b768 287 myTransformation = new TopLoc_Datum3D (aTrsf);
1f7f5a90 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 }
af324faa 301
226fce20 302 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
af324faa 303 {
7dd7c146 304 aPrsIter.ChangeValue()->SetTransformation (myTransformation);
af324faa 305 }
306
1f7f5a90 307 for (PrsMgr_ListOfPresentableObjectsIter aChildIter (myChildren); aChildIter.More(); aChildIter.Next())
af324faa 308 {
1f7f5a90 309 aChildIter.Value()->SetCombinedParentTransform (myTransformation);
7fd59977 310 }
311}
312
7fd59977 313//=======================================================================
bf5f0ca2 314//function : recomputeComputed
315//purpose :
316//=======================================================================
317void PrsMgr_PresentableObject::recomputeComputed() const
318{
226fce20 319 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
bf5f0ca2 320 {
7dd7c146 321 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value();
322 aPrs3d->ReCompute();
bf5f0ca2 323 }
324}
325
326//=======================================================================
7fd59977 327//function : SetTransformPersistence
af324faa 328//purpose :
7fd59977 329//=======================================================================
778cd667 330void PrsMgr_PresentableObject::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
7fd59977 331{
778cd667 332 myTransformPersistence = theTrsfPers;
226fce20 333 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
af324faa 334 {
7dd7c146 335 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value();
336 aPrs3d->SetTransformPersistence (myTransformPersistence);
337 aPrs3d->ReCompute();
af324faa 338 }
7fd59977 339}
340
341//=======================================================================
7fd59977 342//function : GetTransformPersistence
778cd667 343//purpose :
7fd59977 344//=======================================================================
825aa485 345gp_Pnt PrsMgr_PresentableObject::GetTransformPersistencePoint() const
7fd59977 346{
778cd667 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());
7fd59977 381}
59f45b7c 382
383//=======================================================================
0717ddc1 384//function : AddChild
385//purpose :
386//=======================================================================
387void 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//=======================================================================
52c38ce1 401//function : AddChildWithCurrentTransformation
402//purpose :
403//=======================================================================
404void 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//=======================================================================
0717ddc1 412//function : RemoveChild
413//purpose :
414//=======================================================================
415void 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;
7f24b768 423 theObject->SetCombinedParentTransform (Handle(TopLoc_Datum3D)());
0717ddc1 424 myChildren.Remove (anIter);
425 break;
426 }
427 }
428}
429
430//=======================================================================
52c38ce1 431//function : RemoveChildWithRestoreTransformation
432//purpose :
433//=======================================================================
434void 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//=======================================================================
59f45b7c 442//function : SetZLayer
443//purpose :
444//=======================================================================
a1954302 445void PrsMgr_PresentableObject::SetZLayer (const Graphic3d_ZLayerId theLayerId)
59f45b7c 446{
f838dac4 447 if (myDrawer->ZLayer() == theLayerId)
a1954302 448 {
449 return;
450 }
451
f838dac4 452 myDrawer->SetZLayer (theLayerId);
226fce20 453 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
a1954302 454 {
7dd7c146 455 const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
456 aModedPrs->SetZLayer (theLayerId);
a1954302 457 }
59f45b7c 458}
459
4269bd1b 460// =======================================================================
461// function : AddClipPlane
462// purpose :
463// =======================================================================
464void PrsMgr_PresentableObject::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
465{
51b10cd4 466 // add to collection and process changes
3202bf1e 467 if (myClipPlanes.IsNull())
468 {
469 myClipPlanes = new Graphic3d_SequenceOfHClipPlane();
470 }
471
472 myClipPlanes->Append (thePlane);
51b10cd4 473 UpdateClipping();
4269bd1b 474}
475
476// =======================================================================
477// function : RemoveClipPlane
478// purpose :
479// =======================================================================
480void PrsMgr_PresentableObject::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
481{
3202bf1e 482 if (myClipPlanes.IsNull())
483 {
484 return;
485 }
486
51b10cd4 487 // remove from collection and process changes
3202bf1e 488 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*myClipPlanes); aPlaneIt.More(); aPlaneIt.Next())
51b10cd4 489 {
490 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
491 if (aPlane != thePlane)
492 continue;
4269bd1b 493
3202bf1e 494 myClipPlanes->Remove (aPlaneIt);
51b10cd4 495 UpdateClipping();
496 return;
497 }
4269bd1b 498}
499
500// =======================================================================
501// function : SetClipPlanes
502// purpose :
503// =======================================================================
3202bf1e 504void PrsMgr_PresentableObject::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
4269bd1b 505{
51b10cd4 506 // change collection and process changes
4269bd1b 507 myClipPlanes = thePlanes;
4269bd1b 508 UpdateClipping();
509}
510
511// =======================================================================
512// function : UpdateClipping
513// purpose :
514// =======================================================================
515void PrsMgr_PresentableObject::UpdateClipping()
516{
226fce20 517 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
4269bd1b 518 {
7dd7c146 519 const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
520 aModedPrs->SetClipPlanes (myClipPlanes);
4269bd1b 521 }
522}
b7cd4ba7 523
2b886265 524//=======================================================================
525//function : SetInfiniteState
526//purpose :
527//=======================================================================
528void 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 {
7dd7c146 538 const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
539 aModedPrs->SetInfiniteState (theFlag);
2b886265 540 }
541}
542
b7cd4ba7 543// =======================================================================
544// function : SetMutable
545// purpose :
546// =======================================================================
547void PrsMgr_PresentableObject::SetMutable (const Standard_Boolean theIsMutable)
548{
549 if (myIsMutable == theIsMutable)
550 {
551 return;
552 }
553
554 myIsMutable = theIsMutable;
226fce20 555 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
b7cd4ba7 556 {
7dd7c146 557 const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value();
558 aModedPrs->SetMutable (theIsMutable);
b7cd4ba7 559 }
560}
f838dac4 561
562// =======================================================================
f838dac4 563// function : UnsetAttributes
564// purpose :
565// =======================================================================
566void 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;
2b886265 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//=======================================================================
585void 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//=======================================================================
611void PrsMgr_PresentableObject::SynchronizeAspects()
612{
613 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
614 {
7dd7c146 615 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
616 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Groups()); aGroupIter.More(); aGroupIter.Next())
2b886265 617 {
618 if (!aGroupIter.Value().IsNull())
619 {
620 aGroupIter.ChangeValue()->SynchronizeAspects();
621 }
622 }
623 }
624}
625
626//=======================================================================
627//function : replaceAspects
628//purpose :
629//=======================================================================
630void 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 {
7dd7c146 639 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
640 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Groups()); aGroupIter.More(); aGroupIter.Next())
2b886265 641 {
642 if (!aGroupIter.Value().IsNull())
643 {
644 aGroupIter.ChangeValue()->ReplaceAspects (theMap);
645 }
646 }
647 }
648}
649
650//=======================================================================
651//function : BoundingBox
652//purpose :
653//=======================================================================
654void PrsMgr_PresentableObject::BoundingBox (Bnd_Box& theBndBox)
655{
656 if (myDrawer->DisplayMode() == -1)
657 {
658 if (!myPresentations.IsEmpty())
659 {
7dd7c146 660 const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations.First();
661 const Graphic3d_BndBox3d& aBndBox = aPrs3d->CStructure()->BoundingBox();
2b886265 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
7dd7c146 686 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
2b886265 687 {
7dd7c146 688 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
689 if (aPrs3d->Mode() == myDrawer->DisplayMode())
2b886265 690 {
7dd7c146 691 const Graphic3d_BndBox3d& aBndBox = aPrs3d->CStructure()->BoundingBox();
2b886265 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//=======================================================================
710Graphic3d_NameOfMaterial PrsMgr_PresentableObject::Material() const
711{
712 return myDrawer->ShadingAspect()->Material().Name();
713}
714
715//=======================================================================
716//function : SetMaterial
717//purpose :
718//=======================================================================
719void 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//=======================================================================
730void 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//=======================================================================
766void 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//=======================================================================
778void 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//=======================================================================
796void 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//=======================================================================
809Standard_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//=======================================================================
820void 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 }
f838dac4 828}
0904aa63 829
830// =======================================================================
831// function : DumpJson
832// purpose :
833// =======================================================================
bc73b006 834void PrsMgr_PresentableObject::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
0904aa63 835{
bc73b006 836 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
0904aa63 837
bc73b006 838 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myParent)
0904aa63 839
bc73b006 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)
0904aa63 876
bc73b006 877 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToPropagateVisualState)
0904aa63 878}